use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.
the class QueryParser method parseDDL.
public void parseDDL(final MetadataFactory factory, Reader ddl) {
SingleSchemaDatabaseStore store = new SingleSchemaDatabaseStore(factory);
store.startEditing(true);
Database db = new Database(factory.getVdbName(), factory.getVdbVersion());
store.databaseCreated(db);
store.databaseSwitched(factory.getVdbName(), factory.getVdbVersion());
store.dataWrapperCreated(new DataWrapper(NONE));
Server server = new Server(NONE);
server.setDataWrapper(NONE);
store.serverCreated(server);
if (factory.getSchema().isPhysical()) {
Server s = new Server(factory.getSchema().getName());
s.setDataWrapper(NONE);
store.serverCreated(s);
}
List<String> servers = Collections.emptyList();
store.schemaCreated(factory.getSchema(), servers);
// with the schema created, create the TransformationMetadata
CompositeMetadataStore cms = new CompositeMetadataStore(db.getMetadataStore());
TransformationMetadata qmi = new TransformationMetadata(DatabaseUtil.convert(db), cms, null, null, null);
store.setTransformationMetadata(qmi);
store.schemaSwitched(factory.getSchema().getName());
store.setMode(Mode.SCHEMA);
store.setStrict(true);
try {
parseDDL(store, ddl);
Map<String, String> colNs = store.getNameSpaces();
for (String key : colNs.keySet()) {
factory.addNamespace(key, colNs.get(key));
}
} finally {
store.stopEditing();
}
}
use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.
the class DdlPlan method alterInsteadOfTrigger.
public static void alterInsteadOfTrigger(final VDBMetaData vdb, final Table t, final String sql, final Boolean enabled, final TriggerEvent event, boolean updateStore) {
switch(event) {
case DELETE:
if (sql != null) {
t.setDeletePlan(sql);
} else {
t.setDeletePlanEnabled(enabled);
}
break;
case INSERT:
if (sql != null) {
t.setInsertPlan(sql);
} else {
t.setInsertPlanEnabled(enabled);
}
break;
case UPDATE:
if (sql != null) {
t.setUpdatePlan(sql);
} else {
t.setUpdatePlanEnabled(enabled);
}
break;
}
TransformationMetadata indexMetadata = vdb.getAttachment(TransformationMetadata.class);
// $NON-NLS-1$
indexMetadata.addToMetadataCache(t, "transformation/" + event, null);
t.setLastModified(System.currentTimeMillis());
}
use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.
the class DdlPlan method setProperty.
public static String setProperty(final VDBMetaData vdb, final AbstractMetadataRecord record, final String key, final String value) {
TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class);
String result = record.setProperty(key, value);
// $NON-NLS-1$
metadata.addToMetadataCache(record, "transformation/matview", null);
if (record instanceof Table) {
((Table) record).setLastModified(System.currentTimeMillis());
} else if (record instanceof Procedure) {
((Procedure) record).setLastModified(System.currentTimeMillis());
}
return result;
}
use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.
the class RealMetadataFactory method fromDDL.
public static TransformationMetadata fromDDL(String vdbName, DDLHolder... schemas) throws Exception {
CompositeMetadataStore cms = new CompositeMetadataStore(Collections.EMPTY_LIST);
for (DDLHolder schema : schemas) {
MetadataFactory mf = TestDDLParser.helpParse(schema.ddl, schema.name);
cms.merge(mf.asMetadataStore());
}
TransformationMetadata tm = createTransformationMetadata(cms, vdbName);
ValidatorReport report = new MetadataValidator().validate(tm.getVdbMetaData(), tm.getMetadataStore());
if (report.hasItems()) {
throw new RuntimeException(report.getFailureMessage());
}
return tm;
}
use of org.teiid.query.metadata.TransformationMetadata in project teiid by teiid.
the class RealMetadataFactory method createTransformationMetadata.
public static TransformationMetadata createTransformationMetadata(CompositeMetadataStore store, String vdbName, Properties vdbProperties, FunctionTree... functionModels) {
VDBMetaData vdbMetaData = new VDBMetaData();
// $NON-NLS-1$
vdbMetaData.setName(vdbName);
vdbMetaData.setVersion(1);
if (vdbProperties != null) {
vdbMetaData.setProperties(vdbProperties);
}
List<FunctionTree> udfs = new ArrayList<FunctionTree>();
udfs.addAll(Arrays.asList(functionModels));
for (Schema schema : store.getSchemas().values()) {
vdbMetaData.addModel(RealMetadataFactory.createModel(schema.getName(), schema.isPhysical()));
if (!schema.getFunctions().isEmpty()) {
udfs.add(new FunctionTree(schema.getName(), new UDFSource(schema.getFunctions().values()), true));
}
if (!schema.getProcedures().isEmpty()) {
FunctionTree ft = FunctionTree.getFunctionProcedures(schema);
if (ft != null) {
udfs.add(ft);
}
}
}
TransformationMetadata metadata = new TransformationMetadata(vdbMetaData, store, null, SFM.getSystemFunctions(), udfs);
vdbMetaData.addAttchment(TransformationMetadata.class, metadata);
vdbMetaData.addAttchment(QueryMetadataInterface.class, metadata);
return metadata;
}
Aggregations