summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-25 04:12:20 (EDT)
committerEike Stepper2007-08-25 04:12:20 (EDT)
commit29258ad6ac66851417729c38f13da26754d328f7 (patch)
treef72bc58141e97b91c9cfba3d64397d1950afe11e
parent7fa6b103d0e2b190363e04c29498b2c3e5fba06c (diff)
downloadcdo-29258ad6ac66851417729c38f13da26754d328f7.zip
cdo-29258ad6ac66851417729c38f13da26754d328f7.tar.gz
cdo-29258ad6ac66851417729c38f13da26754d328f7.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IMappingStrategy.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java52
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/HorizontalMappingStrategy.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java16
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ObjectIDIterator.java115
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/VerticalMappingStrategy.java10
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java18
8 files changed, 218 insertions, 19 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
index 7795915..7483b8c 100644
--- a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/db/IDBStoreAccessor.java
@@ -10,6 +10,7 @@
**************************************************************************/
package org.eclipse.emf.cdo.server.db;
+import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.server.IStoreReader;
import org.eclipse.emf.cdo.server.IStoreWriter;
@@ -24,4 +25,6 @@ public interface IDBStoreAccessor extends IStoreReader, IStoreWriter
public Connection getConnection();
public Statement getStatement();
+
+ public CDOClassRef readClassRef(int classID);
}
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 85386ee..c41a3e7 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
@@ -14,6 +14,7 @@ import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
+import java.util.Iterator;
import java.util.Map;
/**
@@ -39,5 +40,7 @@ public interface IMappingStrategy
public IMapping getMapping(CDOClass cdoClass);
- public CDOClassRef readObjectType(CDOID id);
+ public Iterator<CDOID> readObjectIDs(IDBStoreAccessor storeAccessor, boolean withTypes);
+
+ public CDOClassRef readObjectType(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 b498dda..211302d 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
@@ -45,6 +45,7 @@ import java.sql.Statement;
import java.util.ArrayList;
import java.util.Collection;
import java.util.HashSet;
+import java.util.Iterator;
import java.util.Set;
/**
@@ -301,7 +302,7 @@ public class DBStoreAccessor implements IDBStoreAccessor
}
};
- String where = CDODBSchema.CLASSES_PACKAGE.getName() + " = " + ServerInfo.getDBID(cdoPackage);
+ String where = CDODBSchema.CLASSES_PACKAGE.getName() + "=" + ServerInfo.getDBID(cdoPackage);
DBUtil.select(connection, rowHandler, where, CDODBSchema.CLASSES_ID, CDODBSchema.CLASSES_CLASSIFIER,
CDODBSchema.CLASSES_NAME, CDODBSchema.CLASSES_ABSTRACT);
}
@@ -319,7 +320,7 @@ public class DBStoreAccessor implements IDBStoreAccessor
}
};
- String where = CDODBSchema.SUPERTYPES_TYPE.getName() + " = " + classID;
+ String where = CDODBSchema.SUPERTYPES_TYPE.getName() + "=" + classID;
DBUtil.select(connection, rowHandler, where, CDODBSchema.SUPERTYPES_SUPERTYPE_PACKAGE,
CDODBSchema.SUPERTYPES_SUPERTYPE_CLASSIFIER);
}
@@ -356,12 +357,27 @@ public class DBStoreAccessor implements IDBStoreAccessor
}
};
- String where = CDODBSchema.FEATURES_CLASS.getName() + " = " + classID;
+ String where = CDODBSchema.FEATURES_CLASS.getName() + "=" + classID;
DBUtil.select(connection, rowHandler, where, CDODBSchema.FEATURES_ID, CDODBSchema.FEATURES_FEATURE,
CDODBSchema.FEATURES_NAME, CDODBSchema.FEATURES_TYPE, CDODBSchema.FEATURES_REFERENCE_PACKAGE,
CDODBSchema.FEATURES_REFERENCE_CLASSIFIER, CDODBSchema.FEATURES_MANY, CDODBSchema.FEATURES_CONTAINMENT);
}
+ public String readPackageURI(int packageID)
+ {
+ String where = CDODBSchema.PACKAGES_ID.getName() + "=" + packageID;
+ Object[] uri = DBUtil.select(connection, where, CDODBSchema.PACKAGES_URI);
+ return (String)uri[0];
+ }
+
+ public CDOClassRef readClassRef(int classID)
+ {
+ String where = CDODBSchema.CLASSES_ID.getName() + "=" + classID;
+ Object[] ids = DBUtil.select(connection, where, CDODBSchema.CLASSES_CLASSIFIER, CDODBSchema.CLASSES_PACKAGE);
+ String packageURI = readPackageURI((Integer)ids[1]);
+ return new CDOClassRefImpl(packageURI, (Integer)ids[0]);
+ }
+
public void writeRevision(CDORevisionImpl revision)
{
if (TRACER.isEnabled())
@@ -374,6 +390,26 @@ public class DBStoreAccessor implements IDBStoreAccessor
mapping.writeRevision(this, revision);
}
+ public Iterator<CDOID> readObjectIDs(boolean withTypes)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.trace("Selecting object ids");
+ }
+
+ return store.getMappingStrategy().readObjectIDs(this, withTypes);
+ }
+
+ public CDOClassRef readObjectType(CDOID id)
+ {
+ if (TRACER.isEnabled())
+ {
+ TRACER.format("Selecting object type: {0}", id);
+ }
+
+ return store.getMappingStrategy().readObjectType(this, id);
+ }
+
public CDORevision readRevision(CDOID id)
{
if (TRACER.isEnabled())
@@ -416,16 +452,6 @@ public class DBStoreAccessor implements IDBStoreAccessor
throw new UnsupportedOperationException("Not yet implemented");
}
- public CDOClassRef readObjectType(CDOID id)
- {
- if (TRACER.isEnabled())
- {
- TRACER.format("Selecting object type: {0}", id);
- }
-
- return store.getMappingStrategy().readObjectType(id);
- }
-
/**
* TODO Move this somehow to DBAdapter
*/
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 4edc720..f926664 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
@@ -13,8 +13,12 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
+import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IMapping;
+import java.sql.ResultSet;
+import java.util.Iterator;
+
/**
* @author Eike Stepper
*/
@@ -34,7 +38,19 @@ public class HorizontalMappingStrategy extends MappingStrategy
return false;
}
- public CDOClassRef readObjectType(CDOID id)
+ public Iterator<CDOID> readObjectIDs(IDBStoreAccessor storeAccessor, boolean withTypes)
+ {
+ return new ObjectIDIterator(this, storeAccessor, withTypes)
+ {
+ @Override
+ protected ResultSet getNextResultSet()
+ {
+ return null;
+ }
+ };
+ }
+
+ public CDOClassRef readObjectType(IDBStoreAccessor storeAccessor, CDOID id)
{
return null;
}
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 751a2ca..569e148 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
@@ -11,7 +11,9 @@
package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
+import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.server.db.IDBStore;
+import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IMapping;
import org.eclipse.emf.cdo.server.db.IMappingStrategy;
@@ -37,6 +39,8 @@ public abstract class MappingStrategy implements IMappingStrategy
private Map<Object, IDBTable> referenceTables = new HashMap();
+ private Map<Integer, CDOClassRef> classRefs = new HashMap();
+
public MappingStrategy()
{
}
@@ -121,6 +125,18 @@ public abstract class MappingStrategy implements IMappingStrategy
return mapping;
}
+ public CDOClassRef getClassRef(IDBStoreAccessor storeAccessor, int classID)
+ {
+ CDOClassRef classRef = classRefs.get(classID);
+ if (classRef == null)
+ {
+ classRef = storeAccessor.readClassRef(classID);
+ classRefs.put(classID, classRef);
+ }
+
+ return classRef;
+ }
+
@Override
public String toString()
{
diff --git a/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ObjectIDIterator.java b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ObjectIDIterator.java
new file mode 100644
index 0000000..1e6bf69
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/ObjectIDIterator.java
@@ -0,0 +1,115 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2007 Eike Stepper, Germany.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Eclipse Public License v1.0
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/epl-v10.html
+ *
+ * Contributors:
+ * Eike Stepper - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.cdo.server.internal.db;
+
+import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
+import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
+import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
+
+import org.eclipse.net4j.db.DBException;
+import org.eclipse.net4j.db.DBUtil;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Iterator;
+
+/**
+ * @author Eike Stepper
+ */
+public abstract class ObjectIDIterator implements Iterator<CDOID>
+{
+ private MappingStrategy mappingStrategy;
+
+ private IDBStoreAccessor storeAccessor;
+
+ private boolean withTypes;
+
+ private ResultSet currentResultSet;
+
+ private CDOID nextID;
+
+ public ObjectIDIterator(MappingStrategy mappingStrategy, IDBStoreAccessor storeAccessor, boolean withTypes)
+ {
+ this.mappingStrategy = mappingStrategy;
+ this.storeAccessor = storeAccessor;
+ this.withTypes = withTypes;
+ }
+
+ public MappingStrategy getMappingStrategy()
+ {
+ return mappingStrategy;
+ }
+
+ public IDBStoreAccessor getStoreAccessor()
+ {
+ return storeAccessor;
+ }
+
+ public boolean isWithTypes()
+ {
+ return withTypes;
+ }
+
+ public boolean hasNext()
+ {
+ nextID = null;
+ for (;;)
+ {
+ if (currentResultSet == null)
+ {
+ currentResultSet = getNextResultSet();
+ if (currentResultSet == null)
+ {
+ return false;
+ }
+ }
+
+ try
+ {
+ if (currentResultSet.next())
+ {
+ long id = currentResultSet.getLong(1);
+ if (withTypes)
+ {
+ int classID = currentResultSet.getInt(2);
+ CDOClassRef type = mappingStrategy.getClassRef(storeAccessor, classID);
+ nextID = CDOIDImpl.create(id, type);
+ }
+ else
+ {
+ nextID = CDOIDImpl.create(id);
+ }
+ return true;
+ }
+
+ DBUtil.close(currentResultSet);
+ currentResultSet = null;
+ }
+ catch (SQLException ex)
+ {
+ throw new DBException(ex);
+ }
+ }
+ }
+
+ public CDOID next()
+ {
+ return nextID;
+ }
+
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ protected abstract ResultSet getNextResultSet();
+}
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 600d429..870db73 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
@@ -13,8 +13,11 @@ package org.eclipse.emf.cdo.server.internal.db;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.model.CDOClass;
import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
+import org.eclipse.emf.cdo.server.db.IDBStoreAccessor;
import org.eclipse.emf.cdo.server.db.IMapping;
+import java.util.Iterator;
+
/**
* @author Eike Stepper
*/
@@ -37,7 +40,12 @@ public class VerticalMappingStrategy extends MappingStrategy
return true;
}
- public CDOClassRef readObjectType(CDOID id)
+ public Iterator<CDOID> readObjectIDs(IDBStoreAccessor storeAccessor, boolean withTypes)
+ {
+ return null;
+ }
+
+ public CDOClassRef readObjectType(IDBStoreAccessor storeAccessor, CDOID id)
{
return null;
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java
index f444277..0a1c871 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java
@@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.protocol.model.CDOPackageInfo;
import org.eclipse.emf.cdo.protocol.revision.CDORevision;
import java.util.Collection;
+import java.util.Iterator;
/**
* @see StoreUtil#getReader()
@@ -32,10 +33,23 @@ public interface IStoreReader extends IStoreAccessor
/**
* Demand loads a given package proxy that has been created on startup of the
* repository.
- * <p>
*/
public void readPackage(CDOPackageImpl cdoPackage);
+ /**
+ * Returns an iterator that iterates over all objects in the store and makes
+ * their ids available for processing. This method is supposed to be called
+ * very infrequently, for example during the recovery from a crash.
+ */
+ public Iterator<CDOID> readObjectIDs(boolean withTypes);
+
+ /**
+ * Reads the type of an object from the associated store and returns a class
+ * reference of it. This method is supposed to be called very infrequently if
+ * the {@link IStore#hasEfficientTypeLookup()} returns <code>false</code>.
+ */
+ public CDOClassRef readObjectType(CDOID id);
+
public CDORevision readRevision(CDOID id);
public CDORevision readRevision(CDOID id, long timeStamp);
@@ -43,6 +57,4 @@ public interface IStoreReader extends IStoreAccessor
public CDOID readResourceID(String path);
public String readResourcePath(CDOID id);
-
- public CDOClassRef readObjectType(CDOID id);
}