Search in sources :

Example 56 with TransformationMetadata

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();
    }
}
Also used : DataWrapper(org.teiid.metadata.DataWrapper) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) Server(org.teiid.metadata.Server) Database(org.teiid.metadata.Database)

Example 57 with TransformationMetadata

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());
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata)

Example 58 with TransformationMetadata

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;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) Table(org.teiid.metadata.Table) AlterProcedure(org.teiid.query.sql.lang.AlterProcedure) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Procedure(org.teiid.metadata.Procedure)

Example 59 with TransformationMetadata

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;
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) MetadataValidator(org.teiid.query.metadata.MetadataValidator) ValidatorReport(org.teiid.query.validator.ValidatorReport)

Example 60 with TransformationMetadata

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;
}
Also used : UDFSource(org.teiid.query.function.UDFSource) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) FunctionTree(org.teiid.query.function.FunctionTree) VDBMetaData(org.teiid.adminapi.impl.VDBMetaData) ArrayList(java.util.ArrayList)

Aggregations

TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)427 Test (org.junit.Test)352 BasicSourceCapabilities (org.teiid.query.optimizer.capabilities.BasicSourceCapabilities)163 ProcessorPlan (org.teiid.query.processor.ProcessorPlan)108 FakeCapabilitiesFinder (org.teiid.query.optimizer.capabilities.FakeCapabilitiesFinder)97 DefaultCapabilitiesFinder (org.teiid.query.optimizer.capabilities.DefaultCapabilitiesFinder)89 List (java.util.List)83 CommandContext (org.teiid.query.util.CommandContext)64 HardcodedDataManager (org.teiid.query.processor.HardcodedDataManager)63 ArrayList (java.util.ArrayList)56 TranslationUtility (org.teiid.cdk.api.TranslationUtility)35 MetadataFactory (org.teiid.metadata.MetadataFactory)35 FakeDataManager (org.teiid.query.processor.FakeDataManager)35 RealMetadataFactory (org.teiid.query.unittest.RealMetadataFactory)35 Schema (org.teiid.metadata.Schema)33 Table (org.teiid.metadata.Table)27 FunctionTree (org.teiid.query.function.FunctionTree)22 Column (org.teiid.metadata.Column)21 Command (org.teiid.language.Command)20 UDFSource (org.teiid.query.function.UDFSource)20