Search in sources :

Example 6 with Database

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

the class DeploymentBasedDatabaseStore method getVDBMetadata.

public VDBMetaData getVDBMetadata(String contents) {
    StringReader reader = new StringReader(contents);
    try {
        startEditing(false);
        this.setMode(Mode.DATABASE_STRUCTURE);
        QueryParser.getQueryParser().parseDDL(this, new BufferedReader(reader));
    } finally {
        reader.close();
        stopEditing();
    }
    Database database = getDatabases().get(0);
    VDBMetaData vdb = DatabaseUtil.convert(database);
    for (ModelMetaData model : vdb.getModelMetaDatas().values()) {
        // $NON-NLS-1$
        model.addSourceMetadata("DDL", null);
    }
    for (VDBImportMetadata vid : this.importedVDBs) {
        vdb.getVDBImports().add(vid);
    }
    vdb.addProperty(VDBMetaData.TEIID_DDL, contents);
    return vdb;
}
Also used : VDBImportMetadata(org.teiid.adminapi.impl.VDBImportMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) StringReader(java.io.StringReader) BufferedReader(java.io.BufferedReader) Database(org.teiid.metadata.Database) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData)

Example 7 with Database

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

the class TestDDLStringVisitor method testDatabase.

@Test
public void testDatabase() throws Exception {
    Database db = new Database("foo", "2");
    String metadataDDL = DDLStringVisitor.getDDLString(db);
    String expected = "\n" + "/*\n" + "###########################################\n" + "# START DATABASE foo\n" + "###########################################\n" + "*/\n" + "CREATE DATABASE foo VERSION '2';\n" + "USE DATABASE foo VERSION '2';\n" + "\n" + "/*\n" + "###########################################\n" + "# END DATABASE foo\n" + "###########################################\n" + "*/\n" + "\n";
    assertEquals(expected, metadataDDL);
}
Also used : Database(org.teiid.metadata.Database) Test(org.junit.Test)

Example 8 with Database

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

the class AbstractVDBDeployer method processVDBDDL.

