Example usage for java.sql DriverManager getDriver

List of usage examples for java.sql DriverManager getDriver

Introduction

In this page you can find the example usage for java.sql DriverManager getDriver.

Prototype

@CallerSensitive
public static Driver getDriver(String url) throws SQLException 

Source Link

Document

Attempts to locate a driver that understands the given URL.

Usage

From source file:de.innovationgate.wgpublisher.WGACore.java

public void shutdown() {

    logCategoryInfo(WGAVersion.WGAPUBLISHER_PRODUCT_NAME + " starting shutdown...", 1);

    fireCoreEvent(new WGACoreEvent(WGACoreEvent.TYPE_PRE_SHUTDOWN, null, this));

    logCategoryInfo("Disabling dispatcher", 2);

    WGPDispatcher dispatcher = getDispatcher();
    if (dispatcher != null) {
        dispatcher.setServePages(false);
    }/*from   w w w  .j a  v  a  2 s. c  om*/

    // Clear listeners whose actions are no longer needed on shutdown
    _moduleRegistry.clearChangeListeners();

    // Shutdown various platform services (db-independent)
    logCategoryInfo("Shutting down platform services", 2);
    getLog().info("Shutting down scheduler");
    try {
        _quartzScheduler.shutdown(true);
    } catch (SchedulerException e) {
        getLog().error("Exception shutting down WGA scheduler", e);
    }
    _quartzScheduler = null;

    if (this.timer != null) {
        this.timer.shutdown();
        this.timer = null;
    }

    getLog().info("Shutting down lucene");
    if (this.luceneManager != null) {
        this.luceneManager.destroy();
        this.luceneManager = null;
    }

    this.fileDerivateManager.stop();
    this.fileDerivateManager = null;

    getLog().info("Shutting down WebSocket connections");
    _pageConnectionManager.shutdown();
    _independentWebSocketManager.shutdown();

    getLog().info("Shutting down event manager");
    _eventManager.shutdown();

    if (_clusterService != null) {
        _clusterService.shutdown();
        _clusterService = null;
    }

    if (_externalFileMaintenanceTask != null) {
        _externalFileMaintenanceTask.stop();
        _externalFileMaintenanceTask = null;
    }

    // Stop the event thread
    getLog().info("Shutting down event thread");
    WGFactory.getInstance().getEventThread().stop();

    // fire pre disconnect event
    fireCoreEvent(new WGACoreEvent(WGACoreEvent.TYPE_SHUTDOWN_PRE_DISCONNECT, null, this));

    logCategoryInfo("Closing content databases", 2);

    // Close content databases
    Iterator<String> dbs = new HashSet<String>(this.contentdbs.keySet()).iterator();
    while (dbs.hasNext()) {
        removeContentDB(dbs.next());
    }

    logCategoryInfo("Closing personalisation databases", 2);

    // Close personalisation databases
    dbs = new HashSet<String>(this.personalisationdbs.keySet()).iterator();
    while (dbs.hasNext()) {
        removePersonalisationDB(dbs.next());
    }

    logCategoryInfo("Closing domains", 2);

    // Close domains (especially their auth modules)
    closeDomainConfigs(this.domains);

    logCategoryInfo("Shutting down basic services", 2);

    unDeployErrorPage();

    WGHierarchicalDatabase.removeCoreListener(_hdbCoreListener);

    // fire post disconnect event
    fireCoreEvent(new WGACoreEvent(WGACoreEvent.TYPE_SHUTDOWN_POST_DISCONNECT, null, this));

    if (_httpSessionManager != null) {
        _httpSessionManager.clearListeners();
        _httpSessionManager.shutdown();
    }

    // Close integrated JMX
    _jmx.shutdown();
    _jmx = null;

    // Close access logger
    if (_accessLogger != null) {
        _accessLogger.close();
    }

    // Cleanup deployer
    _deployer.shutdown();

    // Cleanup WebTML cache
    try {
        _webTMLCache.close();
        _webTMLCache = null;
    } catch (CacheException e) {
        getLog().error("Exception shutting down WebTML cache", e);
    }

    // Cleanup statistics
    if (_usageStatistics != null) {
        _usageStatistics.dispose();
        _usageStatistics = null;
    }

    // Remove all core listeners
    coreEventListeners.clear();

    // Close expression engines and WGA classpath
    ExpressionEngineFactory.closeEngines();
    libraryClassLoadingChain = null;

    // Clear and close caches
    WGFactory.getAuthModuleFactory().clearCache();
    try {
        designFileCache.destroy();
        designFileCache = null;
    } catch (CacheException e) {
        log.error("Exception closing design file cache", e);
    }

    try {
        _calledSequenceIds.destroy();
        _calledSequenceIds = null;
    } catch (CacheException e) {
        log.error("Exception closing action sequence id cache", e);
    }
    EHCacheCore.getCacheManager().shutdown();

    // Unregister HSQLDB driver
    try {
        DriverManager.deregisterDriver(DriverManager.getDriver("jdbc:hsqldb:mem:justShuttingDown"));
    } catch (SQLException e1) {
        getLog().error("Exception de-registering HSQL driver", e1);
    }

    // Close logserver
    if (_logServer != null) {
        try {
            _logServer.shutdown();
        } catch (IOException e) {
            getLog().error("Exception shutting down WGA Remote Log Server", e);
        }
        _logServer = null;
    }

    _problemRegistry.close();
    _problemRegistry = null;

    TemporaryFile.stopEviction();

    fireCoreEvent(new WGACoreEvent(WGACoreEvent.TYPE_POST_SHUTDOWN, null, this));
    logCategoryInfo(WGAVersion.WGAPUBLISHER_PRODUCT_NAME + " finished shutdown", 1);
}

