Search in sources :

Example 1 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class DDLStringVisitor method visit.

public void visit(Database database) {
    append(NEWLINE);
    append("/*").append(NEWLINE);
    append("###########################################").append(NEWLINE);
    append("# START DATABASE ").append(database.getName()).append(NEWLINE);
    append("###########################################").append(NEWLINE);
    append("*/").append(NEWLINE);
    append(CREATE).append(SPACE).append(DATABASE).append(SPACE).append(SQLStringVisitor.escapeSinglePart(database.getName())).append(SPACE).append(VERSION).append(SPACE).append(new Constant(database.getVersion()));
    appendOptions(database);
    append(SEMICOLON);
    append(NEWLINE);
    append(USE).append(SPACE).append(DATABASE).append(SPACE);
    append(SQLStringVisitor.escapeSinglePart(database.getName())).append(SPACE);
    append(VERSION).append(SPACE).append(new Constant(database.getVersion()));
    append(SEMICOLON);
    append(NEWLINE);
    boolean outputDt = false;
    for (Datatype dt : database.getMetadataStore().getDatatypes().values()) {
        if (dt.getType() == Datatype.Type.Domain) {
            outputDt = true;
            break;
        }
    }
    if (outputDt) {
        append(NEWLINE);
        append("--############ Domains ############");
        append(NEWLINE);
        for (Datatype dt : database.getMetadataStore().getDatatypes().values()) {
            if (dt.isBuiltin()) {
                continue;
            }
            visit(dt);
            append(NEWLINE);
            append(NEWLINE);
        }
    }
    if (!database.getDataWrappers().isEmpty()) {
        append(NEWLINE);
        append("--############ Translators ############");
        append(NEWLINE);
        for (DataWrapper dw : database.getDataWrappers()) {
            visit(dw);
            append(NEWLINE);
            append(NEWLINE);
        }
    }
    if (!database.getServers().isEmpty()) {
        append(NEWLINE);
        append("--############ Servers ############");
        append(NEWLINE);
        for (Server server : database.getServers()) {
            visit(server);
            append(NEWLINE);
            append(NEWLINE);
        }
    }
    if (!database.getSchemas().isEmpty()) {
        append(NEWLINE);
        append("--############ Schemas ############");
        append(NEWLINE);
        for (Schema schema : database.getSchemas()) {
            append(CREATE);
            if (!schema.isPhysical()) {
                append(SPACE).append(VIRTUAL);
            }
            append(SPACE).append(SCHEMA).append(SPACE).append(SQLStringVisitor.escapeSinglePart(schema.getName()));
            if (!schema.getServers().isEmpty()) {
                append(SPACE).append(SERVER);
                boolean first = true;
                for (Server s : schema.getServers()) {
                    if (first) {
                        first = false;
                    } else {
                        append(COMMA);
                    }
                    append(SPACE).append(SQLStringVisitor.escapeSinglePart(s.getName()));
                }
            }
            appendOptions(schema);
            append(SEMICOLON);
            append(NEWLINE);
            append(NEWLINE);
            createdSchmea(schema);
        }
    }
    if (!database.getRoles().isEmpty()) {
        append(NEWLINE);
        append("--############ Roles ############");
        append(NEWLINE);
        for (Role role : database.getRoles()) {
            visit(role);
            append(NEWLINE);
            append(NEWLINE);
        }
    }
    for (Schema schema : database.getSchemas()) {
        append(NEWLINE);
        append("--############ Schema:").append(schema.getName()).append(" ############");
        append(NEWLINE);
        append(SET).append(SPACE).append(SCHEMA).append(SPACE);
        append(SQLStringVisitor.escapeSinglePart(schema.getName())).append(SEMICOLON);
        append(NEWLINE);
        append(NEWLINE);
        visit(schema);
    }
    if (!database.getRoles().isEmpty()) {
        append(NEWLINE);
        append("--############ Grants ############");
        append(NEWLINE);
        for (Grant grant : database.getGrants()) {
            visit(grant);
            append(NEWLINE);
        }
    }
    append(NEWLINE);
    append("/*").append(NEWLINE);
    append("###########################################").append(NEWLINE);
    append("# END DATABASE ").append(database.getName()).append(NEWLINE);
    append("###########################################").append(NEWLINE);
    append("*/").append(NEWLINE);
    append(NEWLINE);
}
Also used : Constant(org.teiid.query.sql.symbol.Constant)

Example 2 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class DDLStringVisitor method visit.

private void visit(Server server) {
    append(CREATE).append(SPACE).append(SERVER).append(SPACE).append(SQLStringVisitor.escapeSinglePart(server.getName()));
    if (!server.isVirtual()) {
        append(SPACE).append(TYPE).append(SPACE).append(new Constant(server.getType()));
    }
    if (server.getVersion() != null) {
        append(SPACE).append(VERSION).append(SPACE).append(new Constant(server.getVersion()));
    }
    append(SPACE).append(FOREIGN).append(SPACE).append(DATA).append(SPACE).append(WRAPPER).append(SPACE);
    append(SQLStringVisitor.escapeSinglePart(server.getDataWrapper()));
    appendOptions(server);
    append(SEMICOLON);
}
Also used : Constant(org.teiid.query.sql.symbol.Constant)

