use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestSQLConversionVisitor method queryMetadataInterface.
private static TransformationMetadata queryMetadataInterface() {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("prestodbModel");
MetadataFactory mf = new MetadataFactory("prestodb", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
mf.setParser(new QueryParser());
mf.parse(new FileReader(UnitTestUtil.getTestDataFile("sample.ddl")));
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
} catch (MetadataException | FileNotFoundException e) {
throw new RuntimeException(e);
}
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestDataEntitySchemaBuilder method testArrayType.
@Test
public void testArrayType() throws Exception {
ModelMetaData model = new ModelMetaData();
model.setName("nw");
model.setModelType(Type.PHYSICAL);
MetadataFactory mf = new MetadataFactory("northwind", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), model);
EdmDataServices edm = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new FileReader(UnitTestUtil.getTestDataFile("arraytest.xml"))));
ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
metadataProcessor.getMetadata(mf, edm);
Column c = mf.getSchema().getTable("G2").getColumnByName("e3");
assertEquals("integer[]", c.getRuntimeType());
Procedure p = mf.getSchema().getProcedure("ARRAYITERATE");
assertEquals("varbinary[]", p.getParameters().get(0).getRuntimeType());
assertEquals("varbinary", p.getResultSet().getColumns().get(0).getRuntimeType());
// String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
// System.out.println(ddl);
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataUpdateExecution method testArrayUpdate.
@Test
public void testArrayUpdate() throws Exception {
ModelMetaData model = new ModelMetaData();
model.setName("nw");
model.setModelType(Type.PHYSICAL);
MetadataFactory mf = new MetadataFactory("northwind", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), model);
EdmDataServices edm = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new FileReader(UnitTestUtil.getTestDataFile("arraytest.xml"))));
ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
metadataProcessor.getMetadata(mf, edm);
Column c = mf.getSchema().getTable("G2").getColumnByName("e3");
assertEquals("integer[]", c.getRuntimeType());
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
String query = "Update G2 set e3 = (1,2,3) where e1 = 1";
String expectedURL = "G2(1)";
String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" xml:base=\"http://localhost:8080/odata/loopy/\">\n" + " <title type=\"text\">VM1.x</title>\n" + " <id>http://localhost:8080/odata/loopy/VM1.x</id>\n" + " <updated>2015-10-14T19:36:58Z</updated>\n" + " <link rel=\"self\" title=\"VM1.x\" href=\"VM1.x\" />\n" + " <entry>\n" + " <id>http://localhost:8080/odata/loopy/VM1.x('x')</id>\n" + " <title type=\"text\" />\n" + " <updated>2015-10-14T19:36:58Z</updated>\n" + " <author>\n" + " <name />\n" + " </author>\n" + " <link rel=\"edit\" title=\"x\" href=\"VM1.x('x')\" />\n" + " <category term=\"PM1.G2\" scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\" />\n" + " <content type=\"application/xml\">\n" + " <m:properties>\n" + " <d:e1>32</d:e1>\n" + " <d:e3 m:type=\"Collection(Edm.Int32)\">\n" + " <d:element>1</d:element>\n" + " <d:element>2</d:element>\n" + " <d:element>3</d:element>\n" + " </d:e3>\n" + " </m:properties>\n" + " </content>\n" + " </entry>\n" + "</feed>";
String payload = helpExecute(query, result, expectedURL, new int[] { 200, 204 }, metadata, 2);
String expected = "<category term=\"PM1.G2\" " + "scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\">" + "</category>" + "<content type=\"application/xml\">" + "<m:properties><d:e3 m:type=\"Collection(Edm.Int32)\">" + "<d:element>1</d:element>" + "<d:element>2</d:element>" + "<d:element>3</d:element>" + "</d:e3>" + "</m:properties>" + "</content>" + "</entry>";
assertTrue(expected, payload.endsWith(expected));
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestODataUpdateExecution method testArrayInsert.
@Test
public void testArrayInsert() throws Exception {
ModelMetaData model = new ModelMetaData();
model.setName("nw");
model.setModelType(Type.PHYSICAL);
MetadataFactory mf = new MetadataFactory("northwind", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), model);
EdmDataServices edm = new EdmxFormatParser().parseMetadata(StaxUtil.newXMLEventReader(new FileReader(UnitTestUtil.getTestDataFile("arraytest.xml"))));
ODataMetadataProcessor metadataProcessor = new ODataMetadataProcessor();
// $NON-NLS-1$
PropertiesUtils.setBeanProperties(metadataProcessor, mf.getModelProperties(), "importer");
metadataProcessor.getMetadata(mf, edm);
Column c = mf.getSchema().getTable("G2").getColumnByName("e3");
assertEquals("integer[]", c.getRuntimeType());
String ddl = DDLStringVisitor.getDDLString(mf.getSchema(), null, null);
TransformationMetadata metadata = RealMetadataFactory.fromDDL(ddl, "northwind", "nw");
String query = "insert into G2 (e1, e3) values(1, (1,2,3))";
String expectedURL = "G2";
String result = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<feed xmlns=\"http://www.w3.org/2005/Atom\" xmlns:d=\"http://schemas.microsoft.com/ado/2007/08/dataservices\" xmlns:m=\"http://schemas.microsoft.com/ado/2007/08/dataservices/metadata\" xml:base=\"http://localhost:8080/odata/loopy/\">\n" + " <title type=\"text\">VM1.x</title>\n" + " <id>http://localhost:8080/odata/loopy/VM1.x</id>\n" + " <updated>2015-10-14T19:36:58Z</updated>\n" + " <link rel=\"self\" title=\"VM1.x\" href=\"VM1.x\" />\n" + " <entry>\n" + " <id>http://localhost:8080/odata/loopy/VM1.x('x')</id>\n" + " <title type=\"text\" />\n" + " <updated>2015-10-14T19:36:58Z</updated>\n" + " <author>\n" + " <name />\n" + " </author>\n" + " <link rel=\"edit\" title=\"x\" href=\"VM1.x('x')\" />\n" + " <category term=\"PM1.G2\" scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\" />\n" + " <content type=\"application/xml\">\n" + " <m:properties>\n" + " <d:e1>32</d:e1>\n" + " <d:e3 m:type=\"Collection(Edm.Int32)\">\n" + " <d:element>1</d:element>\n" + " <d:element>2</d:element>\n" + " <d:element>3</d:element>\n" + " </d:e3>\n" + " </m:properties>\n" + " </content>\n" + " </entry>\n" + "</feed>";
String payload = helpExecute(query, result, expectedURL, new int[] { 201, 201 }, metadata, 1);
String expected = "<category term=\"PM1.G2\" " + "scheme=\"http://schemas.microsoft.com/ado/2007/08/dataservices/scheme\">" + "</category>" + "<content type=\"application/xml\">" + "<m:properties>" + "<d:e1 m:type=\"Edm.Int32\">1</d:e1>" + "<d:e3 m:type=\"Collection(Edm.Int32)\">" + "<d:element>1</d:element>" + "<d:element>2</d:element>" + "<d:element>3</d:element>" + "</d:e3>" + "</m:properties>" + "</content>" + "</entry>";
assertTrue(expected, payload.endsWith(expected));
}
use of org.teiid.adminapi.impl.ModelMetaData in project teiid by teiid.
the class TestVisitors method exampleSalesforce.
public static QueryMetadataInterface exampleSalesforce() {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("SalesforceModel");
MetadataFactory mf = new MetadataFactory("sf", 1, SystemMetadata.getInstance().getRuntimeTypeMap(), mmd);
mf.setParser(new QueryParser());
// load the metadata as captured from 8.9 on 9/3/2014
mf.parse(new FileReader(UnitTestUtil.getTestDataFile("sf.ddl")));
SalesForceExecutionFactory factory = new SalesForceExecutionFactory();
factory.start();
for (FunctionMethod func : factory.getPushDownFunctions()) {
mf.addFunction(func);
}
SalesForceMetadataProcessor.addProcedrues(mf);
// Create Contacts group - which has different name in sources
// $NON-NLS-1$
Table contactTable = RealMetadataFactory.createPhysicalGroup("Contacts", mf.getSchema());
// $NON-NLS-1$
contactTable.setNameInSource("Contact");
// $NON-NLS-1$
contactTable.setProperty("Supports Query", Boolean.TRUE.toString());
// Create Contact Columns
String[] elemNames = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"ContactID", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"Name", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"AccountId", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"InitialContact", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"LastTime" };
String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.DefaultDataTypes.TIME };
List<Column> contactCols = RealMetadataFactory.createElements(contactTable, elemNames, elemTypes);
// Set name in source on each column
String[] contactNameInSource = new String[] { // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"id", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"ContactName", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"accountid", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"InitialContact", // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
"LastTime" };
for (int i = 0; i < 2; i++) {
Column obj = contactCols.get(i);
obj.setNameInSource(contactNameInSource[i]);
}
// add a procedure with a native query property
List<ProcedureParameter> params = new LinkedList<ProcedureParameter>();
params.add(RealMetadataFactory.createParameter("x", SPParameter.IN, TypeFacility.RUNTIME_NAMES.STRING));
Procedure nativeProc = RealMetadataFactory.createStoredProcedure("foo", mf.getSchema(), params);
nativeProc.setProperty(SQLStringVisitor.TEIID_NATIVE_QUERY, "search;select accountname from account where accountid = $1");
nativeProc.setResultSet(RealMetadataFactory.createResultSet("rs", new String[] { "accountname" }, new String[] { TypeFacility.RUNTIME_NAMES.STRING }));
TransformationMetadata tm = RealMetadataFactory.createTransformationMetadata(mf.asMetadataStore(), "x");
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations