private void createTables(final Set<String> tables) throws SQLException, IOException { final Connection conn = this.dataSource.getConnection(); conn.setAutoCommit(false); try { for (final String table : tables) { runTableScripts(conn, table); } } finally { conn.close(); } }
if (this.dbOperator.getDataSource().allowsOnDuplicateKey()) { final String INSERT_PROJECT_PERMISSION = "INSERT INTO project_permissions (project_id, modified_time, name, permissions, isGroup) values (?,?,?,?,?)"
if (this.dbOperator.getDataSource().allowsOnDuplicateKey()) { final String INSERT_PROJECT_PERMISSION = "INSERT INTO project_permissions (project_id, modified_time, name, permissions, isGroup) values (?,?,?,?,?)"
@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); }
@Before public void setUp() throws Exception { final AzkabanDataSource datasource = new AzDBTestUtility.EmbeddedH2BasicDataSource(); final DatabaseTransOperator operator = new DatabaseTransOperator(new QueryRunner(), datasource.getConnection()); }