Package org.openrdf.sail.rdbms.evaluation

Examples of org.openrdf.sail.rdbms.evaluation.SqlQueryBuilder


      RdbmsResource s = vf.asRdbmsResource(subj);
      RdbmsURI p = vf.asRdbmsURI(pred);
      RdbmsValue o = vf.asRdbmsValue(obj);
      RdbmsResource[] c = vf.asRdbmsResource(ctxs);
      flush();
      SqlQueryBuilder query = buildSelectQuery(s, p, o, c);
      if (query == null) {
        return new EmptyRdbmsStatementCursor();
      }
      List<?> parameters = query.findParameters(new ArrayList<Object>());
      PreparedStatement stmt = conn.prepareStatement(query.toString());
      try {
        for (int i = 0, n = parameters.size(); i < n; i++) {
          stmt.setObject(i + 1, parameters.get(i));
        }
        return new RdbmsStatementCursor(vf, stmt, ids);
View Full Code Here


  public long size(RdbmsResource subj, RdbmsURI pred, RdbmsValue obj, RdbmsResource... ctxs)
    throws SQLException, StoreException
  {
    flush();
    SqlQueryBuilder qry = buildCountQuery(subj, pred, obj, ctxs);
    if (qry == null) {
      return 0;
    }
    List<?> parameters = qry.findParameters(new ArrayList<Object>());
    PreparedStatement stmt = conn.prepareStatement(qry.toString());
    try {
      for (int i = 0, n = parameters.size(); i < n; i++) {
        stmt.setObject(i + 1, parameters.get(i));
      }
      ResultSet rs = stmt.executeQuery();
View Full Code Here

  {
    if (statements.isEmpty()) {
      return null;
    }
    String tableName = statements.getCombinedTableName();
    SqlQueryBuilder query = factory.createSqlQueryBuilder();
    query.select().column("t", "ctx");
    query.select().append("CASE WHEN MIN(u.value) IS NOT NULL THEN MIN(u.value) ELSE MIN(b.value) END");
    SqlJoinBuilder join = query.from(tableName, "t");
    join.leftjoin(bnodes.getName(), "b").on("id", "t.ctx");
    join.leftjoin(uris.getShortTableName(), "u").on("id", "t.ctx");
    SqlBracketBuilder open = query.filter().and().open();
    open.column("u", "value").isNotNull();
    open.or();
    open.column("b", "value").isNotNull();
    open.close();
    query.groupBy("t.ctx");
    return query.toString();
  }
View Full Code Here

  private SqlQueryBuilder buildCountQuery(RdbmsResource subj, RdbmsURI pred, RdbmsValue obj,
      RdbmsResource... ctxs)
    throws RdbmsException, SQLException
  {
    String tableName = statements.getTableName(vf.getInternalId(pred));
    SqlQueryBuilder query = factory.createSqlQueryBuilder();
    query.select().append("COUNT(*)");
    query.from(tableName, "t");
    if (ctxs != null && ctxs.length > 0) {
      Number[] ids = new Number[ctxs.length];
      for (int i = 0; i < ids.length; i++) {
        ids[i] = vf.getInternalId(ctxs[i]);
      }
      query.filter().and().columnIn("t", "ctx", ids);
    }
    if (subj != null) {
      Number id = vf.getInternalId(subj);
      query.filter().and().columnEquals("t", "subj", id);
    }
    if (pred != null) {
      Number id = vf.getInternalId(pred);
      if (statements.isPredColumnPresent(id)) {
        query.filter().and().columnEquals("t", "pred", id);
      }
    }
    if (obj != null) {
      Number id = vf.getInternalId(obj);
      query.filter().and().columnEquals("t", "obj", id);
    }
    return query;
  }
View Full Code Here

  private SqlQueryBuilder buildSelectQuery(RdbmsResource subj, RdbmsURI pred, RdbmsValue obj,
      RdbmsResource... ctxs)
    throws RdbmsException, SQLException
  {
    String tableName = statements.getTableName(vf.getInternalId(pred));
    SqlQueryBuilder query = factory.createSqlQueryBuilder();
    query.select().column("t", "ctx");
    query.select().append(
        "CASE WHEN cu.value IS NOT NULL THEN cu.value WHEN clu.value IS NOT NULL THEN clu.value ELSE cb.value END");
    query.select().column("t", "subj");
    query.select().append(
        "CASE WHEN su.value IS NOT NULL THEN su.value WHEN slu.value IS NOT NULL THEN slu.value ELSE sb.value END");
    query.select().column("pu", "id");
    query.select().column("pu", "value");
    query.select().column("t", "obj");
    query.select().append(
        "CASE WHEN ou.value IS NOT NULL THEN ou.value" + " WHEN olu.value IS NOT NULL THEN olu.value"
            + " WHEN ob.value IS NOT NULL THEN ob.value"
            + " WHEN ol.value IS NOT NULL THEN ol.value ELSE oll.value END");
    query.select().column("od", "value");
    query.select().column("og", "value");
    SqlJoinBuilder join;
    if (pred != null) {
      join = query.from(uris.getShortTableName(), "pu");
      // TODO what about long predicate URIs?
      join = join.join(tableName, "t");
    }
    else {
      join = query.from(tableName, "t");
    }
    if (pred == null) {
      join.join(uris.getShortTableName(), "pu").on("id", "t.pred");
    }
    join.leftjoin(uris.getShortTableName(), "cu").on("id", "t.ctx");
    join.leftjoin(uris.getLongTableName(), "clu").on("id", "t.ctx");
    join.leftjoin(bnodes.getName(), "cb").on("id", "t.ctx");
    join.leftjoin(uris.getShortTableName(), "su").on("id", "t.subj");
    join.leftjoin(uris.getLongTableName(), "slu").on("id", "t.subj");
    join.leftjoin(bnodes.getName(), "sb").on("id", "t.subj");
    join.leftjoin(uris.getShortTableName(), "ou").on("id", "t.obj");
    join.leftjoin(uris.getLongTableName(), "olu").on("id", "t.obj");
    join.leftjoin(bnodes.getName(), "ob").on("id", "t.obj");
    join.leftjoin(literals.getLabelTable().getName(), "ol").on("id", "t.obj");
    join.leftjoin(literals.getLongLabelTable().getName(), "oll").on("id", "t.obj");
    join.leftjoin(literals.getLanguageTable().getName(), "og").on("id", "t.obj");
    join.leftjoin(literals.getDatatypeTable().getName(), "od").on("id", "t.obj");
    if (ctxs != null && ctxs.length > 0) {
      Number[] ids = new Number[ctxs.length];
      for (int i = 0; i < ids.length; i++) {
        ids[i] = vf.getInternalId(ctxs[i]);
      }
      query.filter().and().columnIn("t", "ctx", ids);
    }
    if (subj != null) {
      Number id = vf.getInternalId(subj);
      query.filter().and().columnEquals("t", "subj", id);
    }
    if (pred != null) {
      Number id = vf.getInternalId(pred);
      query.filter().and().columnEquals("pu", "id", id);
      if (statements.isPredColumnPresent(id)) {
        query.filter().and().columnEquals("t", "pred", id);
      }
    }
    if (obj != null) {
      Number id = vf.getInternalId(obj);
      query.filter().and().columnEquals("t", "obj", id);
    }
    return query;
  }
View Full Code Here

      RdbmsResource s = vf.asRdbmsResource(subj);
      RdbmsURI p = vf.asRdbmsURI(pred);
      RdbmsValue o = vf.asRdbmsValue(obj, pred);
      RdbmsResource[] c = vf.asRdbmsResource(ctxs);
      flush();
      SqlQueryBuilder query = buildSelectQuery(s, p, o, includeInferred, c);
      if (query == null)
        return new EmptyRdbmsStatementIteration();
      List<?> parameters = query.findParameters(new ArrayList<Object>());
      PreparedStatement stmt = conn.prepareStatement(query.toString());
      try {
        for (int i = 0, n = parameters.size(); i < n; i++) {
          stmt.setObject(i + 1, parameters.get(i));
        }
        return new RdbmsStatementIteration(vf, stmt, ids);
View Full Code Here

  private String buildContextQuery() throws SQLException {
    if (statements.isEmpty())
      return null;
    String tableName = statements.getCombinedTableName();
    SqlQueryBuilder query = factory.createSqlQueryBuilder();
    query.select().column("t", "ctx");
    query
        .select()
        .append(
            "CASE WHEN MIN(u.value) IS NOT NULL THEN MIN(u.value) ELSE MIN(b.value) END");
    SqlJoinBuilder join = query.from(tableName, "t");
    join.leftjoin(bnodes.getName(), "b").on("id", "t.ctx");
    join.leftjoin(uris.getShortTableName(), "u").on("id", "t.ctx");
    SqlBracketBuilder open = query.filter().and().open();
    open.column("u", "value").isNotNull();
    open.or();
    open.column("b", "value").isNotNull();
    open.close();
    query.groupBy("t.ctx");
    return query.toString();
  }
View Full Code Here

 
    if (obj != null)
      objId = vf.getInternalId(obj);
   
    String tableName = statements.getTableName(vf.getInternalId(pred), subjId, objId, ctxIds);
    SqlQueryBuilder query = factory.createSqlQueryBuilder();
    query.select().column("t", "ctx");
    query.select().append("CASE WHEN cu.value IS NOT NULL THEN cu.value WHEN clu.value IS NOT NULL THEN clu.value ELSE cb.value END");
    query.select().column("t", "subj");
    query.select().append("CASE WHEN su.value IS NOT NULL THEN su.value WHEN slu.value IS NOT NULL THEN slu.value ELSE sb.value END");
    query.select().column("pu", "id");
    query.select().column("pu", "value");
    query.select().column("t", "obj");
    query.select().append("CASE WHEN ou.value IS NOT NULL THEN ou.value" +
        " WHEN olu.value IS NOT NULL THEN olu.value" +
        " WHEN ob.value IS NOT NULL THEN ob.value" +
        " WHEN ol.value IS NOT NULL THEN ol.value ELSE oll.value END");
    query.select().column("od", "value");
    query.select().column("og", "value");
    query.select().column("t", "expl");
    SqlJoinBuilder join;
    if (pred != null) {
      join = query.from(uris.getShortTableName(), "pu");
      // TODO what about long predicate URIs?
      join = join.join(tableName, "t");
    } else {
      join = query.from(tableName, "t");
    }
    if (pred == null) {
      join.join(uris.getShortTableName(), "pu").on("id", "t.pred");
    }
    join.leftjoin(uris.getShortTableName(), "cu").on("id", "t.ctx");
    join.leftjoin(uris.getLongTableName(), "clu").on("id", "t.ctx");
    join.leftjoin(bnodes.getName(), "cb").on("id", "t.ctx");
    join.leftjoin(uris.getShortTableName(), "su").on("id", "t.subj");
    join.leftjoin(uris.getLongTableName(), "slu").on("id", "t.subj");
    join.leftjoin(bnodes.getName(), "sb").on("id", "t.subj");
    join.leftjoin(uris.getShortTableName(), "ou").on("id", "t.obj");
    join.leftjoin(uris.getLongTableName(), "olu").on("id", "t.obj");
    join.leftjoin(bnodes.getName(), "ob").on("id", "t.obj");
    join.leftjoin(literals.getLabelTable().getName(), "ol").on("id", "t.obj");
    join.leftjoin(literals.getLongLabelTable().getName(), "oll").on("id", "t.obj");
    join.leftjoin(literals.getLanguageTable().getName(), "og").on("id", "t.obj");
    join.leftjoin(literals.getDatatypeTable().getName(), "od").on("id", "t.obj");
    if (ctxIds != null) {
      query.filter().and().columnIn("t", "ctx", ctxIds);
    }
    if (subjId != null) {
      query.filter().and().columnEquals("t", "subj", subjId);
    }
    if (pred != null) {
      Number id = vf.getInternalId(pred);
      query.filter().and().columnEquals("pu", "id", id);
      if (statements.isPredColumnPresent(id)) {
        query.filter().and().columnEquals("t", "pred", id);
      }
    }
    if (objId != null) {
      query.filter().and().columnEquals("t", "obj", objId);
    }
    if (!includeInferred) {
      query.filter().and().columnEquals("t", "expl", new Boolean(true));
    }
    return query;
  }
View Full Code Here

TOP

Related Classes of org.openrdf.sail.rdbms.evaluation.SqlQueryBuilder

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.