Search in sources :

Example 86 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class CompositeGlobalTableStore method createInstance.

public static GlobalTableStore createInstance(CompositeVDB vdb, BufferManager bufferManager, ObjectReplicator replicator) {
    VDBMetaData vdbMetadata = vdb.getVDB();
    QueryMetadataInterface metadata = vdbMetadata.getAttachment(TransformationMetadata.class);
    GlobalTableStore gts = new GlobalTableStoreImpl(bufferManager, vdbMetadata, metadata);
    if (replicator != null) {
        try {
            gts = replicator.replicate(vdbMetadata.getFullName(), GlobalTableStore.class, gts, 300000);
        } catch (Exception e) {
            LogManager.logError(LogConstants.CTX_RUNTIME, e, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40088, gts));
        }
    }
    if (vdb.getChildren() == null) {
        return gts;
    }
    TreeMap<String, GlobalTableStore> stores = new TreeMap<String, GlobalTableStore>(String.CASE_INSENSITIVE_ORDER);
    buildStoreMap(vdb, stores);
    return new CompositeGlobalTableStore(stores, gts, metadata);
}
Also used : GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) QueryMetadataInterface(org.teiid.query.metadata.QueryMetadataInterface) GlobalTableStoreImpl(org.teiid.query.tempdata.GlobalTableStoreImpl) TreeMap(java.util.TreeMap) TeiidComponentException(org.teiid.core.TeiidComponentException) QueryMetadataException(org.teiid.api.exception.query.QueryMetadataException) TeiidProcessingException(org.teiid.core.TeiidProcessingException)

Example 87 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class CompositeGlobalTableStore method buildStoreMap.

static void buildStoreMap(CompositeVDB vdb, TreeMap<String, GlobalTableStore> stores) {
    for (CompositeVDB cvdb : vdb.getChildren().values()) {
        VDBMetaData child = cvdb.getVDB();
        GlobalTableStore childGts = child.getAttachment(GlobalTableStore.class);
        if (cvdb.getChildren() != null) {
            buildStoreMap(cvdb, stores);
        }
        for (String name : child.getModelMetaDatas().keySet()) {
            if (cvdb.getChildren() == null || !child.getImportedModels().contains(name)) {
                stores.put(name, childGts);
            }
        }
    }
}
Also used : GlobalTableStore(org.teiid.query.tempdata.GlobalTableStore) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData)

Example 88 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class CompositeVDB method buildCompositeState.

private void buildCompositeState(VDBRepository vdbRepository) throws VirtualDatabaseException {
    if (vdb.getVDBImports().isEmpty()) {
        this.vdb.addAttchment(ConnectorManagerRepository.class, this.cmr);
        return;
    }
    VDBMetaData newMergedVDB = this.vdb.clone();
    ConnectorManagerRepository mergedRepo = this.cmr;
    if (!this.cmr.isShared()) {
        mergedRepo = new ConnectorManagerRepository();
        mergedRepo.getConnectorManagers().putAll(this.cmr.getConnectorManagers());
    }
    newMergedVDB.addAttchment(ConnectorManagerRepository.class, mergedRepo);
    ClassLoader[] toSearch = new ClassLoader[vdb.getVDBImports().size() + 1];
    toSearch[0] = this.vdb.getAttachment(ClassLoader.class);
    this.children = new LinkedHashMap<VDBKey, CompositeVDB>();
    newMergedVDB.setImportedModels(new TreeSet<String>(String.CASE_INSENSITIVE_ORDER));
    int i = 1;
    for (VDBImport vdbImport : vdb.getVDBImports()) {
        VDBKey key = new VDBKey(vdbImport.getName(), vdbImport.getVersion());
        if (key.isAtMost()) {
            // TODO: could allow partial versions
            throw new VirtualDatabaseException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40144, vdbKey, key));
        }
        CompositeVDB importedVDB = vdbRepository.getCompositeVDB(key);
        if (importedVDB == null) {
            throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40083, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40083, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion()));
        }
        VDBMetaData childVDB = importedVDB.getVDB();
        newMergedVDB.getVisibilityOverrides().putAll(childVDB.getVisibilityOverrides());
        toSearch[i++] = childVDB.getAttachment(ClassLoader.class);
        this.children.put(importedVDB.getVDBKey(), importedVDB);
        if (vdbImport.isImportDataPolicies()) {
            for (DataPolicy dp : importedVDB.getVDB().getDataPolicies()) {
                DataPolicyMetadata role = (DataPolicyMetadata) dp;
                if (newMergedVDB.addDataPolicy(role) != null) {
                    throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40084, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40084, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), role.getName()));
                }
                if (role.isGrantAll()) {
                    role.setSchemas(childVDB.getModelMetaDatas().keySet());
                }
            }
        }
        // add models
        for (ModelMetaData m : childVDB.getModelMetaDatas().values()) {
            if (newMergedVDB.addModel(m) != null) {
                throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40085, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40085, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), m.getName()));
            }
            newMergedVDB.getImportedModels().add(m.getName());
            // $NON-NLS-1$
            String visibilityOverride = newMergedVDB.getPropertyValue(m.getName() + ".visible");
            if (visibilityOverride != null) {
                boolean visible = Boolean.valueOf(visibilityOverride);
                newMergedVDB.setVisibilityOverride(m.getName(), visible);
            }
        }
        ConnectorManagerRepository childCmr = childVDB.getAttachment(ConnectorManagerRepository.class);
        if (childCmr == null) {
            // $NON-NLS-1$
            throw new AssertionError("childVdb does not have a connector manager repository");
        }
        if (!this.cmr.isShared()) {
            for (Map.Entry<String, ConnectorManager> entry : childCmr.getConnectorManagers().entrySet()) {
                if (mergedRepo.getConnectorManagers().put(entry.getKey(), entry.getValue()) != null) {
                    throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40086, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40086, vdb.getName(), vdb.getVersion(), vdbImport.getName(), vdbImport.getVersion(), entry.getKey()));
                }
            }
        }
    }
    if (toSearch[0] != null) {
        CombinedClassLoader ccl = new CombinedClassLoader(toSearch[0].getParent(), toSearch);
        this.mergedVDB.addAttchment(ClassLoader.class, ccl);
    }
    this.mergedVDB = newMergedVDB;
}
Also used : ConnectorManagerRepository(org.teiid.dqp.internal.datamgr.ConnectorManagerRepository) ConnectorManager(org.teiid.dqp.internal.datamgr.ConnectorManager) ModelMetaData(org.teiid.adminapi.impl.ModelMetaData) VDBKey(org.teiid.vdb.runtime.VDBKey) DataPolicyMetadata(org.teiid.adminapi.impl.DataPolicyMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) VDBImport(org.teiid.adminapi.VDBImport) DataPolicy(org.teiid.adminapi.DataPolicy) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 89 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class EventDistributorImpl method getSchema.

