[Helma-user] difficult object relational mapping
Maksim Lin for technical support mailling lists
maksim_lin at ngv.vic.gov.au
Tue Mar 11 06:33:23 CET 2008
Yes that is a better solution!
I must admit I've gotten into the habit of not worrying about pulling
large collections of object into memeory as a large project I've been
working on for a while now has a very large memory cache to basically
keep every HopObject in memory for performance reason (lots of reads,
few writes) but agreed that its definitly not somehting you want to do
in most cases.
Actually I wonder if this could not be the basis for the "pure js" style
HopObject implementation?
I mean from a "data" point of view, HopObject collections need to
implement the following "interface" of functions:
getById()
get()
size()
list()
add()
addAt()
indexOf()
remove()
prefetchChildren()
update()
and to me it looks like you could implement pretty much all of it with
the approach below. I guess what I have in mind is keeping a "global"
hashmap as the in-mem cache of Hopobjects, keyed on Prototype & then on
ID (ie. the implementation of the current static HopObject.getById()
function) and so collections could be intrinsicaly dynamic and with the
framework using them to create collections that are declaritively
defined in the current type.properties files.
I wonder if this approach would also allow greatly simplfiying the
rather scary code thats currently in helma.objectmodel.db package
classes...?
These are all just "thinking out loud" ideas but I may have a go at
prototyping them up and see how it goes.
Maks.
> -----Original Message-----
> From: helma-user-bounces at helma.org
> [mailto:helma-user-bounces at helma.org] On Behalf Of Joshua Paine
> Sent: Thursday, 6 March 2008 15:07
> To: Helma User Mailing List
> Subject: Re: [Helma-user] difficult object relational mapping
>
> Maksim Lin for technical support mailling lists wrote:
> > function getEventsByRecentChanges() {
> > var sqlResult =
> > helma.Database.getInstance("MyDataSource").query("SELECT ID
> from ...);
> > var resultList = [];
> > for (var i=0; i < sqlResults.length; i++) {
> > resultList.push( Event.getById(sqlResult.[i].ID) );
> > }
> > return resultList;
> > }
>
> This is worse than what Breton suggested because it loads
> every Event in the DB into memory all at once. For the
> original poster I still favor a way to use the provided
> collections feature.
>
> We could improve on your sample code, though, to get
> something at least as fast that only loads the entire list of
> IDs into memory at once.
> (That's still too much in some cases, but this will work in
> more cases than the sample above.) Also make it generic and
> act a bit like a HopObject collection:
>
> function createOrderedView(hopType,dataSourceName,query) {
> /* query must select ID */
> var rx = /^\s*[Ss][Ee][Ll][Ee][Cc][Tt]\s+(\w+\s+(as\s+)?)?ID,?\s/;
> if(!rx.test(query)) return null;
> var sqlResults = helma.Database.getInstance(dataSourceName)
> .query(query);
> var pub = ({
> get : function(i) {
> if(!sqlResults[i]) return null;
> return hopType.getById(sqlResults[i].ID);
> },
> size : function() {
> return sqlResults.length;
> },
> list : function() {
> var l = [];
> for(var i = 0; i < sqlResults.length; i++) l[i] = pub.get(i);
> }
> });
> return pub;
> }
>
> This code has not been run. Fixing any errors is left as an
> exercise to the reader ;-).
> _______________________________________________
> Helma-user mailing list
> Helma-user at helma.org
> http://helma.org/mailman/listinfo/helma-user
>
More information about the Helma-user
mailing list