-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Regarding NH-300
PostPosted: Mon Jul 04, 2005 9:42 pm 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
http://jira.nhibernate.org/browse/NH-300

I wonder why not just add some code in loader\loader.cs like this,

around line 316, modify like this:

Code:
for ( count = 0; count < maxRows && rs.Read(); count++ )
            {
               object result = GetRowFromResultSet( rs, session, queryParameters, hydratedObjects, optionalObject, optionalId, keys, returnProxies );
               bool resultExisting = false;
               foreach(object item in results)
               {
                  if (object.ReferenceEquals(result,item))
                  {
                     resultExisting = true;
                     break;
                  }
               }
               if (!resultExisting)
               {
                  results.Add( result );
               }
            }


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 5:43 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
The main reason is it will break existing code. Also, your code is not as efficient as using a set to collect results.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 9:29 am 
Regular
Regular

Joined: Thu Dec 02, 2004 10:42 am
Posts: 54
Do you mean it will not be compatible to existing code using NHibernate?

I suppose the existing code would take the duplicated results and loop them to find those distinct using the same way "object.ReferenceEquals()", cause who will need the duplicate object instance which are reference equal?

For the second reason, I am not quite understand. Could you please explain more?

Thanks


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jul 05, 2005 12:45 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Yes, and it will not work like Hibernate. I can't just change the de-facto standard behavior, even if many people find it useless. The best solution would probably be to create a method named .Set instead of .List which would do the distinctificaton and return a set of results.

As for why your implementation is inefficient - you traverse the list of all previously loaded objects for each new object. This means something like quadratic complexity (n items traversed for each item loaded * n items loaded, bad).

If you use a set, then inserting an object in a set takes log n time, so the whole complexity would be n*log n (not so bad). Or it could be even faster if you just compared the new item to the last loaded item. This would be linear complexity (best), but it would only work if the incoming results were sorted.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.