Search in sources :

Example 76 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestJDBCDirectQueryExecution method testPrepareUpdateCount.

@Test
public void testPrepareUpdateCount() throws Exception {
    // $NON-NLS-1$
    Command command = TranslationHelper.helpTranslate(TranslationHelper.BQT_VDB, "call native('update source set e1=? where e2 = ?', 2, 'foo')");
    Connection connection = Mockito.mock(Connection.class);
    PreparedStatement stmt = Mockito.mock(PreparedStatement.class);
    ResultSet rs = Mockito.mock(ResultSet.class);
    ResultSetMetaData rsm = Mockito.mock(ResultSetMetaData.class);
    Mockito.stub(stmt.getUpdateCount()).toReturn(-1);
    Mockito.stub(stmt.getUpdateCount()).toReturn(5);
    Mockito.stub(stmt.execute()).toReturn(false);
    Mockito.stub(rs.getMetaData()).toReturn(rsm);
    Mockito.stub(rsm.getColumnCount()).toReturn(2);
    // $NON-NLS-1$
    Mockito.stub(connection.prepareStatement("update source set e1=? where e2 = ?")).toReturn(stmt);
    DatabaseMetaData dbmd = Mockito.mock(DatabaseMetaData.class);
    Mockito.stub(connection.getMetaData()).toReturn(dbmd);
    JDBCExecutionFactory ef = new JDBCExecutionFactory();
    ef.setSupportsDirectQueryProcedure(true);
    ResultSetExecution execution = (ResultSetExecution) ef.createExecution(command, new FakeExecutionContextImpl(), Mockito.mock(RuntimeMetadata.class), connection);
    execution.execute();
    assertArrayEquals(new Object[] { 5 }, (Object[]) execution.next().get(0));
}
Also used : ResultSetMetaData(java.sql.ResultSetMetaData) ResultSetExecution(org.teiid.translator.ResultSetExecution) FakeExecutionContextImpl(org.teiid.dqp.internal.datamgr.FakeExecutionContextImpl) Command(org.teiid.language.Command) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) PreparedStatement(java.sql.PreparedStatement) DatabaseMetaData(java.sql.DatabaseMetaData) Test(org.junit.Test)

Example 77 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestModeShapeSqlTranslator method helpTestVisitor.

public void helpTestVisitor(String input, String expectedOutput) throws TranslatorException {
    Command obj = UTIL.parseCommand(input, true, true);
    TranslationHelper.helpTestVisitor(expectedOutput, TRANSLATOR, obj);
}
Also used : Command(org.teiid.language.Command)

Example 78 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestNetezzaTranslatorCapabilities method helpTestVisitor.

public void helpTestVisitor(String input, String expectedOutput) throws TranslatorException {
    // Convert from sql to objects
    Command obj = FakeTranslationFactory.getInstance().getBQTTranslationUtility().parseCommand(input);
    TranslatedCommand tc = new TranslatedCommand(Mockito.mock(ExecutionContext.class), TRANSLATOR);
    tc.translateCommand(obj);
    // Check stuff
    assertEquals("Did not get correct sql", expectedOutput, tc.getSql());
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand)

Example 79 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestLDAPDirectQueryExecution method testDelete.

@Test
public void testDelete() throws Exception {
    String input = "exec native('delete;uid=doe,ou=people,o=teiid.org')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    LdapContext connection = Mockito.mock(LdapContext.class);
    LdapContext ctx = Mockito.mock(LdapContext.class);
    Mockito.stub(connection.lookup("")).toReturn(ctx);
    LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(ctx, Mockito.times(1)).destroySubcontext("uid=doe,ou=people,o=teiid.org");
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) LdapContext(javax.naming.ldap.LdapContext) Test(org.junit.Test)

Example 80 with Command

use of org.teiid.language.Command in project teiid by teiid.

the class TestLDAPDirectQueryExecution method testCreateFail.

@Test(expected = TranslatorException.class)
public void testCreateFail() throws Exception {
    String input = "exec native('create;uid=doe,ou=people,o=teiid.org;attributes=one,two,three', 'one')";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    LdapContext connection = Mockito.mock(LdapContext.class);
    LdapContext ctx = Mockito.mock(LdapContext.class);
    Mockito.stub(connection.lookup("")).toReturn(ctx);
    LDAPDirectCreateUpdateDeleteQueryExecution execution = (LDAPDirectCreateUpdateDeleteQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) LdapContext(javax.naming.ldap.LdapContext) Test(org.junit.Test)

Aggregations

Command (org.teiid.language.Command)136 Test (org.junit.Test)99 ExecutionContext (org.teiid.translator.ExecutionContext)62 TranslationUtility (org.teiid.cdk.api.TranslationUtility)52 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)40 CommandBuilder (org.teiid.cdk.CommandBuilder)25 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)20 ResultSetExecution (org.teiid.translator.ResultSetExecution)18 TranslatedCommand (org.teiid.translator.jdbc.TranslatedCommand)17 UpdateExecution (org.teiid.translator.UpdateExecution)16 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 List (java.util.List)11 Connection (java.sql.Connection)10 LdapContext (javax.naming.ldap.LdapContext)9 Range (org.apache.accumulo.core.data.Range)9 SQLConversionVisitor (org.teiid.translator.jdbc.SQLConversionVisitor)9 MetadataFactory (org.teiid.metadata.MetadataFactory)8 ArrayList (java.util.ArrayList)7 FunctionTree (org.teiid.query.function.FunctionTree)7 UDFSource (org.teiid.query.function.UDFSource)7