@Override public void close() { try { DataSources.destroy(c3p0); } catch (SQLException e) { log.couldNotDestroyC3p0ConnectionPool(c3p0 != null ? c3p0.toString() : null, e); } }
@Override public void stop() { Throwable cause = null; try { tableManager.stop(); tableManager = null; } catch (Throwable t) { cause = t.getCause(); if (cause == null) cause = t; log.debug("Exception while stopping", t); } try { if (configuration.connectionFactory() instanceof ManagedConnectionFactory) { log.tracef("Stopping managed connection factory: %s", connectionFactory); connectionFactory.stop(); } } catch (Throwable t) { if (cause == null) { cause = t; } else { t.addSuppressed(cause); } log.debug("Exception while stopping", t); } if (cause != null) { throw new PersistenceException("Exceptions occurred while stopping store", cause); } }
private void logFileOverride(ClassLoader classLoader) { FileLookup fileLookup = FileLookupFactory.newInstance(); URL c3p0Props = fileLookup.lookupFileLocation(C3P0_PROPERTIES, classLoader); URL c3p0Xml = fileLookup.lookupFileLocation(C3P0_CONFIG, classLoader); if (log.isDebugEnabled()) { if (c3p0Props != null) log.debugf("Found '%s' in classpath: %s", C3P0_PROPERTIES, c3p0Props); if (c3p0Xml != null) log.debugf("Found '%s' in classpath: %s", C3P0_CONFIG, c3p0Xml); } }
dataSource = (DataSource) ctx.lookup(datasourceName); if (trace) { log.tracef("Datasource lookup for %s succeeded: %b", datasourceName, dataSource); log.connectionInJndiNotFound(datasourceName); throw new PersistenceException(String.format( "Could not find a connection in jndi under the name '%s'", datasourceName)); log.namingExceptionLookingUpConnection(datasourceName, e); throw new PersistenceException(e); log.failedClosingNamingCtx(e);
if (LOG.isDebugEnabled()) { LOG.debugf("Guessing database version as '%s'. If this is incorrect, please specify both the correct " + "major and minor version of your database using the 'databaseMajorVersion' and " + "'databaseMinorVersion' attributes in your configuration.", version); return new DbMetaData(databaseType, majorVersion, minorVersion, disableUpsert, disableIndexing, disableSegmented); } catch (SQLException e) { if (LOG.isDebugEnabled()) LOG.debug("Unable to retrieve DB Major and Minor versions from JDBC metadata.", e); } finally { connectionFactory.releaseConnection(connection); return new DbMetaData(guessDialect(dbProduct), majorVersion, minorVersion, disableUpsert, disableIndexing, disableSegmented); } catch (Exception e) { if (LOG.isDebugEnabled()) LOG.debug("Unable to guess dialect from JDBC metadata.", e); } finally { connectionFactory.releaseConnection(connection); if (LOG.isDebugEnabled()) LOG.debug("Unable to detect database dialect using connection metadata. Attempting to guess on driver name."); try { connection = connectionFactory.getConnection(); return new DbMetaData(guessDialect(dbProduct), majorVersion, minorVersion, disableUpsert, disableIndexing, disableSegmented); } catch (Exception e) { if (LOG.isDebugEnabled()) LOG.debug("Unable to guess database dialect from JDBC driver name.", e); } finally {
@Override public void start() { if (configuration.manageConnectionFactory()) { ConnectionFactory factory = ConnectionFactory.getConnectionFactory(configuration.connectionFactory().connectionFactoryClass()); factory.start(configuration.connectionFactory(), factory.getClass().getClassLoader()); initializeConnectionFactory(factory); } try { Object mapper = Util.loadClassStrict(configuration.key2StringMapper(), globalConfiguration.classLoader()).newInstance(); if (mapper instanceof Key2StringMapper) key2StringMapper = (Key2StringMapper) mapper; } catch (Exception e) { log.errorf("Trying to instantiate %s, however it failed due to %s", configuration.key2StringMapper(), e.getClass().getName()); throw new IllegalStateException("This should not happen.", e); } if (trace) { log.tracef("Using key2StringMapper: %s", key2StringMapper.getClass().getName()); } if (configuration.preload()) { enforceTwoWayMapper("preload"); } if (isDistributedCache) { enforceTwoWayMapper("distribution/rehashing"); } }
@Override public void stop() { if (connectionPool != null) { connectionPool.close(); if (trace) log.debug("Successfully stopped PooledConnectionFactory."); } }
public void executeUpdateSql(Connection conn, String sql) throws PersistenceException { Statement statement = null; try { statement = conn.createStatement(); statement.executeUpdate(sql); } catch (SQLException e) { log.errorCreatingTable(sql, e); throw new PersistenceException(e); } finally { JdbcUtil.safeClose(statement); } }
private ByteBuffer marshall(Object obj) throws PersistenceException, InterruptedException { try { return marshaller.objectToBuffer(obj); } catch (IOException e) { log.errorMarshallingObject(e, obj); throw new PersistenceException("I/O failure while marshalling object: " + obj, e); } }
private Properties loadPropertiesFile(ClassLoader classLoader, PooledConnectionFactoryConfiguration poolConfig) { if (classLoader == null) return new Properties(); FileLookup fileLookup = FileLookupFactory.newInstance(); String propertyPath = poolConfig.propertyFile(); InputStream is = null; try { if (propertyPath != null) { is = fileLookup.lookupFileStrict(propertyPath, classLoader); } else if (classLoader.getResource(HIKARI_PROPERTIES) != null) { is = fileLookup.lookupFileStrict(HIKARI_PROPERTIES, classLoader); } if (is != null) { Properties properties = new Properties(); properties.load(is); return properties; } } catch (IOException e) { log.errorLoadingHikariCPProperties(PooledConnectionFactoryConfiguration.class.getName()); } return new Properties(); }
public HikariConnectionPool(ClassLoader classLoader, PooledConnectionFactoryConfiguration poolConfig) { try { Properties properties = loadPropertiesFile(classLoader, poolConfig); if (poolConfig.connectionUrl() != null) properties.setProperty("jdbcUrl", poolConfig.connectionUrl()); if (poolConfig.driverClass() != null) properties.setProperty("driverClassName", poolConfig.driverClass()); if (poolConfig.username() != null) properties.setProperty("dataSource.user", poolConfig.username()); if (poolConfig.password() != null) properties.setProperty("dataSource.password", poolConfig.password()); HikariConfig hikariConfig = new HikariConfig(properties); hikariConfig.setRegisterMbeans(true); hikari = new HikariDataSource(hikariConfig); } catch (Exception e) { log.errorCreatingHikariCP(e); throw new PersistenceException("Error creating HikariCP instance: ", e); } }
public C3P0ConnectionPool(ClassLoader classLoader, PooledConnectionFactoryConfiguration poolConfig) { logWarnMessages(poolConfig); logFileOverride(classLoader); c3p0.setProperties(new Properties()); try { /* Since c3p0 does not throw an exception when it fails to load a driver we attempt to do so here * Also, c3p0 does not allow specifying a custom classloader, so use c3p0's */ Class.forName(poolConfig.driverClass(), true, ComboPooledDataSource.class.getClassLoader()); c3p0.setDriverClass(poolConfig.driverClass()); //loads the jdbc driver } catch (Exception e) { log.errorInstantiatingJdbcDriver(poolConfig.driverClass(), e); throw new PersistenceException(String.format( "Error while instatianting JDBC driver: '%s'", poolConfig.driverClass()), e); } c3p0.setJdbcUrl(poolConfig.connectionUrl()); c3p0.setUser(poolConfig.username()); c3p0.setPassword(poolConfig.password()); }