Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] How to import/apply CDOChangeSetData
[CDO] How to import/apply CDOChangeSetData [message #1603962] Fri, 06 February 2015 14:40 Go to next message
Johannes Schaefer is currently offline Johannes SchaeferFriend
Messages: 6
Registered: October 2014
Junior Member
Hi,

I trying to persist the changed data after changing a model and apply these data to an other model in CDO.

Here is the code to persist the changes
        CDOSession session = getSession();
        CDOTransaction tx = session.openTransaction();
        CDOResource res = tx.getOrCreateResource( "JsCdoTest1" );
        
        // changing the model
        removeElements( res.getContents(), 5 );
        changeElements( res.getContents(), 5 );
        addElements( res.getContents(), 5 );
        
        // getting the changed data
        CDOChangeSetData changeSetData = tx.getChangeSetData();
        
        // persisting the data
        OutputStream outstream = new FileOutputStream( new File( "test.txt" ) );
        ExtendedDataOutput edoutstream = new ExtendedDataOutputStream( outstream );
        CDODataOutput out = CDOCommonUtil.createCDODataOutput( edoutstream, session.getPackageRegistry(), (CDOIDProvider)tx );
        out.writeCDOChangeSetData( changeSetData );
        System.out.println( changeSetData );


Now I'm trying to apply these to an existing model in CDO, but I don't find the correct API.
        CDOSession session = getSession();
        CDOTransaction tx = session.openTransaction();
        CDOResource res = tx.getOrCreateResource( "JsCdoTest1" );
        
        // read the change set
        FileInputStream instream = new FileInputStream( new File( "test.txt" ) );
        ExtendedDataInputStream edinstream = new ExtendedDataInputStream( instream );
        CDODataInput dataInput = CDOCommonUtil.createCDODataInput( edinstream, session.getPackageRegistry(), session.getBranchManager(), 
            session.getCommitInfoManager(), CDORevisionFactory.DEFAULT, CDOListFactory.DEFAULT, ((InternalCDOSession)session).getLobStore() );
        CDOChangeSetData changeSetData = dataInput.readCDOChangeSetData();
        System.out.println( changeSetData );


So how can I apply changeSetData to my transaction?

Thanks for your answers.
Johannes.
Re: [CDO] How to import/apply CDOChangeSetData [message #1604012 is a reply to message #1603962] Fri, 06 February 2015 15:16 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6433
Registered: July 2009
Senior Member
Hi Johannes,

The following API methods have are provided to export changes and apply them later to the same model (IIRC, the CDOIDs
must match):

org.eclipse.emf.cdo.transaction.CDOTransaction.exportChanges(OutputStream)
org.eclipse.emf.cdo.transaction.CDOTransaction.importChanges(InputStream, boolean)

Is that what you're looking for? Maybe you're also interested in org.eclipse.emf.cdo.transaction.CDOPushTransaction,
which makes use of the aforementioned methods.

Cheers
/Eike

----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper


Am 06.02.2015 um 15:40 schrieb Johannes Schaefer:
> Hi,
>
> I trying to persist the changed data after changing a model and apply these data to an other model in CDO.
>
> Here is the code to persist the changes
> CDOSession session = getSession();
> CDOTransaction tx = session.openTransaction();
> CDOResource res = tx.getOrCreateResource( "JsCdoTest1" );
> // changing the model
> removeElements( res.getContents(), 5 );
> changeElements( res.getContents(), 5 );
> addElements( res.getContents(), 5 );
> // getting the changed data
> CDOChangeSetData changeSetData = tx.getChangeSetData();
> // persisting the data
> OutputStream outstream = new FileOutputStream( new File( "test.txt" ) );
> ExtendedDataOutput edoutstream = new ExtendedDataOutputStream( outstream );
> CDODataOutput out = CDOCommonUtil.createCDODataOutput( edoutstream, session.getPackageRegistry(),
> (CDOIDProvider)tx );
> out.writeCDOChangeSetData( changeSetData );
> System.out.println( changeSetData );
>
> Now I'm trying to apply these to an existing model in CDO, but I don't find the correct API.
> CDOSession session = getSession();
> CDOTransaction tx = session.openTransaction();
> CDOResource res = tx.getOrCreateResource( "JsCdoTest1" );
> // read the change set
> FileInputStream instream = new FileInputStream( new File( "test.txt" ) );
> ExtendedDataInputStream edinstream = new ExtendedDataInputStream( instream );
> CDODataInput dataInput = CDOCommonUtil.createCDODataInput( edinstream, session.getPackageRegistry(),
> session.getBranchManager(), session.getCommitInfoManager(), CDORevisionFactory.DEFAULT, CDOListFactory.DEFAULT,
> ((InternalCDOSession)session).getLobStore() );
> CDOChangeSetData changeSetData = dataInput.readCDOChangeSetData();
> System.out.println( changeSetData );
>
> So how can I apply changeSetData to my transaction?
>
> Thanks for your answers.
> Johannes.


Re: [CDO] How to import/apply CDOChangeSetData [message #1604116 is a reply to message #1604012] Fri, 06 February 2015 16:47 Go to previous message
Johannes Schaefer is currently offline Johannes SchaeferFriend
Messages: 6
Registered: October 2014
Junior Member
Hi Eike,

exportChanges and importChanges looks interesting. But actually doesn't work for me Sad .
Here are my tests:
    @Test
    public final void testApplyDiffFile2() throws IOException, ConcurrentAccessException, CommitException 
    {
        CDOSession session = getSession();
        CDOTransaction tx = session.openTransaction();

        System.out.println( "has conflicts: " + tx.hasConflict() );

        // read the change set
        FileInputStream instream = new FileInputStream( new File( "test.txt" ) );
        tx.importChanges( instream, true );
        instream.close();

        System.out.println( "has conflicts: " + tx.hasConflict() );
        for( CDOObject conf : tx.getConflicts() )
        {
            System.out.println( conf );
        }

        // commit the changes
        tx.commit();
        
        session.close();
    }

    @Test
    public final void testCreateDiffFile2() throws ConcurrentAccessException, CommitException, IOException
    {
        CDOSession session = getSession();
        CDOTransaction tx = session.openTransaction();
        CDOResource res = tx.getResource( "JsCdoTest1" );
        
        // changing the model
        removeElements( res.getContents(), 5 );
//        changeElements( res.getContents(), 1 );
//        addElements( res.getContents(), 1 );
        
        
        // persisting the data
        OutputStream outstream = new FileOutputStream( new File( "test.txt" ) );
        tx.exportChanges( outstream );
        outstream.close();
        
        // commit the changes
        tx.commit();
        
        session.close();
    }


When I try to add or remove elements, I get the following exception when I try to import the changes:
org.eclipse.emf.cdo.util.LocalCommitConflictException: This transaction has conflicts
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.commitSynced(CDOTransactionImpl.java:1205)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.commit(CDOTransactionImpl.java:1184)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.commit(CDOTransactionImpl.java:1176)
	at de.psi.metals.cdotest1.CdoTest1.testApplyDiffFile2(CdoTest1.java:116)


When I try to change a existing model element I get the following:
org.eclipse.emf.cdo.util.ObjectNotFoundException: Object _exlqwK4fEeSJ2tysTMRtgg not found in branch 0 at *
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.createObject(AbstractCDOView.java:1097)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.getObject(AbstractCDOView.java:993)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.getObject(CDOTransactionImpl.java:1152)
	at org.eclipse.emf.internal.cdo.view.AbstractCDOView.getObject(AbstractCDOView.java:940)
	at org.eclipse.emf.internal.cdo.transaction.CDOTransactionImpl.importChanges(CDOTransactionImpl.java:2170)
	at de.psi.metals.cdotest1.CdoTest1.testApplyDiffFile2(CdoTest1.java:106)


The status of the transaction after the import is conflicted, but there are no conflicts in the list.
Before each test I clear the resource (res.getContents().clear()) and add the same class structure.

Any ideas?

Regards,
Johannes.

[Updated on: Fri, 06 February 2015 16:48]

Report message to a moderator

Previous Topic:EMF + RAP starts but does not show
Next Topic:[CDO] Security Manager and Branches
Goto Forum:
  


Current Time: Wed May 22 11:36:54 GMT 2019

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

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

Back to the top