org.intermine.sql.Database.getConnection()方法的使用及代码示例

x33g5p2x  于2022-01-18 转载在 其他  
字(8.7k)|赞(0)|评价(0)|浏览(181)

本文整理了Java中org.intermine.sql.Database.getConnection()方法的一些代码示例,展示了Database.getConnection()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Database.getConnection()方法的具体详情如下:
包路径:org.intermine.sql.Database
类名称:Database
方法名:getConnection

Database.getConnection介绍

[英]Gets a Connection to this Database
[中]获取与此数据库的连接

代码示例

代码示例来源:origin: org.intermine/intermine-objectstore

  1. /**
  2. * Returns a Connection. Please put them back.
  3. *
  4. * Whenever you receive a connection from the object-store, you MUST
  5. * release its resources by calling releaseConnection.
  6. *
  7. * Failure to do so KILLS THE OBJECT STORE!
  8. *
  9. * @return a java.sql.Connection
  10. * @throws SQLException if there is a problem with that
  11. */
  12. public Connection getConnection() throws SQLException {
  13. Connection retval = db.getConnection();
  14. if (!retval.getAutoCommit()) {
  15. retval.setAutoCommit(true);
  16. }
  17. return retval;
  18. }

代码示例来源:origin: intermine/intermine

  1. /**
  2. * Returns a Connection. Please put them back.
  3. *
  4. * Whenever you receive a connection from the object-store, you MUST
  5. * release its resources by calling releaseConnection.
  6. *
  7. * Failure to do so KILLS THE OBJECT STORE!
  8. *
  9. * @return a java.sql.Connection
  10. * @throws SQLException if there is a problem with that
  11. */
  12. public Connection getConnection() throws SQLException {
  13. Connection retval = db.getConnection();
  14. if (!retval.getAutoCommit()) {
  15. retval.setAutoCommit(true);
  16. }
  17. return retval;
  18. }

代码示例来源:origin: intermine/intermine

  1. private Connection getConnection() throws SQLException {
  2. ObjectStoreWriterInterMineImpl uosw = (ObjectStoreWriterInterMineImpl) osw;
  3. return uosw.getDatabase().getConnection();
  4. }

代码示例来源:origin: org.intermine/intermine-api

  1. private Connection getConnection() throws SQLException {
  2. ObjectStoreWriterInterMineImpl uosw = (ObjectStoreWriterInterMineImpl) osw;
  3. return uosw.getDatabase().getConnection();
  4. }

代码示例来源:origin: org.intermine/intermine-objectstore

  1. /**
  2. * Set the default value in a column for all values where the current value is null.
  3. * @param database the database to use
  4. * @param tableName the table where update the column
  5. * @param columnName the column to Update
  6. * @param newValue the value to update
  7. * @throws SQLException if there is a database problem
  8. */
  9. public static void updateColumnValue(Database database, String tableName, String columnName,
  10. Object newValue)
  11. throws SQLException {
  12. Connection connection = database.getConnection();
  13. try {
  14. updateColumnValue(connection, tableName, columnName, newValue);
  15. } finally {
  16. connection.close();
  17. }
  18. }

代码示例来源:origin: intermine/intermine

  1. /**
  2. * Set the default value in a column for all values where the current value is null.
  3. * @param database the database to use
  4. * @param tableName the table where update the column
  5. * @param columnName the column to Update
  6. * @param newValue the value to update
  7. * @throws SQLException if there is a database problem
  8. */
  9. public static void updateColumnValue(Database database, String tableName, String columnName,
  10. Object newValue)
  11. throws SQLException {
  12. Connection connection = database.getConnection();
  13. try {
  14. updateColumnValue(connection, tableName, columnName, newValue);
  15. } finally {
  16. connection.close();
  17. }
  18. }

