This is a migrated thread and some comments may be shown as answers.

How create transfer or detachable objects with Open Access

9 Answers 202 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Kareem
Top achievements
Rank 1
Kareem asked on 17 Feb 2009, 10:38 PM
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

9 Answers, 1 is accepted

Sort by
0
Jan Blessenohl
Telerik team
answered on 18 Feb 2009, 03:14 PM
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.
0
Kareem
Top achievements
Rank 1
answered on 18 Feb 2009, 05:24 PM

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

0
Accepted
Jan Blessenohl
Telerik team
answered on 19 Feb 2009, 04:27 PM
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.
0
Kareem
Top achievements
Rank 1
answered on 20 Feb 2009, 03:24 PM

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

0
Jan Blessenohl
Telerik team
answered on 20 Feb 2009, 05:47 PM
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.
0
gmendez
Top achievements
Rank 1
answered on 16 Sep 2009, 02:05 PM
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
0
Jan Blessenohl
Telerik team
answered on 16 Sep 2009, 02:45 PM
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.
0
gmendez
Top achievements
Rank 1
answered on 18 Sep 2009, 11:16 AM
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
0
Alexander
Telerik team
answered on 18 Sep 2009, 03:36 PM
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.
Tags
General Discussions
Asked by
Kareem
Top achievements
Rank 1
Answers by
Jan Blessenohl
Telerik team
Kareem
Top achievements
Rank 1
gmendez
Top achievements
Rank 1
Alexander
Telerik team
Share this question
or