Author: chris.laprun(a)jboss.com
Date: 2010-01-06 10:42:40 -0500 (Wed, 06 Jan 2010)
New Revision: 1180
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/JCRRegistrationPersistenceManager.java
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerMapping.java
Log:
- Fixed ConsumerMapping.createAndAddRegistrationMappingFrom method that was resulting in
creating more registrations than needed.
- Load registrations on init.
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/JCRRegistrationPersistenceManager.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/JCRRegistrationPersistenceManager.java 2010-01-06
15:32:56 UTC (rev 1179)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/JCRRegistrationPersistenceManager.java 2010-01-06
15:42:40 UTC (rev 1180)
@@ -81,7 +81,14 @@
for (ConsumerMapping cm : mappings.getConsumers())
{
- internalAddConsumer(cm.toConsumer(this));
+ ConsumerSPI consumer = cm.toConsumer(this);
+ internalAddConsumer(consumer);
+
+ // get the registrations and add them to local map.
+ for (Registration registration : consumer.getRegistrations())
+ {
+ internalAddRegistration((RegistrationSPI)registration);
+ }
}
}
@@ -155,6 +162,27 @@
return consumer;
}
+ /*@Override
+ protected ConsumerSPI internalSaveChangesTo(Consumer consumer)
+ {
+ ConsumerSPI consumerSPI = super.internalSaveChangesTo(consumer);
+
+ ChromatticSession session = persister.getSession();
+ try
+ {
+ ConsumerMapping cm = session.findById(ConsumerMapping.class,
consumer.getPersistentKey());
+ cm.initFrom(consumer);
+ persister.closeSession(session, true);
+ }
+ catch (Exception e)
+ {
+ e.printStackTrace(); // todo: fix me
+ persister.closeSession(session, false);
+ }
+
+ return consumerSPI;
+ }*/
+
@Override
protected ConsumerGroupSPI internalRemoveConsumerGroup(String name)
{
Modified:
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerMapping.java
===================================================================
---
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerMapping.java 2010-01-06
15:32:56 UTC (rev 1179)
+++
portal/trunk/component/wsrp/src/main/java/org/gatein/portal/wsrp/state/producer/registrations/mapping/ConsumerMapping.java 2010-01-06
15:42:40 UTC (rev 1180)
@@ -95,15 +95,37 @@
@FindById
public abstract ConsumerGroupMapping findGroupById(String id);
+ @FindById
+ public abstract RegistrationMapping findRegistrationById(String id);
+
public RegistrationMapping createAndAddRegistrationMappingFrom(Registration
registration)
{
- // create, add to parent then init
- RegistrationMapping rm = createRegistration("" + System.nanoTime());
- getRegistrations().add(rm);
+ RegistrationMapping rm;
if (registration != null)
{
+ // check if the registration has already been persisted and it should already be
associated to this ConsumerMapping
+ String key = registration.getPersistentKey();
+ if (key != null)
+ {
+ rm = findRegistrationById(key);
+ }
+ else
+ {
+ // else create the registration, add to parent
+ rm = createRegistration("" + System.nanoTime());
+ getRegistrations().add(rm);
+ }
+
+ // then init
rm.initFrom(registration);
}
+ else
+ {
+ // only create the registration and add to parent
+ rm = createRegistration("" + System.nanoTime());
+ getRegistrations().add(rm);
+ }
+
return rm;
}
Show replies by date