Search in sources :

Example 6 with MetadataStore

use of org.teiid.metadata.MetadataStore in project teiid by teiid.

the class TestUpdateValidator method example1.

public static TransformationMetadata example1(boolean allUpdatable) {
    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$
    Table pm1g2 = RealMetadataFactory.createPhysicalGroup("g2", pm1);
    // $NON-NLS-1$
    Table pm1g3 = RealMetadataFactory.createPhysicalGroup("g3", pm1);
    // Create physical elements
    List<Column> pm1g1e = RealMetadataFactory.createElements(pm1g1, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    if (!allUpdatable) {
        pm1g1e.get(0).setUpdatable(false);
    }
    KeyRecord pk = RealMetadataFactory.createKey(Type.Primary, "pk", pm1g1, pm1g1e.subList(0, 1));
    List<Column> pm1g2e = RealMetadataFactory.createElements(pm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    RealMetadataFactory.createKey(Type.Primary, "pk", pm1g2, pm1g1e.subList(1, 2));
    RealMetadataFactory.createForeignKey("fk", pm1g2, pm1g2e.subList(0, 1), pk);
    List<Column> pm1g3e = RealMetadataFactory.createElements(pm1g3, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    pm1g3e.get(0).setNullType(NullType.No_Nulls);
    pm1g3e.get(0).setDefaultValue(null);
    pm1g3e.get(1).setNullType(NullType.No_Nulls);
    pm1g3e.get(1).setAutoIncremented(true);
    pm1g3e.get(1).setDefaultValue(null);
    pm1g3e.get(2).setNullType(NullType.No_Nulls);
    // $NON-NLS-1$
    pm1g3e.get(2).setDefaultValue("xyz");
    RealMetadataFactory.createKey(Type.Primary, "pk", pm1g3, pm1g3e.subList(0, 1));
    // Create virtual groups
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g1n1 = new QueryNode("SELECT e1 as a, e2 FROM pm1.g1 WHERE e3 > 5");
    // $NON-NLS-1$
    Table vm1g1 = RealMetadataFactory.createUpdatableVirtualGroup("g1", vm1, vm1g1n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g2n1 = new QueryNode("SELECT e1, e2, e3, e4 FROM pm1.g2 WHERE e3 > 5");
    // $NON-NLS-1$
    Table vm1g2 = RealMetadataFactory.createUpdatableVirtualGroup("g2", vm1, vm1g2n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g3n1 = new QueryNode("SELECT e1, e3 FROM pm1.g3");
    // $NON-NLS-1$
    Table vm1g3 = RealMetadataFactory.createUpdatableVirtualGroup("g3", vm1, vm1g3n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g4n1 = new QueryNode("SELECT e1, e2 FROM pm1.g3");
    // $NON-NLS-1$
    Table vm1g4 = RealMetadataFactory.createUpdatableVirtualGroup("g4", vm1, vm1g4n1);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vm1g5n1 = new QueryNode("SELECT e2, e3 FROM pm1.g3");
    // $NON-NLS-1$
    Table vm1g5 = RealMetadataFactory.createVirtualGroup("g5", vm1, vm1g5n1);
    // Create virtual elements
    RealMetadataFactory.createElements(vm1g1, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "a", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    RealMetadataFactory.createElements(vm1g2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e1", "e2", "e3", "e4" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN, DataTypeManager.DefaultDataTypes.DOUBLE });
    RealMetadataFactory.createElements(vm1g3, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    RealMetadataFactory.createElements(vm1g4, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "e1", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.BOOLEAN });
    RealMetadataFactory.createElements(vm1g5, // $NON-NLS-1$ //$NON-NLS-2$
    new String[] { "e2", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.BOOLEAN });
    // Stored queries
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ColumnSet<Procedure> rs1 = RealMetadataFactory.createResultSet("rs1", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode sq1n1 = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN SELECT e1, e2 FROM pm1.g1; END");
    // $NON-NLS-1$
    Procedure sq1 = RealMetadataFactory.createVirtualProcedure("sq1", pm1, Collections.EMPTY_LIST, sq1n1);
    sq1.setResultSet(rs1);
    // Create the facade from the store
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) KeyRecord(org.teiid.metadata.KeyRecord) Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure)

Example 7 with MetadataStore

use of org.teiid.metadata.MetadataStore in project teiid by teiid.

the class TestValidator method exampleMetadata.

public static TransformationMetadata exampleMetadata() {
    MetadataStore metadataStore = new MetadataStore();
    // Create metadata objects
    // $NON-NLS-1$
    Schema modelObj = RealMetadataFactory.createPhysicalModel("test", metadataStore);
    // $NON-NLS-1$
    Schema vModelObj2 = RealMetadataFactory.createVirtualModel("vTest", metadataStore);
    // $NON-NLS-1$
    Table groupObj = RealMetadataFactory.createPhysicalGroup("group", modelObj);
    // $NON-NLS-1$
    Column elemObj0 = RealMetadataFactory.createElement("e0", groupObj, DataTypeManager.DefaultDataTypes.INTEGER);
    elemObj0.setNullType(NullType.No_Nulls);
    // $NON-NLS-1$
    Column elemObj1 = RealMetadataFactory.createElement("e1", groupObj, DataTypeManager.DefaultDataTypes.STRING);
    elemObj1.setSelectable(false);
    // $NON-NLS-1$
    Column elemObj2 = RealMetadataFactory.createElement("e2", groupObj, DataTypeManager.DefaultDataTypes.STRING);
    elemObj2.setSearchType(SearchType.Like_Only);
    // $NON-NLS-1$
    Column elemObj3 = RealMetadataFactory.createElement("e3", groupObj, DataTypeManager.DefaultDataTypes.STRING);
    elemObj3.setSearchType(SearchType.All_Except_Like);
    // $NON-NLS-1$
    Table group2Obj = RealMetadataFactory.createPhysicalGroup("group2", modelObj);
    // $NON-NLS-1$
    Column elemObj2_0 = RealMetadataFactory.createElement("e0", group2Obj, DataTypeManager.DefaultDataTypes.INTEGER);
    elemObj2_0.setUpdatable(false);
    // $NON-NLS-1$
    RealMetadataFactory.createElement("e1", group2Obj, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$
    Column elemObj2_2 = RealMetadataFactory.createElement("e2", group2Obj, DataTypeManager.DefaultDataTypes.STRING);
    elemObj2_2.setUpdatable(false);
    // $NON-NLS-1$
    Table group3Obj = RealMetadataFactory.createPhysicalGroup("group3", modelObj);
    group3Obj.setSupportsUpdate(false);
    // $NON-NLS-1$
    RealMetadataFactory.createElement("e0", group3Obj, DataTypeManager.DefaultDataTypes.INTEGER);
    // $NON-NLS-1$
    RealMetadataFactory.createElement("e1", group3Obj, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$
    RealMetadataFactory.createElement("e2", group3Obj, DataTypeManager.DefaultDataTypes.STRING);
    // Create virtual group & elements.
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vNode = new QueryNode("SELECT * FROM test.group WHERE e2 = 'x'");
    // $NON-NLS-1$
    Table vGroup = RealMetadataFactory.createVirtualGroup("vGroup", vModelObj2, vNode);
    RealMetadataFactory.createElements(vGroup, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e0", "e1", "e2", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode vNode2 = new QueryNode("SELECT * FROM test.group");
    // $NON-NLS-1$
    Table vGroup2 = RealMetadataFactory.createVirtualGroup("vMap", vModelObj2, vNode2);
    List<Column> vGroupE2 = RealMetadataFactory.createElements(vGroup2, // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
    new String[] { "e0", "e1", "e2", "e3" }, new String[] { DataTypeManager.DefaultDataTypes.INTEGER, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.STRING });
    vGroupE2.get(0).setNullType(NullType.No_Nulls);
    vGroupE2.get(1).setSelectable(false);
    vGroupE2.get(2).setSearchType(SearchType.Like_Only);
    vGroupE2.get(3).setSearchType(SearchType.All_Except_Like);
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "example");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) Column(org.teiid.metadata.Column) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema)

Example 8 with MetadataStore

use of org.teiid.metadata.MetadataStore in project teiid by teiid.

the class TestValidator method helpCreateCase4237VirtualProcedureMetadata.

/**
 * Create fake metadata for this case.  Need a physical stored procedure and
 * a virtual stored procedure which calls the physical one.
 * @return
 */
private TransformationMetadata helpCreateCase4237VirtualProcedureMetadata() {
    MetadataStore metadataStore = new MetadataStore();
    // $NON-NLS-1$
    Schema physicalModel = RealMetadataFactory.createPhysicalModel("pm1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ColumnSet<Procedure> resultSet = RealMetadataFactory.createResultSet("pm1.rs", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    ProcedureParameter inParam = RealMetadataFactory.createParameter("in", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$ //$NON-NLS-2$
    Procedure storedProcedure = RealMetadataFactory.createStoredProcedure("sp", physicalModel, Arrays.asList(inParam));
    storedProcedure.setResultSet(resultSet);
    // $NON-NLS-1$
    Schema virtualModel = RealMetadataFactory.createVirtualModel("vm1", metadataStore);
    // $NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$
    ColumnSet<Procedure> virtualResultSet = RealMetadataFactory.createResultSet("vm1.rs", new String[] { "e1", "e2" }, new String[] { DataTypeManager.DefaultDataTypes.STRING, DataTypeManager.DefaultDataTypes.INTEGER });
    // $NON-NLS-1$
    ProcedureParameter virtualInParam = RealMetadataFactory.createParameter("in1", ParameterInfo.IN, DataTypeManager.DefaultDataTypes.STRING);
    // $NON-NLS-1$ //$NON-NLS-2$
    QueryNode queryNode = new QueryNode("CREATE VIRTUAL PROCEDURE BEGIN EXEC pm1.sp(vm1.sp.in1); END");
    // $NON-NLS-1$
    Procedure virtualStoredProcedure = RealMetadataFactory.createVirtualProcedure("sp", virtualModel, Arrays.asList(virtualInParam), queryNode);
    virtualStoredProcedure.setResultSet(virtualResultSet);
    return RealMetadataFactory.createTransformationMetadata(metadataStore, "case4237");
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) ProcedureParameter(org.teiid.metadata.ProcedureParameter) QueryNode(org.teiid.query.mapping.relational.QueryNode) Schema(org.teiid.metadata.Schema) Procedure(org.teiid.metadata.Procedure)

Example 9 with MetadataStore

use of org.teiid.metadata.MetadataStore in project teiid by teiid.

the class TestDynamicImportedMetaData method testUseCatalog.

@Test
public void testUseCatalog() throws Exception {
    MetadataFactory mf = createMetadataFactory("x", new Properties());
    Table dup = mf.addTable("dup");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup);
    MetadataStore ms = mf.asMetadataStore();
    server.deployVDB("test", ms);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:test");
    Properties importProperties = new Properties();
    importProperties.setProperty("importer.useCatalogName", Boolean.FALSE.toString());
    mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("TEST").getTables().get("X.DUP");
    assertEquals("\"x\".\"dup\"", t.getNameInSource());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) Properties(java.util.Properties) Test(org.junit.Test)

Example 10 with MetadataStore

use of org.teiid.metadata.MetadataStore in project teiid by teiid.

the class TestDynamicImportedMetaData method testUseQualified.

@Test
public void testUseQualified() throws Exception {
    MetadataFactory mf = createMetadataFactory("x", new Properties());
    Table dup = mf.addTable("dup");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup);
    MetadataStore ms = mf.asMetadataStore();
    server.deployVDB("test", ms);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:test");
    // neither the name nor name in source should be qualified
    Properties importProperties = new Properties();
    importProperties.setProperty("importer.useQualifiedName", Boolean.FALSE.toString());
    mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("TEST").getTables().get("DUP");
    assertEquals("\"dup\"", t.getNameInSource());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) Properties(java.util.Properties) Test(org.junit.Test)

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