-->
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.  [ 3 posts ] 
Author Message
 Post subject: How to wrap persistent list? When the bag is loaded?
PostPosted: Tue Jan 10, 2006 4:06 am 
Beginner
Beginner

Joined: Mon Dec 19, 2005 4:13 am
Posts: 27
Location: Prague, Czech Republic
Hello,

I want to wrap my untyped collections in business classes with some generic wrapper. Wrapper class has some additional functionality, it is raising events when items are added or removed from collection, for example. Because of this functionality, I cannot have the following code for the wrapping - I need to have only one instance of the wrapper per collection.

Code:
    // persistent bag
    private IList m_KnownSubjects = new ArrayList();

    // generic wrapper
    private BusinessList<Subject> g_KnownSubjects {
      get { return new BusinessList<Subject>(m_KnownSubjects); }
    }


Of course I tried to create wrapper in the constructor, but it seems to be too soon - my wrapper then managed empty instance of ArrayList instead of the instance loaded by Nhibernate.

Code:
    // persistent bag
    private IList m_KnownSubjects = new ArrayList();

    // generic wrapper
    private BusinessList<Subject> g_KnownSubjects;

    // constructor code
    g_KnownSubjects = new BusinessList<Subject>(m_KnownSubjects);


Any ideas? Many thanks.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Jan 10, 2006 11:49 am 
Contributor
Contributor

Joined: Thu May 12, 2005 8:45 am
Posts: 226
I hate asking someone to pour through a bunch of code, but the code of http://www.ayende.com/projects/nhibernate-query-analyzer/generics.aspx is a great example.


Top
 Profile  
 
 Post subject: Using delegate instead of interface
PostPosted: Tue Jan 10, 2006 11:55 am 
Beginner
Beginner

Joined: Mon Dec 19, 2005 4:13 am
Posts: 27
Location: Prague, Czech Republic
Ok,

I solved the problem by using delegate instead of interface as parameter for the wrapper. Code in the class looks like this:

Code:
// persistent collection:
private IList m_KnownSubjects = new ArrayList();

// in constructor:
g_KnownSubjects = new TypedList<Subject>(delegate { return m_KnownSubjects; });


I looks like it work very well for now. Of course, the access strategy is set to "nosetter" or "field".

David


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