Пример #1
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");
  }
Пример #2
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);
 }
Пример #3
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());
 }
Пример #4
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$
 }
Пример #5
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());
  }
Пример #6
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);
 }
Пример #7
0
 @Test
 public void testSetTxnIsolationLevel() throws SQLException {
   ConnectionImpl conn = Mockito.mock(ConnectionImpl.class);
   StatementImpl statement =
       new StatementImpl(conn, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY);
   assertFalse(
       statement.execute(
           "set session characteristics as transaction isolation level read committed")); //$NON-NLS-1$
   Mockito.verify(conn).setTransactionIsolation(Connection.TRANSACTION_READ_COMMITTED);
   assertFalse(
       statement.execute(
           "set session characteristics as transaction isolation level read uncommitted")); //$NON-NLS-1$
   Mockito.verify(conn).setTransactionIsolation(Connection.TRANSACTION_READ_UNCOMMITTED);
   assertFalse(
       statement.execute(
           "set session characteristics as transaction isolation level serializable")); //$NON-NLS-1$
   Mockito.verify(conn).setTransactionIsolation(Connection.TRANSACTION_SERIALIZABLE);
   assertFalse(
       statement.execute(
           "set session characteristics as transaction isolation level repeatable read")); //$NON-NLS-1$
   Mockito.verify(conn).setTransactionIsolation(Connection.TRANSACTION_REPEATABLE_READ);
 }