use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestCompositeVDB method testRoleInherit.
@Test
public void testRoleInherit() throws Exception {
VDBRepository repo = new VDBRepository();
repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
repo.setSystemFunctionManager(RealMetadataFactory.SFM);
MetadataStore metadataStore = new MetadataStore();
RealMetadataFactory.createPhysicalModel("x", metadataStore);
VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
DataPolicyMetadata dpm = new DataPolicyMetadata();
dpm.setName("x");
dpm.setGrantAll(true);
vdb.addDataPolicy(dpm);
ConnectorManagerRepository cmr = new ConnectorManagerRepository();
cmr.addConnectorManager("x", new ConnectorManager("y", "z"));
repo.addVDB(vdb, metadataStore, null, null, cmr);
metadataStore = new MetadataStore();
RealMetadataFactory.createPhysicalModel("y", metadataStore);
vdb = createVDBMetadata(metadataStore, "ex");
VDBImportMetadata vdbImport = new VDBImportMetadata();
vdbImport.setName("bqt");
vdbImport.setVersion("1");
vdbImport.setImportDataPolicies(true);
vdb.getVDBImports().add(vdbImport);
repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
vdb = repo.getLiveVDB("ex");
assertEquals(1, vdb.getDataPolicyMap().get("x").getSchemas().size());
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestCompositeVDB method testDeepNesting.
@Test
public void testDeepNesting() throws Exception {
VDBRepository repo = new VDBRepository();
repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
repo.setSystemFunctionManager(RealMetadataFactory.SFM);
MetadataStore metadataStore = new MetadataStore();
RealMetadataFactory.createPhysicalModel("x", metadataStore);
VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
ConnectorManagerRepository cmr = new ConnectorManagerRepository();
cmr.addConnectorManager("x", new ConnectorManager("y", "z"));
repo.addVDB(vdb, metadataStore, null, null, cmr);
metadataStore = new MetadataStore();
RealMetadataFactory.createPhysicalModel("y", metadataStore);
vdb = createVDBMetadata(metadataStore, "ex");
VDBImportMetadata vdbImport = new VDBImportMetadata();
vdbImport.setName("bqt");
vdbImport.setVersion("1");
vdb.getVDBImports().add(vdbImport);
repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
VDBMetaData vdbInstance = repo.getVDB("ex", "1");
assertTrue(!vdbInstance.getAttachment(ConnectorManagerRepository.class).getConnectorManagers().isEmpty());
metadataStore = new MetadataStore();
RealMetadataFactory.createPhysicalModel("z", metadataStore);
vdb = createVDBMetadata(metadataStore, "ex1");
vdbImport = new VDBImportMetadata();
vdbImport.setName("ex");
vdbImport.setVersion("1");
vdb.getVDBImports().add(vdbImport);
repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
vdbInstance = repo.getVDB("ex1", "1");
assertTrue(!vdbInstance.getAttachment(ConnectorManagerRepository.class).getConnectorManagers().isEmpty());
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestCompositeVDB method testImportErrors.
@Test(expected = VirtualDatabaseException.class)
public void testImportErrors() throws Exception {
VDBRepository repo = new VDBRepository();
repo.setSystemStore(RealMetadataFactory.example1Cached().getMetadataStore());
repo.setSystemFunctionManager(RealMetadataFactory.SFM);
MetadataStore metadataStore = RealMetadataFactory.exampleBQTCached().getMetadataStore();
VDBMetaData vdb = createVDBMetadata(metadataStore, "bqt");
repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
vdb = createVDBMetadata(metadataStore, "bqt1");
VDBImportMetadata vdbImport = new VDBImportMetadata();
vdbImport.setName("foo");
vdb.getVDBImports().add(vdbImport);
try {
// foo does not exist
repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
fail();
} catch (VirtualDatabaseException e) {
}
vdb = createVDBMetadata(metadataStore, "bqt1");
vdbImport.setName("bqt");
vdb.getVDBImports().add(vdbImport);
// model conflict
repo.addVDB(vdb, metadataStore, null, null, new ConnectorManagerRepository());
}
use of org.teiid.metadata.MetadataStore 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.MetadataStore 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);
}
Aggregations