@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()); }
@Test public void testSetPayloadStatement() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); Properties p = new Properties(); Mockito.stub(conn.getExecutionProperties()).toReturn(p); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); assertFalse(statement.execute("set payload foo bar")); // $NON-NLS-1$ }
@Test public void testSetAuthorizationStatement() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); Properties p = new Properties(); Mockito.stub(conn.getExecutionProperties()).toReturn(p); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); assertFalse(statement.execute("set session authorization bar")); // $NON-NLS-1$ Mockito.verify(conn).changeUser("bar", null); }
@Test public void testTimeoutProperty() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); Properties p = new Properties(); p.setProperty(ExecutionProperties.QUERYTIMEOUT, "2"); Mockito.stub(conn.getExecutionProperties()).toReturn(p); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); assertEquals(2, statement.getQueryTimeout()); }
@Test public void testUseJDBC4ColumnNameAndLabelSemantics() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); Properties p = new Properties(); p.setProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS, "false"); Mockito.stub(conn.getExecutionProperties()).toReturn(p); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); assertEquals( Boolean.FALSE.toString(), statement.getExecutionProperty(ExecutionProperties.JDBC4COLUMNNAMEANDLABELSEMANTICS)); }
@Test public void testSetStatement() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); assertFalse(statement.execute("set foo bar")); // $NON-NLS-1$ Mockito.verify(conn).setExecutionProperty("foo", "bar"); assertFalse(statement.execute("set foo 'b''ar' ; ")); // $NON-NLS-1$ Mockito.verify(conn).setExecutionProperty("foo", "b'ar"); assertFalse(statement.execute("set \"foo\" 'b''a1r' ; ")); // $NON-NLS-1$ Mockito.verify(conn).setExecutionProperty("foo", "b'a1r"); }
@Test public void testTransactionStatements() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); Properties p = new Properties(); Mockito.stub(conn.getExecutionProperties()).toReturn(p); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); assertFalse(statement.execute("start transaction")); // $NON-NLS-1$ Mockito.verify(conn).setAutoCommit(false); assertFalse(statement.execute("commit")); // $NON-NLS-1$ Mockito.verify(conn).setAutoCommit(true); assertFalse(statement.execute("start transaction")); // $NON-NLS-1$ assertFalse(statement.execute("rollback")); // $NON-NLS-1$ Mockito.verify(conn).rollback(false); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case NetxscriptPackage.REF_ASSIGNMENT__ASSIGNMENT_REF: setAssignmentRef((Reference) null); return; } super.eUnset(featureID); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case NetxscriptPackage.REF_ASSIGNMENT__ASSIGNMENT_REF: setAssignmentRef((Reference) newValue); return; } super.eSet(featureID, newValue); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case AmethystPackage.SYMBOL__NAME: setName(NAME_EDEFAULT); return; } super.eUnset(featureID); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case AmethystPackage.SYMBOL__NAME: setName((String) newValue); return; } super.eSet(featureID, newValue); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case EolPackage.EXPRESSION_STATEMENT__EXPRESSION: setExpression((Expression) null); return; } super.eUnset(featureID); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case EolPackage.EXPRESSION_STATEMENT__EXPRESSION: setExpression((Expression) newValue); return; } super.eSet(featureID, newValue); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case StatechartexpressionsPackage.PROCEDURE_CALL__PROCEDURE: setProcedure((Procedure) newValue); return; } super.eSet(featureID, newValue); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case SadlPackage.FUNCTIONAL_PROPERTY__PROPERTY_NAME: setPropertyName((ResourceByName) null); return; } super.eUnset(featureID); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case SadlPackage.FUNCTIONAL_PROPERTY__PROPERTY_NAME: setPropertyName((ResourceByName) newValue); return; } super.eSet(featureID, newValue); }
@SuppressWarnings("unchecked") @Test public void testTransactionStatementsAsynch() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); Mockito.stub(conn.submitSetAutoCommitTrue(Mockito.anyBoolean())) .toReturn((ResultsFuture) ResultsFuture.NULL_FUTURE); Properties p = new Properties(); Mockito.stub(conn.getExecutionProperties()).toReturn(p); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); statement.submitExecute("start transaction", null); // $NON-NLS-1$ Mockito.verify(conn).setAutoCommit(false); statement.submitExecute("commit", null); // $NON-NLS-1$ Mockito.verify(conn).submitSetAutoCommitTrue(true); statement.submitExecute("start transaction", null); // $NON-NLS-1$ statement.submitExecute("rollback", null); // $NON-NLS-1$ Mockito.verify(conn).submitSetAutoCommitTrue(false); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case StatechartexpressionsPackage.PROCEDURE_CALL__PROCEDURE: setProcedure((Procedure) null); return; } super.eUnset(featureID); }
@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())); }
@Test public void testDisableLocalTransations() throws Exception { ServerConnection mock = Mockito.mock(ServerConnection.class); DQP dqp = Mockito.mock(DQP.class); Mockito.stub(mock.getService(DQP.class)).toReturn(dqp); ConnectionImpl conn = new ConnectionImpl(mock, new Properties(), "x"); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); assertTrue(conn.getAutoCommit()); statement.execute("set disablelocaltxn true"); assertFalse(statement.execute("start transaction")); // $NON-NLS-1$ conn.beginLocalTxnIfNeeded(); assertFalse(conn.isInLocalTxn()); statement.execute("set disablelocaltxn false"); assertFalse(statement.execute("start transaction")); // $NON-NLS-1$ conn.beginLocalTxnIfNeeded(); assertTrue(conn.isInLocalTxn()); }
@Test public void testPropertiesOverride() throws Exception { ConnectionImpl conn = Mockito.mock(ConnectionImpl.class); Properties p = new Properties(); p.setProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS, Boolean.TRUE.toString()); Mockito.stub(conn.getExecutionProperties()).toReturn(p); StatementImpl statement = new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY); assertEquals( Boolean.TRUE.toString(), statement.getExecutionProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS)); statement.setExecutionProperty( ExecutionProperties.ANSI_QUOTED_IDENTIFIERS, Boolean.FALSE.toString()); assertEquals( Boolean.FALSE.toString(), statement.getExecutionProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS)); assertEquals( Boolean.TRUE.toString(), p.getProperty(ExecutionProperties.ANSI_QUOTED_IDENTIFIERS)); }
/** * Close all the statements open on this connection * * @throws SQLException server statement object could not be closed. */ void closeStatements() throws SQLException { // Closing the statement will cause the // MMConnection.closeStatement() method to be called, // which will modify this.statements. So, we do this iteration // in a separate safe copy of the list List<StatementImpl> statementsSafe = new ArrayList<StatementImpl>(this.statements); SQLException ex = null; for (StatementImpl statement : statementsSafe) { try { statement.close(); } catch (SQLException e) { ex = e; } } if (ex != null) { throw TeiidSQLException.create( ex, JDBCPlugin.Util.getString("MMConnection.Err_closing_stmts")); // $NON-NLS-1$ } }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case GlslPackage.WHILE_STATEMENT__CONDITION: setCondition((Exp) newValue); return; case GlslPackage.WHILE_STATEMENT__DO: setDo((Statement) newValue); return; } super.eSet(featureID, newValue); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case AlfPackage.ANNOTATED_STATEMENT__ANNOTATION: setAnnotation((Annotation) newValue); return; case AlfPackage.ANNOTATED_STATEMENT__BLOCK: setBlock((Block) newValue); return; } super.eSet(featureID, newValue); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case AlfPackage.ANNOTATED_STATEMENT__ANNOTATION: setAnnotation((Annotation) null); return; case AlfPackage.ANNOTATED_STATEMENT__BLOCK: setBlock((Block) null); return; } super.eUnset(featureID); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case FsmPackage.LOOP__GUARD: setGuard((Expression) newValue); return; case FsmPackage.LOOP__BODY: setBody((Program) newValue); return; } super.eSet(featureID, newValue); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case FsmPackage.LOOP__GUARD: setGuard((Expression) null); return; case FsmPackage.LOOP__BODY: setBody((Program) null); return; } super.eUnset(featureID); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eSet(int featureID, Object newValue) { switch (featureID) { case ImpModLangPackage.GOTO__GOTO_MARK: setGotoMark((Mark) newValue); return; case ImpModLangPackage.GOTO__COND: setCond((Condition) newValue); return; } super.eSet(featureID, newValue); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case ImpModLangPackage.GOTO__GOTO_MARK: setGotoMark((Mark) null); return; case ImpModLangPackage.GOTO__COND: setCond((Condition) null); return; } super.eUnset(featureID); }
/** * * <!-- begin-user-doc --> * <!-- end-user-doc --> * * @generated */ @Override public void eUnset(int featureID) { switch (featureID) { case GlslPackage.WHILE_STATEMENT__CONDITION: setCondition((Exp) null); return; case GlslPackage.WHILE_STATEMENT__DO: setDo((Statement) null); return; } super.eUnset(featureID); }