private Schema getSchema(String vdbName, String vdbVersion, String schemaName) {
    VDBMetaData vdb = getVdbRepository().getLiveVDB(vdbName, vdbVersion);
    if (vdb == null) {
        return null;
    }
    TransformationMetadata tm = vdb.getAttachment(TransformationMetadata.class);
    if (tm == null) {
        return null;
    }
    return tm.getMetadataStore().getSchemas().get(schemaName);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData)

Example 90 with VDBMetaData

use of org.teiid.adminapi.impl.VDBMetaData in project teiid by teiid.

the class EventDistributorImpl method dataModification.

@Override
public ResultsFuture<?> dataModification(String vdbName, String vdbVersion, String schema, String tableName, Object[] oldValues, Object[] newValues, String[] columnNames) {
    VDBMetaData vdb = getVdbRepository().getLiveVDB(vdbName, vdbVersion);
    if (vdb == null) {
        return null;
    }
    TransformationMetadata tm = vdb.getAttachment(TransformationMetadata.class);
    if (tm == null) {
        return null;
    }
    // lookup, call triggers
    Table t = getTable(vdbName, vdbVersion, schema, tableName);
    if (t == null) {
        return null;
    }
    // notify of just the table modification
    dataModification(vdbName, vdbVersion, schema, tableName);
    if (oldValues == null && newValues == null) {
        return null;
    }
    if (!t.getTriggers().isEmpty()) {
        if (columnNames != null) {
            if ((oldValues != null && oldValues.length != columnNames.length) || (newValues != null && newValues.length != columnNames.length)) {
                throw new IllegalArgumentException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40162));
            }
        } else {
            if ((oldValues != null && oldValues.length != t.getColumns().size()) || (newValues != null && newValues.length != t.getColumns().size())) {
                throw new IllegalArgumentException(RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40163));
            }
        }
        // create command
        SourceEventCommand sec = new SourceEventCommand(t, oldValues, newValues, columnNames);
        try {
            return DQPCore.executeQuery(sec, vdb, "admin", "event-distributor", -1, getDQPCore(), new // $NON-NLS-1$ //$NON-NLS-2$
            DQPCore.ResultsListener() {

                @Override
                public void onResults(List<String> columns, List<? extends List<?>> results) throws Exception {
                // no result
                }
            });
        } catch (Throwable throwable) {
            throw new TeiidRuntimeException(throwable);
        }
    }
    return null;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) DQPCore(org.teiid.dqp.internal.process.DQPCore) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) TeiidComponentException(org.teiid.core.TeiidComponentException) TeiidRuntimeException(org.teiid.core.TeiidRuntimeException) SourceEventCommand(org.teiid.query.optimizer.SourceTriggerActionPlanner.SourceEventCommand) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData)

Aggregations

VDBMetaData (org.teiid.adminapi.impl.VDBMetaData)121 Test (org.junit.Test)48 ModelMetaData (org.teiid.adminapi.impl.ModelMetaData)36 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)16 MetadataStore (org.teiid.metadata.MetadataStore)15 ConnectorManagerRepository (org.teiid.dqp.internal.datamgr.ConnectorManagerRepository)14 VDBRepository (org.teiid.deployers.VDBRepository)12 ArrayList (java.util.ArrayList)10 IOException (java.io.IOException)9 ConnectorManager (org.teiid.dqp.internal.datamgr.ConnectorManager)9 Properties (java.util.Properties)8 XMLStreamException (javax.xml.stream.XMLStreamException)8 VDBImportMetadata (org.teiid.adminapi.impl.VDBImportMetadata)8 DataPolicyMetadata (org.teiid.adminapi.impl.DataPolicyMetadata)7 TeiidComponentException (org.teiid.core.TeiidComponentException)7 VDBKey (org.teiid.vdb.runtime.VDBKey)7 ByteArrayInputStream (java.io.ByteArrayInputStream)6 VDBTranslatorMetaData (org.teiid.adminapi.impl.VDBTranslatorMetaData)6 Schema (org.teiid.metadata.Schema)6 SessionMetadata (org.teiid.adminapi.impl.SessionMetadata)5