@Test public void testWarnings() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); DQP dqp = Mockito.mock(DQP.class); ResultsFuture<ResultsMessage> results = new ResultsFuture<ResultsMessage>(); Mockito.stub(dqp.executeRequest(Mockito.anyLong(), (RequestMessage) Mockito.anyObject())) .toReturn(results); ResultsMessage rm = new ResultsMessage(); rm.setResults(new List<?>[] {Arrays.asList(1)}); rm.setWarnings(Arrays.asList(new Throwable())); rm.setColumnNames(new String[] {"expr1"}); rm.setDataTypes(new String[] {"string"}); results.getResultsReceiver().receiveResults(rm); Mockito.stub(conn.getDQP()).toReturn(dqp); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY) { @Override protected java.util.TimeZone getServerTimeZone() throws java.sql.SQLException { return null; } }; statement.execute("select 'a'"); assertNotNull(statement.getResultSet()); SQLWarning warning = statement.getWarnings(); assertNotNull(warning); assertNull(warning.getNextWarning()); }
/** * Rollback the current local transaction * * @param startTxn * @throws SQLException */ public void rollback(boolean startTxn) throws SQLException { // Check to see the connection is open checkConnection(); if (!autoCommitFlag) { try { if (this.inLocalTxn) { this.inLocalTxn = false; try { ResultsFuture<?> future = this.dqp.rollback(); future.get(); } catch (Exception e) { throw TeiidSQLException.create(e); } logger.fine(JDBCPlugin.Util.getString("MMConnection.Rollback_success")); // $NON-NLS-1$ } } finally { if (startTxn) { this.inLocalTxn = false; } else { this.autoCommitFlag = true; } } } }
protected Xid[] recoverTransaction(int arg0) throws SQLException { checkConnection(); try { ResultsFuture<Xid[]> future = this.dqp.recover(arg0); return future.get(); } catch (Exception e) { throw TeiidSQLException.create(e); } }
protected void forgetTransaction(XidImpl arg0) throws SQLException { checkConnection(); try { ResultsFuture<?> future = this.dqp.forget(arg0); future.get(); } catch (Exception e) { throw TeiidSQLException.create(e); } }
protected int prepareTransaction(XidImpl arg0) throws SQLException { checkConnection(); transactionXid = null; try { ResultsFuture<Integer> future = this.dqp.prepare(arg0); return future.get(); } catch (Exception e) { throw TeiidSQLException.create(e); } }
protected void endTransaction(XidImpl arg0, int arg1) throws SQLException { checkConnection(); this.autoCommitFlag = true; try { ResultsFuture<?> future = this.dqp.end(arg0, arg1); future.get(); } catch (Exception e) { throw TeiidSQLException.create(e); } }
protected void startTransaction(XidImpl arg0, int arg1, int timeout) throws SQLException { checkConnection(); try { ResultsFuture<?> future = this.dqp.start(arg0, arg1, timeout); future.get(); } catch (Exception e) { throw TeiidSQLException.create(e); } transactionXid = arg0; this.autoCommitFlag = false; }
protected void rollbackTransaction(XidImpl arg0) throws SQLException { checkConnection(); transactionXid = null; this.autoCommitFlag = true; try { ResultsFuture<?> future = this.dqp.rollback(arg0); future.get(); } catch (Exception e) { throw TeiidSQLException.create(e); } }
private void directCommit() throws SQLException { if (inLocalTxn) { try { ResultsFuture<?> future = this.dqp.commit(); future.get(); } catch (Exception e) { throw TeiidSQLException.create(e); } logger.fine(JDBCPlugin.Util.getString("MMConnection.Commit_success")); // $NON-NLS-1$ } }
@Test public void testBatchExecution() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); DQP dqp = Mockito.mock(DQP.class); ResultsFuture<ResultsMessage> results = new ResultsFuture<ResultsMessage>(); Mockito.stub(dqp.executeRequest(Mockito.anyLong(), (RequestMessage) Mockito.anyObject())) .toReturn(results); ResultsMessage rm = new ResultsMessage(); rm.setResults(new List<?>[] {Arrays.asList(1), Arrays.asList(2)}); rm.setUpdateResult(true); results.getResultsReceiver().receiveResults(rm); Mockito.stub(conn.getDQP()).toReturn(dqp); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); statement.clearBatch(); // previously caused npe statement.addBatch("delete from table"); // $NON-NLS-1$ statement.addBatch("delete from table1"); // $NON-NLS-1$ assertTrue(Arrays.equals(new int[] {1, 2}, statement.executeBatch())); }