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));
}
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));
}
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"));
}
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);
}
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;
}
Aggregations