/** * Returns a Connection. Please put them back. * * Whenever you receive a connection from the object-store, you MUST * release its resources by calling releaseConnection. * * Failure to do so KILLS THE OBJECT STORE! * * @return a java.sql.Connection * @throws SQLException if there is a problem with that */ public Connection getConnection() throws SQLException { Connection retval = db.getConnection(); if (!retval.getAutoCommit()) { retval.setAutoCommit(true); } return retval; }
dsProps = PropertiesUtil.stripStart("datasource", dsProps); removeProperty(dsProps, "class"); removeProperty(dsProps, "encoding"); removeProperty(dsProps, "schema"); renameProperty(dsProps, "dataSourceName", "poolName"); renameProperty(dsProps, "maxConnections", "maximumPoolSize"); renameProperty(dsProps, "user", "dataSource.user"); renameProperty(dsProps, "password", "dataSource.password"); renameProperty(dsProps, "port", "dataSource.portNumber"); renameProperty(dsProps, "databaseName", "dataSource.databaseName"); renameProperty(dsProps, "serverName", "dataSource.serverName"); + HIKARI_CLASSNAME + " in default.intermine.properties or minename.properties."); configure(props); LOG.info("Creating new Database " + getURL() + "(" + toString() + ") and parallelism " + parallel); } catch (Exception e) {
/** * {@inheritDoc} */ @Override public void finalize() throws Throwable { super.finalize(); if (datasource instanceof com.zaxxer.hikari.HikariDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((com.zaxxer.hikari.HikariDataSource) datasource).close(); } else if (datasource instanceof org.postgresql.ds.PGPoolingDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((org.postgresql.ds.PGPoolingDataSource) datasource).close(); } else if (datasource instanceof org.postgresql.jdbc2.optional.PoolingDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((org.postgresql.jdbc2.optional.PoolingDataSource) datasource).close(); } else { LOG.warn("Finalise - Could not close datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader() + " - " + datasource.getClass().toString()); } }
c = database.getConnection(); c.setAutoCommit(true); DatabaseUtil.removeAllTables(c); sql.setTargetDatabase(database.getPlatform().toLowerCase()); // "postgresql" InputStream schemaFileInputStream = getClass().getClassLoader() .getResourceAsStream(schemaFile); isql.setDriver(database.getDriver()); // "org.postgresql.Driver" isql.setUrl(database.getURL()); // "jdbc:postgresql://localhost/test" isql.setUserid(database.getUser()); // "mark" isql.setPassword(database.getPassword()); // "" isql.setAutocommit(true); TorqueSQLExec.OnError ea = new TorqueSQLExec.OnError(); c = database.getConnection(); c.setAutoCommit(true); c.createStatement().execute("CREATE SEQUENCE " + SERIAL_SEQUENCE_NAME); c = database.getConnection(); c.setAutoCommit(true); c.createStatement().execute("CREATE SEQUENCE " c = database.getConnection(); c.setAutoCommit(true); c.createStatement().execute("ALTER TABLE " + CLOB_TABLE_NAME + " ALTER COLUMN " c = null; try {
OrganismRepository or = OrganismRepository.getOrganismRepository(); try { LOG.info("Querying FlyBase DB: " + db.getName()); for (String clsName : clsCol) { conn = db.getConnection(); String query = "select c.cvterm_id" + " from cvterm c, cv"
public void testConfigure() throws Exception { Database db = new Database(); db.configure(props); assertTrue(db.getDataSource() != null); assertTrue(db.getDataSource() instanceof PGPoolingDataSource); assertEquals("PostgreSQL", db.getPlatform()); assertEquals("dbserver.mydomain.org", ((PGPoolingDataSource) db.getDataSource()).getServerName()); assertEquals("test", ((PGPoolingDataSource) db.getDataSource()).getDatabaseName()); assertEquals(10, ((PGPoolingDataSource) db.getDataSource()).getMaxConnections()); }
/** * Called by the ShutdownHook on shutdown. */ public synchronized void shutdown() { LOG.info("Shutting down open ObjectStoreInterMineImpl with sequence = " + sequenceNumber + " and Database " + getDatabase().getURL()); try { close(); } catch (ObjectStoreException e) { LOG.warn("Exception caught while shutting down ObjectStoreInterMineImpl: " + e); } }
public void testPassword() throws Exception { Database db = new Database(props); assertEquals("secret", db.getPassword()); }
public void testInvalidMethod() throws Exception { Properties invalidProps = new Properties(); invalidProps.put("datasource.class", "org.postgresql.ds.PGPoolingDataSource"); invalidProps.put("datasource.someRubbish", "blahblahblah"); Database db = new Database(invalidProps); }
/** * Run an IQL query in the objectstore and print the first results to the console. * @param os the objectstore * @param iql and IQL query string */ private static void runIqlQuery(ObjectStoreInterMineImpl os, String iql) { System.out .println("Running query in database " + os.getDatabase().getName() + " - " + iql); System.out .println("See intermine.log for query execution details."); Query q = parseIqlQuery(os.getModel(), iql); Results results = os.execute(q); Iterator<?> resIter = results.iterator(); int count = 0; while (resIter.hasNext() && count < MAX_ROWS) { ResultsRow<?> rr = (ResultsRow<?>) resIter.next(); System.out .println(count + " - " + rr); count += 1; } if (resIter.hasNext()) { System.out .println("Only fetching first " + MAX_ROWS + " rows."); } }
public void testVersionIsAtLeast() throws Exception { Database db = new Database(props); db.version = "9.3"; assertTrue(db.isVersionAtLeast("9.2")); assertTrue(db.isVersionAtLeast("9.1.7")); assertTrue(db.isVersionAtLeast("8")); assertTrue(db.isVersionAtLeast("9.3")); assertTrue(db.isVersionAtLeast("9.3.0")); assertFalse(db.isVersionAtLeast("10")); assertFalse(db.isVersionAtLeast("9.4")); assertFalse(db.isVersionAtLeast("9.3.1")); db.version = "9.2.1"; assertTrue(db.isVersionAtLeast("9.2")); assertTrue(db.isVersionAtLeast("9.2.0")); assertTrue(db.isVersionAtLeast("9.2.1.0")); assertFalse(db.isVersionAtLeast("9.2.1.1")); assertFalse(db.isVersionAtLeast("9.2.2")); db.version = "9.4beta3"; assertTrue(db.isVersionAtLeast("9.2")); assertTrue(db.isVersionAtLeast("9.4.0")); assertFalse(db.isVersionAtLeast("9.5")); }
configure(subProps);
.getName()); SchemaType torqueType = SchemaType.getEnum(torqueTypeName); Platform torquePlatform = PlatformFactory.getPlatformFor(state.getDb().getPlatform() .toLowerCase()); Domain torqueDomain = torquePlatform.getDomainForSchemaType(torqueType);
c = database.getConnection(); c.setAutoCommit(true); DatabaseUtil.removeAllTables(c); sql.setTargetDatabase(database.getPlatform().toLowerCase()); // "postgresql" InputStream schemaFileInputStream = getClass().getClassLoader() .getResourceAsStream(schemaFile); isql.setDriver(database.getDriver()); // "org.postgresql.Driver" isql.setUrl(database.getURL()); // "jdbc:postgresql://localhost/test" isql.setUserid(database.getUser()); // "mark" isql.setPassword(database.getPassword()); // "" isql.setAutocommit(true); TorqueSQLExec.OnError ea = new TorqueSQLExec.OnError(); c = database.getConnection(); c.setAutoCommit(true); c.createStatement().execute("CREATE SEQUENCE " + SERIAL_SEQUENCE_NAME); c = database.getConnection(); c.setAutoCommit(true); c.createStatement().execute("CREATE SEQUENCE " c = database.getConnection(); c.setAutoCommit(true); c.createStatement().execute("ALTER TABLE " + CLOB_TABLE_NAME + " ALTER COLUMN " c = null; try {
/** * {@inheritDoc} */ @Override public void finalize() throws Throwable { super.finalize(); if (datasource instanceof com.zaxxer.hikari.HikariDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((com.zaxxer.hikari.HikariDataSource) datasource).close(); } else if (datasource instanceof org.postgresql.ds.PGPoolingDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((org.postgresql.ds.PGPoolingDataSource) datasource).close(); } else if (datasource instanceof org.postgresql.jdbc2.optional.PoolingDataSource) { LOG.info("Finalise - Closing datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader()); ((org.postgresql.jdbc2.optional.PoolingDataSource) datasource).close(); } else { LOG.warn("Finalise - Could not close datasource for Database " + getURL() + "(" + toString() + ") with ClassLoader " + getClass().getClassLoader() + " - " + datasource.getClass().toString()); } }
/** * Finalise this object. */ protected synchronized void doFinalise() { LOG.error("Garbage collecting ObjectStoreInterMineImpl with sequence = " + sequenceNumber + " and Database " + getDatabase().getURL()); try { close(); } catch (ObjectStoreException e) { LOG.error("Exception while garbage-collecting ObjectStoreInterMineImpl: " + e); } }