[jboss-svn-commits] JBL Code SVN: r29424 - in labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query: filter and 1 other directory.
jboss-svn-commits at lists.jboss.org
jboss-svn-commits at lists.jboss.org
Mon Sep 21 13:07:38 EDT 2009
Author: whitingjr
Date: 2009-09-21 13:07:38 -0400 (Mon, 21 Sep 2009)
New Revision: 29424
Added:
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/DeletedEntityFilter.java
labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/Filter.java
Log:
New classes to filter deleted entities.
Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/DeletedEntityFilter.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/DeletedEntityFilter.java (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/DeletedEntityFilter.java 2009-09-21 17:07:38 UTC (rev 29424)
@@ -0,0 +1,84 @@
+ /*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package uk.ac.ncl.sdia.a8905943.stm.query.filter;
+
+import java.lang.reflect.Field;
+import java.util.Collection;
+import java.util.HashSet;
+import java.util.Set;
+
+import org.apache.log4j.Logger;
+
+import uk.ac.ncl.sdia.a8905943.handle.FieldUtils;
+import uk.ac.ncl.sdia.a8905943.handle.exception.FieldNotFoundException;
+
+/**
+ * This object filters all entities that have been marked as deleted.
+ *
+ * @author <a href="whitingjr at hotmail.com">Jeremy Whiting</a>
+ * @version $Revision: 1.1 $
+ */
+public class DeletedEntityFilter implements Filter
+{
+ private final Set<Long> deletedEntityIds;
+ private static final Logger logger = Logger.getLogger(DeletedEntityFilter.class);
+
+ /**
+ * This filter method assumes all the objects in the collection
+ * parameter are of the same type.
+ */
+ @SuppressWarnings("unchecked")
+ @Override
+ public void filter(Collection collection)
+ {
+ if (null != collection && this.deletedEntityIds != null && !collection.isEmpty())
+ {
+ FieldUtils fieldUtils = new FieldUtils();
+
+ Set filterSet = new HashSet();
+ for (Object entity : collection)
+ {// recurse over the collection to find a deleted entity
+ try
+ {
+ Field idField = fieldUtils.findIdField(entity.getClass());
+ if (this.deletedEntityIds.contains(fieldUtils.getValue(idField, entity)))
+ {// add the entity for deletetion, avoiding ConcurrentModificationException
+ filterSet.add(entity);
+ }
+ }
+ catch (FieldNotFoundException fnfe)
+ {
+ logger.warn(fnfe.getMessage(), fnfe);
+ }
+ }
+ collection.removeAll(filterSet);
+ }
+ }
+
+
+ public DeletedEntityFilter( Set<Long> deleted)
+ {
+ this.deletedEntityIds = deleted;
+ }
+
+}
Added: labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/Filter.java
===================================================================
--- labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/Filter.java (rev 0)
+++ labs/jbosstm/workspace/whitingjr/trunk/MVCCSampleSTM/src/main/java/uk/ac/ncl/sdia/a8905943/stm/query/filter/Filter.java 2009-09-21 17:07:38 UTC (rev 29424)
@@ -0,0 +1,31 @@
+ /*
+ * JBoss, Home of Professional Open Source
+ * Copyright 2005, JBoss Inc., and individual contributors as indicated
+ * by the @authors tag. See the copyright.txt in the distribution for a
+ * full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package uk.ac.ncl.sdia.a8905943.stm.query.filter;
+
+import java.util.Collection;
+
+public interface Filter
+{
+ @SuppressWarnings("unchecked")
+ public void filter(Collection collection);
+}
More information about the jboss-svn-commits
mailing list