|
From: Nolwenn (A. F. <fo...@an...> - 2009-10-21 08:19:03
|
Hello,
The post explains how to create Stateful services with the Spring cartridge. The patch was submitted on Jira : .
I need Stateful services with Spring only and also with EJB but this patch doesn't generate stateful session beans when EJB is enabled.
I have implemented EJB stateful as follow. What do you think of this solution ?
Thanks in advance.
0. Applying patch SPRING-131
1. namespace.xml
Add the property ejbStatefulSessionBeanBaseClass
<property name="ejbStatefulSessionBeanBaseClass">
<default>org.springframework.ejb.support.AbstractStatefulSessionBean</default>
<documentation>
Full name of stateful session bean base class for ejb wrapper.
</documentation>
</property>
2. cartridge.xml
Add the property reference ejbStatefulSessionBeanBaseClass
<property reference="ejbStatefulSessionBeanBaseClass"/>
3. SpringSessionBean.vsl
Add the inherited class by service type
#if ($springUtils.isStatefulServicesEnabled() && $service.isServiceTypeStateful())
extends $ejbStatefulSessionBeanBaseClass
#else
extends $ejbSessionBeanBaseClass
#end
Add attributes and getters/setters
#if ($springUtils.isStatefulServicesEnabled() && $service.isServiceTypeStateful())
#foreach ($attribute in $service.attributes)
private $attribute.getterSetterTypeName $attribute.name#if ($attribute.defaultValuePresent) = $attribute.defaultValue#end;
/**
$attribute.getDocumentation(" * ")
*/
public $attribute.getterSetterTypeName ${attribute.getterName}()
{
return this.${attribute.name};
}
## - always have as public, having read-only causes too many issues when attempting to
## use in other cartridges
public void ${attribute.setterName}($attribute.getterSetterTypeName $attribute.name)
{
this.${attribute.name} = $attribute.name;
}
#end
#end
Add methods for stateful EJB
#if (!$service.abstract)
#if ($springUtils.isStatefulServicesEnabled() && $service.isServiceTypeStateful())
/**
* EJB creation and deletion.
*/
public void ejbCreate() throws javax.ejb.CreateException
{
load();
}
public void ejbPostCreate() throws javax.ejb.CreateException
{
}
#if($service.attributes.size() > 0)
public void ejbCreate(
#foreach($attribute in $service.attributes)
$attribute.type.fullyQualifiedName $attribute.name#if($velocityCount != $service.attributes.size()),#else)#end
#end
throws javax.ejb.CreateException
{
#foreach ($attribute in $service.attributes)
this.${attribute.name} = ${attribute.name};
#end
load();
}
public void ejbPostCreate(
#foreach($attribute in $service.attributes)
$attribute.type.fullyQualifiedName $attribute.name#if($velocityCount != $service.attributes.size()),#else)#end
#end
throws javax.ejb.CreateException
{
}
#end
public void ejbRemove()
{
}
/**
* EJB activation and passivation.
*/
public void ejbActivate()
{
load();
}
public void ejbPassivate()
{
unload();
}
/**
* Load the Bean Factory and
* instantiate the Spring Business Object.
*/
private void load()
{
loadBeanFactory();
this.${businessObject} = ($service.fullyQualifiedName)
getBeanFactory().getBean("${service.beanName}");
}
/**
* Unload the Bean Factory.
*/
private void unload()
{
unloadBeanFactory();
setBeanFactoryLocator(null);
}
private javax.ejb.SessionContext sessionContext;
#else
/**
* Every Spring Session EJB needs to
* call this to instantiate the Spring
* Business Object.
*
* @see org.springframework.ejb.support.AbstractStatelessSessionBean#onEjbCreate()
*/
protected void onEjbCreate()
{
#if($service.generalization && !$service.generalization.abstract)
super.onEjbCreate();
#end
this.${businessObject} = ($service.fullyQualifiedName)
getBeanFactory().getBean("${service.beanName}");
}
#end
#set ($seeComment = "@see javax.ejb.SessionBean#setSessionContext(javax.ejb.SessionContext)")
/**
* Override default BeanFactoryLocator implementation to
* provide singleton loading of the application context Bean factory.
*
* $seeComment
*/
public void setSessionContext(javax.ejb.SessionContext sessionContext)
{
super.setSessionContext(sessionContext);
super.setBeanFactoryLocator(
org.springframework.context.access.ContextSingletonBeanFactoryLocator.getInstance("$beanRefFactory"));
super.setBeanFactoryLocatorKey("$beanRefFactoryId");
#if ($springUtils.isStatefulServicesEnabled() && $service.isServiceTypeStateful())
this.sessionContext = sessionContext;
#end
}
#end
4. SpringSessionLocalHome.vsl
Add create() method declaration with attributes
#if ($springUtils.isStatefulServicesEnabled() && $service.isServiceTypeStateful())
#if($service.attributes.size() > 0)
public $service.fullyQualifiedLocalEjbName create(
#foreach($attribute in $service.attributes)
$attribute.type.fullyQualifiedName $attribute.name#if($velocityCount != $service.attributes.size()),#else)#end
#end
throws javax.ejb.CreateException;
#end
#end
5. SpringSessionRemoteHome.vsl
Add create() method declaration with attributes
#if ($springUtils.isStatefulServicesEnabled() && $service.isServiceTypeStateful())
#if($service.attributes.size() > 0)
public $service.fullyQualifiedEjbName create(
#foreach($attribute in $service.attributes)
$attribute.type.fullyQualifiedName $attribute.name#if($velocityCount != $service.attributes.size()),#else)#end
#end
throws javax.ejb.CreateException, java.rmi.RemoteException;
#end
#end
6. ejb-jar.vsl
Add stateful session-type
#if ($springUtils.isStatefulServicesEnabled() && $service.isServiceTypeStateful())
<session-type>Stateful</session-type>
#else
<session-type>Stateless</session-type>
#end
_________________________________________________________
Reply to the post : http://galaxy.andromda.org/forum/viewtopic.php?p=28191#28191
Posting to http://forum.andromda.org/ is preferred over posting to the mailing list!
|