Ejemplo n.º 1
0
 @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());
 }
Ejemplo n.º 2
0
 @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$
 }
Ejemplo n.º 3
0
 @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);
 }
Ejemplo n.º 4
0
 @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());
 }
Ejemplo n.º 5
0
  @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));
  }
Ejemplo n.º 6
0
  @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");
  }
Ejemplo n.º 7
0
 @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);
 }
Ejemplo n.º 8
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 9
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 10
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 11
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 14
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 15
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 16
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 17
0
 @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);
 }
Ejemplo n.º 18
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 19
0
 @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()));
 }
Ejemplo n.º 20
0
  @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());
  }
Ejemplo n.º 21
0
 @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));
 }
Ejemplo n.º 22
0
 /**
  * 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$
   }
 }
Ejemplo n.º 23
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 26
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 27
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 28
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 29
0
 /**
  *
  * <!-- 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);
 }
Ejemplo n.º 30
0
 /**
  *
  * <!-- 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);
 }