How create transfer or detachable objects with Open Access

Thread is closed for posting
10 posts, 1 answers
  1. Kareem
    Kareem avatar
    7 posts
    Member since:
    Nov 2008

    Posted 17 Feb 2009 Link to this post

    Hi,

    I have a business layer that uses the OA Persistent classes. I am trying to return an object back to another layer of our application. But I do not want to return a copy of the Persistent object to the  upper layers. Is there a way to copy the object and return it to the Upper layer? In J2EE we have data transfer objects? In other ORM tools they have detachable objects.

    Any pointers to achieve this with Open Access would be really appreciated.

    Thanks,
    Kareem
  2. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 18 Feb 2009 Link to this post

    Hello Kareem,
    You can just serialize the objects and attach them back to the scope with the ObjectScopeAttacher (in the src dir of your OpenAccess installation)

    If you do not need the serialization you should just pass the objects to everywhere in your app. Please use them like your normal business objects. I do not see the persistent object in the DAL but as seperate module at the same layer as your BLs.

    Like with JDO our scope transaction can be long running, just keep it running during your complete BL operation and commit at the end. The UI changes the data and the scope tracks it and will commit it to the DB.

    How exactly is your architecture?

    Best wishes,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Kareem
    Kareem avatar
    7 posts
    Member since:
    Nov 2008

    Posted 18 Feb 2009 Link to this post

    Jan,

     

    Thanks for your reply. I would need to serialize some of the objects because they are used in web services. But I have several other client applications that simply consume the data and use it perform other processes.

     

    Our architecture is like this:

    At the lowest Level we have the Business Entities (OA Persistent classes), then on top of it we have the Business Workflow layers (This has all the business rules, it uses the Entities).

    The Business workflow layers is used by different Services (Web Services, UI, internal and remote client applications)

    All changes that occur to the data go through the Business Workflow layers as it gets validated against certain business rules. Not all the client applications need to make changes to data so their is no need for it to have a persistent object.

     

    I looked quickly at src directory I did not find the ObjectScopeAttacher; I found two files ObjectNetworkAttacher.cs and OpenAccessDataContext.cs.

     

    Are you referring to the ObjectNetworkAttacher class? Is a quick sample of how to use this class that you are referring to available?

     

    Thanks,

    Kareem

  4. Answer
    Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 19 Feb 2009 Link to this post

    Hi Kareem,
    I see that having transport objects makes your life easier. But at the end the difference between the transport and the real objects are not huge and in a serialized state they will contain exactly the same data.

    Sorry I ment the ObjectNetworkAttacher. The example is attached.


    Regards,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. Kareem
    Kareem avatar
    7 posts
    Member since:
    Nov 2008

    Posted 20 Feb 2009 Link to this post

    Hi Jan,

     

    Thank you very much for the example. You are right; there is barely any difference between the transport objects and the real objects. The serialized object would have everything, but I am looking at the overhead of having to serialize every object.

     

    Do you consider adding a feature in the future that allows the persistent object to be detachable, thus acting as transport object? This would prevent redundant code to be written.

     

    Thanks,

    Kareem

  6. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 20 Feb 2009 Link to this post

    Hello Kareem,
    The code is showing exactly that, by serializing the objects they will be detached and you attach them with the ObjectNetworkAttacher. If you implement a webservice, just have the persistent object as return value. On the way back use the ObjectNetworkAttacher, that's it

    Kind regards,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  7. gmendez
    gmendez avatar
    82 posts
    Member since:
    Jun 2012

    Posted 16 Sep 2009 Link to this post

    Hello Jan,

    I have just seen this thread. I'd like to ask a question.
    So, using this ObjectNetworkAttacher I can retrieve an object through a WCF service without using an ObjectContainer, make changes to it and then the scope would be able to track it's changes? Is that right?
    Thanks in advance,

    Gonzalo
  8. Jan Blessenohl
    Admin
    Jan Blessenohl avatar
    707 posts

    Posted 16 Sep 2009 Link to this post

    Hello gmendez,
    Yes.

    You have to use version fields at your persistent objects to have concurrency control. If that is the case the ObjectNetworkAttacher is able to connect the data (coming form the client) to the scope and will commit your changes to the database.

    Kind regards,
    Jan Blessenohl
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
  9. gmendez
    gmendez avatar
    82 posts
    Member since:
    Jun 2012

    Posted 18 Sep 2009 Link to this post

    Hello Jan,

    Thanks for answering.
    I guess the same is true when trying to attatch an object to an ObjectContainer. The object container has a property in which it stores the ObjectScope. Right?
    What I'd like address here is the scenario where you have an ObjectContainer in the client side which contains some objects retrieved from the database. Then, you bring a single object to the client side which you want to relate to an object inside the ObjectContainer.
    If you just do myContainer.Add(myDetatchedObject) it will crash when trying to persist the container because of a duplicate key exception. It turns out that myDetatchedObject already exists in the scope.
    Could this be resolved using the ObjectNetworkAttacher?

    Best wishes,

    Gonzalo
  10. Alexander
    Admin
    Alexander avatar
    727 posts

    Posted 18 Sep 2009 Link to this post

    Hi gmendez,

    The ObjectNetworkAttacher works the same way for object scopes and object containers as they both implement the IObjectContext interface. You should be able to achieve your goal by using it. This how-to could come in handy if you have not found it already.

    Regards,
    Alexander
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Back to Top