Example 3 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestConnectorWorkItem method testProcedureBatching.

@Test
public void testProcedureBatching() throws Exception {
    ProcedureExecution exec = new FakeProcedureExecution(2, 1);
    // this has two result set columns and 1 out parameter
    int total_columns = 3;
    // $NON-NLS-1$
    StoredProcedure command = (StoredProcedure) helpGetCommand("{call pm2.spTest8(?)}", EXAMPLE_BQT);
    command.getInputParameters().get(0).setExpression(new Constant(1));
    Call proc = new LanguageBridgeFactory(EXAMPLE_BQT).translate(command);
    ProcedureBatchHandler pbh = new ProcedureBatchHandler(proc, exec);
    assertEquals(total_columns, pbh.padRow(Arrays.asList(null, null)).size());
    List params = pbh.getParameterRow();
    assertEquals(total_columns, params.size());
    // check the parameter value
    assertEquals(Integer.valueOf(0), params.get(2));
    try {
        pbh.padRow(Arrays.asList(1));
        // $NON-NLS-1$
        fail("Expected exception from resultset mismatch");
    } catch (TranslatorException err) {
        assertEquals("TEIID30479 Could not process stored procedure results for EXEC spTest8(1).  Expected 2 result set columns, but was 1.  Please update your models to allow for stored procedure results batching.", // $NON-NLS-1$
        err.getMessage());
    }
}
Also used : Call(org.teiid.language.Call) StoredProcedure(org.teiid.query.sql.lang.StoredProcedure) ProcedureExecution(org.teiid.translator.ProcedureExecution) Constant(org.teiid.query.sql.symbol.Constant) List(java.util.List) ArrayList(java.util.ArrayList) TranslatorException(org.teiid.translator.TranslatorException) SourceHint(org.teiid.query.sql.lang.SourceHint) Test(org.junit.Test)

Example 4 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestInsertImpl method helpExample.

public static org.teiid.query.sql.lang.Insert helpExample(String groupName) {
    GroupSymbol group = TestGroupImpl.helpExample(groupName);
    ArrayList<ElementSymbol> elements = new ArrayList<ElementSymbol>();
    // $NON-NLS-1$
    elements.add(TestElementImpl.helpExample(groupName, "e1"));
    // $NON-NLS-1$
    elements.add(TestElementImpl.helpExample(groupName, "e2"));
    // $NON-NLS-1$
    elements.add(TestElementImpl.helpExample(groupName, "e3"));
    // $NON-NLS-1$
    elements.add(TestElementImpl.helpExample(groupName, "e4"));
    ArrayList<Constant> values = new ArrayList<Constant>();
    values.add(TestLiteralImpl.helpExample(1));
    values.add(TestLiteralImpl.helpExample(2));
    values.add(TestLiteralImpl.helpExample(3));
    values.add(TestLiteralImpl.helpExample(4));
    return new org.teiid.query.sql.lang.Insert(group, elements, values);
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) Constant(org.teiid.query.sql.symbol.Constant) GroupSymbol(org.teiid.query.sql.symbol.GroupSymbol) ArrayList(java.util.ArrayList) Insert(org.teiid.language.Insert)

Example 5 with Constant

use of org.teiid.query.sql.symbol.Constant in project teiid by teiid.

the class TestLikeCriteriaImpl method helpExample.

public static MatchCriteria helpExample(String right, char escape, boolean negated) {
    // $NON-NLS-1$ //$NON-NLS-2$
    ElementSymbol e1 = TestElementImpl.helpExample("vm1.g1", "e1");
    MatchCriteria match = new MatchCriteria(e1, new Constant(right), escape);
    match.setNegated(negated);
    return match;
}
Also used : ElementSymbol(org.teiid.query.sql.symbol.ElementSymbol) MatchCriteria(org.teiid.query.sql.lang.MatchCriteria) Constant(org.teiid.query.sql.symbol.Constant)

Aggregations

Constant (org.teiid.query.sql.symbol.Constant)203 ElementSymbol (org.teiid.query.sql.symbol.ElementSymbol)94 Test (org.junit.Test)88 ArrayList (java.util.ArrayList)61 GroupSymbol (org.teiid.query.sql.symbol.GroupSymbol)48 List (java.util.List)38 Expression (org.teiid.query.sql.symbol.Expression)38 Function (org.teiid.query.sql.symbol.Function)31 CompareCriteria (org.teiid.query.sql.lang.CompareCriteria)25 Query (org.teiid.query.sql.lang.Query)22 Select (org.teiid.query.sql.lang.Select)15 Reference (org.teiid.query.sql.symbol.Reference)14 From (org.teiid.query.sql.lang.From)12 HashMap (java.util.HashMap)11 FunctionDescriptor (org.teiid.query.function.FunctionDescriptor)11 Criteria (org.teiid.query.sql.lang.Criteria)11 SetQuery (org.teiid.query.sql.lang.SetQuery)11 LinkedList (java.util.LinkedList)10 Limit (org.teiid.query.sql.lang.Limit)10 StoredProcedure (org.teiid.query.sql.lang.StoredProcedure)9