Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-06-17 09:43:53 +0000
committerEike Stepper2008-06-17 09:43:53 +0000
commit71c279a1ac8df539e03e0db825a740ada9fa8235 (patch)
tree7148041f9578f0f5341aa046427a28bc0dc7e512 /plugins
parente8e3074b3cc47e8e83349f53170d3ab233c74948 (diff)
downloadcdo-71c279a1ac8df539e03e0db825a740ada9fa8235.tar.gz
cdo-71c279a1ac8df539e03e0db825a740ada9fa8235.tar.xz
cdo-71c279a1ac8df539e03e0db825a740ada9fa8235.zip
*** empty log message ***
Diffstat (limited to 'plugins')
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneContainerExample.java (renamed from plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneTCPExample.java)2
-rw-r--r--plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneManualExample.java112
2 files changed, 113 insertions, 1 deletions
diff --git a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneTCPExample.java b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneContainerExample.java
index 8b247ffe96..8f01397e22 100644
--- a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneTCPExample.java
+++ b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneContainerExample.java
@@ -33,7 +33,7 @@ import org.eclipse.emf.ecore.EObject;
/**
* @author Eike Stepper
*/
-public class StandaloneTCPExample
+public class StandaloneContainerExample
{
public static void main(String[] args)
{
diff --git a/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneManualExample.java b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneManualExample.java
new file mode 100644
index 0000000000..d5f018577d
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.examples/src/org/eclipse/emf/cdo/examples/StandaloneManualExample.java
@@ -0,0 +1,112 @@
+/***************************************************************************
+ * 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.examples;
+
+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.tests.model1.Model1Factory;
+import org.eclipse.emf.cdo.tests.model1.Model1Package;
+import org.eclipse.emf.cdo.util.CDOUtil;
+
+import org.eclipse.net4j.Net4jUtil;
+import org.eclipse.net4j.buffer.IBufferProvider;
+import org.eclipse.net4j.util.factory.IFactory;
+import org.eclipse.net4j.util.factory.IFactoryKey;
+import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import org.eclipse.net4j.util.om.OMPlatform;
+import org.eclipse.net4j.util.om.log.PrintLogHandler;
+import org.eclipse.net4j.util.om.trace.PrintTraceHandler;
+import org.eclipse.net4j.util.registry.HashMapRegistry;
+import org.eclipse.net4j.util.registry.IRegistry;
+
+import org.eclipse.emf.ecore.EObject;
+
+import java.util.concurrent.ExecutorService;
+import java.util.concurrent.Executors;
+import java.util.concurrent.ThreadFactory;
+
+/**
+ * @author Eike Stepper
+ */
+public class StandaloneManualExample
+{
+ @SuppressWarnings("restriction")
+ public static void main(String[] args)
+ {
+ // Enable logging and tracing
+ OMPlatform.INSTANCE.setDebugging(true);
+ OMPlatform.INSTANCE.addLogHandler(PrintLogHandler.CONSOLE);
+ OMPlatform.INSTANCE.addTraceHandler(PrintTraceHandler.CONSOLE);
+
+ // Prepare receiveExecutor
+ final ThreadGroup threadGroup = new ThreadGroup("net4j");
+ ExecutorService receiveExecutor = Executors.newCachedThreadPool(new ThreadFactory()
+ {
+ public Thread newThread(Runnable r)
+ {
+ Thread thread = new Thread(threadGroup, r);
+ thread.setDaemon(true);
+ return thread;
+ }
+ });
+
+ // Prepare bufferProvider
+ IBufferProvider bufferProvider = Net4jUtil.createBufferPool();
+ LifecycleUtil.activate(bufferProvider);
+
+ // Prepare protocolFactoryRegistry
+ IFactory protocolFactory = new org.eclipse.emf.internal.cdo.protocol.CDOClientProtocolFactory();
+ IRegistry<IFactoryKey, IFactory> protocolFactoryRegistry = new HashMapRegistry<IFactoryKey, IFactory>();
+ protocolFactoryRegistry.put(protocolFactory.getKey(), protocolFactory);
+ LifecycleUtil.activate(protocolFactoryRegistry);
+
+ // Prepare selector
+ org.eclipse.net4j.internal.tcp.TCPSelector selector = new org.eclipse.net4j.internal.tcp.TCPSelector();
+ selector.activate();
+
+ // Prepare connector
+ org.eclipse.net4j.internal.tcp.TCPClientConnector connector = new org.eclipse.net4j.internal.tcp.TCPClientConnector();
+ connector.setReceiveExecutor(receiveExecutor);
+ connector.setBufferProvider(bufferProvider);
+ connector.setProtocolFactoryRegistry(protocolFactoryRegistry);
+ connector.setSelector(selector);
+ connector.setNegotiator(null);
+ connector.setHost("localhost");
+ connector.setPort(2036);
+ connector.activate();
+
+ // Create configuration
+ CDOSessionConfiguration configuration = CDOUtil.createSessionConfiguration();
+ configuration.setConnector(connector);
+ configuration.setRepositoryName("repo1");
+
+ // Open session
+ CDOSession session = configuration.openSession();
+ session.getPackageRegistry().putEPackage(Model1Package.eINSTANCE);
+
+ // Open transaction
+ CDOTransaction transaction = session.openTransaction();
+
+ // Get or create resource
+ CDOResource resource = transaction.getOrCreateResource("/path/to/my/resource");
+
+ // Work with the resource and commit the transaction
+ EObject object = Model1Factory.eINSTANCE.createCompany();
+ resource.getContents().add(object);
+ transaction.commit();
+
+ // Cleanup
+ session.close();
+ connector.deactivate();
+ }
+}

Back to the top