Search in sources :

Example 11 with DBDatasourceServiceException

use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.

the class NonPooledDatasourceService method retrieve.

@Override
protected DataSource retrieve(String dsName) throws DBDatasourceServiceException {
    DataSource ds = null;
    try {
        IDatasourceMgmtService datasourceMgmtSvc = getDatasourceMgmtService();
        IDatabaseConnection databaseConnection = datasourceMgmtSvc.getDatasourceByName(dsName);
        if (databaseConnection != null) {
            ds = resolveDatabaseConnection(databaseConnection);
            if (ds != null) {
                cacheManager.putInRegionCache(IDBDatasourceService.JDBC_DATASOURCE, dsName, ds);
            }
        } else {
            throw new DBDatasourceServiceException(Messages.getInstance().getErrorString(// $NON-NLS-1$
            "DatasourceService.ERROR_0002_UNABLE_TO_GET_DATASOURCE"));
        }
    } catch (DatasourceMgmtServiceException daoe) {
        throw new DBDatasourceServiceException(Messages.getInstance().getErrorString("DatasourceService.ERROR_0002_UNABLE_TO_GET_DATASOURCE"), // $NON-NLS-1$
        daoe);
    }
    return ds;
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataSource(javax.sql.DataSource) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 12 with DBDatasourceServiceException

use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.

the class NonPooledOrJndiDatasourceService method retrieve.

@Override
protected DataSource retrieve(String dsName) throws DBDatasourceServiceException {
    DataSource ds = null;
    requestedDatasourceName = dsName;
    try {
        IDatasourceMgmtService datasourceMgmtSvc = getDatasourceMgmtService();
        IDatabaseConnection databaseConnection = datasourceMgmtSvc.getDatasourceByName(dsName);
        if (databaseConnection != null && !databaseConnection.getAccessType().equals(DatabaseAccessType.JNDI)) {
            ds = resolveDatabaseConnection(databaseConnection);
        // Database does not have the datasource, look in jndi now
        } else {
            try {
                ds = getJndiDataSource(dsName);
            } catch (DBDatasourceServiceException e) {
            // Ignore, Maybe jndi name is specified as database name in the connection
            }
        }
        if (ds == null && databaseConnection != null) {
            ds = getJndiDataSource(databaseConnection.getDatabaseName());
        }
        // if the resulting datasource is not null then store it in the cache
        if (ds != null) {
            cacheManager.putInRegionCache(IDBDatasourceService.JDBC_DATASOURCE, dsName, ds);
        }
    } catch (DatasourceMgmtServiceException daoe) {
        log.debug(Messages.getInstance().getErrorString("DatasourceService.DEBUG_0001_UNABLE_TO_FIND_DATASOURCE_IN_REPOSITORY", daoe.getLocalizedMessage()), daoe);
        try {
            return getJndiDataSource(dsName);
        } catch (DBDatasourceServiceException dse) {
            throw new DBDatasourceServiceException(Messages.getInstance().getErrorString("DatasourceService.ERROR_0003_UNABLE_TO_GET_JNDI_DATASOURCE"), // $NON-NLS-1$
            dse);
        }
    }
    return ds;
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) IDatabaseConnection(org.pentaho.database.model.IDatabaseConnection) DataSource(javax.sql.DataSource) IDatasourceMgmtService(org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService) DatasourceMgmtServiceException(org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)

Example 13 with DBDatasourceServiceException

use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.

the class PooledDatasourceHelper method setupPooledDataSource.

public static PoolingDataSource setupPooledDataSource(IDatabaseConnection databaseConnection) throws DBDatasourceServiceException {
    PoolingDataSource poolingDataSource = null;
    String driverClass = null;
    String url = null;
    try {
        if (databaseConnection.getAccessType().equals(DatabaseAccessType.JNDI)) {
            throw new DBDatasourceServiceException(Messages.getInstance().getErrorString("PooledDatasourceHelper.ERROR_0008_UNABLE_TO_POOL_DATASOURCE_IT_IS_JNDI", databaseConnection.getName()));
        }
        ICacheManager cacheManager = PentahoSystem.getCacheManager(null);
        IDatabaseDialectService databaseDialectService = PentahoSystem.get(IDatabaseDialectService.class);
        if (databaseDialectService == null) {
            throw new DBDatasourceServiceException(Messages.getInstance().getErrorString("PooledDatasourceHelper.ERROR_0005_UNABLE_TO_POOL_DATASOURCE_NO_DIALECT_SERVICE", databaseConnection.getName()));
        }
        IDatabaseDialect dialect = databaseDialectService.getDialect(databaseConnection);
        if (dialect == null || dialect.getDatabaseType() == null) {
            throw new DBDatasourceServiceException(Messages.getInstance().getErrorString("PooledDatasourceHelper.ERROR_0004_UNABLE_TO_POOL_DATASOURCE_NO_DIALECT", databaseConnection.getName()));
        }
        if (databaseConnection.getDatabaseType().getShortName().equals("GENERIC")) {
            // $NON-NLS-1$
            driverClass = databaseConnection.getAttributes().get(GenericDatabaseDialect.ATTRIBUTE_CUSTOM_DRIVER_CLASS);
            if (StringUtils.isEmpty(driverClass)) {
                throw new DBDatasourceServiceException(Messages.getInstance().getErrorString("PooledDatasourceHelper.ERROR_0006_UNABLE_TO_POOL_DATASOURCE_NO_CLASSNAME", databaseConnection.getName()));
            }
        } else {
            driverClass = dialect.getNativeDriver();
            if (StringUtils.isEmpty(driverClass)) {
                throw new DBDatasourceServiceException(Messages.getInstance().getErrorString("PooledDatasourceHelper.ERROR_0007_UNABLE_TO_POOL_DATASOURCE_NO_DRIVER", databaseConnection.getName()));
            }
        }
        try {
            url = dialect.getURLWithExtraOptions(databaseConnection);
        } catch (DatabaseDialectException e) {
            url = null;
        }
        // Read default connection pooling parameter
        // $NON-NLS-1$
        String maxdleConn = PentahoSystem.getSystemSetting("dbcp-defaults/max-idle-conn", null);
        // $NON-NLS-1$
        String minIdleConn = PentahoSystem.getSystemSetting("dbcp-defaults/min-idle-conn", null);
        // $NON-NLS-1$
        String maxActConn = PentahoSystem.getSystemSetting("dbcp-defaults/max-act-conn", null);
        String validQuery = null;
        // $NON-NLS-1$
        String whenExhaustedAction = PentahoSystem.getSystemSetting("dbcp-defaults/when-exhausted-action", null);
        // $NON-NLS-1$
        String wait = PentahoSystem.getSystemSetting("dbcp-defaults/wait", null);
        // $NON-NLS-1$
        String testWhileIdleValue = PentahoSystem.getSystemSetting("dbcp-defaults/test-while-idle", null);
        // $NON-NLS-1$
        String testOnBorrowValue = PentahoSystem.getSystemSetting("dbcp-defaults/test-on-borrow", null);
        // $NON-NLS-1$
        String testOnReturnValue = PentahoSystem.getSystemSetting("dbcp-defaults/test-on-return", null);
        // property initialization
        boolean testWhileIdle = !StringUtil.isEmpty(testWhileIdleValue) ? Boolean.parseBoolean(testWhileIdleValue) : false;
        boolean testOnBorrow = !StringUtil.isEmpty(testOnBorrowValue) ? Boolean.parseBoolean(testOnBorrowValue) : false;
        boolean testOnReturn = !StringUtil.isEmpty(testOnReturnValue) ? Boolean.parseBoolean(testOnReturnValue) : false;
        int maxActiveConnection = !StringUtil.isEmpty(maxActConn) ? Integer.parseInt(maxActConn) : -1;
        long waitTime = !StringUtil.isEmpty(wait) ? Integer.parseInt(wait) : -1;
        byte whenExhaustedActionType = !StringUtil.isEmpty(whenExhaustedAction) ? Byte.parseByte(whenExhaustedAction) : GenericObjectPool.WHEN_EXHAUSTED_BLOCK;
        int minIdleConnection = !StringUtil.isEmpty(minIdleConn) ? Integer.parseInt(minIdleConn) : -1;
        int maxIdleConnection = !StringUtil.isEmpty(maxdleConn) ? Integer.parseInt(maxdleConn) : -1;
        // setting properties according to user specifications
        Map<String, String> attributes = databaseConnection.getConnectionPoolingProperties();
        if (attributes.containsKey(IDBDatasourceService.MAX_ACTIVE_KEY) && NumberUtils.isNumber(attributes.get(IDBDatasourceService.MAX_ACTIVE_KEY))) {
            maxActiveConnection = Integer.parseInt(attributes.get(IDBDatasourceService.MAX_ACTIVE_KEY));
        }
        if (attributes.containsKey(IDBDatasourceService.MAX_WAIT_KEY) && NumberUtils.isNumber(attributes.get(IDBDatasourceService.MAX_WAIT_KEY))) {
            waitTime = Integer.parseInt(attributes.get(IDBDatasourceService.MAX_WAIT_KEY));
        }
        if (attributes.containsKey(IDBDatasourceService.MIN_IDLE_KEY) && NumberUtils.isNumber(attributes.get(IDBDatasourceService.MIN_IDLE_KEY))) {
            minIdleConnection = Integer.parseInt(attributes.get(IDBDatasourceService.MIN_IDLE_KEY));
        }
        if (attributes.containsKey(IDBDatasourceService.MAX_IDLE_KEY) && NumberUtils.isNumber(attributes.get(IDBDatasourceService.MAX_IDLE_KEY))) {
            maxIdleConnection = Integer.parseInt(attributes.get(IDBDatasourceService.MAX_IDLE_KEY));
        }
        if (attributes.containsKey(IDBDatasourceService.QUERY_KEY)) {
            validQuery = attributes.get(IDBDatasourceService.QUERY_KEY);
        }
        if (attributes.containsKey(IDBDatasourceService.TEST_ON_BORROW)) {
            testOnBorrow = Boolean.parseBoolean(attributes.get(IDBDatasourceService.TEST_ON_BORROW));
        }
        if (attributes.containsKey(IDBDatasourceService.TEST_ON_RETURN)) {
            testOnReturn = Boolean.parseBoolean(attributes.get(IDBDatasourceService.TEST_ON_RETURN));
        }
        if (attributes.containsKey(IDBDatasourceService.TEST_WHILE_IDLE)) {
            testWhileIdle = Boolean.parseBoolean(attributes.get(IDBDatasourceService.TEST_WHILE_IDLE));
        }
        poolingDataSource = new PoolingDataSource();
        if (dialect instanceof IDriverLocator) {
            if (!((IDriverLocator) dialect).initialize(driverClass)) {
                throw new DriverNotInitializedException(Messages.getInstance().getErrorString("PooledDatasourceHelper.ERROR_0009_UNABLE_TO_POOL_DATASOURCE_CANT_INITIALIZE", databaseConnection.getName(), driverClass));
            }
        } else {
            Class.forName(driverClass);
        }
        // As the name says, this is a generic pool; it returns basic Object-class objects.
        GenericObjectPool pool = new GenericObjectPool(null);
        // if removedAbandoned = true, then an AbandonedObjectPool object will take GenericObjectPool's place
        if (attributes.containsKey(IDBDatasourceService.REMOVE_ABANDONED) && true == Boolean.parseBoolean(attributes.get(IDBDatasourceService.REMOVE_ABANDONED))) {
            AbandonedConfig config = new AbandonedConfig();
            config.setRemoveAbandoned(Boolean.parseBoolean(attributes.get(IDBDatasourceService.REMOVE_ABANDONED)));
            if (attributes.containsKey(IDBDatasourceService.LOG_ABANDONED)) {
                config.setLogAbandoned(Boolean.parseBoolean(attributes.get(IDBDatasourceService.LOG_ABANDONED)));
            }
            if (attributes.containsKey(IDBDatasourceService.REMOVE_ABANDONED_TIMEOUT) && NumberUtils.isNumber(attributes.get(IDBDatasourceService.REMOVE_ABANDONED_TIMEOUT))) {
                config.setRemoveAbandonedTimeout(Integer.parseInt(attributes.get(IDBDatasourceService.REMOVE_ABANDONED_TIMEOUT)));
            }
            pool = new AbandonedObjectPool(null, config);
        }
        pool.setWhenExhaustedAction(whenExhaustedActionType);
        // Tuning the connection pool
        pool.setMaxActive(maxActiveConnection);
        pool.setMaxIdle(maxIdleConnection);
        pool.setMaxWait(waitTime);
        pool.setMinIdle(minIdleConnection);
        pool.setTestWhileIdle(testWhileIdle);
        pool.setTestOnReturn(testOnReturn);
        pool.setTestOnBorrow(testOnBorrow);
        pool.setTestWhileIdle(testWhileIdle);
        if (attributes.containsKey(IDBDatasourceService.TIME_BETWEEN_EVICTION_RUNS_MILLIS) && NumberUtils.isNumber(attributes.get(IDBDatasourceService.TIME_BETWEEN_EVICTION_RUNS_MILLIS))) {
            pool.setTimeBetweenEvictionRunsMillis(Long.parseLong(attributes.get(IDBDatasourceService.TIME_BETWEEN_EVICTION_RUNS_MILLIS)));
        }
        /*
       * ConnectionFactory creates connections on behalf of the pool. Here, we use the DriverManagerConnectionFactory
       * because that essentially uses DriverManager as the source of connections.
       */
        ConnectionFactory factory = null;
        if (url.startsWith("jdbc:mysql:") || (url.startsWith("jdbc:mariadb:"))) {
            Properties props = new Properties();
            props.put("user", databaseConnection.getUsername());
            props.put("password", databaseConnection.getPassword());
            props.put("socketTimeout", "0");
            props.put("connectTimeout", "5000");
            factory = new DriverManagerConnectionFactory(url, props);
        } else {
            factory = new DriverManagerConnectionFactory(url, databaseConnection.getUsername(), databaseConnection.getPassword());
        }
        boolean defaultReadOnly = attributes.containsKey(IDBDatasourceService.DEFAULT_READ_ONLY) ? Boolean.parseBoolean(attributes.get(IDBDatasourceService.TEST_WHILE_IDLE)) : // default to false
        false;
        boolean defaultAutoCommit = attributes.containsKey(IDBDatasourceService.DEFAULT_AUTO_COMMIT) ? Boolean.parseBoolean(attributes.get(IDBDatasourceService.DEFAULT_AUTO_COMMIT)) : // default to true
        true;
        KeyedObjectPoolFactory kopf = null;
        if (attributes.containsKey(IDBDatasourceService.POOL_PREPARED_STATEMENTS) && true == Boolean.parseBoolean(attributes.get(IDBDatasourceService.POOL_PREPARED_STATEMENTS))) {
            // unlimited
            int maxOpenPreparedStatements = -1;
            if (attributes.containsKey(IDBDatasourceService.MAX_OPEN_PREPARED_STATEMENTS) && NumberUtils.isNumber(attributes.get(IDBDatasourceService.MAX_OPEN_PREPARED_STATEMENTS))) {
                maxOpenPreparedStatements = Integer.parseInt(attributes.get(IDBDatasourceService.MAX_OPEN_PREPARED_STATEMENTS));
            }
            kopf = new GenericKeyedObjectPoolFactory(null, pool.getMaxActive(), pool.getWhenExhaustedAction(), pool.getMaxWait(), pool.getMaxIdle(), maxOpenPreparedStatements);
        }
        /*
       * Puts pool-specific wrappers on factory connections. For clarification: "[PoolableConnection]Factory," not
       * "Poolable[ConnectionFactory]."
       */
        PoolableConnectionFactory pcf = new PoolableConnectionFactory(// ConnectionFactory
        factory, // ObjectPool
        pool, // KeyedObjectPoolFactory
        kopf, // String (validation query)
        validQuery, // boolean (default to read-only?)
        defaultReadOnly, // boolean (default to auto-commit statements?)
        defaultAutoCommit);
        if (attributes.containsKey(IDBDatasourceService.DEFAULT_TRANSACTION_ISOLATION) && !IDBDatasourceService.TRANSACTION_ISOLATION_NONE_VALUE.equalsIgnoreCase(attributes.get(IDBDatasourceService.DEFAULT_TRANSACTION_ISOLATION))) {
            Isolation isolationLevel = Isolation.valueOf(attributes.get(IDBDatasourceService.DEFAULT_TRANSACTION_ISOLATION));
            if (isolationLevel != null) {
                pcf.setDefaultTransactionIsolation(isolationLevel.value());
            }
        }
        if (attributes.containsKey(IDBDatasourceService.DEFAULT_CATALOG)) {
            pcf.setDefaultCatalog(attributes.get(IDBDatasourceService.DEFAULT_CATALOG));
        }
        /*
       * initialize the pool to X connections
       */
        Logger.debug(PooledDatasourceHelper.class, "Pool defaults to " + maxActiveConnection + " max active/" + maxIdleConnection + "max idle" + "with " + waitTime + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
        "wait time" + // $NON-NLS-1$
        " idle connections.");
        String prePopulatePoolStr = PentahoSystem.getSystemSetting("dbcp-defaults/pre-populate-pool", null);
        if (Boolean.parseBoolean(prePopulatePoolStr)) {
            for (int i = 0; i < maxIdleConnection; ++i) {
                pool.addObject();
            }
            if (Logger.getLogLevel() <= ILogger.DEBUG) {
                Logger.debug(PooledDatasourceHelper.class, "Pool has been pre-populated with " + maxIdleConnection + " connections");
            }
        }
        Logger.debug(PooledDatasourceHelper.class, "Pool now has " + pool.getNumActive() + " active/" + pool.getNumIdle() + // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
        " idle connections.");
        /*
       * All of this is wrapped in a DataSource, which client code should already know how to handle (since it's the
       * same class of object they'd fetch via the container's JNDI tree
       */
        poolingDataSource.setPool(pool);
        if (attributes.containsKey(IDBDatasourceService.ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED)) {
            poolingDataSource.setAccessToUnderlyingConnectionAllowed(Boolean.parseBoolean(attributes.get(IDBDatasourceService.ACCESS_TO_UNDERLYING_CONNECTION_ALLOWED)));
        }
        // store the pool, so we can get to it later
        cacheManager.putInRegionCache(IDBDatasourceService.JDBC_POOL, databaseConnection.getName(), pool);
        return (poolingDataSource);
    } catch (Exception e) {
        throw new DBDatasourceServiceException(e);
    }
}
Also used : AbandonedConfig(org.apache.commons.dbcp.AbandonedConfig) DriverManagerConnectionFactory(org.apache.commons.dbcp.DriverManagerConnectionFactory) IDatabaseDialect(org.pentaho.database.IDatabaseDialect) IDatabaseDialectService(org.pentaho.database.service.IDatabaseDialectService) Properties(java.util.Properties) GenericKeyedObjectPoolFactory(org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory) KeyedObjectPoolFactory(org.apache.commons.pool.KeyedObjectPoolFactory) PoolableConnectionFactory(org.apache.commons.dbcp.PoolableConnectionFactory) ConnectionFactory(org.apache.commons.dbcp.ConnectionFactory) DriverManagerConnectionFactory(org.apache.commons.dbcp.DriverManagerConnectionFactory) PoolableConnectionFactory(org.apache.commons.dbcp.PoolableConnectionFactory) PoolingDataSource(org.apache.commons.dbcp.PoolingDataSource) AbandonedObjectPool(org.apache.commons.dbcp.AbandonedObjectPool) GenericObjectPool(org.apache.commons.pool.impl.GenericObjectPool) NamingException(javax.naming.NamingException) DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) DatabaseDialectException(org.pentaho.database.DatabaseDialectException) GenericKeyedObjectPoolFactory(org.apache.commons.pool.impl.GenericKeyedObjectPoolFactory) DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) DatabaseDialectException(org.pentaho.database.DatabaseDialectException) Isolation(org.springframework.transaction.annotation.Isolation) ICacheManager(org.pentaho.platform.api.engine.ICacheManager) IDriverLocator(org.pentaho.database.IDriverLocator)

