diff options
3 files changed, 47 insertions, 43 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java index d027b70667..1ca20eba2b 100644 --- a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java +++ b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStore.java @@ -32,6 +32,8 @@ import com.db4o.config.Configuration; import com.db4o.query.Query; import com.db4o.reflect.jdk.JdkReflector; +import java.io.File; +import java.io.IOException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -62,8 +64,8 @@ public class DB4OStore extends LongIDStore implements IDB4OStore public DB4OStore(String storeLocation, int port) { - super(IDB4OStore.TYPE, set(ChangeFormat.REVISION, ChangeFormat.DELTA), set(RevisionTemporality.NONE, - RevisionTemporality.AUDITING), set(RevisionParallelism.NONE, RevisionParallelism.BRANCHING)); + super(IDB4OStore.TYPE, set(ChangeFormat.REVISION), set(RevisionTemporality.NONE, RevisionTemporality.AUDITING), + set(RevisionParallelism.NONE, RevisionParallelism.BRANCHING)); // setRevisionTemporality(RevisionTemporality.AUDITING); // setRevisionParallelism(RevisionParallelism.BRANCHING); @@ -174,8 +176,22 @@ public class DB4OStore extends LongIDStore implements IDB4OStore { configuration = createServerConfiguration(); } + { + File file = new File(getStoreLocation()); + if (!file.exists()) + { + try + { + file.createNewFile(); + } + catch (IOException ex) + { + throw new RuntimeException(ex); + } + } + } - server = Db4o.openServer(configuration, storeLocation, port); + server = Db4o.openServer(configuration, getStoreLocation(), getPort()); } protected void tearDownObjectServer() @@ -273,6 +289,10 @@ public class DB4OStore extends LongIDStore implements IDB4OStore { Configuration config = Db4o.newConfiguration(); config.reflectWith(new JdkReflector(getClass().getClassLoader())); + config.objectClass(DB4ORevision.class).objectField("id").indexed(true); + config.objectClass(DB4OPackageUnit.class).objectField("id").indexed(true); + config.objectClass(DB4OIdentifiableObject.class).objectField("id").indexed(true); + config.objectClass(DB4OCommitInfo.class).objectField("timeStamp").indexed(true); return config; } @@ -339,12 +359,10 @@ public class DB4OStore extends LongIDStore implements IDB4OStore public static void removeRevision(ObjectContainer container, CDOID id) { DB4ORevision revision = getRevision(container, id); - if (revision == null) + if (revision != null) { - throw new IllegalArgumentException("Revision with ID " + id + " not found"); + container.delete(revision); } - - container.delete(revision); } /** diff --git a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreAccessor.java index 3198a794d1..9968ef6df5 100644 --- a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreAccessor.java +++ b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreAccessor.java @@ -595,7 +595,10 @@ public class DB4OStoreAccessor extends LongIDStoreAccessor implements IStoreAcce try { + long start = System.currentTimeMillis(); getObjectContainer().commit(); + long end = System.currentTimeMillis(); + OM.LOG.debug("Commit took -> " + (end - start) + " milliseconds"); } catch (Exception e) { @@ -623,10 +626,13 @@ public class DB4OStoreAccessor extends LongIDStoreAccessor implements IStoreAcce try { + long start = System.currentTimeMillis(); for (InternalCDORevision revision : revisions) { writeRevision(revision, monitor.fork()); } + long end = System.currentTimeMillis(); + OM.LOG.debug("Storage of " + revisions.length + " revisions took: " + (end - start) + " milliseconds"); } finally { @@ -657,17 +663,17 @@ public class DB4OStoreAccessor extends LongIDStoreAccessor implements IStoreAcce } } + // TODO removal of previous version implies query, this should be optimized + + long start = System.currentTimeMillis(); // If revision is in the store, remove old, store new - ObjectContainer objectContainer = getObjectContainer(); + // Remove previous version CDOID id = revision.getID(); - DB4ORevision revisionAlreadyInStore = DB4OStore.getRevision(objectContainer, id); - if (revisionAlreadyInStore != null) - { - DB4OStore.removeRevision(objectContainer, id); - } - + DB4OStore.removeRevision(getObjectContainer(), id); DB4ORevision primitiveRevision = DB4ORevision.getDB4ORevision(revision); writeObject(primitiveRevision, monitor); + long end = System.currentTimeMillis(); + OM.LOG.debug("Writing revision " + id + " took: " + (end - start) + " milliseconds"); } finally { diff --git a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreFactory.java b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreFactory.java index 9bc5696064..0926076851 100644 --- a/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreFactory.java +++ b/plugins/org.eclipse.emf.cdo.server.db4o/src/org/eclipse/emf/cdo/server/internal/db4o/DB4OStoreFactory.java @@ -14,9 +14,9 @@ import org.eclipse.emf.cdo.server.IStore; import org.eclipse.emf.cdo.server.IStoreFactory; import org.eclipse.emf.cdo.server.db4o.IDB4OStore; import org.eclipse.emf.cdo.server.internal.db4o.bundle.OM; +import org.eclipse.emf.cdo.spi.server.RepositoryConfigurator; import org.w3c.dom.Element; -import org.w3c.dom.NodeList; import java.util.Map; @@ -25,6 +25,10 @@ import java.util.Map; */ public class DB4OStoreFactory implements IStoreFactory { + private static final String PROPERTY_PORT = "port"; + + private static final String PROPERTY_PATH = "path"; + public DB4OStoreFactory() { } @@ -38,8 +42,10 @@ public class DB4OStoreFactory implements IStoreFactory { try { - String dataFilePath = getFilePath(storeConfig); - int port = getPort(storeConfig); + Map<String, String> properties = RepositoryConfigurator.getProperties(storeConfig, 1); + String dataFilePath = properties.get(PROPERTY_PATH); + String portString = properties.get(PROPERTY_PORT); + int port = portString != null ? Integer.parseInt(portString) : 1677; return new DB4OStore(dataFilePath, port); } catch (Exception ex) @@ -49,30 +55,4 @@ public class DB4OStoreFactory implements IStoreFactory return null; } - - protected int getPort(Element storeConfig) - { - NodeList ooConfig = storeConfig.getElementsByTagName("ooData"); //$NON-NLS-1$ - Element ooElement = (Element)ooConfig.item(0); - String port = ooElement.getAttribute("port"); //$NON-NLS-1$ - if (port == null) - { - throw new IllegalArgumentException("DB4O port not defined"); //$NON-NLS-1$ - } - - return Integer.parseInt(port); - } - - protected String getFilePath(Element storeConfig) - { - NodeList ooConfig = storeConfig.getElementsByTagName("ooData"); //$NON-NLS-1$ - Element ooElement = (Element)ooConfig.item(0); - String filePath = ooElement.getAttribute("path"); //$NON-NLS-1$ - if (filePath == null) - { - throw new IllegalArgumentException("DB4O file path not defined"); //$NON-NLS-1$ - } - - return filePath; - } } |