"icyjamie" wrote : Of course. There was some glitches in the configuration for
the session factory. It must depend on jbpmConfiguration, so:
|
| | - depends-on="jbpmConfiguration" for the sessionFactory (believe me, it
is necessary :-))
| | - The addition of <value>my favorite
directories:-)/hibernate.queries.hbm.xml</value> (the original has still errors
(maybe other hibernate version), so I've made some changes)
| |
| Maybe this could be a starting point of a subproject (or module). I have no
"template" or the like.
|
| ObjectFactoryBeanFactoryAware
|
| | package myFavoritePackage;
| | import java.util.Map;
| | import org.jbpm.configuration.ObjectFactory;
| | import org.springframework.beans.BeansException;
| | import org.springframework.beans.factory.BeanFactory;
| | import org.springframework.beans.factory.BeanFactoryAware;
| |
| | public class ObjectFactoryBeanFactoryAware implements ObjectFactory,
BeanFactoryAware {
| |
| | private BeanFactory beanFactory = null;
| |
| | private Map resources = null;
| |
| | public void setResources(Map resources) {
| | this.resources = resources;
| | }
| |
| | private Object getResource(String name) {
| | return resources.get(name);
| | }
| |
| | private boolean hasResource(String name) {
| | return resources.containsKey(name);
| | }
| |
| | public Object createObject(String name) {
| | Object bean = getResource(name);
| | if (bean == null) {
| | bean = beanFactory.getBean(name);
| | }
| | return bean;
| | }
| |
| | public boolean hasObject(String name) {
| | boolean found = hasResource(name);
| | if (!found) {
| | found = beanFactory.containsBean(name);
| | }
| | return found;
| | }
| |
| | public void setBeanFactory(BeanFactory beanFactory) throws
BeansException {
| | this.beanFactory = beanFactory;
| |
| | }
| |
| | }
| |
| SpringDbPersistenceService
| We did not care about transaction management in the close method, because
we use transaction demarcation on another level
| If you really want to do this, it is easily extended
|
| | package myFavoritePackage;
| |
| | import java.lang.reflect.Constructor;
| |
| | import org.hibernate.Session;
| | import org.jbpm.db.ContextSession;
| | import org.jbpm.db.GraphSession;
| | import org.jbpm.db.LoggingSession;
| | import org.jbpm.db.MessagingSession;
| | import org.jbpm.db.SchedulerSession;
| | import org.jbpm.db.TaskMgmtSession;
| | import org.jbpm.persistence.db.DbPersistenceService;
| | import org.jbpm.persistence.db.DbPersistenceServiceFactory;
| | import org.springframework.orm.hibernate3.SessionFactoryUtils;
| |
| | public class SpringDbPersistenceService extends DbPersistenceService {
| |
| | private boolean isClosed = false;
| | private Class graphSessionClass = null;
| | private Class contextSessionClass = null;
| | private Class loggingSessionClass = null;
| | private Class messagingSessionClass = null;
| | private Class schedulerSessionClass = null;
| | private Class taskMgmtSessionClass = null;
| |
| | public void setContextSessionClass(String contextSessionClass)
throws Exception {
| | this.contextSessionClass =
Class.forName(contextSessionClass);
| | }
| |
| | public void setLoggingSessionClass(String loggingSessionClass)
throws Exception {
| | this.loggingSessionClass =
Class.forName(loggingSessionClass);
| | }
| | public void setMessagingSessionClass(String
messagingSessionClass) throws Exception {
| | this.messagingSessionClass =
Class.forName(messagingSessionClass);
| | }
| | public void setSchedulerSessionClass(String
schedulerSessionClass) throws Exception {
| | this.schedulerSessionClass =
Class.forName(schedulerSessionClass);
| | }
| | public void setTaskMgmtSessionClass(String
taskMgmtSessionClass) throws Exception {
| | this.taskMgmtSessionClass =
Class.forName(taskMgmtSessionClass);
| | }
| | public void setGraphSessionClass(String graphSessionClass)
throws Exception {
| | this.graphSessionClass =
Class.forName(graphSessionClass);
| | }
| |
| |
| |
| | SpringDbPersistenceService(DbPersistenceServiceFactory
dbPersistenceServiceFactory) {
| | super(dbPersistenceServiceFactory);
| | }
| |
| | Object createDbSession(Class clazz) {
| | try {
| | Constructor constructor =
clazz.getConstructor(new Class[] {Session.class});
| | return constructor.newInstance(new Object[]
{this.getSession()});
| | } catch (Exception e) {
| | throw new RuntimeException(e);
| | }
| | }
| |
| | public Object createDbSession(Class beanClass, Class
defaultClass) {
| | if (beanClass != null) {
| | return createDbSession(beanClass);
| | } else {
| | return createDbSession(defaultClass);
| | }
| | }
| |
| |
| | public GraphSession getGraphSession() {
| | return (GraphSession)
createDbSession(graphSessionClass,GraphSession.class);
| | }
| |
| | public ContextSession getContextSession() {
| | return (ContextSession)
createDbSession(contextSessionClass,ContextSession.class);
| | }
| |
| | public LoggingSession getLoggingSession() {
| | return (LoggingSession)
createDbSession(loggingSessionClass,LoggingSession.class);
| | }
| |
| | public MessagingSession getMessagingSession() {
| | return (MessagingSession)
createDbSession(messagingSessionClass,MessagingSession.class);
| | }
| |
| | public SchedulerSession getSchedulerSession() {
| | return (SchedulerSession)
createDbSession(schedulerSessionClass,SchedulerSession.class);
| | }
| |
| | public TaskMgmtSession getTaskMgmtSession() {
| | return (TaskMgmtSession)
createDbSession(taskMgmtSessionClass,TaskMgmtSession.class);
| | }
| |
| | // try releasing the session
| | public void close() {
| | // only allow a close once
| | if (!isClosed) {
| |
SessionFactoryUtils.releaseSession(getSession(), getSessionFactory());
| | isClosed = true;
| | }
| | }
| | }
| |
|
| SpringDbPersistenceServiceFactory
|
| | package MyFavoritePackage;
| |
| | import org.jbpm.persistence.db.DbPersistenceService;
| | import org.jbpm.persistence.db.DbPersistenceServiceFactory;
| | import org.jbpm.svc.Service;
| | import org.springframework.beans.BeansException;
| | import org.springframework.beans.factory.BeanFactory;
| | import org.springframework.beans.factory.BeanFactoryAware;
| | import org.springframework.beans.factory.InitializingBean;
| | import org.springframework.orm.hibernate3.LocalSessionFactoryBean;
| | import org.springframework.orm.hibernate3.SessionFactoryUtils;
| | import org.springframework.transaction.PlatformTransactionManager;
| | import org.springframework.transaction.support.TransactionTemplate;
| |
| | public class SpringDbPersistenceServiceFactory extends
DbPersistenceServiceFactory implements InitializingBean,BeanFactoryAware {
| |
| | // lookup method, replaced by spring
| | // will return a DbPersistenceService, implementing Service as
well
| |
| | private String localSessionFactoryBeanString;
| | private BeanFactory beanFactory;
| |
| |
| |
| | public void setLocalSessionFactoryBeanString(String
localSessionFactoryBeanString) {
| | if (localSessionFactoryBeanString.startsWith("&")) {
| | this.localSessionFactoryBeanString =
localSessionFactoryBeanString;
| | } else {
| | this.localSessionFactoryBeanString = "&" +
localSessionFactoryBeanString;
| | }
| | }
| |
| |
| | public DbPersistenceService createPersistenceService() {
| | return null;
| | }
| |
| |
| | public Service openService() {
| | // TODO Auto-generated method stub
| | Service service = createPersistenceService();
| | DbPersistenceService persistenceService =
(DbPersistenceService) service;
| | // create session if necessary
| |
persistenceService.setSession(SessionFactoryUtils.getSession(getSessionFactory(),true));
| | return service;
| | }
| |
| | public void setBeanFactory(BeanFactory beanFactory) throws
BeansException {
| | this.beanFactory = beanFactory;
| |
| | }
| | public void afterPropertiesSet() throws Exception {
| | this.setConfiguration(((LocalSessionFactoryBean)
beanFactory.getBean(localSessionFactoryBeanString)).getConfiguration());
| | }
| | }
| |
|
| JbpmConfigurationFactoryBean
|
| | package MyFavoritePackage;
| |
| | import org.jbpm.JbpmConfiguration;
| | import org.jbpm.configuration.ObjectFactory;
| | import org.springframework.beans.factory.FactoryBean;
| |
| | public class JbpmConfigurationFactoryBean implements FactoryBean {
| |
| | private ObjectFactory objectFactory;
| |
| | public void setObjectFactory(ObjectFactory objectFactory) {
| | this.objectFactory = objectFactory;
| | }
| |
| | public Class getObjectType() {
| | return JbpmConfiguration.class;
| | }
| |
| | public boolean isSingleton() {
| | return true;
| | }
| |
| | public Object getObject() throws Exception {
| |
JbpmConfiguration.Configs.setDefaultObjectFactory(objectFactory);
| | return JbpmConfiguration.getInstance();
| | }
| | }
| |
|
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3928832#3928832
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3928832
-------------------------------------------------------
This SF.Net email is sponsored by xPML, a groundbreaking scripting language
that extends applications into web and mobile media. Attend the live webcast
and join the prime developer group breaking into this new coding territory!
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720&dat=121642
_______________________________________________
JBoss-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/jboss-user