Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-11-09 05:56:34 -0500
committerEike Stepper2008-11-09 05:56:34 -0500
commitf6a61fa4e90ac8bae599d1147d772b5b2a9e9b69 (patch)
treed9ca347a9da50750cc5075548458a8b805cd4486
parent39f2687d394450984180a8624cd220dc57ef1a22 (diff)
downloadcdo-f6a61fa4e90ac8bae599d1147d772b5b2a9e9b69.tar.gz
cdo-f6a61fa4e90ac8bae599d1147d772b5b2a9e9b69.tar.xz
cdo-f6a61fa4e90ac8bae599d1147d772b5b2a9e9b69.zip
[253664] [DB] Add JDBC connection wrappers
https://bugs.eclipse.org/bugs/show_bug.cgi?id=253664
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/META-INF/MANIFEST.MF3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/plugin.xml9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/schema/delegateProviders.exsd109
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java57
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java17
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IClassMapping.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java13
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegate.java112
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegateProvider.java27
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java222
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java17
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java151
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java23
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalClassMapping.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NoClassMapping.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ObjectTypeCache.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java182
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootClassMapping.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ToOneReferenceMapping.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalClassMapping.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/AbstractJDBCDelegate.java353
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/JDBCPerformanceMeasurementWrapper.java200
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/NonPreparedStatementJDBCDelegate.java283
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/NonPreparedStatementJDBCDelegateProvider.java30
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IConstants.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java77
30 files changed, 1412 insertions, 538 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/META-INF/MANIFEST.MF b/plugins/org.eclipse.emf.cdo.server.db/META-INF/MANIFEST.MF
index 0e739318c8..99511812bf 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/META-INF/MANIFEST.MF
+++ b/plugins/org.eclipse.emf.cdo.server.db/META-INF/MANIFEST.MF
@@ -14,4 +14,5 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="[3.4.0,4.0.0)",
org.eclipse.emf.cdo.server;bundle-version="[2.0.0,3.0.0)";visibility:=reexport
Export-Package: org.eclipse.emf.cdo.server.db;version="2.0.0",
org.eclipse.emf.cdo.server.internal.db;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests",
- org.eclipse.emf.cdo.server.internal.db.bundle;version="2.0.0";x-internal:=true
+ org.eclipse.emf.cdo.server.internal.db.bundle;version="2.0.0";x-internal:=true,
+ org.eclipse.emf.cdo.server.internal.db.jdbc;version="2.0.0";x-friends:="org.eclipse.emf.cdo.tests"
diff --git a/plugins/org.eclipse.emf.cdo.server.db/plugin.xml b/plugins/org.eclipse.emf.cdo.server.db/plugin.xml
index eb54dcd14c..1daf957a0f 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.server.db/plugin.xml
@@ -18,6 +18,7 @@
<plugin>
<extension-point id="mappingStrategies" name="CDO Mapping Strategies" schema="schema/mappingStrategies.exsd"/>
+ <extension-point id="jdbcDelegateProviders" name="CDO JDBC Delegate Providers" schema="schema/delegateProviders.exsd"/>
<extension
point="org.eclipse.emf.cdo.server.storeFactories">
@@ -38,5 +39,13 @@
type="vertical">
</mappingStrategy>
</extension>
+
+ <extension
+ point="org.eclipse.emf.cdo.server.db.jdbcDelegateProviders">
+ <jdbcDelegateProvider
+ class="org.eclipse.emf.cdo.server.internal.db.jdbc.NonPreparedStatementJDBCDelegateProvider"
+ type="nonPreparedStatement">
+ </jdbcDelegateProvider>
+ </extension>
</plugin>
diff --git a/plugins/org.eclipse.emf.cdo.server.db/schema/delegateProviders.exsd b/plugins/org.eclipse.emf.cdo.server.db/schema/delegateProviders.exsd
new file mode 100644
index 0000000000..048126191d
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/schema/delegateProviders.exsd
@@ -0,0 +1,109 @@
+<?xml version='1.0' encoding='UTF-8'?>
+<!-- Schema file written by PDE -->
+<schema targetNamespace="org.eclipse.emf.cdo.server.db" xmlns="http://www.w3.org/2001/XMLSchema">
+<annotation>
+ <appinfo>
+ <meta.schema plugin="org.eclipse.emf.cdo.server.db" id="jdbcDelegateProviders" name="CDO JDBC Delegate Providers"/>
+ </appinfo>
+ <documentation>
+ [Enter description of this extension point.]
+ </documentation>
+ </annotation>
+
+ <element name="extension">
+ <annotation>
+ <appinfo>
+ <meta.element />
+ </appinfo>
+ </annotation>
+ <complexType>
+ <sequence>
+ <element ref="jdbcDelegateProvider" minOccurs="1" maxOccurs="unbounded"/>
+ </sequence>
+ <attribute name="point" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="id" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="name" type="string">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute translatable="true"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <element name="jdbcDelegateProvider">
+ <complexType>
+ <attribute name="type" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ </annotation>
+ </attribute>
+ <attribute name="class" type="string" use="required">
+ <annotation>
+ <documentation>
+
+ </documentation>
+ <appinfo>
+ <meta.attribute kind="java" basedOn=":org.eclipse.emf.cdo.server.db.IJDBCDelegateProvider"/>
+ </appinfo>
+ </annotation>
+ </attribute>
+ </complexType>
+ </element>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="since"/>
+ </appinfo>
+ <documentation>
+ [Enter the first release in which this extension point appears.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="examples"/>
+ </appinfo>
+ <documentation>
+ [Enter extension point usage example here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="apiInfo"/>
+ </appinfo>
+ <documentation>
+ [Enter API information here.]
+ </documentation>
+ </annotation>
+
+ <annotation>
+ <appinfo>
+ <meta.section type="implementation"/>
+ </appinfo>
+ <documentation>
+ [Enter information about supplied implementation of this extension point.]
+ </documentation>
+ </annotation>
+
+
+</schema>
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
index a0ab2f02b7..6aee4ee545 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.server.db;
import org.eclipse.emf.cdo.server.internal.db.DBStore;
import org.eclipse.emf.cdo.server.internal.db.HorizontalMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
+import org.eclipse.emf.cdo.server.internal.db.jdbc.NonPreparedStatementJDBCDelegateProvider;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.IDBConnectionProvider;
@@ -29,19 +30,31 @@ import org.eclipse.core.runtime.Platform;
*/
public final class CDODBUtil
{
- public static final String EXT_POINT = "mappingStrategies";
+ /**
+ * @since 2.0
+ */
+ public static final String EXT_POINT_MAPPING_STRATEGIES = "mappingStrategies";
+
+ /**
+ * @since 2.0
+ */
+ public static final String EXT_POINT_JDBC_DELEGATE_PROVIDERS = "jdbcDelegateProviders";
private CDODBUtil()
{
}
+ /**
+ * @since 2.0
+ */
public static IDBStore createStore(IMappingStrategy mappingStrategy, IDBAdapter dbAdapter,
- IDBConnectionProvider dbConnectionProvider)
+ IDBConnectionProvider dbConnectionProvider, IJDBCDelegateProvider delegateProvider)
{
DBStore store = new DBStore();
store.setMappingStrategy(mappingStrategy);
store.setDbAdapter(dbAdapter);
store.setDbConnectionProvider(dbConnectionProvider);
+ store.setJDBCDelegateProvider(delegateProvider);
mappingStrategy.setStore(store);
return store;
}
@@ -52,6 +65,14 @@ public final class CDODBUtil
}
/**
+ * @since 2.0
+ */
+ public static IJDBCDelegateProvider createNonPreparedStatementJDBCDelegateProvider()
+ {
+ return new NonPreparedStatementJDBCDelegateProvider();
+ }
+
+ /**
* Can only be used when Eclipse is running. In standalone scenarios create the mapping strategy instance by directly
* calling the constructor of the mapping strategy class.
*
@@ -60,7 +81,7 @@ public final class CDODBUtil
public static IMappingStrategy createMappingStrategy(String type)
{
IExtensionRegistry registry = Platform.getExtensionRegistry();
- IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, EXT_POINT);
+ IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID, EXT_POINT_MAPPING_STRATEGIES);
for (final IConfigurationElement element : elements)
{
if ("mappingStrategy".equals(element.getName()))
@@ -83,6 +104,36 @@ public final class CDODBUtil
return null;
}
+ /**
+ * @since 2.0
+ */
+ public static IJDBCDelegateProvider createDelegateProvider(String type)
+ {
+ IExtensionRegistry registry = Platform.getExtensionRegistry();
+ IConfigurationElement[] elements = registry.getConfigurationElementsFor(OM.BUNDLE_ID,
+ EXT_POINT_JDBC_DELEGATE_PROVIDERS);
+ for (final IConfigurationElement element : elements)
+ {
+ if ("jdbcDelegateProvider".equals(element.getName()))
+ {
+ String typeAttr = element.getAttribute("type");
+ if (ObjectUtil.equals(typeAttr, type))
+ {
+ try
+ {
+ return (IJDBCDelegateProvider)element.createExecutableExtension("class");
+ }
+ catch (CoreException ex)
+ {
+ throw WrappedException.wrap(ex);
+ }
+ }
+ }
+ }
+
+ return null;
+ }
+
// public static CDODBStoreManager getStoreManager(IDBAdapter dbAdapter,
// DataSource dataSource)
// {
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java
index 6a2f98fccb..9d88e7d6fc 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IAttributeMapping.java
@@ -10,7 +10,7 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.db;
-import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.net4j.db.ddl.IDBField;
@@ -23,7 +23,18 @@ public interface IAttributeMapping extends IFeatureMapping
{
public IDBField getField();
- public void appendValue(StringBuilder builder, InternalCDORevision revision);
+ /**
+ * @since 2.0
+ */
+ public void appendValue(StringBuilder builder, CDORevision revision);
- public void extractValue(ResultSet resultSet, int column, InternalCDORevision revision);
+ /**
+ * @since 2.0
+ */
+ public void extractValue(ResultSet resultSet, int column, CDORevision revision);
+
+ /**
+ * @since 2.0
+ */
+ public Object getRevisionValue(CDORevision revision);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IClassMapping.java
index 93f70f1c6c..174940d1a4 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IClassMapping.java
@@ -36,6 +36,11 @@ public interface IClassMapping
/**
* @since 2.0
*/
+ public boolean hasFullRevisionInfo();
+
+ /**
+ * @since 2.0
+ */
public IFeatureMapping getFeatureMapping(CDOFeature feature);
public List<IAttributeMapping> getAttributeMappings();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
index 86205ebf43..76266435da 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
@@ -13,10 +13,6 @@ package org.eclipse.emf.cdo.server.db;
import org.eclipse.emf.cdo.common.model.CDOClassRef;
import org.eclipse.emf.cdo.server.IStoreAccessor;
-import java.sql.Connection;
-import java.sql.PreparedStatement;
-import java.sql.Statement;
-
/**
* @author Eike Stepper
* @noimplement This interface is not intended to be implemented by clients.
@@ -30,9 +26,8 @@ public interface IDBStoreAccessor extends IStoreAccessor
*/
public CDOClassRef readClassRef(int classID);
- public Connection getConnection();
-
- public Statement getStatement();
-
- public PreparedStatement prepareStatement(String sql);
+ /**
+ * @since 2.0
+ */
+ public IJDBCDelegate getJDBCDelegate();
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegate.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegate.java
new file mode 100644
index 0000000000..08baa72678
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegate.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:
+ * Stefan Winkler - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.server.db;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
+import org.eclipse.emf.cdo.server.internal.db.jdbc.AbstractJDBCDelegate;
+
+import org.eclipse.net4j.db.IDBConnectionProvider;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.Statement;
+import java.util.List;
+
+/**
+ * Interface for all JDBC related activities regarding revisions.
+ *
+ * @author Stefan Winkler
+ * @since 2.0
+ * @noimplement This interface is not intended to be implemented by clients. Please extend the abstract class
+ * {@link AbstractJDBCDelegate} instead.
+ */
+public interface IJDBCDelegate
+{
+ /**
+ * Insert a reference row. Note: this is likely to be replaced by an implementation that supports storing multiple
+ * references in one batch.
+ */
+ public void insertReference(CDORevision sourceRevision, int index, CDOID targetId, IReferenceMapping referenceMapping);
+
+ /**
+ * Insert an attribute row.
+ */
+ public void insertAttributes(CDORevision revision, IClassMapping classMapping);
+
+ /**
+ * Set the revised date of a specific revision's previous version.
+ */
+ public void updateRevised(CDORevision revision, IClassMapping classMapping);
+
+ /**
+ * Set the revised date of all unrevised rows of cdoid
+ */
+ public void updateRevised(CDOID cdoid, long revised, IClassMapping classMapping);
+
+ /**
+ * Select a revision's attributes
+ */
+ public void selectRevisionAttributes(CDORevision revision, IClassMapping classMapping, String where);
+
+ /**
+ * Select a revision's references (or a part thereof)
+ */
+ public void selectRevisionReferences(CDORevision revision, IReferenceMapping referenceMapping, int referenceChunk);
+
+ /**
+ * Select a revision's reference's chunks
+ */
+ public void selectRevisionReferenceChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks,
+ IReferenceMapping referenceMapping, String where);
+
+ /**
+ * Get the connection object of this JDBC delegate
+ */
+ public Connection getConnection();
+
+ /**
+ * Get the one omnipresent statement object of this JDBC delegate
+ */
+ public Statement getStatement();
+
+ /**
+ * Do a commit on the JDBC connection.
+ */
+ public void commit();
+
+ /**
+ * Do a rollback on the JDBC connection.
+ */
+ public void rollback();
+
+ /**
+ * Get a prepared statement. The caller is responsible of closing it.
+ */
+ public PreparedStatement getPreparedStatement(String sql);
+
+ /**
+ * Initialize the connection. This must be called once and only once immediately after creating.
+ *
+ * @param connectionProvider
+ * a provider for the DB connection
+ * @param readOnly
+ * if this is true, all accessors of this instance must not call directly or indirectly any writing
+ * operations. Setting readOnly to true leads to the connection's autoCommit property set to true.
+ */
+ public void initConnection(IDBConnectionProvider connectionProvider, boolean readOnly);
+
+ /**
+ * Release the DB resources. This has to be called when the delegate is no longer to be used.
+ */
+ public void release();
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegateProvider.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegateProvider.java
new file mode 100644
index 0000000000..4fca9da91d
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegateProvider.java
@@ -0,0 +1,27 @@
+/***************************************************************************
+ * 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:
+ * Stefan Winkler - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.server.db;
+
+/**
+ * Wraps the creation of JDBCDelegates.
+ *
+ * @author Stefan Winkler
+ * @since 2.0
+ */
+public interface IJDBCDelegateProvider
+{
+ /**
+ * Creates and returns a JDBC delegate.
+ * <p>
+ * This is part of the org.eclipse.emf.cdo.server.db.jdbcDelegateProviders extension point.
+ */
+ public IJDBCDelegate getJDBCDelegate();
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java
index 926dfde229..5c341e301a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IReferenceMapping.java
@@ -27,6 +27,11 @@ public interface IReferenceMapping extends IFeatureMapping
/**
* @since 2.0
*/
+ public boolean isWithFeature();
+
+ /**
+ * @since 2.0
+ */
public void writeReference(IDBStoreAccessor accessor, CDORevision revision);
/**
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java
index fb5271ff62..04a3d9b198 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/AttributeMapping.java
@@ -12,6 +12,7 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOFeature;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.db.IAttributeMapping;
import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
@@ -40,20 +41,20 @@ public abstract class AttributeMapping extends FeatureMapping implements IAttrib
return field;
}
- public void appendValue(StringBuilder builder, InternalCDORevision revision)
+ public void appendValue(StringBuilder builder, CDORevision revision)
{
IDBAdapter dbAdapter = getDBAdapter();
Object value = getRevisionValue(revision);
dbAdapter.appendValue(builder, field, value);
}
- protected Object getRevisionValue(InternalCDORevision revision)
+ public Object getRevisionValue(CDORevision revision)
{
CDOFeature feature = getFeature();
- return revision.getValue(feature);
+ return ((InternalCDORevision)revision).getValue(feature);
}
- public void extractValue(ResultSet resultSet, int column, InternalCDORevision revision)
+ public void extractValue(ResultSet resultSet, int column, CDORevision revision)
{
try
{
@@ -63,7 +64,7 @@ public abstract class AttributeMapping extends FeatureMapping implements IAttrib
value = null;
}
- revision.setValue(getFeature(), value);
+ ((InternalCDORevision)revision).setValue(getFeature(), value);
}
catch (SQLException ex)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java
index 65ae811a0b..d09ffbf406 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java
@@ -11,7 +11,6 @@
package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOClass;
import org.eclipse.emf.cdo.common.model.CDOFeature;
import org.eclipse.emf.cdo.common.model.CDOType;
@@ -22,22 +21,16 @@ import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IFeatureMapping;
import org.eclipse.emf.cdo.server.db.IReferenceMapping;
-import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
-import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBIndex;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ImplementationError;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
@@ -48,8 +41,6 @@ import java.util.Set;
*/
public abstract class ClassMapping implements IClassMapping
{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ClassMapping.class);
-
private MappingStrategy mappingStrategy;
private CDOClass cdoClass;
@@ -62,8 +53,6 @@ public abstract class ClassMapping implements IClassMapping
private List<IReferenceMapping> referenceMappings;
- private String selectPrefix;
-
public ClassMapping(MappingStrategy mappingStrategy, CDOClass cdoClass, CDOFeature[] features)
{
this.mappingStrategy = mappingStrategy;
@@ -105,8 +94,6 @@ public abstract class ClassMapping implements IClassMapping
// }
// }
}
-
- selectPrefix = createSelectPrefix();
}
public MappingStrategy getMappingStrategy()
@@ -146,46 +133,6 @@ public abstract class ClassMapping implements IClassMapping
}
}
- protected void appendRevisionInfos(StringBuilder builder, InternalCDORevision revision, boolean full)
- {
- builder.append(CDOIDUtil.getLong(revision.getID()));
- builder.append(", ");
- builder.append(revision.getVersion());
- if (full)
- {
- builder.append(", ");
- builder.append(ServerInfo.getDBID(revision.getCDOClass()));
- builder.append(", ");
- builder.append(revision.getCreated());
- builder.append(", ");
- builder.append(revision.getRevised());
- builder.append(", ");
- builder.append(CDOIDUtil.getLong(revision.getResourceID()));
- builder.append(", ");
- builder.append(CDOIDUtil.getLong((CDOID)revision.getContainerID()));
- builder.append(", ");
- builder.append(revision.getContainingFeatureID());
- }
- }
-
- protected int sqlUpdate(IDBStoreAccessor accessor, String sql) throws DBException
- {
- if (TRACER.isEnabled())
- {
- TRACER.trace(sql);
- }
-
- try
- {
- Statement statement = accessor.getStatement();
- return statement.executeUpdate(sql);
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- }
-
protected IDBTable addTable(String name)
{
IDBTable table = mappingStrategy.getStore().getDBSchema().addTable(name);
@@ -222,51 +169,6 @@ public abstract class ClassMapping implements IClassMapping
return store.getDBAdapter();
}
- protected String createSelectPrefix()
- {
- StringBuilder builder = new StringBuilder();
- builder.append("SELECT ");
-
- if (hasFullRevisionInfo())
- {
- builder.append(CDODBSchema.ATTRIBUTES_VERSION);
- builder.append(", ");
- builder.append(CDODBSchema.ATTRIBUTES_CREATED);
- builder.append(", ");
- builder.append(CDODBSchema.ATTRIBUTES_REVISED);
- builder.append(", ");
- builder.append(CDODBSchema.ATTRIBUTES_RESOURCE);
- builder.append(", ");
- builder.append(CDODBSchema.ATTRIBUTES_CONTAINER);
- builder.append(", ");
- builder.append(CDODBSchema.ATTRIBUTES_FEATURE);
- }
- else
- {
- if (attributeMappings == null)
- {
- // Only references
- return null;
- }
- }
-
- if (attributeMappings != null)
- {
- for (IAttributeMapping attributeMapping : attributeMappings)
- {
- builder.append(", ");
- builder.append(attributeMapping.getField());
- }
- }
-
- builder.append(" FROM ");
- builder.append(table);
- builder.append(" WHERE ");
- builder.append(CDODBSchema.ATTRIBUTES_ID);
- builder.append("=");
- return builder.toString();
- }
-
public IFeatureMapping getFeatureMapping(CDOFeature feature)
{
if (feature.isReference() && mappingStrategy.getToMany() != ToMany.LIKE_ATTRIBUTES)
@@ -416,8 +318,6 @@ public abstract class ClassMapping implements IClassMapping
return cdoFeature;
}
- protected abstract boolean hasFullRevisionInfo();
-
public void writeRevision(IDBStoreAccessor accessor, CDORevision revision)
{
if (revision.getVersion() > 1 && hasFullRevisionInfo())
@@ -451,64 +351,19 @@ public abstract class ClassMapping implements IClassMapping
}
}
- protected void writeRevisedRow(IDBStoreAccessor accessor, InternalCDORevision revision)
- {
- StringBuilder builder = new StringBuilder();
- builder.append("UPDATE ");
- builder.append(table);
- builder.append(" SET ");
- builder.append(CDODBSchema.ATTRIBUTES_REVISED);
- builder.append("=");
- builder.append(revision.getCreated() - 1);
- builder.append(" WHERE ");
- builder.append(CDODBSchema.ATTRIBUTES_ID);
- builder.append("=");
- builder.append(CDOIDUtil.getLong(revision.getID()));
- builder.append(" AND ");
- builder.append(CDODBSchema.ATTRIBUTES_VERSION);
- builder.append("=");
- builder.append(revision.getVersion() - 1);
- sqlUpdate(accessor, builder.toString());
- }
-
- protected void writeRevisedRow(IDBStoreAccessor accessor, CDOID id, long revised)
- {
- StringBuilder builder = new StringBuilder();
- builder.append("UPDATE ");
- builder.append(table);
- builder.append(" SET ");
- builder.append(CDODBSchema.ATTRIBUTES_REVISED);
- builder.append("=");
- builder.append(revised);
- builder.append(" WHERE ");
- builder.append(CDODBSchema.ATTRIBUTES_ID);
- builder.append("=");
- builder.append(CDOIDUtil.getLong(id));
- builder.append(" AND ");
- builder.append(CDODBSchema.ATTRIBUTES_REVISED);
- builder.append("=0");
- sqlUpdate(accessor, builder.toString());
- }
-
- protected void writeAttributes(IDBStoreAccessor accessor, InternalCDORevision revision)
- {
- StringBuilder builder = new StringBuilder();
- builder.append("INSERT INTO ");
- builder.append(table);
- builder.append(" VALUES (");
- appendRevisionInfos(builder, revision, hasFullRevisionInfo());
-
- if (attributeMappings != null)
- {
- for (IAttributeMapping attributeMapping : attributeMappings)
- {
- builder.append(", ");
- attributeMapping.appendValue(builder, revision);
- }
- }
+ protected final void writeRevisedRow(IDBStoreAccessor accessor, InternalCDORevision revision)
+ {
+ accessor.getJDBCDelegate().updateRevised(revision, this);
+ }
- builder.append(")");
- sqlUpdate(accessor, builder.toString());
+ protected final void writeRevisedRow(IDBStoreAccessor accessor, CDOID id, long revised)
+ {
+ accessor.getJDBCDelegate().updateRevised(id, revised, this);
+ }
+
+ protected final void writeAttributes(IDBStoreAccessor accessor, InternalCDORevision revision)
+ {
+ accessor.getJDBCDelegate().insertAttributes(revision, this);
}
protected void writeReferences(IDBStoreAccessor accessor, InternalCDORevision revision)
@@ -549,58 +404,9 @@ public abstract class ClassMapping implements IClassMapping
}
}
- protected void readAttributes(IDBStoreAccessor accessor, InternalCDORevision revision, String where)
+ protected final void readAttributes(IDBStoreAccessor accessor, InternalCDORevision revision, String where)
{
- long id = CDOIDUtil.getLong(revision.getID());
- StringBuilder builder = new StringBuilder(selectPrefix);
- builder.append(id);
- builder.append(" AND (");
- builder.append(where);
- builder.append(")");
-
- String sql = builder.toString();
- if (TRACER.isEnabled())
- {
- TRACER.trace(sql);
- }
-
- ResultSet resultSet = null;
-
- try
- {
- resultSet = accessor.getStatement().executeQuery(sql);
- if (!resultSet.next())
- {
- throw new IllegalStateException("Revision not found: " + id);
- }
-
- int i = 0;
- if (hasFullRevisionInfo())
- {
- revision.setVersion(resultSet.getInt(++i));
- revision.setCreated(resultSet.getLong(++i));
- revision.setRevised(resultSet.getLong(++i));
- revision.setResourceID(CDOIDUtil.createLong(resultSet.getLong(++i)));
- revision.setContainerID(CDOIDUtil.createLong(resultSet.getLong(++i)));
- revision.setContainingFeatureID(resultSet.getInt(++i));
- }
-
- if (attributeMappings != null)
- {
- for (IAttributeMapping attributeMapping : attributeMappings)
- {
- attributeMapping.extractValue(resultSet, ++i, revision);
- }
- }
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- DBUtil.close(resultSet);
- }
+ accessor.getJDBCDelegate().selectRevisionAttributes(revision, this, where);
}
protected void readReferences(IDBStoreAccessor accessor, InternalCDORevision revision, int referenceChunk)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
index 899a1644fc..53f2bb89b2 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.server.StoreThreadLocal;
import org.eclipse.emf.cdo.server.db.IDBStore;
+import org.eclipse.emf.cdo.server.db.IJDBCDelegateProvider;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -71,6 +72,8 @@ public class DBStore extends LongIDStore implements IDBStore
@ExcludeFromDump
private transient int nextFeatureID;
+ private IJDBCDelegateProvider jdbcDelegateProvider;
+
public DBStore()
{
super(TYPE, set(ChangeFormat.REVISION), set(RevisionTemporality.AUDITING), set(RevisionParallelism.NONE));
@@ -105,6 +108,7 @@ public class DBStore extends LongIDStore implements IDBStore
public void setDbConnectionProvider(IDBConnectionProvider dbConnectionProvider)
{
+ // FIXME: need to update provider in JDBCWrapper, too?
this.dbConnectionProvider = dbConnectionProvider;
}
@@ -173,7 +177,6 @@ public class DBStore extends LongIDStore implements IDBStore
{
throw new DBException("No connection from connection provider: " + dbConnectionProvider);
}
-
return connection;
}
@@ -184,7 +187,7 @@ public class DBStore extends LongIDStore implements IDBStore
DBStoreAccessor accessor = (DBStoreAccessor)getWriter(null);
StoreThreadLocal.setAccessor(accessor);
- Connection connection = accessor.getConnection();
+ Connection connection = accessor.getJDBCDelegate().getConnection();
long maxObjectID = mappingStrategy.repairAfterCrash(dbAdapter, connection);
long maxMetaID = DBUtil.selectMaximumLong(connection, CDODBSchema.PACKAGES_RANGE_UB);
@@ -397,4 +400,14 @@ public class DBStore extends LongIDStore implements IDBStore
throw new ImplementationError("Unrecognized CDOType: " + type);
}
+
+ public IJDBCDelegateProvider getJDBCDelegateProvider()
+ {
+ return jdbcDelegateProvider;
+ }
+
+ public void setJDBCDelegateProvider(IJDBCDelegateProvider provider)
+ {
+ jdbcDelegateProvider = provider;
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
index ed56f53b9e..e62ca28e1c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java
@@ -35,6 +35,7 @@ import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.db.IClassMapping;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+import org.eclipse.emf.cdo.server.db.IJDBCDelegate;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.emf.cdo.spi.common.InternalCDOClass;
@@ -49,10 +50,8 @@ import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.collection.CloseableIterator;
import org.eclipse.net4j.util.om.trace.ContextTracer;
-import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
-import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
@@ -65,20 +64,25 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DBStoreAccessor.class);
- private Connection connection;
+ private IJDBCDelegate jdbcDelegate;
- private Statement statement;
+ public IJDBCDelegate getJDBCDelegate()
+ {
+ return jdbcDelegate;
+ }
public DBStoreAccessor(DBStore store, ISession session) throws DBException
{
super(store, session);
- initConnection();
+ jdbcDelegate = store.getJDBCDelegateProvider().getJDBCDelegate();
+ jdbcDelegate.initConnection(store.getDBConnectionProvider(), isReader());
}
public DBStoreAccessor(DBStore store, ITransaction transaction) throws DBException
{
super(store, transaction);
- initConnection();
+ jdbcDelegate = store.getJDBCDelegateProvider().getJDBCDelegate();
+ jdbcDelegate.initConnection(store.getDBConnectionProvider(), isReader());
}
@Override
@@ -87,46 +91,12 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
return (DBStore)super.getStore();
}
- public Connection getConnection()
- {
- return connection;
- }
-
- public Statement getStatement()
- {
- if (statement == null)
- {
- try
- {
- statement = getConnection().createStatement();
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- }
-
- return statement;
- }
-
- public PreparedStatement prepareStatement(String sql)
- {
- try
- {
- return getConnection().prepareStatement(sql);
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- }
-
public DBStoreChunkReader createChunkReader(CDORevision revision, CDOFeature feature)
{
return new DBStoreChunkReader(this, revision, feature);
}
- public Collection<CDOPackageInfo> readPackageInfos()
+ public final Collection<CDOPackageInfo> readPackageInfos()
{
final Collection<CDOPackageInfo> result = new ArrayList<CDOPackageInfo>(0);
IDBRowHandler rowHandler = new IDBRowHandler()
@@ -146,22 +116,23 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
}
};
- DBUtil.select(getConnection(), rowHandler, CDODBSchema.PACKAGES_URI, CDODBSchema.PACKAGES_DYNAMIC,
+ DBUtil.select(jdbcDelegate.getConnection(), rowHandler, CDODBSchema.PACKAGES_URI, CDODBSchema.PACKAGES_DYNAMIC,
CDODBSchema.PACKAGES_RANGE_LB, CDODBSchema.PACKAGES_RANGE_UB, CDODBSchema.PACKAGES_PARENT);
return result;
}
- public void readPackage(CDOPackage cdoPackage)
+ public final void readPackage(CDOPackage cdoPackage)
{
String where = CDODBSchema.PACKAGES_URI.getName() + " = '" + cdoPackage.getPackageURI() + "'";
- Object[] values = DBUtil.select(getConnection(), where, CDODBSchema.PACKAGES_ID, CDODBSchema.PACKAGES_NAME);
+ Object[] values = DBUtil.select(jdbcDelegate.getConnection(), where, CDODBSchema.PACKAGES_ID,
+ CDODBSchema.PACKAGES_NAME);
PackageServerInfo.setDBID(cdoPackage, (Integer)values[0]);
((InternalCDOPackage)cdoPackage).setName((String)values[1]);
readClasses(cdoPackage);
mapPackages(cdoPackage);
}
- protected void readClasses(final CDOPackage cdoPackage)
+ protected final void readClasses(final CDOPackage cdoPackage)
{
IDBRowHandler rowHandler = new IDBRowHandler()
{
@@ -181,11 +152,11 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
};
String where = CDODBSchema.CLASSES_PACKAGE.getName() + "=" + ServerInfo.getDBID(cdoPackage);
- DBUtil.select(getConnection(), rowHandler, where, CDODBSchema.CLASSES_ID, CDODBSchema.CLASSES_CLASSIFIER,
- CDODBSchema.CLASSES_NAME, CDODBSchema.CLASSES_ABSTRACT);
+ DBUtil.select(jdbcDelegate.getConnection(), rowHandler, where, CDODBSchema.CLASSES_ID,
+ CDODBSchema.CLASSES_CLASSIFIER, CDODBSchema.CLASSES_NAME, CDODBSchema.CLASSES_ABSTRACT);
}
- protected void readSuperTypes(final CDOClass cdoClass, int classID)
+ protected final void readSuperTypes(final CDOClass cdoClass, int classID)
{
IDBRowHandler rowHandler = new IDBRowHandler()
{
@@ -199,11 +170,11 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
};
String where = CDODBSchema.SUPERTYPES_TYPE.getName() + "=" + classID;
- DBUtil.select(getConnection(), rowHandler, where, CDODBSchema.SUPERTYPES_SUPERTYPE_PACKAGE,
+ DBUtil.select(jdbcDelegate.getConnection(), rowHandler, where, CDODBSchema.SUPERTYPES_SUPERTYPE_PACKAGE,
CDODBSchema.SUPERTYPES_SUPERTYPE_CLASSIFIER);
}
- protected void readFeatures(final CDOClass cdoClass, int classID)
+ protected final void readFeatures(final CDOClass cdoClass, int classID)
{
IDBRowHandler rowHandler = new IDBRowHandler()
{
@@ -236,22 +207,23 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
};
String where = CDODBSchema.FEATURES_CLASS.getName() + "=" + classID;
- DBUtil.select(getConnection(), rowHandler, where, CDODBSchema.FEATURES_ID, CDODBSchema.FEATURES_FEATURE,
- CDODBSchema.FEATURES_NAME, CDODBSchema.FEATURES_TYPE, CDODBSchema.FEATURES_REFERENCE_PACKAGE,
- CDODBSchema.FEATURES_REFERENCE_CLASSIFIER, CDODBSchema.FEATURES_MANY, CDODBSchema.FEATURES_CONTAINMENT);
+ DBUtil.select(jdbcDelegate.getConnection(), rowHandler, where, CDODBSchema.FEATURES_ID,
+ CDODBSchema.FEATURES_FEATURE, CDODBSchema.FEATURES_NAME, CDODBSchema.FEATURES_TYPE,
+ CDODBSchema.FEATURES_REFERENCE_PACKAGE, CDODBSchema.FEATURES_REFERENCE_CLASSIFIER, CDODBSchema.FEATURES_MANY,
+ CDODBSchema.FEATURES_CONTAINMENT);
}
- public void readPackageEcore(CDOPackage cdoPackage)
+ public final void readPackageEcore(CDOPackage cdoPackage)
{
String where = CDODBSchema.PACKAGES_URI.getName() + " = '" + cdoPackage.getPackageURI() + "'";
- Object[] values = DBUtil.select(getConnection(), where, CDODBSchema.PACKAGES_ECORE);
+ Object[] values = DBUtil.select(jdbcDelegate.getConnection(), where, CDODBSchema.PACKAGES_ECORE);
((InternalCDOPackage)cdoPackage).setEcore((String)values[0]);
}
- public String readPackageURI(int packageID)
+ public final String readPackageURI(int packageID)
{
String where = CDODBSchema.PACKAGES_ID.getName() + "=" + packageID;
- Object[] uri = DBUtil.select(getConnection(), where, CDODBSchema.PACKAGES_URI);
+ Object[] uri = DBUtil.select(jdbcDelegate.getConnection(), where, CDODBSchema.PACKAGES_URI);
return (String)uri[0];
}
@@ -275,10 +247,11 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
return getStore().getMappingStrategy().readObjectType(this, id);
}
- public CDOClassRef readClassRef(int classID)
+ public final CDOClassRef readClassRef(int classID)
{
String where = CDODBSchema.CLASSES_ID.getName() + "=" + classID;
- Object[] res = DBUtil.select(getConnection(), where, CDODBSchema.CLASSES_CLASSIFIER, CDODBSchema.CLASSES_PACKAGE);
+ Object[] res = DBUtil.select(jdbcDelegate.getConnection(), where, CDODBSchema.CLASSES_CLASSIFIER,
+ CDODBSchema.CLASSES_PACKAGE);
int classifierID = (Integer)res[0];
String packageURI = readPackageURI((Integer)res[1]);
return CDOModelUtil.createClassRef(packageURI, classifierID);
@@ -368,33 +341,19 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
{
}
- public void commit()
+ public final void commit()
{
- try
- {
- getConnection().commit();
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
+ jdbcDelegate.commit();
}
@Override
- protected void rollback(IStoreAccessor.CommitContext context)
+ protected final void rollback(IStoreAccessor.CommitContext context)
{
- try
- {
- getConnection().rollback();
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
+ jdbcDelegate.rollback();
}
@Override
- protected void writePackages(CDOPackage[] cdoPackages)
+ protected final void writePackages(CDOPackage[] cdoPackages)
{
new PackageWriter(cdoPackages)
{
@@ -423,7 +382,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
try
{
- pstmt = getConnection().prepareStatement(sql);
+ pstmt = jdbcDelegate.getPreparedStatement(sql);
pstmt.setInt(1, id);
pstmt.setString(2, packageURI);
pstmt.setString(3, name);
@@ -454,7 +413,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
}
@Override
- protected void writeClass(InternalCDOClass cdoClass)
+ protected final void writeClass(InternalCDOClass cdoClass)
{
int id = getStore().getNextClassID();
ClassServerInfo.setDBID(cdoClass, id);
@@ -464,18 +423,18 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
int classifierID = cdoClass.getClassifierID();
String name = cdoClass.getName();
boolean isAbstract = cdoClass.isAbstract();
- DBUtil.insertRow(getConnection(), getStore().getDBAdapter(), CDODBSchema.CLASSES, id, packageID, classifierID,
- name, isAbstract);
+ DBUtil.insertRow(jdbcDelegate.getConnection(), getStore().getDBAdapter(), CDODBSchema.CLASSES, id, packageID,
+ classifierID, name, isAbstract);
}
@Override
- protected void writeSuperType(InternalCDOClass type, CDOClassProxy superType)
+ protected final void writeSuperType(InternalCDOClass type, CDOClassProxy superType)
{
int id = ClassServerInfo.getDBID(type);
String packageURI = superType.getPackageURI();
int classifierID = superType.getClassifierID();
- DBUtil.insertRow(getConnection(), getStore().getDBAdapter(), CDODBSchema.SUPERTYPES, id, packageURI,
- classifierID);
+ DBUtil.insertRow(jdbcDelegate.getConnection(), getStore().getDBAdapter(), CDODBSchema.SUPERTYPES, id,
+ packageURI, classifierID);
}
@Override
@@ -494,13 +453,13 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
boolean many = feature.isMany();
boolean containment = feature.isContainment();
int idx = feature.getFeatureIndex();
- DBUtil.insertRow(getConnection(), getStore().getDBAdapter(), CDODBSchema.FEATURES, id, classID, featureID,
- name, type, packageURI, classifierID, many, containment, idx);
+ DBUtil.insertRow(jdbcDelegate.getConnection(), getStore().getDBAdapter(), CDODBSchema.FEATURES, id, classID,
+ featureID, name, type, packageURI, classifierID, many, containment, idx);
}
}.run();
Set<IDBTable> affectedTables = mapPackages(cdoPackages);
- getStore().getDBAdapter().createTables(affectedTables, getConnection());
+ getStore().getDBAdapter().createTables(affectedTables, jdbcDelegate.getConnection());
}
@Override
@@ -612,19 +571,6 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
return affectedTables;
}
- protected void initConnection()
- {
- try
- {
- connection = getStore().getDBConnectionProvider().getConnection();
- connection.setAutoCommit(isReader());
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- }
-
@Override
protected void doActivate() throws Exception
{
@@ -634,8 +580,7 @@ public class DBStoreAccessor extends StoreAccessor implements IDBStoreAccessor
@Override
protected void doDeactivate() throws Exception
{
- DBUtil.close(statement);
- DBUtil.close(connection);
+ jdbcDelegate.release();
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java
index db6460c008..fd183f60e2 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java
@@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.internal.server.RepositoryConfigurator;
import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.IStoreFactory;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
+import org.eclipse.emf.cdo.server.db.IJDBCDelegateProvider;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
import org.eclipse.net4j.db.DBUtil;
@@ -47,10 +48,30 @@ public class DBStoreFactory implements IStoreFactory
public IStore createStore(Element storeConfig)
{
IMappingStrategy mappingStrategy = getMappingStrategy(storeConfig);
+ IJDBCDelegateProvider delegateProvider = getDelegateProvider(storeConfig);
IDBAdapter dbAdapter = getDBAdapter(storeConfig);
DataSource dataSource = getDataSource(storeConfig);
IDBConnectionProvider connectionProvider = DBUtil.createConnectionProvider(dataSource);
- return CDODBUtil.createStore(mappingStrategy, dbAdapter, connectionProvider);
+ return CDODBUtil.createStore(mappingStrategy, dbAdapter, connectionProvider, delegateProvider);
+ }
+
+ private IJDBCDelegateProvider getDelegateProvider(Element storeConfig)
+ {
+ NodeList delegateProviderConfigs = storeConfig.getElementsByTagName("jdbcDelegate");
+ if (delegateProviderConfigs.getLength() != 1)
+ {
+ throw new IllegalStateException("Exactly one delegate provider must be configured for DB store");
+ }
+
+ Element delegateProviderConfig = (Element)delegateProviderConfigs.item(0);
+ String delegateProviderType = delegateProviderConfig.getAttribute("type");
+ IJDBCDelegateProvider delegateProvider = CDODBUtil.createDelegateProvider(delegateProviderType);
+ if (delegateProvider == null)
+ {
+ throw new IllegalArgumentException("Unknown JDBC delegate type: " + delegateProviderType);
+ }
+
+ return delegateProvider;
}
private IMappingStrategy getMappingStrategy(Element storeConfig)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalClassMapping.java
index 69898ee97a..f8bb6f75fb 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalClassMapping.java
@@ -75,8 +75,7 @@ public class HorizontalClassMapping extends ClassMapping
return new Pair<CDOClass, CDOFeature>(getCDOClass(), cdoFeature);
}
- @Override
- protected boolean hasFullRevisionInfo()
+ public boolean hasFullRevisionInfo()
{
return true;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java
index fbd3e81358..6a86ea8672 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java
@@ -69,7 +69,7 @@ public class HorizontalMappingStrategy extends MappingStrategy
return objectTypeCache.getObjectType(accessor, id);
}
- protected CDOClassRef readObjectTypeFromClassesWithObjectInfo(IDBStoreAccessor accessor, CDOID id)
+ protected final CDOClassRef readObjectTypeFromClassesWithObjectInfo(IDBStoreAccessor accessor, CDOID id)
{
String prefix = "SELECT DISTINCT " + CDODBSchema.ATTRIBUTES_CLASS + " FROM ";
String suffix = " WHERE " + CDODBSchema.ATTRIBUTES_ID + "=" + id;
@@ -91,7 +91,7 @@ public class HorizontalMappingStrategy extends MappingStrategy
try
{
- resultSet = accessor.getStatement().executeQuery(sql);
+ resultSet = accessor.getJDBCDelegate().getStatement().executeQuery(sql);
if (resultSet.next())
{
int classID = resultSet.getInt(1);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
index 3fd4193b88..d7139fc515 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
@@ -266,7 +266,7 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
return builder.toString();
}
- public CloseableIterator<CDOID> readObjectIDs(final IDBStoreAccessor accessor)
+ public final CloseableIterator<CDOID> readObjectIDs(final IDBStoreAccessor accessor)
{
List<CDOClass> classes = getClassesWithObjectInfo();
final Iterator<CDOClass> classIt = classes.iterator();
@@ -293,7 +293,7 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
try
{
- return accessor.getStatement().executeQuery(sql);
+ return accessor.getJDBCDelegate().getStatement().executeQuery(sql);
}
catch (SQLException ex)
{
@@ -308,7 +308,7 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
};
}
- public void queryResources(IDBStoreAccessor accessor, QueryResourcesContext context)
+ public final void queryResources(IDBStoreAccessor accessor, QueryResourcesContext context)
{
CDOID folderID = context.getFolderID();
String name = context.getName();
@@ -334,7 +334,7 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
try
{
- resultSet = accessor.getStatement().executeQuery(sql);
+ resultSet = accessor.getJDBCDelegate().getStatement().executeQuery(sql);
while (resultSet.next())
{
long longID = resultSet.getLong(1);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NoClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NoClassMapping.java
index b4b0fa5704..e16e620af9 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NoClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/NoClassMapping.java
@@ -58,6 +58,11 @@ public class NoClassMapping implements IClassMapping
return Collections.emptySet();
}
+ public boolean hasFullRevisionInfo()
+ {
+ return false;
+ }
+
public IFeatureMapping getFeatureMapping(CDOFeature feature)
{
return null;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ObjectTypeCache.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ObjectTypeCache.java
index dfab0c9c30..6945f9c764 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ObjectTypeCache.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ObjectTypeCache.java
@@ -61,9 +61,9 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
this.mappingStrategy = mappingStrategy;
}
- public CDOClassRef getObjectType(IDBStoreAccessor accessor, CDOID id)
+ public final CDOClassRef getObjectType(IDBStoreAccessor accessor, CDOID id)
{
- Statement statement = accessor.getStatement();
+ Statement statement = accessor.getJDBCDelegate().getStatement();
initialize(statement);
StringBuilder builder = new StringBuilder();
@@ -101,9 +101,9 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
}
}
- public void putObjectType(IDBStoreAccessor accessor, CDOID id, CDOClass type)
+ public final void putObjectType(IDBStoreAccessor accessor, CDOID id, CDOClass type)
{
- Statement statement = accessor.getStatement();
+ Statement statement = accessor.getJDBCDelegate().getStatement();
initialize(statement);
StringBuilder builder = new StringBuilder();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java
index f420dc6e5f..6715fb23b6 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ReferenceMapping.java
@@ -11,7 +11,6 @@
package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOClass;
import org.eclipse.emf.cdo.common.model.CDOFeature;
import org.eclipse.emf.cdo.common.model.CDOPackage;
@@ -20,21 +19,15 @@ import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
+import org.eclipse.emf.cdo.server.db.IJDBCDelegate;
import org.eclipse.emf.cdo.server.db.IReferenceMapping;
-import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
-import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBType;
-import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.db.ddl.IDBIndex.Type;
-import org.eclipse.net4j.util.collection.MoveableList;
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-import java.sql.ResultSet;
-import java.sql.SQLException;
import java.util.List;
import java.util.Map;
@@ -43,29 +36,17 @@ import java.util.Map;
*/
public class ReferenceMapping extends FeatureMapping implements IReferenceMapping
{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ReferenceMapping.class);
-
- private static final String SELECT_SUFFIX = " ORDER BY " + CDODBSchema.REFERENCES_IDX;
-
private IDBTable table;
private ToMany toMany;
private boolean withFeature;
- private String insertPrefix;
-
- private String selectPrefix;
-
public ReferenceMapping(ClassMapping classMapping, CDOFeature feature, ToMany toMany)
{
super(classMapping, feature);
this.toMany = toMany;
mapReference(classMapping.getCDOClass(), feature);
-
- int dbFeatureID = withFeature ? FeatureServerInfo.getDBID(getFeature()) : 0;
- insertPrefix = createInsertPrefix(dbFeatureID);
- selectPrefix = createSelectPrefix(dbFeatureID);
}
public IDBTable getTable()
@@ -73,168 +54,25 @@ public class ReferenceMapping extends FeatureMapping implements IReferenceMappin
return table;
}
- public void writeReference(IDBStoreAccessor accessor, CDORevision revision)
+ public final void writeReference(IDBStoreAccessor accessor, CDORevision revision)
{
- long source = CDOIDUtil.getLong(revision.getID());
- int version = revision.getVersion();
+ IJDBCDelegate jdbcDelegate = accessor.getJDBCDelegate();
int idx = 0;
for (Object element : ((InternalCDORevision)revision).getList(getFeature()))
{
- long target = CDOIDUtil.getLong((CDOID)element);
- StringBuilder builder = new StringBuilder(insertPrefix);
- builder.append(source);
- builder.append(", ");
- builder.append(version);
- builder.append(", ");
- builder.append(idx++);
- builder.append(", ");
- builder.append(target);
- builder.append(")");
- String sql = builder.toString();
- getClassMapping().sqlUpdate(accessor, sql);
- }
- }
-
- public void readReference(IDBStoreAccessor accessor, CDORevision revision, int referenceChunk)
- {
- MoveableList<Object> list = ((InternalCDORevision)revision).getList(getFeature());
- CDOID source = revision.getID();
- int version = revision.getVersion();
-
- String sql = createSelect(source, version, null);
- if (TRACER.isEnabled())
- {
- TRACER.trace(sql);
- }
-
- ResultSet resultSet = null;
-
- try
- {
- resultSet = accessor.getStatement().executeQuery(sql);
- while (resultSet.next() && (referenceChunk == CDORevision.UNCHUNKED || --referenceChunk >= 0))
- {
- long target = resultSet.getLong(1);
- list.add(CDOIDUtil.createLong(target));
- }
-
- // TODO Optimize this?
- while (resultSet.next())
- {
- list.add(InternalCDORevision.UNINITIALIZED);
- }
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- DBUtil.close(resultSet);
- }
- }
-
- public void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
- {
- IDBStoreAccessor storeAccessor = chunkReader.getAccessor();
- CDOID source = chunkReader.getRevision().getID();
- int version = chunkReader.getRevision().getVersion();
-
- String sql = createSelect(source, version, where);
- if (TRACER.isEnabled())
- {
- TRACER.trace(sql);
- }
-
- ResultSet resultSet = null;
-
- try
- {
- Chunk chunk = null;
- int chunkSize = 0;
- int chunkIndex = 0;
- int indexInChunk = 0;
-
- resultSet = storeAccessor.getStatement().executeQuery(sql);
- while (resultSet.next())
- {
- long target = resultSet.getLong(1);
- if (chunk == null)
- {
- chunk = chunks.get(chunkIndex++);
- chunkSize = chunk.size();
- }
-
- chunk.addID(indexInChunk++, CDOIDUtil.createLong(target));
- if (indexInChunk == chunkSize)
- {
- chunk = null;
- indexInChunk = 0;
- }
- }
- }
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
- {
- DBUtil.close(resultSet);
+ jdbcDelegate.insertReference(revision, idx++, (CDOID)element, this);
}
}
- protected String createInsertPrefix(int dbFeatureID)
+ public final void readReference(IDBStoreAccessor accessor, CDORevision revision, int referenceChunk)
{
- StringBuilder builder = new StringBuilder();
- builder.append("INSERT INTO ");
- builder.append(table);
- builder.append(" VALUES (");
- if (dbFeatureID != 0)
- {
- builder.append(FeatureServerInfo.getDBID(getFeature()));
- builder.append(", ");
- }
-
- return builder.toString();
- }
-
- protected String createSelectPrefix(int dbFeatureID)
- {
- StringBuilder builder = new StringBuilder();
- builder.append("SELECT ");
- builder.append(CDODBSchema.REFERENCES_TARGET);
- builder.append(" FROM ");
- builder.append(table);
- builder.append(" WHERE ");
- if (dbFeatureID != 0)
- {
- builder.append(CDODBSchema.REFERENCES_FEATURE);
- builder.append("=");
- builder.append(dbFeatureID);
- builder.append(" AND ");
- }
-
- builder.append(CDODBSchema.REFERENCES_SOURCE);
- builder.append("=");
- return builder.toString();
+ accessor.getJDBCDelegate().selectRevisionReferences(revision, this, referenceChunk);
}
- protected String createSelect(CDOID source, int version, String where)
+ public final void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
{
- StringBuilder builder = new StringBuilder(selectPrefix);
- builder.append(CDOIDUtil.getLong(source));
- builder.append(" AND ");
- builder.append(CDODBSchema.REFERENCES_VERSION);
- builder.append("=");
- builder.append(version);
- if (where != null)
- {
- builder.append(where);
- }
-
- builder.append(SELECT_SUFFIX);
- return builder.toString();
+ chunkReader.getAccessor().getJDBCDelegate().selectRevisionReferenceChunks(chunkReader, chunks, this, where);
}
protected void mapReference(CDOClass cdoClass, CDOFeature cdoFeature)
@@ -309,4 +147,8 @@ public class ReferenceMapping extends FeatureMapping implements IReferenceMappin
return table;
}
+ public boolean isWithFeature()
+ {
+ return withFeature;
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootClassMapping.java
index 5c6f88fced..6228c7fe03 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootClassMapping.java
@@ -31,8 +31,7 @@ public class RootClassMapping extends ClassMapping
return (VerticalMappingStrategy)super.getMappingStrategy();
}
- @Override
- protected boolean hasFullRevisionInfo()
+ public boolean hasFullRevisionInfo()
{
return true;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ToOneReferenceMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ToOneReferenceMapping.java
index 3d88d33fad..c54d4c1dd1 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ToOneReferenceMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ToOneReferenceMapping.java
@@ -13,7 +13,7 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOFeature;
-import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
/**
* @author Eike Stepper
@@ -26,7 +26,7 @@ public class ToOneReferenceMapping extends AttributeMapping.AMObject
}
@Override
- protected Long getRevisionValue(InternalCDORevision revision)
+ public Long getRevisionValue(CDORevision revision)
{
CDOID id = (CDOID)super.getRevisionValue(revision);
return CDOIDUtil.getLong(id);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalClassMapping.java
index 8dca2a91b8..92fa3ef85c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalClassMapping.java
@@ -49,8 +49,7 @@ public class VerticalClassMapping extends ClassMapping
return (VerticalMappingStrategy)super.getMappingStrategy();
}
- @Override
- protected boolean hasFullRevisionInfo()
+ public boolean hasFullRevisionInfo()
{
return false;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/AbstractJDBCDelegate.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/AbstractJDBCDelegate.java
new file mode 100644
index 0000000000..cf15c641e0
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/AbstractJDBCDelegate.java
@@ -0,0 +1,353 @@
+/***************************************************************************
+ * 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:
+ * Stefan Winkler - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.server.internal.db.jdbc;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
+import org.eclipse.emf.cdo.server.db.IAttributeMapping;
+import org.eclipse.emf.cdo.server.db.IClassMapping;
+import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
+import org.eclipse.emf.cdo.server.db.IJDBCDelegate;
+import org.eclipse.emf.cdo.server.db.IReferenceMapping;
+import org.eclipse.emf.cdo.server.internal.db.FeatureServerInfo;
+import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
+
+import org.eclipse.net4j.db.DBException;
+import org.eclipse.net4j.db.DBUtil;
+import org.eclipse.net4j.db.IDBConnectionProvider;
+import org.eclipse.net4j.util.collection.MoveableList;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collections;
+import java.util.List;
+
+/**
+ * This abstract implementation of the {@link IJDBCDelegate} interface is used to translate CDO-related objects to base
+ * types (e.g. CDOIDs to long) and then to delegate the database execution part to the doXYZ methods which should be
+ * implemented by extenders. The purpose of this is to provide several JDBC strategies (e.g. simple or prepared
+ * statement database access) depending on the requirements, but a single point of interpreting and transforming
+ * CDO-internal structures. The JDBCDelegate also keeps open one database connection and one statement which can be used
+ * to perform operations on the database. Extenders may, but don't have to, use the statement to perform operations.
+ *
+ * @author Stefan Winkler
+ * @since 2.0
+ */
+public abstract class AbstractJDBCDelegate implements IJDBCDelegate
+{
+ private Connection connection;
+
+ private Statement statement;
+
+ public final Connection getConnection()
+ {
+ return connection;
+ }
+
+ public final void commit()
+ {
+ try
+ {
+ getConnection().commit();
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ }
+
+ public final void rollback()
+ {
+ try
+ {
+ getConnection().rollback();
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ }
+
+ public final Statement getStatement()
+ {
+ if (statement == null)
+ {
+ try
+ {
+ statement = getConnection().createStatement();
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ }
+
+ return statement;
+ }
+
+ public PreparedStatement getPreparedStatement(String sql)
+ {
+ try
+ {
+ return getConnection().prepareStatement(sql);
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ }
+
+ public void initConnection(IDBConnectionProvider connectionProvider, boolean readOnly)
+ {
+ try
+ {
+ connection = connectionProvider.getConnection();
+ connection.setAutoCommit(readOnly);
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ }
+
+ public void release()
+ {
+ DBUtil.close(statement);
+ DBUtil.close(connection);
+ }
+
+ public final void insertAttributes(CDORevision revision, IClassMapping classMapping)
+ {
+ doInsertAttributes(classMapping.getTable().getName(), revision, classMapping.getAttributeMappings(), classMapping
+ .hasFullRevisionInfo());
+ }
+
+ public final void insertReference(CDORevision sourceRevision, int index, CDOID targetId,
+ IReferenceMapping referenceMapping)
+ {
+ doInsertReference(referenceMapping.getTable().getName(), referenceMapping.isWithFeature() ? FeatureServerInfo
+ .getDBID(referenceMapping.getFeature()) : 0, CDOIDUtil.getLong(sourceRevision.getID()), sourceRevision
+ .getVersion(), index, CDOIDUtil.getLong(targetId));
+ }
+
+ public final void updateRevised(CDORevision revision, IClassMapping classMapping)
+ {
+ doUpdateRevised(classMapping.getTable().getName(), revision.getCreated() - 1, CDOIDUtil.getLong(revision.getID()),
+ revision.getVersion() - 1);
+ }
+
+ public final void updateRevised(CDOID id, long revised, IClassMapping classMapping)
+ {
+ doUpdateRevised(classMapping.getTable().getName(), revised, CDOIDUtil.getLong(id));
+ }
+
+ public final void selectRevisionAttributes(CDORevision revision, IClassMapping classMapping, String where)
+ {
+ List<IAttributeMapping> attributeMappings = classMapping.getAttributeMappings();
+ if (attributeMappings == null)
+ {
+ attributeMappings = Collections.emptyList();
+ }
+
+ boolean withFullRevisionInfo = classMapping.hasFullRevisionInfo();
+ ResultSet resultSet = null;
+ try
+ {
+ resultSet = doSelectRevisionAttributes(classMapping.getTable().getName(), CDOIDUtil.getLong(revision.getID()),
+ attributeMappings, withFullRevisionInfo, where);
+
+ if (!resultSet.next())
+ {
+ throw new IllegalStateException("Revision not found: " + CDOIDUtil.getLong(revision.getID()));
+ }
+
+ int i = 0;
+ if (withFullRevisionInfo)
+ {
+ InternalCDORevision rev = (InternalCDORevision)revision;
+ rev.setVersion(resultSet.getInt(++i));
+ rev.setCreated(resultSet.getLong(++i));
+ rev.setRevised(resultSet.getLong(++i));
+ rev.setResourceID(CDOIDUtil.createLong(resultSet.getLong(++i)));
+ rev.setContainerID(CDOIDUtil.createLong(resultSet.getLong(++i)));
+ rev.setContainingFeatureID(resultSet.getInt(++i));
+ }
+
+ if (attributeMappings != null)
+ {
+ for (IAttributeMapping attributeMapping : attributeMappings)
+ {
+ attributeMapping.extractValue(resultSet, ++i, revision);
+ }
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(resultSet);
+ }
+ }
+
+ public void selectRevisionReferences(CDORevision revision, IReferenceMapping referenceMapping, int referenceChunk)
+ {
+ MoveableList<Object> list = ((InternalCDORevision)revision).getList(referenceMapping.getFeature());
+
+ CDOID source = revision.getID();
+ long sourceId = CDOIDUtil.getLong(source);
+ int version = revision.getVersion();
+
+ ResultSet resultSet = null;
+ try
+ {
+ resultSet = doSelectRevisionReferences(referenceMapping.getTable().getName(), sourceId, version, referenceMapping
+ .isWithFeature() ? FeatureServerInfo.getDBID(referenceMapping.getFeature()) : 0, "");
+
+ while (resultSet.next() && (referenceChunk == CDORevision.UNCHUNKED || --referenceChunk >= 0))
+ {
+ long target = resultSet.getLong(1);
+ list.add(CDOIDUtil.createLong(target));
+ }
+
+ // TODO Optimize this?
+ while (resultSet.next())
+ {
+ list.add(InternalCDORevision.UNINITIALIZED);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(resultSet);
+ }
+ }
+
+ public void selectRevisionReferenceChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks,
+ IReferenceMapping referenceMapping, String where)
+ {
+ CDOID source = chunkReader.getRevision().getID();
+ long sourceId = CDOIDUtil.getLong(source);
+ int version = chunkReader.getRevision().getVersion();
+
+ ResultSet resultSet = null;
+
+ try
+ {
+ resultSet = doSelectRevisionReferences(referenceMapping.getTable().getName(), sourceId, version, referenceMapping
+ .isWithFeature() ? FeatureServerInfo.getDBID(referenceMapping.getFeature()) : 0, where);
+
+ Chunk chunk = null;
+ int chunkSize = 0;
+ int chunkIndex = 0;
+ int indexInChunk = 0;
+
+ while (resultSet.next())
+ {
+ long target = resultSet.getLong(1);
+ if (chunk == null)
+ {
+ chunk = chunks.get(chunkIndex++);
+ chunkSize = chunk.size();
+ }
+
+ chunk.addID(indexInChunk++, CDOIDUtil.createLong(target));
+ if (indexInChunk == chunkSize)
+ {
+ chunk = null;
+ indexInChunk = 0;
+ }
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ close(resultSet);
+ }
+ }
+
+ /**
+ * Insert an attribute row.
+ */
+ protected abstract void doInsertAttributes(String tableName, CDORevision revision,
+ List<IAttributeMapping> attributeMappings, boolean withFullRevisionInfo);
+
+ /**
+ * Insert a reference row. Note: this is likely to be replaced by an implementation that supports storing multiple
+ * references in one batch.
+ */
+ protected abstract void doInsertReference(String tableName, int dbId, long source, int version, int i, long target);
+
+ /**
+ * Set the revised date of all unrevised rows of cdoid
+ */
+ protected abstract void doUpdateRevised(String tableName, long revised, long cdoid);
+
+ /**
+ * Set the revised date of a specific revision's previous version.
+ */
+ protected abstract void doUpdateRevised(String tableName, long revisedStamp, long cdoid, int version);
+
+ /**
+ * Select a revision's attributes. The caller is resposible for closing resultSet and associated statement, if
+ * appropriate.
+ */
+ protected abstract ResultSet doSelectRevisionAttributes(String tableName, long revisionId,
+ List<IAttributeMapping> attributeMappings, boolean hasFullRevisionInfo, String where) throws SQLException;
+
+ /**
+ * Select a revision's references (or a part thereof) The caller is resposible for closing resultSet and associated
+ * statement, if appropriate.
+ */
+ protected abstract ResultSet doSelectRevisionReferences(String tableName, long sourceId, int version,
+ int dbFeatureID, String where) throws SQLException;
+
+ /**
+ * Close the given result set and the statement, if this is needed (which is the case, iff the resultSet's statement
+ * is not the one which is kept open by this instance).
+ */
+ private void close(ResultSet resultSet)
+ {
+ Statement stmt = null;
+
+ try
+ {
+ stmt = resultSet.getStatement();
+ }
+ catch (SQLException ex)
+ {
+ // Ignore
+ }
+ finally
+ {
+ DBUtil.close(resultSet);
+ }
+
+ // if the statement is one that has been created for the operation only
+ // release it.
+ if (stmt != statement)
+ {
+ DBUtil.close(stmt);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/JDBCPerformanceMeasurementWrapper.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/JDBCPerformanceMeasurementWrapper.java
new file mode 100644
index 0000000000..c785eb02a3
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/JDBCPerformanceMeasurementWrapper.java
@@ -0,0 +1,200 @@
+/***************************************************************************
+ * 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.server.internal.db.jdbc;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
+import org.eclipse.emf.cdo.server.db.IClassMapping;
+import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
+import org.eclipse.emf.cdo.server.db.IJDBCDelegate;
+import org.eclipse.emf.cdo.server.db.IReferenceMapping;
+import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
+
+import org.eclipse.net4j.db.IDBConnectionProvider;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.Statement;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+/**
+ * @author Stefan Winkler
+ * @since 2.0
+ */
+public class JDBCPerformanceMeasurementWrapper implements IJDBCDelegate
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, JDBCPerformanceMeasurementWrapper.class);
+
+ private static Map<String, TimeData> timeData = Collections.synchronizedMap(new HashMap<String, TimeData>());
+
+ private IJDBCDelegate delegate;
+
+ public JDBCPerformanceMeasurementWrapper(IJDBCDelegate delegate)
+ {
+ this.delegate = delegate;
+ }
+
+ public void commit()
+ {
+ delegate.commit();
+ }
+
+ public Connection getConnection()
+ {
+ return delegate.getConnection();
+ }
+
+ public PreparedStatement getPreparedStatement(String sql)
+ {
+ return delegate.getPreparedStatement(sql);
+ }
+
+ public Statement getStatement()
+ {
+ return delegate.getStatement();
+ }
+
+ public void initConnection(IDBConnectionProvider connectionProvider, boolean readOnly)
+ {
+ delegate.initConnection(connectionProvider, readOnly);
+ }
+
+ public void insertAttributes(CDORevision revision, IClassMapping classMapping)
+ {
+ long time = System.currentTimeMillis();
+ delegate.insertAttributes(revision, classMapping);
+ time = System.currentTimeMillis() - time;
+
+ registerCall("insertAttributes", time);
+ }
+
+ public void insertReference(CDORevision sourceRevision, int index, CDOID targetId, IReferenceMapping referenceMapping)
+ {
+ long time = System.currentTimeMillis();
+ delegate.insertReference(sourceRevision, index, targetId, referenceMapping);
+ time = System.currentTimeMillis() - time;
+ registerCall("insertReferenceDbId", time);
+ }
+
+ public void release()
+ {
+ delegate.release();
+ }
+
+ public void rollback()
+ {
+ delegate.rollback();
+ }
+
+ public void selectRevisionAttributes(CDORevision revision, IClassMapping classMapping, String where)
+ {
+ long time = System.currentTimeMillis();
+ delegate.selectRevisionAttributes(revision, null, where);
+ time = System.currentTimeMillis() - time;
+ registerCall("selectAttributes", time);
+ }
+
+ public void selectRevisionReferenceChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks,
+ IReferenceMapping referenceMapping, String where)
+ {
+ long time = System.currentTimeMillis();
+ delegate.selectRevisionReferenceChunks(chunkReader, chunks, referenceMapping, where);
+ time = System.currentTimeMillis() - time;
+ registerCall("selectReferencesChunks", time);
+ }
+
+ public void selectRevisionReferences(CDORevision revision, IReferenceMapping referenceMapping, int referenceChunk)
+ {
+ long time = System.currentTimeMillis();
+ delegate.selectRevisionReferences(revision, referenceMapping, referenceChunk);
+ time = System.currentTimeMillis() - time;
+ registerCall("selectReferences", time);
+ }
+
+ public final void updateRevised(CDORevision revision, IClassMapping classMapping)
+ {
+ long time = System.currentTimeMillis();
+ delegate.updateRevised(revision, classMapping);
+ time = System.currentTimeMillis() - time;
+ registerCall("updateRevisedRevision", time);
+ }
+
+ public final void updateRevised(CDOID cdoid, long revised, IClassMapping classMapping)
+ {
+ long time = System.currentTimeMillis();
+ delegate.updateRevised(cdoid, revised, classMapping);
+ time = System.currentTimeMillis() - time;
+ registerCall("updateRevisedID", time);
+ }
+
+ public static void report()
+ {
+ for (TimeData td : timeData.values())
+ {
+ td.report(TRACER);
+ }
+ }
+
+ private static void registerCall(String method, long time)
+ {
+ TimeData data = timeData.get(method);
+ if (data == null)
+ {
+ data = new TimeData(method);
+ timeData.put(method, data);
+ }
+ data.registerCall(time);
+ }
+}
+
+class TimeData
+{
+ private String method;
+
+ private long numberOfCalls = 0;
+
+ private long timeMax = Integer.MIN_VALUE;
+
+ private long timeMin = Integer.MAX_VALUE;
+
+ private long timeTotal = 0;
+
+ public TimeData(String method)
+ {
+ this.method = method;
+ }
+
+ public synchronized void registerCall(long time)
+ {
+ if (timeMin > time)
+ {
+ timeMin = time;
+ }
+ if (timeMax < time)
+ {
+ timeMax = time;
+ }
+
+ numberOfCalls++;
+ timeTotal += time;
+ }
+
+ public void report(ContextTracer tracer)
+ {
+ tracer.format("{0}: {1} calls, {2} avg, {3} min, {4} max", method, numberOfCalls, timeTotal / numberOfCalls,
+ timeMin, timeMax);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/NonPreparedStatementJDBCDelegate.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/NonPreparedStatementJDBCDelegate.java
new file mode 100644
index 0000000000..a7ba498dd4
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/NonPreparedStatementJDBCDelegate.java
@@ -0,0 +1,283 @@
+/***************************************************************************
+ * 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.server.internal.db.jdbc;
+
+import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.common.revision.CDORevisionData;
+import org.eclipse.emf.cdo.server.db.IAttributeMapping;
+import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
+import org.eclipse.emf.cdo.server.internal.db.ServerInfo;
+import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
+
+import org.eclipse.net4j.db.DBException;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.List;
+
+/**
+ * @author Stefan Winkler
+ * @since 2.0
+ */
+public class NonPreparedStatementJDBCDelegate extends AbstractJDBCDelegate
+{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, NonPreparedStatementJDBCDelegate.class);
+
+ public NonPreparedStatementJDBCDelegate()
+ {
+ }
+
+ @Override
+ protected void doInsertAttributes(String table, CDORevision revision, List<IAttributeMapping> attributeMappings,
+ boolean withFullRevisionInfo)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("INSERT INTO ");
+ builder.append(table);
+ builder.append(" VALUES (");
+
+ builder.append(CDOIDUtil.getLong(revision.getID()));
+ builder.append(", ");
+ builder.append(revision.getVersion());
+
+ if (withFullRevisionInfo)
+ {
+ CDORevisionData data = revision.getData();
+ builder.append(", ");
+ builder.append(ServerInfo.getDBID(revision.getCDOClass()));
+ builder.append(", ");
+ builder.append(revision.getCreated());
+ builder.append(", ");
+ builder.append(revision.getRevised());
+ builder.append(", ");
+ builder.append(CDOIDUtil.getLong(data.getResourceID()));
+ builder.append(", ");
+ builder.append(CDOIDUtil.getLong((CDOID)data.getContainerID()));
+ builder.append(", ");
+ builder.append(data.getContainingFeatureID());
+ }
+
+ if (attributeMappings != null)
+ {
+ for (IAttributeMapping attributeMapping : attributeMappings)
+ {
+ builder.append(", ");
+ Object value = attributeMapping.getRevisionValue(revision);
+ attributeMapping.getField().appendValue(builder, value);
+ }
+ }
+
+ builder.append(")");
+ sqlUpdate(builder.toString());
+ }
+
+ @Override
+ protected void doUpdateRevised(String table, long revisedStamp, long cdoid, int version)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("UPDATE ");
+ builder.append(table);
+ builder.append(" SET ");
+ builder.append(CDODBSchema.ATTRIBUTES_REVISED);
+ builder.append("=");
+ builder.append(revisedStamp);
+ builder.append(" WHERE ");
+ builder.append(CDODBSchema.ATTRIBUTES_ID);
+ builder.append("=");
+ builder.append(cdoid);
+ builder.append(" AND ");
+ builder.append(CDODBSchema.ATTRIBUTES_VERSION);
+ builder.append("=");
+ builder.append(version);
+ sqlUpdate(builder.toString());
+ }
+
+ @Override
+ protected void doUpdateRevised(String table, long revisedStamp, long cdoid)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("UPDATE ");
+ builder.append(table);
+ builder.append(" SET ");
+ builder.append(CDODBSchema.ATTRIBUTES_REVISED);
+ builder.append("=");
+ builder.append(revisedStamp);
+ builder.append(" WHERE ");
+ builder.append(CDODBSchema.ATTRIBUTES_ID);
+ builder.append("=");
+ builder.append(cdoid);
+ builder.append(" AND ");
+ builder.append(CDODBSchema.ATTRIBUTES_REVISED);
+ builder.append("=0");
+ sqlUpdate(builder.toString());
+ }
+
+ @Override
+ protected void doInsertReference(String table, int dbId, long source, int version, int i, long target)
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("INSERT INTO ");
+ builder.append(table);
+ builder.append(" VALUES (");
+ if (dbId != 0)
+ {
+ builder.append(dbId);
+ builder.append(", ");
+ }
+ builder.append(source);
+ builder.append(", ");
+ builder.append(version);
+ builder.append(", ");
+ builder.append(i);
+ builder.append(", ");
+ builder.append(target);
+ builder.append(")");
+ sqlUpdate(builder.toString());
+ }
+
+ private int sqlUpdate(String sql) throws DBException
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
+
+ Statement statement = null;
+ try
+ {
+ statement = getConnection().createStatement();
+ return statement.executeUpdate(sql);
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ try
+ {
+ statement.close();
+ }
+ catch (SQLException e)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(e);
+ }
+ }
+ }
+ }
+
+ @Override
+ protected ResultSet doSelectRevisionAttributes(String tableName, long revisionId,
+ List<IAttributeMapping> attributeMappings, boolean hasFullRevisionInfo, String where) throws SQLException
+ {
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT ");
+ if (hasFullRevisionInfo)
+ {
+ builder.append(CDODBSchema.ATTRIBUTES_VERSION);
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_CREATED);
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_REVISED);
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_RESOURCE);
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_CONTAINER);
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_FEATURE);
+ }
+ else
+ {
+ if (attributeMappings == null)
+ {
+ // Only references return
+ return null;
+ }
+ }
+
+ if (attributeMappings != null)
+ {
+ for (IAttributeMapping attributeMapping : attributeMappings)
+ {
+ builder.append(", ");
+ builder.append(attributeMapping.getField());
+ }
+ }
+
+ builder.append(" FROM ");
+ builder.append(tableName);
+ builder.append(" WHERE ");
+ builder.append(CDODBSchema.ATTRIBUTES_ID);
+ builder.append("=");
+ builder.append(revisionId);
+ builder.append(" AND (");
+ builder.append(where);
+ builder.append(")");
+ String sql = builder.toString();
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
+
+ return getStatement().executeQuery(sql);
+ }
+
+ @Override
+ protected ResultSet doSelectRevisionReferences(String tableName, long sourceId, int version, int dbFeatureID,
+ String where) throws SQLException
+ {
+
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT ");
+ builder.append(CDODBSchema.REFERENCES_TARGET);
+ builder.append(" FROM ");
+ builder.append(tableName);
+ builder.append(" WHERE ");
+ if (dbFeatureID != 0)
+ {
+ builder.append(CDODBSchema.REFERENCES_FEATURE);
+ builder.append("=");
+ builder.append(dbFeatureID);
+ builder.append(" AND ");
+ }
+
+ builder.append(CDODBSchema.REFERENCES_SOURCE);
+ builder.append("=");
+ builder.append(sourceId);
+ builder.append(" AND ");
+ builder.append(CDODBSchema.REFERENCES_VERSION);
+ builder.append("=");
+ builder.append(version);
+
+ if (where != null)
+ {
+ builder.append(where);
+ }
+
+ builder.append(" ORDER BY ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+
+ String sql = builder.toString();
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
+
+ return getStatement().executeQuery(sql);
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/NonPreparedStatementJDBCDelegateProvider.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/NonPreparedStatementJDBCDelegateProvider.java
new file mode 100644
index 0000000000..bc7f9718e1
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/NonPreparedStatementJDBCDelegateProvider.java
@@ -0,0 +1,30 @@
+/***************************************************************************
+ * 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.server.internal.db.jdbc;
+
+import org.eclipse.emf.cdo.server.db.IJDBCDelegate;
+import org.eclipse.emf.cdo.server.db.IJDBCDelegateProvider;
+
+/**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+public class NonPreparedStatementJDBCDelegateProvider implements IJDBCDelegateProvider
+{
+ public NonPreparedStatementJDBCDelegateProvider()
+ {
+ }
+
+ public IJDBCDelegate getJDBCDelegate()
+ {
+ return new NonPreparedStatementJDBCDelegate();
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IConstants.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IConstants.java
index 4550e08e26..b5ab69d73b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IConstants.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IConstants.java
@@ -33,11 +33,11 @@ public interface IConstants
public static final RepositoryConfig MEM = RepositoryConfig.MEM.INSTANCE;
- public static final RepositoryConfig DB_HSQL_HORIZONTAL = RepositoryConfig.DBHsqldb.HSQLDB_HORIZONTAL;
+ public static final RepositoryConfig DB_HSQL_HORIZONTAL = RepositoryConfig.DBHsqldbNonPrepStmt.HSQLDB_HORIZONTAL;
- public static final RepositoryConfig DB_DERBY_HORIZONTAL = RepositoryConfig.DBDerby.DERBY_HORIZONTAL;
+ public static final RepositoryConfig DB_DERBY_HORIZONTAL = RepositoryConfig.DBDerbyNonPrepStmt.DERBY_HORIZONTAL;
- public static final RepositoryConfig DB_MYSQL_HORIZONTAL = RepositoryConfig.DBMysql.MYSQL_HORIZONTAL;
+ public static final RepositoryConfig DB_MYSQL_HORIZONTAL = RepositoryConfig.DBMysqlNonPrepStmt.MYSQL_HORIZONTAL;
public static final SessionConfig JVM = SessionConfig.JVM.INSTANCE;
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
index daa80e64d0..653618fe0b 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java
@@ -19,6 +19,7 @@ import org.eclipse.emf.cdo.server.IStore;
import org.eclipse.emf.cdo.server.StoreUtil;
import org.eclipse.emf.cdo.server.IRepository.Props;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
+import org.eclipse.emf.cdo.server.db.IJDBCDelegateProvider;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
import org.eclipse.emf.cdo.tests.bundle.OM;
import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
@@ -55,8 +56,8 @@ import java.util.Map.Entry;
*/
public abstract class RepositoryConfig extends Config implements IRepositoryConfig
{
- public static final RepositoryConfig[] CONFIGS = { MEM.INSTANCE, DBHsqldb.HSQLDB_HORIZONTAL,
- DBDerby.DERBY_HORIZONTAL, DBMysql.MYSQL_HORIZONTAL };
+ public static final RepositoryConfig[] CONFIGS = { MEM.INSTANCE, DBHsqldbNonPrepStmt.HSQLDB_HORIZONTAL,
+ DBDerbyNonPrepStmt.DERBY_HORIZONTAL, DBMysqlNonPrepStmt.MYSQL_HORIZONTAL };
public static final String PROP_TEST_REPOSITORY = "test.repository";
@@ -229,9 +230,13 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
IMappingStrategy mappingStrategy = createMappingStrategy();
IDBAdapter dbAdapter = createDBAdapter();
DataSource dataSource = createDataSource();
- return CDODBUtil.createStore(mappingStrategy, dbAdapter, DBUtil.createConnectionProvider(dataSource));
+ IJDBCDelegateProvider delegateProvider = createDelegateProvider();
+ return CDODBUtil.createStore(mappingStrategy, dbAdapter, DBUtil.createConnectionProvider(dataSource),
+ delegateProvider);
}
+ protected abstract IJDBCDelegateProvider createDelegateProvider();
+
protected abstract IMappingStrategy createMappingStrategy();
protected abstract IDBAdapter createDBAdapter();
@@ -242,10 +247,8 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
/**
* @author Eike Stepper
*/
- public static class DBHsqldb extends DB
+ public abstract static class DBHsqldb extends DB
{
- public static final DBHsqldb HSQLDB_HORIZONTAL = new DBHsqldb("HsqldbHorizontal");
-
private static final long serialVersionUID = 1L;
private transient HSQLDBDataSource dataSource;
@@ -316,13 +319,29 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
}
}
+ public static class DBHsqldbNonPrepStmt extends DBHsqldb
+ {
+ private static final long serialVersionUID = 1L;
+
+ public static final DBHsqldbNonPrepStmt HSQLDB_HORIZONTAL = new DBHsqldbNonPrepStmt("HsqldbHorizontal");
+
+ public DBHsqldbNonPrepStmt(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected IJDBCDelegateProvider createDelegateProvider()
+ {
+ return CDODBUtil.createNonPreparedStatementJDBCDelegateProvider();
+ }
+ }
+
/**
* @author Eike Stepper
*/
- public static class DBDerby extends DB
+ public abstract static class DBDerby extends DB
{
- public static final DBDerby DERBY_HORIZONTAL = new DBDerby("DerbyHorizontal");
-
private static final long serialVersionUID = 1L;
private transient File dbFolder;
@@ -371,13 +390,29 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
}
}
+ public static class DBDerbyNonPrepStmt extends DBDerby
+ {
+ private static final long serialVersionUID = 1L;
+
+ public static final DBDerbyNonPrepStmt DERBY_HORIZONTAL = new DBDerbyNonPrepStmt("DerbyHorizontal");
+
+ public DBDerbyNonPrepStmt(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected IJDBCDelegateProvider createDelegateProvider()
+ {
+ return CDODBUtil.createNonPreparedStatementJDBCDelegateProvider();
+ }
+ }
+
/**
* @author Simon McDuff
*/
- public static class DBMysql extends DB
+ public static abstract class DBMysql extends DB
{
- public static final DBMysql MYSQL_HORIZONTAL = new DBMysql("MysqlHorizontal");
-
private static final long serialVersionUID = 1L;
private transient MysqlDataSource setupDataSource;
@@ -468,4 +503,22 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
}
}
}
+
+ public static class DBMysqlNonPrepStmt extends DBMysql
+ {
+ private static final long serialVersionUID = 1L;
+
+ public static final DBMysqlNonPrepStmt MYSQL_HORIZONTAL = new DBMysqlNonPrepStmt("MysqlHorizontal");
+
+ public DBMysqlNonPrepStmt(String name)
+ {
+ super(name);
+ }
+
+ @Override
+ protected IJDBCDelegateProvider createDelegateProvider()
+ {
+ return CDODBUtil.createNonPreparedStatementJDBCDelegateProvider();
+ }
+ }
}

Back to the top