Solved

ATL collection using database

Posted on 2001-07-12
9
177 Views
Last Modified: 2006-11-17
Hi,
I have implemented a collection in ATL.
"People" is the collection "Man" is an item of the collection.

In the database i have a table People and so, each record in the table is a Man.
I use ADO to access my database.

And my ATL collection have to support multithread.

On each item of the collection, you can Set and Get properties.

The problem i have is on how i get the data of my items. I can't store the data directly in the "Man" object because if another client have changeed the name for instance, the state of my object will be incorrect for other clients.

So, i have to get the data in the database each time the client access a property of an item. And it disturbs me a lot because it implies each item to have a recordset, to go and get the data in the database.

So 70000 items --> 70000 recordsets, i think it is not acceptable.

So my question is, what is the current and efficient way to implement a collection that manages table of a database?

Thanks!




0
Comment
Question by:FMayis
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 2

Expert Comment

by:missionImpossible
ID: 6277348
I don't know if I really got it, but you don't need to have one recordset per item. You can use one recordset per client. The recordset in your case should be a "Dynamic"-recordset type. This is a representation of a dynamic cursor, which shows every changes of other users on the fly. See also MSDN.

0
 
LVL 6

Expert Comment

by:snoegler
ID: 6280083
>> So my question is, what is the current and efficient way to implement a collection that manages table
of a database?

A database :)
Databases are specifically designed for handling this. By putting a 'container' around a database table, all benefits of a database are lost (as long as you want a generic container) (or you are going to re-implement SQL which is specifically designed for doing all time critical tasks within the highly optimized database engine).
0
 
LVL 9

Expert Comment

by:ShaunWilde
ID: 6280828
I agree wish snoeglar let the database be the main store of your collection - if you need to hand it out do a select * and generate your collection on that and pass it on - or you can pass out single items, subsets or the whole thing - if an item needs to check its state (dirtyness) then you can either check with a flag (eg timestamp of last update) or just get the whole thing.
0
 
LVL 6

Expert Comment

by:snoegler
ID: 6280844
>> as long as you want a generic container
i meant:
>> as long as you want a simple container
0
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 

Author Comment

by:FMayis
ID: 6284868
Hi,
I do agree, the database is the main store of the collection.

For the moment i did a select * and then use the generated recordset to implement my collection.

and doing a SELECT * implies loading in memeory lot of things not needed. If a user works with an item and i have some thousand in the database, then lot of memories are lost for nothing.

So,what is the best compromise(performance time, memory size) between loading all, or making a request on each access to data of an item property.

0
 
LVL 2

Accepted Solution

by:
missionImpossible earned 200 total points
ID: 6284908
1. if you need all data of a row (select *), to get it once is quite more performant, as to access the data in multiple access.
But sometimes it could be clever to fetch data lazy: F.ex if your user needs only in 5% of all use cases all the data, you can fetch this data only if he really needs it. in 95% of the cases you can get only the  data he needs and your app will be more performant. It depends on what the user needs.

2. if the user don't needs to access all rows (at the same time), filter your select, to get only one or few rows of data.
0
 

Author Comment

by:FMayis
ID: 6285255
The collection will be used like follows

for i = 1 to Count
    item=col.GetItem(i)
    item.GetName //or anyother property
next

or

item = col.GetItem("Name")
//and then get all properties of the item


I think that getting data when needs will be more performant.

0
 
LVL 6

Expert Comment

by:snoegler
ID: 6285262
What about a collection like this:

MyColl.Init "SELECT * from customer";
For Each Elem in MyColl
  Print Elem("Name"), Elem("Street"), Elem("Zip")
Next

This reminds me of something :)
0
 

Author Comment

by:FMayis
ID: 6368723
Sorry for elapsed time!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The goal of the video will be to teach the user the difference and consequence of passing data by value vs passing data by reference in C++. An example of passing data by value as well as an example of passing data by reference will be be given. Bot…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now