代码示例来源:origin: intermine/intermine

  1. protected void deleteTable() throws Exception {
  2. Connection con = database.getConnection();
  3. con.setAutoCommit(false);
  4. Statement stmt = con.createStatement();
  5. stmt.addBatch("DROP TABLE tabletest");
  6. stmt.addBatch("DROP TABLE precompute_index");
  7. stmt.executeBatch();
  8. con.commit();
  9. con.close();
  10. }

代码示例来源:origin: intermine/intermine

  1. protected void createTable() throws Exception {
  2. // Set up some tables in the database
  3. Connection con = database.getConnection();
  4. con.setAutoCommit(false);
  5. Statement stmt = con.createStatement();
  6. stmt.addBatch("CREATE TABLE tabletest(col1 int, col2 int)");
  7. for (int i = 1; i<100; i++) {
  8. stmt.addBatch("INSERT INTO tabletest VALUES(" + i + ", " + (101-i) + ")" );
  9. }
  10. stmt.executeBatch();
  11. con.commit();
  12. con.close();
  13. }

代码示例来源:origin: intermine/intermine

  1. public void tearDownData() throws Exception {
  2. Connection con = getDatabase().getConnection();
  3. con.setAutoCommit(false);
  4. Statement stmt = con.createStatement();
  5. stmt.addBatch("DROP TABLE IF EXISTS table1");
  6. stmt.addBatch("DROP TABLE IF EXISTS table2");
  7. stmt.addBatch("DROP TABLE IF EXISTS table3");
  8. stmt.executeBatch();
  9. con.commit();
  10. con.close();
  11. }

代码示例来源:origin: intermine/intermine

  1. @Override
  2. public void setUp() throws Exception {
  3. db = DatabaseFactory.getDatabase("db.unittest");
  4. con = db.getConnection();
  5. con.setAutoCommit(true);
  6. }

代码示例来源:origin: intermine/intermine

  1. public void tearDown() throws Exception {
  2. try {
  3. dt.close();
  4. Database db = DatabaseFactory.getDatabase("db.unittest");
  5. Connection c = db.getConnection();
  6. c.setAutoCommit(true);
  7. c.createStatement().execute("DROP TABLE tracker");
  8. c.close();
  9. } catch (Exception e) {
  10. }
  11. }

代码示例来源:origin: intermine/intermine

  1. public void tearDownPrecomputedTables() throws Exception {
  2. Connection con = getDatabase().getConnection();
  3. try {
  4. con.setAutoCommit(false);
  5. PreparedStatement pstmt = con.prepareStatement("DELETE FROM " + PrecomputedTableManager.TABLE_INDEX);
  6. pstmt.execute();
  7. for (String precompTableName : precomps.keySet()) {
  8. Statement stmt = con.createStatement();
  9. stmt.execute("DROP TABLE IF EXISTS " + precompTableName);
  10. System.out.println("Dropped table " + precompTableName);
  11. }
  12. con.commit();
  13. } catch (PSQLException e) {
  14. // ignore
  15. } finally {
  16. con.close();
  17. }
  18. }

代码示例来源:origin: intermine/intermine

  1. protected void setUp() throws Exception {
  2. con = DatabaseFactory.getDatabase("db.unittest").getConnection();
  3. con.setAutoCommit(false);
  4. writer = new DatabaseWriter(con, "table1");
  5. }

代码示例来源:origin: intermine/intermine

  1. public void testNullWarningPreparedStatement() throws Exception {
  2. // pass in an sql statement without an EXPLAIN, should give no warnings
  3. Connection con = DatabaseFactory.getDatabase("db.unittest").getConnection();
  4. try {
  5. String sql = "select 1";
  6. PreparedStatement stmt = con.prepareStatement(sql);
  7. er = new PostgresExplainResult(stmt);
  8. fail("Expected: SQLException");
  9. } catch (SQLException e) {
  10. } catch (NullPointerException e) {
  11. fail("Expected SQLException but Null PointerException thrown");
  12. } finally {
  13. con.close();
  14. }
  15. }

