use of org.teiid.query.metadata.CompositeMetadataStore in project teiid by teiid.
the class TestDDLParser method helpParse.
public static Database helpParse(String ddl, DatabaseStore.Mode mode) {
final Map<String, Datatype> dataTypes = getDataTypes();
DatabaseStore store = new DatabaseStore() {
@Override
public Map<String, Datatype> getRuntimeTypes() {
return dataTypes;
}
@Override
protected TransformationMetadata getTransformationMetadata() {
Database database = getCurrentDatabase();
CompositeMetadataStore store = new CompositeMetadataStore(database.getMetadataStore());
// grants are already stored on the VDBMetaData
store.getGrants().clear();
return new TransformationMetadata(DatabaseUtil.convert(database), store, null, null, null);
}
};
store.startEditing(true);
store.setMode(mode);
QueryParser.getQueryParser().parseDDL(store, new StringReader(ddl));
store.stopEditing();
if (store.getDatabases().isEmpty()) {
return null;
}
return store.getDatabases().get(0);
}
use of org.teiid.query.metadata.CompositeMetadataStore in project teiid by teiid.
the class VDBMetadataFactory method getVDBMetadata.
public static TransformationMetadata getVDBMetadata(String vdbName, URL vdbURL, URL udfFile) throws IOException {
TransformationMetadata vdbmetadata = VDB_CACHE.get(vdbURL);
if (vdbmetadata != null) {
return vdbmetadata;
}
try {
IndexVDB imf = loadMetadata(vdbName, vdbURL);
Resource r = imf.resources.getEntriesPlusVisibilities().get("/META-INF/vdb.xml");
VDBMetaData vdb = null;
if (r != null) {
vdb = VDBMetadataParser.unmarshell(r.openStream());
}
Collection<FunctionMethod> methods = null;
Collection<FunctionTree> trees = null;
if (udfFile != null) {
String schema = FileUtils.getFilenameWithoutExtension(udfFile.getPath());
methods = FunctionMetadataReader.loadFunctionMethods(udfFile.openStream());
trees = Arrays.asList(new FunctionTree(schema, new UDFSource(methods), true));
}
SystemFunctionManager sfm = SystemMetadata.getInstance().getSystemFunctionManager();
vdbmetadata = new TransformationMetadata(vdb, new CompositeMetadataStore(Arrays.asList(SystemMetadata.getInstance().getSystemStore(), imf.store)), imf.resources.getEntriesPlusVisibilities(), sfm.getSystemFunctions(), trees);
VDB_CACHE.put(vdbURL, vdbmetadata);
return vdbmetadata;
} catch (XMLStreamException e) {
throw new IOException(e);
}
}
use of org.teiid.query.metadata.CompositeMetadataStore in project teiid by teiid.
the class CompositeVDB method buildTransformationMetaData.
private static TransformationMetadata buildTransformationMetaData(VDBMetaData vdb, LinkedHashMap<String, VDBResources.Resource> visibilityMap, MetadataStore store, UDFMetaData udf, FunctionTree systemFunctions, MetadataStore[] additionalStores, boolean allowEnv) {
Collection<FunctionTree> udfs = new ArrayList<FunctionTree>();
if (udf != null) {
for (Map.Entry<String, UDFSource> entry : udf.getFunctions().entrySet()) {
udfs.add(new FunctionTree(entry.getKey(), entry.getValue(), true));
}
}
// add functions for procedures
for (Schema schema : store.getSchemas().values()) {
if (!schema.getProcedures().isEmpty()) {
FunctionTree ft = FunctionTree.getFunctionProcedures(schema);
if (ft != null) {
udfs.add(ft);
}
}
}
CompositeMetadataStore compositeStore = new CompositeMetadataStore(store);
for (MetadataStore s : additionalStores) {
compositeStore.merge(s);
for (Schema schema : s.getSchemas().values()) {
if (!schema.getFunctions().isEmpty()) {
UDFSource source = new UDFSource(schema.getFunctions().values());
if (udf != null) {
source.setClassLoader(udf.getClassLoader());
}
udfs.add(new FunctionTree(schema.getName(), source, true));
}
if (!schema.getProcedures().isEmpty()) {
FunctionTree ft = FunctionTree.getFunctionProcedures(schema);
if (ft != null) {
udfs.add(ft);
}
}
}
}
TransformationMetadata metadata = new TransformationMetadata(vdb, compositeStore, visibilityMap, systemFunctions, udfs);
metadata.setAllowENV(allowEnv);
metadata.setUseOutputNames(false);
metadata.setWidenComparisonToString(WIDEN_COMPARISON_TO_STRING);
return metadata;
}
Aggregations