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);
}
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);
}
}
}
}
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;
}
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);
}
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;
}
Aggregations