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

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

本文整理了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

/**
 * 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;
}

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

/**
 * 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;
}

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

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

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

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

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

/**
 * Set the default value in a column for all values where the current value is null.
 * @param database the database to use
 * @param tableName the table where update the column
 * @param columnName the column to Update
 * @param newValue the value to update
 * @throws SQLException if there is a database problem
 */
public static void updateColumnValue(Database database, String tableName, String columnName,
                   Object newValue)
  throws SQLException {
  Connection connection = database.getConnection();
  try {
    updateColumnValue(connection, tableName, columnName, newValue);
  } finally {
    connection.close();
  }
}

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

/**
 * Set the default value in a column for all values where the current value is null.
 * @param database the database to use
 * @param tableName the table where update the column
 * @param columnName the column to Update
 * @param newValue the value to update
 * @throws SQLException if there is a database problem
 */
public static void updateColumnValue(Database database, String tableName, String columnName,
                   Object newValue)
  throws SQLException {
  Connection connection = database.getConnection();
  try {
    updateColumnValue(connection, tableName, columnName, newValue);
  } finally {
    connection.close();
  }
}

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

protected void deleteTable() throws Exception {
  Connection con = database.getConnection();
  con.setAutoCommit(false);
  Statement stmt = con.createStatement();
  stmt.addBatch("DROP TABLE tabletest");
  stmt.addBatch("DROP TABLE precompute_index");
  stmt.executeBatch();
  con.commit();
  con.close();
}

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

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

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

public void tearDownData() throws Exception {
  Connection con = getDatabase().getConnection();
  con.setAutoCommit(false);
  Statement stmt = con.createStatement();
  stmt.addBatch("DROP TABLE IF EXISTS table1");
  stmt.addBatch("DROP TABLE IF EXISTS table2");
  stmt.addBatch("DROP TABLE IF EXISTS table3");
  stmt.executeBatch();
  con.commit();
  con.close();
}

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

@Override
public void setUp() throws Exception {
  db = DatabaseFactory.getDatabase("db.unittest");
  con = db.getConnection();
  con.setAutoCommit(true);
}

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

public void tearDown() throws Exception {
  try {
    dt.close();
    Database db = DatabaseFactory.getDatabase("db.unittest");
    Connection c = db.getConnection();
    c.setAutoCommit(true);
    c.createStatement().execute("DROP TABLE tracker");
    c.close();
  } catch (Exception e) {
  }
}

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

public void tearDownPrecomputedTables() throws Exception {
  Connection con = getDatabase().getConnection();
  try {
    con.setAutoCommit(false);
    PreparedStatement pstmt = con.prepareStatement("DELETE FROM " + PrecomputedTableManager.TABLE_INDEX);
    pstmt.execute();
    for (String precompTableName : precomps.keySet()) {
      Statement stmt = con.createStatement();
      stmt.execute("DROP TABLE IF EXISTS " + precompTableName);
      System.out.println("Dropped table " + precompTableName);
    }
    con.commit();
  } catch (PSQLException e) {
    // ignore
  } finally {
    con.close();
  }
}

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

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

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

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

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

public void testAddInvalid() throws Exception {
  Connection c = database.getConnection();
  c.setAutoCommit(false);
  PrecomputedTableManager ptm = new PrecomputedTableManager(database);
  try {
    ptm.add(new PrecomputedTable(new Query("select table.blah from table"), "select table.blah from table", "precompA", null, c));
    fail("Expected: SQLException");
  } catch (SQLException e) {
  } finally {
    c.close();
  }
}

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

public void testDeleteInvalid() throws Exception {
  Connection c = database.getConnection();
  c.setAutoCommit(false);
  PrecomputedTableManager ptm = new PrecomputedTableManager(database);
  try {
    ptm.delete(new PrecomputedTable(new Query(), "", "tablenotthere", null, c));
    fail("Expected: IllegalArgumentException");
  } catch (IllegalArgumentException e) {
  } finally {
    c.close();
  }
}

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

public void testOrderDescending() throws Exception {
    Query q = new Query("SELECT employee.age FROM employee ORDER BY employee.age DESC");
    Connection con = database.getConnection();
    con.setAutoCommit(false);
    PrecomputedTableManager ptm = new PrecomputedTableManager(database);
    ptm.deleteTableFromDatabase("precompC");

    try {
      PrecomputedTable pt2 = new PrecomputedTable(q, q.getSQLString(), "precompC", "test", con);
      ptm.add(pt2);
    } finally {
      con.close();
    }
  }
}

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

public void setUp() throws Exception {
  singleTableQuery = new Query("SELECT mytable.a FROM mytable WHERE mytable.a = 1");
  singleTableQueryWithFieldAlias = new Query("SELECT mytable.a AS alias FROM mytable WHERE mytable.a = 1");
  singleTableQueryWithTableAlias = new Query("SELECT table1.a FROM mytable table1 WHERE table1.a = 1");
  singleTableQueryNoConstraints = new Query("SELECT mytable.a FROM mytable");
  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");
  con = database.getConnection();
}

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

public void setUp() throws Exception {
  super.setUp();
  pm = im.getProfileManager();
  superUser = im.getProfileManager().getProfile("superUser");
  testUser = im.getProfileManager().getProfile("testUser");
  conn = ((ObjectStoreWriterInterMineImpl) uosw).getDatabase().getConnection();
  templateManager = new TemplateManager(superUser);
  tagManager = new TagManager(uosw);
  createTemplates();
}

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

public void setUp() throws Exception {
  database = DatabaseFactory.getDatabase("db.unittest");
  Query q1 = new Query();
  Table t = new Table("tabletest");
  Constant c = new Constant("50");
  Field f1 = new Field("col1", t);
  Field f2 = new Field("col2", t);
  SelectValue sv1 = new SelectValue(f1, null);
  SelectValue sv2 = new SelectValue(f2, null);
  q1.addFrom(t);
  q1.addSelect(sv1);
  q1.addSelect(sv2);
  q1.addWhere(new Constraint(f1, Constraint.LT, c));
  q1.addOrderBy(f1);
  Connection con = database.getConnection();
  con.setAutoCommit(false);
  pt1 = new PrecomputedTable(q1, q1.getSQLString(), "precompA", "test", con);
  con.close();
}

相关文章