Search in sources :

Example 31 with MetadataStore

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());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) Test(org.junit.Test)

Example 32 with MetadataStore

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());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) Test(org.junit.Test)

Example 33 with MetadataStore

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());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Test(org.junit.Test)

Example 34 with MetadataStore

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);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) Schema(org.teiid.metadata.Schema) TranslationUtility(org.teiid.cdk.api.TranslationUtility) MetadataStore(org.teiid.metadata.MetadataStore) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) Column(org.teiid.metadata.Column) Command(org.teiid.language.Command) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) Test(org.junit.Test)

Example 35 with MetadataStore

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);
}
Also used : CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) MetadataStore(org.teiid.metadata.MetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) Column(org.teiid.metadata.Column) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure)

Aggregations

MetadataStore (org.teiid.metadata.MetadataStore)73 Schema (org.teiid.metadata.Schema)47 Test (org.junit.Test)38 Table (org.teiid.metadata.Table)37 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)22 QueryNode (org.teiid.query.mapping.relational.QueryNode)19 Column (org.teiid.metadata.Column)17 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)15 Properties (java.util.Properties)12 MetadataFactory (org.teiid.metadata.MetadataFactory)12 QueryMetadataInterface (org.teiid.query.metadata.QueryMetadataInterface)12 Procedure (org.teiid.metadata.Procedure)11 List (java.util.List)9 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)9 Connection (java.sql.Connection)8 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)8 ArrayList (java.util.ArrayList)7 ProcedureParameter (org.teiid.metadata.ProcedureParameter)7 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)7 TempMetadataStore (org.teiid.query.metadata.TempMetadataStore)6