summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-09-13 06:54:06 (EDT)
committerEike Stepper2007-09-13 06:54:06 (EDT)
commitbcb3b2beb4819c4c571c128ab6c0eb625b4d528a (patch)
treec1fc104b57a5f8b03204802414ff0599f97d2da5
parent9521cc3ca7349320a52e074a94ce0fab3a3c22dc (diff)
downloadcdo-bcb3b2beb4819c4c571c128ab6c0eb625b4d528a.zip
cdo-bcb3b2beb4819c4c571c128ab6c0eb625b4d528a.tar.gz
cdo-bcb3b2beb4819c4c571c128ab6c0eb625b4d528a.tar.bz2
[202833] Horizontal Mapping Strategy
https://bugs.eclipse.org/bugs/show_bug.cgi?id=202833
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java133
-rw-r--r--plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceHandler.java4
4 files changed, 122 insertions, 23 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java
index 413fac1..f3d91fa 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java
@@ -45,7 +45,7 @@ public interface IMappingStrategy
public CDOClassRef readObjectType(IDBStoreAccessor storeAccessor, CDOID id);
- public CDOID readResourceID(String path);
+ public CDOID readResourceID(IDBStoreAccessor storeAccessor, String path);
- public String readResourcePath(CDOID id);
+ public String readResourcePath(IDBStoreAccessor storeAccessor, CDOID id);
}
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 3cb6e62..648dbbb 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
@@ -469,13 +469,13 @@ public class DBStoreAccessor implements IDBStoreAccessor
public CDOID readResourceID(String path)
{
IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
- return mappingStrategy.readResourceID(path);
+ return mappingStrategy.readResourceID(this, path);
}
public String readResourcePath(CDOID id)
{
IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
- return mappingStrategy.readResourcePath(id);
+ return mappingStrategy.readResourcePath(this, id);
}
public CDORevisionImpl verifyRevision(CDORevisionImpl revision)
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
index 191e9a7..4d9b08d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.internal.db;
+import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
@@ -21,15 +22,18 @@ import org.eclipse.emf.cdo.server.db.IClassMapping;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
+import org.eclipse.emf.cdo.server.internal.db.bundle.OM;
import org.eclipse.net4j.db.DBException;
import org.eclipse.net4j.db.DBUtil;
import org.eclipse.net4j.db.IDBField;
import org.eclipse.net4j.db.IDBTable;
+import org.eclipse.net4j.internal.util.om.trace.ContextTracer;
import org.eclipse.net4j.util.io.CloseableIterator;
import java.sql.ResultSet;
import java.sql.SQLException;
+import java.sql.Statement;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
@@ -40,6 +44,8 @@ import java.util.Map;
*/
public abstract class MappingStrategy implements IMappingStrategy
{
+ private static final ContextTracer TRACER = new ContextTracer(OM.DEBUG, MappingStrategy.class);
+
public static final String PROP_MAPPING_PRECEDENCE = "mappingPrecedence";
public static final String PROP_TO_MANY_REFERENCE_MAPPING = "toManyReferenceMapping";
@@ -64,6 +70,12 @@ public abstract class MappingStrategy implements IMappingStrategy
private IAttributeMapping resourcePathMapping;
+ private IDBTable resourceTable;
+
+ private IDBField resourceIDField;
+
+ private IDBField resourcePathField;
+
public MappingStrategy()
{
}
@@ -152,9 +164,7 @@ public abstract class MappingStrategy implements IMappingStrategy
{
if (resourceClassMapping == null)
{
- IPackageManager packageManager = getStore().getRepository().getPackageManager();
- CDOResourceClass resourceClass = packageManager.getCDOResourcePackage().getCDOResourceClass();
- resourceClassMapping = getClassMapping(resourceClass);
+ initResourceInfos();
}
return resourceClassMapping;
@@ -164,16 +174,56 @@ public abstract class MappingStrategy implements IMappingStrategy
{
if (resourcePathMapping == null)
{
- IPackageManager packageManager = getStore().getRepository().getPackageManager();
- CDOPathFeature pathFeature = packageManager.getCDOResourcePackage().getCDOResourceClass().getCDOPathFeature();
-
- IClassMapping resourceMapping = getResourceClassMapping();
- resourcePathMapping = resourceMapping.getAttributeMapping(pathFeature);
+ initResourceInfos();
}
return resourcePathMapping;
}
+ public IDBTable getResourceTable()
+ {
+ if (resourceTable == null)
+ {
+ initResourceInfos();
+ }
+
+ return resourceTable;
+ }
+
+ public IDBField getResourceIDField()
+ {
+ if (resourceIDField == null)
+ {
+ initResourceInfos();
+ }
+
+ return resourceIDField;
+ }
+
+ public IDBField getResourcePathField()
+ {
+ if (resourcePathField == null)
+ {
+ initResourceInfos();
+ }
+
+ return resourcePathField;
+ }
+
+ protected void initResourceInfos()
+ {
+ IPackageManager packageManager = getStore().getRepository().getPackageManager();
+ CDOResourceClass resourceClass = packageManager.getCDOResourcePackage().getCDOResourceClass();
+ CDOPathFeature pathFeature = packageManager.getCDOResourcePackage().getCDOResourceClass().getCDOPathFeature();
+
+ resourceClassMapping = getClassMapping(resourceClass);
+ resourcePathMapping = resourceClassMapping.getAttributeMapping(pathFeature);
+
+ resourceTable = resourceClassMapping.getTable();
+ resourceIDField = resourceTable.getField(CDODBSchema.ATTRIBUTES_ID);
+ resourcePathField = resourcePathMapping.getField();
+ }
+
public CloseableIterator<CDOID> readObjectIDs(final IDBStoreAccessor storeAccessor, final boolean withTypes)
{
List<CDOClass> classes = getClassesWithObjectInfo();
@@ -273,21 +323,68 @@ public abstract class MappingStrategy implements IMappingStrategy
return classRef;
}
- public CDOID readResourceID(String path)
+ public CDOID readResourceID(IDBStoreAccessor storeAccessor, String path)
{
- IClassMapping resourceClassMapping = getResourceClassMapping();
- IAttributeMapping resourcePathMapping = getResourcePathMapping();
-
- IDBTable resourceTable = resourceClassMapping.getTable();
- IDBField idField = resourceTable.getField(CDODBSchema.ATTRIBUTES_ID);
- IDBField pathField = resourcePathMapping.getField();
+ IDBTable resourceTable = getResourceTable();
+ IDBField selectField = getResourceIDField();
+ IDBField whereField = getResourcePathField();
+ return (CDOID)readResourceInfo(storeAccessor, resourceTable, selectField, whereField, path);
+ }
- return null;
+ public String readResourcePath(IDBStoreAccessor storeAccessor, CDOID id)
+ {
+ IDBTable resourceTable = getResourceTable();
+ IDBField selectField = getResourcePathField();
+ IDBField whereField = getResourceIDField();
+ return (String)readResourceInfo(storeAccessor, resourceTable, selectField, whereField, id);
}
- public String readResourcePath(CDOID id)
+ protected Object readResourceInfo(IDBStoreAccessor storeAccessor, IDBTable resourceTable, IDBField selectField,
+ IDBField whereField, Object whereValue)
{
- return null;
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT ");
+ builder.append(selectField.getName());
+ builder.append(" FROM ");
+ builder.append(resourceTable);
+ builder.append(" WHERE ");
+ builder.append(whereField.getName());
+ getStore().getDBAdapter().appendValue(builder, whereField, whereValue);
+
+ String sql = builder.toString();
+ if (TRACER.isEnabled()) TRACER.trace(sql);
+ ResultSet resultSet = null;
+
+ try
+ {
+ Statement statement = storeAccessor.getStatement();
+ statement.setMaxRows(1); // Reset by DBUtil.close(resultSet)
+
+ resultSet = statement.executeQuery(sql);
+ if (!resultSet.next())
+ {
+ return null;
+ }
+
+ if (whereValue instanceof CDOID)
+ {
+ String path = resultSet.getString(1);
+ return path;
+ }
+ else
+ {
+ long id = resultSet.getLong(1);
+ return CDOIDImpl.create(id);
+ }
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(resultSet);
+ }
}
@Override
diff --git a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceHandler.java b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceHandler.java
index 76c4843..fd699fe 100644
--- a/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceHandler.java
+++ b/plugins/org.eclipse.net4j.util/src/org/eclipse/net4j/internal/util/om/trace/RemoteTraceHandler.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.net4j.internal.util.om.trace;
+import org.eclipse.net4j.internal.util.bundle.OM;
import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.om.trace.OMTraceHandler;
import org.eclipse.net4j.util.om.trace.OMTraceHandlerEvent;
@@ -72,6 +73,7 @@ public class RemoteTraceHandler implements OMTraceHandler
}
catch (IOException ex)
{
+ OM.LOG.error(ex);
return ex;
}
}
@@ -136,7 +138,7 @@ public class RemoteTraceHandler implements OMTraceHandler
try
{
InetAddress localMachine = InetAddress.getLocalHost();
- return localMachine.getHostName() + "#" + (++uniqueCounter);
+ return localMachine.getHostName() + "#" + ++uniqueCounter;
}
catch (Exception ex)
{