Search in sources :

Example 1 with S_Equal

use of org.apache.jena.sdb.core.sqlexpr.S_Equal in project jena by apache.

the class SlotCompiler method processSlot.

public final void processSlot(SDBRequest request, SqlTable table, SqlExprList conditions, Node node, String colName) {
    SqlColumn thisCol = new SqlColumn(table, colName);
    if (!node.isVariable()) {
        constantSlot(request, node, thisCol, conditions);
        return;
    }
    Var var = Var.alloc(node);
    if (table.getIdScope().hasColumnForVar(var)) {
        ScopeEntry e = table.getIdScope().findScopeForVar(var);
        SqlColumn otherCol = e.getColumn();
        SqlExpr c = new S_Equal(otherCol, thisCol);
        conditions.add(c);
        c.addNote("processVar: " + node);
        return;
    }
    table.setIdColumnForVar(var, thisCol);
}
Also used : ScopeEntry(org.apache.jena.sdb.core.ScopeEntry) Var(org.apache.jena.sparql.core.Var) SqlExpr(org.apache.jena.sdb.core.sqlexpr.SqlExpr) S_Equal(org.apache.jena.sdb.core.sqlexpr.S_Equal) SqlColumn(org.apache.jena.sdb.core.sqlexpr.SqlColumn)

Example 2 with S_Equal

use of org.apache.jena.sdb.core.sqlexpr.S_Equal in project jena by apache.

the class SQLBridge2 method insertValueGetter.

private SqlNode insertValueGetter(SDBRequest request, SqlNode sqlNode, Var var) {
    ScopeEntry e1 = sqlNode.getIdScope().findScopeForVar(var);
    if (e1 == null) {
        // Debug.
        Scope scope = sqlNode.getIdScope();
        // Variable not actually in results.
        return sqlNode;
    }
    // Already in scope (from a condition)?
    ScopeEntry e2 = sqlNode.getNodeScope().findScopeForVar(var);
    if (e2 != null)
        // Already there
        return sqlNode;
    SqlColumn c1 = e1.getColumn();
    // Not in scope -- add a table to get it
    TableDescNodes nodeTableDesc = request.getStore().getNodeTableDesc();
    String tableAlias = request.genId(NodeBase);
    SqlTable nTable = new SqlTable(tableAlias, nodeTableDesc.getTableName());
    String nodeKeyColName = nodeTableDesc.getNodeRefColName();
    SqlColumn c2 = new SqlColumn(nTable, nodeKeyColName);
    nTable.setValueColumnForVar(var, c2);
    // Condition for value: triple table column = node table id/hash 
    nTable.addNote("Var: " + var);
    SqlExpr cond = new S_Equal(c1, c2);
    SqlNode n = SqlBuilder.leftJoin(request, sqlNode, nTable, cond);
    return n;
}
Also used : ScopeEntry(org.apache.jena.sdb.core.ScopeEntry) Scope(org.apache.jena.sdb.core.Scope) SqlExpr(org.apache.jena.sdb.core.sqlexpr.SqlExpr) SqlTable(org.apache.jena.sdb.core.sqlnode.SqlTable) S_Equal(org.apache.jena.sdb.core.sqlexpr.S_Equal) SqlColumn(org.apache.jena.sdb.core.sqlexpr.SqlColumn) SqlNode(org.apache.jena.sdb.core.sqlnode.SqlNode)

Example 3 with S_Equal

use of org.apache.jena.sdb.core.sqlexpr.S_Equal in project jena by apache.

the class GenerateSQLVisitor method conditionList.

public void conditionList(SqlExprList conditions) {
    if (conditions.size() == 0)
        return;
    out.print("( ");
    String sep = "  AND ";
    boolean first = true;
    boolean lastAnnotated = false;
    for (SqlExpr c : conditions) {
        if (!first) {
            if (!allOnOneLine)
                out.println();
            out.print(sep);
        }
        boolean needsParens = !(c instanceof S_Equal);
        // TODO Interact with SqlExpr precedence printing
        if (needsParens)
            out.print("( ");
        out.print(c.asSQL());
        if (needsParens)
            out.print(" )");
        if (!allOnOneLine)
            lastAnnotated = annotate(c);
        first = false;
    }
    if (!allOnOneLine && lastAnnotated)
        out.println("");
    out.print(" )");
    first = true;
    if (allOnOneLine) {
        for (SqlExpr c : conditions) {
            if (c.hasNotes()) {
                if (!first)
                    out.println();
                annotate(c);
                first = false;
            }
        }
    }
}
Also used : SqlExpr(org.apache.jena.sdb.core.sqlexpr.SqlExpr) S_Equal(org.apache.jena.sdb.core.sqlexpr.S_Equal)

Aggregations

S_Equal (org.apache.jena.sdb.core.sqlexpr.S_Equal)3 SqlExpr (org.apache.jena.sdb.core.sqlexpr.SqlExpr)3 ScopeEntry (org.apache.jena.sdb.core.ScopeEntry)2 SqlColumn (org.apache.jena.sdb.core.sqlexpr.SqlColumn)2 Scope (org.apache.jena.sdb.core.Scope)1 SqlNode (org.apache.jena.sdb.core.sqlnode.SqlNode)1 SqlTable (org.apache.jena.sdb.core.sqlnode.SqlTable)1 Var (org.apache.jena.sparql.core.Var)1