|
Re: [CDO]How to get different revision of a resource? [message #763852 is a reply to message #763808] |
Sat, 10 December 2011 18:26 |
|
Am 10.12.2011 17:18, schrieb Khosro Asgharifard Sharabiani:
> Hi,
> I use CDO 4.0 ,Eclipse 3.7.
> The following code inserts my model instances to repository :
>
>
> try {
>
> transaction = cdoSession.openTransaction();
> resource = transaction.getOrCreateResource("/res1");
> Library library = LibraryFactory.eINSTANCE.createLibrary();
> library.setName("Something");
> library.setSYSTEM("Tamin");
> Book book = LibraryFactory.eINSTANCE.createBook();
> book.setTitle("Eclipse Modeling Framework (2nd edition)");
> library.getBooks().add(book);
> resource.getContents().add(library);
> transaction.commit();
> cdoSession.close();
>
> } catch (Exception e) {
> e.printStackTrace();
> } finally {
> cdoSession.close();
> }
>
>
> And then i update book instance by the following code(so that ,another row inserted to Book table in
> repository(Database)) :
>
>
>
> public void updateRepository() {
>
>
> transaction = cdoSession.openTransaction();
> resource = transaction.getOrCreateResource("/res1");
> List<EObject> eObjects = resource.getContents();
> for (EObject eObject : eObjects) {
> LibraryImpl libraryImpl = (LibraryImpl) eObject;
> libraryImpl.getBooks().get(0).setTitle("Eclipse Modeling Framework (3nd edition)");
> }
> try {
> transaction.commit();
> } catch (CommitException e) {
> e.printStackTrace();
> } finally {
> cdoSession.close();
> }
> }
>
>
>
> And my cdo-server.xml :
>
>
> <cdoServer>
>
> <acceptor type="tcp" listenAddr="0.0.0.0" port="2036">
> </acceptor>
>
> <repository name="demo">
> <property name="ensureReferentialIntegrity" value="true"/>
> <property name="supportingAudits" value="true"/>
> <property name="supportingBranches" value="true"/>
> <property name="supportingEcore" value="true"/>
> <store type="db">
> <mappingStrategy type="horizontal"/>
> <dbAdapter name="mysql"/>
> <dataSource
> class="com.mysql.jdbc.jdbc2.optional.MysqlDataSource"
> url="jdbc:mysql://localhost:3306/cdotest?createDatabaseIfNotExist=true"
> user="root"
> password="123456"
> />
> </store>
> </repository>
>
> </cdoServer>
>
>
>
> Now How can i programmatically(by writing code) get revision of a Library and Book models and print their
> attributes(EAttribute) to console?
>
> I hope that my question is clear.
Crystal clear ;-)
There's a low-level API to access arbitrary revisions: CDORevisionManager, i.e. session.getRevisionManager(). But on the
CDORevision layer navigation is not directly possible.
If you want to access the entire object graph at a different, historical time it's more convenient to open a CDOView on
the same session and set the (target) timestamp. You can do that when opening the view or even later via setTimeStamp().
A CDOView has a getObject(T) method that you can use to directly jump to an object from another view (your transaction
in this case).
Does that help?
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
Re: [CDO]How to get different revision of a resource? [message #764030 is a reply to message #764022] |
Sun, 11 December 2011 06:31 |
|
<html>
<head>
<meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
</head>
<body bgcolor="#FFFFFF" text="#000000">
Am 11.12.2011 07:00, schrieb Khosro Asgharifard Sharabiani:
<blockquote cite="mid:jc1gtl$5rs$1@news.eclipse.org" type="cite">Thanks
Eike,
<br>
Some questions : 1.I really do not find any proper method(Maybe i
am wrong in finding it) in CDOView to get all of model instances
in a given timestamp,</blockquote>
Think of a CDOView as a read-only transaction, it has most of the
(same) methods for accessing models. In fact a CDOTransaction is a
sub type of a CDOView. In addition it *has* the (target) timestamp
information so that historical model access itself is in no way
different from latest model access. The same application code could
can be used.<br>
<br>
<blockquote cite="mid:jc1gtl$5rs$1@news.eclipse.org" type="cite">except
that getObject(CDOID id) (as you said),and also we must provide a
CDOID to getObject(CDOID id).But i do not know how to provide
CDOID.</blockquote>
No, there is:<br>
<br>
<title></title>
<!-- ======================================================== -->
<!-- = 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 align="left" nowrap="nowrap"
valign="top"> <code>
<font color="#ffffff"> </font><font color="#3f5fbf">/**</font><br>
<font color="#ffffff"> </font><font color="#3f5fbf">* Takes an object from a (possibly) different view and </font><font
color="#7f7f9f"><em></font><font color="#3f5fbf">contextifies</font><font
color="#7f7f9f"></em> </font><font
color="#3f5fbf">it for the usage with this view.</font><br>
<font color="#ffffff"> </font><font color="#3f5fbf">* </font><font
color="#7f7f9f"><ul></font><br>
<font color="#ffffff"> </font><font color="#3f5fbf">* </font><font
color="#7f7f9f"><li></font><font color="#3f5fbf">If the given object is contained in this view it is returned unmodified.</font><br>
<font color="#ffffff"> </font><font color="#3f5fbf">* </font><font
color="#7f7f9f"><li></font><font color="#3f5fbf">If the given object can not be cast to </font><font
color="#3f3fbf">{@link CDOObject} </font><font
color="#3f5fbf">it is returned unmodified.</font><br>
<font color="#ffffff"> </font><font color="#3f5fbf">* </font><font
color="#7f7f9f"><li></font><font color="#3f5fbf">If the view of the given object is contained in a different session an </font><font
color="#7f7f9f"><code></font><font
color="#3f5fbf">IllegalArgumentException</font><font
color="#7f7f9f"></code> </font><font
color="#3f5fbf">is</font><br>
<font color="#ffffff"> </font><font color="#3f5fbf">* thrown.</font><br>
<font color="#ffffff"> </font><font color="#3f5fbf">* </font><font
color="#7f7f9f"><li></font><font color="#3f5fbf">If </font><font
color="#7f7f9f"><code></font><font
color="#3f5fbf">null</font><font color="#7f7f9f"></code> </font><font
color="#3f5fbf">is passed </font><font color="#7f7f9f"><code></font><font
color="#3f5fbf">null</font><font color="#7f7f9f"></code> </font><font
color="#3f5fbf">is returned.</font><br>
<font color="#ffffff"> </font><font color="#3f5fbf">* </font><font
color="#7f7f9f"></ul></font><br>
<font color="#ffffff"> </font><font color="#3f5fbf">*/</font><br>
<font color="#ffffff"> </font><font color="#7f0055"><b>public </b></font><font
color="#000000"><T </font><font color="#7f0055"><b>extends </b></font><font
color="#000000">EObject> T getObject</font><font
color="#000000">(</font><font color="#000000">T objectFromDifferentView</font><font
color="#000000">)</font><font color="#000000">;</font></code>
</td>
<!-- end source code --> </tr>
</tbody>
</table>
</div>
<!-- = END of automatically generated HTML code = -->
<!-- ======================================================== -->
<br>
which you can use to "beam" an existing transactional object back in
time and use the resulting object as a start point for (historical)
model navigation.<br>
<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">
<br>
<blockquote cite="mid:jc1gtl$5rs$1@news.eclipse.org" type="cite">I
think it would be better to have a method like "getAllObject()"
that returns List of object in a given timestamp.
<br>
</blockquote>
That would have two disadvantages:<br>
1) A list of all objects would not scale<br>
2) Historical model access would be incompatible with latest model
access<br>
<br>
<br>
<blockquote cite="mid:jc1gtl$5rs$1@news.eclipse.org" type="cite">In
order to access entire object graph via CDOView i must know the
CDOID of Library instance </blockquote>
You know it because you have a pointer to it in your CDOTransaction.
But the already mentioned <code><font color="#000000">getObject</font><font
color="#000000">(</font><font color="#000000">T objectFromDifferentView</font><font
color="#000000">)</font></code> method is even more convenient.
You can also load the historical resource by getResource(String path)
and navigate from there.<br>
<br>
<blockquote cite="mid:jc1gtl$5rs$1@news.eclipse.org" type="cite">and
then get it by getObject and then get Book instances(Library and
Book have dependency) via Library and so on.
<br>
But how to access the another instances that have not dependency
to Library instance(Again i must know CDOID of that model
instance)?
<br>
</blockquote>
How would you access those in a non-historical view (i.e., a
transaction)?<br>
<br>
<blockquote cite="mid:jc1gtl$5rs$1@news.eclipse.org" type="cite">
<br>
2.I think timestamp is not proper way to get model
instances.Because maybe we do not exactly remember when we
committed our models to repository(so that we do not know
timestamp).
<br>
it would be better to use revision number to get model instances
from repository.
<br>
</blockquote>
The commit timestamp *is* the revision number (in SVN terminology).
It is returned by each commit operation:<br>
<br>
CDOCommitInfo commitInfo1 = transaction.commit();<br>
long t1 = commitInfo1.getTimeStamp();<br>
CDOView view = transaction.getSession().openView(t1);<br>
<br>
<blockquote cite="mid:jc1gtl$5rs$1@news.eclipse.org" type="cite">I
saw a cdo_version column in Library and Book tables,but i do not
know how to play with them to get all object graph in a revision
number(For example revision number 2).
<br>
</blockquote>
CDORevision.getVersion() is *not* the identifier for an entire
commit changeset or a consistent baseline in the repository. It only
has a meaning in the context of a particular object.<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>
</body>
</html>
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
|
Re: [CDO]How to get different revision of a resource? [message #764058 is a reply to message #764049] |
Sun, 11 December 2011 08:10 |
|
Am 11.12.2011 08:45, schrieb Khosro Asgharifard Sharabiani:
> [...]
>> You can also load the historical resource by getResource(String path) and navigate from there.
>
> Oh,I think this is my solution.Maybe this is a good option.Let me try it.
>
>
> At last ,i think CDOView for historical navigation in object graph usage is only when we commit a object to repository
> and in the same time we can use the committed object for navigation.Something like the following code (Am i right?) :
>
> public void InsertAndNavigate() {
> try {
> // CDOUtil.setLegacyModeDefault(true);
>
> Library library = LibraryFactory.eINSTANCE.createLibrary();
> library.setName("OtherThing");
> library.setSYSTEM("Tamin");
>
> library.Book book = LibraryFactory.eINSTANCE.createBook();
> book.setTitle("Java Complete Reference");
> library.getBooks().add(book);
> resource.getContents().add(library);
Ok.
> transaction.commit();
>
> CDOView cdoView = cdoSession.openView();
> cdoView.setTimeStamp(1323531227347L);
Or better:
long commitTime = transaction.commit();
CDOView cdoView = cdoSession.openView(commitTime);
> Library library2 = cdoView.getObject(library);
> // Then navigate on object graph
>
> cdoSession.close();
Superfluous, see finally block below.
>
> } catch (Exception e) {
> e.printStackTrace();
> } finally {
> cdoSession.close();
> }
> }
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Powered by
FUDForum. Page generated in 0.03078 seconds