Search in sources :

Example 11 with CommandBuilder

use of org.teiid.cdk.CommandBuilder in project teiid by teiid.

the class TestOracleTranslator method testConcat2.

@Test
public void testConcat2() throws Exception {
    // $NON-NLS-1$
    String input = "select concat2(stringnum, stringkey) from bqt1.Smalla";
    // $NON-NLS-1$
    String output = "SELECT (g_0.StringNum || g_0.StringKey) FROM SmallA g_0";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    commandBuilder.getLanguageBridgeFactory().setSupportsConcat2(true);
    Command obj = commandBuilder.getCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
Also used : Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 12 with CommandBuilder

use of org.teiid.cdk.CommandBuilder in project teiid by teiid.

the class TestOracleTranslator method testNativeQueryProcPreparedExecution.

@Test
public void testNativeQueryProcPreparedExecution() throws Exception {
    CommandBuilder commandBuilder = new CommandBuilder(getOracleSpecificMetadata());
    Command command = commandBuilder.getCommand("call proc(2)");
    Connection connection = Mockito.mock(Connection.class);
    CallableStatement cs = Mockito.mock(CallableStatement.class);
    Mockito.stub(cs.getUpdateCount()).toReturn(-1);
    ResultSet rs = Mockito.mock(ResultSet.class);
    Mockito.stub(cs.getObject(1)).toReturn(rs);
    Mockito.stub(cs.getInt(3)).toReturn(4);
    // $NON-NLS-1$
    Mockito.stub(connection.prepareCall("select x from y where z = ?")).toReturn(cs);
    OracleExecutionFactory ef = new OracleExecutionFactory();
    JDBCProcedureExecution procedureExecution = new JDBCProcedureExecution(command, connection, Mockito.mock(ExecutionContext.class), ef);
    procedureExecution.execute();
    Mockito.verify(cs, Mockito.never()).registerOutParameter(1, OracleExecutionFactory.CURSOR_TYPE);
    Mockito.verify(cs, Mockito.never()).getObject(1);
    Mockito.verify(cs, Mockito.times(1)).setObject(1, 2, Types.INTEGER);
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CallableStatement(java.sql.CallableStatement) Connection(java.sql.Connection) ResultSet(java.sql.ResultSet) JDBCProcedureExecution(org.teiid.translator.jdbc.JDBCProcedureExecution) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 13 with CommandBuilder

use of org.teiid.cdk.CommandBuilder in project teiid by teiid.

the class TestOracleTranslator method helpTestVisitor.

/**
 * Helper method takes a QueryMetadataInterface impl instead of a VDB filename
 * @throws TranslatorException
 */
private Command helpTestVisitor(QueryMetadataInterface metadata, String input, ExecutionContext context, String dbmsTimeZone, String expectedOutput) throws TranslatorException {
    // Convert from sql to objects
    CommandBuilder commandBuilder = new CommandBuilder(metadata);
    Command obj = commandBuilder.getCommand(input);
    this.helpTestVisitor(obj, context, dbmsTimeZone, expectedOutput);
    return obj;
}
Also used : Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CommandBuilder(org.teiid.cdk.CommandBuilder)

Example 14 with CommandBuilder

use of org.teiid.cdk.CommandBuilder in project teiid by teiid.

the class TestOracleTranslator method testConcat2_useLiteral.

@Test
public void testConcat2_useLiteral() throws Exception {
    // $NON-NLS-1$
    String input = "select concat2(stringnum,'_xx') from bqt1.Smalla";
    // $NON-NLS-1$
    String output = "SELECT (g_0.StringNum || '_xx') FROM SmallA g_0";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    commandBuilder.getLanguageBridgeFactory().setSupportsConcat2(true);
    Command obj = commandBuilder.getCommand(input, true, true);
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
Also used : Command(org.teiid.language.Command) TranslatedCommand(org.teiid.translator.jdbc.TranslatedCommand) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Example 15 with CommandBuilder

use of org.teiid.cdk.CommandBuilder in project teiid by teiid.

the class TestOracleTranslator method testArrayComparison.

@Test
public void testArrayComparison() throws Exception {
    // $NON-NLS-1$
    String input = "select intkey from bqt1.smalla where intkey = 5";
    // $NON-NLS-1$
    String output = "SELECT g_0.IntKey FROM SmallA g_0 WHERE (g_0.IntKey, g_0.IntKey) = ((5, 2))";
    CommandBuilder commandBuilder = new CommandBuilder(RealMetadataFactory.exampleBQTCached());
    Select obj = (Select) commandBuilder.getCommand(input, true, true);
    Comparison comp = (Comparison) obj.getWhere();
    // modify to an array comparison, since there is not yet parsing support
    comp.setLeftExpression(new Array(comp.getLeftExpression().getType(), Arrays.asList(comp.getLeftExpression(), comp.getLeftExpression())));
    comp.setRightExpression(new Array(comp.getLeftExpression().getType(), Arrays.asList(comp.getRightExpression(), new Literal(2, TypeFacility.RUNTIME_TYPES.INTEGER))));
    TranslationHelper.helpTestVisitor(output, TRANSLATOR, obj);
}
Also used : Array(org.teiid.language.Array) Comparison(org.teiid.language.Comparison) Literal(org.teiid.language.Literal) Select(org.teiid.language.Select) CommandBuilder(org.teiid.cdk.CommandBuilder) Test(org.junit.Test)

Aggregations

CommandBuilder (org.teiid.cdk.CommandBuilder)34 Test (org.junit.Test)31 Command (org.teiid.language.Command)25 SQLConversionVisitor (org.teiid.translator.jdbc.SQLConversionVisitor)9 TranslatedCommand (org.teiid.translator.jdbc.TranslatedCommand)9 ExecutionContext (org.teiid.translator.ExecutionContext)8 RuntimeMetadataImpl (org.teiid.dqp.internal.datamgr.RuntimeMetadataImpl)6 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)6 Properties (java.util.Properties)5 DataSource (javax.activation.DataSource)5 Call (org.teiid.language.Call)5 MetadataFactory (org.teiid.metadata.MetadataFactory)5 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)5 WSConnection (org.teiid.translator.WSConnection)5 Connection (java.sql.Connection)4 Select (org.teiid.language.Select)4 StAXSource (javax.xml.transform.stax.StAXSource)3 Procedure (org.teiid.metadata.Procedure)3 ByteArrayInputStream (java.io.ByteArrayInputStream)2 File (java.io.File)2