Example 14 with DBDatasourceServiceException

use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.

the class PentahoDataSourceResolver method lookup.

public DataSource lookup(String dataSourceName) throws Exception {
    javax.sql.DataSource datasource = null;
    String unboundDsName = null;
    IDBDatasourceService datasourceSvc = null;
    try {
        datasourceSvc = PentahoSystem.getObjectFactory().get(IDBDatasourceService.class, PentahoSessionHolder.getSession());
        unboundDsName = datasourceSvc.getDSUnboundName(dataSourceName);
        datasource = datasourceSvc.getDataSource(unboundDsName);
    } catch (ObjectFactoryException e) {
        // $NON-NLS-1$
        logger.error(Messages.getInstance().getErrorString("PentahoXmlaServlet.ERROR_0002_UNABLE_TO_INSTANTIATE"), e);
        throw e;
    } catch (DBDatasourceServiceException e) {
        /* We tried to find the datasource using unbound name. 
      ** Now as a fall back we will attempt to find this datasource as it is.
      ** For example jboss/datasource/Hibernate. The unbound name ends up to be Hibernate
      ** We will first look for Hibernate and if we fail then look for jboss/datasource/Hibernate */
        logger.warn(Messages.getInstance().getString("PentahoXmlaServlet.WARN_0001_UNABLE_TO_FIND_UNBOUND_NAME", dataSourceName, unboundDsName), // $NON-NLS-1$
        e);
        try {
            datasource = datasourceSvc.getDataSource(dataSourceName);
        } catch (DBDatasourceServiceException dbse) {
            logger.error(Messages.getInstance().getErrorString("PentahoXmlaServlet.ERROR_0002_UNABLE_TO_INSTANTIATE"), // $NON-NLS-1$
            e);
            throw dbse;
        }
    }
    return datasource;
}
Also used : DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) DataSource(javax.sql.DataSource) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService)