From source file:net.sourceforge.vulcan.web.dbcp.UnregisteringBasicDataSource.java

@Override
public synchronized void close() throws SQLException {
    super.close();

    DriverManager.deregisterDriver(DriverManager.getDriver(getUrl()));
}

From source file:net.ymate.platform.persistence.jdbc.AbstractDataSourceAdapter.java

public void destroy() {
    if (__inited) {
        __inited = false;/*www.jav a 2 s .c  om*/
        //
        try {
            DriverManager.deregisterDriver(DriverManager.getDriver(__cfgMeta.getConnectionUrl()));
        } catch (SQLException e) {
            _LOG.warn("", e);
        }
        //
        __cfgMeta = null;
        __dialect = null;
    }
}

From source file:orca.util.db.MySqlBase.java

/**
 * Deregister the sun ODBC bridge driver. We don't need it and it is broken
 * on some platforms//from  w w w .j  ava  2 s. com
 */
protected void checkDrivers() {
    try {
        logger.debug(DriverManager.getDriver(source + pool));

        Enumeration<Driver> drivers = DriverManager.getDrivers();
        Driver odbcDriver;

        if ((odbcDriver = drivers.nextElement()) != null) {
            if (odbcDriver.getClass().getName().matches(".*odbc.*")) {
                DriverManager.deregisterDriver(odbcDriver);
                logger.debug("Deregistering " + odbcDriver);
            }
        }
    } catch (Exception e) {
    }
}

From source file:org.agnitas.dao.LoggingEnhBasicDataSource.java

/**
  * <p>Create (if necessary) and return the internal data source we are
  * using to manage our connections.</p>
  */*from w  ww  . j av  a 2  s .c om*/
  * <p><strong>IMPLEMENTATION NOTE</strong> - It is tempting to use the
  * "double checked locking" idiom in an attempt to avoid synchronizing
  * on every single call to this method.  However, this idiom fails to
  * work correctly in the face of some optimizations that are legal for
  * a JVM to perform.</p>
  *
  * @exception SQLException if the object pool cannot be created.
  */
