summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2007-08-25 12:54:38 (EDT)
committerEike Stepper2007-08-25 12:54:38 (EDT)
commitd66c3d23b46a43d7ba06d26a57019ebc6c2f510d (patch)
tree3cf0e9654a2f40b1e84c20dc0c71e4a6bd4a6a56
parent283c4e2688d255b4be62168e785555fab71c022f (diff)
downloadcdo-d66c3d23b46a43d7ba06d26a57019ebc6c2f510d.zip
cdo-d66c3d23b46a43d7ba06d26a57019ebc6c2f510d.tar.gz
cdo-d66c3d23b46a43d7ba06d26a57019ebc6c2f510d.tar.bz2
*** empty log message ***
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/DBStoreAccessor.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ObjectTypeMap.java62
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Repository.java67
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RevisionManager.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TypeManager.java287
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepository.java7
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ITypeManager.java27
8 files changed, 333 insertions, 127 deletions
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 fec39e6..c0f34f4 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
@@ -479,7 +479,7 @@ public class DBStoreAccessor implements IDBStoreAccessor
{
IRepository repository = store.getRepository();
IPackageManager packageManager = repository.getPackageManager();
- CDOClassRef type = repository.getObjectType(this, id);
+ CDOClassRef type = repository.getTypeManager().getObjectType(this, id);
return (CDOClassImpl)type.resolve(packageManager);
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ObjectTypeMap.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ObjectTypeMap.java
deleted file mode 100644
index 34f5424..0000000
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ObjectTypeMap.java
+++ /dev/null
@@ -1,62 +0,0 @@
-package org.eclipse.emf.cdo.internal.server;
-
-import org.eclipse.net4j.util.io.ExtendedIOUtil;
-import org.eclipse.net4j.util.io.SortedFileMap;
-
-import java.io.DataInput;
-import java.io.DataOutput;
-import java.io.File;
-import java.io.IOException;
-
-/**
- * @author Eike Stepper
- */
-public final class ObjectTypeMap extends SortedFileMap<Integer, String>
-{
- public ObjectTypeMap(File file)
- {
- super(file, "rw");
- }
-
- @Override
- public int getKeySize()
- {
- return 4;
- }
-
- @Override
- protected Integer readKey(DataInput in) throws IOException
- {
- return in.readInt();
- }
-
- @Override
- protected void writeKey(DataOutput out, Integer key) throws IOException
- {
- out.writeInt(key);
- }
-
- @Override
- public int getValueSize()
- {
- return 20;
- }
-
- @Override
- protected String readValue(DataInput in) throws IOException
- {
- return ExtendedIOUtil.readString(in);
- }
-
- @Override
- protected void writeValue(DataOutput out, String value) throws IOException
- {
- byte[] bytes = value.getBytes();
- if (bytes.length + 4 > getValueSize())
- {
- throw new IllegalArgumentException("Value size of " + getValueSize() + " exceeded: " + value);
- }
-
- ExtendedIOUtil.writeByteArray(out, bytes);
- }
-}
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 e03d0c1..dd904ca 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
@@ -12,26 +12,17 @@ package org.eclipse.emf.cdo.internal.server;
import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
import org.eclipse.emf.cdo.internal.protocol.CDOIDRangeImpl;
-import org.eclipse.emf.cdo.internal.protocol.model.CDOClassRefImpl;
-import org.eclipse.emf.cdo.internal.server.bundle.OM;
import org.eclipse.emf.cdo.protocol.CDOID;
import org.eclipse.emf.cdo.protocol.CDOIDRange;
-import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStore;
-import org.eclipse.emf.cdo.server.IStoreReader;
import org.eclipse.net4j.internal.util.container.Container;
-import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.net4j.util.StringUtil;
-import org.eclipse.net4j.util.io.IOUtil;
import org.eclipse.net4j.util.lifecycle.LifecycleUtil;
-import java.io.File;
import java.text.MessageFormat;
import java.util.UUID;
-import java.util.concurrent.ConcurrentHashMap;
-import java.util.concurrent.ConcurrentMap;
/**
* @author Eike Stepper
@@ -48,6 +39,8 @@ public class Repository extends Container implements IRepository
private String uuid;
+ private TypeManager typeManager = new TypeManager(this);
+
private PackageManager packageManager = new PackageManager(this);
private SessionManager sessionManager = new SessionManager(this);
@@ -62,12 +55,6 @@ public class Repository extends Container implements IRepository
private long nextMetaIDValue = INITIAL_META_ID_VALUE;
- private ConcurrentMap<CDOID, CDOClassRef> objectTypes = new ConcurrentHashMap();
-
- private ObjectTypeMap objectTypeMap;
-
- private ObjectTypeMap metaObjectTypeMap;
-
public Repository(String name, IStore store)
{
if (StringUtil.isEmpty(name))
@@ -84,7 +71,7 @@ public class Repository extends Container implements IRepository
this.store = store;
uuid = UUID.randomUUID().toString();
- elements = new Object[] { packageManager, sessionManager, resourceManager, revisionManager, store };
+ elements = new Object[] { packageManager, sessionManager, resourceManager, revisionManager, typeManager, store };
}
public String getName()
@@ -102,6 +89,11 @@ public class Repository extends Container implements IRepository
return uuid;
}
+ public TypeManager getTypeManager()
+ {
+ return typeManager;
+ }
+
public PackageManager getPackageManager()
{
return packageManager;
@@ -149,54 +141,19 @@ public class Repository extends Container implements IRepository
return id;
}
- public CDOClassRef getObjectType(IStoreReader storeReader, CDOID id)
- {
- CDOClassRef type = objectTypes.get(id);
- if (type == null)
- {
- type = storeReader.readObjectType(id);
- if (type == null)
- {
- throw new ImplementationError("type == null");
- }
-
- objectTypes.put(id, type);
- }
-
- return type;
- }
-
- public void registerObjectType(CDOID id, CDOClassRefImpl type)
- {
- objectTypes.putIfAbsent(id, type);
- }
-
@Override
public String toString()
{
return MessageFormat.format("Repository[{0}, {1}]", name, uuid);
}
- protected void initTypeMaps()
- {
- if (!store.hasEfficientTypeLookup())
- {
- File stateFolder = new File(OM.BUNDLE.getStateLocation());
- File repositoryFolder = new File(stateFolder, uuid);
- IOUtil.mkdirs(repositoryFolder);
-
- objectTypeMap = new ObjectTypeMap(new File(repositoryFolder, "object.types"));
- metaObjectTypeMap = new ObjectTypeMap(new File(repositoryFolder, "metaobject.types"));
- }
- }
-
@Override
protected void doActivate() throws Exception
{
super.doActivate();
LifecycleUtil.activate(store);
- initTypeMaps();
-
+ typeManager.setPersistent(!store.hasEfficientTypeLookup());
+ typeManager.activate();
packageManager.activate();
sessionManager.activate();
resourceManager.activate();
@@ -210,9 +167,7 @@ public class Repository extends Container implements IRepository
resourceManager.deactivate();
sessionManager.deactivate();
packageManager.deactivate();
-
- IOUtil.close(metaObjectTypeMap);
- IOUtil.close(objectTypeMap);
+ typeManager.deactivate();
LifecycleUtil.deactivate(store);
super.doDeactivate();
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RevisionManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RevisionManager.java
index e5f1013..7a71396 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RevisionManager.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/RevisionManager.java
@@ -51,7 +51,7 @@ public class RevisionManager extends CDORevisionResolverImpl implements IRevisio
{
IStoreReader storeReader = StoreUtil.getReader();
CDORevisionImpl revision = (CDORevisionImpl)storeReader.readRevision(id);
- repository.registerObjectType(revision.getID(), revision.getCDOClass().createClassRef());
+ repository.getTypeManager().registerObjectType(revision.getID(), revision.getCDOClass().createClassRef());
return revision;
}
@@ -60,7 +60,7 @@ public class RevisionManager extends CDORevisionResolverImpl implements IRevisio
{
IStoreReader storeReader = StoreUtil.getReader();
CDORevisionImpl revision = (CDORevisionImpl)storeReader.readRevision(id, timeStamp);
- repository.registerObjectType(revision.getID(), revision.getCDOClass().createClassRef());
+ repository.getTypeManager().registerObjectType(revision.getID(), revision.getCDOClass().createClassRef());
return revision;
}
@@ -83,7 +83,7 @@ public class RevisionManager extends CDORevisionResolverImpl implements IRevisio
public void phase2(IStoreWriter storeWriter)
{
- repository.registerObjectType(revision.getID(), revision.getCDOClass().createClassRef());
+ repository.getTypeManager().registerObjectType(revision.getID(), revision.getCDOClass().createClassRef());
addRevision(revision);
if (revision.isResource())
{
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java
index eeebbcb..5694f7f 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Session.java
@@ -176,7 +176,7 @@ public class Session extends Container<IView> implements ISession, CDOIDProvider
knownObjects.add(id);
Repository repository = sessionManager.getRepository();
- CDOClassRef type = repository.getObjectType(StoreUtil.getReader(), id);
+ CDOClassRef type = repository.getTypeManager().getObjectType(StoreUtil.getReader(), id);
return CDOIDImpl.create(id.getValue(), type);
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TypeManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TypeManager.java
new file mode 100644
index 0000000..5b20c82
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/TypeManager.java
@@ -0,0 +1,287 @@
+/***************************************************************************
+ * 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.internal.server;
+
+import org.eclipse.emf.cdo.internal.protocol.CDOIDImpl;
+import org.eclipse.emf.cdo.internal.protocol.model.CDOClassRefImpl;
+import org.eclipse.emf.cdo.internal.server.bundle.OM;
+import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
+import org.eclipse.emf.cdo.server.IStoreReader;
+import org.eclipse.emf.cdo.server.ITypeManager;
+
+import org.eclipse.net4j.internal.util.lifecycle.Lifecycle;
+import org.eclipse.net4j.util.ImplementationError;
+import org.eclipse.net4j.util.io.CachedFileMap;
+import org.eclipse.net4j.util.io.ExtendedDataInput;
+import org.eclipse.net4j.util.io.ExtendedDataOutput;
+import org.eclipse.net4j.util.io.ExtendedIOUtil;
+import org.eclipse.net4j.util.io.IOUtil;
+import org.eclipse.net4j.util.io.SortedFileMap;
+
+import java.io.File;
+import java.io.IOException;
+import java.util.concurrent.ConcurrentHashMap;
+import java.util.concurrent.ConcurrentMap;
+
+/**
+ * @author Eike Stepper
+ */
+public class TypeManager extends Lifecycle implements ITypeManager
+{
+ private Repository repository;
+
+ private boolean persistent;
+
+ private ConcurrentMap<CDOID, CDOClassRef> objectTypes = new ConcurrentHashMap();
+
+ private PackageURIMap packageURIMap;
+
+ private ObjectTypeMap objectTypeMap;
+
+ private ObjectTypeMap metaObjectTypeMap;
+
+ public TypeManager(Repository repository)
+ {
+ this.repository = repository;
+ }
+
+ public Repository getRepository()
+ {
+ return repository;
+ }
+
+ public boolean isPersistent()
+ {
+ return persistent;
+ }
+
+ public void setPersistent(boolean persistent)
+ {
+ this.persistent = persistent;
+ }
+
+ public CDOClassRef getObjectType(IStoreReader storeReader, CDOID id)
+ {
+ CDOClassRef type = objectTypes.get(id);
+ if (type == null)
+ {
+ type = loadTypeFromMap(id);
+ if (type == null && storeReader != null)
+ {
+ type = storeReader.readObjectType(id);
+ }
+
+ if (type == null)
+ {
+ throw new ImplementationError("type == null");
+ }
+
+ objectTypes.put(id, type);
+ }
+
+ return type;
+ }
+
+ public void registerObjectType(CDOID id, CDOClassRefImpl type)
+ {
+ objectTypes.putIfAbsent(id, type);
+ }
+
+ private CDOClassRef loadTypeFromMap(CDOID id)
+ {
+ TypeEntry entry = null;
+ if (id.isMeta())
+ {
+ if (objectTypeMap != null)
+ {
+ entry = objectTypeMap.get(id);
+ }
+ }
+ else
+ {
+ if (metaObjectTypeMap != null)
+ {
+ entry = metaObjectTypeMap.get(id);
+ }
+ }
+
+ if (entry == null)
+ {
+ return null;
+ }
+
+ String packageURI = packageURIMap.get(entry.getPackageID());
+ return new CDOClassRefImpl(packageURI, entry.getClassifierID());
+ }
+
+ @Override
+ protected void doActivate() throws Exception
+ {
+ super.doActivate();
+ if (persistent)
+ {
+ File stateFolder = new File(OM.BUNDLE.getStateLocation());
+ File repositoryFolder = new File(stateFolder, repository.getUUID());
+ IOUtil.mkdirs(repositoryFolder);
+
+ packageURIMap = new PackageURIMap(new File(repositoryFolder, "package.uris"));
+ objectTypeMap = new ObjectTypeMap(new File(repositoryFolder, "object.types"));
+ metaObjectTypeMap = new ObjectTypeMap(new File(repositoryFolder, "metaobject.types"));
+ }
+ }
+
+ @Override
+ protected void doDeactivate() throws Exception
+ {
+ super.doDeactivate();
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class TypeEntry
+ {
+ public static final int SIZE = 8;
+
+ private int classifierID;
+
+ private int packageID;
+
+ public TypeEntry(int classifierID, int packageID)
+ {
+ this.classifierID = classifierID;
+ this.packageID = packageID;
+ }
+
+ public TypeEntry(ExtendedDataInput in) throws IOException
+ {
+ classifierID = in.readInt();
+ packageID = in.readInt();
+ }
+
+ public void write(ExtendedDataOutput out) throws IOException
+ {
+ out.writeInt(classifierID);
+ out.writeInt(packageID);
+ }
+
+ public int getClassifierID()
+ {
+ return classifierID;
+ }
+
+ public int getPackageID()
+ {
+ return packageID;
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class PackageURIMap extends CachedFileMap<Integer, String>
+ {
+ public PackageURIMap(File file)
+ {
+ super(file, "rw");
+ }
+
+ @Override
+ public int getKeySize()
+ {
+ return 4;
+ }
+
+ @Override
+ protected Integer readKey(ExtendedDataInput in) throws IOException
+ {
+ return in.readInt();
+ }
+
+ @Override
+ protected void writeKey(ExtendedDataOutput out, Integer key) throws IOException
+ {
+ out.writeInt(key);
+ }
+
+ @Override
+ public int getValueSize()
+ {
+ return 260;
+ }
+
+ @Override
+ protected String readValue(ExtendedDataInput in) throws IOException
+ {
+ return in.readString();
+ }
+
+ @Override
+ protected void writeValue(ExtendedDataOutput out, String value) throws IOException
+ {
+ byte[] bytes = value.getBytes();
+ if (bytes.length + 4 > getValueSize())
+ {
+ throw new IllegalArgumentException("Value size of " + getValueSize() + " exceeded: " + value);
+ }
+
+ ExtendedIOUtil.writeByteArray(out, bytes);
+ }
+ }
+
+ /**
+ * @author Eike Stepper
+ */
+ private static final class ObjectTypeMap extends SortedFileMap<CDOID, TypeEntry>
+ {
+ public ObjectTypeMap(File file)
+ {
+ super(file, "rw");
+ }
+
+ @Override
+ public int getKeySize()
+ {
+ return 8;
+ }
+
+ @Override
+ protected CDOID readKey(ExtendedDataInput in) throws IOException
+ {
+ return CDOIDImpl.read(in);
+ }
+
+ @Override
+ protected void writeKey(ExtendedDataOutput out, CDOID key) throws IOException
+ {
+ CDOIDImpl.write(out, key);
+ }
+
+ @Override
+ public int getValueSize()
+ {
+ return TypeEntry.SIZE;
+ }
+
+ @Override
+ protected TypeEntry readValue(ExtendedDataInput in) throws IOException
+ {
+ return new TypeEntry(in);
+ }
+
+ @Override
+ protected void writeValue(ExtendedDataOutput out, TypeEntry value) throws IOException
+ {
+ value.write(out);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepository.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepository.java
index de9d3f1..22b6b06 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepository.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IRepository.java
@@ -10,8 +10,7 @@
**************************************************************************/
package org.eclipse.emf.cdo.server;
-import org.eclipse.emf.cdo.protocol.CDOID;
-import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
+import org.eclipse.emf.cdo.internal.server.TypeManager;
import org.eclipse.net4j.util.container.IContainer;
@@ -26,6 +25,8 @@ public interface IRepository extends IContainer
public String getUUID();
+ public TypeManager getTypeManager();
+
public IPackageManager getPackageManager();
public ISessionManager getSessionManager();
@@ -33,6 +34,4 @@ public interface IRepository extends IContainer
public IResourceManager getResourceManager();
public IRevisionManager getRevisionManager();
-
- public CDOClassRef getObjectType(IStoreReader storeReader, CDOID id);
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ITypeManager.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ITypeManager.java
new file mode 100644
index 0000000..ef6cc1c
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ITypeManager.java
@@ -0,0 +1,27 @@
+/***************************************************************************
+ * 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;
+
+import org.eclipse.emf.cdo.internal.protocol.model.CDOClassRefImpl;
+import org.eclipse.emf.cdo.protocol.CDOID;
+import org.eclipse.emf.cdo.protocol.model.CDOClassRef;
+
+/**
+ * @author Eike Stepper
+ */
+public interface ITypeManager extends IRepositoryElement
+{
+ public boolean isPersistent();
+
+ public CDOClassRef getObjectType(IStoreReader storeReader, CDOID id);
+
+ public void registerObjectType(CDOID id, CDOClassRefImpl type);
+}