Search in sources :

Example 51 with MetadataFactory

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

the class TestDynamicImportedMetaData method testUseCatalogSeparator.

@Test
public void testUseCatalogSeparator() 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$
    final Connection conn = server.createConnection("jdbc:teiid:test");
    Properties importProperties = new Properties();
    Connection conn1 = (Connection) SimpleMock.createSimpleMock(new Object[] { new ConnectionProxy(conn), conn }, new Class<?>[] { Connection.class });
    mf = getMetadata(importProperties, conn1);
    Table t = mf.asMetadataStore().getSchemas().get("TEST").getTables().get("test:X.DUP");
    assertEquals("\"test\":\"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 52 with MetadataFactory

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

the class TestDynamicImportedMetaData method testExcludes.

@Test
public void testExcludes() throws Exception {
    server.deployVDB("vdb", UnitTestUtil.getTestDataPath() + "/TestCase3473/test.vdb");
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:vdb");
    Properties importProperties = new Properties();
    importProperties.setProperty("importer.importProcedures", Boolean.TRUE.toString());
    importProperties.setProperty("importer.excludeTables", "VDB\\.(SYS|pg_catalog).*");
    importProperties.setProperty("importer.excludeProcedures", "VDB\\..*");
    MetadataFactory mf = getMetadata(importProperties, conn);
    assertEquals(String.valueOf(mf.asMetadataStore().getSchemas().get("TEST").getTables()), 3, mf.asMetadataStore().getSchemas().get("TEST").getTables().size());
    assertEquals(0, mf.asMetadataStore().getSchemas().get("TEST").getProcedures().size());
}
Also used : MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) Properties(java.util.Properties) Test(org.junit.Test)

Example 53 with MetadataFactory

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

the class TestDynamicImportedMetaData method testImportFunction.

@Test
public void testImportFunction() 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(NativeMetadataRepository.IMPORT_PUSHDOWN_FUNCTIONS, Boolean.TRUE.toString());
    mf = createMetadataFactory("test", importProperties);
    NativeMetadataRepository nmr = new NativeMetadataRepository();
    OracleExecutionFactory oef = new OracleExecutionFactory();
    oef.start();
    DataSource ds = Mockito.mock(DataSource.class);
    Mockito.stub(ds.getConnection()).toReturn(conn);
    nmr.loadMetadata(mf, oef, ds);
    Map<String, FunctionMethod> functions = mf.asMetadataStore().getSchemas().get("TEST").getFunctions();
    assertEquals(18, functions.size());
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) OracleExecutionFactory(org.teiid.translator.jdbc.oracle.OracleExecutionFactory) Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) NativeMetadataRepository(org.teiid.query.metadata.NativeMetadataRepository) Connection(java.sql.Connection) FunctionMethod(org.teiid.metadata.FunctionMethod) Properties(java.util.Properties) DataSource(javax.sql.DataSource) Test(org.junit.Test)

Example 54 with MetadataFactory

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

the class TestDynamicImportedMetaData method testMultipleFK.

@Test
public void testMultipleFK() throws Exception {
    ModelMetaData mmd = new ModelMetaData();
    mmd.addSourceMetadata("ddl", "create foreign table x (y integer, z integer, primary key (y, z));" + "create foreign table z (y integer, z integer, y1 integer, z1 integer, foreign key (y, z) references x (y, z), foreign key (y1, z1) references x (y, z))");
    mmd.setName("foo");
    mmd.addSourceMapping("x", "x", "x");
    server.addTranslator("x", new ExecutionFactory());
    server.deployVDB("vdb", mmd);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:vdb");
    Properties importProperties = new Properties();
    importProperties.setProperty("importer.importKeys", "true");
    MetadataFactory mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("test").getTables().get("vdb.foo.z");
    List<ForeignKey> fks = t.getForeignKeys();
    assertEquals(2, fks.size());
}
Also used : Table(org.teiid.metadata.Table) MetadataFactory(org.teiid.metadata.MetadataFactory) Connection(java.sql.Connection) OracleExecutionFactory(org.teiid.translator.jdbc.oracle.OracleExecutionFactory) ExecutionFactory(org.teiid.translator.ExecutionFactory) TeiidExecutionFactory(org.teiid.translator.jdbc.teiid.TeiidExecutionFactory) Properties(java.util.Properties) ForeignKey(org.teiid.metadata.ForeignKey) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) Test(org.junit.Test)

Example 55 with MetadataFactory

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

the class TestDynamicImportedMetaData method testIgnorePkIndex.

@Test
public void testIgnorePkIndex() throws Exception {
    MetadataFactory mf = createMetadataFactory("x", new Properties());
    Table dup = mf.addTable("x");
    mf.addColumn("x", DataTypeManager.DefaultDataTypes.STRING, dup);
    mf.addPrimaryKey("foo", Arrays.asList("x"), dup);
    MetadataStore ms = mf.asMetadataStore();
    server.deployVDB("test", ms);
    // cheat and add the index after deployment
    mf.addIndex("foo", false, Arrays.asList("x"), dup);
    // $NON-NLS-1$
    Connection conn = server.createConnection("jdbc:teiid:test");
    Properties importProperties = new Properties();
    importProperties.setProperty("importer.importKeys", Boolean.TRUE.toString());
    importProperties.setProperty("importer.importIndexes", Boolean.TRUE.toString());
    mf = getMetadata(importProperties, conn);
    Table t = mf.asMetadataStore().getSchemas().get("TEST").getTables().get("test.X.X");
    assertNotNull(t.getPrimaryKey());
    assertEquals(0, t.getUniqueKeys().size());
    assertEquals(0, t.getIndexes().size());
}
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

MetadataFactory (org.teiid.metadata.MetadataFactory)159 Test (org.junit.Test)116 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)91 Properties (java.util.Properties)74 Table (org.teiid.metadata.Table)59 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)35 Procedure (org.teiid.metadata.Procedure)30 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)21 Column (org.teiid.metadata.Column)20 Connection (java.sql.Connection)18 FunctionTree (org.teiid.query.function.FunctionTree)15 UDFSource (org.teiid.query.function.UDFSource)14 CouchbaseMetadataProcessor (org.teiid.translator.couchbase.CouchbaseMetadataProcessor)14 Dimension (org.teiid.translator.couchbase.CouchbaseMetadataProcessor.Dimension)14 CouchbaseProperties (org.teiid.translator.couchbase.CouchbaseProperties)14 TranslationUtility (org.teiid.cdk.api.TranslationUtility)13 ValidatorReport (org.teiid.query.validator.ValidatorReport)13 XMLMetadata (org.apache.olingo.client.api.edm.xml.XMLMetadata)12 ClientCsdlXMLMetadata (org.apache.olingo.client.core.edm.ClientCsdlXMLMetadata)12 ForeignKey (org.teiid.metadata.ForeignKey)12