Search in sources :

Example 1 with AlterTrigger

use of org.teiid.query.sql.lang.AlterTrigger in project teiid by teiid.

the class TestAlterResolving method testAlterTriggerInsert.

@Test
public void testAlterTriggerInsert() {
    AlterTrigger alterTrigger = (AlterTrigger) helpResolve("alter trigger on SmallA_2589 instead of insert as for each row begin atomic select new.intkey; end", RealMetadataFactory.exampleBQTCached());
    assertNotNull(alterTrigger.getTarget().getMetadataID());
}
Also used : AlterTrigger(org.teiid.query.sql.lang.AlterTrigger) Test(org.junit.Test)

Example 2 with AlterTrigger

use of org.teiid.query.sql.lang.AlterTrigger in project teiid by teiid.

the class TestParseAlter method testAlterDisabledPhysical.

@Test
public void testAlterDisabledPhysical() throws Exception {
    AlterTrigger alterTrigger = new AlterTrigger();
    alterTrigger.setTarget(new GroupSymbol("x"));
    alterTrigger.setEvent(TriggerEvent.UPDATE);
    alterTrigger.setEnabled(false);
    alterTrigger.setAfter(true);
    alterTrigger.setName("y");
    helpTest("alter trigger y on x after update disabled", "ALTER TRIGGER y ON x AFTER UPDATE DISABLED", alterTrigger);
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) AlterTrigger(org.teiid.query.sql.lang.AlterTrigger) Test(org.junit.Test)

Example 3 with AlterTrigger

use of org.teiid.query.sql.lang.AlterTrigger in project teiid by teiid.

the class TestParseAlter method testCreateTriggerPhysical.

@Test
public void testCreateTriggerPhysical() throws Exception {
    AlterTrigger alterTrigger = new AlterTrigger();
    alterTrigger.setCreate(true);
    alterTrigger.setTarget(new GroupSymbol("x"));
    alterTrigger.setEvent(TriggerEvent.INSERT);
    alterTrigger.setAfter(true);
    alterTrigger.setName("z");
    alterTrigger.setDefinition((TriggerAction) QueryParser.getQueryParser().parseProcedure("for each row begin end", true));
    helpTest("create trigger z on x after insert as for each row begin end", "CREATE TRIGGER z ON x AFTER INSERT AS\nFOR EACH ROW\nBEGIN ATOMIC\nEND", alterTrigger);
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) AlterTrigger(org.teiid.query.sql.lang.AlterTrigger) Test(org.junit.Test)

Example 4 with AlterTrigger

use of org.teiid.query.sql.lang.AlterTrigger in project teiid by teiid.

the class AlterResolver method resolveCommand.

@Override
public void resolveCommand(Command command, TempMetadataAdapter metadata, boolean resolveNullLiterals) throws QueryMetadataException, QueryResolverException, TeiidComponentException {
    Alter<? extends Command> alter = (Alter<? extends Command>) command;
    ResolverUtil.resolveGroup(alter.getTarget(), metadata);
    int type = Command.TYPE_QUERY;
    boolean viewTarget = true;
    if (alter instanceof AlterTrigger) {
        TriggerEvent event = ((AlterTrigger) alter).getEvent();
        switch(event) {
            case DELETE:
                type = Command.TYPE_DELETE;
                break;
            case INSERT:
                type = Command.TYPE_INSERT;
                break;
            case UPDATE:
                type = Command.TYPE_UPDATE;
                break;
        }
        if (((AlterTrigger) alter).isAfter()) {
            viewTarget = false;
        }
    } else if (alter instanceof AlterProcedure) {
        type = Command.TYPE_STORED_PROCEDURE;
        viewTarget = false;
    }
    if (viewTarget && !QueryResolver.isView(alter.getTarget(), metadata)) {
        throw new QueryResolverException(QueryPlugin.Event.TEIID30116, QueryPlugin.Util.gs(QueryPlugin.Event.TEIID30116, alter.getTarget()));
    }
    if (alter.getDefinition() != null) {
        QueryResolver.resolveCommand(alter.getDefinition(), alter.getTarget(), type, metadata.getDesignTimeMetadata(), false);
    }
}
Also used : Alter(org.teiid.query.sql.lang.Alter) AlterProcedure(org.teiid.query.sql.lang.AlterProcedure) Command(org.teiid.query.sql.lang.Command) TriggerEvent(org.teiid.metadata.Table.TriggerEvent) AlterTrigger(org.teiid.query.sql.lang.AlterTrigger) QueryResolverException(org.teiid.api.exception.query.QueryResolverException)

Example 5 with AlterTrigger

use of org.teiid.query.sql.lang.AlterTrigger in project teiid by teiid.

the class TestParseAlter method testCreateTrigger.

@Test
public void testCreateTrigger() throws Exception {
    AlterTrigger alterTrigger = new AlterTrigger();
    alterTrigger.setCreate(true);
    alterTrigger.setTarget(new GroupSymbol("x"));
    alterTrigger.setEvent(TriggerEvent.UPDATE);
    alterTrigger.setDefinition((TriggerAction) QueryParser.getQueryParser().parseProcedure("for each row begin end", true));
    helpTest("create trigger on x instead of update as for each row begin end", "CREATE TRIGGER ON x INSTEAD OF UPDATE AS\nFOR EACH ROW\nBEGIN ATOMIC\nEND", alterTrigger);
}
Also used : GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) AlterTrigger(org.teiid.query.sql.lang.AlterTrigger) Test(org.junit.Test)

Aggregations

AlterTrigger (org.teiid.query.sql.lang.AlterTrigger)7 Test (org.junit.Test)6 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)5 QueryResolverException (org.teiid.api.exception.query.QueryResolverException)1 TriggerEvent (org.teiid.metadata.Table.TriggerEvent)1 Alter (org.teiid.query.sql.lang.Alter)1 AlterProcedure (org.teiid.query.sql.lang.AlterProcedure)1 Command (org.teiid.query.sql.lang.Command)1