@Provides public QueryRunner createQueryRunner(final AzkabanDataSource dataSource) { return new QueryRunner(dataSource); } }
@Bean public QueryRunner queryRunner(DataSource dataSource) { return new QueryRunner(dataSource); }
/** * Create new instance of BaseSchemaRecordsCreation. * * @param connection the connection to relational database */ public BaseSchemaRecordsCreation(Connection connection) { this.connection = connection; runner = new QueryRunner(); dd = new DataDefinition(connection); }
/** * Create entity that responsible for data migration from old tables to new ctl based ones. * * @param connection the connection to relational database */ public AbstractCtlMigration(Connection connection) { this.connection = connection; runner = new QueryRunner(); dd = new DataDefinition(connection); }
/** * Create a new instance that aggregate the same CTL schemas. * * @param connection the connection to relational database */ public CtlAggregation(Connection connection) { this.connection = connection; runner = new QueryRunner(); dd = new DataDefinition(connection); schemasToCtl = new HashMap<>(); ctls = new HashSet<>(); }
private void runTableScripts(final Connection conn, final String table) throws IOException, SQLException { logger.info("Creating new table " + table); final String dbSpecificScript = "create." + table + ".sql"; final File script = new File(this.scriptPath, dbSpecificScript); BufferedInputStream buff = null; try { buff = new BufferedInputStream(new FileInputStream(script)); final String queryStr = IOUtils.toString(buff); final String[] splitQuery = queryStr.split(";\\s*\n"); final QueryRunner runner = new QueryRunner(); for (final String query : splitQuery) { runner.update(conn, query); } conn.commit(); } finally { IOUtils.closeQuietly(buff); } }
public LogDbHelper(LogDbProperties logDbProperties) throws TxLoggerException { log.info("log-db Properties: {}", JSON.toJSONString(logDbProperties)); if (logDbProperties.getDriverClassName() == null) { throw new TxLoggerException("Init TxLogger error. see config [com.codingapi.txlcn.logger.db.LogDbProperties]"); } hikariDataSource = new HikariDataSource(logDbProperties); queryRunner = new QueryRunner(hikariDataSource); log.info("log-db prepared."); }
@Autowired public AspectLogDbHelper(AspectLogDbProperties aspectLogDbProperties) { HikariConfig hikariConfig = new HikariConfig(); hikariConfig.setDriverClassName(org.h2.Driver.class.getName()); log.info("init db at {}", aspectLogDbProperties.getFilePath()); hikariConfig.setJdbcUrl(String.format("jdbc:h2:%s",aspectLogDbProperties.getFilePath())); hikariDataSource = new HikariDataSource(hikariConfig); queryRunner = new QueryRunner(hikariDataSource); log.info("init db finish."); }
/** * Drop foreign key with autogenerated name based on the table where constrain declared and * referenced table name. */ public void dropUnnamedFk(String tableName, String referencedTableName) throws SQLException { QueryRunner runner = new QueryRunner(); String query = String.format(QUERY_FIND_FK_NAME, tableName, referencedTableName); String fkName = runner.query(connection, query, rs -> rs.next() ? rs.getString(1) : null); if (fkName != null) { runner.update(connection, "ALTER TABLE " + tableName + " DROP FOREIGN KEY " + fkName); } else { System.err.println("FK name not found"); } }
public void executeUpdateSql(String sql, Object... params) { try (Connection connection = getConnection()) { new QueryRunner().update(connection, sql, params); if (!connection.getAutoCommit()) { connection.commit(); } } catch (SQLException e) { SQLException nextException = e.getNextException(); if (nextException != null) { throw new IllegalStateException("Fail to execute sql: " + sql, new SQLException(e.getMessage(), nextException.getSQLState(), nextException.getErrorCode(), nextException)); } throw new IllegalStateException("Fail to execute sql: " + sql, e); } catch (Exception e) { throw new IllegalStateException("Fail to execute sql: " + sql, e); } }
public static DatabaseOperator initTestDB() throws Exception { final AzkabanDataSource dataSource = new EmbeddedH2BasicDataSource(); final String sqlScriptsDir = new File("../azkaban-db/src/main/sql/").getCanonicalPath(); final DatabaseSetup setup = new DatabaseSetup(dataSource, sqlScriptsDir); setup.updateDatabase(); return new DatabaseOperator(new QueryRunner(dataSource)); }
public static DatabaseOperator initQuartzDB() throws Exception { final AzkabanDataSource dataSource = new EmbeddedH2BasicDataSource(); final String sqlScriptsDir = new File("../azkaban-web-server/src/test/resources/") .getCanonicalPath(); final DatabaseSetup setup = new DatabaseSetup(dataSource, sqlScriptsDir); setup.updateDatabase(); return new DatabaseOperator(new QueryRunner(dataSource)); }
@Before public void setUp() throws Exception { final AzkabanDataSource datasource = new AzDBTestUtility.EmbeddedH2BasicDataSource(); final DatabaseTransOperator operator = new DatabaseTransOperator(new QueryRunner(), datasource.getConnection()); }
private void performTestForScriptedSchema(String jdbcUrl) throws SQLException { try (HikariDataSource dataSource = getDataSource(jdbcUrl, 1)) { boolean result = new QueryRunner(dataSource).query("SELECT foo FROM bar WHERE foo LIKE '%world'", rs -> { rs.next(); String resultSetString = rs.getString(1); assertEquals("A basic SELECT query succeeds where the schema has been applied from a script", "hello world", resultSetString); return true; }); } }
private void performSimpleTest(String jdbcUrl) throws SQLException { try (HikariDataSource dataSource = getDataSource(jdbcUrl, 1)) { boolean result = new QueryRunner(dataSource, options.contains(Options.PmdKnownBroken)).query("SELECT 1", rs -> { rs.next(); int resultSetInt = rs.getInt(1); assertEquals("A basic SELECT query succeeds", 1, resultSetInt); return true; }); assertTrue("The database returned a record as expected", result); } }
private HikariDataSource verifyCharacterSet(String jdbcUrl) throws SQLException { HikariDataSource dataSource = getDataSource(jdbcUrl, 1); boolean result = new QueryRunner(dataSource).query("SHOW VARIABLES LIKE 'character\\_set\\_connection'", rs -> { rs.next(); String resultSetInt = rs.getString(2); assertEquals("Passing query parameters to set DB connection encoding is successful", "utf8", resultSetInt); return true; }); assertTrue("The database returned a record as expected", result); return dataSource; }
private void performTestForCharacterEncodingForInitialScriptConnection(String jdbcUrl) throws SQLException { try (HikariDataSource dataSource = getDataSource(jdbcUrl, 1)) { boolean result = new QueryRunner(dataSource).query("SELECT foo FROM bar WHERE foo LIKE '%мир'", rs -> { rs.next(); String resultSetString = rs.getString(1); assertEquals("A SELECT query succeed and the correct charset has been applied for the init script", "привет мир", resultSetString); return true; }); assertTrue("The database returned a record as expected", result); } }
private void performSimpleTest(String jdbcUrl) throws SQLException { HikariDataSource dataSource = getDataSource(jdbcUrl, 1); new QueryRunner(dataSource).query("SELECT 1 FROM dual", new ResultSetHandler<Object>() { @Override public Object handle(ResultSet rs) throws SQLException { rs.next(); int resultSetInt = rs.getInt(1); assertEquals("A basic SELECT query succeeds", 1, resultSetInt); return true; } }); dataSource.close(); }
private static void clearMySQLTestDB() throws SQLException { final Props props = new Props(); props.put("database.type", "mysql"); props.put("mysql.host", "localhost"); props.put("mysql.port", "3306"); props.put("mysql.database", ""); props.put("mysql.user", "root"); props.put("mysql.password", ""); props.put("mysql.numconnections", 10); final DataSource datasource = DataSourceUtils.getDataSource(props); final QueryRunner runner = new QueryRunner(datasource); try { runner.update("drop database azkabanunittest"); } catch (final SQLException e) { } runner.update("create database azkabanunittest"); }
private static void clearMySQLTestDb() throws SQLException { final Props props = new Props(); props.put("database.type", "mysql"); props.put("mysql.host", "localhost"); props.put("mysql.port", "3306"); props.put("mysql.database", ""); props.put("mysql.user", "root"); props.put("mysql.password", ""); props.put("mysql.numconnections", 10); final DataSource datasource = DataSourceUtils.getDataSource(props); final QueryRunner runner = new QueryRunner(datasource); try { runner.update("drop database azkabanunittest"); } catch (final SQLException e) { } runner.update("create database azkabanunittest"); }