Home » Modeling » EMF » CDO server and client usage
CDO server and client usage [message #426084] |
Tue, 16 December 2008 08:33 |
Toni Messages: 5 Registered: July 2009 |
Junior Member |
|
|
Hi, I've to create a CDO server and store inside it metamodels ecore
compliant and models created starting from previous metamodels. I've
created using code and following examples on eclipse site a CDO server.
I've used the code below for launch it,and it seems run.
public class TestCdoServerOk {
private static final String DATABASE = "c:\\test\\cdotest";
public static void main(String[] args) throws Exception {
OMPlatform.INSTANCE.setDebugging(true);
OMPlatform.INSTANCE .addLogHandler(org.eclipse.net4j.util.om.log.PrintLogHandler .CONSOLE);
OMPlatform.INSTANCE .addTraceHandler(org.eclipse.net4j.util.om.trace.PrintTraceH andler.CONSOLE);
IManagedContainer container = ContainerUtil.createContainer();
Net4jUtil.prepareContainer(container);
TCPUtil.prepareContainer(container);
CDOServerUtil.prepareContainer(container);
LifecycleUtil.activate(container);
// prepare store parameters
IMappingStrategy strategy = CDODBUtil.createHorizontalMappingStrategy();
Map<String, String> mappingProps = new HashMap<String, String>();
mappingProps.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPP ING,
"MODEL");
mappingProps.put(MappingStrategy.PROP_TO_ONE_REFERENCE_MAPPI NG,
"LIKE_ATTRIBUTES");
mappingProps.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPP ING,
"ONE_TABLE_PER_REFERENCE");
strategy.setProperties(mappingProps);
IDBAdapter adapter = new EmbeddedDerbyAdapter();
DataSource dataSource = createEmbeddedDataSource(DATABASE);
// DataSource dataSource = createClientDataSource(DATABASE);
IDBConnectionProvider provider = DBUtil
.createConnectionProvider(dataSource);
// Create a DBStore
IDBStore store = CDODBUtil.createStore(strategy, adapter, provider);
strategy.setStore(store);
// Create a repository
Map<String, String> props = new HashMap<String, String>();
props.put(Props.PROP_SUPPORTING_AUDITS, "true");
props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");// true does
// not work
// for
// DBStore
props.put(Props.PROP_VERIFYING_REVISIONS, "false");
props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
//ITCPAcceptor tcpAcceptor =
TCPUtil.getAcceptor(container,"0.0.0.0:2036");
IRepository repository = CDOServerUtil.createRepository("repo1", store,
props);
CDOServerUtil.addRepository(container, repository);
container.getElement("org.eclipse.net4j.acceptors", "tcp", null);
}
After that I've try to crate a client that read from the filesystem an
*.ecore file and store it inside the database. I've used the following
code:
public class ClientCDO {
public static void main(String[] argj){
IManagedContainer container = ContainerUtil.createContainer();
IConnector connector;
Net4jUtil.prepareContainer(container);
CDOUtil.prepareContainer(container, true);
IAcceptor acceptor = null;
int kind =0;
if (kind == 0) {
TCPUtil.prepareContainer(container);
// Start the TCP transport
acceptor = TCPUtil.getAcceptor(container, "127.0.0.1:2036");
// Open a TCP connection
connector = TCPUtil.getConnector(container,"127.0.0.1:2036");
} else {
JVMUtil.prepareContainer(container);
// Start the JVM transport
acceptor = JVMUtil.getAcceptor(container, "default");
// Open a JVM connection
connector = JVMUtil.getConnector(container, "default");
}
// Create configuration
CDOSessionConfiguration configuration =
CDOUtil.createSessionConfiguration();
configuration.setConnector(connector);
configuration.setRepositoryName("repo1");
// Open session
CDOSession session = configuration.openSession();
session.getPackageRegistry().putEPackage(Model1Package.eINST ANCE);
// Open transaction
CDOTransaction transaction = session.openTransaction();
System.out.println("prima di creare la risorsa");
// Get or create resource
CDOResource resource =
transaction.createResource("c:/test/test.ecore");
System.out.println("risorsa creata");
// Work with the resource and commit the transaction
//EObject object = Model1Factory.eINSTANCE.createCompany();
//resource.getContents().add(object);
transaction.commit();
System.out.println("dopo commit");
// Cleanup
transaction.close();
session.close();
connector.disconnect();
}
}
When I run the client the following exception appears:
[ERROR] SQL Exception: Column 'PATH' cannot accept a NULL value.
org.eclipse.net4j.db.DBException: SQL Exception: Column 'PATH' cannot
accept a NULL value.
at
org.eclipse.emf.cdo.server.internal.db.ClassMapping.sqlUpdat e(ClassMapping.java:178)
at
org.eclipse.emf.cdo.server.internal.db.ClassMapping.writeAtt ributes(ClassMapping.java:494)
at
org.eclipse.emf.cdo.server.internal.db.ClassMapping.writeRev ision(ClassMapping.java:450)
at
org.eclipse.emf.cdo.server.internal.db.HorizontalClassMappin g.writeRevision(HorizontalClassMapping.java:37)
at
org.eclipse.emf.cdo.server.internal.db.DBStoreWriter.writeRe vision(DBStoreWriter.java:201)
at
org.eclipse.emf.cdo.internal.server.StoreAccessor.writeRevis ions(StoreAccessor.java:197)
at
org.eclipse.emf.cdo.internal.server.StoreAccessor.commit(Sto reAccessor.java:116)
at
org.eclipse.emf.cdo.server.internal.db.DBStoreWriter.commit( DBStoreWriter.java:52)
at
org.eclipse.emf.cdo.internal.server.Transaction.commit(Trans action.java:181)
at
org.eclipse.emf.cdo.internal.server.protocol.CommitTransacti onIndication.indicating(CommitTransactionIndication.java:109 )
at
org.eclipse.net4j.signal.IndicationWithResponse.execute(Indi cationWithResponse.java:46)
at org.eclipse.net4j.signal.Signal.runSync(Signal.java:143)
at org.eclipse.net4j.signal.Signal.run(Signal.java:124)
at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unkno wn Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at java.lang.Thread.run(Unknown Source)
Caused by: SQL Exception: Column 'PATH' cannot accept a NULL value.
at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unkno wn Source)
at
org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQL Exception(Unknown
Source)
at
org.apache.derby.impl.jdbc.TransactionResourceImpl.handleExc eption(Unknown
Source)
at org.apache.derby.impl.jdbc.EmbedConnection.handleException(U nknown
Source)
at org.apache.derby.impl.jdbc.ConnectionChild.handleException(U nknown
Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(U nknown
Source)
at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unkn own Source)
at
org.eclipse.emf.cdo.server.internal.db.ClassMapping.sqlUpdat e(ClassMapping.java:174)
... 15 more
Can anybody help me? This is the way for store a model or metamodel
starting from a file or I'm totally wrong!?
Thanks for the support!
Toni
|
|
|
Re: CDO server and client usage [message #426090 is a reply to message #426084] |
Tue, 16 December 2008 09:43 |
|
Toni,
Comments below...
Toni schrieb:
> Hi, I've to create a CDO server and store inside it metamodels ecore
> compliant and models created starting from previous metamodels. I've
> created using code and following examples on eclipse site a CDO
> server. I've used the code below for launch it,and it seems run.
>
> public class TestCdoServerOk {
> private static final String DATABASE = "c:\\test\\cdotest";
> public static void main(String[] args) throws Exception {
> OMPlatform.INSTANCE.setDebugging(true);
> OMPlatform.INSTANCE
> .addLogHandler(org.eclipse.net4j.util.om.log.PrintLogHandler .CONSOLE);
> OMPlatform.INSTANCE
> .addTraceHandler(org.eclipse.net4j.util.om.trace.PrintTraceH andler.CONSOLE);
>
Don't forget to disable console tracing in production. It consumes
between 30% and 50% of the overall load!
>
> IManagedContainer container = ContainerUtil.createContainer();
> Net4jUtil.prepareContainer(container);
> TCPUtil.prepareContainer(container);
> CDOServerUtil.prepareContainer(container);
> LifecycleUtil.activate(container);
>
> // prepare store parameters
> IMappingStrategy strategy =
> CDODBUtil.createHorizontalMappingStrategy();
>
> Map<String, String> mappingProps = new HashMap<String, String>();
> mappingProps.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPP ING,
> "MODEL");
This is wrong, but overwritten two calls below.
> mappingProps.put(MappingStrategy.PROP_TO_ONE_REFERENCE_MAPPI NG,
> "LIKE_ATTRIBUTES");
> mappingProps.put(MappingStrategy.PROP_TO_MANY_REFERENCE_MAPP ING,
> "ONE_TABLE_PER_REFERENCE");
>
>
> strategy.setProperties(mappingProps);
>
> IDBAdapter adapter = new EmbeddedDerbyAdapter();
>
> DataSource dataSource = createEmbeddedDataSource(DATABASE);
> // DataSource dataSource = createClientDataSource(DATABASE);
> IDBConnectionProvider provider = DBUtil
> .createConnectionProvider(dataSource);
>
> // Create a DBStore
> IDBStore store = CDODBUtil.createStore(strategy, adapter,
> provider);
> strategy.setStore(store);
>
> // Create a repository
> Map<String, String> props = new HashMap<String, String>();
> props.put(Props.PROP_SUPPORTING_AUDITS, "true");
> props.put(Props.PROP_SUPPORTING_REVISION_DELTAS, "false");//
> true does
> //
> not work
> //
> for
> //
> DBStore
> props.put(Props.PROP_VERIFYING_REVISIONS, "false");
> props.put(Props.PROP_CURRENT_LRU_CAPACITY, "10000");
> props.put(Props.PROP_REVISED_LRU_CAPACITY, "10000");
>
> //ITCPAcceptor tcpAcceptor =
> TCPUtil.getAcceptor(container,"0.0.0.0:2036");
> IRepository repository =
> CDOServerUtil.createRepository("repo1", store,
> props);
> CDOServerUtil.addRepository(container, repository);
>
> container.getElement("org.eclipse.net4j.acceptors", "tcp", null);
>
> }
>
> After that I've try to crate a client that read from the filesystem an
> *.ecore file and store it inside the database. I've used the following
> code:
>
> public class ClientCDO {
> public static void main(String[] argj){
> IManagedContainer container = ContainerUtil.createContainer();
>
> IConnector connector;
>
> Net4jUtil.prepareContainer(container);
> CDOUtil.prepareContainer(container, true);
> IAcceptor acceptor = null;
> int kind =0;
> if (kind == 0) {
> TCPUtil.prepareContainer(container);
>
> // Start the TCP transport
> acceptor = TCPUtil.getAcceptor(container, "127.0.0.1:2036");
You should not start an TCP acceptor on the client!!
>
>
> // Open a TCP connection
> connector = TCPUtil.getConnector(container,"127.0.0.1:2036");
> } else {
>
> JVMUtil.prepareContainer(container);
>
> // Start the JVM transport
> acceptor = JVMUtil.getAcceptor(container, "default");
Here the acceptor would be ok, because client == server ;-)
>
> // Open a JVM connection
> connector = JVMUtil.getConnector(container, "default");
> }
>
> // Create configuration
> CDOSessionConfiguration configuration =
> CDOUtil.createSessionConfiguration();
> configuration.setConnector(connector);
> configuration.setRepositoryName("repo1");
>
> // Open session
> CDOSession session = configuration.openSession();
>
> session.getPackageRegistry().putEPackage(Model1Package.eINST ANCE);
>
> // Open transaction
> CDOTransaction transaction = session.openTransaction();
> System.out.println("prima di creare la risorsa");
> // Get or create resource
> CDOResource resource =
> transaction.createResource("c:/test/test.ecore");
This looks like a problem. The path of the *repository* resource should
not start with "c:". It should start with "/".
If you think we shold have better argument checking here, please file a
bugzilla and mention the CDO version you're using.
> System.out.println("risorsa creata");
> // Work with the resource and commit the transaction
> //EObject object = Model1Factory.eINSTANCE.createCompany();
> //resource.getContents().add(object);
> transaction.commit();
> System.out.println("dopo commit");
> // Cleanup
> transaction.close();
> session.close();
> connector.disconnect();
>
> }
> }
>
> When I run the client the following exception appears: [ERROR] SQL
> Exception: Column 'PATH' cannot accept a NULL value.
> org.eclipse.net4j.db.DBException: SQL Exception: Column 'PATH' cannot
> accept a NULL value.
> at
> org.eclipse.emf.cdo.server.internal.db.ClassMapping.sqlUpdat e(ClassMapping.java:178)
>
> at
> org.eclipse.emf.cdo.server.internal.db.ClassMapping.writeAtt ributes(ClassMapping.java:494)
>
> at
> org.eclipse.emf.cdo.server.internal.db.ClassMapping.writeRev ision(ClassMapping.java:450)
>
> at
> org.eclipse.emf.cdo.server.internal.db.HorizontalClassMappin g.writeRevision(HorizontalClassMapping.java:37)
>
> at
> org.eclipse.emf.cdo.server.internal.db.DBStoreWriter.writeRe vision(DBStoreWriter.java:201)
>
> at
> org.eclipse.emf.cdo.internal.server.StoreAccessor.writeRevis ions(StoreAccessor.java:197)
>
> at
> org.eclipse.emf.cdo.internal.server.StoreAccessor.commit(Sto reAccessor.java:116)
>
> at
> org.eclipse.emf.cdo.server.internal.db.DBStoreWriter.commit( DBStoreWriter.java:52)
>
> at
> org.eclipse.emf.cdo.internal.server.Transaction.commit(Trans action.java:181)
>
> at
> org.eclipse.emf.cdo.internal.server.protocol.CommitTransacti onIndication.indicating(CommitTransactionIndication.java:109 )
>
> at
> org.eclipse.net4j.signal.IndicationWithResponse.execute(Indi cationWithResponse.java:46)
>
> at org.eclipse.net4j.signal.Signal.runSync(Signal.java:143)
> at org.eclipse.net4j.signal.Signal.run(Signal.java:124)
> at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(Unkno wn
> Source)
> at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
> at java.lang.Thread.run(Unknown Source)
> Caused by: SQL Exception: Column 'PATH' cannot accept a NULL value.
> at org.apache.derby.impl.jdbc.Util.generateCsSQLException(Unkno wn
> Source)
> at
> org.apache.derby.impl.jdbc.TransactionResourceImpl.wrapInSQL Exception(Unknown
> Source)
> at
> org.apache.derby.impl.jdbc.TransactionResourceImpl.handleExc eption(Unknown
> Source)
> at
> org.apache.derby.impl.jdbc.EmbedConnection.handleException(U nknown
> Source)
> at
> org.apache.derby.impl.jdbc.ConnectionChild.handleException(U nknown
> Source)
> at
> org.apache.derby.impl.jdbc.EmbedStatement.executeStatement(U nknown
> Source)
> at org.apache.derby.impl.jdbc.EmbedStatement.execute(Unknown Source)
> at org.apache.derby.impl.jdbc.EmbedStatement.executeUpdate(Unkn own
> Source)
> at
> org.eclipse.emf.cdo.server.internal.db.ClassMapping.sqlUpdat e(ClassMapping.java:174)
>
> ... 15 more
>
> Can anybody help me? This is the way for store a model or metamodel
> starting from a file or I'm totally wrong!?
No, I would say your code basically looks fine.
Except that I can not see where objects are attached to the resource.
But CDO usually does not care where the objects come from that are
attached to a CDO resource.
Does fixing the resource path value, i.e. the
transaction.createResource(path) call, solve your problem?
Cheers
/Eike
----
http://thegordian.blogspot.com
> Thanks for the support!
> Toni
>
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
| | | | | |
Re: CDO server and client usage [message #426153 is a reply to message #426140] |
Wed, 17 December 2008 13:13 |
Victor Roldan Betancort Messages: 524 Registered: July 2009 |
Senior Member |
|
|
Toni,
> Hi, I've understand the usage of method createResource(" "), and I've
> correct my code. Yes I want to insert into CDO repo a metamodel (or
> model based on it) that is inside an xmi file. Following the graphical
> example called "Using the CDO User Interface", there is a description of
> a package registration. I think that my application crash because when I
> try to insert my metamodel(ecore based)there isn't already the package
> http://www.eclipse.org/emf/2002/Ecore and namespaces are not resolved.
Yes, for some reason, Ecore model isn't being created dynamically in CDO
Repository. According to Eike, it should work. I've submitted the
following bug:
Ecore model isn't being correctly dinamically registered into the backend
https://bugs.eclipse.org/bugs/show_bug.cgi?id=259090
> I've try using the graphical tool to connect to the repository register
> ecore pkg and insert my metamodel and it works, but I cannot insert the
> ecore pack using code.
I wonder how did you make it work! Going through the UI CDO Session
View, I can't :(
> I use the following code but nothing happend:
> session.getPackageRegistry().putEPackage (EcorePackage.eINSTANCE);
> When I browse the repo the isn't the ecore pkg inside.
> What is the way for register packages?
You were doing it the right way :) But don't forget to commit!
Feel free to give some feedback in the bug :)
Cheers,
Victor.
|
|
| |
Re: CDO server and client usage [message #426159 is a reply to message #426155] |
Wed, 17 December 2008 14:02 |
|
Toni, Vik,
In contrast to what' been said here before. It is not possible to
register the *global instance* of Ecore (EcorePackage.eINSTANCE) with a
CDOSession because the Ecore package itself has not been (and can not
be) generated for CDO. It would incur a circular dependency on plugin
level. Instead you must register a dynamic instance of the Ecore.ecore
file. Unfortunately Vik told me that CDO's support for this is currently
broken. He already filed a bugzilla.
I would like to support Ecore as a legacy model when it comes to:
247226: Transparently support legacy models
https://bugs.eclipse.org/bugs/show_bug.cgi?id=247226
But Ed told me that he's not going to support the needed EMF mechanisms
in Ecore due to performance concerns.
Cheers
/Eike
----
http://thegordian.blogspot.com
Toni schrieb:
> Hi, I've register the ecore pack inside the repositoy but when I try
> to create a new resource and a new root element, for example an
> EClass, I've the following error:
> Legacy system not available. Is it a problem?
>
> I've others quation for you:
>
> 1. with the graphical tool I've register my metamodel using the
> command "register workspace packages". After that I can create a new
> model (resource) and commit the transaction. My question is: when I
> register my package the repo is empty, without the Ecore metamodel
> pack, but my pack is inserted anyway. There isn't any check? And if
> register only my pack and close connection, when I access again the
> repo the pack is missing, but if I create a resource and commit the
> pack remain registered. Wy?
>
> 2.after the registration of a custom pack what is the way for create
> resource using the elements of the metamodel just registered? I other
> words I want do with code what I do with the graphical tool.
>
> Thanks for the support.
>
>
>
Cheers
/Eike
----
http://www.esc-net.de
http://thegordian.blogspot.com
http://twitter.com/eikestepper
|
|
|
Goto Forum:
Current Time: Wed Apr 24 23:41:02 GMT 2024
Powered by FUDForum. Page generated in 0.03291 seconds
|