Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] distinguish first-time construction from deserialization
[CDO] distinguish first-time construction from deserialization [message #672224] Fri, 20 May 2011 11:46 Go to next message
Julien Jorge is currently offline Julien JorgeFriend
Messages: 6
Registered: January 2011
Junior Member
Hi,

Is there a way to distinguish the first construction of a CDOObject instance from the construction resulting of the deserialization?

I am working on a code base in which some initialization is done in the constructor of the objects. This initialization must be done only once in the total lifespan of the instances. Unfortunately, when an instance in restored from the repository, the constructor of the class is called and this initialization is repeated.

I would like to avoid this situation. So is there a flag to distinguish those constructions? Or is there a way I can split the construction of CDOObjects in two parts to distinguish the first time construction and the deserialization construction?
Re: [CDO] distinguish first-time construction from deserialization [message #686818 is a reply to message #672224] Fri, 20 May 2011 13:25 Go to previous messageGo to next message
Ed Merks is currently offline Ed MerksFriend
Messages: 33140
Registered: July 2009
Senior Member
Julien,

Maybe CDO provides something specific but there's no way in general to
know why an object is being constructed.

What kind of initialization are you doing? Why do you need to do it?


Julien Jorge wrote:
> Hi,
>
> Is there a way to distinguish the first construction of a CDOObject
> instance from the construction resulting of the deserialization?
>
> I am working on a code base in which some initialization is done in
> the constructor of the objects. This initialization must be done only
> once in the total lifespan of the instances. Unfortunately, when an
> instance in restored from the repository, the constructor of the class
> is called and this initialization is repeated.
>
> I would like to avoid this situation. So is there a flag to
> distinguish those constructions? Or is there a way I can split the
> construction of CDOObjects in two parts to distinguish the first time
> construction and the deserialization construction?
>


Ed Merks
Professional Support: https://www.macromodeling.com/
Re: [CDO] distinguish first-time construction from deserialization (React to change) [message #686835 is a reply to message #672224] Mon, 23 May 2011 07:03 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6682
Registered: July 2009
Senior Member
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
<title></title>
</head>
<body bgcolor="#ffffff" text="#000000">
Hi Julien,<br>
<br>
It is like Ed already said, the lifecycles of the logical persistent
entity and the technical Java object that represents this entity
during some kind of session are kind of orthogonal or interleaved.
It does not make sense to mix them and there's no way to tell why
the constructor of the Java object has been called (other than
inspecting the call stack).<br>
<br>
The logical entity's lifecycle depends on the specific persistence
mechanism you've chosen, e.g. files, Hibernate (Teneo) or CDO. In
CDO this lifecycle is controlled by a finite state machine that
looks like:<br>
<br>
<img src="http://www.eclipse.org/forums/index.php?t=getfile&amp;id=3099" alt="FSM"
height="358" width="600"><br>
<br>
We're offering different hooks that you can register with:<br>
<br>
1)
org.eclipse.emf.cdo.view.CDOView.addObjectHandler(CDOObjectHandler)<br>
<br>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = -->
<!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3"
cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td nowrap="nowrap" align="left"
valign="top"> <code>
<font color="#7f0055"><b>public interface </b></font><font
color="#000000">CDOObjectHandler</font><br>
<font color="#000000">{</font><br>
<font color="#ffffff">  </font><font color="#7f0055"><b>public </b></font><font
color="#7f0055"><b>void </b></font><font
color="#000000">objectStateChanged</font><font
color="#000000">(</font><font color="#000000">CDOView view, CDOObject object, CDOState oldState, CDOState newState</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#000000">}</font></code> </td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== -->
<br>
2)
org.eclipse.emf.cdo.transaction.CDOTransaction.addTransactionHandler(CDOTransactionHandlerBase)<br>
<br>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = -->
<!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3"
cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td nowrap="nowrap" align="left"
valign="top"> <code>
<font color="#7f0055"><b>public interface </b></font><font
color="#000000">CDOTransactionHandler1 </font><font
color="#7f0055"><b>extends </b></font><font
color="#000000">CDOTransactionHandlerBase</font><br>
<font color="#000000">{</font><br>
<font color="#ffffff"></font><font color="#ffffff">  </font><font
color="#7f0055"><b>public </b></font><font
color="#7f0055"><b>void </b></font><font
color="#000000">attachingObject</font><font
color="#000000">(</font><font color="#000000">CDOTransaction transaction, CDOObject object</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">  </font><font color="#7f0055"><b>public </b></font><font
color="#7f0055"><b>void </b></font><font
color="#000000">detachingObject</font><font
color="#000000">(</font><font color="#000000">CDOTransaction transaction, CDOObject object</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">  </font><font color="#7f0055"><b>public </b></font><font
color="#7f0055"><b>void </b></font><font
color="#000000">modifyingObject</font><font
color="#000000">(</font><font color="#000000">CDOTransaction transaction, CDOObject object, CDOFeatureDelta featureDelta</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#000000">}</font></code> </td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== -->
<br>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = -->
<!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3"
cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td nowrap="nowrap" align="left"
valign="top"> <code>
<font color="#7f0055"><b>public interface </b></font><font
color="#000000">CDOTransactionHandler2 </font><font
color="#7f0055"><b>extends </b></font><font
color="#000000">CDOTransactionHandlerBase</font><br>
<font color="#000000">{</font><br>
<font color="#ffffff"></font><font color="#ffffff">  </font><font
color="#7f0055"><b>public </b></font><font
color="#7f0055"><b>void </b></font><font
color="#000000">committingTransaction</font><font
color="#000000">(</font><font color="#000000">CDOTransaction transaction, CDOCommitContext commitContext</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">  </font><font color="#7f0055"><b>public </b></font><font
color="#7f0055"><b>void </b></font><font
color="#000000">committedTransaction</font><font
color="#000000">(</font><font color="#000000">CDOTransaction transaction, CDOCommitContext commitContext</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#ffffff">  </font><font color="#7f0055"><b>public </b></font><font
color="#7f0055"><b>void </b></font><font
color="#000000">rolledBackTransaction</font><font
color="#000000">(</font><font color="#000000">CDOTransaction transaction</font><font
color="#000000">)</font><font color="#000000">;</font><br>
<font color="#000000">}</font></code> </td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== -->
<br>
3) CDOView is an INotifier (offers an addListener method) that fires
this event for remote updates:<br>
<br>
<title></title>
<style type="text/css">
<!--code { font-family: Courier New, Courier; font-size: 10pt; margin: 0px; }-->
</style>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<!-- ======================================================== -->
<!-- = Java Sourcecode to HTML automatically converted code = -->
<!-- = Java2Html Converter 5.0 [2006-02-26] by Markus Gebhard markus@jave.de = -->
<!-- = Further information: http://www.java2html.de = -->
<div class="java" align="left">
<table bgcolor="#ffffff" border="0" cellpadding="3"
cellspacing="0">
<tbody>
<tr>
<!-- start source code --> <td nowrap="nowrap" align="left"
valign="top"> <code>
<font color="#7f0055"><b>public interface </b></font><font
color="#000000">CDOViewInvalidationEvent </font><font
color="#7f0055"><b>extends </b></font><font
color="#000000">CDOViewEvent</font><br>
<font color="#000000">{</font><br>
<font color="#ffffff"></font><font color="#ffffff">  </font><font
color="#7f0055"><b>public </b></font><font
color="#7f0055"><b>long </b></font><font
color="#000000">getTimeStamp</font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff">  </font><font color="#7f0055"><b>public </b></font><font
color="#000000">Set&lt;CDOObject&gt; getDirtyObjects</font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff">  </font><font color="#7f0055"><b>public </b></font><font
color="#000000">Map&lt;CDOObject, CDORevisionDelta&gt; getRevisionDeltas</font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#ffffff">  </font><font color="#7f0055"><b>public </b></font><font
color="#000000">Set&lt;CDOObject&gt; getDetachedObjects</font><font
color="#000000">()</font><font color="#000000">;</font><br>
<font color="#000000">}</font></code> </td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== -->
<br>
4) EMF adapters are notified for remote changes with a
CDODeltaNotification if you've registered a change subscription
policy via
org.eclipse.emf.cdo.view.CDOView.Options.addChangeSubscriptionPolicy(CDOAdapterPolicy)<br>
<br>
The real code contains more JavaDocs ;-)<br>
<br>
Cheers<br>
/Eike<br>
<br>
----<br>
<a class="moz-txt-link-freetext" href="http://www.esc-net.de">http://www.esc-net.de</a><br>
<a class="moz-txt-link-freetext" href="http://thegordian.blogspot.com">http://thegordian.blogspot.com</a><br>
<a class="moz-txt-link-freetext" href="http://twitter.com/eikestepper">http://twitter.com/eikestepper</a><br>
<br>
<br>
<br>
Am 20.05.2011 13:46, schrieb Julien Jorge:
<blockquote cite="mid:ir5jr7$2g4$1@news.eclipse.org" type="cite">Hi,
<br>
<br>
Is there a way to distinguish the first construction of a
CDOObject instance from the construction resulting of the
deserialization?
<br>
<br>
I am working on a code base in which some initialization is done
in the constructor of the objects. This initialization must be
done only once in the total lifespan of the instances.
Unfortunately, when an instance in restored from the repository,
the constructor of the class is called and this initialization is
repeated.
<br>
<br>
I would like to avoid this situation. So is there a flag to
distinguish those constructions? Or is there a way I can split the
construction of CDOObjects in two parts to distinguish the first
time construction and the deserialization construction?
<br>
<br>
</blockquote>
</body>
</html>


Previous Topic:How To Persistence Eobject
Next Topic:(no subject)
Goto Forum:
  


Current Time: Tue Apr 23 16:18:21 GMT 2024

Powered by FUDForum. Page generated in 0.02807 seconds
.:: Contact :: Home ::.

Powered by: FUDforum 3.0.2.
Copyright ©2001-2010 FUDforum Bulletin Board Software

Back to the top