org.apache.commons.dbutils.QueryRunner.getDataSource()方法的使用及代码示例

x33g5p2x  于2022-01-28 转载在 其他  
字(5.0k)|赞(0)|评价(0)|浏览(67)

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

QueryRunner.getDataSource介绍

暂无

代码示例

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

/**
  * @return datasource wrapped in the database operator.
  */
 public AzkabanDataSource getDataSource() {
  return (AzkabanDataSource) this.queryRunner.getDataSource();
 }
}

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

/**
 * Note: this queryRunner should include a concrete {@link AzkabanDataSource} inside.
 */
@Inject
public DatabaseOperator(final QueryRunner queryRunner) {
 requireNonNull(queryRunner.getDataSource(), "data source must not be null.");
 this.queryRunner = queryRunner;
}

代码示例来源:origin: codingapi/tx-lcn

@Override
public void writeUndoLog(UndoLogDO undoLogDo) throws SQLException {
  Connection connection = queryRunner.getDataSource().getConnection();
  writeUndoLogByGivenConnection(connection, undoLogDo);
  DbUtils.close(connection);
}

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

/**
 * Provide a way to allow users define custom SQL operations without relying on fixed SQL
 * interface. The common use case is to group a sequence of SQL operations without commit every
 * time.
 *
 * @param operations A sequence of DB operations
 * @param <T> The type of object that the operations returns. Note that T could be null
 * @return T The object returned by the SQL statement, expected by the caller
 */
public <T> T transaction(final SQLTransaction<T> operations) throws SQLException {
 Connection conn = null;
 try {
  conn = this.queryRunner.getDataSource().getConnection();
  conn.setAutoCommit(false);
  final DatabaseTransOperator transOperator = new DatabaseTransOperator(this.queryRunner,
    conn);
  final T res = operations.execute(transOperator);
  conn.commit();
  return res;
 } catch (final SQLException ex) {
  // todo kunkun-tang: Retry logics should be implemented here.
  logger.error("transaction failed", ex);
  if (this.dbMetrics != null) {
   this.dbMetrics.markDBFailTransaction();
  }
  throw ex;
 } finally {
  DbUtils.closeQuietly(conn);
 }
}

代码示例来源:origin: codingapi/tx-lcn

rollbackInfo.setRollbackSqlList(undoLogDOList);
  txLogger.trace(groupId, unitId, "txc", "rollbackInfo sql " + rollbackInfo.toString());
  connection = queryRunner.getDataSource().getConnection();
  undoRollbackInfoSql(connection, rollbackInfo);
} finally {

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

@Before
public void setUp() throws Exception {
 this.queryRunner = mock(QueryRunner.class);
 this.conn = this.datasource.getConnection();
 final DataSource mockDataSource = mock(this.datasource.getClass());
 when(this.queryRunner.getDataSource()).thenReturn(mockDataSource);
 when(mockDataSource.getConnection()).thenReturn(this.conn);
 this.dbOperator = new DatabaseOperator(this.queryRunner);
 list.add(index_1);
 list.add(index_2);
 // valid query returns correct value
 when(this.queryRunner.query("select * from blah where ? = ?", this.handler, "id", 2))
   .thenReturn(index_2);
 // If select an non-existing entry, handler returns 0.
 when(this.queryRunner.query("select * from blah where ? = ?", this.handler, "id", 3))
   .thenReturn(0);
 //If typos, throw Exceptions.
 doThrow(SQLException.class).when(this.queryRunner)
   .query("sele * from blah where ? = ?", this.handler, "id", 2);
 doAnswer(invocation -> {
  index_1 = 26;
  return 1;
 }).when(this.queryRunner).update("update blah set ? = ?", "1", 26);
}

代码示例来源:origin: com.github.becauseQA/becauseQA-utils

public static DataSource getDataSource(Properties properties) {
  if (dataSource == null) {
    try {
      dataSource = BasicDataSourceFactory.createDataSource(properties);
    } catch (Exception e) {
      // TODO Auto-generated catch block
      e.printStackTrace();
    }
  }
  queryRunner = new QueryRunner(dataSource, false);
  try {
    dataSource.setValidationQuery("select 1"); // http://stackoverflow.com/questions/26404283/java-hibernate-with-sql-server-2012-not-working/27847317#27847317
    connection = queryRunner.getDataSource().getConnection();
  } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  return dataSource;
}

代码示例来源:origin: com.github.becauseQA/becauseQA-utils

public static DataSource getDataSource(DatabaseDriver driver, String domain, String serverName,
    String defaultDatabaseName, String username, String password) {
  if (dataSource == null) {
    dataSource = new BasicDataSource();
    dataSource.setDriverClassName(driver.getdriverClassName());
    String driverurl = driver.getdriverUrl() + "://" + serverName + "/" + defaultDatabaseName;
    String NTLMStr = (StringUtils.isNotEmpty(domain))
        ? ";integrated security=false;useNTLMv2=true;domain=" + domain : ";useKerberos=true;";
    dataSource.setUrl(driverurl + NTLMStr);
    dataSource.setUsername(username);
    dataSource.setPassword(password);
    // set the auto commit for transaction
    dataSource.setMaxTotal(100);
    dataSource.setDefaultAutoCommit(true);
  }
  queryRunner = new QueryRunner(dataSource, false);
  try {
    dataSource.setValidationQuery("select 1"); // http://stackoverflow.com/questions/26404283/java-hibernate-with-sql-server-2012-not-working/27847317#27847317
    connection = queryRunner.getDataSource().getConnection();
  } catch (SQLException e) {
    // TODO Auto-generated catch block
    e.printStackTrace();
  }
  return dataSource;
}

相关文章