Skip to main content



      Home
Home » Modeling » EMF » [CDO] commit in EmbeddedRepositoryExample
[CDO] commit in EmbeddedRepositoryExample [message #1868880] Wed, 24 July 2024 07:45 Go to next message
Eclipse UserFriend
Hello,

In the EmbeddedRepositoryExample, I made some modifications to the main function, as follows:
 
 CDOTransaction transaction = CDOFacade.INSTANCE.getTransaction();
      CDOResource resource = transaction.getOrCreateResource("test1");

      Company company = CompanyFactory.eINSTANCE.createCompany();
      company.setName("Company 1");

      resource.getContents().add(company);
      transaction.commit();

      company.setName("Company 2");

      for (EObject object : resource.getContents())
      {
        if (object instanceof Company)
        {
          System.out.println(((Company)object).getName());
        }
      }

      CDOResource resource2 = transaction.getOrCreateResource("test1");

      for (EObject object : resource2.getContents())
      {
        if (object instanceof Company)
        {
          System.out.println(((Company)object).getName());
        }
      }


In this code, I changed the company name after the commit. However, when I retrieve the CDO resource again, the modification of the name is reflected. I was expecting that the modification would not be reflected because it occurred after the commit. Here is my output:
Company 2
Company 2

I use the release 4.25 of CDO
Re: [CDO] commit in EmbeddedRepositoryExample [message #1868886 is a reply to message #1868880] Wed, 24 July 2024 09:15 Go to previous messageGo to next message
Eclipse UserFriend
Have you checked if "resource == resource2"? After all, the method is called getOrCreate so I would personally expect to get the same one back on a subsequent call on the same transaction.
Re: [CDO] commit in EmbeddedRepositoryExample [message #1868889 is a reply to message #1868886] Wed, 24 July 2024 09:39 Go to previous messageGo to next message
Eclipse UserFriend
Ed Merks wrote on Wed, 24 July 2024 13:15
Have you checked if "resource == resource2"?


Yes, i check resource = resource2

Ed Merks wrote on Wed, 24 July 2024 13:15
After all, the method is called getOrCreate so I would personally expect to get the same one back on a subsequent call on the same transaction.


How can i have the resource stored (commited) in the database when i do getOrCreateResource() ?
Re: [CDO] commit in EmbeddedRepositoryExample [message #1868892 is a reply to message #1868889] Wed, 24 July 2024 10:32 Go to previous messageGo to next message
Eclipse UserFriend
I don't think that org.eclipse.emf.cdo.examples.embedded.CDOFacade is designed for that purpose. You can look at the implementation to see how it creates a transaction; I assume you'll need to create a new transaction rather than reusing the one transaction with the one resource set and one session wrapped by that facade example. (I'm don't know much about the implementation details; I'm just looking at the sources.)
Re: [CDO] commit in EmbeddedRepositoryExample [message #1868988 is a reply to message #1868880] Sat, 27 July 2024 08:53 Go to previous messageGo to next message
Eclipse UserFriend
When you open a model through a transaction and then modify the model, these modifications are locally remembered inside that transaction until you either roll it back or commit it.

If you want a "clean" view on the same model, you can open a separate view or transaction on the same session, or open an entirely new session. The first approach is much cheaper, though.
Re: [CDO] commit in EmbeddedRepositoryExample [message #1869006 is a reply to message #1868880] Mon, 29 July 2024 05:03 Go to previous message
Eclipse UserFriend
Thank you for your answers. I will open a separate transaction.

[Updated on: Mon, 29 July 2024 05:04] by Moderator

Previous Topic:Issue Generating Java Code Programmatically from Ecore Model Using Gen Model
Next Topic:[CDO] Configure release conditions for cached objects
Goto Forum:
  


Current Time: Fri Jun 13 05:30:53 EDT 2025

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

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

Back to the top