Author: chris.laprun(a)jboss.com
Date: 2011-10-12 07:46:48 -0400 (Wed, 12 Oct 2011)
New Revision: 7727
Modified:
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/AbstractRegistrationPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java
Log:
- Added isConsumerExisting method on RegistrationManager so that we can avoid creating a
Consumer when we just want to test its existence.
- Updated DefaultRegistrationPolicy to use isConsumerExisting.
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-12
11:37:43 UTC (rev 7726)
+++
components/wsrp/trunk/jcr-impl/src/main/java/org/gatein/wsrp/registration/JCRRegistrationPersistenceManager.java 2011-10-12
11:46:48 UTC (rev 7727)
@@ -41,6 +41,7 @@
import org.gatein.wsrp.registration.mapping.RegistrationMapping;
import org.gatein.wsrp.registration.mapping.RegistrationPropertiesMapping;
+import javax.jcr.RepositoryException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
@@ -53,7 +54,7 @@
public class JCRRegistrationPersistenceManager extends
RegistrationPersistenceManagerImpl
{
private ChromatticPersister persister;
- private ConsumersAndGroupsMapping mappings;
+ private final String rootNodePath;
public static final List<Class> mappingClasses = new ArrayList<Class>(6);
@@ -63,14 +64,20 @@
RegistrationMapping.class, ConsumerCapabilitiesMapping.class,
RegistrationPropertiesMapping.class);
}
-
public JCRRegistrationPersistenceManager(ChromatticPersister persister) throws
Exception
{
+ this(persister, "/");
+ }
+
+ protected JCRRegistrationPersistenceManager(ChromatticPersister persister, String
rootNodePath) throws Exception
+ {
ParameterValidation.throwIllegalArgExceptionIfNull(persister,
"ChromatticPersister");
+
+ this.rootNodePath = rootNodePath.endsWith("/") ? rootNodePath :
rootNodePath + "/";
this.persister = persister;
ChromatticSession session = persister.getSession();
- mappings = session.findByPath(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME);
+ ConsumersAndGroupsMapping mappings =
session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
if (mappings == null)
{
mappings = session.insert(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME);
@@ -110,7 +117,7 @@
protected RegistrationSPI internalCreateRegistration(ConsumerSPI consumer, Map
registrationProperties) throws RegistrationException
{
ChromatticSession session = persister.getSession();
- RegistrationSPI registration = null;
+ RegistrationSPI registration;
try
{
ConsumerMapping cm = session.findById(ConsumerMapping.class,
consumer.getPersistentKey());
@@ -149,7 +156,7 @@
ConsumerSPI consumer = super.internalCreateConsumer(consumerId, consumerName);
ChromatticSession session = persister.getSession();
- mappings = session.findByPath(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME);
+ ConsumersAndGroupsMapping mappings =
session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
try
{
ConsumerMapping cm = mappings.createConsumer(consumerId);
@@ -237,7 +244,7 @@
ConsumerGroupSPI group = super.internalCreateConsumerGroup(name);
ChromatticSession session = persister.getSession();
- mappings = session.findByPath(ConsumersAndGroupsMapping.class,
ConsumersAndGroupsMapping.NODE_NAME);
+ ConsumersAndGroupsMapping mappings =
session.findByPath(ConsumersAndGroupsMapping.class, ConsumersAndGroupsMapping.NODE_NAME);
try
{
ConsumerGroupMapping cgm = mappings.createConsumerGroup(name);
@@ -254,4 +261,21 @@
return group;
}
+
+ public boolean isConsumerExisting(String consumerId) throws RegistrationException
+ {
+ ChromatticSession session = persister.getSession();
+ try
+ {
+ return session.getJCRSession().itemExists(rootNodePath +
ConsumersAndGroupsMapping.NODE_NAME + "/" + consumerId);
+ }
+ catch (RepositoryException e)
+ {
+ throw new RuntimeException(e);
+ }
+ finally
+ {
+ persister.closeSession(false);
+ }
+ }
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/AbstractRegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/AbstractRegistrationPersistenceManager.java 2011-10-12
11:37:43 UTC (rev 7726)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/AbstractRegistrationPersistenceManager.java 2011-10-12
11:46:48 UTC (rev 7727)
@@ -162,6 +162,11 @@
return consumer;
}
+ public boolean isConsumerExisting(String consumerId) throws RegistrationException
+ {
+ return getConsumerById(consumerId) != null;
+ }
+
// internal methods: extension points for subclasses
protected abstract void internalAddRegistration(RegistrationSPI registration) throws
RegistrationException;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationManager.java 2011-10-12
11:37:43 UTC (rev 7726)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationManager.java 2011-10-12
11:46:48 UTC (rev 7727)
@@ -62,6 +62,8 @@
Consumer getConsumerByIdentity(String identity) throws RegistrationException;
+ boolean isConsumerExisting(String consumerId) throws RegistrationException;
+
Consumer getConsumerFor(String registrationHandle) throws RegistrationException;
Registration getRegistration(String registrationHandle) throws RegistrationException;
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java 2011-10-12
11:37:43 UTC (rev 7726)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/RegistrationPersistenceManager.java 2011-10-12
11:46:48 UTC (rev 7727)
@@ -103,4 +103,6 @@
Collection<? extends Consumer> getConsumers() throws RegistrationException;
Collection<? extends Registration> getRegistrations() throws
RegistrationException;
+
+ boolean isConsumerExisting(String consumerId) throws RegistrationException;
}
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java 2011-10-12
11:37:43 UTC (rev 7726)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/impl/RegistrationManagerImpl.java 2011-10-12
11:46:48 UTC (rev 7727)
@@ -235,6 +235,13 @@
return persistenceManager.getConsumerById(identity);
}
+ public boolean isConsumerExisting(String consumerId) throws RegistrationException
+ {
+ ParameterValidation.throwIllegalArgExceptionIfNullOrEmpty(consumerId,
"consumer id", null);
+
+ return persistenceManager.isConsumerExisting(consumerId);
+ }
+
public Consumer getConsumerFor(String registrationHandle) throws
RegistrationException
{
return (Consumer)getConsumerOrRegistration(registrationHandle, true);
Modified:
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java
===================================================================
---
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java 2011-10-12
11:37:43 UTC (rev 7726)
+++
components/wsrp/trunk/producer/src/main/java/org/gatein/registration/policies/DefaultRegistrationPolicy.java 2011-10-12
11:46:48 UTC (rev 7727)
@@ -197,8 +197,7 @@
/** Rejects registration if a Consumer with the specified name already exists. */
public void validateConsumerName(String consumerName, final RegistrationManager
manager) throws IllegalArgumentException, RegistrationException
{
- Consumer consumer = manager.getConsumerByIdentity(getConsumerIdFrom(consumerName,
Collections.<QName, Object>emptyMap()));
- if (consumer != null)
+ if (manager.isConsumerExisting(getConsumerIdFrom(consumerName,
Collections.<QName, Object>emptyMap())))
{
throw new DuplicateRegistrationException("A Consumer named '" +
consumerName + "' has already been registered.");
}
@@ -231,7 +230,8 @@
}
/**
- * Instructs this policy to use the specified RegistrationPropertyValidator. There
shouldn't be any need to call this
+ * Instructs this policy to use the specified RegistrationPropertyValidator. There
shouldn't be any need to call
+ * this
* method manually, as the validator is configured via the WSRP Producer xml
configuration file.
*
* @param validator