protected synchronized DataSource createDataSource() throws SQLException {

    // Return the pool if we have already created it
    if (dataSource != null) {
        return (dataSource);
    }

    logger.error("-------------------------------------------- Create new datasource");
    // Load the JDBC driver class
    if (driverClassName != null) {
        try {
            Class.forName(driverClassName);
        } catch (Throwable t) {
            String message = "Cannot load JDBC driver class '" + driverClassName + "'";
            logWriter.println(message);
            t.printStackTrace(logWriter);
            throw new SQLNestedException(message, t);
        }
    }

    // Create a JDBC driver instance
    Driver driver = null;
    try {
        driver = DriverManager.getDriver(url);
    } catch (Throwable t) {
        String message = "Cannot create JDBC driver of class '"
                + (driverClassName != null ? driverClassName : "") + "' for connect URL '" + url + "'";
        logWriter.println(message);
        t.printStackTrace(logWriter);
        throw new SQLNestedException(message, t);
    }

    // Can't test without a validationQuery
    if (validationQuery == null) {
        setTestOnBorrow(false);
        setTestOnReturn(false);
        setTestWhileIdle(false);
    }

    // Create an object pool to contain our active connections
    connectionPool = new LoggingObjectPool();
    connectionPool.setMaxActive(maxActive);
    connectionPool.setMaxIdle(maxIdle);
    connectionPool.setMinIdle(minIdle);
    connectionPool.setMaxWait(maxWait);
    connectionPool.setTestOnBorrow(testOnBorrow);
    connectionPool.setTestOnReturn(testOnReturn);
    connectionPool.setTimeBetweenEvictionRunsMillis(timeBetweenEvictionRunsMillis);
    connectionPool.setNumTestsPerEvictionRun(numTestsPerEvictionRun);
    connectionPool.setMinEvictableIdleTimeMillis(minEvictableIdleTimeMillis);
    connectionPool.setTestWhileIdle(testWhileIdle);

    // Set up statement pool, if desired
    GenericKeyedObjectPoolFactory statementPoolFactory = null;
    if (isPoolPreparedStatements()) {
        statementPoolFactory = new GenericKeyedObjectPoolFactory(null, -1, // unlimited maxActive (per key)
                GenericKeyedObjectPool.WHEN_EXHAUSTED_FAIL, 0, // maxWait
                1, // maxIdle (per key) 
                maxOpenPreparedStatements);
    }

    // Set up the driver connection factory we will use
    if (username != null) {
        connectionProperties.put("user", username);
    } else {
        logger.error("DBCP DataSource configured without a 'username'");
    }

    if (password != null) {
        connectionProperties.put("password", password);
    } else {
        logger.error("DBCP DataSource configured without a 'password'");
    }

    DriverConnectionFactory driverConnectionFactory = new DriverConnectionFactory(driver, url,
            connectionProperties);

    // Set up the poolable connection factory we will use
    PoolableConnectionFactory connectionFactory = null;
    try {
        connectionFactory = new PoolableConnectionFactory(driverConnectionFactory, connectionPool,
                statementPoolFactory, validationQuery, defaultReadOnly, defaultAutoCommit,
                defaultTransactionIsolation, defaultCatalog, null);
        if (connectionFactory == null) {
            throw new SQLException("Cannot create PoolableConnectionFactory");
        }
        validateConnectionFactory(connectionFactory);
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new SQLNestedException("Cannot create PoolableConnectionFactory (" + e.getMessage() + ")", e);
    }

    // Create and return the pooling data source to manage the connections
    dataSource = new PoolingDataSource(connectionPool);
    ((PoolingDataSource) dataSource)
            .setAccessToUnderlyingConnectionAllowed(isAccessToUnderlyingConnectionAllowed());
    dataSource.setLogWriter(logWriter);

    try {
        for (int i = 0; i < initialSize; i++) {
            connectionPool.addObject();
        }
    } catch (Exception e) {
        throw new SQLNestedException("Error preloading the connection pool", e);
    }

    return dataSource;
}

From source file:org.apache.avalon.dbcp.DbcpConnectionManager.java

