use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestMetaDataProcessor method examplePrivatePhysicalModel.
public static TransformationMetadata examplePrivatePhysicalModel() {
MetadataStore metadataStore = new MetadataStore();
// Create models
// $NON-NLS-1$
Schema pm1 = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
// $NON-NLS-1$
Schema vm1 = RealMetadataFactory.createVirtualModel("vm1", metadataStore);
// Create physical groups
// $NON-NLS-1$
Table pm1g1 = RealMetadataFactory.createPhysicalGroup("g1", pm1);
// $NON-NLS-1$ //$NON-NLS-2$
QueryNode vm1g1n1 = new QueryNode("SELECT * FROM pm1.g1");
// $NON-NLS-1$
Table vm1g1 = RealMetadataFactory.createVirtualGroup("g1", vm1, vm1g1n1);
// $NON-NLS-1$
Table pm1g2 = RealMetadataFactory.createPhysicalGroup("g2", pm1);
// Create physical elements
RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$
new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.SHORT });
// Create physical elements
List<Column> pm1g2e = RealMetadataFactory.createElements(pm1g2, // $NON-NLS-1$
new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.BIG_DECIMAL });
Column e1 = pm1g2e.get(0);
e1.setPrecision(19);
e1.setLength(21);
e1.setScale(4);
RealMetadataFactory.createElements(vm1g1, // $NON-NLS-1$
new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
// Create the facade from the store
return RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestMetadataFactory method setUp.
@Before
public void setUp() {
MetadataStore metadataStore = new MetadataStore();
CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
VDBMetaData vdbMetaData = new VDBMetaData();
// $NON-NLS-1$
vdbMetaData.setName("foo");
vdbMetaData.setVersion(1);
Map<String, VDBResources.Resource> vdbEntries = new LinkedHashMap<String, VDBResources.Resource>();
vdbEntries.put(MY_RESOURCE_PATH, new VDBResources.Resource(root.getChild("foo")));
metadataFactory = new RuntimeMetadataImpl(new TransformationMetadata(vdbMetaData, store, vdbEntries, null, null));
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestODataIntegration method testBasicTypes.
@Test
public void testBasicTypes() throws Exception {
try {
ModelMetaData mmd = new ModelMetaData();
mmd.setName("m");
mmd.addSourceMapping("x3", "x3", null);
MetadataStore ms = RealMetadataFactory.exampleBQTStore();
Schema s = ms.getSchema("BQT1");
KeyRecord pk = new KeyRecord(KeyRecord.Type.Primary);
Table smalla = s.getTable("SmallA");
pk.setName("pk");
pk.addColumn(smalla.getColumnByName("IntKey"));
smalla.setPrimaryKey(pk);
String ddl = DDLStringVisitor.getDDLString(s, EnumSet.allOf(SchemaObjectType.class), "SmallA");
mmd.addSourceMetadata("DDL", ddl);
HardCodedExecutionFactory hc = buildHardCodedExecutionFactory();
teiid.addTranslator("x3", hc);
teiid.deployVDB("northwind", mmd);
localClient = getClient(teiid.getDriver(), "northwind", new Properties());
ContentResponse response = http.GET(baseURL + "/northwind/m/SmallA?$format=json&$select=TimeValue");
assertEquals(200, response.getStatus());
} finally {
localClient = null;
teiid.undeployVDB("northwind");
}
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestODataSQLBuilder method setup.
private BaseState setup(String ddl, String url, String method, ServletInputStream stream, BaseState state) throws Exception {
Client client = Mockito.mock(Client.class);
DDLHolder model = new DDLHolder("PM1", ddl);
TransformationMetadata metadata = RealMetadataFactory.fromDDL("vdb", model);
MetadataStore store = metadata.getMetadataStore();
// TranslationUtility utility = new TranslationUtility(metadata);
OData odata = OData4Impl.newInstance();
org.teiid.metadata.Schema teiidSchema = store.getSchema("PM1");
CsdlSchema schema = ODataSchemaBuilder.buildMetadata("vdb", teiidSchema);
TeiidEdmProvider edmProvider = new TeiidEdmProvider("baseuri", schema, "x");
ServiceMetadata serviceMetadata = odata.createServiceMetadata(edmProvider, Collections.<EdmxReference>emptyList());
ODataHttpHandler handler = odata.createHandler(serviceMetadata);
Hashtable<String, String> headers = new Hashtable<String, String>();
headers.put("Content-Type", "application/json");
Mockito.stub(client.getMetadataStore()).toReturn(store);
Mockito.stub(client.executeCount(Mockito.any(Query.class), Mockito.anyListOf(SQLParameter.class))).toReturn(new CountResponse() {
@Override
public int getCount() {
return 10;
}
});
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.stub(request.getHeaderNames()).toReturn(headers.keys());
Mockito.stub(request.getHeaders("Content-Type")).toReturn(headers.elements());
Mockito.stub(request.getMethod()).toReturn(method);
String requestURL = url;
String queryString = "";
int idx = url.indexOf("?");
if (idx != -1) {
requestURL = url.substring(0, idx);
queryString = url.substring(idx + 1);
}
Mockito.stub(request.getRequestURL()).toReturn(new StringBuffer(requestURL));
Mockito.stub(request.getQueryString()).toReturn(queryString);
Mockito.stub(request.getServletPath()).toReturn("");
Mockito.stub(request.getContextPath()).toReturn("/odata4/vdb/PM1");
Mockito.stub(request.getInputStream()).toReturn(stream);
final StringBuffer sb = new StringBuffer();
ServletOutputStream out = new ServletOutputStream() {
@Override
public void write(int b) throws IOException {
sb.append((char) b);
}
@Override
public boolean isReady() {
return true;
}
@Override
public void setWriteListener(WriteListener writeListener) {
}
};
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
Mockito.stub(response.getOutputStream()).toReturn(out);
try {
TeiidServiceHandler tsh = new TeiidServiceHandler("PM1");
tsh.setPrepared(false);
TeiidServiceHandler.setClient(client);
handler.register(tsh);
handler.process(request, response);
} finally {
TeiidServiceHandler.setClient(null);
}
ArgumentCaptor<Integer> statusCapture = ArgumentCaptor.forClass(Integer.class);
Mockito.verify(response).setStatus(statusCapture.capture());
state.client = client;
state.response = sb.toString();
state.status = statusCapture.getValue();
return state;
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestOptimizer method testUnnamedAggInView.
@Test
public void testUnnamedAggInView() throws Exception {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema bqt1 = RealMetadataFactory.createPhysicalModel("BQT1", metadataStore);
// $NON-NLS-1$
Schema vqt = RealMetadataFactory.createVirtualModel("VQT", metadataStore);
// $NON-NLS-1$
Table bqt1SmallA = RealMetadataFactory.createPhysicalGroup("SmallA", bqt1);
RealMetadataFactory.createElement("col", bqt1SmallA, DataTypeManager.DefaultDataTypes.STRING);
Table agg3 = RealMetadataFactory.createVirtualGroup("Agg3", vqt, new QueryNode("select count(*) from smalla"));
RealMetadataFactory.createElement("count", agg3, DataTypeManager.DefaultDataTypes.INTEGER);
TransformationMetadata metadata = RealMetadataFactory.createTransformationMetadata(metadataStore, "x");
BasicSourceCapabilities bac = getTypicalCapabilities();
bac.setCapabilitySupport(Capability.QUERY_FROM_INLINE_VIEWS, true);
bac.setCapabilitySupport(Capability.QUERY_AGGREGATES_COUNT_STAR, true);
bac.setCapabilitySupport(Capability.QUERY_GROUP_BY, true);
helpPlan("select count(*) from agg3", metadata, new String[] {}, new DefaultCapabilitiesFinder(bac), ComparisonMode.EXACT_COMMAND_STRING);
}
Aggregations