summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-05-10 04:56:33 (EDT)
committerEike Stepper2008-05-10 04:56:33 (EDT)
commite9c80d5f548c8b901f1eda689b4ac71a173f516b (patch)
treef1d2f1c16dc1d744424821bb98b980154359b7b7
parentf9ff06daafa17c15dc13538f74724c81a75f0200 (diff)
downloadcdo-e9c80d5f548c8b901f1eda689b4ac71a173f516b.zip
cdo-e9c80d5f548c8b901f1eda689b4ac71a173f516b.tar.gz
cdo-e9c80d5f548c8b901f1eda689b4ac71a173f516b.tar.bz2
[230066] Implement a demand-populating EPackageRegistry
https://bugs.eclipse.org/bugs/show_bug.cgi?id=230066
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicEcoreTest.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicUmlTest.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/GeneratedEcoreTest.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ImportXML.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/MangoTest.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/NoLegacyTest.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java43
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionDeltaTest.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java13
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOSession.java2
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOSessionConfiguration.java46
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageRegistry.java3
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java27
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionConfigurationImpl.java123
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java6
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java18
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java206
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Notifier.java5
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/INotifier.java2
21 files changed, 489 insertions, 71 deletions
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
index 4e6785d..ddff4cd 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AbstractCDOTest.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.cdo.tests;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOSessionConfiguration;
import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.eresource.CDOResource;
@@ -78,9 +79,18 @@ public abstract class AbstractCDOTest extends AbstractTransportTest
startTransport();
}
+ protected CDOSession openSession()
+ {
+ CDOSessionConfiguration configuration = CDOUtil.createSessionConfiguration();
+ configuration.setConnector(getConnector());
+ configuration.setRepositoryName(REPOSITORY_NAME);
+ configuration.setDisableLegacyObjects(true);
+ return configuration.openSession();
+ }
+
protected CDOSession openModel1Session()
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
+ CDOSession session = openSession();
session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
return session;
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicEcoreTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicEcoreTest.java
index bce671f..6cb8ed0 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicEcoreTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicEcoreTest.java
@@ -13,7 +13,6 @@ package org.eclipse.emf.cdo.tests;
import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.eresource.CDOResource;
-import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EObject;
@@ -38,7 +37,7 @@ public class DymamicEcoreTest extends AbstractCDOTest
EPackage ecore = (EPackage)loadModel("ecore/Ecore.ecore", EPackage.Registry.INSTANCE);
// Create resource in session 1
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
session.getPackageRegistry().putEPackage(ecore);
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.createResource("/res");
@@ -50,7 +49,7 @@ public class DymamicEcoreTest extends AbstractCDOTest
{
// Load resource in session 2
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.getResource("/res");
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicUmlTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicUmlTest.java
index c6d1760..239ed4d 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicUmlTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/DymamicUmlTest.java
@@ -16,8 +16,6 @@ import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
-import org.eclipse.emf.cdo.tests.model1.Model1Package;
-import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
@@ -39,8 +37,7 @@ public class DymamicUmlTest extends AbstractCDOTest
{
{
// Create resource in session 1
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
- session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+ CDOSession session = openModel1Session();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.createResource("/res");
@@ -52,7 +49,7 @@ public class DymamicUmlTest extends AbstractCDOTest
{
// Load resource in session 2
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.getResource("/res");
@@ -70,8 +67,7 @@ public class DymamicUmlTest extends AbstractCDOTest
EAttribute nameAttribute = (EAttribute)companyClass.getEStructuralFeature("name");
// Create resource in session 1
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
- session.getPackageRegistry().putEPackage(model1);
+ CDOSession session = openModel1Session();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.createResource("/res");
@@ -83,7 +79,7 @@ public class DymamicUmlTest extends AbstractCDOTest
{
// Load resource in session 2
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.getResource("/res");
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/GeneratedEcoreTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/GeneratedEcoreTest.java
index 323148f..8b1234a 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/GeneratedEcoreTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/GeneratedEcoreTest.java
@@ -35,7 +35,7 @@ public class GeneratedEcoreTest extends AbstractCDOTest
EPackage ecore = EcorePackage.eINSTANCE;
// Create resource in session 1
- CDOSession session1 = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session1 = openSession();
session1.getPackageRegistry().putEPackage(ecore);
CDOTransaction transaction1 = session1.openTransaction();
CDOResource res1 = transaction1.createResource("/res");
@@ -45,7 +45,7 @@ public class GeneratedEcoreTest extends AbstractCDOTest
transaction1.commit();
// Load resource in session 2
- CDOSession session2 = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session2 = openSession();
CDOTransaction transaction2 = session2.openTransaction();
CDOResource res2 = transaction2.getResource("/res");
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ImportXML.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ImportXML.java
index 5928fd3..5c62af1 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ImportXML.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ImportXML.java
@@ -11,6 +11,7 @@
package org.eclipse.emf.cdo.tests;
import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOSessionConfiguration;
import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.server.CDOServerUtil;
import org.eclipse.emf.cdo.server.IRepository;
@@ -61,7 +62,7 @@ public class ImportXML
// Establish a communications connection and open a session with the repository
IConnector connector = JVMUtil.getConnector(container, "default"); // Open a JVM connection
- CDOSession session = CDOUtil.openSession(connector, REPOSITORY_NAME, true);// Open a CDO session
+ CDOSession session = openSession(connector);// Open a CDO session
session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);// Not needed after first commit!!!
CDOTransaction transaction = session.openTransaction();// Open a CDO transaction
@@ -108,4 +109,13 @@ public class ImportXML
cat2.getProducts().add(p3);
return cat1;
}
+
+ private static CDOSession openSession(IConnector connector)
+ {
+ CDOSessionConfiguration configuration = CDOUtil.createSessionConfiguration();
+ configuration.setConnector(connector);
+ configuration.setRepositoryName(REPOSITORY_NAME);
+ configuration.setDisableLegacyObjects(true);
+ return configuration.openSession();
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/MangoTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/MangoTest.java
index 50835f8..5ea0ae7 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/MangoTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/MangoTest.java
@@ -18,7 +18,6 @@ import org.eclipse.emf.cdo.tests.mango.MangoFactory;
import org.eclipse.emf.cdo.tests.mango.MangoPackage;
import org.eclipse.emf.cdo.tests.mango.Value;
import org.eclipse.emf.cdo.tests.mango.ValueList;
-import org.eclipse.emf.cdo.util.CDOUtil;
/**
* @author Eike Stepper
@@ -27,7 +26,7 @@ public class MangoTest extends AbstractCDOTest
{
private CDOSession openMangoSession()
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
+ CDOSession session = openSession();
session.getPackageRegistry().putEPackage(MangoPackage.eINSTANCE);
return session;
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/NoLegacyTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/NoLegacyTest.java
index 07f9cb2..d9cdf8f 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/NoLegacyTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/NoLegacyTest.java
@@ -11,6 +11,7 @@
package org.eclipse.emf.cdo.tests;
import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOSessionConfiguration;
import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.util.CDOUtil;
@@ -31,7 +32,11 @@ public class NoLegacyTest extends AbstractCDOTest
try
{
- session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, false);
+ CDOSessionConfiguration configuration = CDOUtil.createSessionConfiguration();
+ configuration.setConnector(getConnector());
+ configuration.setRepositoryName(REPOSITORY_NAME);
+ configuration.setDisableLegacyObjects(false);
+ session = configuration.openSession();
fail("LegacySystemNotAvailableException expected");
}
catch (LegacySystemNotAvailableException ex)
@@ -48,7 +53,7 @@ public class NoLegacyTest extends AbstractCDOTest
public void testAttachLegacyObject() throws Exception
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
+ CDOSession session = openSession();
session.getPackageRegistry().putEPackage(XMLTypePackage.eINSTANCE);
CDOTransaction transaction = session.openTransaction();
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
index bd3e340..6b0a31f 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/PackageRegistryTest.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.cdo.tests;
import org.eclipse.emf.cdo.CDOObject;
import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOSessionConfiguration;
import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
@@ -34,6 +35,8 @@ import org.eclipse.emf.cdo.tests.model3.subpackage.SubpackagePackage;
import org.eclipse.emf.cdo.util.CDOPackageTypeRegistry;
import org.eclipse.emf.cdo.util.CDOUtil;
+import org.eclipse.emf.internal.cdo.util.CDOPackageRegistryImpl;
+
import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EAttribute;
import org.eclipse.emf.ecore.EClass;
@@ -54,8 +57,7 @@ public class PackageRegistryTest extends AbstractCDOTest
{
{
// Create resource in session 1
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
- session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+ CDOSession session = openModel1Session();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.createResource("/res");
@@ -67,7 +69,7 @@ public class PackageRegistryTest extends AbstractCDOTest
{
// Load resource in session 2
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.getResource("/res");
@@ -79,7 +81,7 @@ public class PackageRegistryTest extends AbstractCDOTest
public void testCommitTwoPackages() throws Exception
{
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
+ CDOSession session = openSession();
session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
session.getPackageRegistry().putEPackage(Model2Package.eINSTANCE);
CDOTransaction transaction = session.openTransaction();
@@ -92,7 +94,7 @@ public class PackageRegistryTest extends AbstractCDOTest
}
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.getResource("/res");
@@ -104,8 +106,7 @@ public class PackageRegistryTest extends AbstractCDOTest
public void testCommitUnrelatedPackage() throws Exception
{
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
- session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+ CDOSession session = openModel1Session();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.createResource("/res");
@@ -117,7 +118,7 @@ public class PackageRegistryTest extends AbstractCDOTest
}
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
session.getPackageRegistry().putEPackage(MangoPackage.eINSTANCE);
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.getResource("/res");
@@ -133,7 +134,7 @@ public class PackageRegistryTest extends AbstractCDOTest
public void testCommitNestedPackages() throws Exception
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
+ CDOSession session = openSession();
session.getPackageRegistry().putEPackage(Model3Package.eINSTANCE);
assertEquals(2, session.getPackageRegistry().size());
@@ -166,7 +167,7 @@ public class PackageRegistryTest extends AbstractCDOTest
public void testLoadNestedPackages() throws Exception
{
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
+ CDOSession session = openSession();
session.getPackageRegistry().putEPackage(Model3Package.eINSTANCE);
CDOTransaction transaction = session.openTransaction();
@@ -179,7 +180,7 @@ public class PackageRegistryTest extends AbstractCDOTest
}
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
+ CDOSession session = openSession();
CDOPackage model3Package = session.getPackageManager().lookupPackage(Model3Package.eINSTANCE.getNsURI());
assertEquals(8, model3Package.getMetaIDRange().size());
assertNotNull(model3Package.getEcore());
@@ -194,7 +195,7 @@ public class PackageRegistryTest extends AbstractCDOTest
public void testCommitCircularPackages() throws Exception
{
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true);
+ CDOSession session = openSession();
session.getPackageRegistry().putEPackage(Model3Package.eINSTANCE);
CDOTransaction transaction = session.openTransaction();
CDOResource res1 = transaction.createResource("/res1");
@@ -211,7 +212,7 @@ public class PackageRegistryTest extends AbstractCDOTest
}
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource res1 = transaction.getResource("/res1");
@@ -222,7 +223,7 @@ public class PackageRegistryTest extends AbstractCDOTest
}
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource res2 = transaction.getResource("/res2");
@@ -239,7 +240,13 @@ public class PackageRegistryTest extends AbstractCDOTest
{
// Create resource in session 1
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME, true, true);
+ CDOSessionConfiguration configuration = CDOUtil.createSessionConfiguration();
+ configuration.setConnector(getConnector());
+ configuration.setRepositoryName(REPOSITORY_NAME);
+ configuration.setDisableLegacyObjects(true);
+ configuration.setPackageRegistry(new CDOPackageRegistryImpl.SelfPopulating());
+
+ CDOSession session = configuration.openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.createResource("/res");
@@ -251,7 +258,7 @@ public class PackageRegistryTest extends AbstractCDOTest
{
// Load resource in session 2
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.getResource("/res");
@@ -276,7 +283,7 @@ public class PackageRegistryTest extends AbstractCDOTest
EAttribute nameAttribute = (EAttribute)companyClass.getEStructuralFeature("name");
// Create resource in session 1
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
session.getPackageRegistry().putEPackage(model1);
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.createResource("/res");
@@ -289,7 +296,7 @@ public class PackageRegistryTest extends AbstractCDOTest
{
// Load resource in session 2
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
+ CDOSession session = openSession();
CDOTransaction transaction = session.openTransaction();
CDOResource res = transaction.getResource("/res");
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionDeltaTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionDeltaTest.java
index a95bca8..8900968 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionDeltaTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RevisionDeltaTest.java
@@ -31,7 +31,6 @@ import org.eclipse.emf.cdo.tests.model1.Customer;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
import org.eclipse.emf.cdo.tests.model1.Model1Package;
import org.eclipse.emf.cdo.tests.model1.SalesOrder;
-import org.eclipse.emf.cdo.util.CDOUtil;
import junit.framework.Assert;
@@ -43,9 +42,7 @@ public class RevisionDeltaTest extends AbstractCDOTest
{
public void testBasicRevisionDelta() throws Exception
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
- session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
-
+ CDOSession session = openModel1Session();
CDOTransaction transaction = session.openTransaction();
CDOResource resource1 = transaction.createResource("/test1");
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java
index 97782a7..bb13ba7 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/RollbackTest.java
@@ -16,8 +16,6 @@ import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.tests.model1.Category;
import org.eclipse.emf.cdo.tests.model1.Company;
import org.eclipse.emf.cdo.tests.model1.Model1Factory;
-import org.eclipse.emf.cdo.tests.model1.Model1Package;
-import org.eclipse.emf.cdo.util.CDOUtil;
import org.eclipse.net4j.util.transaction.TransactionException;
@@ -28,25 +26,20 @@ public class RollbackTest extends AbstractCDOTest
{
public void testRollbackSameSession() throws Exception
{
- CDOSession session = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
- session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
-
+ CDOSession session = openModel1Session();
CDOTransaction transaction1 = session.openTransaction();
CDOTransaction transaction2 = session.openTransaction();
-
flow1(transaction1, transaction2);
}
public void testRollbackSeparateSession() throws Exception
{
// Client1
- CDOSession session1 = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
- session1.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+ CDOSession session1 = openModel1Session();
CDOTransaction transaction1 = session1.openTransaction();
// Client2
- CDOSession session2 = CDOUtil.openSession(getConnector(), REPOSITORY_NAME);
- session2.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+ CDOSession session2 = openModel1Session();
CDOTransaction transaction2 = session2.openTransaction();
flow1(transaction1, transaction2);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOSession.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOSession.java
index a59f03e..c640715 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOSession.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOSession.java
@@ -25,8 +25,6 @@ import org.eclipse.emf.ecore.resource.ResourceSet;
*/
public interface CDOSession extends CDOProtocolSession, IContainer<CDOView>
{
- public void setDisableLegacyObjects(boolean disableLegacyObjects);
-
public int getReferenceChunkSize();
public void setReferenceChunkSize(int referenceChunkSize);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOSessionConfiguration.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOSessionConfiguration.java
new file mode 100644
index 0000000..e123472
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOSessionConfiguration.java
@@ -0,0 +1,46 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo;
+
+import org.eclipse.emf.internal.cdo.util.CDOPackageRegistryImpl;
+
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.signal.failover.IFailOverStrategy;
+
+/**
+ * @author Eike Stepper
+ */
+public interface CDOSessionConfiguration
+{
+ public IConnector getConnector();
+
+ public void setConnector(IConnector connector);
+
+ public String getRepositoryName();
+
+ public void setRepositoryName(String repositoryName);
+
+ public boolean isDisableLegacyObjects();
+
+ public void setDisableLegacyObjects(boolean disableLegacyObjects);
+
+ public IFailOverStrategy getFailOverStrategy();
+
+ public void setFailOverStrategy(IFailOverStrategy failOverStrategy);
+
+ public CDOPackageRegistryImpl getPackageRegistry();
+
+ public void setPackageRegistry(CDOPackageRegistryImpl packageRegistry);
+
+ public CDOSession openSession();
+
+ public boolean isSessionOpen();
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageRegistry.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageRegistry.java
index 8a5b312..b3cdcb0 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageRegistry.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOPackageRegistry.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.emf.cdo.util;
+import org.eclipse.emf.cdo.CDOSession;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
import org.eclipse.emf.ecore.EPackage;
@@ -29,4 +30,6 @@ public interface CDOPackageRegistry extends EPackage.Registry
public EPackage putEPackage(EPackage ePackage);
public void putPackageDescriptor(CDOPackage proxy);
+
+ public void setSession(CDOSession session);
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
index c8a6261..fb71873 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/util/CDOUtil.java
@@ -11,10 +11,12 @@
package org.eclipse.emf.cdo.util;
import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOSessionConfiguration;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.eresource.CDOResourceFactory;
import org.eclipse.emf.cdo.protocol.CDOProtocolConstants;
+import org.eclipse.emf.internal.cdo.CDOSessionConfigurationImpl;
import org.eclipse.emf.internal.cdo.CDOSessionFactory;
import org.eclipse.emf.internal.cdo.CDOSessionImpl;
import org.eclipse.emf.internal.cdo.CDOStateMachine;
@@ -56,6 +58,15 @@ public final class CDOUtil
{
}
+ public static CDOSessionConfiguration createSessionConfiguration()
+ {
+ return new CDOSessionConfigurationImpl();
+ }
+
+ /**
+ * @deprecated Use {@link #createSessionConfiguration()} instead.
+ */
+ @Deprecated
public static CDOSession openSession(IConnector connector, String repositoryName, boolean disableLegacyObjects,
boolean automaticPackageRegistry, IFailOverStrategy failOverStrategy) throws ConnectorException
{
@@ -66,23 +77,39 @@ public final class CDOUtil
return session;
}
+ /**
+ * @deprecated Use {@link #createSessionConfiguration()} instead.
+ */
+ @Deprecated
public static CDOSession openSession(IConnector connector, String repositoryName, boolean disableLegacyObjects,
boolean automaticPackageRegistry) throws ConnectorException
{
return openSession(connector, repositoryName, disableLegacyObjects, automaticPackageRegistry, null);
}
+ /**
+ * @deprecated Use {@link #createSessionConfiguration()} instead.
+ */
+ @Deprecated
public static CDOSession openSession(IConnector connector, String repositoryName, boolean disableLegacyObjects)
throws ConnectorException
{
return openSession(connector, repositoryName, disableLegacyObjects, false, null);
}
+ /**
+ * @deprecated Use {@link #createSessionConfiguration()} instead.
+ */
+ @Deprecated
public static CDOSession openSession(IConnector connector, String repositoryName) throws ConnectorException
{
return openSession(connector, repositoryName, true);
}
+ /**
+ * @deprecated Use {@link #createSessionConfiguration()} instead.
+ */
+ @Deprecated
public static CDOSession openSession(IManagedContainer container, String description) throws ConnectorException
{
return CDOSessionFactory.get(container, description);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionConfigurationImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionConfigurationImpl.java
new file mode 100644
index 0000000..a94614a
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionConfigurationImpl.java
@@ -0,0 +1,123 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo;
+
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOSessionConfiguration;
+
+import org.eclipse.emf.internal.cdo.util.CDOPackageRegistryImpl;
+
+import org.eclipse.net4j.connector.IConnector;
+import org.eclipse.net4j.signal.failover.IFailOverStrategy;
+
+/**
+ * @author Eike Stepper
+ */
+public class CDOSessionConfigurationImpl implements CDOSessionConfiguration
+{
+ private CDOSessionImpl session;
+
+ private IConnector connector;
+
+ private String repositoryName;
+
+ private boolean disableLegacyObjects;
+
+ private IFailOverStrategy failOverStrategy;
+
+ private CDOPackageRegistryImpl packageRegistry;
+
+ public CDOSessionConfigurationImpl()
+ {
+ }
+
+ public IConnector getConnector()
+ {
+ return connector;
+ }
+
+ public void setConnector(IConnector connector)
+ {
+ this.connector = connector;
+ }
+
+ public String getRepositoryName()
+ {
+ return repositoryName;
+ }
+
+ public void setRepositoryName(String repositoryName)
+ {
+ this.repositoryName = repositoryName;
+ }
+
+ public boolean isDisableLegacyObjects()
+ {
+ return disableLegacyObjects;
+ }
+
+ public void setDisableLegacyObjects(boolean disableLegacyObjects)
+ {
+ this.disableLegacyObjects = disableLegacyObjects;
+ }
+
+ public IFailOverStrategy getFailOverStrategy()
+ {
+ return failOverStrategy;
+ }
+
+ public void setFailOverStrategy(IFailOverStrategy failOverStrategy)
+ {
+ this.failOverStrategy = failOverStrategy;
+ }
+
+ public CDOPackageRegistryImpl getPackageRegistry()
+ {
+ return packageRegistry;
+ }
+
+ public void setPackageRegistry(CDOPackageRegistryImpl packageRegistry)
+ {
+ this.packageRegistry = packageRegistry;
+ }
+
+ public CDOSession openSession()
+ {
+ if (!isSessionOpen())
+ {
+ session = new CDOSessionImpl();
+ session.setConnector(connector);
+ session.setRepositoryName(repositoryName);
+ session.setDisableLegacyObjects(disableLegacyObjects);
+ session.setFailOverStrategy(failOverStrategy);
+ session.setPackageRegistry(packageRegistry);
+ session.activate();
+ }
+
+ return session;
+ }
+
+ public boolean isSessionOpen()
+ {
+ if (session == null)
+ {
+ return false;
+ }
+
+ if (session.isOpen())
+ {
+ return true;
+ }
+
+ session = null;
+ return false;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java
index e0626ad..93b7f6f 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionFactory.java
@@ -71,7 +71,9 @@ public class CDOSessionFactory extends Factory
CDOSessionImpl session = new CDOSessionImpl();
if (automaticPackageRegistry)
{
- session.setPackageRegistry(new CDOPackageRegistryImpl.SelfPopulating(session));
+ CDOPackageRegistryImpl.SelfPopulating packageRegistry = new CDOPackageRegistryImpl.SelfPopulating();
+ packageRegistry.setSession(session);
+ session.setPackageRegistry(packageRegistry);
}
session.setRepositoryName(repositoryName);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
index 1628c84..8357886 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOSessionImpl.java
@@ -150,6 +150,8 @@ public class CDOSessionImpl extends Container<CDOView> implements CDOSession, CD
{
packageManager = createPackageManager();
revisionManager = createRevisionManager();
+
+ // TODO Remove preferences from core
referenceChunkSize = OM.PREF_REFERENCE_CHUNK_SIZE.getValue();
}
@@ -552,7 +554,7 @@ public class CDOSessionImpl extends Container<CDOView> implements CDOSession, CD
protected CDOPackageRegistryImpl createPackageRegistry()
{
- return new CDOPackageRegistryImpl(this);
+ return new CDOPackageRegistryImpl();
}
protected CDOSessionPackageManagerImpl createPackageManager()
@@ -636,6 +638,8 @@ public class CDOSessionImpl extends Container<CDOView> implements CDOSession, CD
packageRegistry = createPackageRegistry();
}
+ packageRegistry.setSession(this);
+
if (channel == null)
{
channel = connector.openChannel(CDOProtocolConstants.PROTOCOL_NAME, this);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
index 9dfaefd..f3b2640 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
@@ -48,6 +48,7 @@ import org.eclipse.emf.ecore.EPackage;
import java.text.MessageFormat;
import java.util.ArrayList;
+import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.HashSet;
@@ -223,12 +224,12 @@ public class CDOTransactionImpl extends CDOViewImpl implements CDOTransaction
try
{
- CDOSessionImpl session = getSession();
- newPackages = analyzeNewPackages(session);
+ newPackages = analyzeNewPackages();
preCommit(newObjects);
preCommit(dirtyObjects);
+ CDOSessionImpl session = getSession();
IChannel channel = session.getChannel();
IFailOverStrategy failOverStrategy = session.getFailOverStrategy();
CommitTransactionRequest request = new CommitTransactionRequest(channel, this);
@@ -388,7 +389,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements CDOTransaction
}
}
- private List<CDOPackage> analyzeNewPackages(CDOSessionImpl session)
+ private List<CDOPackage> analyzeNewPackages()
{
// Find all used classes and their super classes
Set<EClass> usedClasses = new HashSet<EClass>();
@@ -404,16 +405,21 @@ public class CDOTransactionImpl extends CDOViewImpl implements CDOTransaction
}
}
+ return analyzeNewPackages(usedClasses);
+ }
+
+ private List<CDOPackage> analyzeNewPackages(Collection<EClass> eClasses)
+ {
// Calculate the top level packages of the used classes
Set<EPackage> usedPackages = new HashSet<EPackage>();
- for (EClass usedClass : usedClasses)
+ for (EClass eClass : eClasses)
{
- EPackage topLevelPackage = ModelUtil.getTopLevelPackage(usedClass.getEPackage());
+ EPackage topLevelPackage = ModelUtil.getTopLevelPackage(eClass.getEPackage());
usedPackages.add(topLevelPackage);
}
// Determine which of the used packages are new
- CDOSessionPackageManagerImpl packageManager = session.getPackageManager();
+ CDOSessionPackageManagerImpl packageManager = getSession().getPackageManager();
List<CDOPackage> newPackages = new ArrayList<CDOPackage>();
for (EPackage usedPackage : usedPackages)
{
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java
index fb954f6..94e0dfa 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/util/CDOPackageRegistryImpl.java
@@ -10,9 +10,15 @@
**************************************************************************/
package org.eclipse.emf.internal.cdo.util;
+import org.eclipse.emf.cdo.CDOObject;
+import org.eclipse.emf.cdo.CDOSession;
+import org.eclipse.emf.cdo.CDOTransaction;
+import org.eclipse.emf.cdo.CDOTransactionHandler;
+import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.internal.protocol.model.InternalCDOPackage;
import org.eclipse.emf.cdo.protocol.id.CDOIDMetaRange;
import org.eclipse.emf.cdo.protocol.model.CDOPackage;
+import org.eclipse.emf.cdo.protocol.revision.delta.CDOFeatureDelta;
import org.eclipse.emf.cdo.util.CDOPackageRegistry;
import org.eclipse.emf.cdo.util.CDOPackageType;
import org.eclipse.emf.cdo.util.CDOPackageTypeRegistry;
@@ -28,13 +34,18 @@ import org.eclipse.net4j.util.container.IContainer;
import org.eclipse.net4j.util.event.IListener;
import org.eclipse.net4j.util.lifecycle.ILifecycle;
+import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EFactory;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.impl.EPackageImpl;
import org.eclipse.emf.ecore.impl.EPackageRegistryImpl;
import java.text.MessageFormat;
+import java.util.ArrayList;
+import java.util.HashSet;
+import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -47,9 +58,8 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
private CDOSessionImpl session;
- public CDOPackageRegistryImpl(CDOSessionImpl session)
+ public CDOPackageRegistryImpl()
{
- this.session = session;
}
public CDOSessionImpl getSession()
@@ -57,8 +67,14 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
return session;
}
+ public void setSession(CDOSession session)
+ {
+ this.session = (CDOSessionImpl)session;
+ }
+
public void putPackageDescriptor(CDOPackage cdoPackage)
{
+ checkSession();
EPackage.Descriptor descriptor = new RemotePackageDescriptor(cdoPackage);
String uri = cdoPackage.getPackageURI();
if (TRACER.isEnabled())
@@ -71,6 +87,7 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
public EPackage putEPackage(EPackage ePackage)
{
+ checkSession();
String uri = ePackage.getNsURI();
if (ePackage.getESuperPackage() != null)
{
@@ -97,6 +114,7 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
@Override
public Object put(String key, Object value)
{
+ checkSession();
if (value instanceof EPackage)
{
if (TRACER.isEnabled())
@@ -127,6 +145,14 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
throw new UnsupportedOperationException();
}
+ private void checkSession()
+ {
+ if (session == null)
+ {
+ throw new IllegalStateException("session == null");
+ }
+ }
+
/**
* @author Eike Stepper
*/
@@ -172,26 +198,127 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
/**
* @author Eike Stepper
*/
- public static class SelfPopulating extends CDOPackageRegistryImpl
+ public static abstract class SessionBound extends CDOPackageRegistryImpl
{
private static final long serialVersionUID = 1L;
- private IListener sessionListener = new LifecycleEventAdapter()
+ private IListener sessionLifecycleListener = new LifecycleEventAdapter()
{
@Override
protected void onActivated(ILifecycle lifecycle)
{
- populate();
+ sessionActivated();
}
@Override
protected void onAboutToDeactivate(ILifecycle lifecycle)
{
getSession().removeListener(this);
- CDOPackageTypeRegistry.INSTANCE.removeListener(typeListener);
+ sessionAboutToDeactivate();
}
};
+ public SessionBound()
+ {
+ }
+
+ @Override
+ public void setSession(CDOSession session)
+ {
+ super.setSession(session);
+ session.addListener(sessionLifecycleListener);
+ }
+
+ protected abstract void sessionActivated();
+
+ protected abstract void sessionAboutToDeactivate();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class TransactionBound extends SessionBound implements CDOTransactionHandler
+ {
+ private static final long serialVersionUID = 1L;
+
+ private List<CDOTransaction> transactions = new ArrayList<CDOTransaction>();
+
+ private IListener sessionContainerListener = new ContainerEventAdapter<CDOView>()
+ {
+ @Override
+ protected void onAdded(IContainer<CDOView> session, CDOView view)
+ {
+ if (view instanceof CDOTransaction)
+ {
+ CDOTransaction transaction = (CDOTransaction)view;
+ transaction.addHandler(TransactionBound.this);
+ synchronized (transactions)
+ {
+ transactions.add(transaction);
+ }
+ }
+ }
+
+ @Override
+ protected void onRemoved(IContainer<CDOView> session, CDOView view)
+ {
+ if (view instanceof CDOTransaction)
+ {
+ CDOTransaction transaction = (CDOTransaction)view;
+ transaction.removeHandler(TransactionBound.this);
+ synchronized (transactions)
+ {
+ transactions.remove(transaction);
+ }
+ }
+ }
+ };
+
+ public TransactionBound()
+ {
+ }
+
+ @Override
+ protected void sessionActivated()
+ {
+ getSession().addListener(sessionContainerListener);
+ }
+
+ @Override
+ protected void sessionAboutToDeactivate()
+ {
+ getSession().removeListener(sessionContainerListener);
+ synchronized (transactions)
+ {
+ for (CDOTransaction transaction : transactions)
+ {
+ transaction.removeHandler(this);
+ }
+
+ transactions.clear();
+ }
+ }
+
+ public void addingObject(CDOTransaction transaction, CDOObject object)
+ {
+ }
+
+ public void modifyingObject(CDOTransaction transaction, CDOObject object, CDOFeatureDelta featureDelta)
+ {
+ }
+
+ public void committingTransaction(CDOTransaction transaction)
+ {
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class SelfPopulating extends SessionBound
+ {
+ private static final long serialVersionUID = 1L;
+
private IListener typeListener = new ContainerEventAdapter<Map.Entry<String, CDOPackageType>>()
{
@Override
@@ -202,13 +329,12 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
}
};
- public SelfPopulating(CDOSessionImpl session)
+ public SelfPopulating()
{
- super(session);
- session.addListener(sessionListener);
}
- protected void populate()
+ @Override
+ protected void sessionActivated()
{
for (Map.Entry<String, CDOPackageType> entry : CDOPackageTypeRegistry.INSTANCE.entrySet())
{
@@ -218,6 +344,12 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
CDOPackageTypeRegistry.INSTANCE.addListener(typeListener);
}
+ @Override
+ protected void sessionAboutToDeactivate()
+ {
+ CDOPackageTypeRegistry.INSTANCE.removeListener(typeListener);
+ }
+
protected void addEntry(Map.Entry<String, CDOPackageType> entry)
{
CDOPackageType packageType = entry.getValue();
@@ -239,4 +371,58 @@ public class CDOPackageRegistryImpl extends EPackageRegistryImpl implements CDOP
}
}
}
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class DemandPopulating extends TransactionBound
+ {
+ private static final long serialVersionUID = 1L;
+
+ private Set<EClass> usedClasses = new HashSet<EClass>();
+
+ public DemandPopulating()
+ {
+ }
+
+ @Override
+ public void addingObject(CDOTransaction transaction, CDOObject object)
+ {
+ EClass usedClass = object.eClass();
+ if (usedClasses.add(usedClass))
+ {
+ addPackage(usedClass.getEPackage());
+ for (EClass superType : usedClass.getEAllSuperTypes())
+ {
+ usedClasses.add(superType);
+ addPackage(superType.getEPackage());
+ }
+ }
+ }
+
+ @Override
+ protected void sessionAboutToDeactivate()
+ {
+ usedClasses.clear();
+ super.sessionAboutToDeactivate();
+ }
+
+ private void addPackage(EPackage ePackage)
+ {
+ if (!containsKey(ePackage.getNsURI()))
+ {
+ EPackage topLevelPackage = ModelUtil.getTopLevelPackage(ePackage);
+ addPackageRecursively(topLevelPackage);
+ }
+ }
+
+ private void addPackageRecursively(EPackage ePackage)
+ {
+ putEPackage(ePackage);
+ for (EPackage subPackage : ePackage.getESubpackages())
+ {
+ addPackageRecursively(subPackage);
+ }
+ }
+ }
}
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Notifier.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Notifier.java
index 695402b..c7df10f 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Notifier.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/event/Notifier.java
@@ -48,6 +48,11 @@ public class Notifier implements INotifier.Introspection
}
}
+ public boolean hasListeners()
+ {
+ return !listeners.isEmpty();
+ }
+
public IListener[] getListeners()
{
synchronized (listeners)
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/INotifier.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/INotifier.java
index 1934f58..39f3701 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/INotifier.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/util/event/INotifier.java
@@ -24,6 +24,8 @@ public interface INotifier
*/
public interface Introspection extends INotifier
{
+ public boolean hasListeners();
+
public IListener[] getListeners();
}
}