/**
 * Initialization of the component by the container.
 * // w  ww  .jav a 2s  . co  m
 * @throws Exception if an error occurs while initializing
 * the component
 */
public void initialize() throws Exception {
    m_logger.debug("Initializing...");

    // First, let's load the DBCP's pooling driver class
    m_logger.debug("Loading DBCP Pooling Driver class...");
    Class.forName("org.apache.commons.dbcp.PoolingDriver");

    // loop through all the configured datasources...
    for (int i = 0; i < m_datasources.length; i++) {
        // this is the next datasource configuration object to process
        Configuration datasource = m_datasources[i];
        String name = datasource.getAttribute("name");
        boolean isDefault = datasource.getAttributeAsBoolean("default", false);
        m_logger.debug("Processing datasource [" + name + "]" + " (default=" + isDefault + ")");

        // create an object pool that will actually hold our connections
        ObjectPool connectionPool = createObjectPool();
        m_logger.debug("Object pool created...");

        // load the underlying JDBC driver of the datasource
        loadJDBCDriver(datasource);
        m_logger.debug("Underlying JDBC driver loaded...");

        // create a driver manager connection factory that will be
        // used to actually create the database connection(s)
        ConnectionFactory connectionFactory = createConnectionFactory(datasource);
        m_logger.debug("Connection factory created...");

        // create a poolable connection factory wrapper
        PoolableConnectionFactory poolableConnectionFactory = createPoolableConnectionFactory(connectionFactory,
                connectionPool, datasource);
        m_logger.debug("Poolable connection factory created...");

        // get an instance of the DBCP pooling driver... 
        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
        m_logger.debug("Pooling driver instance obtained...");

        // register our pool with it...
        driver.registerPool(name, connectionPool);

        // is this the default datasource?
        if (isDefault) {
            driver.registerPool("default", connectionPool);
        }
    }
}

From source file:org.apache.avalon.dbcp.DbcpConnectionManager.java

/**
 *  Cleans up the component. //from  w  w w .j ava  2  s.  c o  m
 */
public void dispose() {
    try {
        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver("jdbc:apache:commons:dbcp:");
        // loop through all the configured datasources...
        for (int i = 0; i < m_datasources.length; i++) {
            Configuration datasource = m_datasources[i];
            String name = datasource.getAttribute("name");
            driver.closePool(name);
        }
    } catch (Exception e) {
        m_logger.warn(e.getMessage());
    }
}

From source file:org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCachePoolAccess.java

/**
 * How many are idle in the pool./*from  w w  w  .  j a  va  2 s.c om*/
 * <p>
 * @return number idle
 */
public int getNumIdleInPool() {
    int numIdle = 0;
    try {
        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(DRIVER_NAME);
        ObjectPool connectionPool = driver.getConnectionPool(this.getPoolName());

        if (log.isDebugEnabled()) {
            log.debug(connectionPool);
        }
        numIdle = connectionPool.getNumIdle();
    } catch (Exception e) {
        log.error(e);
    }
    return numIdle;
}

From source file:org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCachePoolAccess.java

/**
 * How many are active in the pool./*from  w  w  w.j  a va 2 s. c  o  m*/
 * <p>
 * @return number active
 */
public int getNumActiveInPool() {
    int numActive = 0;
    try {
        PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(DRIVER_NAME);
        ObjectPool connectionPool = driver.getConnectionPool(this.getPoolName());

        if (log.isDebugEnabled()) {
            log.debug(connectionPool);
        }
        numActive = connectionPool.getNumActive();
    } catch (Exception e) {
        log.error(e);
    }
    return numActive;
}

From source file:org.apache.jcs.auxiliary.disk.jdbc.JDBCDiskCachePoolAccess.java

/**
 * @throws Exception/*from w  w w .j  a v  a 2s .  c  o  m*/
 */
public void shutdownDriver() throws Exception {
    PoolingDriver driver = (PoolingDriver) DriverManager.getDriver(DRIVER_NAME);
    driver.closePool(this.getPoolName());
}