Eclipse Community Forums
Forum Search:

Search      Help    Register    Login    Home
Home » Modeling » EMF » [CDO] How to preserve database when model changes?
[CDO] How to preserve database when model changes? [message #945721] Mon, 15 October 2012 15:14 Go to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 424
Registered: September 2009
Senior Member
I am quite new o CDO, so I might have overlooked the obvious.

I have a reasonably complex model I'm building (currently 20 classes, but far from being complete).

I did some testing filling one of the lists (and only one) attached to the root element. I was able to read and write to the model with a simple program.

Problem arrived when I added one single EAttribute to the class: I expected to be able to read back the class and find the "new" element null, but that was not the case. trying to get the EList containing my class resulted in an EOF error with the server.
To cure this I had to stop the server, delete the database and reconstruct everything from scratch.

Is this an expected behavior?
Right now it is NOT a problem, but if I get to production and later, for any reason I need to modify the model losing the database won't be an option.
What is the Right Way to do this?

Relevant fragment of the model is:

public interface StudioM extends CDOObject {

...

/**
* @return the value of the '<em>Elenco Comuni</em>' containment reference list.
* @see studiom.StudiomPackage#getStudioM_ElencoComuni()
* @model containment="true"
* @generated
*/
EList<Comune> getElencoComuni();

...

} // StudioM

public interface Comune extends CDOObject {
/**
* @model required="true"
* @generated
*/
String getNome();

/**
* @generated
*/
void setNome(String value);

/**
* @model required="true"
* @generated
*/
String getProvincia(); <----- this is the added field

/**
* @generated
*/
void setProvincia(String value);<----- generated with above

/**
* @model required="true"
* @generated
*/
String getCodice();

/**
* @generated
*/
void setCodice(String value);

/**
* @model required="true"
* @generated
*/
String getCAP();

/**
* @generated
*/
void setCAP(String value);

/**
* @model required="true"
* @generated
*/
String getPrefisso();

/**
* @generated
*/
void setPrefisso(String value);

} // Comune

Test program is very simple:

public class FillComuni {

public static final String REPO_NAME = "repo1";
public static final String RESOURCE_NAME = "/StudioMedico";

public static void main(String[] args) {

Net4jUtil.prepareContainer(IPluginContainer.INSTANCE);
TCPUtil.prepareContainer(IPluginContainer.INSTANCE);
final IConnector connector = (IConnector) IPluginContainer.INSTANCE
.getElement( //
"org.eclipse.net4j.connectors", // Product group
"tcp", // Type
"localhost"); // Description

CDONet4jSessionConfiguration config = CDONet4jUtil
.createNet4jSessionConfiguration();
config.setConnector(connector);
config.setRepositoryName(REPO_NAME);

CDOSession session = config.openNet4jSession();

session.addListener(new LifecycleEventAdapter() {
@Override
protected void onDeactivated(ILifecycle lifecycle) {
connector.close();
}
});


CDOTransaction transaction = session.openTransaction();

StudiomPackage.eINSTANCE.getClass();

Resource resource = transaction.getOrCreateResource(RESOURCE_NAME);
StudioM studio = null;
for (EObject eo : resource.getContents()) {
if (eo instanceof StudioM) {
studio = (StudioM) eo;
break;
}
}
if (studio == null) {

...

Once I added the EAttribute "provincia" I consistently got a
fatal error (EOF on socket) at "resource.getContents()".

Help, please!

Mauro
Re: [CDO] How to preserve database when model changes? [message #946536 is a reply to message #945721] Tue, 16 October 2012 06:39 Go to previous messageGo to next message
Eike Stepper is currently offline Eike StepperFriend
Messages: 5590
Registered: July 2009
Senior Member
Hi Mauro,

Automatic model evolution (or schema migration) is not yet supported in CDO:

256856: Support model evolution
https://bugs.eclipse.org/bugs/show_bug.cgi?id=256856

It would be a major effort and noone has stepped up, yet, to fund it ;-(

This forum already has several threads (search for, e.g., "evolution") that give hints how to cope (not Edapt :P ) with
this situation now.

Cheers
/Eike

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



Am 15.10.2012 17:14, schrieb Mauro Condarelli:
> I am quite new o CDO, so I might have overlooked the obvious.
>
> I have a reasonably complex model I'm building (currently 20 classes, but far from being complete).
>
> I did some testing filling one of the lists (and only one) attached to the root element. I was able to read and write to the model with a simple program.
>
> Problem arrived when I added one single EAttribute to the class: I expected to be able to read back the class and find the "new" element null, but that was not the case. trying to get the EList containing my class resulted in an EOF error with the server.
> To cure this I had to stop the server, delete the database and reconstruct everything from scratch.
>
> Is this an expected behavior?
> Right now it is NOT a problem, but if I get to production and later, for any reason I need to modify the model losing the database won't be an option.
> What is the Right Way to do this?
>
> Relevant fragment of the model is:
>
> public interface StudioM extends CDOObject {
>
> ...
>
> /**
> * @return the value of the '<em>Elenco Comuni</em>' containment reference list.
> * @see studiom.StudiomPackage#getStudioM_ElencoComuni()
> * @model containment="true"
> * @generated
> */
> EList<Comune> getElencoComuni();
>
> ...
>
> } // StudioM
>
> public interface Comune extends CDOObject {
> /**
> * @model required="true"
> * @generated
> */
> String getNome();
>
> /**
> * @generated
> */
> void setNome(String value);
>
> /**
> * @model required="true"
> * @generated
> */
> String getProvincia(); <----- this is the added field
>
> /**
> * @generated
> */
> void setProvincia(String value);<----- generated with above
>
> /**
> * @model required="true"
> * @generated
> */
> String getCodice();
>
> /**
> * @generated
> */
> void setCodice(String value);
>
> /**
> * @model required="true"
> * @generated
> */
> String getCAP();
>
> /**
> * @generated
> */
> void setCAP(String value);
>
> /**
> * @model required="true"
> * @generated
> */
> String getPrefisso();
>
> /**
> * @generated
> */
> void setPrefisso(String value);
>
> } // Comune
>
> Test program is very simple:
>
> public class FillComuni {
>
> public static final String REPO_NAME = "repo1";
> public static final String RESOURCE_NAME = "/StudioMedico";
>
> public static void main(String[] args) {
>
> Net4jUtil.prepareContainer(IPluginContainer.INSTANCE);
> TCPUtil.prepareContainer(IPluginContainer.INSTANCE);
> final IConnector connector = (IConnector) IPluginContainer.INSTANCE
> .getElement( //
> "org.eclipse.net4j.connectors", // Product group
> "tcp", // Type
> "localhost"); // Description
>
> CDONet4jSessionConfiguration config = CDONet4jUtil
> .createNet4jSessionConfiguration();
> config.setConnector(connector);
> config.setRepositoryName(REPO_NAME);
>
> CDOSession session = config.openNet4jSession();
>
> session.addListener(new LifecycleEventAdapter() {
> @Override
> protected void onDeactivated(ILifecycle lifecycle) {
> connector.close();
> }
> });
>
>
> CDOTransaction transaction = session.openTransaction();
>
> StudiomPackage.eINSTANCE.getClass();
>
> Resource resource = transaction.getOrCreateResource(RESOURCE_NAME);
> StudioM studio = null;
> for (EObject eo : resource.getContents()) {
> if (eo instanceof StudioM) {
> studio = (StudioM) eo;
> break;
> }
> }
> if (studio == null) {
>
> ...
>
> Once I added the EAttribute "provincia" I consistently got a
> fatal error (EOF on socket) at "resource.getContents()".
>
> Help, please!
>
> Mauro
Re: [CDO] How to preserve database when model changes? [message #946581 is a reply to message #946536] Tue, 16 October 2012 10:06 Go to previous messageGo to next message
Mauro Condarelli is currently offline Mauro CondarelliFriend
Messages: 424
Registered: September 2009
Senior Member
Hi Eike,
thanks a lot for Your answer.
If I understand correctly the current state this seems a show-stopper.

My model *will* evolve in the future, even if I can try to think ahead
now. I can limit changes to Column and Table addition (no change in the
already existing ones), but having to do explicit database migration
every time is a burden I don't think I can allow.

It looks like I will have to go back to straight JDBC :(

Regards
Mauro

On 16/10/2012 08:39, Eike Stepper wrote:
> Hi Mauro,
>
> Automatic model evolution (or schema migration) is not yet supported in
> CDO:
>
> 256856: Support model evolution
> https://bugs.eclipse.org/bugs/show_bug.cgi?id=256856
>
> It would be a major effort and noone has stepped up, yet, to fund it ;-(
>
> This forum already has several threads (search for, e.g., "evolution")
> that give hints how to cope (not Edapt :P ) with this situation now.
>
> Cheers
> /Eike
Re: [CDO] How to preserve database when model changes? [message #946637 is a reply to message #946581] Tue, 16 October 2012 11:07 Go to previous message
Eike Stepper is currently offline Eike StepperFriend
Messages: 5590
Registered: July 2009
Senior Member
Am 16.10.2012 12:06, schrieb Mauro Condarelli:
> Hi Eike,
> thanks a lot for Your answer.
> If I understand correctly the current state this seems a show-stopper.
>
> My model *will* evolve in the future, even if I can try to think ahead
> now. I can limit changes to Column and Table addition (no change in the
> already existing ones), but having to do explicit database migration
> every time is a burden I don't think I can allow.
>
> It looks like I will have to go back to straight JDBC :(
If you search this forum you should find CDO server exports and imports that can really help with model evolution now.
It's nastier than a fully automatic mechanism but it's scalable and the XML export format is very simple.

Cheers
/Eike

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


>
> Regards
> Mauro
>
> On 16/10/2012 08:39, Eike Stepper wrote:
>> Hi Mauro,
>>
>> Automatic model evolution (or schema migration) is not yet supported in
>> CDO:
>>
>> 256856: Support model evolution
>> https://bugs.eclipse.org/bugs/show_bug.cgi?id=256856
>>
>> It would be a major effort and noone has stepped up, yet, to fund it ;-(
>>
>> This forum already has several threads (search for, e.g., "evolution")
>> that give hints how to cope (not Edapt :P ) with this situation now.
>>
>> Cheers
>> /Eike
Previous Topic:CDO Serverv. 2.0 and Embedded Derby setup
Next Topic:[CDO] really removing a DB record
Goto Forum:
  


Current Time: Sun Dec 21 14:28:14 GMT 2014

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

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