代码示例来源:origin: intermine/intermine

  1. public void testAddInvalid() throws Exception {
  2. Connection c = database.getConnection();
  3. c.setAutoCommit(false);
  4. PrecomputedTableManager ptm = new PrecomputedTableManager(database);
  5. try {
  6. ptm.add(new PrecomputedTable(new Query("select table.blah from table"), "select table.blah from table", "precompA", null, c));
  7. fail("Expected: SQLException");
  8. } catch (SQLException e) {
  9. } finally {
  10. c.close();
  11. }
  12. }

代码示例来源:origin: intermine/intermine

  1. public void testDeleteInvalid() throws Exception {
  2. Connection c = database.getConnection();
  3. c.setAutoCommit(false);
  4. PrecomputedTableManager ptm = new PrecomputedTableManager(database);
  5. try {
  6. ptm.delete(new PrecomputedTable(new Query(), "", "tablenotthere", null, c));
  7. fail("Expected: IllegalArgumentException");
  8. } catch (IllegalArgumentException e) {
  9. } finally {
  10. c.close();
  11. }
  12. }

代码示例来源:origin: intermine/intermine

  1. public void testOrderDescending() throws Exception {
  2. Query q = new Query("SELECT employee.age FROM employee ORDER BY employee.age DESC");
  3. Connection con = database.getConnection();
  4. con.setAutoCommit(false);
  5. PrecomputedTableManager ptm = new PrecomputedTableManager(database);
  6. ptm.deleteTableFromDatabase("precompC");
  7. try {
  8. PrecomputedTable pt2 = new PrecomputedTable(q, q.getSQLString(), "precompC", "test", con);
  9. ptm.add(pt2);
  10. } finally {
  11. con.close();
  12. }
  13. }
  14. }

代码示例来源:origin: intermine/intermine

  1. public void setUp() throws Exception {
  2. singleTableQuery = new Query("SELECT mytable.a FROM mytable WHERE mytable.a = 1");
  3. singleTableQueryWithFieldAlias = new Query("SELECT mytable.a AS alias FROM mytable WHERE mytable.a = 1");
  4. singleTableQueryWithTableAlias = new Query("SELECT table1.a FROM mytable table1 WHERE table1.a = 1");
  5. singleTableQueryNoConstraints = new Query("SELECT mytable.a FROM mytable");
  6. twoSameTableQuery = new Query("SELECT table1.b, table2.a FROM mytable table1, mytable table2 WHERE table1.a = 1 AND table2.b < 3 AND table1.a = table2.join");
  7. con = database.getConnection();
  8. }

代码示例来源:origin: intermine/intermine

  1. public void setUp() throws Exception {
  2. super.setUp();
  3. pm = im.getProfileManager();
  4. superUser = im.getProfileManager().getProfile("superUser");
  5. testUser = im.getProfileManager().getProfile("testUser");
  6. conn = ((ObjectStoreWriterInterMineImpl) uosw).getDatabase().getConnection();
  7. templateManager = new TemplateManager(superUser);
  8. tagManager = new TagManager(uosw);
  9. createTemplates();
  10. }

代码示例来源:origin: intermine/intermine

  1. public void setUp() throws Exception {
  2. database = DatabaseFactory.getDatabase("db.unittest");
  3. Query q1 = new Query();
  4. Table t = new Table("tabletest");
  5. Constant c = new Constant("50");
  6. Field f1 = new Field("col1", t);
  7. Field f2 = new Field("col2", t);
  8. SelectValue sv1 = new SelectValue(f1, null);
  9. SelectValue sv2 = new SelectValue(f2, null);
  10. q1.addFrom(t);
  11. q1.addSelect(sv1);
  12. q1.addSelect(sv2);
  13. q1.addWhere(new Constraint(f1, Constraint.LT, c));
  14. q1.addOrderBy(f1);
  15. Connection con = database.getConnection();
  16. con.setAutoCommit(false);
  17. pt1 = new PrecomputedTable(q1, q1.getSQLString(), "precompA", "test", con);
  18. con.close();
  19. }

相关文章