Search in sources :

Example 1 with BPELDatabaseCreator

use of org.wso2.carbon.bpel.core.ode.integration.utils.BPELDatabaseCreator in project carbon-business-process by wso2.

the class BPELServerImpl method initDataSource.

/**
 * Initialize the data source.
 *
 * @throws BPELEngineException If error occured while initializing datasource
 */
private void initDataSource() throws BPELEngineException {
    db = new Database(odeConfigurationProperties);
    db.setTransactionManager(transactionManager);
    if (System.getProperty("setup") != null) {
        BPELDatabaseCreator bpelDBCreator;
        try {
            bpelDBCreator = new BPELDatabaseCreator(db.<DataSource>lookupInJndi(odeConfigurationProperties.getDbDataSource()));
        } catch (Exception e) {
            String errMsg = "Error creating BPELDatabaseCreator";
            log.error(errMsg, e);
            throw new BPELEngineException(errMsg, e);
        }
        if (!bpelDBCreator.isDatabaseStructureCreated("SELECT * FROM ODE_SCHEMA_VERSION")) {
            try {
                // TODO rename following method
                bpelDBCreator.createRegistryDatabase();
            } catch (Exception e) {
                String errMsg = "Error creating BPEL database";
                log.error(errMsg, e);
                throw new BPELEngineException(errMsg, e);
            }
        } else {
            if (log.isDebugEnabled()) {
                log.debug("BPEL database already exists. Using the old database.");
            }
        }
    }
    // In carbon, embedded H2 database for ODE is located at CARBON_HOME/repository/database
    String dbRoot = CarbonUtils.getCarbonHome() + File.separator + "repository" + File.separator + "database";
    File dbRootDir = new File(dbRoot);
    if (dbRootDir.exists() && dbRootDir.isDirectory()) {
        db.setWorkRoot(dbRootDir);
    } else {
        db.setWorkRoot(null);
    }
    try {
        db.start();
    } catch (Exception e) {
        String errMsg = "Error starting database connections, check the database configuration!";
        log.error(errMsg, e);
        throw new BPELEngineException(errMsg, e);
    }
}
Also used : Database(org.apache.ode.il.dbutil.Database) BPELDatabaseCreator(org.wso2.carbon.bpel.core.ode.integration.utils.BPELDatabaseCreator) File(java.io.File) InstanceAlreadyExistsException(javax.management.InstanceAlreadyExistsException) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanRegistrationException(javax.management.MBeanRegistrationException) BpelEngineException(org.apache.ode.bpel.iapi.BpelEngineException) DataSource(javax.sql.DataSource)

Aggregations

File (java.io.File)1 InstanceAlreadyExistsException (javax.management.InstanceAlreadyExistsException)1 MBeanRegistrationException (javax.management.MBeanRegistrationException)1 NotCompliantMBeanException (javax.management.NotCompliantMBeanException)1 DataSource (javax.sql.DataSource)1 BpelEngineException (org.apache.ode.bpel.iapi.BpelEngineException)1 Database (org.apache.ode.il.dbutil.Database)1 BPELDatabaseCreator (org.wso2.carbon.bpel.core.ode.integration.utils.BPELDatabaseCreator)1