Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorEike Stepper2006-09-06 18:25:17 +0000
committerEike Stepper2006-09-06 18:25:17 +0000
commit4d46c49aab837d5aacc41495cbec8aea221752e5 (patch)
tree40022e634e6bfc97011c0bc25f1fd36c1fc3e1fe
parentc434765219c35c559710a54db796c170840cbf95 (diff)
downloadcdo-4d46c49aab837d5aacc41495cbec8aea221752e5.tar.gz
cdo-4d46c49aab837d5aacc41495cbec8aea221752e5.tar.xz
cdo-4d46c49aab837d5aacc41495cbec8aea221752e5.zip
[156163] Add delete resource functionality https://bugs.eclipse.org/bugs/show_bug.cgi?id=156163
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java18
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ServerCDOProtocol.java6
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ServerCDOResProtocol.java46
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java75
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/SQLConstants.java14
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java49
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/DeleteResourcesIndication.java143
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/InvalidateObjectRequest.java11
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOProtocolImpl.java58
-rw-r--r--plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOResProtocolImpl.java46
10 files changed, 406 insertions, 60 deletions
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java
index 7fe1225916..f37c990bb8 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/Mapper.java
@@ -14,7 +14,11 @@ package org.eclipse.emf.cdo.server;
import org.eclipse.net4j.core.Channel;
import org.eclipse.net4j.spring.Service;
+import org.eclipse.emf.cdo.core.OID;
import org.eclipse.emf.cdo.core.OIDEncoder;
+import org.eclipse.emf.cdo.core.RID;
+
+import java.util.Set;
public interface Mapper extends Service
@@ -79,6 +83,20 @@ public interface Mapper extends Service
public void transmitXRefs(Channel channel, long oid, int rid);
+ /**
+ * Deletes the given resource within a transaction.<p>
+ *
+ * @param rid The {@link RID} of the resource to be deleted.<p>
+ */
+ public void deleteResource(int rid);
+
+ /**
+ * Removes all references with missing target objects.<p>
+ *
+ * @return The {@link Set} of modified {@link OID}s.<p>
+ */
+ public Set<Long> removeStaleReferences();
+
public void createAttributeTables(PackageInfo packageInfo);
public void insertResource(int rid, String path);
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ServerCDOProtocol.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ServerCDOProtocol.java
index 22da500e8c..b478c3fc36 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ServerCDOProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ServerCDOProtocol.java
@@ -11,10 +11,14 @@
package org.eclipse.emf.cdo.server;
+import org.eclipse.net4j.core.Channel;
+
import org.eclipse.emf.cdo.core.CDOProtocol;
import org.springframework.transaction.support.TransactionTemplate;
+import java.util.Collection;
+
public interface ServerCDOProtocol extends CDOProtocol
{
@@ -23,4 +27,6 @@ public interface ServerCDOProtocol extends CDOProtocol
public TransactionTemplate getTransactionTemplate();
public ServerCDOResProtocol getServerCDOResProtocol();
+
+ public void fireInvalidationNotification(Channel initiator, Collection<Long> changedObjectIds);
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ServerCDOResProtocol.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ServerCDOResProtocol.java
index 38cf5f4862..c4e27f9f74 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ServerCDOResProtocol.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/ServerCDOResProtocol.java
@@ -12,13 +12,59 @@ package org.eclipse.emf.cdo.server;
import org.eclipse.emf.cdo.core.CDOResProtocol;
+import org.eclipse.emf.cdo.core.OID;
+import org.eclipse.emf.cdo.core.protocol.ResourceChangeInfo;
import org.springframework.transaction.support.TransactionTemplate;
+import java.util.Collection;
+import java.util.List;
+import java.util.Set;
+
public interface ServerCDOResProtocol extends CDOResProtocol
{
public Mapper getMapper();
public TransactionTemplate getTransactionTemplate();
+
+ public void fireResourcesChangedNotification(List<ResourceChangeInfo> resourceChanges);
+
+ public void fireInvalidationNotification(Collection<Long> modifiedOIDs);
+
+ /**
+ * Adds a {@link InvalidationListener} to the list of listeners to be notified about
+ * invalidated obejcts in the scope of this {@link ServerCDOResProtocol}.<p>
+ *
+ * @param listener The {@link InvalidationListener} to be added.<p>
+ */
+ public void addInvalidationListener(InvalidationListener listener);
+
+ /**
+ * Removes a {@link InvalidationListener} from the list of listeners to be notified about
+ * invalidated obejcts in the scope of this {@link ServerCDOResProtocol}.<p>
+ *
+ * @param listener The {@link InvalidationListener} to be removed.<p>
+ */
+ public void removeInvalidationListener(InvalidationListener listener);
+
+
+ /**
+ * Can be registered with a {@link ServerCDOResProtocol} to be subsequently notified about
+ * invalidated objects.<p>
+ *
+ * @author Eike Stepper
+ */
+ public interface InvalidationListener
+ {
+ /**
+ * Called by the {@link ServerCDOResProtocol} this {@link InvalidationListener} is
+ * registered with to notify about invalidated objects.<p>
+ *
+ * @param protocol The {@link ServerCDOResProtocol} this {@link InvalidationListener} is
+ * registered with.<p>
+ * @param modifiedOIDs A {@link Set} of {@link OID}s which have been invalidated.<p>
+ */
+ public void notifyInvalidation(ServerCDOResProtocol protocol, Collection<Long> modifiedOIDs);
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java
index 411878d684..bc8ef82b94 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/MapperImpl.java
@@ -42,9 +42,11 @@ import org.springframework.dao.IncorrectResultSizeDataAccessException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowCallbackHandler;
+import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
+import java.util.Set;
import java.sql.ResultSet;
import java.sql.SQLException;
@@ -570,13 +572,9 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants
jdbcTemplate.update(REMOVE_REFERENCES, args);
}
- public void removeObject(long oid)
+ public void removeObject(long oid, int cid)
{
- removeReferences(oid); // TODO optimize for objects with no refs
-
- int cid = selectCIDOfObject(oid);
ClassInfo classInfo = packageManager.getClassInfo(cid);
-
while (classInfo != null)
{
removeUserSegment(oid, classInfo.getTableName());
@@ -584,6 +582,13 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants
}
removeSegment(oid);
+ removeReferences(oid); // TODO optimize for objects with no refs
+ }
+
+ public void removeObject(long oid)
+ {
+ int cid = selectCIDOfObject(oid);
+ removeObject(oid, cid);
}
protected int selectCIDOfObject(long oid)
@@ -870,6 +875,66 @@ public class MapperImpl extends ServiceImpl implements Mapper, SQLConstants
channel.transmitInt(CDOResProtocol.NO_MORE_RESOURCES);
}
+ public void deleteResource(int rid)
+ {
+ if (isDebugEnabled())
+ {
+ debug("Deleting resource: rid=" + rid);
+ }
+
+ sql(DELETE_RESOURCE, new Object[] { rid});
+
+ Object[] args = ridBounds(rid);
+ if (isDebugEnabled())
+ debug(StringHelper.replaceWildcards(SELECT_ALL_OBJECTS_OF_RESOURCE, "?", args));
+
+ jdbcTemplate.query(SELECT_ALL_OBJECTS_OF_RESOURCE, args, new RowCallbackHandler()
+ {
+ public void processRow(ResultSet resultSet) throws SQLException
+ {
+ long oid = resultSet.getLong(1);
+ int cid = resultSet.getInt(2);
+
+ if (isDebugEnabled())
+ {
+ debug("Deleting object: oid=" + oidEncoder.toString(oid) + ", cid=" + cid);
+ }
+
+ removeObject(oid, cid);
+ }
+ });
+ }
+
+ public Set<Long> removeStaleReferences()
+ {
+ if (isDebugEnabled())
+ {
+ debug("Removing stale references");
+ }
+
+ final Set<Long> modifiedOIDs = new HashSet<Long>();
+ jdbcTemplate.query(SELECT_ALL_STALE_REFERENCES, new RowCallbackHandler()
+ {
+ public void processRow(ResultSet resultSet) throws SQLException
+ {
+ long oid = resultSet.getLong(1);
+ int feature = resultSet.getInt(2);
+ int ordinal = resultSet.getInt(3);
+
+ if (isDebugEnabled())
+ {
+ debug("Reference: oid=" + oidEncoder.toString(oid) + ", feature=" + feature
+ + ", ordinal=" + ordinal);
+ }
+
+ removeReference(oid, feature, ordinal);
+ modifiedOIDs.add(oid);
+ }
+ });
+
+ return modifiedOIDs;
+ }
+
public void transmitExtent(final Channel channel, final int context, final boolean exactMatch,
int rid)
{
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/SQLConstants.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/SQLConstants.java
index 7b0ceef1c9..a3e07f4e62 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/SQLConstants.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/impl/SQLConstants.java
@@ -142,6 +142,17 @@ public interface SQLConstants
+ "." + REFERENCE_CONTENT_COLUMN + "=FALSE AND " + REFERENCE_TABLE + "."
+ REFERENCE_OID_COLUMN + "=" + OBJECT_TABLE + "." + OBJECT_OID_COLUMN;
+ public static final String SELECT_ALL_OBJECTS_OF_RESOURCE = "SELECT " + OBJECT_OID_COLUMN + ", "
+ + OBJECT_CID_COLUMN + " FROM " + OBJECT_TABLE + " WHERE " + OBJECT_OID_COLUMN
+ + " BETWEEN ? AND ?";
+
+ public static final String SELECT_ALL_STALE_REFERENCES = "SELECT " + REFERENCE_TABLE + "."
+ + REFERENCE_OID_COLUMN + ", " + REFERENCE_TABLE + "." + REFERENCE_FEATUREID_COLUMN + ", "
+ + REFERENCE_TABLE + "." + REFERENCE_ORDINAL_COLUMN + " FROM " + REFERENCE_TABLE
+ + " LEFT JOIN " + OBJECT_TABLE + " ON " + REFERENCE_TABLE + "." + REFERENCE_TARGET_COLUMN
+ + "=" + OBJECT_TABLE + "." + OBJECT_OID_COLUMN + " WHERE " + OBJECT_TABLE + "."
+ + OBJECT_OID_COLUMN + " IS NULL";
+
public static final String SELECT_ALL_RESOURCES = "SELECT " + RESOURCE_RID_COLUMN + ", "
+ RESOURCE_PATH_COLUMN + " FROM " + RESOURCE_TABLE;
@@ -157,6 +168,9 @@ public interface SQLConstants
public static final String INSERT_RESOURCE = "INSERT INTO " + RESOURCE_TABLE + " VALUES (?, ?)";
+ public static final String DELETE_RESOURCE = "DELETE FROM " + RESOURCE_TABLE + " WHERE "
+ + RESOURCE_RID_COLUMN + "=?";
+
public static final String INSERT_REFERENCE = "INSERT INTO " + REFERENCE_TABLE
+ " VALUES (?, ?, ?, ?, ?)";
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java
index 6068090a6e..229ae8d994 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/CommitTransactionIndication.java
@@ -600,31 +600,8 @@ public class CommitTransactionIndication extends AbstractIndicationWithResponse
if (!changedObjectIds.isEmpty())
{
Channel me = getChannel();
- int myType = me.getConnector().getType();
- Protocol cdo = me.getProtocol();
-
- Channel[] channels = cdo.getChannels();
- for (int i = 0; i < channels.length; i++)
- {
- Channel channel = channels[i];
- if (channel != me)
- {
- int type = channel.getConnector().getType();
- if (type == myType) // Important to exclude embedded peers (clients)
- {
- InvalidateObjectRequest signal = new InvalidateObjectRequest(changedObjectIds);
-
- try
- {
- channel.transmit(signal);
- }
- catch (Exception ex)
- {
- error("Error while requesting signal " + signal, ex);
- }
- }
- }
- }
+ ServerCDOProtocol cdo = (ServerCDOProtocol) me.getProtocol();
+ cdo.fireInvalidationNotification(me, changedObjectIds);
}
}
@@ -633,29 +610,9 @@ public class CommitTransactionIndication extends AbstractIndicationWithResponse
if (!newResources.isEmpty())
{
Channel me = getChannel();
- int myType = me.getConnector().getType();
ServerCDOProtocol cdo = (ServerCDOProtocol) me.getProtocol();
ServerCDOResProtocol cdores = cdo.getServerCDOResProtocol();
-
- Channel[] channels = cdores.getChannels();
- for (int i = 0; i < channels.length; i++)
- {
- Channel channel = channels[i];
- int type = channel.getConnector().getType();
- if (type == myType) // Important to exclude embedded peers (clients)
- {
- ResourcesChangedRequest signal = new ResourcesChangedRequest(newResources);
-
- try
- {
- channel.transmit(signal);
- }
- catch (Exception ex)
- {
- error("Error while requesting signal " + signal, ex);
- }
- }
- }
+ cdores.fireResourcesChangedNotification(newResources);
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/DeleteResourcesIndication.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/DeleteResourcesIndication.java
new file mode 100644
index 0000000000..c6985ce4c5
--- /dev/null
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/DeleteResourcesIndication.java
@@ -0,0 +1,143 @@
+/***************************************************************************
+ * Copyright (c) 2004, 2005, 2006 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.protocol;
+
+
+import org.eclipse.net4j.core.Channel;
+import org.eclipse.net4j.core.impl.AbstractIndicationWithResponse;
+
+import org.eclipse.emf.cdo.core.CDOResProtocol;
+import org.eclipse.emf.cdo.core.CDOResSignals;
+import org.eclipse.emf.cdo.core.protocol.ResourceChangeInfo;
+import org.eclipse.emf.cdo.server.Mapper;
+import org.eclipse.emf.cdo.server.ServerCDOResProtocol;
+
+import org.springframework.transaction.TransactionException;
+import org.springframework.transaction.TransactionStatus;
+import org.springframework.transaction.support.TransactionCallback;
+import org.springframework.transaction.support.TransactionTemplate;
+
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Set;
+
+
+public class DeleteResourcesIndication extends AbstractIndicationWithResponse implements
+ CDOResSignals
+{
+ private boolean ok;
+
+ public DeleteResourcesIndication()
+ {
+ }
+
+ public short getSignalId()
+ {
+ return DELETE_RESOURCES;
+ }
+
+ public void indicate()
+ {
+ Set<Integer> rids = new HashSet<Integer>();
+ for (;;)
+ {
+ int rid = receiveInt();
+ if (rid == CDOResProtocol.NO_MORE_RESOURCES) break;
+
+ if (isDebugEnabled())
+ {
+ debug("Deleting rid " + rid);
+ }
+
+ rids.add(rid);
+ }
+
+ Set<Long> modifiedOIDs = deleteResources(rids);
+ if (modifiedOIDs != null)
+ {
+ ok = true;
+ transmitInvalidations(modifiedOIDs);
+ transmitRescourceChanges(rids);
+ }
+ else
+ {
+ ok = false;
+ }
+ }
+
+ public void respond()
+ {
+ if (isDebugEnabled())
+ {
+ debug("Deleted resources: " + ok);
+ }
+
+ transmitBoolean(ok);
+ }
+
+ private Set<Long> deleteResources(final Set<Integer> rids)
+ {
+ try
+ {
+ ServerCDOResProtocol protocol = (ServerCDOResProtocol) getProtocol();
+ final Mapper mapper = protocol.getMapper();
+
+ TransactionTemplate transactionTemplate = protocol.getTransactionTemplate();
+ return (Set<Long>) transactionTemplate.execute(new TransactionCallback()
+ {
+ public Object doInTransaction(TransactionStatus status)
+ {
+ for (Integer rid : rids)
+ {
+ mapper.deleteResource(rid);
+ }
+
+ return mapper.removeStaleReferences();
+ }
+ });
+ }
+ catch (TransactionException ex)
+ {
+ error("Error while committing transaction to database", ex);
+ }
+
+ return null;
+ }
+
+ private void transmitInvalidations(Collection<Long> changedObjectIds)
+ {
+ if (!changedObjectIds.isEmpty())
+ {
+ Channel me = getChannel();
+ ServerCDOResProtocol cdores = (ServerCDOResProtocol) me.getProtocol();
+ cdores.fireInvalidationNotification(changedObjectIds);
+ }
+ }
+
+ private void transmitRescourceChanges(Collection<Integer> rids)
+ {
+ if (!rids.isEmpty())
+ {
+ List<ResourceChangeInfo> resourceChanges = new ArrayList<ResourceChangeInfo>();
+ for (Integer rid : rids)
+ {
+ ResourceChangeInfo info = new ResourceChangeInfo(ResourceChangeInfo.REMOVED, rid, null);
+ resourceChanges.add(info);
+ }
+
+ Channel me = getChannel();
+ ServerCDOResProtocol cdores = (ServerCDOResProtocol) me.getProtocol();
+ cdores.fireResourcesChangedNotification(resourceChanges);
+ }
+ }
+}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/InvalidateObjectRequest.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/InvalidateObjectRequest.java
index e5e9e9998c..d2a1e9db72 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/InvalidateObjectRequest.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/InvalidateObjectRequest.java
@@ -15,15 +15,16 @@ import org.eclipse.net4j.core.impl.AbstractRequest;
import org.eclipse.emf.cdo.core.CDOProtocol;
+import java.util.Collection;
import java.util.Iterator;
import java.util.List;
public class InvalidateObjectRequest extends AbstractRequest
{
- private List changedObjectIds;
+ private Collection<Long> changedObjectIds;
- public InvalidateObjectRequest(List changedObjectIds)
+ public InvalidateObjectRequest(Collection<Long> changedObjectIds)
{
this.changedObjectIds = changedObjectIds;
}
@@ -36,11 +37,9 @@ public class InvalidateObjectRequest extends AbstractRequest
public void request()
{
transmitInt(changedObjectIds.size());
-
- for (Iterator iter = changedObjectIds.iterator(); iter.hasNext();)
+ for (Long oid : changedObjectIds)
{
- Long id = (Long) iter.next();
- transmitLong(id.longValue());
+ transmitLong(oid);
}
}
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOProtocolImpl.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOProtocolImpl.java
index b0a3eb284b..40fef72abe 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOProtocolImpl.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOProtocolImpl.java
@@ -11,6 +11,7 @@
package org.eclipse.emf.cdo.server.protocol;
+import org.eclipse.net4j.core.Channel;
import org.eclipse.net4j.core.Indication;
import org.eclipse.net4j.spring.ValidationException;
import org.eclipse.net4j.util.ImplementationError;
@@ -20,11 +21,15 @@ import org.eclipse.emf.cdo.core.protocol.AbstractCDOProtocol;
import org.eclipse.emf.cdo.server.Mapper;
import org.eclipse.emf.cdo.server.ServerCDOProtocol;
import org.eclipse.emf.cdo.server.ServerCDOResProtocol;
+import org.eclipse.emf.cdo.server.ServerCDOResProtocol.InvalidationListener;
import org.springframework.transaction.support.TransactionTemplate;
+import java.util.Collection;
-public class ServerCDOProtocolImpl extends AbstractCDOProtocol implements ServerCDOProtocol
+
+public class ServerCDOProtocolImpl extends AbstractCDOProtocol implements ServerCDOProtocol,
+ InvalidationListener
{
protected Mapper mapper;
@@ -68,10 +73,10 @@ public class ServerCDOProtocolImpl extends AbstractCDOProtocol implements Server
case QUERY_EXTENT:
return new QueryExtentIndication();
-
+
case QUERY_XREFS:
return new QueryXRefsIndication();
-
+
default:
throw new ImplementationError("Invalid " + CDOProtocol.PROTOCOL_NAME + " signalId: "
+ signalId);
@@ -108,10 +113,57 @@ public class ServerCDOProtocolImpl extends AbstractCDOProtocol implements Server
doSet("serverCDOResProtocol", serverCDOResProtocol);
}
+ public void notifyInvalidation(ServerCDOResProtocol protocol, Collection<Long> modifiedOIDs)
+ {
+ fireInvalidationNotification(null, modifiedOIDs);
+ }
+
+ public void fireInvalidationNotification(Channel initiator, Collection<Long> changedObjectIds)
+ {
+ for (Channel channel : getChannels())
+ {
+ if (initiator == null || channel != initiator
+ && channel.getConnector().getType() == initiator.getConnector().getType())
+ {
+ try
+ {
+ InvalidateObjectRequest signal = new InvalidateObjectRequest(changedObjectIds);
+ channel.transmit(signal);
+ }
+ catch (Exception ex)
+ {
+ error("Error while transmitting invalidation notifications " + changedObjectIds, ex);
+ }
+ }
+ }
+ }
+
+ @Override
protected void validate() throws ValidationException
{
super.validate();
assertNotNull("mapper");
assertNotNull("transactionTemplate");
}
+
+ @Override
+ protected void activate() throws Exception
+ {
+ super.activate();
+ if (serverCDOResProtocol != null)
+ {
+ serverCDOResProtocol.addInvalidationListener(this);
+ }
+ }
+
+ @Override
+ protected void deactivate() throws Exception
+ {
+ if (serverCDOResProtocol != null)
+ {
+ serverCDOResProtocol.removeInvalidationListener(this);
+ }
+
+ super.deactivate();
+ }
}
diff --git a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOResProtocolImpl.java b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOResProtocolImpl.java
index 6dc4306865..11a7a6c68b 100644
--- a/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOResProtocolImpl.java
+++ b/plugins/org.eclipse.emf.cdo.server/src/org/eclipse/emf/cdo/server/protocol/ServerCDOResProtocolImpl.java
@@ -11,16 +11,22 @@
package org.eclipse.emf.cdo.server.protocol;
+import org.eclipse.net4j.core.Channel;
import org.eclipse.net4j.core.Indication;
import org.eclipse.net4j.spring.ValidationException;
import org.eclipse.net4j.util.ImplementationError;
import org.eclipse.emf.cdo.core.protocol.AbstractCDOResProtocol;
+import org.eclipse.emf.cdo.core.protocol.ResourceChangeInfo;
import org.eclipse.emf.cdo.server.Mapper;
import org.eclipse.emf.cdo.server.ServerCDOResProtocol;
import org.springframework.transaction.support.TransactionTemplate;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.List;
+
public class ServerCDOResProtocolImpl extends AbstractCDOResProtocol implements
ServerCDOResProtocol
@@ -29,6 +35,8 @@ public class ServerCDOResProtocolImpl extends AbstractCDOResProtocol implements
protected TransactionTemplate transactionTemplate;
+ protected transient List<InvalidationListener> listeners = new ArrayList<InvalidationListener>();
+
public ServerCDOResProtocolImpl()
{
}
@@ -45,6 +53,9 @@ public class ServerCDOResProtocolImpl extends AbstractCDOResProtocol implements
case QUERY_ALL_RESOURCES:
return new QueryAllResourcesIndication();
+ case DELETE_RESOURCES:
+ return new DeleteResourcesIndication();
+
default:
throw new ImplementationError("Invalid " + PROTOCOL_NAME + " signalId: " + signalId);
}
@@ -70,6 +81,41 @@ public class ServerCDOResProtocolImpl extends AbstractCDOResProtocol implements
doSet("transactionTemplate", transactionTemplate);
}
+ public void fireResourcesChangedNotification(List<ResourceChangeInfo> resourceChanges)
+ {
+ for (Channel channel : getChannels())
+ {
+ try
+ {
+ ResourcesChangedRequest signal = new ResourcesChangedRequest(resourceChanges);
+ channel.transmit(signal);
+ }
+ catch (Exception ex)
+ {
+ error("Error while notifying resource changes " + resourceChanges, ex);
+ }
+ }
+ }
+
+ public void fireInvalidationNotification(Collection<Long> modifiedOIDs)
+ {
+ InvalidationListener[] array = listeners.toArray(new InvalidationListener[listeners.size()]);
+ for (InvalidationListener listener : array)
+ {
+ listener.notifyInvalidation(this, modifiedOIDs);
+ }
+ }
+
+ public void addInvalidationListener(InvalidationListener listener)
+ {
+ listeners.add(listener);
+ }
+
+ public void removeInvalidationListener(InvalidationListener listener)
+ {
+ listeners.remove(listener);
+ }
+
protected void validate() throws ValidationException
{
super.validate();

Back to the top