private void processVDBDDL(final VDBMetaData vdb, final MetadataStore vdbMetadataStore, final ConnectorManagerRepository cmr, final VDBResources vdbResources) {
    if (vdb.getStatus() == Status.FAILED) {
        return;
    }
    String ddl = vdb.getPropertyValue(VDBMetaData.TEIID_DDL);
    if (ddl != null) {
        final Database database = DatabaseUtil.convert(vdb, vdbMetadataStore);
        CompositeMetadataStore compositeStore = new CompositeMetadataStore(vdbMetadataStore);
        final TransformationMetadata metadata = new TransformationMetadata(vdb, compositeStore, null, getVDBRepository().getSystemFunctionManager().getSystemFunctions(), null);
        DeploymentBasedDatabaseStore deploymentStore = new DeploymentBasedDatabaseStore(getVDBRepository()) {

            @Override
            protected TransformationMetadata getTransformationMetadata() {
                return metadata;
            }

            @Override
            public void importSchema(String schemaName, String serverType, String serverName, String foreignSchemaName, List<String> includeTables, List<String> excludeTables, Map<String, String> properties) {
                ModelMetaData model = vdb.getModel(schemaName);
                MetadataFactory factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
                factory.getModelProperties().putAll(model.getPropertiesMap());
                factory.getModelProperties().putAll(properties);
                if (!includeTables.isEmpty()) {
                    // $NON-NLS-1$
                    factory.getModelProperties().put("importer.includeTables", StringUtil.join(includeTables, ","));
                }
                if (!excludeTables.isEmpty()) {
                    // $NON-NLS-1$
                    factory.getModelProperties().put("importer.excludeTables", StringUtil.join(excludeTables, ","));
                }
                factory.setParser(new QueryParser());
                if (vdbResources != null) {
                    factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
                }
                MetadataRepository baseRepo = model.getAttachment(MetadataRepository.class);
                MetadataRepository metadataRepository;
                try {
                    metadataRepository = getMetadataRepository(serverType);
                    if (metadataRepository == null) {
                        throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40094, model.getName(), vdb.getName(), vdb.getVersion(), serverType));
                    }
                } catch (VirtualDatabaseException e1) {
                    throw new MetadataException(e1);
                }
                metadataRepository = new ChainingMetadataRepository(Arrays.asList(new MetadataRepositoryWrapper(metadataRepository, null), baseRepo));
                ExecutionFactory ef = null;
                Object cf = null;
                Exception te = null;
                for (ConnectorManager cm : getConnectorManagers(model, cmr)) {
                    if (te != null) {
                        // $NON-NLS-1$
                        LogManager.logDetail(LogConstants.CTX_RUNTIME, te, "Failed to get metadata, trying next source.");
                        te = null;
                    }
                    try {
                        if (cm != null) {
                            ef = cm.getExecutionFactory();
                            cf = cm.getConnectionFactory();
                        }
                    } catch (TranslatorException e) {
                        // $NON-NLS-1$
                        LogManager.logDetail(LogConstants.CTX_RUNTIME, e, "Failed to get a connection factory for metadata load.");
                    }
                    if (LogManager.isMessageToBeRecorded(LogConstants.CTX_RUNTIME, MessageLevel.TRACE)) {
                        // $NON-NLS-1$ //$NON-NLS-2$
                        LogManager.logTrace(LogConstants.CTX_RUNTIME, "CREATE SCHEMA", factory.getSchema().getName(), ";\n", DDLStringVisitor.getDDLString(factory.getSchema(), null, null));
                    }
                    try {
                        metadataRepository.loadMetadata(factory, ef, cf);
                        break;
                    } catch (Exception e) {
                        te = e;
                        factory = DatabaseStore.createMF(this, getSchema(schemaName), true);
                        factory.getModelProperties().putAll(model.getPropertiesMap());
                        factory.getModelProperties().putAll(properties);
                        factory.setParser(new QueryParser());
                        if (vdbResources != null) {
                            factory.setVdbResources(vdbResources.getEntriesPlusVisibilities());
                        }
                    }
                }
                if (te != null) {
                    if (te instanceof RuntimeException) {
                        throw (RuntimeException) te;
                    }
                    throw new MetadataException(te);
                }
            }
        };
        deploymentStore.startEditing(false);
        deploymentStore.databaseCreated(database);
        deploymentStore.databaseSwitched(database.getName(), database.getVersion());
        deploymentStore.setMode(Mode.SCHEMA);
        try {
            QueryParser.getQueryParser().parseDDL(deploymentStore, new StringReader(ddl));
        } finally {
            deploymentStore.stopEditing();
        }
        DatabaseUtil.copyDatabaseGrantsAndRoles(database, vdb);
    }
}
Also used : ExecutionFactory(org.teiid.translator.ExecutionFactory) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) DeploymentBasedDatabaseStore(org.teiid.metadatastore.DeploymentBasedDatabaseStore) MetadataException(org.teiid.metadata.MetadataException) MetadataException(org.teiid.metadata.MetadataException) TranslatorException(org.teiid.translator.TranslatorException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) MetadataRepository(org.teiid.metadata.MetadataRepository) QueryParser(org.teiid.query.parser.QueryParser) MetadataFactory(org.teiid.metadata.MetadataFactory) Database(org.teiid.metadata.Database) StringReader(java.io.StringReader) ArrayList(java.util.ArrayList) List(java.util.List) TranslatorException(org.teiid.translator.TranslatorException) VirtualDatabaseException(org.teiid.deployers.VirtualDatabaseException) Map(java.util.Map) ConcurrentSkipListMap(java.util.concurrent.ConcurrentSkipListMap)

Example 9 with Database

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

the class EmbeddedAdminImpl method getSchema.

@Override
public String getSchema(String vdbName, String vdbVersion, String modelName, EnumSet<SchemaObjectType> allowedTypes, String typeNamePattern) throws AdminException {
    if (vdbVersion == null) {
        vdbVersion = "1";
    }
    VDBMetaData vdb = checkVDB(vdbName, vdbVersion);
    MetadataStore metadataStore = vdb.getAttachment(TransformationMetadata.class).getMetadataStore();
    if (modelName != null) {
        Schema schema = metadataStore.getSchema(modelName);
        return DDLStringVisitor.getDDLString(schema, allowedTypes, typeNamePattern);
    } else {
        Database db = DatabaseUtil.convert(vdb, metadataStore);
        return DDLStringVisitor.getDDLString(db);
    }
}
Also used : MetadataStore(org.teiid.metadata.MetadataStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) Schema(org.teiid.metadata.Schema) Database(org.teiid.metadata.Database)

Aggregations

Database (org.teiid.metadata.Database)9 Test (org.junit.Test)4 StringReader (java.io.StringReader)3 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)3 VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)2 DataWrapper (org.teiid.metadata.DataWrapper)2 MetadataRepository (org.teiid.metadata.MetadataRepository)2 Schema (org.teiid.metadata.Schema)2 Server (org.teiid.metadata.Server)2 DeploymentBasedDatabaseStore (org.teiid.metadatastore.DeploymentBasedDatabaseStore)2 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)2 BufferedReader (java.io.BufferedReader)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 Map (java.util.Map)1 ConcurrentSkipListMap (java.util.concurrent.ConcurrentSkipListMap)1 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)1 VDBImportMetadata (org.teiid.adminapi.impl.VDBImportMetadata)1 VirtualDatabaseException (org.teiid.deployers.VirtualDatabaseException)1 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)1