Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2013-09-16 10:56:56 +0000
committerEike Stepper2013-09-18 07:13:00 +0000
commit1ce4e15e515c4a09cf8762145173240f271f14c6 (patch)
treef15ccfcc050956aa5e2878471da704089fff27be
parentfbd7508c0b3d6d7b6767c9616558b58fff3cc166 (diff)
downloadcdo-1ce4e15e515c4a09cf8762145173240f271f14c6.tar.gz
cdo-1ce4e15e515c4a09cf8762145173240f271f14c6.tar.xz
cdo-1ce4e15e515c4a09cf8762145173240f271f14c6.zip
[417321] [Hibernate] Replace HibernateCommandProvider with
ExportHbmCommand https://bugs.eclipse.org/bugs/show_bug.cgi?id=417321
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF8
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF.orig33
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/plugin.xml7
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/ExportHbmCommand.java73
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/HibernateCommandProvider.java157
-rw-r--r--plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/OM.java7
6 files changed, 84 insertions, 201 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF
index 72e94442e3..816bcc42e8 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF
@@ -1,7 +1,7 @@
Manifest-Version: 1.0
Bundle-ManifestVersion: 2
Bundle-SymbolicName: org.eclipse.emf.cdo.server.hibernate.teneo;singleton:=true
-Bundle-Version: 4.2.0.qualifier
+Bundle-Version: 4.2.100.qualifier
Bundle-Name: %pluginName
Bundle-Vendor: %providerName
Bundle-Localization: plugin
@@ -27,8 +27,8 @@ Import-Package: org.eclipse.emf.cdo.security;version="[4.0.0,5.0.0)",
org.eclipse.emf.teneo.hibernate.mapper;version="[2.0.1,3.0.0)",
org.eclipse.emf.teneo.simpledom;version="[2.0.1,3.0.0)",
org.eclipse.emf.teneo.util;version="[2.0.1,3.0.0)"
-Export-Package: org.eclipse.emf.cdo.server.hibernate.internal.teneo;version="4.2.0";x-friends:="org.eclipse.emf.cdo.tests.hibernate",
- org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle;version="4.2.0";x-friends:="org.eclipse.emf.cdo.tests.hibernate",
- org.eclipse.emf.cdo.server.hibernate.teneo;version="4.2.0"
+Export-Package: org.eclipse.emf.cdo.server.hibernate.internal.teneo;version="4.2.100";x-friends:="org.eclipse.emf.cdo.tests.hibernate",
+ org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle;version="4.2.100";x-friends:="org.eclipse.emf.cdo.tests.hibernate",
+ org.eclipse.emf.cdo.server.hibernate.teneo;version="4.2.100"
Bundle-ActivationPolicy: lazy
Bundle-Activator: org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle.OM$Activator
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF.orig b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF.orig
deleted file mode 100644
index b8ca44db40..0000000000
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/META-INF/MANIFEST.MF.orig
+++ /dev/null
@@ -1,33 +0,0 @@
-Manifest-Version: 1.0
-Bundle-ManifestVersion: 2
-Bundle-SymbolicName: org.eclipse.emf.cdo.server.hibernate.teneo;singleton:=true
-Bundle-Version: 4.2.0.qualifier
-Bundle-Name: %pluginName
-Bundle-Vendor: %providerName
-Bundle-Localization: plugin
-Bundle-RequiredExecutionEnvironment: J2SE-1.5
-Eclipse-BuddyPolicy: registered
-Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
- org.eclipse.emf.ecore.xmi;bundle-version="[2.4.0,3.0.0)",
- org.eclipse.emf.cdo;bundle-version="[4.0.0,5.0.0)",
- org.eclipse.emf.cdo.server;bundle-version="[4.0.0,5.0.0)",
- org.eclipse.emf.cdo.common;bundle-version="[4.0.0,5.0.0)"
-Import-Package: org.eclipse.emf.cdo.security;version="[4.0.0,5.0.0)",
- org.eclipse.emf.teneo;version="[2.0.1,3.0.0)",
- org.eclipse.emf.teneo.annotations.mapper;version="[2.0.1,3.0.0)",
- org.eclipse.emf.teneo.annotations.pamodel;version="[2.0.1,3.0.0)",
- org.eclipse.emf.teneo.annotations.pannotation;version="[2.0.1,3.0.0)",
- org.eclipse.emf.teneo.annotations.xml;version="[2.0.1,3.0.0)",
- org.eclipse.emf.teneo.extension;version="[2.0.1,3.0.0)",
- org.eclipse.emf.teneo.hibernate.annotations;version="[2.0.1,3.0.0)",
- org.eclipse.emf.teneo.hibernate.hbannotation;version="[2.0.1,3.0.0)",
- org.eclipse.emf.teneo.hibernate.mapper;version="[2.0.1,3.0.0)",
- org.eclipse.emf.teneo.simpledom;version="[2.0.1,3.0.0)",
- org.eclipse.emf.cdo.server.hibernate;version="[4.0.0,5.0.0)",
- org.eclipse.emf.cdo.server.internal.hibernate;version="[4.0.0,5.0.0)",
- org.eclipse.emf.cdo.server.internal.hibernate.tuplizer;version="[4.0.0,5.0.0)"
-Export-Package: org.eclipse.emf.cdo.server.hibernate.internal.teneo;version="4.2.0";x-friends:="org.eclipse.emf.cdo.tests.hibernate",
- org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle;version="4.2.0";x-friends:="org.eclipse.emf.cdo.tests.hibernate",
- org.eclipse.emf.cdo.server.hibernate.teneo;version="4.2.0"
-Bundle-ActivationPolicy: lazy
-Bundle-Activator: org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle.OM$Activator
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/plugin.xml b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/plugin.xml
index e86851b569..ce6a0fad9d 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/plugin.xml
@@ -20,4 +20,11 @@
type="teneo"/>
</extension>
+ <extension point="org.eclipse.net4j.util.factories">
+ <factory
+ productGroup="org.eclipse.emf.cdo.server.commands"
+ type="exporthbm"
+ class="org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle.ExportHbmCommand$Factory"/>
+ </extension>
+
</plugin>
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/ExportHbmCommand.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/ExportHbmCommand.java
new file mode 100644
index 0000000000..5563ceb569
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/ExportHbmCommand.java
@@ -0,0 +1,73 @@
+/*
+ * Copyright (c) 2004-2013 Eike Stepper (Berlin, Germany) and others.
+ * 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.server.hibernate.internal.teneo.bundle;
+
+import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
+import org.eclipse.emf.cdo.spi.server.CDOCommand;
+import org.eclipse.emf.cdo.spi.server.InternalRepository;
+
+import org.eclipse.net4j.util.factory.ProductCreationException;
+import org.eclipse.net4j.util.io.IOUtil;
+
+import java.io.FileOutputStream;
+import java.io.OutputStream;
+
+/**
+ * @author Eike Stepper
+ */
+public class ExportHbmCommand extends CDOCommand.WithRepository
+{
+ public static final String NAME = "exporthbm";
+
+ public ExportHbmCommand()
+ {
+ super(NAME, "export generated hibernate mapping to a file", parameter("export-file"));
+ }
+
+ @Override
+ public void execute(InternalRepository repository, String[] args) throws Exception
+ {
+ String exportFile = args[0];
+ OutputStream out = null;
+
+ try
+ {
+ out = new FileOutputStream(exportFile);
+
+ final HibernateStore store = (HibernateStore)repository.getStore();
+ final String mapping = store.getMappingXml();
+
+ out.write(mapping.getBytes());
+ println("Hibernate mapping exported");
+ }
+ finally
+ {
+ IOUtil.close(out);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ public static class Factory extends CDOCommand.Factory
+ {
+ public Factory()
+ {
+ super(NAME);
+ }
+
+ @Override
+ public CDOCommand create(String description) throws ProductCreationException
+ {
+ return new ExportHbmCommand();
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/HibernateCommandProvider.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/HibernateCommandProvider.java
deleted file mode 100644
index 7072953f18..0000000000
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/HibernateCommandProvider.java
+++ /dev/null
@@ -1,157 +0,0 @@
-/*
- * Copyright (c) 2012 Eike Stepper (Berlin, Germany) and others.
- * 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:
- * Erdal Karaca - initial API and implementation
- */
-package org.eclipse.emf.cdo.server.hibernate.internal.teneo.bundle;
-
-import org.eclipse.emf.cdo.server.internal.hibernate.HibernateStore;
-import org.eclipse.emf.cdo.spi.server.InternalRepository;
-import org.eclipse.emf.cdo.spi.server.RepositoryFactory;
-
-import org.eclipse.net4j.util.container.IPluginContainer;
-import org.eclipse.net4j.util.io.IOUtil;
-
-import org.eclipse.osgi.framework.console.CommandInterpreter;
-import org.eclipse.osgi.framework.console.CommandProvider;
-
-import org.osgi.framework.BundleContext;
-
-import java.io.FileOutputStream;
-import java.io.OutputStream;
-
-/**
- * Provides a command to export the hbm file directly from the osgi prompt.
- *
- * See:
- *
- * https://bugs.eclipse.org/bugs/show_bug.cgi?id=378797
- *
- * Exports the hbm through the following osgi command:
- * hibernate mapping repo1 /tmp/hbm.xml
- *
- * @author Erdal Karaca
- */
-public class HibernateCommandProvider implements CommandProvider
-{
- private static final String NEW_LINE = "\r\n"; //$NON-NLS-1$
-
- private static final String INDENT = " "; //$NON-NLS-1$
-
- public HibernateCommandProvider(BundleContext bundleContext)
- {
- bundleContext.registerService(CommandProvider.class.getName(), this, null);
- }
-
- public String getHelp()
- {
- StringBuffer buffer = new StringBuffer();
- buffer.append("---CDO Hibernate commands---" + NEW_LINE);
- buffer.append(INDENT + "hibernate mapping - export generated hibernate file" + NEW_LINE);
- return buffer.toString();
- }
-
- public Object _hibernate(CommandInterpreter interpreter)
- {
- try
- {
- String cmd = interpreter.nextArgument();
- if ("mapping".equals(cmd))
- {
- exportHbm(interpreter);
- return null;
- }
-
- interpreter.println(getHelp());
- }
- catch (CommandException ex)
- {
- interpreter.println(ex.getMessage());
- }
- catch (Exception ex)
- {
- interpreter.printStackTrace(ex);
- }
-
- return null;
- }
-
- private void exportHbm(CommandInterpreter interpreter) throws Exception
- {
- String syntax = "Syntax: hibernate mapping <repository-name> <export-file>";
- InternalRepository repository = getRepository(interpreter, syntax);
- String exportFile = nextArgument(interpreter, syntax);
- final HibernateStore store = (HibernateStore)repository.getStore();
- OutputStream out = null;
-
- try
- {
- out = new FileOutputStream(exportFile);
- final String mapping = store.getMappingXml();
- out.write(mapping.getBytes());
- interpreter.println("Hibernate mapping exported");
- }
- finally
- {
- IOUtil.close(out);
- }
- }
-
- private String nextArgument(CommandInterpreter interpreter, String syntax)
- {
- String argument = interpreter.nextArgument();
- if (argument == null && syntax != null)
- {
- throw new CommandException(syntax);
- }
-
- return argument;
- }
-
- private InternalRepository getRepository(CommandInterpreter interpreter, String syntax)
- {
- String repositoryName = nextArgument(interpreter, syntax);
- InternalRepository repository = getRepository(repositoryName);
- if (repository == null)
- {
- throw new CommandException("Repository not found: " + repositoryName);
- }
-
- return repository;
- }
-
- private InternalRepository getRepository(String name)
- {
- for (Object element : IPluginContainer.INSTANCE.getElements(RepositoryFactory.PRODUCT_GROUP))
- {
- if (element instanceof InternalRepository)
- {
- InternalRepository repository = (InternalRepository)element;
- if (repository.getName().equals(name))
- {
- return repository;
- }
- }
- }
-
- return null;
- }
-
- /**
- * @author Eike Stepper
- */
- private static final class CommandException extends RuntimeException
- {
- private static final long serialVersionUID = 1L;
-
- public CommandException(String message)
- {
- super(message);
- }
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/OM.java b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/OM.java
index b5d91f807c..236217d410 100644
--- a/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/OM.java
+++ b/plugins/org.eclipse.emf.cdo.server.hibernate.teneo/src/org/eclipse/emf/cdo/server/hibernate/internal/teneo/bundle/OM.java
@@ -41,12 +41,5 @@ public abstract class OM
{
super(BUNDLE);
}
-
- @Override
- protected void doStart() throws Exception
- {
- new HibernateCommandProvider(bundleContext);
- }
}
-
}

Back to the top