use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class ConnectorHost method executeCommand.
public List executeCommand(String query) throws TranslatorException {
Command command = getCommand(query);
RuntimeMetadata runtimeMetadata = getRuntimeMetadata();
return executeCommand(command, runtimeMetadata, true);
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestSAPODataMetadataProcessor method testSchema.
@Test
public void testSchema() throws Exception {
translator = new SAPODataExecutionFactory();
translator.start();
String csdl = ObjectConverterUtil.convertFileToString(UnitTestUtil.getTestDataFile("sap-metadata.xml"));
SAPMetadataProcessor processor = new SAPMetadataProcessor();
Properties props = new Properties();
MetadataFactory mf = new MetadataFactory("vdb", 1, "flight", SystemMetadata.getInstance().getRuntimeTypeMap(), props, null);
processor.getMetadata(mf, new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new InputStreamReader(new ByteArrayInputStream(csdl.getBytes())))));
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "flight", new FunctionTree("foo", new UDFSource(translator.getPushDownFunctions())));
ValidatorReport report = new MetadataValidator().validate(metadata.getVdbMetaData(), metadata.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
// String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
// System.out.println(ddl);
//
// MetadataFactory mf2 = new MetadataFactory(null, 1, "flight", SystemMetadata.getInstance().getRuntimeTypeMap(), new Properties(), null);
// QueryParser.getQueryParser().parseDDL(mf2, ddl);
TranslationUtility utility = new TranslationUtility(metadata);
RuntimeMetadata rm = utility.createRuntimeMetadata();
Table t = rm.getTable("flight", "SubscriptionCollection");
assertNotNull(t);
// check the label name
assertNotNull(t.getColumnByName("persistNotifications"));
assertTrue(!t.getColumnByName("ID").isUpdatable());
assertEquals("Persist Notification", t.getColumnByName("persistNotifications").getAnnotation());
// check filterable
assertEquals(SearchType.Unsearchable, t.getColumnByName("persistNotifications").getSearchType());
// check sortable
assertEquals(SearchType.Unsearchable, t.getColumnByName("filter").getSearchType());
// check visible
assertEquals(false, t.getColumnByName("filter").isSelectable());
// check required-in-filter
assertEquals(1, t.getAccessPatterns().size());
assertEquals(2, t.getAccessPatterns().get(0).getColumns().size());
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestNativeSpreadsheet method testDirect.
@Test
public void testDirect() throws TranslatorException {
SpreadsheetExecutionFactory sef = new SpreadsheetExecutionFactory();
sef.setSupportsDirectQueryProcedure(true);
String input = "call native('worksheet=x;query=$1 foo;limit=2', 'a')";
TranslationUtility util = FakeTranslationFactory.getInstance().getExampleTranslationUtility();
Command command = util.parseCommand(input);
ExecutionContext ec = Mockito.mock(ExecutionContext.class);
RuntimeMetadata rm = Mockito.mock(RuntimeMetadata.class);
GoogleSpreadsheetConnection connection = Mockito.mock(GoogleSpreadsheetConnection.class);
RowsResult result = Mockito.mock(RowsResult.class);
Mockito.stub(result.iterator()).toReturn(Arrays.asList(new SheetRow()).iterator());
Mockito.stub(connection.executeQuery("x", "'a' foo", null, 2, 0)).toReturn(result);
ResultSetExecution execution = (ResultSetExecution) sef.createExecution(command, ec, rm, connection);
execution.execute();
List<?> vals = execution.next();
assertTrue(vals.get(0) instanceof Object[]);
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestLDAPDirectQueryExecution method testUpdate.
@Test
public void testUpdate() throws Exception {
String input = "exec native('update;uid=doe,ou=people,o=teiid.org;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);
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();
ArgumentCaptor<String> nameArgument = ArgumentCaptor.forClass(String.class);
ArgumentCaptor<ModificationItem[]> modificationItemArgument = ArgumentCaptor.forClass(ModificationItem[].class);
Mockito.verify(ctx).modifyAttributes(nameArgument.capture(), modificationItemArgument.capture());
assertEquals("uid=doe,ou=people,o=teiid.org", nameArgument.getValue());
assertEquals("one", modificationItemArgument.getValue()[0].getAttribute().getID());
assertEquals("one", modificationItemArgument.getValue()[0].getAttribute().get());
assertEquals("two", modificationItemArgument.getValue()[1].getAttribute().getID());
assertEquals("2", modificationItemArgument.getValue()[1].getAttribute().get());
assertEquals("three", modificationItemArgument.getValue()[2].getAttribute().getID());
assertEquals("3.0", modificationItemArgument.getValue()[2].getAttribute().get());
}
use of org.teiid.metadata.RuntimeMetadata in project teiid by teiid.
the class TestLDAPDirectQueryExecution method testSearchDefaultsAndEscaping.
@Test
public void testSearchDefaultsAndEscaping() throws Exception {
String input = "exec native('search;context-name=corporate;filter=(;;)')";
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("corporate")).toReturn(ctx);
LDAPDirectSearchQueryExecution execution = (LDAPDirectSearchQueryExecution) TRANSLATOR.createExecution(command, ec, rm, connection);
execution.execute();
LDAPSearchDetails details = execution.getDelegate().getSearchDetails();
assertEquals("corporate", details.getContextName());
assertEquals("(;)", details.getContextFilter());
assertEquals(-1, details.getCountLimit());
assertEquals(0, details.getTimeLimit());
assertEquals(1, details.getSearchScope());
assertEquals(0, details.getElementList().size());
}
Aggregations