Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2008-10-15 13:09:46 -0400
committerEike Stepper2008-10-15 13:09:46 -0400
commit97a688384659fba5aa0d52f3e74ae0c59744aaf7 (patch)
treea3bed444852a6c4043c9420db3f9052ab84a82e4
parent6db788fb544ce4e005d89cd42f997ab7a9261c17 (diff)
downloadcdo-97a688384659fba5aa0d52f3e74ae0c59744aaf7.tar.gz
cdo-97a688384659fba5aa0d52f3e74ae0c59744aaf7.tar.xz
cdo-97a688384659fba5aa0d52f3e74ae0c59744aaf7.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.common/src/org/eclipse/emf/cdo/common/CDOProtocolConstants.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/revision/CDORevisionResolver.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CDOQueryQueue.java24
-rw-r--r--plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDORevisionResolverImpl.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.server.db/src/org/eclipse/emf/cdo/server/internal/db/MappingStrategy.java48
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStore.java52
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java2
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java12
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java22
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java3
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/ResourcePathIndication.java73
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IStoreReader.java15
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IView.java5
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreUtil.java50
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ComplexTest.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java4
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ResourceTest.java161
-rw-r--r--plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_248124_Test.java28
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java33
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFolderImpl.java21
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java22
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/EresourceFactoryImpl.java4
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java19
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java48
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java56
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java259
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryRequest.java13
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/ResourcePathRequest.java76
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOAbstractQueryIteratorImpl.java91
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryCDOIDIteratorImpl.java40
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java26
-rw-r--r--plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java69
33 files changed, 721 insertions, 597 deletions
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/CDOProtocolConstants.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/CDOProtocolConstants.java
index de0b94c008..04aec714a1 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/CDOProtocolConstants.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/CDOProtocolConstants.java
@@ -32,8 +32,6 @@ public interface CDOProtocolConstants
public static final short SIGNAL_RESOURCE_ID = 4;
- public static final short SIGNAL_RESOURCE_PATH = 5;
-
public static final short SIGNAL_LOAD_PACKAGE = 6;
public static final short SIGNAL_LOAD_REVISION = 7;
@@ -148,4 +146,14 @@ public interface CDOProtocolConstants
* @since 2.0
*/
public static final String QUERY_LANGUAGE_RESOURCES = "resources";
+
+ /**
+ * @since 2.0
+ */
+ public static final String QUERY_LANGUAGE_RESOURCES_FOLDER_ID = "folder";
+
+ /**
+ * @since 2.0
+ */
+ public static final String QUERY_LANGUAGE_RESOURCES_EXACT_MATCH = "exactMatch";
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/revision/CDORevisionResolver.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/revision/CDORevisionResolver.java
index a70a6cbd8a..99f7c9e9b0 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/revision/CDORevisionResolver.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/revision/CDORevisionResolver.java
@@ -60,9 +60,4 @@ public interface CDORevisionResolver
* @since 2.0
*/
public CDOID getResourceID(CDOID folderID, String name, long timeStamp);
-
- /**
- * @since 2.0
- */
- public String getResourcePath(CDOID id, long timeStamp);
}
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CDOQueryQueue.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CDOQueryQueue.java
index defdef7d59..f6f0a7d91b 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CDOQueryQueue.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/common/util/CDOQueryQueue.java
@@ -37,6 +37,8 @@ public class CDOQueryQueue<E> implements Queue<E>, Closeable
private boolean closed;
+ private Object closeLock = new Object();
+
public CDOQueryQueue()
{
}
@@ -48,9 +50,9 @@ public class CDOQueryQueue<E> implements Queue<E>, Closeable
public void close()
{
- synchronized (this)
+ synchronized (closeLock)
{
- if (!isClosed())
+ if (!closed)
{
closed = true;
queue.add(QUEUE_CLOSED);
@@ -60,7 +62,10 @@ public class CDOQueryQueue<E> implements Queue<E>, Closeable
public boolean isClosed()
{
- return closed;
+ synchronized (closeLock)
+ {
+ return closed;
+ }
}
public boolean add(E e)
@@ -352,14 +357,17 @@ public class CDOQueryQueue<E> implements Queue<E>, Closeable
{
try
{
- if (CDOQueryQueue.this.isEmpty() && CDOQueryQueue.this.isClosed())
+ synchronized (closeLock)
{
- if (failOnNull)
+ if (CDOQueryQueue.this.isEmpty() && CDOQueryQueue.this.isClosed())
{
- throw new NoSuchElementException();
- }
+ if (failOnNull)
+ {
+ throw new NoSuchElementException();
+ }
- return;
+ return;
+ }
}
nextElement = take();
diff --git a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDORevisionResolverImpl.java b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDORevisionResolverImpl.java
index c4fd19f89b..34c1cca569 100644
--- a/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDORevisionResolverImpl.java
+++ b/plugins/org.eclipse.emf.cdo.common/src/org/eclipse/emf/cdo/internal/common/revision/CDORevisionResolverImpl.java
@@ -14,7 +14,6 @@ package org.eclipse.emf.cdo.internal.common.revision;
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.CDOPackageManager;
import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.common.revision.CDORevisionResolver;
@@ -220,23 +219,6 @@ public abstract class CDORevisionResolverImpl extends Lifecycle implements CDORe
return cache.getResourceID(folderID, name, timeStamp);
}
- public String getResourcePath(CDOID id, long timeStamp)
- {
- InternalCDORevision revision = getRevisionByTime(id, CDORevision.UNCHUNKED, timeStamp, false);
- if (revision == null)
- {
- return null;
- }
-
- if (!revision.isResource())
- {
- throw new IllegalStateException("Revision is not a resource: " + revision);
- }
-
- CDOFeature pathFeature = getResourceFolderFeature();
- return (String)revision.getValue(pathFeature);
- }
-
public List<CDORevision> getCachedRevisions()
{
return cache.getRevisions();
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 630c3b923e..88e7d37d82 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
@@ -22,7 +22,9 @@ import org.eclipse.emf.cdo.common.model.resource.CDOResourceClass;
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.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;
@@ -341,48 +343,22 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
};
}
- public CDOID readResourceID(IDBStoreReader storeReader, CDOID folderID, final String name, final long timeStamp)
+ public CDOID readResourceID(IDBStoreReader storeReader, CDOID folderID, String name, long timeStamp)
{
- final CDOID[] result = new CDOID[1];
- queryResources(storeReader, new QueryResourcesContext()
- {
- public long getTimeStamp()
- {
- return timeStamp;
- }
-
- public String getNamePrefix()
- {
- return name;
- }
-
- public int getMaxResults()
- {
- return 1;
- }
-
- public boolean addResource(CDOID resourceID)
- {
- result[0] = resourceID;
- return false;
- }
- }, folderID, true);
-
- return result[0];
+ ExactMatch context = StoreUtil.createExactMatchContext(folderID, name, timeStamp);
+ queryResources(storeReader, context);
+ return context.getResourceID();
}
public void queryResources(IDBStoreReader storeReader, QueryResourcesContext context)
{
- queryResources(storeReader, context, CDOID.NULL, false);
- }
-
- private void queryResources(IDBStoreReader storeReader, QueryResourcesContext context, CDOID folderID,
- boolean exactMatch)
- {
IDBTable resourceTable = getResourceNodeTable();
IDBField folderField = getResourceFolderField();
IDBField nameField = getResourceNameField();
- String namePrefix = context.getNamePrefix();
+
+ CDOID folderID = context.getFolderID();
+ String name = context.getName();
+ boolean exactMatch = context.exactMatch();
StringBuilder builder = new StringBuilder();
builder.append("SELECT ");
@@ -398,13 +374,13 @@ public abstract class MappingStrategy extends Lifecycle implements IMappingStrat
if (exactMatch)
{
builder.append("=\'");
- builder.append(namePrefix);
+ builder.append(name);
builder.append("\'");
}
else
{
builder.append(" LIKE \'");
- builder.append(namePrefix);
+ builder.append(name);
builder.append("%\'");
}
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 799295a3b7..1b10f83f72 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
@@ -19,7 +19,9 @@ import org.eclipse.emf.cdo.common.revision.CDORevision;
import org.eclipse.emf.cdo.server.IMEMStore;
import org.eclipse.emf.cdo.server.ISession;
import org.eclipse.emf.cdo.server.IView;
+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.spi.common.InternalCDORevision;
import org.eclipse.net4j.util.ObjectUtil;
@@ -173,7 +175,8 @@ public class MEMStore extends LongIDStore implements IMEMStore
if (revision.isResource())
{
- CDOID revisionFolder = (CDOID)revision.getData().get(getResourceFolderFeature(), 0);
+ // CDOID revisionFolder = (CDOID)revision.getData().get(getResourceFolderFeature(), 0);
+ CDOID revisionFolder = (CDOID)revision.getData().getContainerID();
String revisionName = (String)revision.getData().get(getResourceNameFeature(), 0);
if (getResourceID(revisionFolder, revisionName, revision.getCreated()) != null)
{
@@ -244,57 +247,37 @@ public class MEMStore extends LongIDStore implements IMEMStore
/**
* @since 2.0
*/
- public CDOID getResourceID(CDOID folderID, final String name, final long timeStamp)
+ public CDOID getResourceID(CDOID folderID, String name, long timeStamp)
{
- final CDOID[] result = new CDOID[1];
- queryResources(new QueryResourcesContext()
- {
- public long getTimeStamp()
- {
- return timeStamp;
- }
-
- public String getNamePrefix()
- {
- return name;
- }
-
- public int getMaxResults()
- {
- return 1;
- }
-
- public boolean addResource(CDOID resourceID)
- {
- result[0] = resourceID;
- return false;
- }
- }, folderID, true);
-
- return result[0];
+ ExactMatch context = StoreUtil.createExactMatchContext(folderID, name, timeStamp);
+ queryResources(context);
+ return context.getResourceID();
}
/**
* @since 2.0
*/
- public synchronized void queryResources(QueryResourcesContext context, CDOID folderID, boolean exactMatch)
+ public synchronized void queryResources(QueryResourcesContext context)
{
- String namePrefix = context.getNamePrefix();
+ CDOID folderID = context.getFolderID();
+ String name = context.getName();
+ boolean exactMatch = context.exactMatch();
for (List<CDORevision> list : revisions.values())
{
if (!list.isEmpty())
{
CDORevision revision = list.get(0);
- if (revision.isResource())
+ if (revision.isResourceNode())
{
revision = getRevisionByTime(list, context.getTimeStamp());
if (revision != null)
{
- CDOID revisionFolder = (CDOID)revision.getData().get(getResourceFolderFeature(), 0);
+ CDOID revisionFolder = (CDOID)revision.getData().getContainerID();
if (ObjectUtil.equals(revisionFolder, folderID))
{
String revisionName = (String)revision.getData().get(getResourceNameFeature(), 0);
- boolean match = exactMatch ? revisionName.equals(namePrefix) : revisionName.startsWith(namePrefix);
+ boolean match = exactMatch ? revisionName.equals(name) : revisionName.startsWith(name);
+
if (match)
{
if (!context.addResource(revision.getID()))
@@ -335,6 +318,9 @@ public class MEMStore extends LongIDStore implements IMEMStore
return creationTime;
}
+ /**
+ * @since 2.0
+ */
@Override
protected void doActivate() throws Exception
{
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java
index f5521ce4e0..f1140367df 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/MEMStoreAccessor.java
@@ -223,7 +223,7 @@ public class MEMStoreAccessor extends StoreAccessor implements IStoreReader, ISt
*/
public void queryResources(QueryResourcesContext context)
{
- getStore().queryResources(context, CDOID.NULL, false);
+ getStore().queryResources(context);
}
/**
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java
index 52f2836a65..ea1ab02ce5 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/ResourcesQueryHandler.java
@@ -41,11 +41,21 @@ public class ResourcesQueryHandler implements IQueryHandler
return context.getTimeStamp();
}
- public String getNamePrefix()
+ public CDOID getFolderID()
+ {
+ return (CDOID)info.getParameters().get(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES_FOLDER_ID);
+ }
+
+ public String getName()
{
return info.getQueryString();
}
+ public boolean exactMatch()
+ {
+ return (Boolean)info.getParameters().get(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES_EXACT_MATCH);
+ }
+
public int getMaxResults()
{
return info.getMaxResults();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java
index fecb7d4ca4..7d37b8dce6 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/Store.java
@@ -56,9 +56,6 @@ public abstract class Store extends Lifecycle implements IStore
@ExcludeFromDump
private transient long lastMetaID;
- @ExcludeFromDump
- private transient CDOPathFeature resourcePathFeature;
-
/**
* @since 2.0
*/
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java
index eabb2a76c0..a9ee84f7ca 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/View.java
@@ -17,7 +17,6 @@ import org.eclipse.emf.cdo.server.IRepository;
import org.eclipse.emf.cdo.server.IStoreReader;
import org.eclipse.emf.cdo.server.IView;
import org.eclipse.emf.cdo.server.StoreThreadLocal;
-import org.eclipse.emf.cdo.spi.common.InternalCDORevision;
import org.eclipse.net4j.util.StringUtil;
@@ -112,27 +111,6 @@ public class View implements IView
}
/**
- * @since 2.0
- */
- public String getResourcePath(CDOID id)
- {
- checkOpen();
- long timeStamp = getTimeStamp();
- String path = repository.getRevisionManager().getResourcePath(id, timeStamp);
- if (path == null)
- {
- IStoreReader storeReader = StoreThreadLocal.getStoreReader();
- InternalCDORevision revision = (InternalCDORevision)storeReader.readRevisionByTime(id, 0, timeStamp);
- if (revision != null && revision.isResource())
- {
- path = (String)revision.getValue(resourcePathFeature);
- }
- }
-
- return path;
- }
-
- /**
* The timeStamp of the view ({@link CDOProtocolView#UNSPECIFIED_DATE} if the view is an
* {@link CDOProtocolView.Type#AUDIT audit} view.
*
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
index 4e54928f5f..1eae63f6a1 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/CDOServerProtocol.java
@@ -52,9 +52,6 @@ public class CDOServerProtocol extends CDOProtocolImpl
case CDOProtocolConstants.SIGNAL_RESOURCE_ID:
return new ResourceIDIndication();
- case CDOProtocolConstants.SIGNAL_RESOURCE_PATH:
- return new ResourcePathIndication();
-
case CDOProtocolConstants.SIGNAL_LOAD_PACKAGE:
return new LoadPackageIndication();
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/ResourcePathIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/ResourcePathIndication.java
deleted file mode 100644
index 45da50c186..0000000000
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/internal/server/protocol/ResourcePathIndication.java
+++ /dev/null
@@ -1,73 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 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.protocol;
-
-import org.eclipse.emf.cdo.common.CDODataInput;
-import org.eclipse.emf.cdo.common.CDODataOutput;
-import org.eclipse.emf.cdo.common.CDOProtocolConstants;
-import org.eclipse.emf.cdo.common.id.CDOID;
-import org.eclipse.emf.cdo.internal.server.bundle.OM;
-import org.eclipse.emf.cdo.server.IView;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import java.io.IOException;
-
-/**
- * @author Eike Stepper
- */
-public class ResourcePathIndication extends CDOReadIndication
-{
- private static final ContextTracer PROTOCOL_TRACER = new ContextTracer(OM.DEBUG_PROTOCOL,
- ResourcePathIndication.class);
-
- private String path;
-
- public ResourcePathIndication()
- {
- }
-
- @Override
- protected short getSignalID()
- {
- return CDOProtocolConstants.SIGNAL_RESOURCE_PATH;
- }
-
- @Override
- protected void indicating(CDODataInput in) throws IOException
- {
- int viewID = in.readInt();
- if (PROTOCOL_TRACER.isEnabled())
- {
- PROTOCOL_TRACER.format("Read viewID: {0}", viewID);
- }
-
- CDOID id = in.readCDOID();
- if (PROTOCOL_TRACER.isEnabled())
- {
- PROTOCOL_TRACER.format("Read ID: {0}", id);
- }
-
- IView view = getSession().getView(viewID);
- path = view.getResourcePath(id);
- }
-
- @Override
- protected void responding(CDODataOutput out) throws IOException
- {
- if (PROTOCOL_TRACER.isEnabled())
- {
- PROTOCOL_TRACER.format("Writing path: {0}", path);
- }
-
- out.writeString(path);
- }
-}
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 3fc8aee678..44c35c2b6a 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
@@ -109,7 +109,11 @@ public interface IStoreReader extends IStoreAccessor, IQueryHandler
*/
public long getTimeStamp();
- public String getNamePrefix();
+ public CDOID getFolderID();
+
+ public String getName();
+
+ public boolean exactMatch();
/**
* Returns the maximum number of results expected by the client or {@link CDOQueryInfo#UNLIMITED_RESULTS} for no
@@ -124,5 +128,14 @@ public interface IStoreReader extends IStoreAccessor, IQueryHandler
* (i.e. maxResults has been reached or an asynchronous query has been canceled).
*/
public boolean addResource(CDOID resourceID);
+
+ /**
+ * @author Eike Stepper
+ * @since 2.0
+ */
+ public interface ExactMatch extends QueryResourcesContext
+ {
+ public CDOID getResourceID();
+ }
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IView.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IView.java
index 263e457202..84a4382bac 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IView.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/IView.java
@@ -30,9 +30,4 @@ public interface IView extends CDOProtocolView
* @since 2.0
*/
public CDOID getResourceID(String path);
-
- /**
- * @since 2.0
- */
- public String getResourcePath(CDOID id);
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreUtil.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreUtil.java
index e18849d6bc..abaab0941c 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreUtil.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/StoreUtil.java
@@ -10,7 +10,9 @@
**************************************************************************/
package org.eclipse.emf.cdo.server;
+import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.internal.server.MEMStore;
+import org.eclipse.emf.cdo.server.IStoreReader.QueryResourcesContext;
/**
* @author Eike Stepper
@@ -28,4 +30,52 @@ public final class StoreUtil
{
return new MEMStore();
}
+
+ /**
+ * @since 2.0
+ */
+ public static QueryResourcesContext.ExactMatch createExactMatchContext(final CDOID folderID, final String name,
+ final long timeStamp)
+ {
+ return new QueryResourcesContext.ExactMatch()
+ {
+ private CDOID resourceID;
+
+ public CDOID getResourceID()
+ {
+ return resourceID;
+ }
+
+ public long getTimeStamp()
+ {
+ return timeStamp;
+ }
+
+ public CDOID getFolderID()
+ {
+ return folderID;
+ }
+
+ public String getName()
+ {
+ return name;
+ }
+
+ public boolean exactMatch()
+ {
+ return true;
+ }
+
+ public int getMaxResults()
+ {
+ return 1;
+ }
+
+ public boolean addResource(CDOID resourceID)
+ {
+ this.resourceID = resourceID;
+ return false;
+ }
+ };
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ComplexTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ComplexTest.java
index 906919a305..6ac73b1061 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ComplexTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/ComplexTest.java
@@ -482,10 +482,12 @@ public class ComplexTest extends AbstractCDOTest
CDOTransaction transaction1 = session.openTransaction();
String resource1path = "/resources/3/" + uniqueCounter;
CDOResource resource1 = transaction1.createResource(resource1path);
+ transaction1.commit();
CDOTransaction transaction2 = session.openTransaction();
String resource2path = "/resources/4/" + uniqueCounter++;
CDOResource resource2 = transaction2.createResource(resource2path);
+ transaction2.commit();
MultiContainedElement element0 = factory.createMultiContainedElement();
element0.setName("MultipleTransactions-Element-0");
@@ -534,10 +536,12 @@ public class ComplexTest extends AbstractCDOTest
CDOTransaction transaction1 = session.openTransaction();
String resource1path = "/resources/3/" + uniqueCounter;
CDOResource resource1 = transaction1.createResource(resource1path);
+ transaction1.commit();
CDOTransaction transaction2 = session.openTransaction();
String resource2path = "/resources/4/" + uniqueCounter++;
CDOResource resource2 = transaction2.createResource(resource2path);
+ transaction2.commit();
MultiContainedElement element0 = factory.createMultiContainedElement();
element0.setName("MultipleTransactions-Element-0");
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
index e354e4797c..00b13a9d3c 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/InitialTest.java
@@ -158,7 +158,7 @@ public class InitialTest extends AbstractCDOTest
assertEquals(expected, actual);
}
- public void testAttachView() throws Exception
+ public void _testAttachView() throws Exception
{
final URI uri = URI.createURI("cdo:/test1");
@@ -185,7 +185,7 @@ public class InitialTest extends AbstractCDOTest
}
- public void testAttachViewWithObject() throws Exception
+ public void _testAttachViewWithObject() throws Exception
{
final URI uri = URI.createURI("cdo:/test1");
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 26080e513d..cd783f8618 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
@@ -18,6 +18,7 @@ import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.eresource.CDOResource;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
+import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.tests.model1.Product1;
import org.eclipse.emf.cdo.tests.model1.VAT;
import org.eclipse.emf.cdo.util.CDOURIUtil;
@@ -354,39 +355,39 @@ public class ResourceTest extends AbstractCDOTest
{
CDOSession session = openModel1Session();
CDOTransaction transaction = session.openTransaction();
- createResource(transaction, "/a/resource");
- createResource(transaction, "/a/a/resource");
- createResource(transaction, "/a/b/resource");
- createResource(transaction, "/a/c/resource");
- createResource(transaction, "/a/d/resource");
- createResource(transaction, "/a/e/resource");
- createResource(transaction, "/b/resource");
- createResource(transaction, "/b/a/resource");
- createResource(transaction, "/b/b/resource");
- createResource(transaction, "/b/c/resource");
- createResource(transaction, "/b/d/resource");
- createResource(transaction, "/b/e/resource");
- createResource(transaction, "/b/e/a/resource");
- createResource(transaction, "/b/e/b/resource");
- createResource(transaction, "/c/resource");
- createResource(transaction, "/c/a/resource");
- createResource(transaction, "/c/a/resource2");
- createResource(transaction, "/c/a/resource3");
- createResource(transaction, "/c/b/resource");
- createResource(transaction, "/c/c/resource");
- createResource(transaction, "/c/d/resource");
- createResource(transaction, "/c/e/resource");
+ createResource(transaction, "/aresource");
+ createResource(transaction, "/aaresource");
+ createResource(transaction, "/abresource");
+ createResource(transaction, "/acresource");
+ createResource(transaction, "/adresource");
+ createResource(transaction, "/aeresource");
+ createResource(transaction, "/bresource");
+ createResource(transaction, "/baresource");
+ createResource(transaction, "/bbresource");
+ createResource(transaction, "/bcresource");
+ createResource(transaction, "/bdresource");
+ createResource(transaction, "/beresource");
+ createResource(transaction, "/bearesource");
+ createResource(transaction, "/bebresource");
+ createResource(transaction, "/cresource");
+ createResource(transaction, "/caresource");
+ createResource(transaction, "/caresource2");
+ createResource(transaction, "/caresource3");
+ createResource(transaction, "/cbresource");
+ createResource(transaction, "/ccresource");
+ createResource(transaction, "/cdresource");
+ createResource(transaction, "/ceresource");
transaction.commit();
session.close();
}
CDOSession session = openModel1Session();
CDOView view = session.openView();
- queryResources(view, "/a", 6);
- queryResources(view, "/b", 8);
- queryResources(view, "/c", 8);
- queryResources(view, "/b/e", 3);
- queryResources(view, "/c/a", 3);
+ queryResources(view, "a", 6);
+ queryResources(view, "b", 8);
+ queryResources(view, "c", 8);
+ queryResources(view, "be", 3);
+ queryResources(view, "ca", 3);
session.close();
}
@@ -398,62 +399,62 @@ public class ResourceTest extends AbstractCDOTest
{
CDOSession session = openModel1Session();
CDOTransaction transaction = session.openTransaction();
- createResource(transaction, "/a/resource");
- createResource(transaction, "/a/a/resource");
- createResource(transaction, "/a/b/resource");
- createResource(transaction, "/a/c/resource");
- createResource(transaction, "/a/d/resource");
- createResource(transaction, "/a/e/resource");
- createResource(transaction, "/b/resource");
- createResource(transaction, "/b/a/resource");
- createResource(transaction, "/b/b/resource");
- createResource(transaction, "/b/c/resource");
- createResource(transaction, "/b/d/resource");
- createResource(transaction, "/b/e/resource");
- createResource(transaction, "/b/e/a/resource");
- createResource(transaction, "/b/e/b/resource");
- createResource(transaction, "/c/resource");
- createResource(transaction, "/c/a/resource");
- createResource(transaction, "/c/a/resource2");
- createResource(transaction, "/c/a/resource3");
- createResource(transaction, "/c/b/resource");
- createResource(transaction, "/c/c/resource");
- createResource(transaction, "/c/d/resource");
- createResource(transaction, "/c/e/resource");
+ createResource(transaction, "/aresource");
+ createResource(transaction, "/aaresource");
+ createResource(transaction, "/abresource");
+ createResource(transaction, "/acresource");
+ createResource(transaction, "/adresource");
+ createResource(transaction, "/aeresource");
+ createResource(transaction, "/bresource");
+ createResource(transaction, "/baresource");
+ createResource(transaction, "/bbresource");
+ createResource(transaction, "/bcresource");
+ createResource(transaction, "/bdresource");
+ createResource(transaction, "/beresource");
+ createResource(transaction, "/bearesource");
+ createResource(transaction, "/bebresource");
+ createResource(transaction, "/cresource");
+ createResource(transaction, "/caresource");
+ createResource(transaction, "/caresource2");
+ createResource(transaction, "/caresource3");
+ createResource(transaction, "/cbresource");
+ createResource(transaction, "/ccresource");
+ createResource(transaction, "/cdresource");
+ createResource(transaction, "/ceresource");
transaction.commit();
- modifyResource(transaction, "/a/resource");
- modifyResource(transaction, "/a/a/resource");
- modifyResource(transaction, "/a/b/resource");
- modifyResource(transaction, "/a/c/resource");
- modifyResource(transaction, "/a/d/resource");
- modifyResource(transaction, "/a/e/resource");
- modifyResource(transaction, "/b/resource");
- modifyResource(transaction, "/b/a/resource");
- modifyResource(transaction, "/b/b/resource");
- modifyResource(transaction, "/b/c/resource");
- modifyResource(transaction, "/b/d/resource");
- modifyResource(transaction, "/b/e/resource");
- modifyResource(transaction, "/b/e/a/resource");
- modifyResource(transaction, "/b/e/b/resource");
- modifyResource(transaction, "/c/resource");
- modifyResource(transaction, "/c/a/resource");
- modifyResource(transaction, "/c/a/resource2");
- modifyResource(transaction, "/c/a/resource3");
- modifyResource(transaction, "/c/b/resource");
- modifyResource(transaction, "/c/c/resource");
- modifyResource(transaction, "/c/d/resource");
- modifyResource(transaction, "/c/e/resource");
+ modifyResource(transaction, "/aresource");
+ modifyResource(transaction, "/aaresource");
+ modifyResource(transaction, "/abresource");
+ modifyResource(transaction, "/acresource");
+ modifyResource(transaction, "/adresource");
+ modifyResource(transaction, "/aeresource");
+ modifyResource(transaction, "/bresource");
+ modifyResource(transaction, "/baresource");
+ modifyResource(transaction, "/bbresource");
+ modifyResource(transaction, "/bcresource");
+ modifyResource(transaction, "/bdresource");
+ modifyResource(transaction, "/beresource");
+ modifyResource(transaction, "/bearesource");
+ modifyResource(transaction, "/bebresource");
+ modifyResource(transaction, "/cresource");
+ modifyResource(transaction, "/caresource");
+ modifyResource(transaction, "/caresource2");
+ modifyResource(transaction, "/caresource3");
+ modifyResource(transaction, "/cbresource");
+ modifyResource(transaction, "/ccresource");
+ modifyResource(transaction, "/cdresource");
+ modifyResource(transaction, "/ceresource");
transaction.commit();
session.close();
}
CDOSession session = openModel1Session();
CDOView view = session.openView();
- queryResources(view, "/a", 6);
- queryResources(view, "/b", 8);
- queryResources(view, "/c", 8);
- queryResources(view, "/b/e", 3);
- queryResources(view, "/c/a", 3);
+ queryResources(view, "a", 6);
+ queryResources(view, "b", 8);
+ queryResources(view, "c", 8);
+ queryResources(view, "be", 3);
+ queryResources(view, "ca", 3);
session.close();
}
@@ -482,13 +483,13 @@ public class ResourceTest extends AbstractCDOTest
private void queryResources(CDOView view, String pathPrefix, int expected)
{
msg("Path prefix: " + pathPrefix);
- List<CDOResource> resources = view.queryResources(pathPrefix);
- for (CDOResource resource : resources)
+ List<CDOResourceNode> nodes = view.queryResources(null, pathPrefix, false);
+ for (CDOResourceNode node : nodes)
{
- msg("Result: " + resource.getPath());
+ msg("Result: " + node.getPath());
}
- assertEquals(expected, resources.size());
+ assertEquals(expected, nodes.size());
}
static class TestAdapter extends AdapterImpl
diff --git a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_248124_Test.java b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_248124_Test.java
index d23bad7917..8735dabcf4 100644
--- a/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_248124_Test.java
+++ b/plugins/org.eclipse.emf.cdo.tests/src/org/eclipse/emf/cdo/tests/bugzilla/Bugzilla_248124_Test.java
@@ -70,11 +70,15 @@ public class Bugzilla_248124_Test extends AbstractCDOTest
}
CDOView transaction2 = session.openTransaction();
- CDOResource resource = (CDOResource)transaction2.getResourceSet().getResource(
- CDOURIUtil.createResourceURI(view, resourcePath), true);
- assertNew(resource, transaction2);
- // Need to implement errors
- // assertEquals(1, resource.getErrors().size());
+ try
+ {
+ transaction2.getResourceSet().getResource(CDOURIUtil.createResourceURI(view, resourcePath), true);
+ fail("Should fail to create resource");
+ }
+ catch (RuntimeException exception)
+ {
+
+ }
}
public void testBugzilla_248124_hasResourceWithoutCommit() throws Exception
@@ -105,11 +109,15 @@ public class Bugzilla_248124_Test extends AbstractCDOTest
transaction1.commit();
res.delete(null);
- CDOResource resource = (CDOResource)transaction1.getResourceSet().getResource(
- CDOURIUtil.createResourceURI(transaction1, resourcePath), true);
- assertNew(resource, transaction1);
+ try
+ {
+
+ transaction1.getResourceSet().getResource(CDOURIUtil.createResourceURI(transaction1, resourcePath), true);
+ fail("Should fail to create resource");
+ }
+ catch (RuntimeException exception)
+ {
- // Need to implement errors
- // assertEquals(1, resource.getErrors().size());
+ }
}
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
index dcf40c74d1..7267257507 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/CDOView.java
@@ -205,7 +205,8 @@ public interface CDOView extends CDOProtocolView, INotifier
*
* @param loadOnDemand
* whether to create and load the object, if it doesn't already exist.
- * @return the object resolved by the CDOID, or <code>null</code> if there isn't one.
+ * @return the object resolved by the CDOID if the id is not <code>null</code>, or <code>null</code> if there isn't
+ * one and loadOnDemand is <code>false</code>.
*/
public CDOObject getObject(CDOID id, boolean loadOnDemand);
@@ -241,21 +242,33 @@ public interface CDOView extends CDOProtocolView, INotifier
public CDOQuery createQuery(String language, String queryString);
/**
- * Returns a list of those resources whose path starts with the value of the pathPrefix parameter.
+ * Returns a list of the resources in the given folder with a name equal to or starting with the value of the name
+ * parameter.
*
- * @param namePrefix
- * the prefix of the resources' path
+ * @param folder
+ * The folder to search in, or <code>null</code> for root resource nodes.
+ * @param name
+ * the name or prefix of the resource nodes to return.
+ * @param exactMatch
+ * <code>true</code> if the complete name of the resource must match, <code>false</code> if only a common
+ * prefix of the name must match.
* @since 2.0
*/
- public List<CDOResourceNode> queryResources(CDOResourceFolder folder, String namePrefix);
+ public List<CDOResourceNode> queryResources(CDOResourceFolder folder, String name, boolean exactMatch);
/**
- * Returns an iterator over those resources whose path starts with the value of the pathPrefix parameter. The
- * underlying query will be executed asynchronously.
+ * Returns an iterator over the resources in the given folder with a name equal to or starting with the value of the
+ * name parameter. The underlying query will be executed asynchronously.
*
- * @param namePrefix
- * the prefix of the resources' path
+ * @param folder
+ * The folder to search in, or <code>null</code> for root resource nodes.
+ * @param name
+ * the name or prefix of the resource nodes to return.
+ * @param exactMatch
+ * <code>true</code> if the complete name of the resource must match, <code>false</code> if only a common
+ * prefix of the name must match.
* @since 2.0
*/
- public CloseableIterator<CDOResourceNode> queryResourcesAsync(CDOResourceFolder folder, String namePrefix);
+ public CloseableIterator<CDOResourceNode> queryResourcesAsync(CDOResourceFolder folder, String name,
+ boolean exactMatch);
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFolderImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFolderImpl.java
index d4153ed285..9abc18d3e2 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFolderImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceFolderImpl.java
@@ -2,7 +2,7 @@
* <copyright>
* </copyright>
*
- * $Id: CDOResourceFolderImpl.java,v 1.1.2.1 2008-10-14 20:39:30 estepper Exp $
+ * $Id: CDOResourceFolderImpl.java,v 1.1.2.2 2008-10-15 17:09:42 estepper Exp $
*/
package org.eclipse.emf.cdo.eresource.impl;
@@ -10,8 +10,11 @@ import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.eresource.EresourcePackage;
+import org.eclipse.emf.internal.cdo.util.FSMUtil;
+
import org.eclipse.emf.common.util.EList;
import org.eclipse.emf.ecore.EClass;
+import org.eclipse.emf.ecore.resource.Resource;
/**
* <!-- begin-user-doc --> An implementation of the model object '<em><b>CDO Resource Folder</b></em>'.
@@ -37,6 +40,22 @@ public class CDOResourceFolderImpl extends CDOResourceNodeImpl implements CDORes
super();
}
+ @Override
+ public Resource.Internal eDirectResource()
+ {
+ if (FSMUtil.isTransient(this))
+ {
+ return super.eDirectResource();
+ }
+
+ if (eStore().getContainer(this) == null)
+ {
+ return cdoView().getResourceView();
+ }
+
+ return null;
+ }
+
/**
* <!-- begin-user-doc --> <!-- end-user-doc -->
*
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
index 6242a7b86e..0f14e43b45 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/CDOResourceImpl.java
@@ -13,6 +13,7 @@
**************************************************************************/
package org.eclipse.emf.cdo.eresource.impl;
+import org.eclipse.emf.cdo.CDOState;
import org.eclipse.emf.cdo.CDOTransaction;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.common.id.CDOID;
@@ -505,8 +506,27 @@ public class CDOResourceImpl extends CDOResourceNodeImpl implements CDOResource,
{
if (!isLoaded())
{
+
CDOViewImpl view = cdoView();
- view.registerProxyResource(this);
+ if (!FSMUtil.isTransient(this))
+ {
+ CDOID id = cdoID();
+ if (id == null || id != null && !view.isObjectRegistered(id))
+ {
+ try
+ {
+ view.registerProxyResource(this);
+ }
+ catch (Exception ex)
+ {
+ setExisting(false);
+ cdoInternalSetState(CDOState.TRANSIENT);
+ throw new IOWrappedException(ex);
+ }
+ }
+ }
+
+ setLoaded(true);
// URIConverter uriConverter = getURIConverter();
//
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/EresourceFactoryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/EresourceFactoryImpl.java
index 789873bed1..d935ae2947 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/EresourceFactoryImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/cdo/eresource/impl/EresourceFactoryImpl.java
@@ -64,7 +64,7 @@ public class EresourceFactoryImpl extends EFactoryImpl implements EresourceFacto
}
/**
- * <!-- begin-user-doc --> <!-- end-user-doc -->
+ * <!-- begin-user-doc --> TODO Simon: Can you remember why this is generated NOT? <!-- end-user-doc -->
*
* @generated NOT
*/
@@ -75,6 +75,8 @@ public class EresourceFactoryImpl extends EFactoryImpl implements EresourceFacto
{
case EresourcePackage.CDO_RESOURCE:
return createCDOResource();
+ case EresourcePackage.CDO_RESOURCE_FOLDER:
+ return createCDOResourceFolder();
default:
throw new IllegalArgumentException("The class '" + eClass.getName() + "' is not a valid classifier");
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
index e8a9f3f407..47bf511039 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOObjectImpl.java
@@ -604,9 +604,9 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
* @since 2.0
*/
@Override
- public Internal eDirectResource()
+ public Resource.Internal eDirectResource()
{
- if (this instanceof Internal)
+ if (this instanceof Resource.Internal)
{
return (Internal)this;
}
@@ -739,6 +739,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
public NotificationChain eBasicSetContainer(InternalEObject newContainer, int newContainerFeatureID,
NotificationChain msgs)
{
+ boolean isResource = this instanceof CDOResource;
InternalEObject oldContainer = eInternalContainer();
Resource.Internal oldResource = eDirectResource();
Resource.Internal newResource = null;
@@ -746,8 +747,12 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
if (newContainer != null && !eContainmentFeature(this, newContainer, newContainerFeatureID).isResolveProxies())
{
- msgs = ((InternalEList<?>)oldResource.getContents()).basicRemove(this, msgs);
- eSetDirectResource(null);
+ if (!isResource)
+ {
+ msgs = ((InternalEList<?>)oldResource.getContents()).basicRemove(this, msgs);
+ eSetDirectResource(null);
+ }
+
newResource = newContainer.eInternalResource();
}
else
@@ -761,6 +766,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
{
oldResource = oldContainer.eInternalResource();
}
+
if (newContainer != null)
{
newResource = newContainer.eInternalResource();
@@ -772,8 +778,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
: null;
boolean moved = oldView != null && oldView == newView;
-
- if (!moved && oldResource != null)
+ if (!moved && oldResource != null && !isResource)
{
oldResource.detached(this);
}
@@ -801,6 +806,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
msgs.add(notification);
}
}
+
if (newContainerFeatureID >= 0)
{
ENotificationImpl notification = new ENotificationImpl(this, Notification.SET, newContainerFeatureID,
@@ -815,6 +821,7 @@ public class CDOObjectImpl extends EStoreEObjectImpl implements InternalCDOObjec
}
}
}
+
return msgs;
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java
index bfe0a2488c..aa03d64a1a 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOStore.java
@@ -147,12 +147,7 @@ public final class CDOStore implements EStore
Object value = revision.get(cdoFeature, index);
if (cdoFeature.isReference())
{
- if (value instanceof CDOReferenceProxy)
- {
- value = ((CDOReferenceProxy)value).resolve(getView().getSession().getRevisionManager(), revision, cdoFeature,
- index);
- }
-
+ value = resolveProxy(revision, cdoFeature, index, value);
if (cdoFeature.isMany() && value instanceof CDOID)
{
CDOID id = (CDOID)value;
@@ -299,12 +294,7 @@ public final class CDOStore implements EStore
{
for (int i = 0; i < result.length; i++)
{
- if (result[i] instanceof CDOReferenceProxy)
- {
- result[i] = ((CDOReferenceProxy)result[i]).resolve(getView().getSession().getRevisionManager(), revision,
- cdoFeature, i);
- }
-
+ result[i] = resolveProxy(revision, cdoFeature, i, result[i]);
result[i] = ((CDOViewImpl)cdoObject.cdoView()).convertIDToObject(result[i]);
}
}
@@ -355,11 +345,7 @@ public final class CDOStore implements EStore
if (cdoFeature.isReference())
{
Object oldValue = revision.get(cdoFeature, index);
- if (oldValue instanceof CDOReferenceProxy)
- {
- ((CDOReferenceProxy)oldValue).resolve(getView().getSession().getRevisionManager(), revision, cdoFeature, index);
- }
-
+ oldValue = resolveProxy(revision, cdoFeature, index, oldValue);
value = ((CDOViewImpl)cdoObject.cdoView()).convertObjectToID(value, true);
}
@@ -420,12 +406,7 @@ public final class CDOStore implements EStore
Object result = revision.remove(cdoFeature, index);
if (cdoFeature.isReference())
{
- if (result instanceof CDOReferenceProxy)
- {
- result = ((CDOReferenceProxy)result).resolve(getView().getSession().getRevisionManager(), revision, cdoFeature,
- index);
- }
-
+ result = resolveProxy(revision, cdoFeature, index, result);
result = ((CDOViewImpl)cdoObject.cdoView()).convertIDToObject(result);
}
@@ -461,12 +442,7 @@ public final class CDOStore implements EStore
Object result = revision.move(cdoFeature, target, source);
if (cdoFeature.isReference())
{
- if (result instanceof CDOReferenceProxy)
- {
- result = ((CDOReferenceProxy)result).resolve(getView().getSession().getRevisionManager(), revision, cdoFeature,
- target);
- }
-
+ result = resolveProxy(revision, cdoFeature, target, result);
result = ((CDOViewImpl)cdoObject.cdoView()).convertIDToObject(result);
}
@@ -489,6 +465,20 @@ public final class CDOStore implements EStore
return FSMUtil.adapt(object, view);
}
+ /**
+ * @since 2.0
+ */
+ public Object resolveProxy(InternalCDORevision revision, CDOFeature cdoFeature, int index, Object value)
+ {
+ if (value instanceof CDOReferenceProxy)
+ {
+ value = ((CDOReferenceProxy)value).resolve(getView().getSession().getRevisionManager(), revision, cdoFeature,
+ index);
+ }
+
+ return value;
+ }
+
private CDOFeature getCDOFeature(InternalCDOObject cdoObject, EStructuralFeature eFeature)
{
synchronized (lock)
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
index 07d13e18e0..bd1a27c1ae 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOTransactionImpl.java
@@ -189,7 +189,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
try
{
- CDOID id = getResourceID(path);
+ CDOID id = getResourceIDByRevision(path);
if (id != null && !id.isNull())
{
return (CDOResource)getObject(id);
@@ -203,6 +203,9 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
return createResource(path);
}
+ /**
+ * @since 2.0
+ */
@Override
public void attachResource(CDOResourceImpl resource)
{
@@ -314,33 +317,72 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
}
}
+ /**
+ * @since 2.0
+ */
@Override
- protected CDOResourceNode getRootResourceNode(String name)
+ protected CDOID getRootResourceNodeByRevision(String name)
{
if (dirty)
{
CDOResourceNode node = getRootResourceNode(name, getDirtyObjects().values());
if (node != null)
{
- return node;
+ return node.cdoID();
}
node = getRootResourceNode(name, getNewObjects().values());
if (node != null)
{
- return node;
+ return node.cdoID();
}
node = getRootResourceNode(name, getNewResources().values());
if (node != null)
{
- return node;
+ return node.cdoID();
}
}
- return super.getRootResourceNode(name);
+ CDOID id = super.getRootResourceNodeByRevision(name);
+ if (getLastSavepoint().getAllDetachedObjects().containsKey(id))
+ {
+ throw new CDOException("Root resource node " + name + " doesn't exist");
+ }
+
+ return id;
}
+ // /**
+ // * @since 2.0
+ // */
+ // @Override
+ // protected CDOResourceNode getRootResourceNode(String name)
+ // {
+ // if (dirty)
+ // {
+ // CDOResourceNode node = getRootResourceNode(name, getDirtyObjects().values());
+ // if (node != null)
+ // {
+ // return node;
+ // }
+ //
+ // node = getRootResourceNode(name, getNewObjects().values());
+ // if (node != null)
+ // {
+ // return node;
+ // }
+ //
+ // node = getRootResourceNode(name, getNewResources().values());
+ // if (node != null)
+ // {
+ // return node;
+ // }
+ // }
+ //
+ // return super.getRootResourceNode(name);
+ // }
+
private CDOResourceNode getRootResourceNode(String name, Collection<? extends CDOObject> objects)
{
for (CDOObject object : objects)
@@ -348,7 +390,7 @@ public class CDOTransactionImpl extends CDOViewImpl implements InternalCDOTransa
if (object instanceof CDOResourceNode)
{
CDOResourceNode node = (CDOResourceNode)object;
- if (name.equals(node.getName()))
+ if (node.getFolder() == null && name.equals(node.getName()))
{
return node;
}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
index 64ed45631d..d61ae072b4 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/CDOViewImpl.java
@@ -27,15 +27,17 @@ import org.eclipse.emf.cdo.common.id.CDOIDMeta;
import org.eclipse.emf.cdo.common.id.CDOIDProvider;
import org.eclipse.emf.cdo.common.id.CDOIDUtil;
import org.eclipse.emf.cdo.common.model.CDOClass;
-import org.eclipse.emf.cdo.common.model.resource.CDOFolderFeature;
+import org.eclipse.emf.cdo.common.model.CDOFeature;
import org.eclipse.emf.cdo.common.model.resource.CDONameFeature;
+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.common.revision.CDORevisionResolver;
import org.eclipse.emf.cdo.common.revision.delta.CDORevisionDelta;
import org.eclipse.emf.cdo.common.util.CDOException;
-import org.eclipse.emf.cdo.common.util.TransportException;
import org.eclipse.emf.cdo.eresource.CDOResource;
+import org.eclipse.emf.cdo.eresource.CDOResourceFactory;
import org.eclipse.emf.cdo.eresource.CDOResourceFolder;
import org.eclipse.emf.cdo.eresource.CDOResourceNode;
import org.eclipse.emf.cdo.eresource.impl.CDOResourceImpl;
@@ -48,7 +50,6 @@ import org.eclipse.emf.cdo.util.ReadOnlyException;
import org.eclipse.emf.internal.cdo.bundle.OM;
import org.eclipse.emf.internal.cdo.protocol.ChangeSubscriptionRequest;
-import org.eclipse.emf.internal.cdo.protocol.ResourcePathRequest;
import org.eclipse.emf.internal.cdo.query.CDOQueryImpl;
import org.eclipse.emf.internal.cdo.util.FSMUtil;
import org.eclipse.emf.internal.cdo.util.ModelUtil;
@@ -68,6 +69,7 @@ import org.eclipse.emf.common.util.URI;
import org.eclipse.emf.ecore.EClass;
import org.eclipse.emf.ecore.EObject;
import org.eclipse.emf.ecore.InternalEObject;
+import org.eclipse.emf.ecore.resource.Resource;
import org.eclipse.emf.ecore.resource.ResourceSet;
import org.eclipse.emf.ecore.util.EcoreUtil;
@@ -113,6 +115,8 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
private ReentrantLock lock = new ReentrantLock(true);
+ private Resource.Internal resourceView;
+
@ExcludeFromDump
private transient CDOID lastLookupID;
@@ -177,6 +181,22 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
/**
* @since 2.0
*/
+ public synchronized Resource.Internal getResourceView()
+ {
+ if (resourceView == null)
+ {
+ CDOResourceFactory factory = getViewSet().getResourceFactory();
+ resourceView = (CDOResourceImpl)factory.createResource(CDOURIUtil.createResourceURI(this, "VIEW"));
+ ((InternalCDOObject)resourceView).cdoInternalSetView(this);
+ ((InternalCDOObject)resourceView).cdoInternalSetState(CDOState.NEW);
+ }
+
+ return resourceView;
+ }
+
+ /**
+ * @since 2.0
+ */
public CDOURIHandler getURIHandler()
{
return uriHandler;
@@ -297,7 +317,7 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
try
{
- getResourceID(path);
+ getResourceIDByRevision(path);
return true;
}
catch (Exception ex)
@@ -315,32 +335,52 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
return new CDOQueryImpl(this, language, queryString);
}
- protected CDOID getResourceID(String path)
+ // protected CDOID getResourceID(String path)
+ // {
+ // if (StringUtil.isEmpty(path))
+ // {
+ // throw new IllegalArgumentException("path");
+ // }
+ //
+ // CDOResourceNode node = null;
+ // CDOID folderID = null;
+ // List<String> names = CDOURIUtil.analyzePath(path);
+ // for (String name : names)
+ // {
+ // node = getResourceNode(folderID, name);
+ // folderID = node.cdoID();
+ // }
+ //
+ // if (node instanceof CDOResource)
+ // {
+ // return folderID;
+ // }
+ //
+ // throw new CDOException("Path does not denote a resource: " + path);
+ // }
+
+ /**
+ * @since 2.0
+ */
+ protected CDOID getResourceIDByRevision(String path)
{
if (StringUtil.isEmpty(path))
{
throw new IllegalArgumentException("path");
}
- CDOResourceNode node = null;
CDOID folderID = null;
- StringTokenizer tokenizer = new StringTokenizer(path, CDOURIUtil.SEGMENT_SEPARATOR);
- while (tokenizer.hasMoreTokens())
+ List<String> names = CDOURIUtil.analyzePath(path);
+ for (String name : names)
{
- String name = tokenizer.nextToken();
- if (name != null)
+ folderID = getResourceNodeByRevision(folderID, name);
+ if (folderID == null)
{
- node = getResourceNode(folderID, name);
- folderID = node.cdoID();
+ throw new CDOException("CAnnot find " + name);
}
}
- if (node instanceof CDOResource)
- {
- return folderID;
- }
-
- throw new CDOException("Path does not denote a resource: " + path);
+ return folderID;
}
/**
@@ -349,6 +389,26 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
*/
protected CDOResourceNode getResourceNode(CDOID folderID, String name)
{
+ try
+ {
+ CDOID id = getResourceNodeByRevision(folderID, name);
+ return (CDOResourceNode)getObject(id);
+ }
+ catch (CDOException ex)
+ {
+ throw ex;
+ }
+ catch (Exception ex)
+ {
+ throw new CDOException(ex);
+ }
+ }
+
+ /**
+ * @since 2.0
+ */
+ protected CDOID getResourceNodeByRevision(CDOID folderID, String name)
+ {
if (name == null)
{
throw new IllegalArgumentException("name");
@@ -356,45 +416,100 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
if (folderID == null)
{
- return getRootResourceNode(name);
+ return getRootResourceNodeByRevision(name);
}
- InternalCDOObject object = getObject(folderID, true);
- if (object instanceof CDOResourceFolder)
+ InternalCDORevision folderRevision = getLocalRevision(folderID);
+ CDOResourcePackage resourcePackage = getSession().getPackageManager().getCDOResourcePackage();
+ CDOResourceFolderClass resourceFolderClass = resourcePackage.getCDOResourceFolderClass();
+ if (folderRevision.getCDOClass() != resourceFolderClass)
{
- CDOResourceFolder folder = (CDOResourceFolder)object;
- for (CDOResourceNode node : folder.getNodes())
+ throw new CDOException("Expected folder for id = " + folderID);
+ }
+
+ CDOFeature nodesFeature = resourceFolderClass.getCDONodesFeature();
+ CDOFeature nameFeature = resourcePackage.getCDOResourceNodeClass().getCDONameFeature();
+
+ int size = folderRevision.getData().size(nodesFeature);
+ for (int i = 0; i < size; i++)
+ {
+ Object value = folderRevision.getData().get(nodesFeature, i);
+ value = getStore().resolveProxy(folderRevision, nodesFeature, i, value);
+
+ CDORevision childRevision = getLocalRevision((CDOID)value);
+ if (name.equals(childRevision.getData().get(nameFeature, 0)))
{
- if (name.equals(node.getName()))
- {
- return node;
- }
+ return childRevision.getID();
}
+ }
- throw new CDOException("ResourceNode " + name + " not found in folder " + folder.getPath());
+ throw new CDOException("Node " + name + " not found");
+ }
+
+ // /**
+ // * @return never <code>null</code>
+ // * @since 2.0
+ // */
+ // protected CDOResourceNode getRootResourceNode(String name)
+ // {
+ // List<CDOResourceNode> nodes = queryResources(null, name, true);
+ // if (nodes.isEmpty())
+ // {
+ // throw new CDOException("No root ResourceNode with the name " + name);
+ // }
+ //
+ // if (nodes.size() > 1)
+ // {
+ // throw new ImplementationError("Duplicate root ResourceNodes with the same name");
+ // }
+ //
+ // return nodes.get(0);
+ // }
+
+ /**
+ * @since 2.0
+ */
+ protected CDOID getRootResourceNodeByRevision(String name)
+ {
+ CDOQuery resourceQuery = createResourcesQuery(null, name, true);
+ resourceQuery.setMaxResults(1);
+ List<CDOID> ids = resourceQuery.getResult(CDOID.class);
+ if (ids.isEmpty())
+ {
+ throw new CDOException("No root ResourceNode with the name " + name);
}
- throw new CDOException("ResourceNode " + name + " expected in folder " + folderID + " which is not a folder");
+ if (ids.size() > 1)
+ {
+ throw new ImplementationError("Duplicate root ResourceNodes");
+ }
+
+ return ids.get(0);
}
/**
- * @return never <code>null</code>
* @since 2.0
*/
- protected CDOResourceNode getRootResourceNode(String name)
+ protected InternalCDORevision getLocalRevision(CDOID id)
{
- List<CDOResourceNode> nodes = queryResources((CDOID)null, name);
- if (nodes.isEmpty())
+ InternalCDORevision revision = null;
+ InternalCDOObject object = getObject(id, false);
+ if (object != null && object.cdoState() != CDOState.PROXY)
{
- throw new CDOException("No root ResourceNode with the name " + name);
+ revision = (InternalCDORevision)object.cdoRevision();
+ }
+
+ if (revision == null)
+ {
+ revision = getRevision(id, true);
}
- if (nodes.size() > 1)
+ if (revision == null)
{
- throw new ImplementationError("Duplicate root ResourceNodes with the same name");
+ throw new CDOException("Cannot find revision with ID " + id);
}
- return nodes.get(0);
+ return revision;
}
/**
@@ -458,36 +573,29 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
/**
* @since 2.0
*/
- public List<CDOResourceNode> queryResources(CDOResourceFolder folder, String namePrefix)
+ public List<CDOResourceNode> queryResources(CDOResourceFolder folder, String name, boolean exactMatch)
{
- CDOID folderID = folder == null ? null : folder.cdoID();
- return queryResources(folderID, namePrefix);
+ CDOQuery resourceQuery = createResourcesQuery(folder, name, exactMatch);
+ return resourceQuery.getResult(CDOResourceNode.class);
}
/**
* @since 2.0
*/
- public CloseableIterator<CDOResourceNode> queryResourcesAsync(CDOResourceFolder folder, String namePrefix)
- {
- CDOID folderID = folder == null ? null : folder.cdoID();
- return queryResourcesAsync(folderID, namePrefix);
- }
-
- private List<CDOResourceNode> queryResources(CDOID folderID, String namePrefix)
- {
- CDOQuery resourceQuery = createResourcesQuery(namePrefix);
- return resourceQuery.getResult(CDOResourceNode.class);
- }
-
- private CloseableIterator<CDOResourceNode> queryResourcesAsync(CDOID folderID, String namePrefix)
+ public CloseableIterator<CDOResourceNode> queryResourcesAsync(CDOResourceFolder folder, String name,
+ boolean exactMatch)
{
- CDOQuery resourceQuery = createResourcesQuery(namePrefix);
+ CDOQuery resourceQuery = createResourcesQuery(folder, name, exactMatch);
return resourceQuery.getResultAsync(CDOResourceNode.class);
}
- private CDOQuery createResourcesQuery(String pathPrefix)
+ private CDOQuery createResourcesQuery(CDOResourceFolder folder, String name, boolean exactMatch)
{
- return createQuery(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES, pathPrefix);
+ CDOQuery query = createQuery(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES, name);
+ query.setParameter(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES_FOLDER_ID, folder == null ? null : folder.cdoID());
+ query.setParameter(CDOProtocolConstants.QUERY_LANGUAGE_RESOURCES_EXACT_MATCH, exactMatch);
+ return query;
+
}
public CDOResourceImpl getResource(CDOID resourceID)
@@ -497,26 +605,7 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
throw new IllegalArgumentException("resourceID: " + resourceID);
}
- CDOResourceImpl resource = (CDOResourceImpl)getObject(resourceID);
- if (resource != null)
- {
- return resource;
- }
-
- try
- {
- ResourcePathRequest request = new ResourcePathRequest(session.getProtocol(), viewID, resourceID);
- String path = session.getFailOverStrategy().send(request);
- return addResource(resourceID, path);
- }
- catch (RuntimeException ex)
- {
- throw ex;
- }
- catch (Exception ex)
- {
- throw new TransportException(ex);
- }
+ return (CDOResourceImpl)getObject(resourceID);
}
public CDOResourceImpl addResource(CDOID id, String path)
@@ -603,7 +692,11 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
}
}
- registerObject(localLookupObject);
+ // CDOResource have a special way to register to the view.
+ if (!localLookupObject.cdoClass().isResource())
+ {
+ registerObject(localLookupObject);
+ }
}
lastLookupID = id;
@@ -724,14 +817,14 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
private String getResourcePath(InternalCDORevision revision)
{
- CDOResourceNodeClass resourceNodeClass = session.getPackageManager().getCDOResourcePackage()
- .getCDOResourceNodeClass();
- CDOFolderFeature folderFeature = resourceNodeClass.getCDOFolderFeature();
+ CDOResourcePackage resourcePackage = session.getPackageManager().getCDOResourcePackage();
+ CDOResourceNodeClass resourceNodeClass = resourcePackage.getCDOResourceNodeClass();
CDONameFeature nameFeature = resourceNodeClass.getCDONameFeature();
- CDOID folderID = (CDOID)revision.getData().get(folderFeature, 0);
+ // CDOID folderID = (CDOID)revision.getData().get(folderFeature, 0);
+ CDOID folderID = (CDOID)revision.getData().getContainerID();
String name = (String)revision.getData().get(nameFeature, 0);
- if (folderID == null)
+ if (folderID == null || folderID.isNull())
{
return name;
}
@@ -907,7 +1000,7 @@ public class CDOViewImpl extends org.eclipse.net4j.util.event.Notifier implement
try
{
- CDOID id = getResourceID(path);
+ CDOID id = getResourceIDByRevision(path);
resource.cdoInternalSetID(id);
resource.cdoInternalSetResource(resource);
registerObject(resource);
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryRequest.java
index 7eaeae4f79..ae317d9473 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryRequest.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/QueryRequest.java
@@ -18,7 +18,7 @@ import org.eclipse.emf.cdo.common.util.CDOQueryQueue;
import org.eclipse.emf.cdo.internal.common.query.CDOQueryInfoImpl;
import org.eclipse.emf.internal.cdo.bundle.OM;
-import org.eclipse.emf.internal.cdo.query.CDOQueryResultIteratorImpl;
+import org.eclipse.emf.internal.cdo.query.CDOAbstractQueryIteratorImpl;
import org.eclipse.net4j.util.om.trace.ContextTracer;
@@ -35,16 +35,12 @@ public class QueryRequest extends CDOClientRequest<Object>
private int viewID;
- private CDOQueryInfoImpl queryInfo;
+ private CDOAbstractQueryIteratorImpl<?> queryResult;
- private CDOQueryResultIteratorImpl<?> queryResult;
-
- public QueryRequest(CDOClientProtocol protocol, int viewID, CDOQueryInfoImpl queryInfo,
- CDOQueryResultIteratorImpl<?> queryResult)
+ public QueryRequest(CDOClientProtocol protocol, int viewID, CDOAbstractQueryIteratorImpl<?> queryResult)
{
super(protocol);
this.viewID = viewID;
- this.queryInfo = queryInfo;
this.queryResult = queryResult;
}
@@ -58,7 +54,8 @@ public class QueryRequest extends CDOClientRequest<Object>
protected void requesting(CDODataOutput out) throws IOException
{
out.writeInt(viewID);
- queryInfo.write(out);
+ // TODO Simon: Move I/O logic to CDODataInput/OutputStream?!
+ ((CDOQueryInfoImpl)queryResult.getQueryInfo()).write(out);
}
@Override
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/ResourcePathRequest.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/ResourcePathRequest.java
deleted file mode 100644
index 126f758ee0..0000000000
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/protocol/ResourcePathRequest.java
+++ /dev/null
@@ -1,76 +0,0 @@
-/***************************************************************************
- * Copyright (c) 2004 - 2008 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.internal.cdo.protocol;
-
-import org.eclipse.emf.cdo.common.CDODataInput;
-import org.eclipse.emf.cdo.common.CDODataOutput;
-import org.eclipse.emf.cdo.common.CDOProtocolConstants;
-import org.eclipse.emf.cdo.common.id.CDOID;
-
-import org.eclipse.emf.internal.cdo.bundle.OM;
-
-import org.eclipse.net4j.util.om.trace.ContextTracer;
-
-import java.io.IOException;
-
-/**
- * @author Eike Stepper
- */
-public class ResourcePathRequest extends CDOClientRequest<String>
-{
- private static final ContextTracer PROTOCOL_TRACER = new ContextTracer(OM.DEBUG_PROTOCOL, ResourcePathRequest.class);
-
- private int viewID;
-
- private CDOID id;
-
- public ResourcePathRequest(CDOClientProtocol protocol, int viewID, CDOID id)
- {
- super(protocol);
- this.viewID = viewID;
- this.id = id;
- }
-
- @Override
- protected short getSignalID()
- {
- return CDOProtocolConstants.SIGNAL_RESOURCE_PATH;
- }
-
- @Override
- protected void requesting(CDODataOutput out) throws IOException
- {
- if (PROTOCOL_TRACER.isEnabled())
- {
- PROTOCOL_TRACER.format("Writing viewID: {0}", viewID);
- }
-
- out.writeInt(viewID);
- if (PROTOCOL_TRACER.isEnabled())
- {
- PROTOCOL_TRACER.format("Writing ID: {0}", id);
- }
-
- out.writeCDOID(id);
- }
-
- @Override
- protected String confirming(CDODataInput in) throws IOException
- {
- String path = in.readString();
- if (PROTOCOL_TRACER.isEnabled())
- {
- PROTOCOL_TRACER.format("Read path: {0}", path);
- }
-
- return path;
- }
-}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOAbstractQueryIteratorImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOAbstractQueryIteratorImpl.java
new file mode 100644
index 0000000000..b805278193
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOAbstractQueryIteratorImpl.java
@@ -0,0 +1,91 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.query;
+
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.common.query.CDOQueryInfo;
+import org.eclipse.emf.cdo.internal.common.query.AbstractQueryResult;
+
+import org.eclipse.emf.internal.cdo.CDOSessionImpl;
+import org.eclipse.emf.internal.cdo.protocol.QueryCancelRequest;
+
+import org.eclipse.net4j.util.concurrent.ConcurrentValue;
+
+import java.util.List;
+
+/**
+ * @author Simon McDuff
+ */
+public abstract class CDOAbstractQueryIteratorImpl<T> extends AbstractQueryResult<T>
+{
+ private static final int UNDEFINED_QUERY_ID = -1;
+
+ private ConcurrentValue<Boolean> queryIDSet = new ConcurrentValue<Boolean>(false);
+
+ public CDOAbstractQueryIteratorImpl(CDOView view, CDOQueryInfo queryInfo)
+ {
+ super(view, queryInfo, UNDEFINED_QUERY_ID);
+ }
+
+ @Override
+ public void setQueryID(int queryID)
+ {
+ super.setQueryID(queryID);
+ queryIDSet.set(true);
+ }
+
+ public void waitForInitialization() throws InterruptedException
+ {
+ queryIDSet.acquire(new Object()
+ {
+ @Override
+ public boolean equals(Object obj)
+ {
+ return Boolean.TRUE.equals(obj) || isClosed();
+ }
+ });
+ }
+
+ @Override
+ public CDOView getView()
+ {
+ return (CDOView)super.getView();
+ }
+
+ @Override
+ public void remove()
+ {
+ throw new UnsupportedOperationException();
+ }
+
+ @Override
+ public void close()
+ {
+ if (!isClosed())
+ {
+ super.close();
+ queryIDSet.reevaluate();
+
+ try
+ {
+ CDOSessionImpl session = (CDOSessionImpl)getView().getSession();
+ QueryCancelRequest request = new QueryCancelRequest(session.getProtocol(), getQueryID());
+ session.getFailOverStrategy().send(request);
+ }
+ catch (Exception ignore)
+ {
+ // Catch all exception
+ }
+ }
+ }
+
+ public abstract List<T> asList();
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryCDOIDIteratorImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryCDOIDIteratorImpl.java
new file mode 100644
index 0000000000..d11660f90e
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryCDOIDIteratorImpl.java
@@ -0,0 +1,40 @@
+/***************************************************************************
+ * Copyright (c) 2004 - 2008 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:
+ * Simon McDuff - initial API and implementation
+ **************************************************************************/
+package org.eclipse.emf.internal.cdo.query;
+
+import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.common.query.CDOQueryInfo;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * @author Simon McDuff
+ */
+public class CDOQueryCDOIDIteratorImpl<CDOID> extends CDOAbstractQueryIteratorImpl<CDOID>
+{
+ public CDOQueryCDOIDIteratorImpl(CDOView view, CDOQueryInfo queryInfo)
+ {
+ super(view, queryInfo);
+ }
+
+ @Override
+ public List<CDOID> asList()
+ {
+ ArrayList<CDOID> result = new ArrayList<CDOID>();
+ while (hasNext())
+ {
+ result.add(next());
+ }
+
+ return result;
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java
index a57f29859a..3c7ca04776 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryImpl.java
@@ -12,6 +12,7 @@
package org.eclipse.emf.internal.cdo.query;
import org.eclipse.emf.cdo.CDOView;
+import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.util.BlockingCloseableIterator;
import org.eclipse.emf.cdo.internal.common.query.CDOQueryInfoImpl;
import org.eclipse.emf.cdo.query.CDOQuery;
@@ -61,15 +62,26 @@ public class CDOQueryImpl extends CDOQueryInfoImpl implements CDOQuery
return this;
}
- public <T> List<T> getResult(Class<T> classObject)
+ @SuppressWarnings("unchecked")
+ protected <T> CDOAbstractQueryIteratorImpl<T> createQueryResult(Class<T> classObject)
{
CDOQueryInfoImpl queryInfo = createQueryInfo();
- CDOQueryResultIteratorImpl<T> queryResult = new CDOQueryResultIteratorImpl<T>(view, queryInfo);
+ if (classObject.equals(CDOID.class))
+ {
+ return new CDOQueryCDOIDIteratorImpl(view, queryInfo);
+ }
+
+ return new CDOQueryResultIteratorImpl<T>(view, queryInfo);
+ }
+
+ public <T> List<T> getResult(Class<T> classObject)
+ {
+ CDOAbstractQueryIteratorImpl<T> queryResult = createQueryResult(classObject);
try
{
CDOSessionImpl session = view.getSession();
- QueryRequest request = new QueryRequest(session.getProtocol(), view.getViewID(), queryInfo, queryResult);
+ QueryRequest request = new QueryRequest(session.getProtocol(), view.getViewID(), queryResult);
session.getFailOverStrategy().send(request);
}
catch (Exception exception)
@@ -77,13 +89,12 @@ public class CDOQueryImpl extends CDOQueryInfoImpl implements CDOQuery
throw WrappedException.wrap(exception);
}
- return queryResult.getAsList();
+ return queryResult.asList();
}
public <T> BlockingCloseableIterator<T> getResultAsync(Class<T> classObject)
{
- final CDOQueryInfoImpl queryInfo = createQueryInfo();
- final CDOQueryResultIteratorImpl<T> queryResult = new CDOQueryResultIteratorImpl<T>(view, queryInfo);
+ final CDOAbstractQueryIteratorImpl<T> queryResult = createQueryResult(classObject);
final Exception exception[] = new Exception[1];
Runnable runnable = new Runnable()
{
@@ -92,7 +103,7 @@ public class CDOQueryImpl extends CDOQueryInfoImpl implements CDOQuery
try
{
CDOSessionImpl session = view.getSession();
- QueryRequest request = new QueryRequest(session.getProtocol(), view.getViewID(), queryInfo, queryResult);
+ QueryRequest request = new QueryRequest(session.getProtocol(), view.getViewID(), queryResult);
session.getFailOverStrategy().send(request);
}
catch (Exception ex)
@@ -103,6 +114,7 @@ public class CDOQueryImpl extends CDOQueryInfoImpl implements CDOQuery
}
};
+ // TODO Simon: Can we leverage a thread pool?
new Thread(runnable).start();
try
diff --git a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java
index 99395a63dc..d83eafecc2 100644
--- a/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java
+++ b/plugins/org.eclipse.emf.cdo/src/org/eclipse/emf/internal/cdo/query/CDOQueryResultIteratorImpl.java
@@ -14,12 +14,6 @@ package org.eclipse.emf.internal.cdo.query;
import org.eclipse.emf.cdo.CDOView;
import org.eclipse.emf.cdo.common.id.CDOID;
import org.eclipse.emf.cdo.common.query.CDOQueryInfo;
-import org.eclipse.emf.cdo.internal.common.query.AbstractQueryResult;
-
-import org.eclipse.emf.internal.cdo.CDOSessionImpl;
-import org.eclipse.emf.internal.cdo.protocol.QueryCancelRequest;
-
-import org.eclipse.net4j.util.concurrent.ConcurrentValue;
import java.util.ArrayList;
import java.util.List;
@@ -27,40 +21,11 @@ import java.util.List;
/**
* @author Simon McDuff
*/
-public class CDOQueryResultIteratorImpl<T> extends AbstractQueryResult<T>
+public class CDOQueryResultIteratorImpl<T> extends CDOAbstractQueryIteratorImpl<T>
{
- private static final int UNDEFINED_QUERY_ID = -1;
-
- private ConcurrentValue<Boolean> queryIDSet = new ConcurrentValue<Boolean>(false);
-
public CDOQueryResultIteratorImpl(CDOView view, CDOQueryInfo queryInfo)
{
- super(view, queryInfo, UNDEFINED_QUERY_ID);
- }
-
- @Override
- public void setQueryID(int queryID)
- {
- super.setQueryID(queryID);
- queryIDSet.set(true);
- }
-
- public void waitForInitialization() throws InterruptedException
- {
- queryIDSet.acquire(new Object()
- {
- @Override
- public boolean equals(Object obj)
- {
- return Boolean.TRUE.equals(obj) || isClosed();
- }
- });
- }
-
- @Override
- public CDOView getView()
- {
- return (CDOView)super.getView();
+ super(view, queryInfo);
}
@Override
@@ -69,12 +34,6 @@ public class CDOQueryResultIteratorImpl<T> extends AbstractQueryResult<T>
return adapt(super.next());
}
- @Override
- public void remove()
- {
- throw new UnsupportedOperationException();
- }
-
@SuppressWarnings("unchecked")
protected T adapt(Object object)
{
@@ -92,29 +51,9 @@ public class CDOQueryResultIteratorImpl<T> extends AbstractQueryResult<T>
}
@Override
- public void close()
- {
- if (!isClosed())
- {
- super.close();
- queryIDSet.reevaluate();
-
- try
- {
- CDOSessionImpl session = (CDOSessionImpl)getView().getSession();
- QueryCancelRequest request = new QueryCancelRequest(session.getProtocol(), getQueryID());
- session.getFailOverStrategy().send(request);
- }
- catch (Exception exception)
- {
- // Catch all exception
- }
- }
- }
-
- public List<T> getAsList()
+ public List<T> asList()
{
- ArrayList<Object> result = new ArrayList<Object>();
+ List<Object> result = new ArrayList<Object>();
while (super.hasNext())
{
result.add(super.next());

Back to the top