summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-04-07 05:15:55 (EDT)
committerStefan Winkler2009-04-07 05:15:55 (EDT)
commita1796a62d7f66e705d3461d4c0d5e3b93c3e3280 (patch)
tree2d89bf92ae1817d963cb3f6eb48e2e3e39c8cf7c
parent67946864d6750549401b1f3ed3b031ddae72cba2 (diff)
downloadcdo-a1796a62d7f66e705d3461d4c0d5e3b93c3e3280.zip
cdo-a1796a62d7f66e705d3461d4c0d5e3b93c3e3280.tar.gz
cdo-a1796a62d7f66e705d3461d4c0d5e3b93c3e3280.tar.bz2
Refactoring DBStore
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/.settings/org.eclipse.jdt.core.prefs4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/.settings/org.eclipse.jdt.ui.prefs4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/plugin.xml14
-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.java51
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegate.java181
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegateProvider.java35
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java51
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java176
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java26
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ObjectTypeCache.java126
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/AbstractJDBCDelegate.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/JDBCPerformanceReporter.java334
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegate.java98
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegateProvider.java49
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/StatementJDBCDelegateProvider.java37
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ClassMapping.java602
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/MappingStrategy.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ReferenceMapping.java698
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldb.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbNonAudit.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbPrepStmt.java31
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbPrepStmtNonAudit.java51
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/IConstants.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/config/impl/RepositoryConfig.java387
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/verifier/AbstractDBStoreVerifier.java10
28 files changed, 1549 insertions, 1571 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/.settings/org.eclipse.jdt.core.prefs b/plugins/org.eclipse.emf.cdo.server.db/.settings/org.eclipse.jdt.core.prefs
index 4a9b13a..0ac91bb 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/.settings/org.eclipse.jdt.core.prefs
+++ b/plugins/org.eclipse.emf.cdo.server.db/.settings/org.eclipse.jdt.core.prefs
@@ -1,4 +1,4 @@
-#Fri Aug 01 21:17:01 CEST 2008
+#Fri Apr 03 14:03:34 CEST 2009
eclipse.preferences.version=1
org.eclipse.jdt.core.codeComplete.argumentPrefixes=
org.eclipse.jdt.core.codeComplete.argumentSuffixes=
@@ -8,6 +8,8 @@ org.eclipse.jdt.core.codeComplete.localPrefixes=
org.eclipse.jdt.core.codeComplete.localSuffixes=
org.eclipse.jdt.core.codeComplete.staticFieldPrefixes=
org.eclipse.jdt.core.codeComplete.staticFieldSuffixes=
+org.eclipse.jdt.core.codeComplete.staticFinalFieldPrefixes=
+org.eclipse.jdt.core.codeComplete.staticFinalFieldSuffixes=
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.5
org.eclipse.jdt.core.compiler.compliance=1.5
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
diff --git a/plugins/org.eclipse.emf.cdo.server.db/.settings/org.eclipse.jdt.ui.prefs b/plugins/org.eclipse.emf.cdo.server.db/.settings/org.eclipse.jdt.ui.prefs
index a4a18ea..ea82348 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/.settings/org.eclipse.jdt.ui.prefs
+++ b/plugins/org.eclipse.emf.cdo.server.db/.settings/org.eclipse.jdt.ui.prefs
@@ -1,4 +1,4 @@
-#Wed Sep 17 09:24:12 CEST 2008
+#Fri Apr 03 14:03:34 CEST 2009
cleanup.add_default_serial_version_id=true
cleanup.add_generated_serial_version_id=false
cleanup.add_missing_annotations=true
@@ -64,7 +64,7 @@ org.eclipse.jdt.ui.keywordthis=false
org.eclipse.jdt.ui.ondemandthreshold=99
org.eclipse.jdt.ui.overrideannotation=true
org.eclipse.jdt.ui.staticondemandthreshold=99
-org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment"/><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment"/><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment"/><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\r\n * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n * \r\n * Contributors\:\r\n * Eike Stepper - initial API and implementation\r\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author Eike Stepper\r\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment"/><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment"/><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment"/><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">${exception_var}.printStackTrace();</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
+org.eclipse.jdt.ui.text.custom_code_templates=<?xml version\="1.0" encoding\="UTF-8" standalone\="no"?><templates><template autoinsert\="false" context\="gettercomment_context" deleted\="false" description\="Comment for getter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.gettercomment" name\="gettercomment"/><template autoinsert\="false" context\="settercomment_context" deleted\="false" description\="Comment for setter method" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.settercomment" name\="settercomment"/><template autoinsert\="false" context\="constructorcomment_context" deleted\="false" description\="Comment for created constructors" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorcomment" name\="constructorcomment"/><template autoinsert\="false" context\="filecomment_context" deleted\="false" description\="Comment for created Java files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.filecomment" name\="filecomment">/**\r\n * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.\r\n * All rights reserved. This program and the accompanying materials\r\n * are made available under the terms of the Eclipse Public License v1.0\r\n * which accompanies this distribution, and is available at\r\n * http\://www.eclipse.org/legal/epl-v10.html\r\n * \r\n * Contributors\:\r\n * Eike Stepper - initial API and implementation\r\n * Stefan Winkler - major refactoring\r\n */</template><template autoinsert\="false" context\="typecomment_context" deleted\="false" description\="Comment for created types" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.typecomment" name\="typecomment">/**\r\n * @author Eike Stepper\r\n * @author Stefan Winkler\r\n */</template><template autoinsert\="false" context\="fieldcomment_context" deleted\="false" description\="Comment for fields" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.fieldcomment" name\="fieldcomment"/><template autoinsert\="false" context\="methodcomment_context" deleted\="false" description\="Comment for non-overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodcomment" name\="methodcomment"/><template autoinsert\="false" context\="overridecomment_context" deleted\="false" description\="Comment for overriding methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.overridecomment" name\="overridecomment"/><template autoinsert\="false" context\="delegatecomment_context" deleted\="false" description\="Comment for delegate methods" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.delegatecomment" name\="delegatecomment"/><template autoinsert\="true" context\="newtype_context" deleted\="false" description\="Newly created files" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.newtype" name\="newtype">${filecomment}\r\n${package_declaration}\r\n\r\n${typecomment}\r\n${type_declaration}</template><template autoinsert\="true" context\="classbody_context" deleted\="false" description\="Code in new class type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.classbody" name\="classbody">\r\n</template><template autoinsert\="true" context\="interfacebody_context" deleted\="false" description\="Code in new interface type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.interfacebody" name\="interfacebody">\r\n</template><template autoinsert\="true" context\="enumbody_context" deleted\="false" description\="Code in new enum type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.enumbody" name\="enumbody">\r\n</template><template autoinsert\="true" context\="annotationbody_context" deleted\="false" description\="Code in new annotation type bodies" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.annotationbody" name\="annotationbody">\r\n</template><template autoinsert\="false" context\="catchblock_context" deleted\="false" description\="Code in new catch blocks" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.catchblock" name\="catchblock">${exception_var}.printStackTrace();</template><template autoinsert\="false" context\="methodbody_context" deleted\="false" description\="Code in created method stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.methodbody" name\="methodbody">${body_statement}</template><template autoinsert\="false" context\="constructorbody_context" deleted\="false" description\="Code in created constructor stubs" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.constructorbody" name\="constructorbody">${body_statement}</template><template autoinsert\="true" context\="getterbody_context" deleted\="false" description\="Code in created getters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.getterbody" name\="getterbody">return ${field};</template><template autoinsert\="true" context\="setterbody_context" deleted\="false" description\="Code in created setters" enabled\="true" id\="org.eclipse.jdt.ui.text.codetemplates.setterbody" name\="setterbody">${field} \= ${param};</template></templates>
sp_cleanup.add_default_serial_version_id=true
sp_cleanup.add_generated_serial_version_id=false
sp_cleanup.add_missing_annotations=true
diff --git a/plugins/org.eclipse.emf.cdo.server.db/plugin.xml b/plugins/org.eclipse.emf.cdo.server.db/plugin.xml
index acd168a..016d911 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/plugin.xml
+++ b/plugins/org.eclipse.emf.cdo.server.db/plugin.xml
@@ -14,7 +14,6 @@
<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">
@@ -35,17 +34,4 @@
type="vertical">
</mappingStrategy>
</extension>
-
- <extension
- point="org.eclipse.emf.cdo.server.db.jdbcDelegateProviders">
- <jdbcDelegateProvider
- class="org.eclipse.emf.cdo.server.internal.db.jdbc.StatementJDBCDelegateProvider"
- type="statement">
- </jdbcDelegateProvider>
- <jdbcDelegateProvider
- class="org.eclipse.emf.cdo.server.internal.db.jdbc.PreparedStatementJDBCDelegateProvider"
- type="preparedStatement">
- </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
deleted file mode 100644
index 0481261..0000000
--- a/plugins/org.eclipse.emf.cdo.server.db/schema/delegateProviders.exsd
+++ /dev/null
@@ -1,109 +0,0 @@
-<?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 c9dca68..624e1cd 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
@@ -15,8 +15,6 @@ import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.DBStore;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-import org.eclipse.emf.cdo.server.internal.db.jdbc.PreparedStatementJDBCDelegateProvider;
-import org.eclipse.emf.cdo.server.internal.db.jdbc.StatementJDBCDelegateProvider;
import org.eclipse.emf.cdo.server.internal.db.mapping.HorizontalMappingStrategy;
import org.eclipse.net4j.db.IDBAdapter;
@@ -52,13 +50,12 @@ public final class CDODBUtil
* @since 2.0
*/
public static IDBStore createStore(IMappingStrategy mappingStrategy, IDBAdapter dbAdapter,
- IDBConnectionProvider dbConnectionProvider, IJDBCDelegateProvider delegateProvider)
+ IDBConnectionProvider dbConnectionProvider)
{
DBStore store = new DBStore();
store.setMappingStrategy(mappingStrategy);
store.setDBAdapter(dbAdapter);
store.setDbConnectionProvider(dbConnectionProvider);
- store.setJDBCDelegateProvider(delegateProvider);
mappingStrategy.setStore(store);
return store;
}
@@ -72,22 +69,6 @@ public final class CDODBUtil
}
/**
- * @since 2.0
- */
- public static IJDBCDelegateProvider createStatementJDBCDelegateProvider()
- {
- return new StatementJDBCDelegateProvider();
- }
-
- /**
- * @since 2.0
- */
- public static IJDBCDelegateProvider createPreparedStatementJDBCDelegateProvider()
- {
- return new PreparedStatementJDBCDelegateProvider();
- }
-
- /**
* 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.
*
@@ -121,36 +102,6 @@ public final class CDODBUtil
}
/**
- * @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;
- }
-
- /**
* Get the long value of a CDOID (by delegating to {@link CDOIDUtil#getLong(org.eclipse.emf.cdo.common.id.CDOID)}) In
* addition, provide a check for external IDs which are not supported by the DBStore
*
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java
index 3a51ec5..d236155 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStore.java
@@ -43,12 +43,16 @@ public interface IDBStore extends IStore
/**
* @since 2.0
+ * @deprecated should be moved to metamanager
*/
+ @Deprecated
public long getMetaID(EModelElement modelElement);
/**
* @since 2.0
+ * @deprecated should be moved to metamanager
*/
+ @Deprecated
public EModelElement getMetaInstance(long id);
/**
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 53eeb07..0a024cc 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
@@ -12,6 +12,8 @@ package org.eclipse.emf.cdo.server.db;
import org.eclipse.emf.cdo.server.IStoreAccessor;
+import java.sql.Connection;
+
/**
* @author Eike Stepper
* @noimplement This interface is not intended to be implemented by clients.
@@ -20,8 +22,5 @@ public interface IDBStoreAccessor extends IStoreAccessor
{
public IDBStore getStore();
- /**
- * @since 2.0
- */
- public IJDBCDelegate getJDBCDelegate();
+ public Connection getConnection();
}
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
deleted file mode 100644
index e456e1f..0000000
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegate.java
+++ /dev/null
@@ -1,181 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Stefan Winkler - initial API and implementation
- * Eike Stepper - maintenance
- * Stefan Winkler - https://bugs.eclipse.org/bugs/show_bug.cgi?id=259402
- */
-package org.eclipse.emf.cdo.server.db;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.server.IStoreAccessor;
-import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
-import org.eclipse.emf.cdo.server.db.mapping.IAttributeMapping;
-import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
-import org.eclipse.emf.cdo.server.db.mapping.IReferenceMapping;
-import org.eclipse.emf.cdo.server.internal.db.jdbc.AbstractJDBCDelegate;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.eclipse.net4j.db.IDBConnectionProvider;
-import org.eclipse.net4j.util.collection.Pair;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-
-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 extends IDBConnectionProvider
-{
- // --------------------------------------------------------------
- // General methods
- // --------------------------------------------------------------
-
- /**
- * Get the one omnipresent statement object of this JDBC delegate
- */
- public Statement getStatement();
-
- /**
- * Get a prepared statement. The caller is responsible of closing it.
- */
- public PreparedStatement getPreparedStatement(String sql);
-
- public void setStoreAccessor(IDBStoreAccessor storeAccessor);
-
- /**
- * Do any outstanding writes (e.g. execute batches). Called any number of times - but at least once immediately before
- * commit().
- *
- * @see IStoreAccessor#write(org.eclipse.emf.cdo.server.IStoreAccessor.CommitContext, OMMonitor)
- */
- public void flush(OMMonitor monitor);
-
- /**
- * Do a commit on the JDBC connection.
- */
- public void commit(OMMonitor monitor);
-
- /**
- * Do a rollback on the JDBC connection.
- */
- public void rollback();
-
- // --------------------------------------------------------------
- // Writing Revisions / Attributes
- // --------------------------------------------------------------
-
- /**
- * Insert an attribute row.
- */
- public void insertAttributes(InternalCDORevision revision, IClassMapping classMapping);
-
- /**
- * Update an attribute row.
- */
- public void updateAttributes(InternalCDORevision revision, IClassMapping classMapping);
-
- /**
- * Update an attribute row.
- */
- public void updateAttributes(CDOID id, int newVersion, long created,
- List<Pair<IAttributeMapping, Object>> attributeChanges, IClassMapping classMapping);
-
- /**
- * Update an attribute row (including containment and resource attributes).
- */
- public void updateAttributes(CDOID id, int newVersion, long created, CDOID newContainerId,
- int newContainingFeatureId, CDOID newResourceId, List<Pair<IAttributeMapping, Object>> attributeChanges,
- IClassMapping classMapping);
-
- /**
- * Set the revised date of a specific revision's previous version.
- */
- public void updateRevisedForReplace(InternalCDORevision revision, IClassMapping classMapping);
-
- /**
- * Set the revised date of all unrevised rows of cdoid
- */
- public void updateRevisedForDetach(CDOID id, long revised, IClassMapping classMapping);
-
- /**
- * Remove an attribute row.
- */
- public void deleteAttributes(CDOID id, IClassMapping classMapping);
-
- // --------------------------------------------------------------
- // Writing References
- // --------------------------------------------------------------
-
- /**
- * Insert a reference row.
- */
- public void insertReference(CDOID id, int version, int index, CDOID targetId, IReferenceMapping referenceMapping);
-
- /**
- * Insert a reference row shifting all subsequent indices one position up.
- */
- public void insertReferenceRow(CDOID id, int newVersion, int index, CDOID value, IReferenceMapping referenceMapping);
-
- /**
- * Move one reference row shifting all subsequent indices in between accordingly.
- */
- public void moveReferenceRow(CDOID id, int newVersion, int oldPosition, int newPosition,
- IReferenceMapping referenceMapping);
-
- /**
- * Remove a reference row shifting all subsequent indices one position down.
- */
- public void removeReferenceRow(CDOID id, int index, int newVersion, IReferenceMapping referenceMapping);
-
- /**
- * Update the value of a reference row.
- */
- public void updateReference(CDOID id, int newVersion, int index, CDOID value, IReferenceMapping referenceMapping);
-
- /**
- * Delete all reference rows of a cdoid.
- */
- public void deleteReferences(CDOID id, IReferenceMapping referenceMapping);
-
- /**
- * Update the version number of all references of a CDOID to newVersion.
- */
- public void updateReferenceVersion(CDOID id, int newVersion, IReferenceMapping referenceMapping);
-
- // --------------------------------------------------------------
- // Reading
- // --------------------------------------------------------------
-
- /**
- * Select a revision's attributes
- *
- * @return <code>true</code> if the revision attributes have been successfully loaded.<br>
- * <code>false</code> if the revision does not exist in the database.
- */
- public boolean selectRevisionAttributes(InternalCDORevision revision, IClassMapping classMapping, String where);
-
- /**
- * Select a revision's references (or a part thereof)
- */
- public void selectRevisionReferences(InternalCDORevision revision, IReferenceMapping referenceMapping,
- int referenceChunk);
-
- /**
- * Select a revision's reference's chunks
- */
- public void selectRevisionReferenceChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks,
- IReferenceMapping referenceMapping, String where);
-}
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
deleted file mode 100644
index 4aec640..0000000
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IJDBCDelegateProvider.java
+++ /dev/null
@@ -1,35 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Stefan Winkler - initial API and implementation
- * Eike Stepper - maintenance
- */
-package org.eclipse.emf.cdo.server.db;
-
-import java.util.Map;
-
-/**
- * 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();
-
- /**
- * Set configuration properties
- */
- public void setProperties(Map<String, String> properties);
-}
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 599f031..834c28c 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
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - https://bugs.eclipse.org/bugs/show_bug.cgi?id=259402
+ * Stefan Winkler - https://bugs.eclipse.org/bugs/show_bug.cgi?id=259402
*/
package org.eclipse.emf.cdo.server.internal.db;
@@ -18,7 +18,6 @@ import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.server.db.IDBStore;
-import org.eclipse.emf.cdo.server.db.IJDBCDelegateProvider;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageRegistry;
@@ -53,7 +52,7 @@ import java.util.Map;
import java.util.Set;
/**
- * @author Eike Stepper
+ * @author Eike Stepper TODO: factor out type map and meta stuff into MetadataManager
*/
public class DBStore extends LongIDStore implements IDBStore
{
@@ -71,8 +70,6 @@ public class DBStore extends LongIDStore implements IDBStore
private IDBConnectionProvider dbConnectionProvider;
- private IJDBCDelegateProvider jdbcDelegateProvider;
-
@ExcludeFromDump
private transient ProgressDistributor accessorWriteDistributor = new ProgressDistributor.Geometric()
{
@@ -95,6 +92,7 @@ public class DBStore extends LongIDStore implements IDBStore
@ExcludeFromDump
private transient StoreAccessorPool writerPool = new StoreAccessorPool(this, null);
+ @Deprecated
private static Map<EClassifier, DBType> typeMap = new HashMap<EClassifier, DBType>();
static
@@ -123,22 +121,11 @@ public class DBStore extends LongIDStore implements IDBStore
public DBStore()
{
- super(TYPE, set(ChangeFormat.REVISION, ChangeFormat.DELTA), set(RevisionTemporality.AUDITING,
- RevisionTemporality.NONE), set(RevisionParallelism.NONE));
- setRevisionTemporality(RevisionTemporality.AUDITING);
- }
+ super(TYPE, set(ChangeFormat.REVISION), set(RevisionTemporality.AUDITING, RevisionTemporality.NONE),
+ set(RevisionParallelism.NONE));
- @Override
- public Set<ChangeFormat> getSupportedChangeFormats()
- {
- if (getRevisionTemporality() == RevisionTemporality.AUDITING)
- {
- return set(ChangeFormat.REVISION);
- }
- else
- {
- return set(ChangeFormat.REVISION, ChangeFormat.DELTA);
- }
+ // TODO: move temporality and changformat properties to mapping strategy
+ setRevisionTemporality(RevisionTemporality.AUDITING);
}
public IMappingStrategy getMappingStrategy()
@@ -169,7 +156,6 @@ public class DBStore extends LongIDStore implements IDBStore
public void setDbConnectionProvider(IDBConnectionProvider dbConnectionProvider)
{
- // TODO Need to update provider in JDBCWrapper, too?
this.dbConnectionProvider = dbConnectionProvider;
}
@@ -178,16 +164,6 @@ public class DBStore extends LongIDStore implements IDBStore
dbConnectionProvider = DBUtil.createConnectionProvider(dataSource);
}
- public IJDBCDelegateProvider getJDBCDelegateProvider()
- {
- return jdbcDelegateProvider;
- }
-
- public void setJDBCDelegateProvider(IJDBCDelegateProvider provider)
- {
- jdbcDelegateProvider = provider;
- }
-
public ProgressDistributor getAccessorWriteDistributor()
{
return accessorWriteDistributor;
@@ -234,6 +210,8 @@ public class DBStore extends LongIDStore implements IDBStore
return new DBStoreAccessor(this, transaction);
}
+ /** @deprecated move to meta manager */
+ @Deprecated
public long getMetaID(EModelElement modelElement)
{
InternalCDOPackageRegistry packageRegistry = (InternalCDOPackageRegistry)getRepository().getPackageRegistry();
@@ -250,6 +228,8 @@ public class DBStore extends LongIDStore implements IDBStore
}
}
+ /** @deprecated move to meta manager */
+ @Deprecated
public EModelElement getMetaInstance(long id)
{
CDOIDMeta cdoid = CDOIDUtil.createMeta(id);
@@ -258,6 +238,7 @@ public class DBStore extends LongIDStore implements IDBStore
return (EModelElement)metaInstance;
}
+ @Deprecated
public Connection getConnection()
{
Connection connection = dbConnectionProvider.getConnection();
@@ -294,6 +275,7 @@ public class DBStore extends LongIDStore implements IDBStore
super.doActivate();
Connection connection = getConnection();
+ // TODO move to meta manager?
try
{
Set<IDBTable> createdTables = CDODBSchema.INSTANCE.create(dbAdapter, connection);
@@ -320,6 +302,7 @@ public class DBStore extends LongIDStore implements IDBStore
creationTime = getStartupTime();
firstTime = true;
+ // TODO: unify and standardize repository management
DBUtil.insertRow(connection, dbAdapter, CDODBSchema.REPOSITORY, creationTime, 1, creationTime, 0, CRASHED, CRASHED);
OM.LOG.info(MessageFormat.format("First start: {0,date} {0,time}", creationTime));
}
@@ -342,6 +325,7 @@ public class DBStore extends LongIDStore implements IDBStore
setLastMetaID(lastMetaId);
setLastObjectID(lastObjectID);
+ // TODO: unify and standardize repository management
StringBuilder builder = new StringBuilder();
builder.append("UPDATE ");
builder.append(CDODBSchema.REPOSITORY);
@@ -383,6 +367,7 @@ public class DBStore extends LongIDStore implements IDBStore
LifecycleUtil.deactivate(mappingStrategy);
+ // TODO: unify and standardize repository management
StringBuilder builder = new StringBuilder();
builder.append("UPDATE ");
builder.append(CDODBSchema.REPOSITORY);
@@ -432,6 +417,10 @@ public class DBStore extends LongIDStore implements IDBStore
return System.currentTimeMillis();
}
+ /**
+ * @deprecated move to meta-manager
+ */
+ @Deprecated
public static DBType getDBType(EClassifier type)
{
if (type instanceof EClass)
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 c8ac86f..dcdeecd 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
@@ -25,10 +25,10 @@ import org.eclipse.emf.cdo.common.revision.CDORevisionUtil;
import org.eclipse.emf.cdo.server.IQueryContext;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.ISession;
+import org.eclipse.emf.cdo.server.IStoreAccessor;
import org.eclipse.emf.cdo.server.ITransaction;
import org.eclipse.emf.cdo.server.IStore.RevisionTemporality;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
-import org.eclipse.emf.cdo.server.db.IJDBCDelegate;
import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
import org.eclipse.emf.cdo.server.db.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -44,7 +44,6 @@ import org.eclipse.net4j.db.IDBRowHandler;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
import org.eclipse.net4j.util.collection.CloseableIterator;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
import org.eclipse.net4j.util.om.monitor.ProgressDistributable;
import org.eclipse.net4j.util.om.monitor.ProgressDistributor;
@@ -55,6 +54,7 @@ import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
+import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.util.ArrayList;
@@ -73,9 +73,11 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, DBStoreAccessor.class);
+ /** @deprecated move to meta manager */
+ @Deprecated
private static final boolean ZIP_PACKAGE_BYTES = true;
- private IJDBCDelegate jdbcDelegate;
+ private Connection connection = null;
@ExcludeFromDump
@SuppressWarnings("unchecked")
@@ -91,31 +93,19 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
{
public void runLoop(int index, CommitContext commitContext, OMMonitor monitor) throws Exception
{
- jdbcDelegate.flush(monitor.fork());
+ // TODO - reenable when reimplementing stmt caching
+ // flush(monitor.fork());
}
});
public DBStoreAccessor(DBStore store, ISession session) throws DBException
{
super(store, session);
- initJDBCDelegate();
}
public DBStoreAccessor(DBStore store, ITransaction transaction) throws DBException
{
super(store, transaction);
- initJDBCDelegate();
- }
-
- private void initJDBCDelegate()
- {
- jdbcDelegate = getStore().getJDBCDelegateProvider().getJDBCDelegate();
- jdbcDelegate.setStoreAccessor(this);
- }
-
- public IJDBCDelegate getJDBCDelegate()
- {
- return jdbcDelegate;
}
@Override
@@ -124,11 +114,16 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return (DBStore)super.getStore();
}
+ /** TODO: check how to handle */
public DBStoreChunkReader createChunkReader(InternalCDORevision revision, EStructuralFeature feature)
{
return new DBStoreChunkReader(this, revision, feature);
}
+ /**
+ * @deprecated move to meta manager
+ */
+ @Deprecated
public final Collection<InternalCDOPackageUnit> readPackageUnits()
{
final Map<String, InternalCDOPackageUnit> packageUnits = new HashMap<String, InternalCDOPackageUnit>();
@@ -144,7 +139,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
};
- DBUtil.select(jdbcDelegate.getConnection(), unitRowHandler, CDODBSchema.PACKAGE_UNITS_ID,
+ DBUtil.select(getConnection(), unitRowHandler, CDODBSchema.PACKAGE_UNITS_ID,
CDODBSchema.PACKAGE_UNITS_ORIGINAL_TYPE, CDODBSchema.PACKAGE_UNITS_TIME_STAMP);
final Map<String, List<InternalCDOPackageInfo>> packageInfos = new HashMap<String, List<InternalCDOPackageInfo>>();
@@ -175,9 +170,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
};
- DBUtil.select(jdbcDelegate.getConnection(), infoRowHandler, CDODBSchema.PACKAGE_INFOS_UNIT,
- CDODBSchema.PACKAGE_INFOS_URI, CDODBSchema.PACKAGE_INFOS_PARENT, CDODBSchema.PACKAGE_INFOS_META_LB,
- CDODBSchema.PACKAGE_INFOS_META_UB);
+ DBUtil.select(getConnection(), infoRowHandler, CDODBSchema.PACKAGE_INFOS_UNIT, CDODBSchema.PACKAGE_INFOS_URI,
+ CDODBSchema.PACKAGE_INFOS_PARENT, CDODBSchema.PACKAGE_INFOS_META_LB, CDODBSchema.PACKAGE_INFOS_META_UB);
for (Entry<String, InternalCDOPackageUnit> entry : packageUnits.entrySet())
{
@@ -192,15 +186,22 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return packageUnits.values();
}
+ /**
+ * @deprecated move to meta manager
+ */
+ @Deprecated
public final EPackage[] loadPackageUnit(InternalCDOPackageUnit packageUnit)
{
String where = CDODBSchema.PACKAGE_UNITS_ID.getName() + "='" + packageUnit.getID() + "'";
- Object[] values = DBUtil.select(jdbcDelegate.getConnection(), where, CDODBSchema.PACKAGE_UNITS_PACKAGE_DATA);
+ Object[] values = DBUtil.select(getConnection(), where, CDODBSchema.PACKAGE_UNITS_PACKAGE_DATA);
byte[] bytes = (byte[])values[0];
EPackage ePackage = createEPackage(packageUnit, bytes);
return EMFUtil.getAllPackages(ePackage);
}
+ /**
+ * TODO caching?
+ */
public CloseableIterator<CDOID> readObjectIDs()
{
if (TRACER.isEnabled())
@@ -211,6 +212,9 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return getStore().getMappingStrategy().readObjectIDs(this);
}
+ /**
+ * TODO caching?
+ */
public CDOClassifierRef readObjectType(CDOID id)
{
if (TRACER.isEnabled())
@@ -221,6 +225,20 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return getStore().getMappingStrategy().readObjectType(this, id);
}
+ protected EClass getObjectType(CDOID id)
+ {
+ // TODO Replace calls to getObjectType by optimized calls to RevisionManager.getObjectType (cache!)
+ CDOClassifierRef type = readObjectType(id);
+ if (type == null)
+ {
+ return null;
+ }
+
+ IRepository repository = getStore().getRepository();
+ CDOPackageRegistry packageRegistry = repository.getPackageRegistry();
+ return (EClass)type.resolve(packageRegistry);
+ }
+
public InternalCDORevision readRevision(CDOID id, int referenceChunk, AdditionalRevisionCache cache)
{
if (TRACER.isEnabled())
@@ -292,6 +310,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
/**
+ * TODO: implement as query when query implementation is done?
+ *
* @since 2.0
*/
public void queryResources(QueryResourcesContext context)
@@ -309,20 +329,6 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
throw new UnsupportedOperationException();
}
- protected EClass getObjectType(CDOID id)
- {
- // TODO Replace calls to getObjectType by optimized calls to RevisionManager.getObjectType (cache!)
- CDOClassifierRef type = readObjectType(id);
- if (type == null)
- {
- return null;
- }
-
- IRepository repository = getStore().getRepository();
- CDOPackageRegistry packageRegistry = repository.getPackageRegistry();
- return (EClass)type.resolve(packageRegistry);
- }
-
public CloseableIterator<Object> createQueryIterator(CDOQueryInfo queryInfo)
{
throw new UnsupportedOperationException();
@@ -330,6 +336,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
public void refreshRevisions()
{
+ // TODO is this empty on purpose or should it be implemented (how?)
}
@Override
@@ -339,6 +346,10 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
distributor.run(ops, context, monitor);
}
+ /**
+ * @deprecated move to meta manager
+ */
+ @Deprecated
public final void writePackageUnits(InternalCDOPackageUnit[] packageUnits, OMMonitor monitor)
{
try
@@ -353,6 +364,10 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
}
+ /**
+ * @deprecated move to meta manager
+ */
+ @Deprecated
private void fillSystemTables(InternalCDOPackageUnit[] packageUnits, OMMonitor monitor)
{
try
@@ -369,6 +384,10 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
}
+ /**
+ * @deprecated move to meta manager
+ */
+ @Deprecated
private void fillSystemTables(InternalCDOPackageUnit packageUnit, OMMonitor monitor)
{
try
@@ -388,7 +407,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
try
{
- pstmt = jdbcDelegate.getPreparedStatement(sql);
+ pstmt = getPreparedStatement(sql);
pstmt.setString(1, packageUnit.getID());
pstmt.setInt(2, packageUnit.getOriginalType().ordinal());
pstmt.setLong(3, packageUnit.getTimeStamp());
@@ -425,6 +444,18 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
}
+ /**
+ * TODO - inline statement preparing to simplify handling
+ */
+ private PreparedStatement getPreparedStatement(String sql) throws SQLException
+ {
+ return getConnection().prepareStatement(sql);
+ }
+
+ /**
+ * @deprecated move to meta manager
+ */
+ @Deprecated
private byte[] getEPackageBytes(InternalCDOPackageUnit packageUnit)
{
EPackage ePackage = packageUnit.getTopLevelPackageInfo().getEPackage();
@@ -432,12 +463,20 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return EMFUtil.getEPackageBytes(ePackage, ZIP_PACKAGE_BYTES, packageRegistry);
}
+ /**
+ * @deprecated move to meta manager
+ */
+ @Deprecated
private EPackage createEPackage(InternalCDOPackageUnit packageUnit, byte[] bytes)
{
CDOPackageRegistry packageRegistry = getStore().getRepository().getPackageRegistry();
return EMFUtil.createEPackage(packageUnit.getID(), bytes, ZIP_PACKAGE_BYTES, packageRegistry);
}
+ /**
+ * @deprecated move to meta manager
+ */
+ @Deprecated
private void fillSystemTables(InternalCDOPackageInfo packageInfo, OMMonitor monitor)
{
if (TRACER.isEnabled())
@@ -459,7 +498,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
try
{
- pstmt = jdbcDelegate.getPreparedStatement(sql);
+ pstmt = getPreparedStatement(sql);
pstmt.setString(1, packageURI);
pstmt.setString(2, parentURI);
pstmt.setString(3, unitID);
@@ -487,6 +526,10 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
}
+ /**
+ * @deprecated move to meta manager
+ */
+ @Deprecated
private void createModelTables(InternalCDOPackageUnit[] packageUnits, OMMonitor monitor)
{
monitor.begin();
@@ -495,7 +538,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
try
{
Set<IDBTable> affectedTables = mapPackageUnits(packageUnits);
- getStore().getDBAdapter().createTables(affectedTables, jdbcDelegate.getConnection());
+ getStore().getDBAdapter().createTables(affectedTables, getConnection());
}
finally
{
@@ -507,6 +550,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
@Override
protected void writeRevisionDeltas(InternalCDORevisionDelta[] revisionDeltas, long created, OMMonitor monitor)
{
+ // TODO move check to mapping strategy
+
if (!(getStore().getRevisionTemporality() == RevisionTemporality.NONE))
{
throw new UnsupportedOperationException("Revision Deltas are only supported in non-auditing mode!");
@@ -595,8 +640,9 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
/**
- * TODO Move this somehow to DBAdapter
+ * @deprecated TODO Move this somehow to DBAdapter
*/
+ @Deprecated
protected Boolean getBoolean(Object value)
{
if (value == null)
@@ -617,6 +663,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
throw new IllegalArgumentException("Not a boolean value: " + value);
}
+ /** @deprecated move to meta manager */
+ @Deprecated
protected Set<IDBTable> mapPackageUnits(InternalCDOPackageUnit[] packageUnits)
{
Set<IDBTable> affectedTables = new HashSet<IDBTable>();
@@ -631,6 +679,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return affectedTables;
}
+ /** @deprecated move to meta manager */
+ @Deprecated
protected void mapPackageInfos(InternalCDOPackageInfo[] packageInfos, Set<IDBTable> affectedTables)
{
for (InternalCDOPackageInfo packageInfo : packageInfos)
@@ -645,6 +695,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
}
+ /** @deprecated move to meta manager */
+ @Deprecated
protected Set<IDBTable> mapClasses(EClass... eClasses)
{
Set<IDBTable> affectedTables = new HashSet<IDBTable>();
@@ -664,37 +716,69 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return affectedTables;
}
+ /** @deprecated move to meta manager */
+ @Deprecated
protected InternalCDOPackageUnit createPackageUnit()
{
return (InternalCDOPackageUnit)CDOModelUtil.createPackageUnit();
}
+ /** @deprecated move to meta manager */
+ @Deprecated
protected InternalCDOPackageInfo createPackageInfo()
{
return (InternalCDOPackageInfo)CDOModelUtil.createPackageInfo();
}
+ public Connection getConnection()
+ {
+ return connection;
+ }
+
public final void commit(OMMonitor monitor)
{
- jdbcDelegate.commit(monitor);
+ monitor.begin();
+ Async async = monitor.forkAsync();
+
+ try
+ {
+ getConnection().commit();
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ async.stop();
+ monitor.done();
+ }
}
@Override
- protected final void rollback(CommitContext context)
+ protected final void rollback(IStoreAccessor.CommitContext commitContext)
{
- jdbcDelegate.rollback();
+ try
+ {
+ getConnection().rollback();
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
}
@Override
protected void doActivate() throws Exception
{
- LifecycleUtil.activate(jdbcDelegate);
+ connection = getStore().getDBConnectionProvider().getConnection();
}
@Override
protected void doDeactivate() throws Exception
{
- LifecycleUtil.deactivate(jdbcDelegate);
+ DBUtil.close(connection);
+ connection = null;
}
@Override
@@ -706,6 +790,6 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
@Override
protected void doUnpassivate() throws Exception
{
- // Do nothing
+ // TODO Check if connection is still valid.
}
}
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 1f23877..b2759fc 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,7 +14,6 @@ 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.mapping.IMappingStrategy;
import org.eclipse.net4j.db.DBUtil;
@@ -48,33 +47,10 @@ 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, 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);
- }
-
- Map<String, String> properties = RepositoryConfigurator.getProperties(delegateProviderConfig, 1);
- delegateProvider.setProperties(properties);
-
- return delegateProvider;
+ return CDODBUtil.createStore(mappingStrategy, dbAdapter, connectionProvider);
}
private IMappingStrategy getMappingStrategy(Element storeConfig)
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 e5f3823..8b6194e 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
@@ -8,6 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
* Stefan Winkler - https://bugs.eclipse.org/bugs/show_bug.cgi?id=259402
+ * Stefan Winkler - redesign (prepared statements)
*/
package org.eclipse.emf.cdo.server.internal.db;
@@ -30,6 +31,8 @@ import org.eclipse.net4j.util.lifecycle.Lifecycle;
import org.eclipse.emf.ecore.EClass;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;
@@ -49,6 +52,12 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
private transient Object initializeLock = new Object();
+ private String sqlDelete;
+
+ private String sqlInsert;
+
+ private String sqlSelect;
+
public ObjectTypeCache()
{
}
@@ -65,26 +74,18 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
public final CDOClassifierRef getObjectType(IDBStoreAccessor accessor, CDOID id)
{
- Statement statement = accessor.getJDBCDelegate().getStatement();
- initialize(statement);
-
- StringBuilder builder = new StringBuilder();
- builder.append("SELECT ");
- builder.append(typeField);
- builder.append(" FROM ");
- builder.append(table);
- builder.append(" WHERE ");
- builder.append(idField);
- builder.append("=");
- builder.append(CDOIDUtil.getLong(id));
- String sql = builder.toString();
- DBUtil.trace(sql);
-
- ResultSet resultSet = null;
+ Connection connection = accessor.getConnection();
+ initialize(connection);
+
+ PreparedStatement stmt = null;
try
{
- resultSet = statement.executeQuery(sql);
+ stmt = connection.prepareStatement(sqlSelect);
+ stmt.setLong(1, CDOIDUtil.getLong(id));
+ DBUtil.trace(stmt.toString());
+ ResultSet resultSet = stmt.executeQuery();
+
if (!resultSet.next())
{
DBUtil.trace("ClassID for CDOID " + id + " not found");
@@ -101,59 +102,57 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
}
finally
{
- DBUtil.close(resultSet);
+ // TODO - statement caching
+ DBUtil.close(stmt);
}
}
public final void putObjectType(IDBStoreAccessor accessor, CDOID id, EClass type)
{
- Statement statement = accessor.getJDBCDelegate().getStatement();
- initialize(statement);
-
- StringBuilder builder = new StringBuilder();
- builder.append("INSERT INTO ");
- builder.append(table);
- builder.append(" VALUES (");
- builder.append(CDOIDUtil.getLong(id));
- builder.append(", ");
- builder.append(accessor.getStore().getMetaID(type));
- builder.append(")");
- String sql = builder.toString();
- DBUtil.trace(sql);
+ Connection connection = accessor.getConnection();
+ initialize(connection);
+
+ PreparedStatement stmt = null;
try
{
- statement.execute(sql);
- if (statement.getUpdateCount() != 1)
+ stmt = connection.prepareStatement(sqlInsert);
+ stmt.setLong(1, CDOIDUtil.getLong(id));
+ stmt.setLong(2, accessor.getStore().getMetaID(type));
+ DBUtil.trace(stmt.toString());
+ int result = stmt.executeUpdate();
+
+ if (result != 1)
{
- throw new DBException("Object type not inserted: " + id + " -> " + type);
+ throw new DBException("Object type could not be deleted: " + id);
}
}
catch (SQLException ex)
{
throw new DBException(ex);
}
+ finally
+ {
+ // TODO - statement caching
+ DBUtil.close(stmt);
+ }
}
public final void removeObjectType(IDBStoreAccessor accessor, CDOID id)
{
- Statement statement = accessor.getJDBCDelegate().getStatement();
- initialize(statement);
-
- StringBuilder builder = new StringBuilder();
- builder.append("DELETE FROM ");
- builder.append(table);
- builder.append(" WHERE ");
- builder.append(idField);
- builder.append(" = ");
- builder.append(CDOIDUtil.getLong(id));
- String sql = builder.toString();
- DBUtil.trace(sql);
+ Connection connection = accessor.getConnection();
+ initialize(connection);
+
+ PreparedStatement stmt = null;
try
{
- statement.execute(sql);
- if (statement.getUpdateCount() != 1)
+ stmt = connection.prepareStatement(sqlDelete);
+ stmt.setLong(1, CDOIDUtil.getLong(id));
+ DBUtil.trace(stmt.toString());
+ int result = stmt.executeUpdate();
+
+ if (result != 1)
{
throw new DBException("Object type could not be deleted: " + id);
}
@@ -162,10 +161,17 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
{
throw new DBException(ex);
}
+ finally
+ {
+ // TODO - statement caching
+ DBUtil.close(stmt);
+ }
}
- private void initialize(Statement statement)
+ private void initialize(Connection connection)
{
+ // TODO - is there a better way to initialize this
+ // e.g. doActivate() - only problem there is to get hold of a statement ....
synchronized (initializeLock)
{
if (table == null)
@@ -177,8 +183,28 @@ public class ObjectTypeCache extends Lifecycle implements IObjectTypeCache
table.addIndex(IDBIndex.Type.PRIMARY_KEY, idField);
IDBAdapter dbAdapter = mappingStrategy.getStore().getDBAdapter();
- dbAdapter.createTable(table, statement);
+
+ Statement statement = null;
+ try
+ {
+ statement = connection.createStatement();
+ dbAdapter.createTable(table, statement);
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(statement);
+ }
}
+
+ sqlSelect = "SELECT " + typeField.getName() + " FROM " + table.getName() + " WHERE " + idField.getName() + " = ?";
+
+ sqlInsert = "INSERT INTO " + table.getName() + " VALUES (?,?)";
+
+ sqlDelete = "DELETE FROM " + table.getName() + " WHERE " + idField.getName() + " = ?";
}
}
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
index 33acb78..06a656a 100644
--- 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
@@ -19,7 +19,6 @@ import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
import org.eclipse.emf.cdo.server.db.CDODBUtil;
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.mapping.IAttributeMapping;
import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
import org.eclipse.emf.cdo.server.db.mapping.IReferenceMapping;
@@ -54,7 +53,7 @@ import java.util.List;
* @author Stefan Winkler
* @since 2.0
*/
-public abstract class AbstractJDBCDelegate extends Lifecycle implements IJDBCDelegate
+public abstract class AbstractJDBCDelegate extends Lifecycle
{
private IDBStoreAccessor storeAccessor;
@@ -107,7 +106,7 @@ public abstract class AbstractJDBCDelegate extends Lifecycle implements IJDBCDel
return storeAccessor.isReader();
}
- public final Connection getConnection()
+ public Connection getConnection()
{
return connection;
}
@@ -547,6 +546,6 @@ public abstract class AbstractJDBCDelegate extends Lifecycle implements IJDBCDel
* 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, long metaID,
- String where) throws SQLException;
+ abstract ResultSet doSelectRevisionReferences(String tableName, long sourceId, int version, long metaID, String where)
+ throws SQLException;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/JDBCPerformanceReporter.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/JDBCPerformanceReporter.java
deleted file mode 100644
index f45a982..0000000
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/JDBCPerformanceReporter.java
+++ /dev/null
@@ -1,334 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.server.internal.db.jdbc;
-
-import org.eclipse.emf.cdo.common.id.CDOID;
-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.mapping.IAttributeMapping;
-import org.eclipse.emf.cdo.server.db.mapping.IClassMapping;
-import org.eclipse.emf.cdo.server.db.mapping.IReferenceMapping;
-import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
-import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
-
-import org.eclipse.net4j.util.collection.Pair;
-import org.eclipse.net4j.util.lifecycle.Lifecycle;
-import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import org.eclipse.net4j.util.om.monitor.OMMonitor;
-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;
-
-/**
- * This class is only to be used in tests (there is a static data aggregation member!).
- *
- * @author Stefan Winkler
- * @since 2.0
- */
-public class JDBCPerformanceReporter extends Lifecycle implements IJDBCDelegate
-{
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, JDBCPerformanceReporter.class);
-
- private static Map<String, TimeData> timeData = Collections.synchronizedMap(new HashMap<String, TimeData>());
-
- private IJDBCDelegate delegate;
-
- public JDBCPerformanceReporter()
- {
- }
-
- public IJDBCDelegate getDelegate()
- {
- return delegate;
- }
-
- public void setDelegate(IJDBCDelegate delegate)
- {
- checkInactive();
- this.delegate = delegate;
- }
-
- public Connection getConnection()
- {
- return delegate.getConnection();
- }
-
- public PreparedStatement getPreparedStatement(String sql)
- {
- return delegate.getPreparedStatement(sql);
- }
-
- public Statement getStatement()
- {
- return delegate.getStatement();
- }
-
- public void insertAttributes(InternalCDORevision revision, IClassMapping classMapping)
- {
- long time = System.currentTimeMillis();
- delegate.insertAttributes(revision, classMapping);
- time = System.currentTimeMillis() - time;
-
- registerCall("insertAttributes", time);
- }
-
- public void insertReference(CDOID id, int version, int index, CDOID targetId, IReferenceMapping referenceMapping)
- {
- long time = System.currentTimeMillis();
- delegate.insertReference(id, version, index, targetId, referenceMapping);
- time = System.currentTimeMillis() - time;
- registerCall("insertReferenceDbId", time);
- }
-
- public void flush(OMMonitor monitor)
- {
- long time = System.currentTimeMillis();
- delegate.flush(monitor);
- time = System.currentTimeMillis() - time;
- registerCall("write", time);
- }
-
- public void commit(OMMonitor monitor)
- {
- delegate.commit(monitor);
- }
-
- public void rollback()
- {
- delegate.rollback();
- }
-
- public boolean selectRevisionAttributes(InternalCDORevision revision, IClassMapping classMapping, String where)
- {
- long time = System.currentTimeMillis();
- boolean result = delegate.selectRevisionAttributes(revision, null, where);
- time = System.currentTimeMillis() - time;
- registerCall("selectAttributes", time);
- return result;
- }
-
- 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(InternalCDORevision revision, IReferenceMapping referenceMapping,
- int referenceChunk)
- {
- long time = System.currentTimeMillis();
- delegate.selectRevisionReferences(revision, referenceMapping, referenceChunk);
- time = System.currentTimeMillis() - time;
- registerCall("selectReferences", time);
- }
-
- public final void updateRevisedForReplace(InternalCDORevision revision, IClassMapping classMapping)
- {
- long time = System.currentTimeMillis();
- delegate.updateRevisedForReplace(revision, classMapping);
- time = System.currentTimeMillis() - time;
- registerCall("updateRevisedForReplace", time);
- }
-
- public final void updateRevisedForDetach(CDOID cdoid, long revised, IClassMapping classMapping)
- {
- long time = System.currentTimeMillis();
- delegate.updateRevisedForDetach(cdoid, revised, classMapping);
- time = System.currentTimeMillis() - time;
- registerCall("updateRevisedForDetach", time);
- }
-
- public void deleteAttributes(CDOID id, IClassMapping classMapping)
- {
- long time = System.currentTimeMillis();
- delegate.deleteAttributes(id, classMapping);
- time = System.currentTimeMillis() - time;
- registerCall("deleteAttributes", time);
- }
-
- public void deleteReferences(CDOID id, IReferenceMapping referenceMapping)
- {
- long time = System.currentTimeMillis();
- delegate.deleteReferences(id, referenceMapping);
- time = System.currentTimeMillis() - time;
- registerCall("deleteReferences", time);
- }
-
- public void updateAttributes(InternalCDORevision revision, IClassMapping classMapping)
- {
- long time = System.currentTimeMillis();
- delegate.updateAttributes(revision, classMapping);
- time = System.currentTimeMillis() - time;
- registerCall("updateAllAttributes", time);
- }
-
- public void updateAttributes(CDOID id, int newVersion, long created,
- List<Pair<IAttributeMapping, Object>> attributeChanges, IClassMapping classMapping)
- {
- long time = System.currentTimeMillis();
- delegate.updateAttributes(id, newVersion, created, attributeChanges, classMapping);
- time = System.currentTimeMillis() - time;
- registerCall("updateAttributes", time);
- }
-
- public void updateReferenceVersion(CDOID id, int newVersion, IReferenceMapping referenceMapping)
- {
- long time = System.currentTimeMillis();
- delegate.updateReferenceVersion(id, newVersion, referenceMapping);
- time = System.currentTimeMillis() - time;
- registerCall("updateReferenceVersion", time);
- }
-
- public void insertReferenceRow(CDOID id, int newVersion, int index, CDOID value, IReferenceMapping referenceMapping)
- {
- long time = System.currentTimeMillis();
- delegate.insertReferenceRow(id, newVersion, index, value, referenceMapping);
- time = System.currentTimeMillis() - time;
- registerCall("insertReferenceRow", time);
- }
-
- public void updateReference(CDOID id, int newVersion, int index, CDOID value, IReferenceMapping referenceMapping)
- {
- long time = System.currentTimeMillis();
- delegate.updateReference(id, newVersion, index, value, referenceMapping);
- time = System.currentTimeMillis() - time;
- registerCall("updateReference", time);
- }
-
- public void moveReferenceRow(CDOID id, int newVersion, int oldPosition, int newPosition,
- IReferenceMapping referenceMapping)
- {
- long time = System.currentTimeMillis();
- delegate.moveReferenceRow(id, newVersion, oldPosition, newPosition, referenceMapping);
- time = System.currentTimeMillis() - time;
- registerCall("moveReferenceRow", time);
- }
-
- public void removeReferenceRow(CDOID id, int index, int newVersion, IReferenceMapping referenceMapping)
- {
- long time = System.currentTimeMillis();
- delegate.removeReferenceRow(id, index, newVersion, referenceMapping);
- time = System.currentTimeMillis() - time;
- registerCall("removeReferenceRow", time);
- }
-
- public void updateAttributes(CDOID id, int newVersion, long created, CDOID newContainerId,
- int newContainingFeatureId, CDOID newResourceId, List<Pair<IAttributeMapping, Object>> attributeChanges,
- IClassMapping classMapping)
- {
- long time = System.currentTimeMillis();
- delegate.updateAttributes(id, newVersion, created, newContainerId, newContainingFeatureId, newResourceId,
- attributeChanges, classMapping);
- time = System.currentTimeMillis() - time;
- registerCall("updateAttributes_with_containment", time);
- }
-
- public void setStoreAccessor(IDBStoreAccessor storeAccessor)
- {
- delegate.setStoreAccessor(storeAccessor);
- }
-
- @Override
- protected void doBeforeActivate() throws Exception
- {
- super.doBeforeActivate();
- checkState(delegate, "delegate");
- }
-
- @Override
- protected void doActivate() throws Exception
- {
- LifecycleUtil.activate(delegate);
- super.doActivate();
- }
-
- @Override
- protected void doDeactivate() throws Exception
- {
- report();
- super.doDeactivate();
- LifecycleUtil.deactivate(delegate);
- }
-
- 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);
- }
-
- /**
- * @author Stefan Winkler
- * @since 2.0
- */
- private static final 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/PreparedStatementJDBCDelegate.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegate.java
index 7634e77..72893bf 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegate.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegate.java
@@ -15,6 +15,7 @@ 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.db.CDODBUtil;
+import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.mapping.IAttributeMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
@@ -30,6 +31,7 @@ import org.eclipse.net4j.util.ref.ReferenceValueMap;
import org.eclipse.emf.ecore.EEnumLiteral;
+import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -47,6 +49,18 @@ import java.util.Map.Entry;
*/
public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
{
+ @Override
+ public Connection getConnection()
+ {
+ return null;
+ }
+
+ @Override
+ public IDBStoreAccessor getStoreAccessor()
+ {
+ return null;
+ }
+
/**
* Value for {@link #cachingFlag}: Guess if caching is needed
*/
@@ -62,17 +76,17 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
*/
public static final String CACHE_STMTS_FALSE = "false";
- private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, PreparedStatementJDBCDelegate.class);
+ public static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, PreparedStatementJDBCDelegate.class);
- private static final String SQL_UPDATE_REVISE_VERSION = " SET " + CDODBSchema.ATTRIBUTES_REVISED + " = ? WHERE "
+ public static final String SQL_UPDATE_REVISE_VERSION = " SET " + CDODBSchema.ATTRIBUTES_REVISED + " = ? WHERE "
+ CDODBSchema.ATTRIBUTES_ID + " = ? AND " + CDODBSchema.ATTRIBUTES_VERSION + " = ?";
- private static final String SQL_UPDATE_REVISE_UNREVISED = " SET " + CDODBSchema.ATTRIBUTES_REVISED + " = ? WHERE "
+ public static final String SQL_UPDATE_REVISE_UNREVISED = " SET " + CDODBSchema.ATTRIBUTES_REVISED + " = ? WHERE "
+ CDODBSchema.ATTRIBUTES_ID + " = ? AND " + CDODBSchema.ATTRIBUTES_REVISED + " = 0";
- private static final String SQL_INSERT_REFERENCE_WITH_DBID = " VALUES (?, ?, ?, ?, ?)";
+ public static final String SQL_INSERT_REFERENCE_WITH_DBID = " VALUES (?, ?, ?, ?, ?)";
- private static final String SQL_INSERT_REFERENCE = " VALUES (?, ?, ?, ?)";
+ public static final String SQL_INSERT_REFERENCE = " VALUES (?, ?, ?, ?)";
/**
* Cache for preparedStatements used in diverse methods
@@ -106,7 +120,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
@Override
protected void doActivate() throws Exception
{
- super.doActivate();
+ // super.doActivate();
dirtyStatements = new ReferenceValueMap.Strong<CacheKey, PreparedStatement>();
switch (cachingEnablement)
@@ -162,7 +176,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
statementCache.clear();
}
- super.doBeforeDeactivate();
+ // super.doBeforeDeactivate();
}
public CachingEnablement getCachingEnablement()
@@ -172,7 +186,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
public void setCachingEnablement(CachingEnablement cachingEnablement)
{
- checkInactive();
+ // checkInactive();
this.cachingEnablement = cachingEnablement;
}
@@ -279,7 +293,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected void doInsertAttributes(String tableName, CDORevision rev, List<IAttributeMapping> attributeMappings,
+ public void doInsertAttributes(String tableName, CDORevision rev, List<IAttributeMapping> attributeMappings,
boolean withFullRevisionInfo)
{
boolean firstBatch = false;
@@ -376,7 +390,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected void doUpdateAttributes(String tableName, long cdoid, int newVersion, long created,
+ public void doUpdateAttributes(String tableName, long cdoid, int newVersion, long created,
List<Pair<IAttributeMapping, Object>> attributeChanges, boolean hasFullRevisionInfo)
{
StringBuilder builder = new StringBuilder();
@@ -427,7 +441,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected void doUpdateAttributes(String tableName, long cdoid, int newVersion, long created, long newContainerId,
+ public void doUpdateAttributes(String tableName, long cdoid, int newVersion, long created, long newContainerId,
int newContainingFeatureId, long newResourceId, List<Pair<IAttributeMapping, Object>> attributeChanges,
boolean hasFullRevisionInfo)
{
@@ -493,7 +507,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected void doUpdateRevisedForReplace(String tableName, long revisedStamp, long cdoid, int version)
+ public void doUpdateRevisedForReplace(String tableName, long revisedStamp, long cdoid, int version)
{
PreparedStatement stmt = null;
if (cacheStatements)
@@ -540,7 +554,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected void doUpdateRevisedForDetach(String tableName, long revisedStamp, long cdoid)
+ public void doUpdateRevisedForDetach(String tableName, long revisedStamp, long cdoid)
{
PreparedStatement stmt = null;
if (cacheStatements)
@@ -587,18 +601,17 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
/*
* This has been the preparedStatement version of updateAttributes. Does not make sense now, as amount of attributes
- * is variable. Preparing for any number of attributes is not very intelligent ...
- * @Override protected void doUpdateAllAttributes(String tableName, long cdoid, int version, long created,
- * List<Pair<IAttributeMapping, Object>> attributeChanges, boolean withFullRevisionInfo) { boolean firstBatch = false;
- * PreparedStatement stmt = getDirtyStatement(StmtType.UPDATE_ATTRIBUTES, tableName); if (stmt == null &&
- * cacheStatements) { firstBatch = true; stmt = getAndRemoveCachedStatement(StmtType.UPDATE_ATTRIBUTES, tableName); }
- * try { firstBatch = true; if (stmt == null) { StringBuilder sql = new StringBuilder(); sql.append("UPDATE ");
- * sql.append(tableName); sql.append(" SET "); sql.append(CDODBSchema.ATTRIBUTES_VERSION); sql.append(" = ? "); if
- * (withFullRevisionInfo) { sql.append(", "); sql.append(CDODBSchema.ATTRIBUTES_RESOURCE); sql.append(" = ?,");
- * sql.append(CDODBSchema.ATTRIBUTES_CONTAINER); sql.append(" = ?,"); sql.append(CDODBSchema.ATTRIBUTES_FEATURE);
- * sql.append(" = ?"); } for (IAttributeMapping attributeMapping : attributeMappings) { sql.append(", ");
- * sql.append(attributeMapping.getField()); sql.append(" = ?"); } sql.append(" WHERE ");
- * sql.append(CDODBSchema.ATTRIBUTES_ID); sql.append(" = ? "); stmt =
+ * is variable. Preparing for any number of attributes is not very intelligent ... protected void
+ * doUpdateAllAttributes(String tableName, long cdoid, int version, long created, List<Pair<IAttributeMapping,
+ * Object>> attributeChanges, boolean withFullRevisionInfo) { boolean firstBatch = false; PreparedStatement stmt =
+ * getDirtyStatement(StmtType.UPDATE_ATTRIBUTES, tableName); if (stmt == null && cacheStatements) { firstBatch = true;
+ * stmt = getAndRemoveCachedStatement(StmtType.UPDATE_ATTRIBUTES, tableName); } try { firstBatch = true; if (stmt ==
+ * null) { StringBuilder sql = new StringBuilder(); sql.append("UPDATE "); sql.append(tableName); sql.append(" SET ");
+ * sql.append(CDODBSchema.ATTRIBUTES_VERSION); sql.append(" = ? "); if (withFullRevisionInfo) { sql.append(", ");
+ * sql.append(CDODBSchema.ATTRIBUTES_RESOURCE); sql.append(" = ?,"); sql.append(CDODBSchema.ATTRIBUTES_CONTAINER);
+ * sql.append(" = ?,"); sql.append(CDODBSchema.ATTRIBUTES_FEATURE); sql.append(" = ?"); } for (IAttributeMapping
+ * attributeMapping : attributeMappings) { sql.append(", "); sql.append(attributeMapping.getField());
+ * sql.append(" = ?"); } sql.append(" WHERE "); sql.append(CDODBSchema.ATTRIBUTES_ID); sql.append(" = ? "); stmt =
* getConnection().prepareStatement(sql.toString()); } int col = 1; if (TRACER.isEnabled()) {
* TRACER.trace(stmt.toString()); } stmt.setInt(col++, revision.getVersion()); if (withFullRevisionInfo) {
* stmt.setLong(col++, CDOIDUtil.getLong(revision.getResourceID())); stmt.setLong(col++,
@@ -611,7 +624,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
*/
@Override
- protected void doDeleteAttributes(String tableName, long cdoid)
+ public void doDeleteAttributes(String tableName, long cdoid)
{
PreparedStatement stmt = null;
if (cacheStatements)
@@ -658,7 +671,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected void doInsertReference(String tableName, long dbID, long source, int version, int index, long target)
+ public void doInsertReference(String tableName, long dbID, long source, int version, int index, long target)
{
PreparedStatement stmt = null;
if (cacheStatements)
@@ -711,14 +724,14 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected void doInsertReferenceRow(String tableName, long metaID, long cdoid, int newVersion, long target, int index)
+ public void doInsertReferenceRow(String tableName, long metaID, long cdoid, int newVersion, long target, int index)
{
move1up(tableName, metaID, cdoid, newVersion, index);
doInsertReference(tableName, metaID, cdoid, newVersion, index, target);
}
@Override
- protected void doMoveReferenceRow(String tableName, long metaID, long cdoid, int newVersion, int oldPosition,
+ public void doMoveReferenceRow(String tableName, long metaID, long cdoid, int newVersion, int oldPosition,
int newPosition)
{
if (oldPosition == newPosition)
@@ -746,15 +759,14 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected void doRemoveReferenceRow(String tableName, long metaID, long cdoid, int index, int newVersion)
+ public void doRemoveReferenceRow(String tableName, long metaID, long cdoid, int index, int newVersion)
{
deleteReferenceRow(tableName, metaID, cdoid, index);
move1down(tableName, metaID, cdoid, newVersion, index);
}
@Override
- protected void doUpdateReference(String tableName, long metaID, long sourceId, int newVersion, int index,
- long targetId)
+ public void doUpdateReference(String tableName, long metaID, long sourceId, int newVersion, int index, long targetId)
{
PreparedStatement stmt = null;
if (cacheStatements)
@@ -824,7 +836,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected void doUpdateReferenceVersion(String tableName, long cdoid, int newVersion)
+ public void doUpdateReferenceVersion(String tableName, long cdoid, int newVersion)
{
boolean firstBatch = false;
@@ -876,7 +888,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected void doDeleteReferences(String tableName, long metaID, long cdoid)
+ public void doDeleteReferences(String tableName, long metaID, long cdoid)
{
PreparedStatement stmt = null;
if (cacheStatements)
@@ -935,7 +947,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected ResultSet doSelectRevisionAttributes(String tableName, long revisionId,
+ public ResultSet doSelectRevisionAttributes(String tableName, long revisionId,
List<IAttributeMapping> attributeMappings, boolean hasFullRevisionInfo, String where) throws SQLException
{
// Because of the variable where clause, statement caching can not be
@@ -1000,7 +1012,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
@Override
- protected ResultSet doSelectRevisionReferences(String tableName, long sourceId, int version, long metaID, String where)
+ public ResultSet doSelectRevisionReferences(String tableName, long sourceId, int version, long metaID, String where)
throws SQLException
{
StringBuilder builder = new StringBuilder();
@@ -1069,7 +1081,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
// leave open cached statements
if (!cacheStatements || !(stmt instanceof PreparedStatement))
{
- super.releaseStatement(stmt);
+ // super.releaseStatement(stmt);
}
// /* This code would guarantee that releaseStatement is only called
@@ -1087,7 +1099,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
// List management helpers
// ----------------------------------------------------------
- private void updateOneIndex(String tableName, long metaID, long cdoid, int newVersion, int oldIndex, int newIndex)
+ public void updateOneIndex(String tableName, long metaID, long cdoid, int newVersion, int oldIndex, int newIndex)
{
if (TRACER.isEnabled())
{
@@ -1165,7 +1177,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
* Move references downwards to close a gap at position <code>index</code>. Only indexes starting with
* <code>index + 1</code> and ending with <code>upperIndex</code> are moved down.
*/
- private void move1down(String tableName, long metaID, long cdoid, int newVersion, int index, int upperIndex)
+ public void move1down(String tableName, long metaID, long cdoid, int newVersion, int index, int upperIndex)
{
if (TRACER.isEnabled())
{
@@ -1243,7 +1255,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
* Move references downwards to close a gap at position <code>index</code>. All indexes starting with
* <code>index + 1</code> are moved down.
*/
- private void move1down(String tableName, long metaID, long cdoid, int newVersion, int index)
+ public void move1down(String tableName, long metaID, long cdoid, int newVersion, int index)
{
if (TRACER.isEnabled())
{
@@ -1319,7 +1331,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
* Move references upwards to make room at position <code>index</code>. Only indexes starting with <code>index</code>
* and ending with <code>upperIndex - 1</code> are moved up.
*/
- private void move1up(String tableName, long metaID, long cdoid, int newVersion, int index, int upperIndex)
+ public void move1up(String tableName, long metaID, long cdoid, int newVersion, int index, int upperIndex)
{
if (TRACER.isEnabled())
{
@@ -1397,7 +1409,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
/**
* Move references upwards to make room at position <code>index</code>. Only indexes starting with <code>index</code>.
*/
- private void move1up(String tableName, long metaID, long cdoid, int newVersion, int index)
+ public void move1up(String tableName, long metaID, long cdoid, int newVersion, int index)
{
if (TRACER.isEnabled())
{
@@ -1469,7 +1481,7 @@ public class PreparedStatementJDBCDelegate extends AbstractJDBCDelegate
}
}
- private void deleteReferenceRow(String tableName, long metaID, long cdoid, int index)
+ public void deleteReferenceRow(String tableName, long metaID, long cdoid, int index)
{
PreparedStatement stmt = null;
if (cacheStatements)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegateProvider.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegateProvider.java
deleted file mode 100644
index 08b13d3..0000000
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/PreparedStatementJDBCDelegateProvider.java
+++ /dev/null
@@ -1,49 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.server.internal.db.jdbc;
-
-import org.eclipse.emf.cdo.server.db.IJDBCDelegate;
-import org.eclipse.emf.cdo.server.db.IJDBCDelegateProvider;
-import org.eclipse.emf.cdo.server.internal.db.jdbc.PreparedStatementJDBCDelegate.CachingEnablement;
-
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- */
-public class PreparedStatementJDBCDelegateProvider implements IJDBCDelegateProvider
-{
- public static final String CACHE_STATEMENT_PROPERTY_KEY = "cacheStatements";
-
- private CachingEnablement cachingEnablement = CachingEnablement.GUESS;
-
- public PreparedStatementJDBCDelegateProvider()
- {
- }
-
- public IJDBCDelegate getJDBCDelegate()
- {
- PreparedStatementJDBCDelegate delegate = new PreparedStatementJDBCDelegate();
- delegate.setCachingEnablement(cachingEnablement);
- return delegate;
- }
-
- public void setProperties(Map<String, String> properties)
- {
- String value = properties.get(CACHE_STATEMENT_PROPERTY_KEY);
- if (value == null)
- {
- value = "GUESS";
- }
-
- cachingEnablement = CachingEnablement.valueOf(value.toUpperCase());
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/StatementJDBCDelegateProvider.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/StatementJDBCDelegateProvider.java
deleted file mode 100644
index ecb8353..0000000
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/jdbc/StatementJDBCDelegateProvider.java
+++ /dev/null
@@ -1,37 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.server.internal.db.jdbc;
-
-import org.eclipse.emf.cdo.server.db.IJDBCDelegate;
-import org.eclipse.emf.cdo.server.db.IJDBCDelegateProvider;
-
-import java.util.Map;
-
-/**
- * @author Eike Stepper
- * @since 2.0
- */
-public class StatementJDBCDelegateProvider implements IJDBCDelegateProvider
-{
- public StatementJDBCDelegateProvider()
- {
- }
-
- public IJDBCDelegate getJDBCDelegate()
- {
- return new StatementJDBCDelegate();
- }
-
- public void setProperties(Map<String, String> properties)
- {
- // ignore -- no properties for this delegate
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ClassMapping.java
index 396bfe5..96a0a5d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ClassMapping.java
@@ -12,21 +12,12 @@
package org.eclipse.emf.cdo.server.internal.db.mapping;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOModelUtil;
import org.eclipse.emf.cdo.common.model.CDOType;
import org.eclipse.emf.cdo.common.revision.CDORevision;
-import org.eclipse.emf.cdo.common.revision.delta.CDOAddFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOClearFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOContainerFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOFeatureDeltaVisitor;
-import org.eclipse.emf.cdo.common.revision.delta.CDOListFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOMoveFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDORemoveFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOSetFeatureDelta;
-import org.eclipse.emf.cdo.common.revision.delta.CDOUnsetFeatureDelta;
import org.eclipse.emf.cdo.server.IStore;
+import org.eclipse.emf.cdo.server.db.CDODBUtil;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.mapping.IAttributeMapping;
@@ -36,34 +27,44 @@ import org.eclipse.emf.cdo.server.db.mapping.IReferenceMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.DBStore;
import org.eclipse.emf.cdo.server.internal.db.ToMany;
+import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
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.collection.Pair;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
-import org.eclipse.net4j.util.om.monitor.OMMonitor.Async;
+import org.eclipse.net4j.util.om.trace.ContextTracer;
import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.EEnumLiteral;
import org.eclipse.emf.ecore.EReference;
import org.eclipse.emf.ecore.EStructuralFeature;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Timestamp;
import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Date;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
- * @author Eike Stepper
+ * @author Eike Stepper TODO: refactor attribute/reference/type mappings
*/
public abstract class ClassMapping implements IClassMapping
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, ClassMapping.class);
+
private MappingStrategy mappingStrategy;
private EClass eClass;
@@ -76,14 +77,27 @@ public abstract class ClassMapping implements IClassMapping
private List<IReferenceMapping> referenceMappings;
- private ThreadLocal<FeatureDeltaWriter> deltaWriter = new ThreadLocal<FeatureDeltaWriter>()
- {
- @Override
- protected FeatureDeltaWriter initialValue()
- {
- return new FeatureDeltaWriter();
- };
- };
+ private String sqlSelectAttributesPrefix;
+
+ private String sqlSelectAttributesAffix;
+
+ private String sqlDeleteAttributes;
+
+ private String sqlReviseAttributes;
+
+ private String sqlReviseAttributesByID;
+
+ private String sqlInsertAttributes;
+
+ private String sqlUpdateAttributesAffix;
+
+ private String sqlUpdateAttributesContainmentPart;
+
+ private String sqlUpdateAttributesPrefix;
+
+ private String sqlUpdateAllAttributesPart;
+
+ private String sqlUpdateAllAttributes;
public ClassMapping(MappingStrategy mappingStrategy, EClass eClass, EStructuralFeature[] features)
{
@@ -125,6 +139,8 @@ public abstract class ClassMapping implements IClassMapping
// }
// }
}
+
+ initSqlStrings();
}
public MappingStrategy getMappingStrategy()
@@ -189,6 +205,7 @@ public abstract class ClassMapping implements IClassMapping
protected int getDBLength(EStructuralFeature feature)
{
+ // TODO make length DB dependent (Oracle only supports 30 chars)
// Derby: The maximum length for a VARCHAR string is 32,672 characters.
CDOType type = CDOModelUtil.getType(feature.getEType());
return type == CDOType.STRING || type == CDOType.CUSTOM ? 32672 : IDBField.DEFAULT;
@@ -283,6 +300,10 @@ public abstract class ClassMapping implements IClassMapping
return referenceMappings.isEmpty() ? null : referenceMappings;
}
+ /**
+ * @deprecated move into extensible and flexible type mapping facility
+ */
+ @Deprecated
protected AttributeMapping createAttributeMapping(EStructuralFeature feature)
{
CDOType type = CDOModelUtil.getType(feature.getEType());
@@ -445,29 +466,249 @@ public abstract class ClassMapping implements IClassMapping
protected final void writeRevisedRow(IDBStoreAccessor accessor, InternalCDORevision revision)
{
- accessor.getJDBCDelegate().updateRevisedForReplace(revision, this);
+ PreparedStatement stmt = null;
+
+ try
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlReviseAttributes);
+
+ stmt.setLong(1, (revision.getCreated() - 1));
+ stmt.setLong(2, CDOIDUtil.getLong(revision.getID()));
+ stmt.setInt(3, (revision.getVersion() - 1));
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(stmt.toString());
+ }
+
+ int result = stmt.executeUpdate();
+ // only one unrevised row may exist - update count must be 1
+ if (result != 1)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned Update count " + result + " (expected: 1)");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
}
protected final void writeRevisedRow(IDBStoreAccessor accessor, CDOID id, long revised)
{
- accessor.getJDBCDelegate().updateRevisedForDetach(id, revised, this);
+ PreparedStatement stmt = null;
+
+ try
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlReviseAttributesByID);
+
+ stmt.setLong(1, revised);
+ stmt.setLong(2, CDOIDUtil.getLong(id));
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(stmt.toString());
+ }
+
+ int result = stmt.executeUpdate();
+
+ // only one unrevised row may exist - update count must be 1
+ if (result != 1)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned Update count " + result + " (expected: 1)");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
}
protected final void writeAttributes(IDBStoreAccessor accessor, InternalCDORevision revision)
{
if (revision.getVersion() == 1 || isAuditing())
{
- accessor.getJDBCDelegate().insertAttributes(revision, this);
+ insertAttributes(accessor, revision);
}
else
{
- accessor.getJDBCDelegate().updateAttributes(revision, this);
+ updateAttributes(accessor, revision);
+ }
+ }
+
+ private void insertAttributes(IDBStoreAccessor accessor, InternalCDORevision revision)
+ {
+ PreparedStatement stmt = null;
+
+ try
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlInsertAttributes);
+
+ int col = 1;
+
+ stmt.setLong(col++, CDOIDUtil.getLong(revision.getID()));
+ stmt.setInt(col++, revision.getVersion());
+ if (hasFullRevisionInfo())
+ {
+ stmt.setLong(col++, accessor.getStore().getMetaID(revision.getEClass()));
+ stmt.setLong(col++, revision.getCreated());
+ stmt.setLong(col++, revision.getRevised());
+ stmt.setLong(col++, CDOIDUtil.getLong(revision.getResourceID()));
+ stmt.setLong(col++, CDODBUtil.getLong((CDOID)revision.getContainerID()));
+ stmt.setInt(col++, revision.getContainingFeatureID());
+ }
+
+ if (attributeMappings != null)
+ {
+ for (IAttributeMapping attributeMapping : attributeMappings)
+ {
+ Object value = attributeMapping.getRevisionValue(revision);
+
+ if (value == null)
+ {
+ stmt.setNull(col++, attributeMapping.getField().getType().getCode());
+ }
+ else if (value instanceof java.util.Date)
+ {
+ // BUG 217255
+ stmt.setTimestamp(col++, new Timestamp(((Date)value).getTime()));
+ }
+ else if (value instanceof EEnumLiteral)
+ {
+ stmt.setInt(col++, ((EEnumLiteral)value).getValue());
+ }
+ else
+ {
+ stmt.setObject(col++, value);
+ }
+ }
+ }
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(stmt.toString());
+ }
+
+ int result = stmt.executeUpdate();
+ // INSERT should insert one row
+ if (result != 1)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned Update count " + result + " (expected: 1)");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
+ }
+
+ protected final void updateAttributes(IDBStoreAccessor accessor, InternalCDORevision revision)
+ {
+ PreparedStatement stmt = null;
+
+ try
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlUpdateAllAttributes);
+
+ int col = 1;
+ stmt.setInt(col++, revision.getVersion());
+ stmt.setLong(col++, revision.getCreated());
+ stmt.setLong(col++, CDODBUtil.getLong((CDOID)revision.getContainerID()));
+ stmt.setInt(col++, revision.getContainingFeatureID());
+ stmt.setLong(col++, CDOIDUtil.getLong(revision.getResourceID()));
+
+ if (attributeMappings != null)
+ {
+ for (IAttributeMapping attributeMapping : attributeMappings)
+ {
+ Object value = attributeMapping.getRevisionValue(revision);
+
+ if (value == null)
+ {
+ stmt.setNull(col++, attributeMapping.getField().getType().getCode());
+ }
+ else if (value instanceof java.util.Date)
+ {
+ // BUG 217255
+ stmt.setTimestamp(col++, new Timestamp(((Date)value).getTime()));
+ }
+ else if (value instanceof EEnumLiteral)
+ {
+ stmt.setInt(col++, ((EEnumLiteral)value).getValue());
+ }
+ else
+ {
+ stmt.setObject(col++, value);
+ }
+ }
+ }
+
+ stmt.setLong(col++, CDOIDUtil.getLong(revision.getID()));
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(stmt.toString());
+ }
+
+ int result = stmt.executeUpdate();
+ // UPDATE should update one row
+ if (result != 1)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned Update count " + result + " (expected: 1)");
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
}
}
protected final void deleteAttributes(IDBStoreAccessor accessor, CDOID id)
{
- accessor.getJDBCDelegate().deleteAttributes(id, this);
+ PreparedStatement stmt = null;
+
+ try
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlDeleteAttributes);
+ stmt.setLong(1, CDOIDUtil.getLong(id));
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(stmt.toString());
+ }
+
+ int result = stmt.executeUpdate();
+
+ // DELETE should delete one row
+ if (result != 1)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned Update count " + result + " (expected: 1)");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
}
protected final void deleteReferences(IDBStoreAccessor accessor, CDOID id)
@@ -494,24 +735,6 @@ public abstract class ClassMapping implements IClassMapping
}
}
- public void writeRevisionDelta(IDBStoreAccessor accessor, InternalCDORevisionDelta delta, long created,
- OMMonitor monitor)
- {
- monitor.begin();
- Async async = monitor.forkAsync();
-
- try
- {
- FeatureDeltaWriter writer = deltaWriter.get();
- writer.process(accessor, delta, created);
- }
- finally
- {
- async.stop();
- monitor.done();
- }
- }
-
public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int referenceChunk)
{
String where = mappingStrategy.createWhereClause(CDORevision.UNSPECIFIED_DATE);
@@ -553,156 +776,215 @@ public abstract class ClassMapping implements IClassMapping
return success;
}
- /**
- * Read the revision's attributes from the DB.
- *
- * @return <code>true</code> if the revision has been read successfully.<br>
- * <code>false</code> if the revision does not exist in the DB.
- */
- protected final boolean readAttributes(IDBStoreAccessor accessor, InternalCDORevision revision, String where)
+ private void initSqlStrings()
{
- return accessor.getJDBCDelegate().selectRevisionAttributes(revision, this, where);
- }
+ // ----------- Select Revision ---------------------------
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT ");
+ builder.append(CDODBSchema.ATTRIBUTES_VERSION);
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_CREATED);
- protected void readReferences(IDBStoreAccessor accessor, InternalCDORevision revision, int referenceChunk)
- {
- for (IReferenceMapping referenceMapping : referenceMappings)
+ if (hasFullRevisionInfo())
{
- referenceMapping.readReference(accessor, revision, referenceChunk);
+ 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);
}
- }
-
- private class FeatureDeltaWriter implements CDOFeatureDeltaVisitor
- {
- private CDOID id;
- private int newVersion;
-
- private long created;
-
- private IDBStoreAccessor accessor;
-
- private boolean updateContainer = false;
-
- private List<Pair<IAttributeMapping, Object>> attributeChanges;
+ if (attributeMappings != null)
+ {
+ for (IAttributeMapping attributeMapping : attributeMappings)
+ {
+ builder.append(", ");
+ builder.append(attributeMapping.getField());
+ }
+ }
- private int newContainingFeatureID;
+ builder.append(" FROM ");
+ builder.append(table.getName());
+ builder.append(" WHERE ");
+ builder.append(CDODBSchema.ATTRIBUTES_ID);
+ builder.append("= ? AND (");
+
+ sqlSelectAttributesPrefix = builder.toString();
+ sqlSelectAttributesAffix = ")";
+
+ // ----------- Delete Revision ---------------------------
+ builder = new StringBuilder("DELETE FROM ");
+ builder.append(table.getName());
+ builder.append(" WHERE ");
+ builder.append(CDODBSchema.ATTRIBUTES_ID);
+ builder.append(" = ? ");
+
+ sqlDeleteAttributes = builder.toString();
+
+ // ----------- Update to set revised ---------------------
+ builder = new StringBuilder("UPDATE ");
+ builder.append(table.getName());
+ builder.append(" SET ");
+ builder.append(CDODBSchema.ATTRIBUTES_REVISED);
+ builder.append(" = ? WHERE ");
+ builder.append(CDODBSchema.ATTRIBUTES_ID);
+ builder.append(" = ? AND ");
+ builder.append(CDODBSchema.ATTRIBUTES_VERSION);
+ builder.append(" = ?");
+ sqlReviseAttributes = builder.toString();
+
+ // TODO unify both ways to revise revisions!
+ // ----------- Update to set revised by ID ----------------
+ builder = new StringBuilder("UPDATE ");
+ builder.append(getTable().getName());
+ builder.append(" SET ");
+ builder.append(CDODBSchema.ATTRIBUTES_REVISED);
+ builder.append(" = ? WHERE ");
+ builder.append(CDODBSchema.ATTRIBUTES_ID);
+ builder.append(" = ? AND ");
+ builder.append(CDODBSchema.ATTRIBUTES_REVISED);
+ builder.append(" = 0");
+ sqlReviseAttributesByID = builder.toString();
+
+ // ----------- Insert Attributes -------------------------
+ builder = new StringBuilder();
+ builder.append("INSERT INTO ");
+ builder.append(table.getName());
+ builder.append(" VALUES (?, ?, ");
+ if (hasFullRevisionInfo())
+ {
+ builder.append("?, ?, ?, ?, ?, ?");
+ }
+ if (attributeMappings != null)
+ {
+ for (int i = 0; i < getAttributeMappings().size(); i++)
+ {
+ builder.append(", ?");
+ }
+ }
+ builder.append(")");
+ sqlInsertAttributes = builder.toString();
+
+ // ------------- Update Attributes -----------------------
+ builder = new StringBuilder();
+ builder.append("UPDATE ");
+ builder.append(table.getName());
+ builder.append(" SET ");
+ builder.append(CDODBSchema.ATTRIBUTES_VERSION);
+ builder.append(" = ?, ");
+ builder.append(CDODBSchema.ATTRIBUTES_CREATED);
+ builder.append(" = ?");
+ sqlUpdateAttributesPrefix = builder.toString();
+
+ builder = new StringBuilder();
+ builder.append(", ");
+ builder.append(CDODBSchema.ATTRIBUTES_CONTAINER);
+ builder.append(" = ?, ");
+ builder.append(CDODBSchema.ATTRIBUTES_FEATURE);
+ builder.append(" = ?, ");
+ builder.append(CDODBSchema.ATTRIBUTES_RESOURCE);
+ builder.append(" = ?");
+ sqlUpdateAttributesContainmentPart = builder.toString();
+
+ builder = new StringBuilder();
+ if (attributeMappings != null)
+ {
+ for (IAttributeMapping am : attributeMappings)
+ {
+ builder.append(", ");
+ builder.append(am.getField().getName());
+ builder.append("= ?");
+ }
+ }
+ sqlUpdateAllAttributesPart = builder.toString();
- private CDOID newContainerID;
+ builder = new StringBuilder();
+ builder.append(" WHERE ");
+ builder.append(CDODBSchema.ATTRIBUTES_ID);
+ builder.append(" = ?");
+ sqlUpdateAttributesAffix = builder.toString();
- private CDOID newResourceID;
+ sqlUpdateAllAttributes = sqlUpdateAttributesPrefix + sqlUpdateAttributesContainmentPart
+ + sqlUpdateAllAttributesPart + sqlUpdateAttributesAffix;
- public FeatureDeltaWriter()
- {
- attributeChanges = new ArrayList<Pair<IAttributeMapping, Object>>();
- }
+ }
- protected void reset()
+ /**
+ * Read the revision's attributes from the DB.
+ *
+ * @return <code>true</code> if the revision has been read successfully.<br>
+ * <code>false</code> if the revision does not exist in the DB.
+ */
+ protected final boolean readAttributes(IDBStoreAccessor accessor, InternalCDORevision revision, String where)
+ {
+ List<IAttributeMapping> attributeMappings = getAttributeMappings();
+ if (attributeMappings == null)
{
- attributeChanges.clear();
- updateContainer = false;
+ attributeMappings = Collections.emptyList();
}
- public void process(IDBStoreAccessor a, CDORevisionDelta d, long c)
+ PreparedStatement pstmt = null;
+ ResultSet resultSet = null;
+ try
{
- // set context
+ String sql = sqlSelectAttributesPrefix + where + sqlSelectAttributesAffix;
- reset();
- id = d.getID();
- newVersion = d.getDirtyVersion();
- created = c;
- accessor = a;
+ // TODO add caching
+ pstmt = accessor.getConnection().prepareStatement(sql);
+ pstmt.setLong(1, CDOIDUtil.getLong(revision.getID()));
+ resultSet = pstmt.executeQuery();
- // process revision delta tree
- d.accept(this);
-
- // update attributes
- if (updateContainer)
- {
- accessor.getJDBCDelegate().updateAttributes(id, newVersion, created, newContainerID, newContainingFeatureID,
- newResourceID, attributeChanges, ClassMapping.this);
- }
- else
+ if (!resultSet.next())
{
- accessor.getJDBCDelegate().updateAttributes(id, newVersion, created, attributeChanges, ClassMapping.this);
+ return false;
}
- // update version number of all references to current version
- if (referenceMappings != null)
+ int i = 0;
+ if (hasFullRevisionInfo())
{
- for (IReferenceMapping referenceMapping : getReferenceMappings())
- {
- referenceMapping.updateReferenceVersion(accessor, id, newVersion);
- }
+ 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));
}
- }
-
- public void visit(CDOMoveFeatureDelta delta)
- {
- getReferenceMapping(delta.getFeature()).moveReferenceEntry(accessor, id, newVersion, delta.getOldPosition(),
- delta.getNewPosition());
- }
- public void visit(CDOSetFeatureDelta delta)
- {
- if (delta.getFeature().isMany())
+ if (attributeMappings != null)
{
- IReferenceMapping rm = getReferenceMapping(delta.getFeature());
- if (rm == null)
+ for (IAttributeMapping attributeMapping : attributeMappings)
{
- throw new IllegalArgumentException("ReferenceMapping for " + delta.getFeature() + " is null!");
+ attributeMapping.extractValue(resultSet, ++i, revision);
}
- rm.updateReference(accessor, id, newVersion, delta.getIndex(), (CDOID)delta.getValue());
}
- else
- {
- IAttributeMapping am = getAttributeMapping(delta.getFeature());
- if (am == null)
- {
- throw new IllegalArgumentException("AttributeMapping for " + delta.getFeature() + " is null!");
- }
- attributeChanges.add(new Pair<IAttributeMapping, Object>(am, delta.getValue()));
- }
- }
- public void visit(CDOUnsetFeatureDelta delta)
- {
- // TODO Correct this when DBStore implements unsettable features
- // see Bugs 259868 and 263010
- IAttributeMapping am = getAttributeMapping(delta.getFeature());
- attributeChanges.add(new Pair<IAttributeMapping, Object>(am, null));
+ return true;
}
-
- public void visit(CDOListFeatureDelta delta)
- {
- for (CDOFeatureDelta listChange : delta.getListChanges())
- {
- listChange.accept(this);
- }
- }
-
- public void visit(CDOClearFeatureDelta delta)
+ catch (SQLException ex)
{
- getReferenceMapping(delta.getFeature()).deleteReference(accessor, id);
+ throw new DBException(ex);
}
-
- public void visit(CDOAddFeatureDelta delta)
+ finally
{
- getReferenceMapping(delta.getFeature()).insertReferenceEntry(accessor, id, newVersion, delta.getIndex(),
- (CDOID)delta.getValue());
+ DBUtil.close(resultSet);
+ DBUtil.close(pstmt);
}
+ }
- public void visit(CDORemoveFeatureDelta delta)
+ protected void readReferences(IDBStoreAccessor accessor, InternalCDORevision revision, int referenceChunk)
+ {
+ for (IReferenceMapping referenceMapping : referenceMappings)
{
- getReferenceMapping(delta.getFeature()).removeReferenceEntry(accessor, id, delta.getIndex(), newVersion);
+ referenceMapping.readReference(accessor, revision, referenceChunk);
}
+ }
- public void visit(CDOContainerFeatureDelta delta)
- {
- newContainingFeatureID = delta.getContainerFeatureID();
- newContainerID = (CDOID)delta.getContainerID();
- newResourceID = delta.getResourceID();
- updateContainer = true;
- }
+ public void writeRevisionDelta(IDBStoreAccessor accessor, InternalCDORevisionDelta delta, long created,
+ OMMonitor monitor)
+ {
+ throw new UnsupportedOperationException();
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/MappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/MappingStrategy.java
index fe5e0d6..8e1abf6 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/MappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/MappingStrategy.java
@@ -282,7 +282,8 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
try
{
- return accessor.getJDBCDelegate().getStatement().executeQuery(sql);
+ // TODO - close statement
+ return accessor.getConnection().createStatement().executeQuery(sql);
}
catch (SQLException ex)
{
@@ -323,7 +324,8 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
try
{
- resultSet = accessor.getJDBCDelegate().getStatement().executeQuery(sql);
+ // TODO - close statement
+ resultSet = accessor.getConnection().createStatement().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/mapping/ReferenceMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ReferenceMapping.java
index 026b63b..2c7e2b1 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ReferenceMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/ReferenceMapping.java
@@ -12,25 +12,37 @@
package org.eclipse.emf.cdo.server.internal.db.mapping;
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.IRepository;
import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
+import org.eclipse.emf.cdo.server.db.CDODBUtil;
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.mapping.IReferenceMapping;
import org.eclipse.emf.cdo.server.internal.db.CDODBSchema;
import org.eclipse.emf.cdo.server.internal.db.ToMany;
+import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
+import org.eclipse.emf.cdo.server.internal.db.jdbc.PreparedStatementJDBCDelegate;
import org.eclipse.emf.cdo.spi.common.revision.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 org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EPackage;
import org.eclipse.emf.ecore.EStructuralFeature;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Statement;
import java.text.MessageFormat;
import java.util.List;
import java.util.Map;
@@ -40,17 +52,52 @@ 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 int MOVE_UNBOUNDED = -1;
+
private IDBTable table;
+ // TODO - refactor into subclass
private ToMany toMany;
+ // TODO - refactor into subclass
private boolean withFeature;
+ // TODO - remove
+ PreparedStatementJDBCDelegate TEMP = null;
+
+ private String sqlSelectChunksPrefix;
+
+ private String sqlOrderByIndex;
+
+ private String sqlClearReference;
+
+ private String sqlUpdateRefVersion;
+
+ private String sqlUpdateTarget;
+
+ private String sqlMoveUp;
+
+ private String sqlMoveUpWithLimit;
+
+ private String sqlMoveDown;
+
+ private String sqlMoveDownWithLimit;
+
+ private String sqlUpdateIndex;
+
+ private String sqlInsertEntry;
+
+ private String sqlDeleteEntry;
+
public ReferenceMapping(ClassMapping classMapping, EStructuralFeature feature, ToMany toMany)
{
super(classMapping, feature);
this.toMany = toMany;
mapReference(classMapping.getEClass(), feature);
+
+ initSqlStrings();
}
public IDBTable getTable()
@@ -104,6 +151,11 @@ public class ReferenceMapping extends FeatureMapping implements IReferenceMappin
return getClassMapping().createReferenceMappingKey(feature);
}
+ protected final long getMetaID()
+ {
+ return getClassMapping().getMappingStrategy().getStore().getMetaID(getFeature());
+ }
+
protected IDBTable mapReferenceTable(Object key, String tableName)
{
Map<Object, IDBTable> referenceTables = getClassMapping().getMappingStrategy().getReferenceTables();
@@ -146,48 +198,491 @@ public class ReferenceMapping extends FeatureMapping implements IReferenceMappin
public final void writeReferenceEntry(IDBStoreAccessor accessor, CDOID id, int version, int idx, CDOID targetId)
{
- IJDBCDelegate jdbcDelegate = accessor.getJDBCDelegate();
- jdbcDelegate.insertReference(id, version, idx++, targetId, this);
+ PreparedStatement stmt = null;
+
+ try
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlInsertEntry);
+
+ int idx1 = 1;
+ if (withFeature)
+ {
+ stmt.setLong(idx1++, getMetaID());
+ }
+
+ stmt.setLong(idx1++, CDOIDUtil.getLong(id));
+ stmt.setInt(idx1++, version);
+ stmt.setInt(idx1++, idx++);
+ stmt.setLong(idx1++, CDODBUtil.getLong(targetId));
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(stmt.toString());
+ }
+
+ int result = stmt.executeUpdate();
+ // UPDATE should affect one row
+ if (result != 1)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned Update count " + result + " (expected: 1)");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
+ }
+
+ public void deleteReferenceEntry(IDBStoreAccessor accessor, CDOID id, int index)
+ {
+ PreparedStatement stmt = null;
+ try
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlDeleteEntry);
+
+ stmt.setLong(1, CDOIDUtil.getLong(id));
+ stmt.setInt(2, index);
+ if (withFeature)
+ {
+ stmt.setLong(3, getMetaID());
+ }
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(stmt.toString());
+ }
+
+ int result = stmt.executeUpdate();
+ // DELETE should affect one row
+ if (result != 1)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned Update count " + result + " (expected: 1)");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
+ }
+
+ public void removeReferenceEntry(IDBStoreAccessor accessor, CDOID id, int index, int newVersion)
+ {
+ deleteReferenceEntry(accessor, id, index);
+ move1down(accessor, id, newVersion, index, MOVE_UNBOUNDED);
}
public void insertReferenceEntry(IDBStoreAccessor accessor, CDOID id, int newVersion, int index, CDOID value)
{
- accessor.getJDBCDelegate().insertReferenceRow(id, newVersion, index, value, this);
+ move1up(accessor, id, newVersion, index, MOVE_UNBOUNDED);
+ insertReferenceEntry(accessor, id, newVersion, index, value);
}
public void moveReferenceEntry(IDBStoreAccessor accessor, CDOID id, int newVersion, int oldPosition, int newPosition)
{
- accessor.getJDBCDelegate().moveReferenceRow(id, newVersion, oldPosition, newPosition, this);
+ if (oldPosition == newPosition)
+ {
+ return;
+ }
+
+ // move element away temporarily
+ updateOneIndex(accessor, id, newVersion, oldPosition, -1);
+
+ // move elements in between
+ if (oldPosition < newPosition)
+ {
+ move1down(accessor, id, newVersion, oldPosition, newPosition);
+ }
+ else
+ {
+ // oldPosition > newPosition -- equal case is handled above
+ move1up(accessor, id, newVersion, newPosition, oldPosition);
+ }
+
+ // move temporary element to new position
+ updateOneIndex(accessor, id, newVersion, -1, newPosition);
}
- public void removeReferenceEntry(IDBStoreAccessor accessor, CDOID id, int index, int newVersion)
+ // ----------------------------------------------------------
+ // List management helpers
+ // ----------------------------------------------------------
+
+ public void updateOneIndex(IDBStoreAccessor accessor, CDOID cdoid, int newVersion, int oldIndex, int newIndex)
{
- accessor.getJDBCDelegate().removeReferenceRow(id, index, newVersion, this);
+ PreparedStatement stmt = null;
+
+ try
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlUpdateIndex);
+
+ int idx = 1;
+ stmt.setInt(idx++, newIndex);
+ stmt.setInt(idx++, newVersion);
+
+ if (withFeature)
+ {
+ stmt.setLong(idx++, getMetaID());
+ }
+
+ stmt.setLong(idx++, CDOIDUtil.getLong(cdoid));
+ stmt.setLong(idx++, oldIndex);
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(stmt.toString());
+ }
+
+ int result = stmt.executeUpdate();
+ // UPDATE should affect one row
+ if (result != 1)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned Update count " + result + " (expected: 1)");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
+ }
+
+ /**
+ * Move references downwards to close a gap at position <code>index</code>. Only indexes starting with
+ * <code>index + 1</code> and ending with <code>upperIndex</code> are moved down.
+ */
+ public void move1down(IDBStoreAccessor accessor, CDOID cdoid, int newVersion, int index, int upperIndex)
+ {
+ PreparedStatement stmt = null;
+
+ try
+ {
+ if (upperIndex == MOVE_UNBOUNDED)
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlMoveDown);
+ }
+ else
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlMoveDownWithLimit);
+ }
+
+ int idx = 1;
+ stmt.setInt(idx++, newVersion);
+
+ if (withFeature)
+ {
+ stmt.setLong(idx++, getMetaID());
+ }
+
+ stmt.setLong(idx++, CDOIDUtil.getLong(cdoid));
+ stmt.setInt(idx++, index);
+ if (upperIndex != MOVE_UNBOUNDED)
+ {
+ stmt.setInt(idx++, upperIndex);
+ }
+
+ int result = stmt.executeUpdate();
+ if (result == Statement.EXECUTE_FAILED)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned execution failure.");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
+ }
+
+ /**
+ * Move references upwards to make room at position <code>index</code>. Only indexes starting with <code>index</code>
+ * and ending with <code>upperIndex - 1</code> are moved up. <code>upperIndex</code> may be MOVE_UNBOUNDED in which
+ * case the upper bound is determined by the list size.
+ */
+ public void move1up(IDBStoreAccessor accessor, CDOID cdoid, int newVersion, int index, int upperIndex)
+ {
+ PreparedStatement stmt = null;
+
+ try
+ {
+ if (upperIndex == MOVE_UNBOUNDED)
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlMoveUp);
+ }
+ else
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlMoveUpWithLimit);
+ }
+
+ int idx = 1;
+ stmt.setInt(idx++, newVersion);
+
+ if (withFeature)
+ {
+ stmt.setLong(idx++, getMetaID());
+ }
+
+ stmt.setLong(idx++, CDOIDUtil.getLong(cdoid));
+ stmt.setInt(idx++, index);
+ if (upperIndex != MOVE_UNBOUNDED)
+ {
+ stmt.setInt(idx++, upperIndex);
+ }
+
+ int result = stmt.executeUpdate();
+ if (result != Statement.EXECUTE_FAILED)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned execution failure.");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
}
public void updateReference(IDBStoreAccessor accessor, CDOID id, int newVersion, int index, CDOID value)
{
- accessor.getJDBCDelegate().updateReference(id, newVersion, index, value, this);
+ PreparedStatement stmt = null;
+
+ try
+ {
+ stmt = TEMP.getConnection().prepareStatement(sqlUpdateTarget);
+
+ int idx = 1;
+ stmt.setLong(idx++, CDODBUtil.getLong(value));
+ stmt.setInt(idx++, newVersion);
+
+ if (withFeature)
+ {
+ stmt.setLong(idx++, getMetaID());
+ }
+
+ stmt.setLong(idx++, CDOIDUtil.getLong(id));
+ stmt.setLong(idx++, index);
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(stmt.toString());
+ }
+
+ int result = stmt.executeUpdate();
+ if (result == Statement.EXECUTE_FAILED)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned execution failure.");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
}
public void updateReferenceVersion(IDBStoreAccessor accessor, CDOID id, int newVersion)
{
- accessor.getJDBCDelegate().updateReferenceVersion(id, newVersion, this);
+ PreparedStatement stmt = null;
+ try
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlUpdateRefVersion);
+
+ stmt.setInt(1, newVersion);
+ stmt.setLong(2, CDOIDUtil.getLong(id));
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(stmt.toString());
+ }
+
+ int result = stmt.executeUpdate();
+ if (result == Statement.EXECUTE_FAILED)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned execution failure.");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
}
public void deleteReference(IDBStoreAccessor accessor, CDOID id)
{
- accessor.getJDBCDelegate().deleteReferences(id, this);
+ PreparedStatement stmt = null;
+
+ try
+ {
+ stmt = accessor.getConnection().prepareStatement(sqlClearReference);
+
+ stmt.setLong(1, CDOIDUtil.getLong(id));
+ if (withFeature)
+ {
+ stmt.setLong(2, getMetaID());
+ }
+
+ int result = stmt.executeUpdate();
+ if (result == Statement.EXECUTE_FAILED)
+ {
+ throw new IllegalStateException(stmt.toString() + " returned execution failure.");
+ }
+ }
+ catch (SQLException e)
+ {
+ throw new DBException(e);
+ }
+ finally
+ {
+ DBUtil.close(stmt);
+ }
}
public final void readReference(IDBStoreAccessor accessor, InternalCDORevision revision, int referenceChunk)
{
- accessor.getJDBCDelegate().selectRevisionReferences(revision, this, referenceChunk);
+ MoveableList<Object> list = revision.getList(getFeature());
+
+ CDOID source = revision.getID();
+ long sourceId = CDOIDUtil.getLong(source);
+ int version = revision.getVersion();
+
+ PreparedStatement pstmt = null;
+ ResultSet resultSet = null;
+
+ try
+ {
+ String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
+
+ pstmt = accessor.getConnection().prepareStatement(sql);
+ int idx = 1;
+
+ // TODO- refactor
+ if (withFeature)
+ {
+ pstmt.setLong(idx++, getMetaID());
+ }
+
+ pstmt.setLong(idx++, sourceId);
+ pstmt.setInt(idx++, version);
+ resultSet = pstmt.executeQuery();
+
+ 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);
+ DBUtil.close(pstmt);
+ }
}
public final void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
{
- chunkReader.getAccessor().getJDBCDelegate().selectRevisionReferenceChunks(chunkReader, chunks, this, where);
+ CDOID source = chunkReader.getRevision().getID();
+ long sourceId = CDOIDUtil.getLong(source);
+ int version = chunkReader.getRevision().getVersion();
+
+ PreparedStatement pstmt = null;
+ ResultSet resultSet = null;
+
+ try
+ {
+ StringBuilder builder = new StringBuilder(sqlSelectChunksPrefix);
+ if (where != null)
+ {
+ builder.append(where);
+ }
+ builder.append(sqlOrderByIndex);
+
+ String sql = builder.toString();
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
+
+ pstmt = chunkReader.getAccessor().getConnection().prepareStatement(sql);
+
+ int idx = 1;
+
+ // TODO - refactor into subclass
+ if (withFeature)
+ {
+ pstmt.setLong(idx++, getMetaID());
+ }
+
+ pstmt.setLong(idx++, sourceId);
+ pstmt.setInt(idx++, version);
+ resultSet = pstmt.executeQuery();
+
+ 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.add(indexInChunk++, CDOIDUtil.createLong(target));
+ if (indexInChunk == chunkSize)
+ {
+ chunk = null;
+ indexInChunk = 0;
+ }
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(resultSet);
+ DBUtil.close(pstmt);
+ }
}
@Override
@@ -195,4 +690,183 @@ public class ReferenceMapping extends FeatureMapping implements IReferenceMappin
{
return MessageFormat.format("ReferenceMapping[feature={0}, table={1}]", getFeature(), getTable());
}
+
+ private void initSqlStrings()
+ {
+ String tableName = getTable().getName();
+
+ // ---------------- SELECT to read chunks ----------------------------
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT ");
+ builder.append(CDODBSchema.REFERENCES_TARGET);
+ builder.append(" FROM ");
+ builder.append(tableName);
+ builder.append(" WHERE ");
+
+ // TODO - remove condition
+ if (withFeature)
+ {
+ builder.append(CDODBSchema.REFERENCES_FEATURE);
+ builder.append("= ? AND ");
+ }
+
+ builder.append(CDODBSchema.REFERENCES_SOURCE);
+ builder.append("= ? AND ");
+ builder.append(CDODBSchema.REFERENCES_VERSION);
+ builder.append("= ? ");
+
+ sqlSelectChunksPrefix = builder.toString();
+
+ sqlOrderByIndex = " ORDER BY " + CDODBSchema.REFERENCES_IDX;
+
+ // ---------------- DELETE - to clear reference ----------------------------
+ builder = new StringBuilder("DELETE FROM ");
+ builder.append(tableName);
+ builder.append(" WHERE ");
+ builder.append(CDODBSchema.REFERENCES_SOURCE);
+ builder.append(" = ? ");
+
+ if (withFeature)
+ {
+ builder.append("AND");
+ builder.append(CDODBSchema.REFERENCES_FEATURE);
+ builder.append(" = ? ");
+ }
+
+ sqlClearReference = builder.toString();
+
+ // ----------------- UPDATE - reference version ------------------
+ // TODO - remove this in the future
+ builder = new StringBuilder();
+ builder.append("UPDATE ");
+ builder.append(tableName);
+ builder.append(" SET ");
+ builder.append(CDODBSchema.REFERENCES_VERSION);
+ builder.append(" = ? ");
+ builder.append(" WHERE ");
+ builder.append(CDODBSchema.REFERENCES_SOURCE);
+ builder.append(" = ?");
+
+ sqlUpdateRefVersion = builder.toString();
+
+ // ----------------- UPDATE - reference target -----------------
+ builder = new StringBuilder("UPDATE ");
+ builder.append(tableName);
+ builder.append(" SET ");
+ builder.append(CDODBSchema.REFERENCES_TARGET);
+ builder.append(" = ?, ");
+ builder.append(CDODBSchema.REFERENCES_VERSION);
+ builder.append(" = ? WHERE ");
+ if (withFeature)
+ {
+ builder.append(CDODBSchema.REFERENCES_FEATURE);
+ builder.append("= ? AND ");
+ }
+
+ builder.append(CDODBSchema.REFERENCES_SOURCE);
+ builder.append("= ? AND ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append(" = ?");
+
+ sqlUpdateTarget = builder.toString();
+
+ // ----------------- UPDATE - reference index -----------------
+ builder = new StringBuilder("UPDATE ");
+ builder.append(tableName);
+ builder.append(" SET ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append(" = ?, ");
+ builder.append(CDODBSchema.REFERENCES_VERSION);
+ builder.append(" = ? WHERE ");
+ if (withFeature)
+ {
+ builder.append(CDODBSchema.REFERENCES_FEATURE);
+ builder.append("= ? AND ");
+ }
+
+ builder.append(CDODBSchema.REFERENCES_SOURCE);
+ builder.append("= ? AND ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append(" = ?");
+ sqlUpdateIndex = builder.toString();
+
+ // ----------------- UPDATE - move1up -----------------
+ builder = new StringBuilder();
+ builder.append("UPDATE ");
+ builder.append(tableName);
+ builder.append(" SET ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append(" = ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append("+1 ,");
+ builder.append(CDODBSchema.REFERENCES_VERSION);
+ builder.append(" = ? WHERE ");
+ if (withFeature)
+ {
+ builder.append(CDODBSchema.REFERENCES_FEATURE);
+ builder.append("= ? AND ");
+ }
+
+ builder.append(CDODBSchema.REFERENCES_SOURCE);
+ builder.append("= ? AND ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append(" >= ?");
+ sqlMoveUp = builder.toString();
+ builder.append(" AND ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append(" < ?");
+ sqlMoveUpWithLimit = builder.toString();
+
+ // ----------------- UPDATE - move1down -----------------
+ builder = new StringBuilder();
+ builder.append("UPDATE ");
+ builder.append(tableName);
+ builder.append(" SET ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append(" = ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append("-1 ,");
+ builder.append(CDODBSchema.REFERENCES_VERSION);
+ builder.append(" = ? WHERE ");
+ if (withFeature)
+ {
+ builder.append(CDODBSchema.REFERENCES_FEATURE);
+ builder.append("= ? AND ");
+ }
+
+ builder.append(CDODBSchema.REFERENCES_SOURCE);
+ builder.append("= ? AND ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append(" > ?");
+ sqlMoveDown = builder.toString();
+
+ builder.append(" AND ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append(" <= ?");
+ sqlMoveDownWithLimit = builder.toString();
+
+ // ----------------- INSERT - reference entry -----------------
+ builder = new StringBuilder("INSERT INTO ");
+ builder.append(tableName);
+ builder.append(withFeature ? " VALUES (?, ?, ?, ?, ?)" : " VALUES (?, ?, ?, ?)");
+ sqlInsertEntry = builder.toString();
+
+ // ----------------- DELETE - reference entry -----------------
+ builder = new StringBuilder("DELETE FROM ");
+ builder.append(tableName);
+ builder.append(" WHERE ");
+ builder.append(CDODBSchema.REFERENCES_SOURCE);
+ builder.append(" = ? AND ");
+ builder.append(CDODBSchema.REFERENCES_IDX);
+ builder.append(" = ? ");
+
+ if (withFeature)
+ {
+ builder.append("AND");
+ builder.append(CDODBSchema.REFERENCES_FEATURE);
+ builder.append(" = ? ");
+ }
+
+ sqlDeleteEntry = builder.toString();
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldb.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldb.java
index 857d86f..9c0b5c5 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldb.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldb.java
@@ -26,6 +26,6 @@ public class AllTestsDBHsqldb extends AllTestsAllConfigs
@Override
protected void initConfigSuites(TestSuite parent)
{
- addScenario(parent, COMBINED, DB_HSQL_HORIZONTAL, TCP, NATIVE);
+ addScenario(parent, COMBINED, DB_HSQL, JVM, NATIVE);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbNonAudit.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbNonAudit.java
index 751b35c..d3baeb5 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbNonAudit.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbNonAudit.java
@@ -33,7 +33,7 @@ public class AllTestsDBHsqldbNonAudit extends AllTestsAllConfigs
@Override
protected void initConfigSuites(TestSuite parent)
{
- addScenario(parent, COMBINED, DB_HSQL_HORIZONTAL_NONAUDIT, TCP, NATIVE);
+ addScenario(parent, COMBINED, DB_HSQL_NONAUDIT, JVM, NATIVE);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbPrepStmt.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbPrepStmt.java
deleted file mode 100644
index 0402d4a..0000000
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbPrepStmt.java
+++ /dev/null
@@ -1,31 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.tests;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * @author Eike Stepper
- */
-public class AllTestsDBHsqldbPrepStmt extends AllTestsAllConfigs
-{
- public static Test suite()
- {
- return new AllTestsDBHsqldbPrepStmt().getTestSuite("CDO Tests (DB Hsql Horizontal PrepStmt)");
- }
-
- @Override
- protected void initConfigSuites(TestSuite parent)
- {
- addScenario(parent, COMBINED, DB_HSQL_HORIZONTAL_PREPSTMT, TCP, NATIVE);
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbPrepStmtNonAudit.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbPrepStmtNonAudit.java
deleted file mode 100644
index 412d9c9..0000000
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/AllTestsDBHsqldbPrepStmtNonAudit.java
+++ /dev/null
@@ -1,51 +0,0 @@
-/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
- * All rights reserved. This program and the accompanying materials
- * are made available under the terms of the Eclipse Public License v1.0
- * which accompanies this distribution, and is available at
- * http://www.eclipse.org/legal/epl-v10.html
- *
- * Contributors:
- * Eike Stepper - initial API and implementation
- */
-package org.eclipse.emf.cdo.tests;
-
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_252214_Test;
-import org.eclipse.emf.cdo.tests.bugzilla.Bugzilla_261218_Test;
-import org.eclipse.emf.cdo.tests.config.impl.ConfigTest;
-
-import java.util.List;
-
-import junit.framework.Test;
-import junit.framework.TestSuite;
-
-/**
- * @author Stefan Winkler
- */
-public class AllTestsDBHsqldbPrepStmtNonAudit extends AllTestsAllConfigs
-{
- public static Test suite()
- {
- return new AllTestsDBHsqldbPrepStmtNonAudit().getTestSuite("CDO Tests (DB Hsql Horizontal PrepStmt Non-Audit)");
- }
-
- @Override
- protected void initConfigSuites(TestSuite parent)
- {
- addScenario(parent, COMBINED, DB_HSQL_HORIZONTAL_PREPSTMT_NONAUDIT, TCP, NATIVE);
- }
-
- @Override
- protected void initTestClasses(List<Class<? extends ConfigTest>> testClasses)
- {
- super.initTestClasses(testClasses);
-
- // non-audit mode - remove audit tests
- testClasses.remove(AuditTest.class);
- testClasses.remove(AuditTest.LocalAuditTest.class);
- testClasses.remove(Bugzilla_252214_Test.class);
-
- // this takes ages - so for now, we disable it
- testClasses.remove(Bugzilla_261218_Test.class);
- }
-}
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 0f771df..be3a168 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,21 +33,13 @@ public interface IConstants
public static final RepositoryConfig MEM = RepositoryConfig.MEM.INSTANCE;
- public static final RepositoryConfig DB_HSQL_HORIZONTAL = RepositoryConfig.DB.Hsqldb.Stmt.INSTANCE;
+ public static final RepositoryConfig DB_HSQL = RepositoryConfig.DB.Hsqldb.INSTANCE;
- public static final RepositoryConfig DB_HSQL_HORIZONTAL_NONAUDIT = RepositoryConfig.DB.Hsqldb.StmtNonAudit.INSTANCE;
+ public static final RepositoryConfig DB_HSQL_NONAUDIT = RepositoryConfig.DB.HsqldbNonAudit.INSTANCE;
- public static final RepositoryConfig DB_HSQL_HORIZONTAL_PREPSTMT = RepositoryConfig.DB.Hsqldb.PrepStmt.INSTANCE;
+ public static final RepositoryConfig DB_DERBY = RepositoryConfig.DB.Derby.INSTANCE;
- public static final RepositoryConfig DB_HSQL_HORIZONTAL_PREPSTMT_NONAUDIT = RepositoryConfig.DB.Hsqldb.PrepStmtNonAudit.INSTANCE;
-
- public static final RepositoryConfig DB_DERBY_HORIZONTAL = RepositoryConfig.DB.Derby.Stmt.INSTANCE;
-
- public static final RepositoryConfig DB_DERBY_HORIZONTAL_PREPSTMT = RepositoryConfig.DB.Derby.PrepStmt.INSTANCE;
-
- // public static final RepositoryConfig DB_MYSQL_HORIZONTAL = RepositoryConfig.DB.Mysql.Stmt.INSTANCE;
- //
- // public static final RepositoryConfig DB_MYSQL_HORIZONTAL_PREPSTMT = RepositoryConfig.DB.Mysql.PrepStmt.INSTANCE;
+ public static final RepositoryConfig DB_MYSQL = RepositoryConfig.DB.Mysql.INSTANCE;
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 b29a90e..300b95c 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,25 +19,25 @@ import org.eclipse.emf.cdo.server.IRepositoryProvider;
import org.eclipse.emf.cdo.server.IStore;
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.mapping.IMappingStrategy;
import org.eclipse.emf.cdo.server.mem.MEMStoreUtil;
import org.eclipse.emf.cdo.tests.bundle.OM;
import org.eclipse.emf.cdo.tests.config.IRepositoryConfig;
-import org.eclipse.emf.cdo.tests.store.verifier.AuditDBStoreIntegrityVerifier;
-import org.eclipse.emf.cdo.tests.store.verifier.NonAuditDBStoreIntegrityVerifier;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.db.derby.EmbeddedDerbyAdapter;
import org.eclipse.net4j.db.hsqldb.HSQLDBAdapter;
import org.eclipse.net4j.db.hsqldb.HSQLDBDataSource;
+import org.eclipse.net4j.db.mysql.MYSQLAdapter;
import org.eclipse.net4j.util.ObjectUtil;
import org.eclipse.net4j.util.container.IManagedContainer;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.io.TMPUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
+import com.mysql.jdbc.jdbc2.optional.MysqlDataSource;
+
import org.apache.derby.jdbc.EmbeddedDataSource;
import javax.sql.DataSource;
@@ -57,10 +57,9 @@ import java.util.Map.Entry;
public abstract class RepositoryConfig extends Config implements IRepositoryConfig
{
public static final RepositoryConfig[] CONFIGS = { MEM.INSTANCE, //
- DB.Hsqldb.Stmt.INSTANCE, DB.Hsqldb.PrepStmt.INSTANCE, //
- DB.Derby.Stmt.INSTANCE, DB.Derby.PrepStmt.INSTANCE /*
- * , // DB.Mysql.Stmt.INSTANCE, DB.Mysql.PrepStmt.INSTANCE
- */};
+ DB.Hsqldb.INSTANCE, //
+ DB.Derby.INSTANCE, //
+ DB.Mysql.INSTANCE };
public static final String PROP_TEST_REPOSITORY = "test.repository";
@@ -233,13 +232,9 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
IMappingStrategy mappingStrategy = createMappingStrategy();
IDBAdapter dbAdapter = createDBAdapter();
DataSource dataSource = createDataSource();
- IJDBCDelegateProvider delegateProvider = createDelegateProvider();
- return CDODBUtil.createStore(mappingStrategy, dbAdapter, DBUtil.createConnectionProvider(dataSource),
- delegateProvider);
+ return CDODBUtil.createStore(mappingStrategy, dbAdapter, DBUtil.createConnectionProvider(dataSource));
}
- protected abstract IJDBCDelegateProvider createDelegateProvider();
-
protected abstract IMappingStrategy createMappingStrategy();
protected abstract IDBAdapter createDBAdapter();
@@ -249,10 +244,12 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
/**
* @author Eike Stepper
*/
- public abstract static class Hsqldb extends DB
+ public static class Hsqldb extends DB
{
private static final long serialVersionUID = 1L;
+ public static final Hsqldb INSTANCE = new Hsqldb("HSQLDB");
+
private transient HSQLDBDataSource dataSource;
public Hsqldb(String name)
@@ -319,143 +316,36 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
}
}
}
+ }
- public static class Stmt extends Hsqldb
- {
- private static final long serialVersionUID = 1L;
-
- public static final Stmt INSTANCE = new Stmt("HsqldbHorizontalStmt");
-
- public Stmt(String name)
- {
- super(name);
- }
+ public static class HsqldbNonAudit extends Hsqldb
+ {
+ private static final long serialVersionUID = 1L;
- @Override
- protected IJDBCDelegateProvider createDelegateProvider()
- {
- return CDODBUtil.createStatementJDBCDelegateProvider();
- }
- }
+ public static final HsqldbNonAudit INSTANCE = new HsqldbNonAudit("DBStore: Hsqldb (non audit)");
- public static class StmtNonAudit extends Hsqldb
+ public HsqldbNonAudit(String name)
{
- private static final long serialVersionUID = 1L;
-
- public static final StmtNonAudit INSTANCE = new StmtNonAudit("HsqldbHorizontalNonAudit");
-
- public StmtNonAudit(String name)
- {
- super(name);
- }
-
- @Override
- protected void initRepositoryProperties(Map<String, String> props)
- {
- super.initRepositoryProperties(props);
- props.put(IRepository.Props.SUPPORTING_AUDITS, "false");
- }
-
- @Override
- protected IJDBCDelegateProvider createDelegateProvider()
- {
- return CDODBUtil.createStatementJDBCDelegateProvider();
- }
-
- @Override
- public void tearDown() throws Exception
- {
- try
- {
- // verify DB integrity
- new NonAuditDBStoreIntegrityVerifier(getRepository(REPOSITORY_NAME)).verify();
- }
- finally
- {
- super.tearDown();
- }
- }
+ super(name);
}
- public static class PrepStmt extends Hsqldb
+ @Override
+ protected void initRepositoryProperties(Map<String, String> props)
{
- private static final long serialVersionUID = 1L;
-
- public static final PrepStmt INSTANCE = new PrepStmt("HsqldbHorizontalPrepStmt");
-
- public PrepStmt(String name)
- {
- super(name);
- }
-
- @Override
- public void tearDown() throws Exception
- {
- try
- {
- // verify DB integrity
- new AuditDBStoreIntegrityVerifier(getRepository(REPOSITORY_NAME)).verify();
- }
- finally
- {
- super.tearDown();
- }
- }
-
- @Override
- protected IJDBCDelegateProvider createDelegateProvider()
- {
- return CDODBUtil.createPreparedStatementJDBCDelegateProvider();
- }
- }
-
- public static class PrepStmtNonAudit extends Hsqldb
- {
- private static final long serialVersionUID = 1L;
-
- public static final PrepStmtNonAudit INSTANCE = new PrepStmtNonAudit("HsqldbHorizontalPrepStmtNonAudit");
-
- public PrepStmtNonAudit(String name)
- {
- super(name);
- }
-
- @Override
- protected void initRepositoryProperties(Map<String, String> props)
- {
- super.initRepositoryProperties(props);
- props.put(IRepository.Props.SUPPORTING_AUDITS, "false");
- }
-
- @Override
- protected IJDBCDelegateProvider createDelegateProvider()
- {
- return CDODBUtil.createPreparedStatementJDBCDelegateProvider();
- }
-
- @Override
- public void tearDown() throws Exception
- {
- try
- {
- // verify DB integrity
- new NonAuditDBStoreIntegrityVerifier(getRepository(REPOSITORY_NAME)).verify();
- }
- finally
- {
- super.tearDown();
- }
- }
+ super.initRepositoryProperties(props);
+ props.put(IRepository.Props.SUPPORTING_AUDITS, "false");
}
}
/**
* @author Eike Stepper
*/
- public abstract static class Derby extends DB
+ public static class Derby extends DB
{
private static final long serialVersionUID = 1L;
+ public static final Derby INSTANCE = new Derby("DBStore: Derby");
+
private transient File dbFolder;
private transient EmbeddedDataSource dataSource;
@@ -500,176 +390,105 @@ public abstract class RepositoryConfig extends Config implements IRepositoryConf
{
IOUtil.delete(dbFolder);
}
+ }
- public static class Stmt extends Derby
+ /**
+ * @author Simon McDuff
+ */
+ public static class Mysql extends DB
+ {
+ private static final long serialVersionUID = 1L;
+
+ public static final Mysql INSTANCE = new Mysql("DBStore: Mysql");
+
+ private transient MysqlDataSource setupDataSource;
+
+ private transient MysqlDataSource dataSource;
+
+ public Mysql(String name)
{
- private static final long serialVersionUID = 1L;
+ super(name);
+ }
- public static final Stmt INSTANCE = new Stmt("DerbyHorizontalStmt");
+ @Override
+ protected IMappingStrategy createMappingStrategy()
+ {
+ return CDODBUtil.createHorizontalMappingStrategy();
+ }
- public Stmt(String name)
+ @Override
+ protected IDBAdapter createDBAdapter()
+ {
+ return new MYSQLAdapter();
+ }
+
+ private MysqlDataSource getSetupDataSource()
+ {
+ if (setupDataSource == null)
{
- super(name);
+ setupDataSource = new MysqlDataSource();
+ setupDataSource.setUrl("jdbc:mysql://localhost");
+ setupDataSource.setUser("sa");
}
- @Override
- protected IJDBCDelegateProvider createDelegateProvider()
+ return setupDataSource;
+ }
+
+ @Override
+ public void setUp() throws Exception
+ {
+ dropDatabase();
+ Connection connection = null;
+ try
{
- return CDODBUtil.createStatementJDBCDelegateProvider();
+ connection = getSetupDataSource().getConnection();
+ connection.prepareStatement("create database cdodb1").execute();
}
+ catch (SQLException ignore)
+ {
+
+ }
+ finally
+ {
+ connection.close();
+ }
+ super.setUp();
}
- public static class PrepStmt extends Derby
+ @Override
+ protected DataSource createDataSource()
{
- private static final long serialVersionUID = 1L;
+ dataSource = new MysqlDataSource();
+ dataSource.setUrl("jdbc:mysql://localhost/cdodb1");
+ dataSource.setUser("sa");
+ return dataSource;
+ }
- public static final PrepStmt INSTANCE = new PrepStmt("DerbyHorizontalPrepStmt");
+ @Override
+ public void tearDown() throws Exception
+ {
+ super.tearDown();
+ dropDatabase();
+ }
- public PrepStmt(String name)
+ private void dropDatabase() throws Exception
+ {
+ Connection connection = null;
+ try
{
- super(name);
+ connection = getSetupDataSource().getConnection();
+ connection.prepareStatement("DROP database cdodb1").execute();
}
+ catch (SQLException ignore)
+ {
- @Override
- protected IJDBCDelegateProvider createDelegateProvider()
+ }
+ finally
{
- return CDODBUtil.createPreparedStatementJDBCDelegateProvider();
+ connection.close();
}
}
- }
- // XXX
- // /**
- // * @author Simon McDuff
- // */
- // public static abstract class Mysql extends DB
- // {
- // private static final long serialVersionUID = 1L;
- //
- // private transient MysqlDataSource setupDataSource;
- //
- // private transient MysqlDataSource dataSource;
- //
- // public Mysql(String name)
- // {
- // super(name);
- // }
- //
- // @Override
- // protected IMappingStrategy createMappingStrategy()
- // {
- // return CDODBUtil.createHorizontalMappingStrategy();
- // }
- //
- // @Override
- // protected IDBAdapter createDBAdapter()
- // {
- // return new MYSQLAdapter();
- // }
- //
- // private MysqlDataSource getSetupDataSource()
- // {
- // if (setupDataSource == null)
- // {
- // setupDataSource = new MysqlDataSource();
- // setupDataSource.setUrl("jdbc:mysql://localhost");
- // setupDataSource.setUser("sa");
- // }
- //
- // return setupDataSource;
- // }
- //
- // @Override
- // public void setUp() throws Exception
- // {
- // dropDatabase();
- // Connection connection = null;
- // try
- // {
- // connection = getSetupDataSource().getConnection();
- // connection.prepareStatement("create database cdodb1").execute();
- // }
- // catch (SQLException ignore)
- // {
- //
- // }
- // finally
- // {
- // connection.close();
- // }
- // super.setUp();
- // }
- //
- // @Override
- // protected DataSource createDataSource()
- // {
- // dataSource = new MysqlDataSource();
- // dataSource.setUrl("jdbc:mysql://localhost/cdodb1");
- // dataSource.setUser("sa");
- // return dataSource;
- // }
- //
- // @Override
- // public void tearDown() throws Exception
- // {
- // super.tearDown();
- // dropDatabase();
- // }
- //
- // private void dropDatabase() throws Exception
- // {
- // Connection connection = null;
- // try
- // {
- // connection = getSetupDataSource().getConnection();
- // connection.prepareStatement("DROP database cdodb1").execute();
- // }
- // catch (SQLException ignore)
- // {
- //
- // }
- // finally
- // {
- // connection.close();
- // }
- // }
- //
- // public static class Stmt extends Mysql
- // {
- // private static final long serialVersionUID = 1L;
- //
- // public static final Stmt INSTANCE = new Stmt("MysqlHorizontalStmt");
- //
- // public Stmt(String name)
- // {
- // super(name);
- // }
- //
- // @Override
- // protected IJDBCDelegateProvider createDelegateProvider()
- // {
- // return CDODBUtil.createStatementJDBCDelegateProvider();
- // }
- // }
- //
- // public static class PrepStmt extends Mysql
- // {
- // private static final long serialVersionUID = 1L;
- //
- // public static final PrepStmt INSTANCE = new PrepStmt("MysqlHorizontalPrepStmt");
- //
- // public PrepStmt(String name)
- // {
- // super(name);
- // }
- //
- // @Override
- // protected IJDBCDelegateProvider createDelegateProvider()
- // {
- // return CDODBUtil.createPreparedStatementJDBCDelegateProvider();
- // }
- // }
- // }
+ }
}
-
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/verifier/AbstractDBStoreVerifier.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/verifier/AbstractDBStoreVerifier.java
index 87f2bab..67ed540 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/verifier/AbstractDBStoreVerifier.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/store/verifier/AbstractDBStoreVerifier.java
@@ -65,7 +65,15 @@ public abstract class AbstractDBStoreVerifier
accessor = (IDBStoreAccessor)repository.getStore().getReader(null);
}
- return accessor.getJDBCDelegate().getStatement();
+ try
+ {
+ return accessor.getConnection().createStatement();
+ }
+ catch (SQLException ex)
+ {
+ ex.printStackTrace();
+ return null;
+ }
}
protected List<IClassMapping> getClassMappings()