-->
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.  [ 6 posts ] 
Author Message
 Post subject: Implementing IUserCollectionType
PostPosted: Sat Jul 14, 2007 5:55 pm 
Beginner
Beginner

Joined: Thu Aug 17, 2006 3:20 pm
Posts: 21
I am attempt to use a custom collection type and I am running into a problem with calling methods on the actual implementation of the Collection that lives in my domain model.

Here are the classes:

Code:
public class PhotoCollection : IPhotoCollection {
    public void Finalize() {
        // some code here
    }
}

public class PersistentPhotoCollection : PersistentBag, IPersistentCollection {
    public void Finalize() {
        // how do i call PhotoCollection.Finalize from here?
    }
}

public class PhotoCollectionType : IUserCollectionType {}


It works fine for persistence to the database, but IPhotoCollection has the Finalize() method on it that are implemented in PhotoCollection.

I can't figure out how to call these implementations from PersistentPhotoCollection. How do I obtain a reference to PhotoCollection? Is it the Owner property on PersistentBag? I don't seem to "get it"

any help would be appreciated. Thank you!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 15, 2007 4:58 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
PersistentPhotoCollection should implement IPhotoCollection, and will probably be a wrapper around a PhotoCollection instance. So when somebody calls PersistentPhotoCollection.Finalize, it would pass the call to the collection it's wrapping.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 15, 2007 11:01 am 
Beginner
Beginner

Joined: Thu Aug 17, 2006 3:20 pm
Posts: 21
sergey,

I realize that this is what is occuring, I just don't know how to access the underlying collection.

How do I access the PhotoCollection instance from within PersistentPhotoCollection?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 15, 2007 11:33 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Ahh, you want to have access to the bag the PersistentBag is wrapping - I don't think it's possible to access it - you can either recompile NHibernate changing the field to protected, or duplicate the PersistentBag code in your class, then you wouldn't inherit from PersistentBag.

And submit a JIRA issue to make the field protected, please.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 15, 2007 11:37 am 
Beginner
Beginner

Joined: Thu Aug 17, 2006 3:20 pm
Posts: 21
I don't think we're on the same page. I just need to call Finalize on the PhotoCollection instance. Is there an instance of this class provided to PersistentPhotoCollection?

I don't know how to get an instance reference to PhotoCollection from within the Finalize method so that I can call PhotoCollection.Finalize from PersistentPhotoCollection.Finalize

Are we talking about the same thing?


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jul 15, 2007 4:40 pm 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
dkode wrote:
I don't know how to get an instance reference to PhotoCollection from within the Finalize method so that I can call PhotoCollection.Finalize from PersistentPhotoCollection.Finalize


It's up to you to provide that reference. IUserCollectionType.Instantiate is called for new collections and IUserCollectionType.Wrap is called to create a wrapper around an existing collection. The wrapper should then store that collection reference somewhere.

There is an example of IUserCollectionType implementation in the NHibernate test suite.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 6 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.