Search in sources :

Example 56 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestSalesForceDirectQueryExecution method testCreate.

@Test
public void testCreate() throws Exception {
    String input = "exec native('create;id=pk;type=table;attributes=one,two,three', 'one', 2, 3.0)";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    ArgumentCaptor<DataPayload> payloadArgument = ArgumentCaptor.forClass(DataPayload.class);
    Mockito.stub(connection.create(payloadArgument.capture())).toReturn(23);
    DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection).create(payloadArgument.capture());
    assertEquals("pk", payloadArgument.getValue().getID());
    assertEquals("table", payloadArgument.getValue().getType());
    assertEquals(3, payloadArgument.getValue().getMessageElements().size());
    assertArrayEquals(new Object[] { 23 }, (Object[]) execution.next().get(0));
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) SObject(com.sforce.soap.partner.sobject.SObject) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) Test(org.junit.Test)

Example 57 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestSalesForceDirectQueryExecution method testUpdate.

@Test
public void testUpdate() throws Exception {
    String input = "exec native('update;id=pk;type=table;attributes=one,two,three', 'one', 2, 3.0)";
    TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
    Command command = util.parseCommand(input);
    ExecutionContext ec = Mockito.mock(ExecutionContext.class);
    RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
    SalesforceConnection connection = Mockito.mock(SalesforceConnection.class);
    ArgumentCaptor<List> payloadArgument = ArgumentCaptor.forClass(List.class);
    Mockito.stub(connection.update(payloadArgument.capture())).toReturn(23);
    DirectQueryExecution execution = (DirectQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
    execution.execute();
    Mockito.verify(connection).update(payloadArgument.capture());
    assertEquals(1, payloadArgument.getValue().size());
    assertEquals("pk", ((DataPayload) payloadArgument.getValue().get(0)).getID());
    assertEquals("table", ((DataPayload) payloadArgument.getValue().get(0)).getType());
    assertEquals(3, ((DataPayload) payloadArgument.getValue().get(0)).getMessageElements().size());
    assertArrayEquals(new Object[] { 23 }, (Object[]) execution.next().get(0));
}
Also used : ExecutionContext(org.teiid.translator.ExecutionContext) Command(org.teiid.language.Command) TranslationUtility(org.teiid.cdk.api.TranslationUtility) List(java.util.List) SObject(com.sforce.soap.partner.sobject.SObject) RuntimeMetadata(org.teiid.metadata.RuntimeMetadata) SalesforceConnection(org.teiid.translator.salesforce.SalesforceConnection) Test(org.junit.Test)

Example 58 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestCoherenceTranslator method getTradeTranslationUtility.

/**
 * this is used as an alternative to loading the vdb
 * @return
 */
private TranslationUtility getTradeTranslationUtility() {
    MetadataStore metadataStore = new MetadataStore();
    // Create TRADE
    // $NON-NLS-1$
    Schema trading = RealMetadataFactory.createPhysicalModel("Trade_Object", metadataStore);
    // Create physical groups
    // $NON-NLS-1$
    Table trade = RealMetadataFactory.createPhysicalGroup("TRADE", trading);
    trade.setNameInSource("org.teiid.translator.coherence.Trade");
    // Create physical elements
    String[] elemNames = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
    "NAME", // $NON-NLS-1$ //$NON-NLS-2$
    "TRADEID" };
    String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.LONG };
    List<Column> cols = RealMetadataFactory.createElements(trade, elemNames, elemTypes);
    // Set name in source on each column
    String[] nameInSource = new String[] { "Name", "TradeId" };
    for (int i = 0; i < nameInSource.length; i++) {
        cols.get(i).setNameInSource(nameInSource[i]);
    }
    List<Column> keys = new ArrayList(1);
    keys.add(cols.get(1));
    KeyRecord trade_pk = RealMetadataFactory.createKey(Type.Primary, "TradeID_PK", trade, keys);
    // LEG
    // $NON-NLS-1$
    Table leg = RealMetadataFactory.createPhysicalGroup("LEG", trading);
    leg.setNameInSource("org.teiid.translator.coherence.Leg");
    // Create physical elements
    String[] legNames = new String[] { // $NON-NLS-1$ //$NON-NLS-2$
    "LEGID", // $NON-NLS-1$ //$NON-NLS-2$
    "NOTATIONAL", // $NON-NLS-1$ //$NON-NLS-2$
    "NAME", // $NON-NLS-1$ //$NON-NLS-2$
    "TRADEID" };
    String[] legTypes = new String[] { DataTypeManager.DefaultDataTypes.LONG, DataTypeManager.DefaultDataTypes.DOUBLE, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.LONG };
    List<Column> legcols = RealMetadataFactory.createElements(leg, legNames, legTypes);
    // Set name in source on each column
    String[] legnameInSource = new String[] { "LegId", "Notational", "Name", "TradeId" };
    for (int i = 0; i < legnameInSource.length; i++) {
        legcols.get(i).setNameInSource(legnameInSource[i]);
    }
    legcols.get(3).setSelectable(false);
    legcols.get(3).setUpdatable(false);
    List<Column> legkeys = new ArrayList(1);
    keys.add(legcols.get(0));
    RealMetadataFactory.createKey(Type.Primary, "Leg_ID_PK", leg, legkeys);
    List<Column> foreignkey = new ArrayList(1);
    foreignkey.add(legcols.get(3));
    ForeignKey fk = RealMetadataFactory.createForeignKey("TRADE_FK", leg, foreignkey, trade_pk);
    fk.setNameInSource("Legs");
    fk.setParent(trade);
    // Set column-specific properties
    // cols.get(0).setSelectable(false);
    // cols.get(0).setSearchType(SearchType.Unsearchable);
    Schema tradeview = RealMetadataFactory.createVirtualModel("Trade_View", metadataStore);
    QueryNode qn = new QueryNode("SELECT Trade_Object.Trade.TradeID, Trade_Object.Trade.Name, Trade_Object.Leg.LegID, Trade_Object.Leg.Notational, Trade_Object.Leg.Name AS LegName " + " FROM Trade_Object.Trade, Trade_Object.Leg " + "WHERE	Trade_Object.Trade.TradeID = Trade_Object.Leg.TradeID " + "SELECT * FROM Trade.Trad " + " WHERE Trade.Trade.TradeID = Trade.Trade.TradeID");
    Table trades = RealMetadataFactory.createVirtualGroup("Trades", tradeview, qn);
    return new TranslationUtility(RealMetadataFactory.createTransformationMetadata(metadataStore, "Trade"));
}
Also used : Table(org.teiid.metadata.Table) Schema(org.teiid.metadata.Schema) ArrayList(java.util.ArrayList) TranslationUtility(org.teiid.cdk.api.TranslationUtility) ForeignKey(org.teiid.metadata.ForeignKey) MetadataStore(org.teiid.metadata.MetadataStore) KeyRecord(org.teiid.metadata.KeyRecord) Column(org.teiid.metadata.Column) QueryNode(org.teiid.query.mapping.relational.QueryNode)

