use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestCompositeGlobalTableStore method testCompositeGlobalTableStore.
@Test
public void testCompositeGlobalTableStore() throws VirtualDatabaseException {
CompositeVDB vdb = TestCompositeVDB.createCompositeVDB(new MetadataStore(), "foo");
GlobalTableStore gts = CompositeGlobalTableStore.createInstance(vdb, BufferManagerFactory.getStandaloneBufferManager(), null);
assertTrue(gts instanceof GlobalTableStoreImpl);
vdb.children = new LinkedHashMap<VDBKey, CompositeVDB>();
MetadataStore ms = new MetadataStore();
Schema s = new Schema();
s.setName("x");
ms.addSchema(s);
CompositeVDB imported = TestCompositeVDB.createCompositeVDB(ms, "foo");
GlobalTableStore gts1 = Mockito.mock(GlobalTableStore.class);
imported.getVDB().addAttchment(GlobalTableStore.class, gts1);
vdb.getChildren().put(new VDBKey("foo1", 1), imported);
CompositeGlobalTableStore cgts = (CompositeGlobalTableStore) CompositeGlobalTableStore.createInstance(vdb, BufferManagerFactory.getStandaloneBufferManager(), null);
assertEquals(gts1, cgts.getStoreForTable(RelationalPlanner.MAT_PREFIX + "X.Y"));
assertEquals(cgts.getPrimary(), cgts.getStore("Z"));
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestSqlServerConversionVisitor method testUniqueidentifier.
@Test
public void testUniqueidentifier() throws Exception {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema foo = RealMetadataFactory.createPhysicalModel("foo", metadataStore);
// $NON-NLS-1$
Table table = RealMetadataFactory.createPhysicalGroup("bar", foo);
String[] elemNames = new String[] { // $NON-NLS-1$
"x" };
String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.STRING };
List<Column> cols = RealMetadataFactory.createElements(table, elemNames, elemTypes);
Column obj = cols.get(0);
// $NON-NLS-1$
obj.setNativeType("uniqueidentifier");
CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
QueryMetadataInterface metadata = new TransformationMetadata(null, store, null, RealMetadataFactory.SFM.getSystemFunctions(), null);
TranslationUtility tu = new TranslationUtility(metadata);
// $NON-NLS-1$
Command command = tu.parseCommand("select max(x) from bar");
// $NON-NLS-1$
TranslationHelper.helpTestVisitor("SELECT MAX(bar.x) FROM bar", trans, command);
// $NON-NLS-1$
command = tu.parseCommand("select * from (select max(x) as max from bar) x");
// $NON-NLS-1$
TranslationHelper.helpTestVisitor("SELECT x.max FROM (SELECT MAX(bar.x) AS max FROM bar) x", trans, command);
// $NON-NLS-1$
command = tu.parseCommand("insert into bar (x) values ('a')");
// $NON-NLS-1$
TranslationHelper.helpTestVisitor("INSERT INTO bar (x) VALUES ('a')", trans, command);
trans = new SQLServerExecutionFactory();
trans.setDatabaseVersion(SQLServerExecutionFactory.V_2000);
trans.start();
// $NON-NLS-1$
command = tu.parseCommand("select max(x) from bar");
// $NON-NLS-1$
TranslationHelper.helpTestVisitor("SELECT MAX(cast(bar.x as char(36))) FROM bar", trans, command);
// $NON-NLS-1$
command = tu.parseCommand("select * from (select max(x) as max from bar) x");
// $NON-NLS-1$
TranslationHelper.helpTestVisitor("SELECT x.max FROM (SELECT MAX(cast(bar.x as char(36))) AS max FROM bar) x", trans, command);
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestOracleTranslator method getOracleSpecificMetadata.
/**
* create fake BQT metadata to test this case, name in source is important
*/
private QueryMetadataInterface getOracleSpecificMetadata() {
MetadataStore metadataStore = new MetadataStore();
// $NON-NLS-1$
Schema foo = RealMetadataFactory.createPhysicalModel("BQT1", metadataStore);
// $NON-NLS-1$
Table table = RealMetadataFactory.createPhysicalGroup("SmallA", foo);
// $NON-NLS-1$
Table x = RealMetadataFactory.createPhysicalGroup("x", foo);
x.setProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, "select c from d");
// $NON-NLS-1$
Table dual = RealMetadataFactory.createPhysicalGroup("DUAL", foo);
// $NON-NLS-1$
table.setNameInSource("SmallishA");
String[] elemNames = new String[] { // $NON-NLS-1$
"DoubleNum", // $NON-NLS-1$
"ID", // $NON-NLS-1$
"timestampvalue", "description", "ndescription" };
String[] elemTypes = new String[] { DataTypeManager.DefaultDataTypes.DOUBLE, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.TIMESTAMP, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING };
RealMetadataFactory.createElements(x, elemNames, elemTypes);
List<Column> cols = RealMetadataFactory.createElements(table, elemNames, elemTypes);
cols.get(1).setAutoIncremented(true);
// $NON-NLS-1$
cols.get(1).setNameInSource("ID:SEQUENCE=MYSEQUENCE.nextVal");
// $NON-NLS-1$
cols.get(2).setNativeType("date");
cols.get(3).setNativeType("CHAR");
cols.get(4).setNativeType("NCHAR");
// $NON-NLS-1$
List<Column> dualCols = RealMetadataFactory.createElements(dual, new String[] { "something" }, new String[] { DataTypeManager.DefaultDataTypes.STRING });
dualCols.get(0).setNameInSource("seq.nextval");
// $NON-NLS-1$
ProcedureParameter in1 = RealMetadataFactory.createParameter("in1", SPParameter.IN, DataTypeManager.DefaultDataTypes.INTEGER);
// $NON-NLS-1$ //$NON-NLS-2$
ColumnSet<Procedure> rs3 = RealMetadataFactory.createResultSet("proc.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER });
Procedure p = RealMetadataFactory.createStoredProcedure("proc", foo, Arrays.asList(in1));
p.setResultSet(rs3);
p.setProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, "select x from y where z = $1");
p = RealMetadataFactory.createStoredProcedure("proc1", foo, Arrays.asList(RealMetadataFactory.createParameter("in1", SPParameter.IN, DataTypeManager.DefaultDataTypes.STRING)));
// $NON-NLS-1$ //$NON-NLS-2$
p.setResultSet(RealMetadataFactory.createResultSet("proc.rs1", new String[] { "e1" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER }));
p.setProperty(SQLConversionVisitor.TEIID_NATIVE_QUERY, "select $1 from y");
p.setProperty(SQLConversionVisitor.TEIID_NON_PREPARED, "true");
CompositeMetadataStore store = new CompositeMetadataStore(metadataStore);
return new TransformationMetadata(null, store, null, RealMetadataFactory.SFM.getSystemFunctions(), null);
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class TestModeShapeSqlTranslator method getMetadata.
public static TransformationMetadata getMetadata() {
MetadataStore store = new MetadataStore();
Schema modeshape = RealMetadataFactory.createPhysicalModel("modeshape", store);
Table nt_base = RealMetadataFactory.createPhysicalGroup("nt_base", modeshape);
nt_base.setNameInSource("\"nt:base\"");
List<Column> cols = RealMetadataFactory.createElements(nt_base, new String[] { "jcr_path", "mode_properties", "jcr_primaryType", "prop" }, new String[] { TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING });
cols.get(0).setNameInSource("\"jcr:path\"");
cols.get(1).setNameInSource("\"mode:properties\"");
cols.get(2).setNameInSource("\"jcr:primaryType\"");
Table nt_version = RealMetadataFactory.createPhysicalGroup("nt_version", modeshape);
nt_version.setNameInSource("\"nt:version\"");
List<Column> cols2 = RealMetadataFactory.createElements(nt_version, new String[] { "jcr_path", "mode_properties", "jcr_primaryType", "prop" }, new String[] { TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING, TypeFacility.RUNTIME_NAMES.STRING });
cols2.get(0).setNameInSource("\"jcr:path\"");
cols2.get(1).setNameInSource("\"mode:properties\"");
cols2.get(2).setNameInSource("\"jcr:primaryType\"");
return RealMetadataFactory.createTransformationMetadata(store, "modeshape");
}
use of org.teiid.metadata.Schema in project teiid by teiid.
the class ODataUpdateExecution method execute.
@Override
public void execute() throws TranslatorException {
if (this.visitor.getMethod().equals("DELETE")) {
// $NON-NLS-1$
// DELETE
BinaryWSProcedureExecution execution = executeDirect(this.visitor.getMethod(), this.visitor.buildURL(), null, getDefaultHeaders());
if (execution.getResponseCode() != Status.OK.getStatusCode() && (execution.getResponseCode() != Status.NO_CONTENT.getStatusCode())) {
throw buildError(execution);
}
} else if (this.visitor.getMethod().equals("PUT")) {
// $NON-NLS-1$
// UPDATE
Schema schema = visitor.getTable().getParent();
EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
// $NON-NLS-1$
BinaryWSProcedureExecution execution = executeDirect("GET", this.visitor.buildURL(), null, getDefaultHeaders());
if (execution.getResponseCode() == Status.OK.getStatusCode()) {
// $NON-NLS-1$
String etag = getHeader(execution, "ETag");
String payload = buildPayload(this.visitor.getTable().getName(), this.visitor.getPayload(), edm);
this.response = executeWithReturnEntity(this.visitor.getMethod(), this.visitor.buildURL(), payload, this.visitor.getTable().getName(), edm, etag, Status.OK, Status.NO_CONTENT);
if (this.response != null) {
if (this.response.hasError()) {
throw this.response.getError();
}
}
}
} else if (this.visitor.getMethod().equals("POST")) {
// $NON-NLS-1$
// INSERT
Schema schema = visitor.getTable().getParent();
EdmDataServices edm = new TeiidEdmMetadata(schema.getName(), ODataEntitySchemaBuilder.buildMetadata(schema));
String payload = buildPayload(this.visitor.getTable().getName(), this.visitor.getPayload(), edm);
this.response = executeWithReturnEntity(this.visitor.getMethod(), this.visitor.buildURL(), payload, this.visitor.getTable().getName(), edm, null, Status.CREATED);
if (this.response != null) {
if (this.response.hasError()) {
throw this.response.getError();
}
}
}
}
Aggregations