[jboss-cvs] jboss-portal/core/src/main/org/jboss/portal/core/impl/portlet/state ...
Julien Viet
julien at jboss.com
Sun Jul 30 08:36:21 EDT 2006
User: julien
Date: 06/07/30 08:36:21
Modified: core/src/main/org/jboss/portal/core/impl/portlet/state
PersistentState.java PersistentStateStore.java
Added: core/src/main/org/jboss/portal/core/impl/portlet/state
StatefulPortletInvoker.java
Log:
JBPORTAL-973 : Portlet instance container integration testing
JBPORTAL-972 : Portlet stateful invoker testing
Revision Changes Path
1.8 +2 -2 jboss-portal/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentState.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PersistentState.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentState.java,v
retrieving revision 1.7
retrieving revision 1.8
diff -u -b -r1.7 -r1.8
--- PersistentState.java 28 May 2006 14:32:48 -0000 1.7
+++ PersistentState.java 30 Jul 2006 12:36:21 -0000 1.8
@@ -35,7 +35,7 @@
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.7 $
+ * @version $Revision: 1.8 $
*/
public class PersistentState implements State
{
@@ -131,7 +131,7 @@
this.entries = entries;
}
- public ValueMap getValue()
+ public ValueMap getProperties()
{
return new ValueMap()
{
1.7 +89 -27 jboss-portal/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentStateStore.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: PersistentStateStore.java
===================================================================
RCS file: /cvsroot/jboss/jboss-portal/core/src/main/org/jboss/portal/core/impl/portlet/state/PersistentStateStore.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -b -r1.6 -r1.7
--- PersistentStateStore.java 28 May 2006 14:32:48 -0000 1.6
+++ PersistentStateStore.java 30 Jul 2006 12:36:21 -0000 1.7
@@ -23,19 +23,22 @@
import org.jboss.portal.portlet.state.producer.StateStore;
import org.jboss.portal.portlet.state.producer.State;
+import org.jboss.portal.portlet.state.producer.NoSuchStateException;
+import org.jboss.portal.portlet.state.producer.InvalidStateIdException;
import org.jboss.portal.common.value.ValueMap;
import org.jboss.portal.common.value.Value;
import org.jboss.portal.common.value.SimpleValueMap;
import org.jboss.portal.common.system.AbstractJBossService;
import org.hibernate.SessionFactory;
import org.hibernate.Session;
+import org.hibernate.Query;
import javax.naming.InitialContext;
import java.util.Iterator;
/**
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
- * @version $Revision: 1.6 $
+ * @version $Revision: 1.7 $
*/
public class PersistentStateStore extends AbstractJBossService implements StateStore
{
@@ -56,15 +59,18 @@
this.sessionFactoryJNDIName = sessionFactoryJNDIName;
}
- public State loadState(String id)
+ public State loadState(String id) throws InvalidStateIdException, NoSuchStateException
{
if(id == null)
{
throw new IllegalArgumentException("id cannot be null");
}
+
+ //
Session session = getCurrentSession();
- PersistentState state = lookup(session, id);
- return state;
+
+ //
+ return lookup(session, id);
}
public String createState(String portletId, ValueMap valueMap)
@@ -73,6 +79,10 @@
{
throw new IllegalArgumentException("id cannot be null");
}
+ if (valueMap == null)
+ {
+ throw new IllegalArgumentException("No null value map accepted");
+ }
//
Session session = getCurrentSession();
@@ -86,31 +96,55 @@
return state.getId();
}
- public String cloneState(String stateId, ValueMap valueMap)
+ public String cloneState(String stateId, ValueMap valueMap) throws InvalidStateIdException, NoSuchStateException
{
if(stateId == null)
{
throw new IllegalArgumentException("id cannot be null");
}
+ if (valueMap == null)
+ {
+ throw new IllegalArgumentException("value map cannot be null");
+ }
//
Session session = getCurrentSession();
//
PersistentState parentState = (PersistentState)loadState(stateId);
- if (parentState == null)
- {
- throw new IllegalArgumentException("State to clone does not exist");
- }
+
+ // Create the persistent state
+ PersistentState state = new PersistentState(parentState.getPortletId(), valueMap);
+ session.persist(state);
+
+ // Make the association
+ state.setParent(parentState);
+ parentState.getChildren().add(state);
+ session.update(parentState);
//
- if (valueMap == null)
+ session.flush();
+
+ //
+ return state.getId();
+ }
+
+ public String cloneState(String stateId) throws IllegalArgumentException, NoSuchStateException, InvalidStateIdException
+ {
+ if(stateId == null)
{
- valueMap = new SimpleValueMap(parentState.getValue());
+ throw new IllegalArgumentException("id cannot be null");
}
+ //
+ Session session = getCurrentSession();
+
+ //
+ PersistentState parentState = (PersistentState)loadState(stateId);
+
+ //
// Create the persistent state
- PersistentState state = new PersistentState(parentState.getPortletId(), valueMap);
+ PersistentState state = new PersistentState(parentState.getPortletId(), new SimpleValueMap(parentState.getProperties()));
session.persist(state);
// Make the association
@@ -125,14 +159,12 @@
return state.getId();
}
- public void updateState(String id, ValueMap valueMap)
+ public void updateState(String stateId, ValueMap valueMap) throws InvalidStateIdException, NoSuchStateException
{
Session session = getCurrentSession();
- PersistentState state = lookup(session, id);
- if (state == null)
- {
- throw new IllegalArgumentException();
- }
+
+ //
+ PersistentState state = lookup(session, stateId);
//
state.entries.clear();
@@ -143,17 +175,30 @@
PersistentStateEntry entry = new PersistentStateEntry(key, value);
state.entries.put(key, entry);
}
+
+ //
+ session.update(state);
}
- public void destroyState(String id)
+ public void destroyState(String stateId) throws InvalidStateIdException, NoSuchStateException
{
- Session session = getCurrentSession();
- PersistentState state = lookup(session, id);
- if(state == null)
+ if (stateId == null)
{
- throw new IllegalArgumentException(id);
+ throw new IllegalArgumentException("No null state id accepted");
}
- // Delete state
+
+ //
+ Session session = getCurrentSession();
+
+ //
+ PersistentState state = lookup(session, stateId);
+
+ // Efficiently set the children parent to null
+ String update = "update PersistentState p set p.parent=NULL where p.parent=:parent";
+ Query query = session.createQuery(update).setLong("parent", state.getKey().longValue());
+ query.executeUpdate();
+
+ // Delete the state
session.delete(state);
session.flush();
}
@@ -173,9 +218,26 @@
return sessionFactory.getCurrentSession();
}
- private PersistentState lookup(Session session, String id)
+ private PersistentState lookup(Session session, String stateId) throws NoSuchStateException, InvalidStateIdException
+ {
+ Long key;
+ try
+ {
+ key = new Long(stateId);
+ }
+ catch (NumberFormatException e)
+ {
+ throw new InvalidStateIdException(e, stateId);
+ }
+
+ //
+ PersistentState state = (PersistentState)session.get(PersistentState.class, key);
+ if (state == null)
{
- Long key = new Long(id);
- return (PersistentState)session.get(PersistentState.class, key);
+ throw new NoSuchStateException(stateId);
+ }
+
+ //
+ return state;
}
}
1.1 date: 2006/07/30 12:36:21; author: julien; state: Exp;jboss-portal/core/src/main/org/jboss/portal/core/impl/portlet/state/StatefulPortletInvoker.java
Index: StatefulPortletInvoker.java
===================================================================
/*
* 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 org.jboss.portal.core.impl.portlet.state;
import org.jboss.portal.portlet.PortletInvokerException;
import org.jboss.portal.portlet.invocation.PortletInvocation;
import org.jboss.portal.common.invocation.InvocationException;
/**
* The subclass is used to be able to add AOP behavior.
*
* @author <a href="mailto:julien at jboss.org">Julien Viet</a>
* @version $Revision: 1.1 $
*/
public class StatefulPortletInvoker extends org.jboss.portal.portlet.state.producer.StatefulPortletInvoker
{
public String createClone(String portletId) throws PortletInvokerException
{
return super.createClone(portletId);
}
public void destroyClone(String portletId) throws PortletInvokerException
{
super.destroyClone(portletId);
}
public void invoke(PortletInvocation invocation) throws PortletInvokerException, InvocationException
{
super.invoke(invocation);
}
}
More information about the jboss-cvs-commits
mailing list