Example 15 with DBDatasourceServiceException

use of org.pentaho.platform.api.data.DBDatasourceServiceException in project pentaho-platform by pentaho.

the class EmbeddedQuartzSystemListener method startup.

public boolean startup(final IPentahoSession session) {
    boolean result = true;
    Properties quartzProps = null;
    if (quartzPropertiesFile != null) {
        quartzProps = PentahoSystem.getSystemSettings().getSystemSettingsProperties(quartzPropertiesFile);
    } else if (quartzProperties != null) {
        quartzProps = quartzProperties;
    }
    try {
        if (quartzProps == null) {
            quartzProps = findPropertiesInClasspath();
        }
        if (quartzProps == null) {
            result = false;
        } else {
            // $NON-NLS-1$
            String dsName = quartzProps.getProperty("org.quartz.dataSource.myDS.jndiURL");
            if (dsName != null) {
                IDBDatasourceService datasourceService = getQuartzDatasourceService(session);
                String boundDsName = datasourceService.getDSBoundName(dsName);
                if (boundDsName != null) {
                    // $NON-NLS-1$
                    quartzProps.setProperty("org.quartz.dataSource.myDS.jndiURL", boundDsName);
                }
                DataSource ds = datasourceService.getDataSource(dsName);
                result = verifyQuartzIsConfigured(ds);
            }
            // $NON-NLS-1$
            QuartzScheduler scheduler = (QuartzScheduler) PentahoSystem.get(IScheduler.class, "IScheduler2", null);
            if (logger.isDebugEnabled()) {
                // $NON-NLS-1$
                logger.debug("Quartz configured with properties");
                // $NON-NLS-1$
                quartzProps.store(System.out, "debugging");
            }
            scheduler.setQuartzSchedulerFactory(new org.quartz.impl.StdSchedulerFactory(quartzProps));
            if (logger.isDebugEnabled()) {
                logger.debug(scheduler.getQuartzScheduler().getSchedulerName());
            }
            scheduler.start();
        }
    } catch (IOException ex) {
        result = false;
        logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0004_LOAD_PROPERTIES_FROM_CLASSPATH"), // $NON-NLS-1$
        ex);
    } catch (ObjectFactoryException objface) {
        logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0005_UNABLE_TO_INSTANTIATE_OBJECT", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
        objface);
        result = false;
    } catch (DBDatasourceServiceException dse) {
        logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0006_UNABLE_TO_GET_DATASOURCE", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
        dse);
        result = false;
    } catch (SQLException sqle) {
        // $NON-NLS-1$
        logger.error("EmbeddedQuartzSystemListener.ERROR_0007_SQLERROR", sqle);
        result = false;
    } catch (SchedulerException e) {
        logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0001_Scheduler_Not_Initialized", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
        e);
        result = false;
    } catch (org.pentaho.platform.api.scheduler2.SchedulerException e) {
        logger.error(Messages.getInstance().getErrorString("EmbeddedQuartzSystemListener.ERROR_0001_Scheduler_Not_Initialized", EmbeddedQuartzSystemListener.class.getName()), // $NON-NLS-1$
        e);
        result = false;
    }
    return result;
}
Also used : SchedulerException(org.quartz.SchedulerException) SQLException(java.sql.SQLException) IOException(java.io.IOException) Properties(java.util.Properties) IDBDatasourceService(org.pentaho.platform.api.data.IDBDatasourceService) DataSource(javax.sql.DataSource) DBDatasourceServiceException(org.pentaho.platform.api.data.DBDatasourceServiceException) ObjectFactoryException(org.pentaho.platform.api.engine.ObjectFactoryException) IScheduler(org.pentaho.platform.api.scheduler2.IScheduler)

