Author: chris.laprun(a)jboss.com
Date: 2011-10-13 12:30:15 -0400 (Thu, 13 Oct 2011)
New Revision: 7740
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/EndpointInfoMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationInfoMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerGroupMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerMapping.java
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManagerTestCase.java
Log:
- Improved and fixed JCRRegistrationPersistenceManager.remove method.
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java 2011-10-13
10:20:10 UTC (rev 7739)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/migration/mapping/ExportInfoMapping.java 2011-10-13
16:30:15 UTC (rev 7740)
@@ -140,4 +140,10 @@
return new ExportInfo(getExportTime(), errorCodesToHandles, states,
IOTools.safeGetBytes(getExportContext()));
}
+
+ public Class<ExportInfo> getModelClass()
+ {
+ return ExportInfo.class;
+ }
+
}
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/EndpointInfoMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/EndpointInfoMapping.java 2011-10-13
10:20:10 UTC (rev 7739)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/EndpointInfoMapping.java 2011-10-13
16:30:15 UTC (rev 7740)
@@ -88,6 +88,11 @@
return initial;
}
+ public Class<EndpointConfigurationInfo> getModelClass()
+ {
+ return EndpointConfigurationInfo.class;
+ }
+
@Override
public WSSEndpointEnabled getMixin()
{
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java 2011-10-13
10:20:10 UTC (rev 7739)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/ProducerInfoMapping.java 2011-10-13
16:30:15 UTC (rev 7740)
@@ -146,6 +146,11 @@
return info;
}
+ public Class<ProducerInfo> getModelClass()
+ {
+ return ProducerInfo.class;
+ }
+
private ModifyRegistrationRequired getCreatedModifyRegistrationRequiredMixin()
{
ModifyRegistrationRequired mmr = getModifyRegistrationRequiredMixin();
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationInfoMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationInfoMapping.java 2011-10-13
10:20:10 UTC (rev 7739)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/consumer/registry/mapping/RegistrationInfoMapping.java 2011-10-13
16:30:15 UTC (rev 7740)
@@ -123,4 +123,10 @@
return initial;
}
+
+ public Class<RegistrationInfo> getModelClass()
+ {
+ return RegistrationInfo.class;
+ }
+
}
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java 2011-10-13
10:20:10 UTC (rev 7739)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/jcr/mapping/BaseMapping.java 2011-10-13
16:30:15 UTC (rev 7740)
@@ -29,7 +29,15 @@
*/
public interface BaseMapping<T, R>
{
+ /**
+ * Must match constant used by implementations to identify the JCR node name/type that
the implementation
+ * represents.
+ */
+ public static final String JCR_TYPE_NAME_CONSTANT_NAME = "NODE_NAME";
+
void initFrom(T model);
T toModel(T initial, R registry);
+
+ Class<T> getModelClass();
}
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java 2011-10-13
10:20:10 UTC (rev 7739)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java 2011-10-13
16:30:15 UTC (rev 7740)
@@ -26,7 +26,6 @@
import org.chromattic.api.ChromatticSession;
import org.gatein.common.util.ParameterValidation;
import org.gatein.registration.Consumer;
-import org.gatein.registration.ConsumerGroup;
import org.gatein.registration.Registration;
import org.gatein.registration.RegistrationException;
import org.gatein.registration.impl.RegistrationPersistenceManagerImpl;
@@ -34,6 +33,7 @@
import org.gatein.registration.spi.ConsumerSPI;
import org.gatein.registration.spi.RegistrationSPI;
import org.gatein.wsrp.jcr.ChromatticPersister;
+import org.gatein.wsrp.jcr.mapping.BaseMapping;
import org.gatein.wsrp.registration.mapping.ConsumerCapabilitiesMapping;
import org.gatein.wsrp.registration.mapping.ConsumerGroupMapping;
import org.gatein.wsrp.registration.mapping.ConsumerMapping;
@@ -42,6 +42,9 @@
import org.gatein.wsrp.registration.mapping.RegistrationPropertiesMapping;
import javax.jcr.RepositoryException;
+import javax.jcr.query.Query;
+import javax.jcr.query.QueryResult;
+import javax.jcr.query.RowIterator;
import javax.xml.namespace.QName;
import java.util.ArrayList;
import java.util.Collections;
@@ -110,11 +113,15 @@
}
}
+ protected ChromatticPersister getPersister()
+ {
+ return persister;
+ }
+
@Override
protected RegistrationSPI internalRemoveRegistration(String registrationId) throws
RegistrationException
{
- Registration registration = getRegistration(registrationId);
- remove(registration.getPersistentKey(), RegistrationMapping.class);
+ remove(registrationId, RegistrationMapping.class, RegistrationSPI.class);
return super.internalRemoveRegistration(registrationId);
}
@@ -144,20 +151,49 @@
@Override
protected ConsumerSPI internalRemoveConsumer(String consumerId) throws
RegistrationException
{
- remove(consumerId, ConsumerMapping.class);
-
+ remove(consumerId, ConsumerMapping.class, ConsumerSPI.class);
return super.internalRemoveConsumer(consumerId);
}
- private <T> T remove(String id, Class<T> clazz)
+ private <T extends BaseMapping, U> U remove(String name, Class<T>
mappingClass, Class<U> modelClass)
{
ChromatticSession session = persister.getSession();
try
{
- T toRemove = session.findById(clazz, id);
+ String jcrType =
(String)mappingClass.getField(BaseMapping.JCR_TYPE_NAME_CONSTANT_NAME).get(null);
+ String id;
+ final Query query =
session.getJCRSession().getWorkspace().getQueryManager().createQuery("select jcr:uuid
from " + jcrType + " where jcr:path = '/%/" + name + "'",
Query.SQL);
+ final QueryResult queryResult = query.execute();
+ final RowIterator rows = queryResult.getRows();
+ final long size = rows.getSize();
+ if (size == 0)
+ {
+ return null;
+ }
+ else
+ {
+ if (size != 1)
+ {
+ throw new IllegalArgumentException("There should be only one " +
modelClass.getSimpleName() + " named " + name);
+ }
+
+ id = rows.nextRow().getValue("jcr:uuid").getString();
+
+ }
+
+ T toRemove = session.findById(mappingClass, id);
+ Class aClass = toRemove.getModelClass();
+ if (!modelClass.isAssignableFrom(aClass))
+ {
+ throw new IllegalArgumentException("Cannot convert a " +
mappingClass.getSimpleName() + " to a " + modelClass.getSimpleName());
+ }
+
+ final U result = modelClass.cast(toRemove.toModel(null, this));
+
session.remove(toRemove);
persister.closeSession(true);
- return toRemove;
+
+ return result;
}
catch (Exception e)
{
@@ -234,23 +270,7 @@
@Override
protected ConsumerGroupSPI internalRemoveConsumerGroup(String name) throws
RegistrationException
{
- try
- {
- ConsumerGroup group = getConsumerGroup(name);
- if (group == null)
- {
- return super.internalRemoveConsumerGroup(name);
- }
- else
- {
- remove(group.getPersistentKey(), ConsumerGroupMapping.class);
- }
- }
- catch (RegistrationException e)
- {
- throw new IllegalArgumentException("Couldn't remove ConsumerGroup
'" + name + "'", e);
- }
-
+ remove(name, ConsumerGroupMapping.class, ConsumerGroupSPI.class);
return super.internalRemoveConsumerGroup(name);
}
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerGroupMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerGroupMapping.java 2011-10-13
10:20:10 UTC (rev 7739)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerGroupMapping.java 2011-10-13
16:30:15 UTC (rev 7740)
@@ -123,4 +123,10 @@
throw new RuntimeException(e);
}
}
+
+ public Class<ConsumerGroupSPI> getModelClass()
+ {
+ return ConsumerGroupSPI.class;
+ }
+
}
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerMapping.java 2011-10-13
10:20:10 UTC (rev 7739)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/ConsumerMapping.java 2011-10-13
16:30:15 UTC (rev 7740)
@@ -182,4 +182,10 @@
return consumer;
}
+
+ public Class<ConsumerSPI> getModelClass()
+ {
+ return ConsumerSPI.class;
+ }
+
}
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java 2011-10-13
10:20:10 UTC (rev 7739)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/mapping/RegistrationMapping.java 2011-10-13
16:30:15 UTC (rev 7740)
@@ -161,6 +161,11 @@
return initial;
}
+ public Class<RegistrationSPI> getModelClass()
+ {
+ return RegistrationSPI.class;
+ }
+
public RegistrationSPI toRegistration(ConsumerSPI consumer,
JCRRegistrationPersistenceManager persistenceManager) throws RegistrationException
{
RegistrationPropertiesMapping rpm = getProperties();
Modified:
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManagerTestCase.java
===================================================================
---
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManagerTestCase.java 2011-10-13
10:20:10 UTC (rev 7739)
+++
components/wsrp/trunk/jcr-impl/src/test/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManagerTestCase.java 2011-10-13
16:30:15 UTC (rev 7740)
@@ -1,24 +1,25 @@
/*
-* JBoss, a division of Red Hat
-* Copyright 2008, Red Hat Middleware, LLC, 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.
-*/
+ * JBoss, a division of Red Hat
+ * Copyright 2011, Red Hat Middleware, LLC, 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 org.gatein.wsrp.registration;
@@ -26,7 +27,12 @@
import org.gatein.registration.AbstractRegistrationPersistenceManagerTestCase;
import org.gatein.registration.RegistrationPersistenceManager;
import org.gatein.wsrp.jcr.BaseChromatticPersister;
+import org.gatein.wsrp.jcr.ChromatticPersister;
+import javax.jcr.Node;
+import javax.jcr.NodeIterator;
+import javax.jcr.Session;
+
/**
* @author <a href="mailto:chris.laprun@jboss.com">Chris
Laprun</a>
* @version $Revision$
@@ -51,10 +57,29 @@
}
};
persister.initializeBuilderFor(JCRRegistrationPersistenceManager.mappingClasses);
- persistenceManager = new JCRRegistrationPersistenceManager(persister);
+ persistenceManager = new JCRRegistrationPersistenceManager(persister,
workspaceName);
}
+
@Override
+ protected void tearDown() throws Exception
+ {
+ // remove node containing consumer informations so that we can start with a clean
state
+ final ChromatticPersister persister = persistenceManager.getPersister();
+ final Session session = persister.getSession().getJCRSession();
+ final Node rootNode = session.getRootNode();
+ final NodeIterator nodes = rootNode.getNodes();
+ while (nodes.hasNext())
+ {
+ nodes.nextNode().remove();
+ }
+
+ // then save
+ persister.closeSession(true);
+ }
+
+
+ @Override
public RegistrationPersistenceManager getManager() throws Exception
{
return persistenceManager;