Solved

ATL collection using database

Posted on 2001-07-12
9
178 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
Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

 
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
 

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

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
The goal of the video will be to teach the user the concept of local variables and scope. An example of a locally defined variable will be given as well as an explanation of what scope is in C++. The local variable and concept of scope will be relat…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.

816 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