Aggregations

DBDatasourceServiceException (org.pentaho.platform.api.data.DBDatasourceServiceException)22 IDatabaseConnection (org.pentaho.database.model.IDatabaseConnection)11 DataSource (javax.sql.DataSource)9 Test (org.junit.Test)7 IDatabaseDialectService (org.pentaho.database.service.IDatabaseDialectService)6 HashMap (java.util.HashMap)5 Matchers.containsString (org.hamcrest.Matchers.containsString)5 DatabaseConnection (org.pentaho.database.model.DatabaseConnection)5 DatabaseDialectService (org.pentaho.database.service.DatabaseDialectService)5 IDBDatasourceService (org.pentaho.platform.api.data.IDBDatasourceService)5 DatasourceMgmtServiceException (org.pentaho.platform.api.repository.datasource.DatasourceMgmtServiceException)5 IDatasourceMgmtService (org.pentaho.platform.api.repository.datasource.IDatasourceMgmtService)5 NamingException (javax.naming.NamingException)3 Before (org.junit.Before)3 DatabaseTypeHelper (org.pentaho.database.util.DatabaseTypeHelper)3 ObjectFactoryException (org.pentaho.platform.api.engine.ObjectFactoryException)3 SQLException (java.sql.SQLException)2 Properties (java.util.Properties)2 InitialContext (javax.naming.InitialContext)2 PoolingDataSource (org.apache.commons.dbcp.PoolingDataSource)2