Skip to main content


Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] How to manually create DDL for schema updates?
[CDO] How to manually create DDL for schema updates? [message #1809646] Fri, 19 July 2019 09:39 Go to next message
Linuxhippy Mising name is currently offline Linuxhippy Mising nameFriend
Messages: 36
Registered: July 2009
Member
Hi,

I am currently migrating from CDO-4.5 to the latest available weekly build (may 2019) and so far the migration has been progressing very smooth.
The only real show-stopper left is generating DDL off-line for manually patching the production systems (automatic schema migration performed by CDO is not an option there).

The application has code which worked for CDO 4.5 and looks like:
IDBSchemaTransaction schemaTransaction = ((DBStore) store).getDatabase().openSchemaTransaction();
IDBSchema schema = ((DBStore) store).getDatabase().getSchema();
			((InternalDBSchema) schema).unlock();

IMappingStrategy mappingStrategy = ((DBStore) store).getMappingStrategy();
EList<EClassifier> eClassifiers = emfPackage.getEClassifiers();

for (EClassifier eClassifier : eClassifiers) {
	if (eClassifier instanceof EClass && !((EClass) eClassifier).isInterface()
							&& !((EClass) eClassifier).isAbstract()) {
						// required to initalize als mappings
						IClassMapping mapping = mappingStrategy.getClassMapping((EClass) eClassifier);
.......

IDBSchemaDelta schemaDelta = schemaTransaction.getSchemaDelta();
//manually generate schema using the delta



However in the latest CDO-Version SchemaTransaction.ensureSchema is called as soon as adding a Repository - furthermorethe the policy used doesn't seem to be configureable (DEFAULT_ENSURE_SCHEMA_POLICY is final and frozen).
In my case a lot of changes are detected (seem to be mostly "remove"-changes - please see the file attached) but discarded because of the default policy - yet ensureSchema applies the delta to the on-memory representation and later on calls to getSchemaDelta() return no delta at all.

Furthermore, because the schema stays unchanged, I later get NPEs accessing attributes that were added:
Caused by: java.lang.NullPointerException
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractHorizontalClassMapping.readValuesFromResultSet(AbstractHorizontalClassMapping.java:486)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.AbstractHorizontalClassMapping.readValuesFromStatement(AbstractHorizontalClassMapping.java:413)
	at org.eclipse.emf.cdo.server.internal.db.mapping.horizontal.HorizontalAuditClassMapping.readRevision(HorizontalAuditClassMapping.java:309)
	at org.eclipse.emf.cdo.server.internal.db.DBStoreAccessor.readRevision(DBStoreAccessor.java:269)
	at org.eclipse.emf.cdo.internal.server.Repository.loadRevisions(Repository.java:571)


Could you think of a sane way how to generate the DDL off-line?
And is there a way to change the policy used by ensureSchema when called during initialization to also support (this way I could wrap a java.sql.Connection and at least dump the generated SQL to a file)?

As always thank you very much in advance.

Best regards, Clemens

[Updated on: Fri, 19 July 2019 09:41]

Report message to a moderator

Re: [CDO] How to manually create DDL for schema updates? [message #1809667 is a reply to message #1809646] Fri, 19 July 2019 15:04 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6457
Registered: July 2009
Senior Member
Can't you start the repository with the new metamodel on an empty schema/db?

When you manually copy the old rows/values into the new schema pay attention to at least two things:

1) Make sure the column CDO_OBJECTS.CDO_CLASS points to the right rows in CDO_EXTERNAL_REFS.ID
2) Make sure that the CDO_FEATURE columns in your attribute tables contain the result of InternalEObject.eContainerFeatureID()


Re: [CDO] How to manually create DDL for schema updates? [message #1809668 is a reply to message #1809667] Fri, 19 July 2019 15:06 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6457
Registered: July 2009
Senior Member
BTW. I know that some CDO users use https://flywaydb.org/ to assist their model migration.

Re: [CDO] How to manually create DDL for schema updates? [message #1809675 is a reply to message #1809668] Fri, 19 July 2019 17:53 Go to previous messageGo to next message
Linuxhippy Mising name is currently offline Linuxhippy Mising nameFriend
Messages: 36
Registered: July 2009
Member
Hi Eike,

Thank you so much for again taking the time answering questions.

> Can't you start the repository with the new metamodel on an empty schema/db?
I can only diff against an existing one to extract the DDL - in fact I do (officially) not even have access to the production databse.

Is there any way to omit (or redo) the ensureSchema() call during initialization, so I can query the schema delta using SchemaTransaction.getSchemaDelta() like it was possible with previous versions of CDO?

Best regards, Clemens
Re: [CDO] How to manually create DDL for schema updates? [message #1809682 is a reply to message #1809675] Sat, 20 July 2019 07:02 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 6457
Registered: July 2009
Senior Member
Hi Clemens,

I see, you don't want to generate the DDL for the new schema, but for the delta between old and new schema, right?

The ensureSchema() call in DBStore.doActivate() only makes sure that CDO's system tables exist, as defined by CDODBSchema.INSTANCE. As you found out, the attribute and list tables of the mapped EClasses are created lazily by default, see AbstractHorizontalClassMapping and XyzListTableWithRanges. You can create those tables eagerly with <property name="eagerTableCreation" value="true"/> under the <mappingStrategy> element in cdo-server.xml. You may also want to use the <initialPackage> element under the <repository> element, see the example in cdo-server.xml.

You can generate your DLL for IDBSchemaDeltas with the following code:

    database.addListener(new IListener()
    {
      public void notifyEvent(IEvent event)
      {
        if (event instanceof SchemaChangedEvent)
        {
          SchemaChangedEvent e = (SchemaChangedEvent)event;
          IDBSchemaDelta schemaDelta = e.getSchemaDelta();
          System.out.println(schemaDelta);

          // Manually generate schema using the delta...
        }
      }
    });


Unfortunately at the moment I see no way to add this listener right after the database instance is created, so you can only patch DBStore.doActivate(). I can add a respective hook if you submit a bugzilla. I can probably also find a way then to customize the IDBDeltaVisitor.Filter.Policy for IDBSchemaTransaction.ensureSchema(IDBSchema).


Re: [CDO] How to manually create DDL for schema updates? [message #1809738 is a reply to message #1809682] Mon, 22 July 2019 08:47 Go to previous message
Linuxhippy Mising name is currently offline Linuxhippy Mising nameFriend
Messages: 36
Registered: July 2009
Member
Hello Eike,

Quote:

You can create those tables eagerly with <property name="eagerTableCreation" value="true"/> under the <mappingStrategy> element in cdo-server.xml.


Thanks for this tip - definitivly better than to trigger lazy creation by accessing it manually.

Quote:

Unfortunately at the moment I see no way to add this listener right after the database instance is created, so you can only patch DBStore.doActivate(). I can add a respective hook if you submit a bugzilla. I can probably also find a way then to customize the IDBDeltaVisitor.Filter.Policy for IDBSchemaTransaction.ensureSchema(IDBSchema).


That would be really awesome - I've create two bugzilla entries:
https://bugs.eclipse.org/bugs/show_bug.cgi?id=549452
https://bugs.eclipse.org/bugs/show_bug.cgi?id=549453

Thanks a lot & best regards, Clemens
Previous Topic:Query an EMF model with QVTo
Next Topic:Get IllegalValueException when opening model with Ecore Model Editor
Goto Forum:
  


Current Time: Mon Dec 09 20:40:36 GMT 2019

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

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

Back to the top