Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-10-18 05:11:22 -0400
committerEike Stepper2008-10-18 05:11:22 -0400
commitef93168041828aca5f0203d043adfc3c5f736b10 (patch)
treec7eb4d83640c6c54836c9b995a697e48afb1ec20
parent11968dd945be9ae7292a991cb2a13b24a23e1d36 (diff)
downloadcdo-ef93168041828aca5f0203d043adfc3c5f736b10.tar.gz
cdo-ef93168041828aca5f0203d043adfc3c5f736b10.tar.xz
cdo-ef93168041828aca5f0203d043adfc3c5f736b10.zip
[249847] Store resources in a hierarchical structure
https://bugs.eclipse.org/bugs/show_bug.cgi?id=249847
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java25
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java24
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStore.java21
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalClassMapping.java28
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java57
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java247
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootClassMapping.java9
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalClassMapping.java8
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java1
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java78
13 files changed, 234 insertions, 283 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 967db24936..9f562e3d3d 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
@@ -15,6 +15,7 @@ import org.eclipse.emf.cdo.common.model.CDOClass;
import org.eclipse.emf.cdo.common.model.CDOClassRef;
import org.eclipse.emf.cdo.server.IStoreReader.QueryResourcesContext;
+import org.eclipse.net4j.db.IDBAdapter;
import org.eclipse.net4j.util.collection.CloseableIterator;
import java.sql.Connection;
@@ -55,21 +56,6 @@ public interface IMappingStrategy
/**
* @since 2.0
*/
- public IClassMapping getResourceNodeClassMapping();
-
- /**
- * @since 2.0
- */
- public IClassMapping getResourceFolderClassMapping();
-
- /**
- * @since 2.0
- */
- public IClassMapping getResourceClassMapping();
-
- /**
- * @since 2.0
- */
public CDOClassRef getClassRef(IDBStoreReader storeReader, int classID);
/**
@@ -90,7 +76,14 @@ public interface IMappingStrategy
public void queryResources(IDBStoreReader storeReader, QueryResourcesContext context);
/**
+ * @since 2.0
+ */
+ public void createResourceTables(IDBAdapter dbAdapter, Connection connection);
+
+ /**
* Returns the maximum CDOID value.
+ *
+ * @since 2.0
*/
- public long repairAfterCrash(Connection connection);
+ public long repairAfterCrash(IDBAdapter dbAdapter, Connection connection);
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java
index 72118e2e4f..6f3cdd4900 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ClassMapping.java
@@ -467,29 +467,14 @@ public abstract class ClassMapping implements IClassMapping
public void writeRevision(IDBStoreWriter storeWriter, CDORevision revision)
{
- if (revision.getVersion() >= 2 && hasFullRevisionInfo())
+ if (revision.getVersion() > 1 && hasFullRevisionInfo())
{
writeRevisedRow(storeWriter, (InternalCDORevision)revision);
}
- if (revision.isResourceNode())
+ if (revision.isResourceFolder() || revision.isResource())
{
- // TODO Provide better design for store capabilities and repository support
- // Example: Currently a store can not specify that it does not support non-auditing mode!
- if (true || mappingStrategy.getStore().getRepository().isSupportingAudits())
- {
- // If auditing is not supported this is checked by a table index (see constructor)
- CDOFeature resourceFolderFeature = mappingStrategy.getResourceFolderFeatureMapping().getFeature();
- CDOID revisionFolder = (CDOID)revision.getData().get(resourceFolderFeature, 0);
-
- CDOFeature resourceNameFeature = mappingStrategy.getResourceNameFeatureMapping().getFeature();
- String revisionName = (String)revision.getData().get(resourceNameFeature, 0);
-
- if (mappingStrategy.readResourceID(storeWriter, revisionFolder, revisionName, revision.getCreated()) != null)
- {
- throw new IllegalStateException("Duplicate resource: " + revisionName + " (folderID=" + revisionFolder + ")");
- }
- }
+ checkDuplicateResources(storeWriter, revision);
}
if (attributeMappings != null)
@@ -503,6 +488,9 @@ public abstract class ClassMapping implements IClassMapping
}
}
+ protected abstract void checkDuplicateResources(IDBStoreReader storeReader, CDORevision revision)
+ throws IllegalStateException;
+
public void detachObject(IDBStoreWriter storeWriter, CDOID id, long revised)
{
if (hasFullRevisionInfo())
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 f9712ce7be..92dd511985 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
@@ -36,7 +36,6 @@ import javax.sql.DataSource;
import java.sql.Connection;
import java.text.MessageFormat;
-import java.util.HashSet;
import java.util.Set;
/**
@@ -185,7 +184,7 @@ public class DBStore extends LongIDStore implements IDBStore
StoreThreadLocal.setStoreReader(storeWriter);
Connection connection = storeWriter.getConnection();
- long maxObjectID = mappingStrategy.repairAfterCrash(connection);
+ long maxObjectID = mappingStrategy.repairAfterCrash(dbAdapter, connection);
long maxMetaID = DBUtil.selectMaximumLong(connection, CDODBSchema.PACKAGES_RANGE_UB);
OM.LOG.info(MessageFormat.format("Repaired after crash: maxObjectID={0}, maxMetaID={1}", maxObjectID, maxMetaID));
@@ -230,7 +229,8 @@ public class DBStore extends LongIDStore implements IDBStore
DBUtil.insertRow(connection, dbAdapter, CDODBSchema.REPOSITORY, creationTime, 1, startupTime, 0, CRASHED,
CRASHED);
- initResourceTables(connection);
+ IMappingStrategy mappingStrategy = getMappingStrategy();
+ mappingStrategy.createResourceTables(dbAdapter, connection);
}
else
{
@@ -336,21 +336,6 @@ public class DBStore extends LongIDStore implements IDBStore
return new DBSchema(name);
}
- protected void initResourceTables(Connection connection)
- {
- IMappingStrategy mappingStrategy = getMappingStrategy();
- Set<IDBTable> tables = new HashSet<IDBTable>();
-
- tables.addAll(mappingStrategy.getResourceNodeClassMapping().getAffectedTables());
- tables.addAll(mappingStrategy.getResourceFolderClassMapping().getAffectedTables());
- tables.addAll(mappingStrategy.getResourceClassMapping().getAffectedTables());
-
- if (dbAdapter.createTables(tables, connection).size() != tables.size())
- {
- throw new DBException("Resource tables not completely created");
- }
- }
-
protected long getStartupTime()
{
return System.currentTimeMillis();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java
index 0fb7f1e9ad..d77d6f0a74 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreWriter.java
@@ -205,8 +205,7 @@ public class DBStoreWriter extends DBStoreReader implements IDBStoreWriter
}
CDOClass cdoClass = revision.getCDOClass();
- IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
- IClassMapping mapping = mappingStrategy.getClassMapping(cdoClass);
+ IClassMapping mapping = getStore().getMappingStrategy().getClassMapping(cdoClass);
mapping.writeRevision(this, revision);
}
@@ -231,8 +230,7 @@ public class DBStoreWriter extends DBStoreReader implements IDBStoreWriter
}
CDOClass cdoClass = getObjectType(id);
- IMappingStrategy mappingStrategy = getStore().getMappingStrategy();
- IClassMapping mapping = mappingStrategy.getClassMapping(cdoClass);
+ IClassMapping mapping = getStore().getMappingStrategy().getClassMapping(cdoClass);
mapping.detachObject(this, id, revised);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalClassMapping.java
index cc79018bbc..9837bd9ecf 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalClassMapping.java
@@ -12,8 +12,13 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.model.CDOClass;
+import org.eclipse.emf.cdo.common.model.CDOFeature;
+import org.eclipse.emf.cdo.common.model.resource.CDOResourceNodeClass;
import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.server.IPackageManager;
+import org.eclipse.emf.cdo.server.db.IDBStoreReader;
import org.eclipse.emf.cdo.server.db.IDBStoreWriter;
+import org.eclipse.emf.cdo.server.db.IMappingStrategy;
/**
* @author Eike Stepper
@@ -44,6 +49,29 @@ public class HorizontalClassMapping extends ClassMapping
}
@Override
+ protected void checkDuplicateResources(IDBStoreReader storeReader, CDORevision revision) throws IllegalStateException
+ {
+ // If auditing is not supported this is checked by a table index (see constructor)
+ IMappingStrategy mappingStrategy = getMappingStrategy();
+ if (mappingStrategy.getStore().getRepository().isSupportingAudits())
+ {
+ IPackageManager packageManager = mappingStrategy.getStore().getRepository().getPackageManager();
+ CDOResourceNodeClass resourceNodeClass = packageManager.getCDOResourcePackage().getCDOResourceNodeClass();
+
+ CDOFeature resourceFolderFeature = resourceNodeClass.getCDOFolderFeature();
+ CDOID folderID = (CDOID)revision.getData().get(resourceFolderFeature, 0);
+
+ CDOFeature resourceNameFeature = resourceNodeClass.getCDONameFeature();
+ String name = (String)revision.getData().get(resourceNameFeature, 0);
+
+ if (mappingStrategy.readResourceID(storeReader, folderID, name, revision.getCreated()) != null)
+ {
+ throw new IllegalStateException("Duplicate resource or folder: " + name + " in folder " + folderID);
+ }
+ }
+ }
+
+ @Override
protected boolean hasFullRevisionInfo()
{
return true;
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java
index 045632678c..723c2aed3f 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java
@@ -11,9 +11,12 @@
package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.common.id.CDOID;
+import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOClass;
import org.eclipse.emf.cdo.common.model.CDOClassRef;
import org.eclipse.emf.cdo.common.model.CDOPackage;
+import org.eclipse.emf.cdo.common.model.resource.CDOResourceNodeClass;
+import org.eclipse.emf.cdo.common.model.resource.CDOResourcePackage;
import org.eclipse.emf.cdo.server.IPackageManager;
import org.eclipse.emf.cdo.server.db.IClassMapping;
import org.eclipse.emf.cdo.server.db.IDBStore;
@@ -23,6 +26,7 @@ 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.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
import org.eclipse.net4j.util.om.trace.ContextTracer;
@@ -82,6 +86,7 @@ public class HorizontalMappingStrategy extends MappingStrategy
{
TRACER.trace(sql);
}
+
ResultSet resultSet = null;
try
@@ -150,6 +155,58 @@ public class HorizontalMappingStrategy extends MappingStrategy
}
@Override
+ protected String[] getResourceQueries(CDOID folderID, String name, boolean exactMatch)
+ {
+ CDOResourcePackage resourcePackage = getStore().getRepository().getPackageManager().getCDOResourcePackage();
+ String[] queries = new String[2];
+
+ IClassMapping resourceFolderMapping = getClassMapping(resourcePackage.getCDOResourceFolderClass());
+ queries[0] = getResourceQuery(folderID, name, exactMatch, resourceFolderMapping);
+
+ IClassMapping resourceMapping = getClassMapping(resourcePackage.getCDOResourceClass());
+ queries[1] = getResourceQuery(folderID, name, exactMatch, resourceMapping);
+
+ return queries;
+ }
+
+ protected String getResourceQuery(CDOID folderID, String name, boolean exactMatch, IClassMapping classMapping)
+ {
+ CDOResourcePackage resourcePackage = getStore().getRepository().getPackageManager().getCDOResourcePackage();
+ CDOResourceNodeClass resourceNodeClass = resourcePackage.getCDOResourceNodeClass();
+
+ IDBTable table = classMapping.getTable();
+ IDBField folderField = classMapping.getAttributeMapping(resourceNodeClass.getCDOFolderFeature()).getField();
+ IDBField nameField = classMapping.getAttributeMapping(resourceNodeClass.getCDONameFeature()).getField();
+
+ StringBuilder builder = new StringBuilder();
+ builder.append("SELECT ");
+ builder.append(CDODBSchema.ATTRIBUTES_ID);
+ builder.append(" FROM ");
+ builder.append(table);
+ builder.append(" WHERE ");
+ builder.append(folderField);
+ builder.append("=");
+ builder.append(CDOIDUtil.getLong(folderID));
+ builder.append(" AND ");
+ builder.append(nameField);
+ if (exactMatch)
+ {
+ builder.append("=\'");
+ builder.append(name);
+ builder.append("\'");
+ }
+ else
+ {
+ builder.append(" LIKE \'");
+ builder.append(name);
+ builder.append("%\'");
+ }
+
+ String sql = builder.toString();
+ return sql;
+ }
+
+ @Override
protected void doDeactivate() throws Exception
{
LifecycleUtil.deactivate(objectTypeCache);
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 2dd1174577..2adb419d0b 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
@@ -16,26 +16,20 @@ import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOClass;
import org.eclipse.emf.cdo.common.model.CDOClassRef;
import org.eclipse.emf.cdo.common.model.CDOPackage;
-import org.eclipse.emf.cdo.common.model.resource.CDOFolderFeature;
-import org.eclipse.emf.cdo.common.model.resource.CDONameFeature;
-import org.eclipse.emf.cdo.common.model.resource.CDOResourceClass;
-import org.eclipse.emf.cdo.common.model.resource.CDOResourceFolderClass;
-import org.eclipse.emf.cdo.common.model.resource.CDOResourceNodeClass;
import org.eclipse.emf.cdo.common.model.resource.CDOResourcePackage;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.StoreUtil;
import org.eclipse.emf.cdo.server.IStoreReader.QueryResourcesContext;
import org.eclipse.emf.cdo.server.IStoreReader.QueryResourcesContext.ExactMatch;
-import org.eclipse.emf.cdo.server.db.IAttributeMapping;
import org.eclipse.emf.cdo.server.db.IClassMapping;
import org.eclipse.emf.cdo.server.db.IDBStore;
import org.eclipse.emf.cdo.server.db.IDBStoreReader;
-import org.eclipse.emf.cdo.server.db.IFeatureMapping;
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.IDBAdapter;
import org.eclipse.net4j.db.ddl.IDBField;
import org.eclipse.net4j.db.ddl.IDBTable;
import org.eclipse.net4j.util.collection.CloseableIterator;
@@ -46,9 +40,11 @@ import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.HashMap;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
+import java.util.Set;
/**
* @author Eike Stepper
@@ -65,24 +61,6 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
private Map<Integer, CDOClassRef> classRefs = new HashMap<Integer, CDOClassRef>();
- private IClassMapping resourceNodeClassMapping;
-
- private IClassMapping resourceFolderClassMapping;
-
- private IClassMapping resourceClassMapping;
-
- private IAttributeMapping resourceFolderFeatureMapping;
-
- private IAttributeMapping resourceNameFeatureMapping;
-
- private IDBTable resourceNodeTable;
-
- private IDBField resourceIDField;
-
- private IDBField resourceFolderField;
-
- private IDBField resourceNameField;
-
public MappingStrategy()
{
}
@@ -190,124 +168,6 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
return mapping;
}
- public IClassMapping getResourceNodeClassMapping()
- {
- if (resourceNodeClassMapping == null)
- {
- initResourceInfos();
- }
-
- return resourceNodeClassMapping;
- }
-
- public IClassMapping getResourceFolderClassMapping()
- {
- if (resourceFolderClassMapping == null)
- {
- initResourceInfos();
- }
-
- return resourceFolderClassMapping;
- }
-
- public IClassMapping getResourceClassMapping()
- {
- if (resourceClassMapping == null)
- {
- initResourceInfos();
- }
-
- return resourceClassMapping;
- }
-
- public IFeatureMapping getResourceFolderFeatureMapping()
- {
- if (resourceFolderFeatureMapping == null)
- {
- initResourceInfos();
- }
-
- return resourceFolderFeatureMapping;
- }
-
- public IAttributeMapping getResourceNameFeatureMapping()
- {
- if (resourceNameFeatureMapping == null)
- {
- initResourceInfos();
- }
-
- return resourceNameFeatureMapping;
- }
-
- public IDBTable getResourceNodeTable()
- {
- if (resourceNodeTable == null)
- {
- initResourceInfos();
- }
-
- return resourceNodeTable;
- }
-
- public IDBField getResourceIDField()
- {
- if (resourceIDField == null)
- {
- initResourceInfos();
- }
-
- return resourceIDField;
- }
-
- public IDBField getResourceFolderField()
- {
- if (resourceFolderField == null)
- {
- initResourceInfos();
- }
-
- return resourceFolderField;
- }
-
- public IDBField getResourceNameField()
- {
- if (resourceNameField == null)
- {
- initResourceInfos();
- }
-
- return resourceNameField;
- }
-
- protected void initResourceInfos()
- {
- // Package
- CDOResourcePackage resourcePackage = getStore().getRepository().getPackageManager().getCDOResourcePackage();
-
- // Classes
- CDOResourceNodeClass resourceNodeClass = resourcePackage.getCDOResourceNodeClass();
- CDOResourceFolderClass resourceFolderClass = resourcePackage.getCDOResourceFolderClass();
- CDOResourceClass resourceClass = resourcePackage.getCDOResourceClass();
-
- // Features
- CDOFolderFeature folderFeature = resourceNodeClass.getCDOFolderFeature();
- CDONameFeature nameFeature = resourceNodeClass.getCDONameFeature();
-
- // Mappings
- resourceNodeClassMapping = getClassMapping(resourceNodeClass);
- resourceFolderClassMapping = getClassMapping(resourceFolderClass);
- resourceClassMapping = getClassMapping(resourceClass);
- resourceFolderFeatureMapping = resourceNodeClassMapping.getAttributeMapping(folderFeature);
- resourceNameFeatureMapping = resourceNodeClassMapping.getAttributeMapping(nameFeature);
-
- // Schema
- resourceNodeTable = resourceNodeClassMapping.getTable();
- resourceIDField = resourceNodeTable.getField(CDODBSchema.ATTRIBUTES_ID);
- resourceFolderField = resourceFolderFeatureMapping.getField();
- resourceNameField = resourceNameFeatureMapping.getField();
- }
-
public String getTableName(CDOPackage cdoPackage)
{
if (isQualifiedNames())
@@ -404,76 +264,71 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
public void queryResources(IDBStoreReader storeReader, QueryResourcesContext context)
{
- IDBTable resourceTable = getResourceNodeTable();
- IDBField folderField = getResourceFolderField();
- IDBField nameField = getResourceNameField();
-
CDOID folderID = context.getFolderID();
String name = context.getName();
boolean exactMatch = context.exactMatch();
-
- StringBuilder builder = new StringBuilder();
- builder.append("SELECT ");
- builder.append(CDODBSchema.ATTRIBUTES_ID);
- builder.append(" FROM ");
- builder.append(resourceTable);
- builder.append(" WHERE ");
- builder.append(folderField);
- builder.append("=");
- builder.append(CDOIDUtil.getLong(folderID));
- builder.append(" AND ");
- builder.append(nameField);
- if (exactMatch)
- {
- builder.append("=\'");
- builder.append(name);
- builder.append("\'");
- }
- else
- {
- builder.append(" LIKE \'");
- builder.append(name);
- builder.append("%\'");
- }
-
String where = createWhereClause(context.getTimeStamp());
- builder.append(" AND (");
- builder.append(where);
- builder.append(")");
- String sql = builder.toString();
- if (TRACER.isEnabled())
+ String[] queries = getResourceQueries(folderID, name, exactMatch);
+ for (String query : queries)
{
- TRACER.trace(sql);
- }
+ StringBuilder builder = new StringBuilder();
+ builder.append(query);
+ builder.append(" AND (");
+ builder.append(where);
+ builder.append(")");
+
+ String sql = builder.toString();
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace(sql);
+ }
- ResultSet resultSet = null;
+ ResultSet resultSet = null;
- try
- {
- resultSet = storeReader.getStatement().executeQuery(sql);
- while (resultSet.next())
+ try
{
- long longID = resultSet.getLong(1);
- CDOID id = CDOIDUtil.createLong(longID);
- if (!context.addResource(id))
+ resultSet = storeReader.getStatement().executeQuery(sql);
+ while (resultSet.next())
{
- // No more results allowed
- break;
+ long longID = resultSet.getLong(1);
+ CDOID id = CDOIDUtil.createLong(longID);
+ if (!context.addResource(id))
+ {
+ // No more results allowed
+ return;
+ }
}
}
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ finally
+ {
+ DBUtil.close(resultSet);
+ }
}
- catch (SQLException ex)
- {
- throw new DBException(ex);
- }
- finally
+ }
+
+ protected abstract String[] getResourceQueries(CDOID folderID, String name, boolean exactMatch);
+
+ public void createResourceTables(IDBAdapter dbAdapter, Connection connection)
+ {
+ Set<IDBTable> tables = new HashSet<IDBTable>();
+ CDOResourcePackage resourcePackage = getStore().getRepository().getPackageManager().getCDOResourcePackage();
+
+ tables.addAll(getClassMapping(resourcePackage.getCDOResourceNodeClass()).getAffectedTables());
+ tables.addAll(getClassMapping(resourcePackage.getCDOResourceFolderClass()).getAffectedTables());
+ tables.addAll(getClassMapping(resourcePackage.getCDOResourceClass()).getAffectedTables());
+
+ if (dbAdapter.createTables(tables, connection).size() != tables.size())
{
- DBUtil.close(resultSet);
+ throw new DBException("Resource tables not completely created");
}
}
- public long repairAfterCrash(Connection connection)
+ public long repairAfterCrash(IDBAdapter dbAdapter, Connection connection)
{
long maxCDOID = 0L;
for (CDOClass idClass : getClassesWithObjectInfo())
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootClassMapping.java
index ca00ed9715..c783651d3d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/RootClassMapping.java
@@ -11,6 +11,8 @@
package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.common.model.core.CDOObjectClass;
+import org.eclipse.emf.cdo.common.revision.CDORevision;
+import org.eclipse.emf.cdo.server.db.IDBStoreReader;
/**
* @author Eike Stepper
@@ -35,6 +37,13 @@ public class RootClassMapping extends ClassMapping
return true;
}
+ @Override
+ protected void checkDuplicateResources(IDBStoreReader storeReader, CDORevision revision) throws IllegalStateException
+ {
+ // TODO: implement RootClassMapping.checkDuplicateResources(storeReader, revision)
+ throw new UnsupportedOperationException();
+ }
+
private static CDOObjectClass getRootClass(VerticalMappingStrategy mappingStrategy)
{
return mappingStrategy.getStore().getRepository().getPackageManager().getCDOCorePackage().getCDOObjectClass();
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalClassMapping.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalClassMapping.java
index d1749026c9..9a07b556d6 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalClassMapping.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalClassMapping.java
@@ -13,6 +13,7 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.common.model.CDOClass;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.db.IClassMapping;
+import org.eclipse.emf.cdo.server.db.IDBStoreReader;
import org.eclipse.emf.cdo.server.db.IDBStoreWriter;
import java.util.ArrayList;
@@ -72,4 +73,11 @@ public class VerticalClassMapping extends ClassMapping
}
}
}
+
+ @Override
+ protected void checkDuplicateResources(IDBStoreReader storeReader, CDORevision revision) throws IllegalStateException
+ {
+ // TODO: implement VerticalClassMapping.checkDuplicateResources(storeReader, revision)
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java
index cba25e8dfb..040594dc1d 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java
@@ -62,4 +62,11 @@ public class VerticalMappingStrategy extends MappingStrategy
{
return Collections.singletonList(rootClassMapping.getCDOClass());
}
+
+ @Override
+ protected String[] getResourceQueries(CDOID folderID, String name, boolean exactMatch)
+ {
+ // TODO: implement VerticalMappingStrategy.getResourceQueries(folderID, name, exactMatch)
+ throw new UnsupportedOperationException();
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java
index 747d43c9bf..eabb0662ac 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java
@@ -55,6 +55,7 @@ public class MEMStore extends LongIDStore implements IMEMStore
{
super(TYPE, set(ChangeFormat.REVISION, ChangeFormat.DELTA), set(RevisionTemporality.NONE,
RevisionTemporality.AUDITING), set(RevisionParallelism.NONE));
+ setRevisionTemporality(RevisionTemporality.AUDITING);
this.listLimit = listLimit;
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
index dfe11e7d5e..b680fca943 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java
@@ -518,12 +518,16 @@ public class Repository extends Container<IRepositoryElement> implements IReposi
{
String value = getProperties().get(Props.SUPPORTING_AUDITS);
- supportingAudits = value == null ? false : Boolean.valueOf(value);
if (value != null)
{
+ supportingAudits = Boolean.valueOf(value);
store.setRevisionTemporality(supportingAudits ? IStore.RevisionTemporality.AUDITING
: IStore.RevisionTemporality.NONE);
}
+ else
+ {
+ supportingAudits = store.getRevisionTemporality() == IStore.RevisionTemporality.AUDITING;
+ }
}
{
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java
index 0a7f5339af..841ad9aff4 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java
@@ -49,37 +49,37 @@ public class ResourceTest extends AbstractCDOTest
{
public void testAttachDetachResourceDepth1_Delete() throws Exception
{
- testAttachDetachResourceDepth1(1, true, 0);
+ attachDetachResourceDepth1(1, true, 0);
}
public void testAttachDetachResourceDepth1_Remove() throws Exception
{
- testAttachDetachResourceDepth1(1, false, 0);
+ attachDetachResourceDepth1(1, false, 0);
}
public void testAttachDetachResourceDepth2_Delete() throws Exception
{
- testAttachDetachResourceDepth1(2, true, 1);
+ attachDetachResourceDepth1(2, true, 1);
}
public void testAttachDetachResourceDepth2_Remove() throws Exception
{
- testAttachDetachResourceDepth1(2, false, 1);
+ attachDetachResourceDepth1(2, false, 1);
}
public void testAttachDetachResourceDepth3_Delete() throws Exception
{
- testAttachDetachResourceDepth1(3, true, 2);
+ attachDetachResourceDepth1(3, true, 2);
}
public void testAttachDetachResourceDepth3_Remove() throws Exception
{
- testAttachDetachResourceDepth1(3, false, 2);
+ attachDetachResourceDepth1(3, false, 2);
}
public void testAttachDetachResourceDepth3_Remove_Tree() throws Exception
{
- testAttachDetachResourceDepth1(3, false, 1);
+ attachDetachResourceDepth1(3, false, 1);
}
/**
@@ -90,7 +90,7 @@ public class ResourceTest extends AbstractCDOTest
* deptToRemove = /0/1/2/...<br>
* It will remove it from parent folder (depthtoRemove - 1);
*/
- public void testAttachDetachResourceDepth1(int depth, boolean callDelete, int depthtoRemove) throws Exception
+ private void attachDetachResourceDepth1(int depth, boolean callDelete, int depthtoRemove) throws Exception
{
CDOSession session = openModel1Session();
ResourceSet resourceSet = new ResourceSetImpl();
@@ -270,6 +270,24 @@ public class ResourceTest extends AbstractCDOTest
assertEquals(transaction.getResourceSet(), resource.getResourceSet());
}
+ public void testCreateResource_WithDeepPath() throws Exception
+ {
+ {
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+ transaction.createResource("/org/eclipse/net4j/core");
+ transaction.commit();
+ session.close();
+ }
+
+ CDOSession session = openModel1Session();
+ CDOTransaction transaction = session.openTransaction();
+ CDOResource resource = transaction.getResource("/org/eclipse/net4j/core");
+ assertEquals(CDOURIUtil.createResourceURI(session, "/org/eclipse/net4j/core"), resource.getURI());
+ assertEquals(transaction.getResourceSet(), resource.getResourceSet());
+ session.close();
+ }
+
public void testRemoveResourceWithCloseView() throws Exception
{
{
@@ -396,60 +414,47 @@ public class ResourceTest extends AbstractCDOTest
session.close();
}
- private String createPath(String namePrefix, int depth, String name)
- {
- String path = "";
- for (int i = 0; i < depth; i++)
- {
- String localName = namePrefix + String.valueOf(i + 1);
- path += "/" + localName;
- }
-
- path += "/" + name;
- return path;
- }
-
public void testChangePathFromDepth0ToDepth0() throws Exception
{
- testChangePath(0, 0);
+ changePath(0, 0);
}
public void testChangePathFromDepth0ToDepth1() throws Exception
{
- testChangePath(0, 1);
+ changePath(0, 1);
}
public void testChangePathFromDepth0ToDepth2() throws Exception
{
- testChangePath(0, 2);
+ changePath(0, 2);
}
public void testChangePathFromDepth0ToDepth3() throws Exception
{
- testChangePath(0, 3);
+ changePath(0, 3);
}
public void testChangePathFromDepth3ToDepth3() throws Exception
{
- testChangePath(3, 3);
+ changePath(3, 3);
}
public void testChangePathFromDepth3ToDepth2() throws Exception
{
- testChangePath(3, 2);
+ changePath(3, 2);
}
public void testChangePathFromDepth3ToDepth1() throws Exception
{
- testChangePath(3, 1);
+ changePath(3, 1);
}
public void testChangePathFromDepth3ToDepth0() throws Exception
{
- testChangePath(3, 0);
+ changePath(3, 0);
}
- public void testChangePath(int depthFrom, int depthTo) throws Exception
+ private void changePath(int depthFrom, int depthTo) throws Exception
{
String prefixA = "testA";
String prefixB = "testB";
@@ -509,6 +514,19 @@ public class ResourceTest extends AbstractCDOTest
assertNotNull(resource);
}
+ private String createPath(String namePrefix, int depth, String name)
+ {
+ String path = "";
+ for (int i = 0; i < depth; i++)
+ {
+ String localName = namePrefix + String.valueOf(i + 1);
+ path += "/" + localName;
+ }
+
+ path += "/" + name;
+ return path;
+ }
+
public void testChangePath() throws Exception
{
long commitTime1;

Back to the top