use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestValidator method exampleMetadata3.
public static TransformationMetadata exampleMetadata3() {
MetadataStore metadataStore = new MetadataStore();
// Create metadata objects
// $NON-NLS-1$
Schema modelObj = RealMetadataFactory.createPhysicalModel("test", metadataStore);
// $NON-NLS-1$
Table groupObj = RealMetadataFactory.createPhysicalGroup("group", modelObj);
// $NON-NLS-1$
RealMetadataFactory.createElement("e0", groupObj, DataTypeManager.DefaultDataTypes.INTEGER);
// $NON-NLS-1$
Column elemObj1 = RealMetadataFactory.createElement("e1", groupObj, DataTypeManager.DefaultDataTypes.STRING);
elemObj1.setNullType(NullType.No_Nulls);
elemObj1.setDefaultValue(Boolean.FALSE.toString());
elemObj1.setAutoIncremented(true);
// $NON-NLS-1$
elemObj1.setNameInSource("e1:SEQUENCE=MYSEQUENCE.nextVal");
return RealMetadataFactory.createTransformationMetadata(metadataStore, "example3");
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class VDBService method start.
@Override
public void start(final StartContext context) throws StartException {
ConnectorManagerRepository cmr = new ConnectorManagerRepository();
TranslatorRepository repo = new TranslatorRepository();
this.vdb.addAttchment(TranslatorRepository.class, repo);
// check if this is a VDB with index files, if there are then build the TransformationMetadata
UDFMetaData udf = this.vdb.getAttachment(UDFMetaData.class);
// add required connector managers; if they are not already there
for (Translator t : this.vdb.getOverrideTranslators()) {
VDBTranslatorMetaData data = (VDBTranslatorMetaData) t;
String type = data.getType();
VDBTranslatorMetaData parent = getTranslatorRepository().getTranslatorMetaData(type);
data.setModuleName(parent.getModuleName());
data.addAttchment(ClassLoader.class, parent.getAttachment(ClassLoader.class));
data.setParent(parent);
repo.addTranslatorMetadata(data.getName(), data);
}
createConnectorManagers(cmr, repo, this.vdb);
final ServiceBuilder<Void> vdbService = addVDBFinishedService(context);
this.vdbListener = new VDBLifeCycleListener() {
@Override
public void added(String name, CompositeVDB cvdb) {
}
@Override
public void beforeRemove(String name, CompositeVDB cvdb) {
}
@Override
public void removed(String name, CompositeVDB cvdb) {
}
@Override
public void finishedDeployment(String name, CompositeVDB cvdb) {
if (!VDBService.this.vdbKey.equals(cvdb.getVDBKey())) {
return;
}
// clear out the indexmetadatarepository as it holds state that is no longer necessary
// $NON-NLS-1$
repositories.put("index", new IndexMetadataRepository());
VDBMetaData vdbInstance = cvdb.getVDB();
if (vdbInstance.getStatus().equals(Status.ACTIVE)) {
vdbService.install();
}
}
};
getVDBRepository().addListener(this.vdbListener);
MetadataStore store = new MetadataStore();
try {
// check to see if there is an index file. if there is then we assume
// that index is the default metadata repo
MetadataRepository<?, ?> defaultRepo = null;
for (String s : this.vdbResources.getEntriesPlusVisibilities().keySet()) {
if (s.endsWith(VDBResources.INDEX_EXT)) {
// $NON-NLS-1$
defaultRepo = super.getMetadataRepository("index");
break;
}
}
this.assignMetadataRepositories(vdb, defaultRepo);
// add transformation metadata to the repository.
getVDBRepository().addVDB(this.vdb, store, vdbResources.getEntriesPlusVisibilities(), udf, cmr);
} catch (VirtualDatabaseException e) {
cleanup(context);
throw new StartException(e);
}
this.vdb.removeAttachment(UDFMetaData.class);
try {
loadMetadata(this.vdb, cmr, store, this.vdbResources);
} catch (TranslatorException e) {
cleanup(context);
throw new StartException(e);
}
this.runtimeVDB = buildRuntimeVDB(this.vdb, context.getController().getServiceContainer());
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class TestMatViewAliasing method setUp.
@Before
public void setUp() throws Exception {
server = new FakeServer(true);
VDBRepository vdbRepository = new VDBRepository();
MetadataFactory mf = new MetadataFactory(null, 1, "foo", vdbRepository.getRuntimeTypeMap(), new Properties(), null);
mf.getSchema().setPhysical(false);
Table mat = mf.addTable("mat");
mat.setVirtual(true);
mat.setMaterialized(true);
mat.setSelectTransformation("/*+ cache(ttl:0) */ select 1 as x, 'y' as Name");
mf.addColumn("x", DataTypeManager.DefaultDataTypes.INTEGER, mat);
mf.addColumn("Name", DataTypeManager.DefaultDataTypes.STRING, mat);
MetadataStore ms = mf.asMetadataStore();
server.deployVDB(MATVIEWS, ms);
conn = server.createConnection("jdbc:teiid:" + MATVIEWS);
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class EmbeddedServer method deployVDB.
protected void deployVDB(VDBMetaData vdb, VDBResources resources) throws ConnectorManagerException, VirtualDatabaseException, TranslatorException {
checkStarted();
if (!vdb.getOverrideTranslators().isEmpty() && !allowOverrideTranslators()) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40106, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40106, vdb.getName()));
}
vdb.addAttchment(ClassLoader.class, Thread.currentThread().getContextClassLoader());
try {
createPreParser(vdb);
} catch (TeiidException e1) {
throw new VirtualDatabaseException(e1);
}
cmr.createConnectorManagers(vdb, this);
MetadataStore metadataStore = new MetadataStore();
UDFMetaData udfMetaData = new UDFMetaData();
udfMetaData.setFunctionClassLoader(Thread.currentThread().getContextClassLoader());
MetadataRepository<?, ?> defaultRepo = null;
LinkedHashMap<String, VDBResources.Resource> visibilityMap = null;
if (resources != null) {
// that index is the default metadata repo
for (String s : resources.getEntriesPlusVisibilities().keySet()) {
if (s.endsWith(VDBResources.INDEX_EXT)) {
defaultRepo = new IndexMetadataRepository();
break;
}
}
visibilityMap = resources.getEntriesPlusVisibilities();
} else {
visibilityMap = new LinkedHashMap<String, VDBResources.Resource>();
}
this.assignMetadataRepositories(vdb, defaultRepo);
repo.addVDB(vdb, metadataStore, visibilityMap, udfMetaData, cmr);
try {
this.loadMetadata(vdb, cmr, metadataStore, resources);
} catch (VDBValidationError e) {
throw new VirtualDatabaseException(RuntimePlugin.Event.valueOf(e.getCode()), e.getMessage());
}
}
use of org.teiid.metadata.MetadataStore in project teiid by teiid.
the class VDBRepository method addVDB.
public void addVDB(VDBMetaData vdb, MetadataStore metadataStore, LinkedHashMap<String, VDBResources.Resource> visibilityMap, UDFMetaData udf, ConnectorManagerRepository cmr) throws VirtualDatabaseException {
// get the system VDB metadata store
if (this.systemStore == null) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40022, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40022));
}
if (dataRolesRequired && vdb.getDataPolicyMap().isEmpty()) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40143, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40143, vdb));
}
boolean pgMetadataEnabled = ADD_PG_METADATA;
String includePgMetadata = vdb.getPropertyValue("include-pg-metadata");
if (includePgMetadata != null) {
pgMetadataEnabled = Boolean.parseBoolean(includePgMetadata);
}
if (pgMetadataEnabled && odbcException != null) {
throw odbcException;
}
MetadataStore[] stores = null;
if (pgMetadataEnabled) {
stores = new MetadataStore[] { this.systemStore, odbcStore };
} else {
stores = new MetadataStore[] { this.systemStore };
}
CompositeVDB cvdb = new CompositeVDB(vdb, metadataStore, visibilityMap, udf, this.systemFunctionManager.getSystemFunctions(), cmr, this, stores);
lock.lock();
try {
VDBKey vdbKey = cvdb.getVDBKey();
if (vdbKey.isAtMost()) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40145, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40145, vdbKey));
}
if (vdbRepo.containsKey(vdbKey)) {
throw new VirtualDatabaseException(RuntimePlugin.Event.TEIID40035, RuntimePlugin.Util.gs(RuntimePlugin.Event.TEIID40035, vdb.getName(), vdb.getVersion()));
}
// canonicalize the version
vdb.setVersion(vdbKey.getVersion());
// save the key for comparisons
vdb.addAttchment(VDBKey.class, vdbKey);
vdb.setStatus(Status.LOADING);
this.vdbRepo.put(vdbKey, cvdb);
this.pendingDeployments.remove(vdbKey);
vdbAdded.signalAll();
} finally {
lock.unlock();
}
notifyAdd(vdb.getName(), vdb.getVersion(), cvdb);
}
Aggregations