Example 59 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestSolrUpdateExecution method setUp.

@Before
public void setUp() throws Exception {
    this.translator = new SolrExecutionFactory();
    this.translator.start();
    TransformationMetadata metadata = RealMetadataFactory.fromDDL(ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("exampleTBL.ddl")), "example", "solr");
    this.utility = new TranslationUtility(metadata);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) TranslationUtility(org.teiid.cdk.api.TranslationUtility) Before(org.junit.Before)

Example 60 with TranslationUtility

use of org.teiid.cdk.api.TranslationUtility in project teiid by teiid.

the class TestTeiidLanguageToSolr method setUp.

private QueryMetadataInterface setUp(String ddl, String vdbName, String modelName) throws Exception {
    this.translator = new SolrExecutionFactory();
    this.translator.start();
    metadata = RealMetadataFactory.fromDDL(ddl, vdbName, modelName);
    this.utility = new TranslationUtility(metadata);
    return metadata;
}
Also used : TranslationUtility(org.teiid.cdk.api.TranslationUtility)

Aggregations

TranslationUtility (org.teiid.cdk.api.TranslationUtility)76 Command (org.teiid.language.Command)52 Test (org.junit.Test)45 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 ExecutionContext (org.teiid.translator.ExecutionContext)33 RuntimeMetadata (org.teiid.metadata.RuntimeMetadata)26 SimpleDBSQLVisitor (org.teiid.translator.simpledb.SimpleDBSQLVisitor)14 MetadataFactory (org.teiid.metadata.MetadataFactory)13 FunctionTree (org.teiid.query.function.FunctionTree)11 UDFSource (org.teiid.query.function.UDFSource)11 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)11 Before (org.junit.Before)10 LdapContext (javax.naming.ldap.LdapContext)9 ByteArrayInputStream (java.io.ByteArrayInputStream)8 SimpleDBExecutionFactory (org.teiid.translator.simpledb.SimpleDBExecutionFactory)8 List (java.util.List)7 ResultSetExecution (org.teiid.translator.ResultSetExecution)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 DataSource (javax.activation.DataSource)6 WSConnection (org.teiid.translator.WSConnection)6