Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorStefan Winkler2009-04-16 15:31:31 +0000
committerStefan Winkler2009-04-16 15:31:31 +0000
commit0614d2a4b04c2e36b4a772e4e1a0f79852cc025a (patch)
treeb181771e783930571964a77b54265c3c85596f9e /plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server
parent1a6330dd049c7a38b0137065877799cd356fc432 (diff)
downloadcdo-0614d2a4b04c2e36b4a772e4e1a0f79852cc025a.tar.gz
cdo-0614d2a4b04c2e36b4a772e4e1a0f79852cc025a.tar.xz
cdo-0614d2a4b04c2e36b4a772e4e1a0f79852cc025a.zip
Documentation added.
Diffstat (limited to 'plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server')
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/CDODBUtil.java38
-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/IMetaDataManager.java39
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IObjectTypeCache.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IAuditSupport.java50
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMapping.java97
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IDeltaSupport.java24
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMapping.java63
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMappingDeltaSupport.java77
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java147
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ITypeMapping.java89
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java29
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreChunkReader.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreFactory.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java13
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java33
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java228
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java10
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/FieldInfo.java42
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java44
27 files changed, 848 insertions, 263 deletions
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 7b28a913cb..5957710263 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
@@ -7,6 +7,9 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Stefan Winkler - 271444: [DB] Multiple refactorings
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
+ *
*/
package org.eclipse.emf.cdo.server.db;
@@ -135,6 +138,19 @@ public final class CDODBUtil
}
/**
+ * Execute update on the given prepared statement and handle common cases of return values.
+ *
+ * @param stmt
+ * the prepared statement
+ * @param exactlyOne
+ * if <code>true</code>, the update count is checked to be <code>1</code>. Else the update result is only
+ * checked so that the update was successful (i.e. result code != Statement.EXECUTE_FAILED).
+ * @return the update count / execution result as returned by {@link PreparedStatement#executeUpdate()}. Can be used
+ * by the caller to perform more advanced checks.
+ * @throws SQLException
+ * if {@link PreparedStatement#executeUpdate()} throws it.
+ * @throws IllegalStateException
+ * if the check indicated by <code>excatlyOne</code> indicates an error.
* @since 2.0
*/
public static int sqlUpdate(PreparedStatement stmt, boolean exactlyOne) throws SQLException
@@ -155,29 +171,13 @@ public final class CDODBUtil
return result;
}
- // public static CDODBStoreManager getStoreManager(IDBAdapter dbAdapter,
- // DataSource dataSource)
- // {
- // CDODBStoreManager storeManager = new CDODBStoreManager(dbAdapter,
- // dataSource);
- // storeManager.initDatabase();
- // return storeManager;
- // }
- //
- // public static CDODBStoreManager getStoreManager()
- // {
- // Properties properties = OM.BUNDLE.getConfigProperties();
- // String adapterName = properties.getProperty("store.adapterName", "derby-embedded");
- // IDBAdapter dbAdapter = DBUtil.getDBAdapter(adapterName);
- // DataSource dataSource = DBUtil.createDataSource(properties, "datasource");
- // return getStoreManager(dbAdapter, dataSource);
- // }
-
/**
* For debugging purposes ONLY!
*
+ * @deprecated Should only be used when debugging.
* @since 2.0
*/
+ @Deprecated
public static void sqlDump(Connection conn, String sql)
{
ContextTracer TRACER = new ContextTracer(OM.DEBUG, CDODBUtil.class);
@@ -246,8 +246,10 @@ public final class CDODBUtil
/**
* For debugging purposes ONLY!
*
+ * @deprecated Should only be used when debugging.
* @since 2.0
*/
+ @Deprecated
public static void sqlDump(IDBConnectionProvider connectionProvider, String sql)
{
Connection connection = connectionProvider.getConnection();
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 9fd4f41452..5bc90d1bcc 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
@@ -7,6 +7,8 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Stefan Winkler - 271444: [DB] Multiple refactorings
+ * https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.db;
@@ -50,6 +52,8 @@ public interface IDBStore extends IStore
public IDBStoreAccessor getWriter(ITransaction transaction);
/**
+ * Get the meta data manager associated with this DBStore.
+ *
* @since 2.0
*/
public IMetaDataManager getMetaDataManager();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java
index ac76a09eb6..0e4e7a31fe 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMetaDataManager.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.db;
@@ -31,31 +31,66 @@ import java.util.Collection;
public interface IMetaDataManager
{
/**
+ * Returns the meta ID of the given {@link EModelElement}. <code> getMetaID(getMetaInstance(x))</code> yields
+ * <code>x</code>
+ *
+ * @param modelElement
+ * the element
+ * @return the corresponding ID
* @since 2.0
*/
public long getMetaID(EModelElement modelElement);
/**
+ * Returns the {@link EModelElement} referred to by the given ID. <code> getMetaInstance(getMetaID(m))</code> yields
+ * <code>m</code>
+ *
* @since 2.0
*/
public EModelElement getMetaInstance(long id);
/**
+ * Loads a package unit from the database.
+ *
+ * @param connection
+ * the DB connection to read from.
+ * @param packageUnit
+ * the package unit to load.
+ * @return the loaded package unit.
* @since 2.0
*/
public EPackage[] loadPackageUnit(Connection connection, InternalCDOPackageUnit packageUnit);
- /**
+/**
+ * Reads information about package units present in the database.
+ * @param connection the DB connection to read from.
+ * @return a collection of package unit information records which can be
+ * passed to {@link IMetaDataManager#loadPackageUnit(Connection, InternalCDOPackageUnit))
+ * in order to read the EPackage.
+ *
* @since 2.0
*/
public Collection<InternalCDOPackageUnit> readPackageUnits(Connection connection);
/**
+ * Write package units to the database.
+ *
+ * @param connection
+ * the DB connection to write to.
+ * @param packageUnits
+ * the package units to write.
+ * @param monitor
+ * the monitor to indicate progress.
* @since 2.0
*/
public void writePackageUnits(Connection connection, InternalCDOPackageUnit[] packageUnits, OMMonitor monitor);
/**
+ * Get the DB type associated with the given {@link EClassifier}.
+ *
+ * @param eType
+ * the type to look up.
+ * @return the {@link DBType} of the given {@link EClassifier}.
* @since 2.0
*/
public DBType getDBType(EClassifier eType);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IObjectTypeCache.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IObjectTypeCache.java
index 5b9bdbff31..b7f86154c5 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IObjectTypeCache.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IObjectTypeCache.java
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.db;
@@ -38,6 +39,11 @@ public interface IObjectTypeCache
public void removeObjectType(IDBStoreAccessor accessor, CDOID id);
/**
+ * Return the maximum object id managed by this cache.
+ *
+ * @param connection
+ * the DB connection to use.
+ * @return the maximum object id.
* @since 2.0
*/
public long getMaxId(Connection connection);
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IAuditSupport.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IAuditSupport.java
index 7a6311f9a5..15bf3cc983 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IAuditSupport.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IAuditSupport.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.db.mapping;
@@ -15,17 +15,57 @@ import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
/**
+ * Interface which complements {@link IClassMapping} with methods to facilitate
+ * audit support.
+ *
+ * @see {@link IMappingStrategy#hasAuditSupport()
+ *
* @author Eike Stepper
* @author Stefan Winkler
+ *
* @since 2.0
*/
public interface IAuditSupport
{
- boolean readRevisionByVersion(IDBStoreAccessor dbStoreAccessor, InternalCDORevision revision, int version,
- int referenceChunk);
+ /**
+ * Read a specific version of a revision. If this method returns <code>true</code> it is guaranteed that
+ * <code>revision.getVersion() == version</code>
+ *
+ * @param dbStoreAccessor
+ * the accessor to use.
+ * @param revision
+ * the revision object into which the data should be read. The revision has to be have its ID set to the
+ * requested object's ID. The version is ignored, as the version parameter is used to determine the version
+ * to be read.
+ * @param version
+ * the version which should be read.
+ * @param listChunk
+ * the chunk size to read attribute lists.
+ * @return <code>true</code>, if the revision has been found and read correctly. <code>false</code> if the revision
+ * could not be found. In this case, the content of <code>revision</code> is undefined.
+ */
+ public boolean readRevisionByVersion(IDBStoreAccessor dbStoreAccessor, InternalCDORevision revision, int version,
+ int listChunk);
- boolean readRevisionByTime(IDBStoreAccessor dbStoreAccessor, InternalCDORevision revision, long timeStamp,
- int referenceChunk);
+ /**
+ * Read a specific past version of a revision. If this method returns <code>true</code> it is guaranteed that
+ * <code>revision.getCreated() <= timeStamp && (getRevised() == 0 || getRevised() >= timeStamp))</code>
+ *
+ * @param dbStoreAccessor
+ * the accessor to use.
+ * @param revision
+ * the revision object into which the data should be read. The revision has to be have its ID set to the
+ * requested object's ID. The version is ignored, as the version parameter is used to determine the version
+ * to be read.
+ * @param timeStamp
+ * the timeStamp which should be used to determine the revision's version.
+ * @param listChunk
+ * the chunk size to read attribute lists.
+ * @return <code>true</code>, if the revision has been found and read correctly. <code>false</code> if the revision
+ * could not be found. In this case, the content of <code>revision</code> is undefined.
+ */
+ public boolean readRevisionByTime(IDBStoreAccessor dbStoreAccessor, InternalCDORevision revision, long timeStamp,
+ int listChunk);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMapping.java
index 2a27b70083..2367cf8add 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IClassMapping.java
@@ -7,15 +7,17 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.db.mapping;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevision;
import org.eclipse.net4j.db.ddl.IDBTable;
+import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
import org.eclipse.emf.ecore.EStructuralFeature;
@@ -24,26 +26,103 @@ import java.sql.PreparedStatement;
import java.util.Collection;
/**
+ * Basic interface for class mappings.
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
*/
public interface IClassMapping
{
+ /**
+ * Returns all DB tables which are used by this class and all its contained features.
+ *
+ * @return a collection of all tables of this class and all its contained features.
+ */
+ public Collection<IDBTable> getDBTables();
- void detachObject(IDBStoreAccessor dbStoreAccessor, CDOID id, long revised, OMMonitor monitor);
+ /**
+ * Get the mapping of the many-valued feature.
+ *
+ * @param feature
+ * the feature for which the mapping should be returned. <code>feature.isMany()</code> has to be
+ * <code>true</code>.
+ * @return the list mapping corresponding to the feature.
+ */
+ public IListMapping getListMapping(EStructuralFeature feature);
- void writeRevision(IDBStoreAccessor dbStoreAccessor, InternalCDORevision revision, OMMonitor monitor);
+ /**
+ * Read the current version of a revision.
+ *
+ * @param dbStoreAccessor
+ * the accessor to use.
+ * @param revision
+ * the revision object into which the data should be read. The revision has to be have its ID set to the
+ * requested object's ID. The version is ignored, as the version parameter is used to determine the version
+ * to be read.
+ * @param listChunk
+ * the chunk size to read attribute lists.
+ * @return <code>true</code>, if the revision has been found and read correctly. <code>false</code> if the revision
+ * could not be found. In this case, the content of <code>revision</code> is undefined.
+ */
+ public boolean readRevision(IDBStoreAccessor dbStoreAccessor, InternalCDORevision revision, int listChunk);
- boolean readRevision(IDBStoreAccessor dbStoreAccessor, InternalCDORevision revision, int referenceChunk);
+ /**
+ * Write the revision data to the database.
+ *
+ * @param dbStoreAccessor
+ * the accessor to use.
+ * @param revision
+ * the revision to write.
+ * @param monitor
+ * the monitor to indicate progress.
+ */
+ public void writeRevision(IDBStoreAccessor dbStoreAccessor, InternalCDORevision revision, OMMonitor monitor);
- Collection<IDBTable> getDBTables();
+ /**
+ * Removes an object from the database. In the case of auditing support the object is just marked as revised, else it
+ * it permanently deleted.
+ *
+ * @param dbStoreAccessor
+ * the accessor to use.
+ * @param id
+ * the ID of the object to remove.
+ * @param revised
+ * the timeStamp when this object became detached.
+ * @param monitor
+ * the monitor to indicate progress.
+ */
+ public void detachObject(IDBStoreAccessor dbStoreAccessor, CDOID id, long revised, OMMonitor monitor);
- PreparedStatement createObjectIdStatement(IDBStoreAccessor accessor);
+ /**
+ * Create a prepared statement which returns all IDs of instances of the corresponding class.
+ *
+ * @param accessor
+ * the accessor to use to create the statement
+ * @return the prepared statement ready to be executed using <code>result.executeQuery()</code>.
+ */
+ public PreparedStatement createObjectIdStatement(IDBStoreAccessor accessor);
- PreparedStatement createResourceQueryStatement(IDBStoreAccessor accessor, CDOID folderId, String name,
+ /**
+ * Create a prepared statement which returns all IDs of instances of the corresponding class.
+ *
+ * @param accessor
+ * the accessor to use to create the statement
+ * @param folderId
+ * the ID of the containing folder. <code>0</code> means none.
+ * @param name
+ * the name of the resource node to look up
+ * @param exactMatch
+ * if <code>true</code>, <code>name</code> must match exactly, otherwise all resource nodes starting with
+ * <code>name</code> are returned.
+ * @param timeStamp
+ * a timestamp in the past if past versions should be looked up. In case of no audit support, this must be
+ * {@link CDORevision#UNSPECIFIED_DATE}.
+ * @return the prepared statement ready to be executed using <code>result.executeQuery()</code>.
+ * @throws ImplementationError
+ * if called on a mapping which does not map an <code>EClass instanceof CDOResourceNode</code>.
+ */
+ public PreparedStatement createResourceQueryStatement(IDBStoreAccessor accessor, CDOID folderId, String name,
boolean exactMatch, long timeStamp);
- IListMapping getListMapping(EStructuralFeature feature);
-
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IDeltaSupport.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IDeltaSupport.java
index 072dd0a61a..4e73d84015 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IDeltaSupport.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IDeltaSupport.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * 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
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.db.mapping;
@@ -17,6 +17,11 @@ import org.eclipse.emf.cdo.spi.common.revision.InternalCDORevisionDelta;
import org.eclipse.net4j.util.om.monitor.OMMonitor;
/**
+ * Interface which complements {@link IClassMapping} with methods to facilitate
+ * revision delta support.
+ *
+ * @see {@link IMappingStrategy#hasDeltaSupport()
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
@@ -24,7 +29,18 @@ import org.eclipse.net4j.util.om.monitor.OMMonitor;
public interface IDeltaSupport
{
- void writeRevisionDelta(IDBStoreAccessor dbStoreAccessor, InternalCDORevisionDelta delta, long created,
+ /**
+ * Write a revision delta.
+ *
+ * @param dbStoreAccessor
+ * the accessor to use.
+ * @param delta
+ * the delta to write.
+ * @param created
+ * the creation timestamp of the new version
+ * @param monitor
+ * the monitor to report progress.
+ */
+ public void writeRevisionDelta(IDBStoreAccessor dbStoreAccessor, InternalCDORevisionDelta delta, long created,
OMMonitor monitor);
-
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMapping.java
index 53f3274c02..c26ce2b807 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMapping.java
@@ -12,6 +12,7 @@
package org.eclipse.emf.cdo.server.db.mapping;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.IStoreChunkReader.Chunk;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IDBStoreChunkReader;
@@ -25,26 +26,74 @@ import java.util.Collection;
import java.util.List;
/**
+ * Interface for mapping features with <code>isMany() == true</code>.
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
*/
public interface IListMapping
{
+ /**
+ * Return the mapped feature.
+ *
+ * @return the mapped feature.
+ */
+ public EStructuralFeature getFeature();
- void writeValues(IDBStoreAccessor accessor, InternalCDORevision revision);
-
- void readValues(IDBStoreAccessor accessor, InternalCDORevision revision, int referenceChunk);
+ /**
+ * Returns all DB tables which are used by this feature.
+ *
+ * @return a collection of all tables of this feature.
+ */
+ public Collection<IDBTable> getDBTables();
- void readChunks(IDBStoreChunkReader dbStoreChunkReader, List<Chunk> chunks, String string);
+ /**
+ * Write a complete list of values to the database.
+ *
+ * @param accessor
+ * the accessor to use.
+ * @param revision
+ * the revision containing the list to be written.
+ */
+ public void writeValues(IDBStoreAccessor accessor, InternalCDORevision revision);
- Collection<IDBTable> getDBTables();
+ /**
+ * Read the list size and the complete list or the first part of it.
+ *
+ * @param accessor
+ * the accessor to use.
+ * @param revision
+ * the revision into which the list values should be read.
+ * @param listChunk
+ * indicating the lazy loading behavior: {@link CDORevision#UNCHUNKED} means that the whole list should be
+ * read. Else, if <code>listChunk >= 0</code>, the list is filled with
+ * {@link InternalCDORevision#UNINITIALIZED} and only the first <code>listChunk</code> values are read.
+ */
+ public void readValues(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk);
- EStructuralFeature getFeature();
+ /**
+ * Used to load-on-demand chunks of a list.
+ *
+ * @param dbStoreChunkReader
+ * the chunkReader to use
+ * @param chunks
+ * the chunks to read
+ * @param where
+ * the where-clause to use in order to read the chunks.
+ */
+ public void readChunks(IDBStoreChunkReader dbStoreChunkReader, List<Chunk> chunks, String where);
/**
* Hook with which a list mapping is notified that a containing object has been revised. Can be implemented in order
* to clean up lists of revised objects.
+ *
+ * @param accessor
+ * the accessor to use.
+ * @param id
+ * the ID of the object which has been revised.
+ * @param revised
+ * the timestamp at which the object was revised.
*/
- void objectRevised(IDBStoreAccessor accessor, CDOID id, long revised);
+ public void objectRevised(IDBStoreAccessor accessor, CDOID id, long revised);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMappingDeltaSupport.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMappingDeltaSupport.java
index 5bdcd16f2b..823c760d07 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMappingDeltaSupport.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IListMappingDeltaSupport.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * 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
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.db.mapping;
@@ -15,19 +15,84 @@ import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
/**
+ * Interface to complement {@link IListMapping} in order to provide list delta processing support.
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
*/
public interface IListMappingDeltaSupport
{
- void removeListItem(IDBStoreAccessor accessor, CDOID id, int newVersion, int index);
-
+ /**
+ * Insert a list item at a specified position.
+ *
+ * @param accessor
+ * the accessor to use
+ * @param id
+ * the id of the revision to insert the value
+ * @param newVersion
+ * the new version of the revision after the value is inserted.
+ * @param index
+ * the position at which the value should be inserted.
+ * @param value
+ * the value to insert.
+ */
void insertListItem(IDBStoreAccessor accessor, CDOID id, int newVersion, int index, Object value);
- void clearList(IDBStoreAccessor accessor, CDOID id);
-
+ /**
+ * Set a value at a specified position to the given value.
+ *
+ * @param accessor
+ * the accessor to use
+ * @param id
+ * the id of the revision to set the value
+ * @param newVersion
+ * the new version of the revision after the value is set.
+ * @param index
+ * the position at which the value should be set.
+ * @param value
+ * the value to be set.
+ */
void setListItem(IDBStoreAccessor accessor, CDOID id, int newVersion, int index, Object value);
+ /**
+ * Move a list item from one position to another. Indices between both positions are updated so that the list remains
+ * consistent.
+ *
+ * @param accessor
+ * the accessor to use
+ * @param id
+ * the id of the revision in which to move the item
+ * @param newVersion
+ * the new version of the revision after the item is moved.
+ * @param oldPosition
+ * the old position of the item.
+ * @param newPosition
+ * the new position of the item.
+ */
void moveListItem(IDBStoreAccessor accessor, CDOID id, int newVersion, int oldPosition, int newPosition);
+
+ /**
+ * Remove a list item from a specified a position.
+ *
+ * @param accessor
+ * the accessor to use
+ * @param id
+ * the id of the revision from which to remove the item
+ * @param newVersion
+ * the new version of the revision after the item is removed.
+ * @param index
+ * the index of the item to be removed.
+ */
+ void removeListItem(IDBStoreAccessor accessor, CDOID id, int newVersion, int index);
+
+ /**
+ * Clear a list of a given revision.
+ *
+ * @param accessor
+ * the accessor to use
+ * @param id
+ * the id of the revision from which to remove all items
+ */
+ void clearList(IDBStoreAccessor accessor, CDOID id);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java
index 0b056ca739..2ffd5aca26 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/IMappingStrategy.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * 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
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.db.mapping;
@@ -16,6 +16,7 @@ import org.eclipse.emf.cdo.common.model.CDOClassifierRef;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryResourcesContext;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+import org.eclipse.emf.cdo.server.internal.db.DBStore;
import org.eclipse.emf.cdo.spi.common.model.InternalCDOPackageUnit;
import org.eclipse.net4j.db.IDBAdapter;
@@ -30,6 +31,12 @@ import java.sql.Connection;
import java.util.Map;
/**
+ * The mapping strategy acts as a connection between the DBStore and the database management (and OR-mapping) classes.
+ * The {@link DBStore} uses methods of this interface to create and lookup mappings (or mappers, as they could also be
+ * named as such) and to get properties and informations about the mappings used. The mapping classes (e.g., instances
+ * of IClassMapping and IListMapping) also use this class as a central point of information and as a resource of common
+ * functionalities.
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
@@ -65,39 +72,161 @@ public interface IMappingStrategy
*/
public static final String PROP_FORCE_NAMES_WITH_ID = "forceNamesWithID";
- public static final String PROP_TO_MANY_REFERENCE_MAPPING = "toManyReferenceMapping";
-
- public static final String PROP_TO_ONE_REFERENCE_MAPPING = "toOneReferenceMapping";
-
+ /**
+ * @return the store, this MappingStrategy instance belongs to.
+ */
public IDBStore getStore();
+ /**
+ * Set the store to which this MappingStrategy instance belongs. Should only be called by the {@link DBStore}, and
+ * only once to initialize the connection between {@link DBStore} and mapping strategy.
+ *
+ * @param dbStore
+ * the DBStore instance to which this MappingStrategy instance belongs.
+ */
public void setStore(IDBStore dbStore);
+ /**
+ * Factory for value mappings of single-valued attributes.
+ *
+ * @param feature
+ * the feature for which a mapping should be created. It must hold <code>feature.isMany() == false</code>.
+ * @return the mapping created.
+ */
public ITypeMapping createValueMapping(EStructuralFeature feature);
+ /**
+ * Factory for value mappings of multi-valued-attributes.
+ *
+ * @param containingClass
+ * the class containing the feature.
+ * @param feature
+ * the feature for which a mapping should be created. It must hold <code>feature.isMany() == true</code>.
+ * @return
+ */
public IListMapping createListMapping(EClass containingClass, EStructuralFeature feature);
- public String getTableName(ENamedElement eClass);
+ /**
+ * Create a suitable table name which can be used to map the given element. Should only be called by mapping classes.
+ *
+ * @param element
+ * the element for which the name should be created. It must hold:
+ * <code>element instanceof EClass || element instanceof EPackage</code>.
+ * @return the created table name. It is guaranteed that the table name is compatible with the chosen database.
+ */
+ public String getTableName(ENamedElement element);
+ /**
+ * Create a suitable table name which can be used to map the given element. Should only be called by mapping classes.
+ * Should only be called by mapping classes.
+ *
+ * @param containingClass
+ * the class containeng the feature.
+ * @param feature
+ * the feature for which the table name should be created.
+ * @return the created table name. It is guaranteed that the table name is compatible with the chosen database.
+ */
public String getTableName(EClass containingClass, EStructuralFeature feature);
+ /**
+ * Create a suitable column name which can be used to map the given element. Should only be called by mapping classes.
+ *
+ * @param feature
+ * the feature for which the column name should be created.
+ * @return the created column name. It is guaranteed that the name is compatible with the chosen database.
+ */
public String getFieldName(EStructuralFeature feature);
+ /**
+ * Create and initialize the mapping infrastructure for the given packages. Should be called from the DBStore or the
+ * DBStoreAccessor.
+ *
+ * @param connection
+ * the connection to use.
+ * @param packageUnits
+ * the packages whose elements should be mapped.
+ * @param monitor
+ * the monitor to report progress.
+ */
public void createMapping(Connection connection, InternalCDOPackageUnit[] packageUnits, OMMonitor monitor);
+ /**
+ * Look up an existing class mapping for the given class. Before this method is called, the class mapping must have
+ * been initialized by calling {@link #createMapping(Connection, InternalCDOPackageUnit[], OMMonitor)} on its
+ * containing package.
+ *
+ * @param eClass
+ * the class to look up.
+ * @return the class mapping.
+ */
public IClassMapping getClassMapping(EClass eClass);
+ /**
+ * Query if this mapping supports revision deltas. <br>
+ * If this method returns <code>true</code>, it is guaranteed that all class mappings returned by
+ * {@link #getClassMapping(EClass)} implement {@link IDeltaSupport}.
+ *
+ * @return <code>true</code> if revision deltas are supported, <code>false</code> else.
+ */
public boolean hasDeltaSupport();
- public void queryResources(IDBStoreAccessor dbStoreAccessor, QueryResourcesContext context);
-
+ /**
+ * Query if this mapping supports audits. <br>
+ * If this method returns <code>true</code>, it is guaranteed that all class mappings returned by
+ * {@link #getClassMapping(EClass)} implement {@link IAuditSupport}.
+ *
+ * @return <code>true</code> if audits are supported, <code>false</code> else.
+ */
public boolean hasAuditSupport();
+ /**
+ * Execute a resource query.
+ *
+ * @param dbStoreAccessor
+ * the accessor to use.
+ * @param context
+ * the context from which the query parameters are read and to which the result is written.
+ */
+ public void queryResources(IDBStoreAccessor dbStoreAccessor, QueryResourcesContext context);
+
+ /**
+ * Read the type (i.e. class) of the object referred to by a given ID.
+ *
+ * @param dbStoreAccessor
+ * the accessor to use to look up the type.
+ * @param id
+ * the ID of the object for which the type is to be determined.
+ * @return the type of the object.
+ */
public CDOClassifierRef readObjectType(IDBStoreAccessor dbStoreAccessor, CDOID id);
+ /**
+ * Get an iterator over all instances of objects in the store.
+ *
+ * @param dbStoreAccessor
+ * the accessor to use.
+ * @return the iterator.
+ */
public CloseableIterator<CDOID> readObjectIDs(IDBStoreAccessor dbStoreAccessor);
+ /**
+ * Return the maximum object id used in the store. This is used by the DBStore if a previous crash is discovered
+ * during the startup process. Should only be called by the DBStore and only during startup.
+ *
+ * @param dbAdapter
+ * the dbAdapter to use to access the database
+ * @param connection
+ * the connection to use to access the database
+ * @return the maximum object id used in the store.
+ */
public long repairAfterCrash(IDBAdapter dbAdapter, Connection connection);
+ /**
+ * Set configuration properties for this mapping strategy. Should only be called by the factory creating the mapping
+ * strategy instance.
+ *
+ * @param properties
+ * the configuration properties to set.
+ */
public void setProperties(Map<String, String> properties);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ITypeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ITypeMapping.java
index 59adc24f54..c16756cc06 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ITypeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/mapping/ITypeMapping.java
@@ -23,25 +23,98 @@ import java.sql.ResultSet;
import java.sql.SQLException;
/**
+ * Mapping of single values to and from the database.
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
*/
public interface ITypeMapping
{
- public void setValueFromRevision(PreparedStatement stmt, int index, InternalCDORevision value) throws SQLException;
-
- public void setValue(PreparedStatement stmt, int index, Object value) throws SQLException;
-
- public void readValueToRevision(ResultSet resultSet, int i, InternalCDORevision revision) throws SQLException;
+ /**
+ * @return The feature which is associated with this mapping.
+ */
+ public EStructuralFeature getFeature();
- public Object readValue(ResultSet resultSet, int i) throws SQLException;
+ /**
+ * @return The db field which is associated with this mapping.
+ */
+ public IDBField getField();
+ /**
+ * Creates the DBField and adds it to the given table. The name of the DBField is derived from the feature.
+ *
+ * @param table
+ * the table to add this field to.
+ */
public void createDBField(IDBTable table);
+ /**
+ * Creates the DBField and adds it to the given table. The name of the DBField is explicitly determined by the
+ * corresponding parameter.
+ *
+ * @param table
+ * the table to add this field to.
+ * @param fieldName
+ * the name for the DBField.
+ */
public void createDBField(IDBTable table, String fieldName);
- public IDBField getField();
+ /**
+ * Set the given value to the JDBC {@link PreparedStatement} using an appropriate <code>setXxx</code> method.
+ *
+ * @param stmt
+ * the prepared statement to set the value
+ * @param index
+ * the index to use for the <code>setXxx</code> method.
+ * @param value
+ * the value to set.
+ * @throws SQLException
+ * if the <code>setXxx</code> throws it.
+ */
+ public void setValue(PreparedStatement stmt, int index, Object value) throws SQLException;
+
+ /**
+ * Set a value of the given revision to the JDBC {@link PreparedStatement} using an appropriate <code>setXxx</code>
+ * method. The feature from which the value is taken is determined by {@link #getFeature()}.
+ *
+ * @param stmt
+ * the prepared statement to set the value
+ * @param index
+ * the index to use for the <code>setXxx</code> method.
+ * @param revision
+ * the revision to get the value to set from.
+ * @throws SQLException
+ * if the <code>setXxx</code> throws it.
+ */
+ public void setValueFromRevision(PreparedStatement stmt, int index, InternalCDORevision value) throws SQLException;
+
+ /**
+ * Read a value from a {@link ResultSet} and convert it from the DB to the CDO representation.
+ *
+ * @param resultSet
+ * the result set to read from
+ * @param i
+ * the column index in the result set to read from
+ * @return the read value
+ * @throws SQLException
+ * if reading the value throws an SQLException
+ */
+ public Object readValue(ResultSet resultSet, int i) throws SQLException;
+
+ /**
+ * Read a value from a {@link ResultSet}, convert it from the DB to the CDO representation and set it to the feature
+ * of the revision. The feature is determined by getFeature()
+ *
+ * @param resultSet
+ * the result set to read from
+ * @param i
+ * the column index in the result set to read from
+ * @param revision
+ * the revision to which the value should be set.
+ * @throws SQLException
+ * if reading the value throws an SQLException
+ */
+ public void readValueToRevision(ResultSet resultSet, int i, InternalCDORevision revision) throws SQLException;
- public EStructuralFeature getFeature();
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
index 7e55b96d7f..a772fe809c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/CDODBSchema.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * 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
@@ -7,6 +7,8 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
+ *
*/
package org.eclipse.emf.cdo.server.internal.db;
@@ -120,17 +122,17 @@ public class CDODBSchema extends DBSchema
public static final String ATTRIBUTES_FEATURE = "cdo_feature";
/**
- * Field names of reference tables
+ * Field names of list tables
*/
- public static final String REFERENCES_FEATURE = "cdo_feature";
+ public static final String LIST_FEATURE = "cdo_feature";
- public static final String FEATURE_REVISION_ID = "cdo_source";
+ public static final String LIST_REVISION_ID = "cdo_source";
- public static final String FEATURE_REVISION_VERSION = "cdo_version";
+ public static final String LIST_REVISION_VERSION = "cdo_version";
- public static final String FEATURE_IDX = "cdo_idx";
+ public static final String LIST_IDX = "cdo_idx";
- public static final String FEATURE_TARGET = "cdo_target";
+ public static final String LIST_VALUE = "cdo_value";
private CDODBSchema()
{
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 705373c83c..68e1524ed4 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,8 @@
*
* 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
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db;
@@ -29,7 +30,6 @@ import org.eclipse.net4j.db.ddl.IDBSchema;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.spi.db.DBSchema;
import org.eclipse.net4j.util.ReflectUtil.ExcludeFromDump;
-import org.eclipse.net4j.util.lifecycle.ILifecycle;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.monitor.ProgressDistributor;
@@ -40,7 +40,7 @@ import java.text.MessageFormat;
import java.util.Set;
/**
- * @author Eike Stepper TODO: factor out type map and meta stuff into MetadataManager
+ * @author Eike Stepper
*/
public class DBStore extends LongIDStore implements IDBStore
{
@@ -80,7 +80,7 @@ public class DBStore extends LongIDStore implements IDBStore
@ExcludeFromDump
private transient StoreAccessorPool writerPool = new StoreAccessorPool(this, null);
- private IMetaDataManager metaDataManager;
+ private transient IMetaDataManager metaDataManager;
public DBStore()
{
@@ -212,7 +212,7 @@ public class DBStore extends LongIDStore implements IDBStore
super.doActivate();
metaDataManager = new MetaDataManager(this);
- ((ILifecycle)metaDataManager).activate();
+ LifecycleUtil.activate(metaDataManager);
Connection connection = getConnection();
LifecycleUtil.activate(mappingStrategy);
@@ -301,7 +301,7 @@ public class DBStore extends LongIDStore implements IDBStore
{
Connection connection = null;
- ((ILifecycle)metaDataManager).deactivate();
+ LifecycleUtil.deactivate(metaDataManager);
metaDataManager = null;
try
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 e6d1d7fafa..68c7ec9940 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
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * 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
@@ -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 - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db;
@@ -94,15 +95,11 @@ 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);
}
- /**
- * TODO caching?
- */
public CloseableIterator<CDOID> readObjectIDs()
{
if (TRACER.isEnabled())
@@ -113,9 +110,6 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return getStore().getMappingStrategy().readObjectIDs(this);
}
- /**
- * TODO caching?
- */
public CDOClassifierRef readObjectType(CDOID id)
{
if (TRACER.isEnabled())
@@ -128,7 +122,8 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
protected EClass getObjectType(CDOID id)
{
- // TODO Replace calls to getObjectType by optimized calls to RevisionManager.getObjectType (cache!)
+ // TODO (taken over from old implementation:) Replace calls to getObjectType by optimized calls to
+ // RevisionManager.getObjectType (cache!)
CDOClassifierRef type = readObjectType(id);
if (type == null)
{
@@ -140,7 +135,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return (EClass)type.resolve(packageRegistry);
}
- public InternalCDORevision readRevision(CDOID id, int referenceChunk, AdditionalRevisionCache cache)
+ public InternalCDORevision readRevision(CDOID id, int listChunk, AdditionalRevisionCache cache)
{
if (TRACER.isEnabled())
{
@@ -157,7 +152,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
IClassMapping mapping = mappingStrategy.getClassMapping(eClass);
- if (mapping.readRevision(this, revision, referenceChunk))
+ if (mapping.readRevision(this, revision, listChunk))
{
return revision;
}
@@ -166,8 +161,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return null;
}
- public InternalCDORevision readRevisionByTime(CDOID id, int referenceChunk, AdditionalRevisionCache cache,
- long timeStamp)
+ public InternalCDORevision readRevisionByTime(CDOID id, int listChunk, AdditionalRevisionCache cache, long timeStamp)
{
IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
@@ -185,7 +179,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
InternalCDORevision revision = (InternalCDORevision)CDORevisionUtil.create(eClass, id);
IAuditSupport mapping = (IAuditSupport)mappingStrategy.getClassMapping(eClass);
- if (mapping.readRevisionByTime(this, revision, timeStamp, referenceChunk))
+ if (mapping.readRevisionByTime(this, revision, timeStamp, listChunk))
{
return revision;
}
@@ -194,8 +188,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
return null;
}
- public InternalCDORevision readRevisionByVersion(CDOID id, int referenceChunk, AdditionalRevisionCache cache,
- int version)
+ public InternalCDORevision readRevisionByVersion(CDOID id, int listChunk, AdditionalRevisionCache cache, int version)
{
IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
@@ -213,7 +206,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
}
// if audit support is present, just use the audit method
- success = ((IAuditSupport)mapping).readRevisionByVersion(this, revision, version, referenceChunk);
+ success = ((IAuditSupport)mapping).readRevisionByVersion(this, revision, version, listChunk);
}
else
{
@@ -228,7 +221,7 @@ public class DBStoreAccessor extends LongIDStoreAccessor implements IDBStoreAcce
TRACER.format("Selecting current base revision: {0}", id);
}
- success = mapping.readRevision(this, revision, referenceChunk);
+ success = mapping.readRevision(this, revision, listChunk);
if (success && revision.getVersion() != version)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreChunkReader.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreChunkReader.java
index d05d1570bb..1de3985e2d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreChunkReader.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreChunkReader.java
@@ -49,7 +49,7 @@ public class DBStoreChunkReader extends StoreChunkReader implements IDBStoreChun
{
super.addSimpleChunk(index);
builder.append(" AND ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append("=");
builder.append(index);
}
@@ -59,7 +59,7 @@ public class DBStoreChunkReader extends StoreChunkReader implements IDBStoreChun
{
super.addRangedChunk(fromIndex, toIndex);
builder.append(" AND ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" BETWEEN ");
builder.append(fromIndex);
builder.append(" AND ");
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 b2759fc713..7112195c4a 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
@@ -7,6 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java
index a7722f2c6e..9cc7b5508e 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MetaDataManager.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
index d6238f31a7..903f61abe7 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/AbstractMappingStrategy.java
@@ -8,6 +8,7 @@
* Contributors:
* Eike Stepper - initial API and implementation
* Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db.mapping;
@@ -56,12 +57,16 @@ import java.util.Map;
import java.util.Set;
/**
+ * This abstract base class implements those methods which are most likely common to most mapping strategies. It can be
+ * used to derive custom mapping strategy implementation.
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
*/
public abstract class AbstractMappingStrategy extends Lifecycle implements IMappingStrategy
{
+ // --------- database name generation strings --------------
protected static final String NAME_SEPARATOR = "_";
protected static final String TYPE_PREFIX_FEATURE = "F";
@@ -74,7 +79,7 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
// private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, AbstractMappingStrategy.class);
- private IDBStore store;
+ private IDBStore store = null;
private Map<String, String> properties;
@@ -141,6 +146,7 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
public final void setStore(IDBStore dbStore)
{
+ checkInactive();
store = dbStore;
}
@@ -197,7 +203,6 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
currentStatement = null;
}
};
-
};
public abstract CDOClassifierRef readObjectType(IDBStoreAccessor dbStoreAccessor, CDOID id);
@@ -365,7 +370,13 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
public final IClassMapping getClassMapping(EClass eClass)
{
- return classMappings.get(eClass);
+ IClassMapping result = classMappings.get(eClass);
+ if (result != null)
+ {
+ return result;
+ }
+
+ throw new ImplementationError("Class mapping not found for " + eClass.toString());
}
public ITypeMapping createValueMapping(EStructuralFeature feature)
@@ -426,6 +437,7 @@ public abstract class AbstractMappingStrategy extends Lifecycle implements IMapp
public final IListMapping createListMapping(EClass containingClass, EStructuralFeature feature)
{
+ checkArg(feature.isMany(), "Only many-valued features allowed.");
IListMapping mapping = doCreateListMapping(containingClass, feature);
return mapping;
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
index f423cffc49..d2f301d427 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/TypeMapping.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db.mapping;
@@ -32,6 +32,9 @@ import java.sql.Timestamp;
import java.util.Date;
/**
+ * This is a default implementation for the {@link ITypeMapping} interface which provides default behavor for all common
+ * types.
+ *
* @author Eike Stepper
* @author Stefan Winkler
*/
@@ -43,6 +46,14 @@ public abstract class TypeMapping implements ITypeMapping
private IDBField field;
+ /**
+ * Create a new type mapping
+ *
+ * @param mappingStrategy
+ * the associated mapping strategy.
+ * @param feature
+ * the feature to be mapped.
+ */
public TypeMapping(IMappingStrategy mappingStrategy, EStructuralFeature feature)
{
this.mappingStrategy = mappingStrategy;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java
index a78b702115..aa11d0a37a 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalClassMapping.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
@@ -191,11 +191,11 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping
}
}
- protected final void readLists(IDBStoreAccessor accessor, InternalCDORevision revision, int referenceChunk)
+ protected final void readLists(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
for (IListMapping listMapping : listMappings)
{
- listMapping.readValues(accessor, revision, referenceChunk);
+ listMapping.readValues(accessor, revision, listChunk);
}
}
@@ -264,7 +264,8 @@ public abstract class AbstractHorizontalClassMapping implements IClassMapping
return mapping;
}
}
- return null;
+
+ throw new IllegalArgumentException("List mapping for feature " + feature + " does not exist.");
}
protected final IDBTable getTable()
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
index 8579cad2d8..1097c65c62 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractHorizontalMappingStrategy.java
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
@@ -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.model.CDOClassifierRef;
import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.eresource.EresourcePackage;
import org.eclipse.emf.cdo.server.IStoreAccessor.QueryResourcesContext;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
@@ -38,6 +39,13 @@ import java.sql.SQLException;
import java.util.Collection;
/**
+ * * This abstract base class refines {@link AbstractMappingStrategy} by implementing aspects common to horizontal
+ * mapping strategies -- namely:
+ * <ul>
+ * <li>object type cache (table cdo_objects)
+ * <li>resource query handling
+ * </ul>
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
@@ -46,6 +54,9 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, AbstractHorizontalMappingStrategy.class);
+ /**
+ * The associated object type cache.
+ */
private IObjectTypeCache objectTypeCache;
@Override
@@ -62,7 +73,7 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
@Override
public long repairAfterCrash(IDBAdapter dbAdapter, Connection connection)
{
- return objectTypeCache.getMaxId(connection);
+ return objectTypeCache.getMaxId(connection) + 1;
}
@Override
@@ -100,6 +111,7 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
@Override
public void queryResources(IDBStoreAccessor dbStoreAccessor, QueryResourcesContext context)
{
+ // only support timestamp in audit mode
if (context.getTimeStamp() != CDORevision.UNSPECIFIED_DATE && !hasAuditSupport())
{
throw new UnsupportedOperationException("Mapping Strategy does not support audits.");
@@ -107,7 +119,12 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
EresourcePackage resourcesPackage = EresourcePackage.eINSTANCE;
- if (queryResources(dbStoreAccessor, getClassMapping(resourcesPackage.getCDOResourceFolder()), context))
+ // first query folders
+ boolean shallContinue = queryResources(dbStoreAccessor, getClassMapping(resourcesPackage.getCDOResourceFolder()),
+ context);
+
+ // not enough results? -> query resources
+ if (shallContinue)
{
queryResources(dbStoreAccessor, getClassMapping(resourcesPackage.getCDOResource()), context);
}
@@ -117,8 +134,14 @@ public abstract class AbstractHorizontalMappingStrategy extends AbstractMappingS
* This is an intermediate implementation. It should be changed after classmappings support a general way to implement
* queries ...
*
- * @return true if result context is not yet full and query should continue false, if result context is full and query
- * should stop.
+ * @param accessor
+ * the accessor to use.
+ * @param classMapping
+ * the class mapping of a class instanceof {@link CDOResourceNode} which should be queried.
+ * @param context
+ * the query context containing the parameters and the result.
+ * @return <code>true</code> if result context is not yet full and query should continue false, if result context is
+ * full and query should stop.
*/
private boolean queryResources(IDBStoreAccessor accessor, IClassMapping classMapping, QueryResourcesContext context)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java
index c98acee320..8dd6bc41e7 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AbstractListTableMapping.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * 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
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
@@ -44,6 +44,8 @@ import java.util.Collection;
import java.util.List;
/**
+ * This abstract base class provides basic behavior needed for mapping many-valued attributes to tables.
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
@@ -52,14 +54,27 @@ public abstract class AbstractListTableMapping implements IListMapping
{
private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, AbstractListTableMapping.class);
+ /**
+ * The feature for this mapping.
+ */
private EStructuralFeature feature;
+ /**
+ * The table of this mapping.
+ */
private IDBTable table;
+ /**
+ * The type mapping for the value field.
+ */
private ITypeMapping typeMapping;
+ /**
+ * The associated mapping strategy.
+ */
private IMappingStrategy mappingStrategy;
+ // --------- SQL strings - see initSqlStrings() -----------------
private String sqlSelectChunksPrefix;
private String sqlOrderByIndex;
@@ -68,6 +83,8 @@ public abstract class AbstractListTableMapping implements IListMapping
private EClass containingClass;
+ private String sqlGetListLastIndex;
+
public AbstractListTableMapping(IMappingStrategy mappingStrategy, EClass eClass, EStructuralFeature feature)
{
this.mappingStrategy = mappingStrategy;
@@ -93,11 +110,11 @@ public abstract class AbstractListTableMapping implements IListMapping
}
// add field for list index
- IDBField idxField = table.addField(CDODBSchema.FEATURE_IDX, DBType.INTEGER);
+ IDBField idxField = table.addField(CDODBSchema.LIST_IDX, DBType.INTEGER);
// add field for value
typeMapping = mappingStrategy.createValueMapping(feature);
- typeMapping.createDBField(table, CDODBSchema.FEATURE_TARGET);
+ typeMapping.createDBField(table, CDODBSchema.LIST_VALUE);
// add table indexes
table.addIndex(Type.NON_UNIQUE, dbFields);
@@ -121,7 +138,7 @@ public abstract class AbstractListTableMapping implements IListMapping
// ---------------- SELECT to read chunks ----------------------------
StringBuilder builder = new StringBuilder();
builder.append("SELECT ");
- builder.append(CDODBSchema.FEATURE_TARGET);
+ builder.append(CDODBSchema.LIST_VALUE);
builder.append(" FROM ");
builder.append(tableName);
builder.append(" WHERE ");
@@ -143,7 +160,32 @@ public abstract class AbstractListTableMapping implements IListMapping
sqlSelectChunksPrefix = builder.toString();
- sqlOrderByIndex = " ORDER BY " + CDODBSchema.FEATURE_IDX;
+ sqlOrderByIndex = " ORDER BY " + CDODBSchema.LIST_IDX;
+
+ // ----------------- count list size --------------------------
+
+ builder = new StringBuilder("SELECT max(");
+ builder.append(CDODBSchema.LIST_IDX);
+ builder.append(") FROM ");
+ builder.append(tableName);
+ builder.append(" WHERE ");
+
+ for (int i = 0; i < fields.length; i++)
+ {
+ builder.append(fields[i].getName());
+ if (i + 1 < fields.length)
+ {
+ // more to come
+ builder.append("= ? AND ");
+ }
+ else
+ {
+ // last one
+ builder.append("= ? ");
+ }
+ }
+
+ sqlGetListLastIndex = builder.toString();
// ----------------- INSERT - reference entry -----------------
builder = new StringBuilder("INSERT INTO ");
@@ -177,10 +219,26 @@ public abstract class AbstractListTableMapping implements IListMapping
return typeMapping;
}
- public void readValues(IDBStoreAccessor accessor, InternalCDORevision revision, int referenceChunk)
+ public void readValues(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
MoveableList<Object> list = revision.getList(getFeature());
+ int listSize = 0;
+
+ if (listChunk != CDORevision.UNCHUNKED)
+ {
+ listSize = getListLastIndex(accessor, revision);
+ if (listSize == -1)
+ {
+ // list is empty - take shortcut
+ return;
+ }
+ else
+ {
+ // subtract amount of items we are going to read now
+ listSize -= listChunk;
+ }
+ }
if (TRACER.isEnabled())
{
@@ -206,7 +264,7 @@ public abstract class AbstractListTableMapping implements IListMapping
resultSet = pstmt.executeQuery();
- while ((referenceChunk == CDORevision.UNCHUNKED || --referenceChunk >= 0) && resultSet.next())
+ while ((listChunk == CDORevision.UNCHUNKED || --listChunk >= 0) && resultSet.next())
{
Object value = typeMapping.readValue(resultSet, 1);
if (TRACER.isEnabled())
@@ -216,21 +274,75 @@ public abstract class AbstractListTableMapping implements IListMapping
list.add(value);
}
- // TODO Optimize this?
- while (resultSet.next())
+ while (listSize-- > 0)
{
+ list.add(InternalCDORevision.UNINITIALIZED);
if (TRACER.isEnabled())
{
- TRACER.format("Additional value for index {0} ignored due to chunking. Setting uninitialized.", list.size());
+ TRACER.format("Added UNINITIALIZED for index {0} ", list.size());
}
-
- list.add(InternalCDORevision.UNINITIALIZED);
}
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(resultSet);
+ DBUtil.close(pstmt);
+ }
+
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Reading list values done for feature {0}.{1} of {2}v{3}", containingClass.getName(), feature
+ .getName(), revision.getID(), revision.getVersion());
+ }
+ }
+
+ /**
+ * Return the last (maximum) list index. (euals to size-1)
+ *
+ * @param accessor
+ * the accessor to use
+ * @param revision
+ * the revision to which the feature list belongs
+ * @return the last index or <code>-1</code> if the list is empty.
+ */
+ private int getListLastIndex(IDBStoreAccessor accessor, InternalCDORevision revision)
+ {
+ PreparedStatement pstmt = null;
+ ResultSet resultSet = null;
+
+ try
+ {
+ pstmt = accessor.getConnection().prepareStatement(sqlGetListLastIndex);
+
+ setKeyFields(pstmt, revision);
if (TRACER.isEnabled())
{
- TRACER.format("Reading list values done for feature {0}.{1} of {2}v{3}", containingClass.getName(), feature
- .getName(), revision.getID(), revision.getVersion());
+ TRACER.trace(pstmt.toString());
+ }
+
+ resultSet = pstmt.executeQuery();
+
+ if (!resultSet.next())
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("No last index found -> list is empty. ");
+ }
+ return -1;
+ }
+ else
+ {
+ int result = resultSet.getInt(1);
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Read list size = " + result);
+ }
+ return result;
}
}
catch (SQLException ex)
@@ -242,7 +354,6 @@ public abstract class AbstractListTableMapping implements IListMapping
DBUtil.close(resultSet);
DBUtil.close(pstmt);
}
-
}
public final void readChunks(IDBStoreChunkReader chunkReader, List<Chunk> chunks, String where)
@@ -338,10 +449,6 @@ public abstract class AbstractListTableMapping implements IListMapping
{
CDOList values = revision.getList(getFeature());
- // if(values.contains(InternalCDORevision.UNINITIALIZED)) {
- // readUninitializedValues(accessor, values);
- // }
-
int idx = 0;
for (Object element : values)
{
@@ -349,59 +456,6 @@ public abstract class AbstractListTableMapping implements IListMapping
}
}
- // private void readUninitializedValues(IDBStoreAccessor accessor, CDORevision revision, MoveableList<Object> values)
- // {
- // CDOID id = revision.getID();
- // int version = revision.getVersion();
- //
- // if (TRACER.isEnabled())
- // {
- // TRACER.format("Reading uninitialized list values for feature {0}.{1} of {2}v{3}", containingClass.getName(),
- // feature.getName(),
- // id, version);
- // }
- //
- // PreparedStatement pstmt = null;
- // ResultSet resultSet = null;
- //
- // try
- // {
- // String sql = sqlSelectChunksPrefix + sqlOrderByIndex;
- //
- // pstmt = accessor.getConnection().prepareStatement(sql);
- //
- // pstmt.setLong(1, CDOIDUtil.getLong(id));
- // pstmt.setInt(2, version);
- // if (TRACER.isEnabled())
- // {
- // TRACER.trace(pstmt.toString());
- // }
- //
- // resultSet = pstmt.executeQuery();
- //
- // int index = 0;
- //
- // while(resultSet.next()) {
- // if(values.get(index) == InternalCDORevision.UNINITIALIZED) {
- // Object value = typeMapping.readValue(resultSet, 1);
- // if (TRACER.isEnabled())
- // {
- // TRACER.format("Read value for index {0} from result set: {1}", list.size(), value);
- // }
- // }
- // }
- // }
- // catch (SQLException ex)
- // {
- // throw new DBException(ex);
- // }
- // finally
- // {
- // DBUtil.close(resultSet);
- // DBUtil.close(pstmt);
- // }
- // }
-
protected final void writeValue(IDBStoreAccessor accessor, CDORevision revision, int idx, Object value)
{
PreparedStatement stmt = null;
@@ -432,4 +486,32 @@ public abstract class AbstractListTableMapping implements IListMapping
DBUtil.close(stmt);
}
}
+
+ /**
+ * Used by subclasses to indicate which fields should be in the table. I.e. just a pair of name and DBType ...
+ *
+ * @author Stefan Winkler
+ */
+ protected static class FieldInfo
+ {
+ private String name;
+
+ private DBType dbType;
+
+ public FieldInfo(String name, DBType dbType)
+ {
+ this.name = name;
+ this.dbType = dbType;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public DBType getDbType()
+ {
+ return dbType;
+ }
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java
index e2491414d7..23bad70f0c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/AuditListTableMapping.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * 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
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
@@ -27,14 +27,16 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
+ * This is a list-table mapping for audit mode. It has ID and version columns and no delta support.
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
*/
public class AuditListTableMapping extends AbstractListTableMapping
{
- private static final FieldInfo[] KEY_FIELDS = { new FieldInfo(CDODBSchema.FEATURE_REVISION_ID, DBType.BIGINT),
- new FieldInfo(CDODBSchema.FEATURE_REVISION_VERSION, DBType.INTEGER) };
+ private static final FieldInfo[] KEY_FIELDS = { new FieldInfo(CDODBSchema.LIST_REVISION_ID, DBType.BIGINT),
+ new FieldInfo(CDODBSchema.LIST_REVISION_VERSION, DBType.INTEGER) };
public AuditListTableMapping(IMappingStrategy mappingStrategy, EClass eClass, EStructuralFeature feature)
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/FieldInfo.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/FieldInfo.java
deleted file mode 100644
index ef770ca06a..0000000000
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/FieldInfo.java
+++ /dev/null
@@ -1,42 +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
- * Stefan Winkler - major refactoring
- */
-package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
-
-import org.eclipse.net4j.db.DBType;
-
-/**
- * @author Eike Stepper
- * @author Stefan Winkler
- * @since 2.0
- */
-public class FieldInfo
-{
- private String name;
-
- private DBType dbType;
-
- public FieldInfo(String name, DBType dbType)
- {
- this.name = name;
- this.dbType = dbType;
- }
-
- public String getName()
- {
- return name;
- }
-
- public DBType getDbType()
- {
- return dbType;
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
index 64fa5a1c85..041856fc97 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalAuditClassMapping.java
@@ -157,7 +157,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
public boolean readRevisionByTime(IDBStoreAccessor accessor, InternalCDORevision revision, long timeStamp,
- int referenceChunk)
+ int listChunk)
{
PreparedStatement pstmt = null;
try
@@ -174,7 +174,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
// Read multival tables only if revision exists
if (success)
{
- readLists(accessor, revision, referenceChunk);
+ readLists(accessor, revision, listChunk);
}
return success;
@@ -190,7 +190,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
public boolean readRevisionByVersion(IDBStoreAccessor accessor, InternalCDORevision revision, int version,
- int referenceChunk)
+ int listChunk)
{
PreparedStatement pstmt = null;
try
@@ -206,7 +206,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
// Read multival tables only if revision exists
if (success)
{
- readLists(accessor, revision, referenceChunk);
+ readLists(accessor, revision, listChunk);
}
return success;
@@ -318,7 +318,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
}
}
- public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int referenceChunk)
+ public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
PreparedStatement pstmt = null;
try
@@ -333,7 +333,7 @@ public class HorizontalAuditClassMapping extends AbstractHorizontalClassMapping
// Read multival tables only if revision exists
if (success)
{
- readLists(accessor, revision, referenceChunk);
+ readLists(accessor, revision, listChunk);
}
return success;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
index eaaf72e34a..16880550fc 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/HorizontalNonAuditClassMapping.java
@@ -293,7 +293,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
}
}
- public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int referenceChunk)
+ public boolean readRevision(IDBStoreAccessor accessor, InternalCDORevision revision, int listChunk)
{
PreparedStatement pstmt = null;
try
@@ -308,7 +308,7 @@ public class HorizontalNonAuditClassMapping extends AbstractHorizontalClassMappi
// Read multival tables only if revision exists
if (success)
{
- readLists(accessor, revision, referenceChunk);
+ readLists(accessor, revision, listChunk);
}
return success;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java
index 53f23a28ed..0f4e3fe60d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/mapping/horizontal/NonAuditListTableMapping.java
@@ -1,5 +1,5 @@
/**
- * Copyright (c) 2004 - 2009 Eike Stepper (Berlin, Germany) and others.
+ * 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
@@ -7,7 +7,7 @@
*
* Contributors:
* Eike Stepper - initial API and implementation
- * Stefan Winkler - major refactoring
+ * Stefan Winkler - 271444: [DB] Multiple refactorings https://bugs.eclipse.org/bugs/show_bug.cgi?id=271444
*/
package org.eclipse.emf.cdo.server.internal.db.mapping.horizontal;
@@ -32,6 +32,8 @@ import java.sql.PreparedStatement;
import java.sql.SQLException;
/**
+ * This is a list-to-table mapping optimized for non-audit-mode. It doesn't care about version and has delta support.
+ *
* @author Eike Stepper
* @author Stefan Winkler
* @since 2.0
@@ -39,7 +41,7 @@ import java.sql.SQLException;
public class NonAuditListTableMapping extends AbstractListTableMapping implements IListMapping,
IListMappingDeltaSupport
{
- private static final FieldInfo[] KEY_FIELDS = { new FieldInfo(CDODBSchema.FEATURE_REVISION_ID, DBType.BIGINT) };
+ private static final FieldInfo[] KEY_FIELDS = { new FieldInfo(CDODBSchema.LIST_REVISION_ID, DBType.BIGINT) };
private static final int TEMP_INDEX = -1;
@@ -78,13 +80,13 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
builder.append("DELETE FROM ");
builder.append(getTable().getName());
builder.append(" WHERE ");
- builder.append(CDODBSchema.FEATURE_REVISION_ID);
+ builder.append(CDODBSchema.LIST_REVISION_ID);
builder.append(" = ? ");
sqlClear = builder.toString();
builder.append(" AND ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" = ? ");
sqlDeleteItem = builder.toString();
@@ -94,12 +96,12 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
builder.append("UPDATE ");
builder.append(getTable().getName());
builder.append(" SET ");
- builder.append(CDODBSchema.FEATURE_TARGET);
+ builder.append(CDODBSchema.LIST_VALUE);
builder.append(" = ? ");
builder.append(" WHERE ");
- builder.append(CDODBSchema.FEATURE_REVISION_ID);
+ builder.append(CDODBSchema.LIST_REVISION_ID);
builder.append(" = ? AND ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" = ? ");
sqlUpdateValue = builder.toString();
@@ -115,12 +117,12 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
builder.append("UPDATE ");
builder.append(getTable().getName());
builder.append(" SET ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" = ? ");
builder.append(" WHERE ");
- builder.append(CDODBSchema.FEATURE_REVISION_ID);
+ builder.append(CDODBSchema.LIST_REVISION_ID);
builder.append(" = ? AND ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" = ? ");
sqlUpdateIndex = builder.toString();
@@ -129,18 +131,18 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
builder.append("UPDATE ");
builder.append(getTable().getName());
builder.append(" SET ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" = ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append("-1 WHERE ");
- builder.append(CDODBSchema.FEATURE_REVISION_ID);
+ builder.append(CDODBSchema.LIST_REVISION_ID);
builder.append("= ? AND ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" > ? ");
sqlMoveDown = builder.toString();
builder.append(" AND ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" <= ?");
sqlMoveDownWithLimit = builder.toString();
@@ -149,18 +151,18 @@ public class NonAuditListTableMapping extends AbstractListTableMapping implement
builder.append("UPDATE ");
builder.append(getTable().getName());
builder.append(" SET ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" = ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append("+1 WHERE ");
- builder.append(CDODBSchema.FEATURE_REVISION_ID);
+ builder.append(CDODBSchema.LIST_REVISION_ID);
builder.append("= ? AND ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" >= ? ");
sqlMoveUp = builder.toString();
builder.append(" AND ");
- builder.append(CDODBSchema.FEATURE_IDX);
+ builder.append(CDODBSchema.LIST_IDX);
builder.append(" < ?");
sqlMoveUpWithLimit = builder.toString();

Back to the top