1 5 6 package org.exoplatform.services.workflow.impl; 7 8 import org.exoplatform.commons.Environment; 9 import org.exoplatform.commons.utils.ExoProperties; 10 import org.exoplatform.container.configuration.ConfigurationManager; 11 import org.exoplatform.container.configuration.ServiceConfiguration; 12 13 import java.sql.Connection ; 14 import java.sql.SQLException ; 15 import java.util.Properties ; 16 17 import org.picocontainer.Startable; 18 import org.exoplatform.services.database.DatabaseService; 19 import org.exoplatform.services.exception.ExoServiceException; 20 import org.exoplatform.services.workflow.*; 21 import org.jbpm.JbpmServiceFactory; 22 import org.jbpm.JbpmConfiguration; 23 24 import javax.sql.DataSource ; 25 26 31 public class WorkflowServiceContainerImpl implements WorkflowServiceContainer, Startable { 32 33 private DataSource workflowDS; 34 35 private static final String DATASOURCE_PROPERTY = "hibernate.connection.datasource"; 36 private static final String CACHE_PROPERTY = "hibernate.cache.provider_class" ; 37 static final String DIALECT_PROPERTY = "hibernate.dialect"; 38 static final String SHOW_SQL_PROPERTY = "hibernate.show_sql"; 39 static final String REFLECTION_OPTIMIZER_PROPERTY = "hibernate.cglib.use_reflection_optimizer"; 40 static final String CONNECTION_PROVIDER_PROPERTY = "hibernate.connection.provider_class"; 41 42 private JbpmServiceFactory serviceLocator; 43 private ServiceConfiguration serviceConfiguration; 44 private DatabaseService databaseService; 45 46 public WorkflowServiceContainerImpl(ConfigurationManager conf, 47 DatabaseService databaseService) throws Exception { 48 this.serviceConfiguration = conf.getServiceConfiguration(this.getClass()); 49 this.databaseService = databaseService; 50 } 51 52 private void init(){ 53 Properties properties = new Properties(); 54 if (Environment.getInstance().getPlatform() != Environment.STAND_ALONE) { 55 String datasource = serviceConfiguration.getValuesParam("datasource").getValue(); 56 properties.setProperty(DATASOURCE_PROPERTY, datasource); 57 String cache = serviceConfiguration.getValuesParam("cache").getValue(); 58 properties.setProperty(CACHE_PROPERTY, cache); 59 String connectionProvider = serviceConfiguration.getValuesParam("connection-provider").getValue(); 60 properties.setProperty(CONNECTION_PROVIDER_PROPERTY, connectionProvider); 61 String dbType = databaseService.getDatabaseType(DatabaseService.EXO_WORKFLOW_DATASOURCE_NAME); 62 setDialect(properties, dbType); 63 } else { 64 properties.setProperty(CACHE_PROPERTY, "org.exoplatform.services.database.impl.ExoCacheProvider"); 65 } 66 this.serviceLocator = new JbpmServiceFactory(new JbpmConfiguration(properties)); 67 68 } 69 70 private void setDialect(Properties properties, String dbType) { 71 if (DatabaseService.HSQL.equals(dbType)) { 72 properties.setProperty(DIALECT_PROPERTY, "net.sf.hibernate.dialect.HSQLDialect"); 73 } else if (DatabaseService.MYSQL.equals(dbType)) { 74 properties.setProperty(DIALECT_PROPERTY, "net.sf.hibernate.dialect.MySQLDialect"); 75 } else if (DatabaseService.DB2.equals(dbType)) { 76 properties.setProperty(DIALECT_PROPERTY, "net.sf.hibernate.dialect.DB2Dialect"); 77 } else if (DatabaseService.ORACLE.equals(dbType)) { 78 properties.setProperty(DIALECT_PROPERTY, "net.sf.hibernate.dialect.Oracle9Dialect"); 79 } 80 } 81 82 public WorkflowDefinitionService createWorkflowDefinitionService() { 83 if(serviceLocator == null) 84 init(); 85 return new WorkflowDefinitionServiceImpl(serviceLocator); 86 } 87 88 public WorkflowExecutionService createWorkflowExecutionService() { 89 if(serviceLocator == null) 90 init(); 91 return new WorkflowExecutionServiceImpl(serviceLocator); 92 } 93 94 public void start() { 95 96 } 97 98 public void stop() { 99 } 100 101 } 102 | Popular Tags |