Search in sources :

Example 1 with DatabaseStore

use of org.teiid.query.metadata.DatabaseStore in project teiid by teiid.

the class DdlPlan method alterProcedureDefinition.

public static void alterProcedureDefinition(final VDBMetaData vdb, final Procedure p, final String sql, boolean updateStore) {
    TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class);
    DatabaseStore store = vdb.getAttachment(DatabaseStore.class);
    try {
        Command command = QueryParser.getQueryParser().parseProcedure(p.getQueryPlan(), false);
        QueryResolver.resolveCommand(command, new GroupSymbol(p.getFullName()), Command.TYPE_STORED_PROCEDURE, metadata, false);
        MetadataValidator.determineDependencies(p, command);
    } catch (TeiidException e) {
    // should have been caught in validation, but this logic
    // is also not mature so since there is no lock on the vdb
    // it is possible that the plan is no longer valid at this point due
    // to a concurrent execution
    }
    p.setQueryPlan(sql);
    p.setLastModified(System.currentTimeMillis());
    // $NON-NLS-1$
    metadata.addToMetadataCache(p, "transformation/" + StoredProcedure.class.getSimpleName().toUpperCase(), null);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) DatabaseStore(org.teiid.query.metadata.DatabaseStore) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) Command(org.teiid.query.sql.lang.Command) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) TeiidException(org.teiid.core.TeiidException)

Example 2 with DatabaseStore

use of org.teiid.query.metadata.DatabaseStore in project teiid by teiid.

the class DdlPlan method alterView.

public static void alterView(final VDBMetaData vdb, final Table t, final String sql, boolean updateStore) {
    TransformationMetadata metadata = vdb.getAttachment(TransformationMetadata.class);
    DatabaseStore store = vdb.getAttachment(DatabaseStore.class);
    try {
        Command command = QueryParser.getQueryParser().parseCommand(t.getSelectTransformation());
        QueryResolver.resolveCommand(command, metadata);
        MetadataValidator.determineDependencies(t, command);
    } catch (TeiidException e) {
    // should have been caught in validation, but this logic
    // is also not mature so since there is no lock on the vdb
    // it is possible that the plan is no longer valid at this point due
    // to a concurrent execution
    }
    t.setSelectTransformation(sql);
    t.setLastModified(System.currentTimeMillis());
    // $NON-NLS-1$
    metadata.addToMetadataCache(t, "transformation/" + SQLConstants.Reserved.SELECT, null);
}
Also used : TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) DatabaseStore(org.teiid.query.metadata.DatabaseStore) Command(org.teiid.query.sql.lang.Command) TeiidException(org.teiid.core.TeiidException)

Example 3 with DatabaseStore

use of org.teiid.query.metadata.DatabaseStore 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);
}
Also used : DatabaseStore(org.teiid.query.metadata.DatabaseStore) TransformationMetadata(org.teiid.query.metadata.TransformationMetadata) CompositeMetadataStore(org.teiid.query.metadata.CompositeMetadataStore) StringReader(java.io.StringReader)

Aggregations

DatabaseStore (org.teiid.query.metadata.DatabaseStore)3 TransformationMetadata (org.teiid.query.metadata.TransformationMetadata)3 TeiidException (org.teiid.core.TeiidException)2 Command (org.teiid.query.sql.lang.Command)2 StringReader (java.io.StringReader)1 CompositeMetadataStore (org.teiid.query.metadata.CompositeMetadataStore)1 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)1 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)1