Search in sources :

Example 6 with SDBException

use of org.apache.jena.sdb.SDBException in project jena by apache.

the class RegexSqlGen method compile.

@Override
public SqlExpr compile(Scope scope) {
    // TODO Convert regex to using a string value table?
    MapResult rMap = exprPattern.match(getExpr());
    if (rMap == null)
        throw new SDBException("Couldn't compile after all: " + getExpr());
    Var var = rMap.get(Var.alloc("a1")).getExprVar().asVar();
    String pattern = rMap.get(Var.alloc("a2")).getConstant().getString();
    if (!scope.hasColumnForVar(var)) {
        LoggerFactory.getLogger(this.getClass()).error("Variable '" + var + "' not in scope");
        return null;
    }
    SqlColumn vCol = scope.findScopeForVar(var).getColumn();
    // Ensure it's the lex column
    SqlColumn lexCol = new SqlColumn(vCol.getTable(), "lex");
    SqlColumn vTypeCol = new SqlColumn(vCol.getTable(), "type");
    // "is a string"
    SqlExpr isStr = new S_Equal(vTypeCol, new SqlConstant(ValueType.STRING.getTypeId()));
    isStr.addNote("is a string");
    // regex.
    SqlExpr sCond = new S_Regex(vCol, pattern, flags);
    sCond.addNote(getExpr().toString());
    SqlExpr sqlExpr = new S_And(isStr, sCond);
    return sqlExpr;
}
Also used : Var(org.apache.jena.sparql.core.Var) ActionMatchVar(org.apache.jena.sdb.exprmatch.ActionMatchVar) SDBException(org.apache.jena.sdb.SDBException) ActionMatchString(org.apache.jena.sdb.exprmatch.ActionMatchString) MapResult(org.apache.jena.sdb.exprmatch.MapResult)

Example 7 with SDBException

use of org.apache.jena.sdb.SDBException in project jena by apache.

the class StringEqualsSqlGen method compile.

@Override
public SqlExpr compile(Scope scope) {
    MapResult rMap = exprPattern.match(getExpr());
    if (rMap == null)
        throw new SDBException("Couldn't compile after all: " + getExpr());
    //log.info("equalsString - Matched: ?a1 = "+rMap.get("a1")+" : ?a2 = "+rMap.get("a2")) ;
    Var var = rMap.get("a1").getExprVar().asVar();
    String str = rMap.get("a2").getConstant().getString();
    if (!scope.hasColumnForVar(var)) {
        LoggerFactory.getLogger(this.getClass()).error("Variable '" + var + "' not in scope");
        return null;
    }
    SqlColumn vCol = scope.findScopeForVar(var).getColumn();
    SqlColumn lexCol = new SqlColumn(vCol.getTable(), "lex");
    SqlColumn vTypeCol = new SqlColumn(vCol.getTable(), "type");
    // "is a string"
    SqlExpr isStr = new S_Equal(vTypeCol, new SqlConstant(ValueType.STRING.getTypeId()));
    isStr.addNote("is a string");
    // Equality
    SqlExpr strEquals = new S_Equal(lexCol, new SqlConstant(str));
    isStr.addNote(getExpr().toString());
    return new S_And(isStr, strEquals);
}
Also used : Var(org.apache.jena.sparql.core.Var) ActionMatchVar(org.apache.jena.sdb.exprmatch.ActionMatchVar) SDBException(org.apache.jena.sdb.SDBException) ActionMatchString(org.apache.jena.sdb.exprmatch.ActionMatchString) MapResult(org.apache.jena.sdb.exprmatch.MapResult)

Example 8 with SDBException

use of org.apache.jena.sdb.SDBException in project jena by apache.

the class FormatterSimpleSAP method reformatPrefixesWorker.

private void reformatPrefixesWorker(boolean loadPrefixes) {
    try {
        dropTable("Prefixes");
        connection().exec(sqlStr("CREATE " + storageType.getStorageName() + " TABLE Prefixes (", "    prefix NVARCHAR(" + TablePrefixes.prefixColWidth + ") NOT NULL ,", "    uri NVARCHAR(" + TablePrefixes.uriColWidth + ") NOT NULL", ")"));
        connection().exec(sqlStr("ALTER TABLE Prefixes ADD PRIMARY KEY (prefix)"));
        if (loadPrefixes) {
            connection().execUpdate("INSERT INTO Prefixes VALUES ('x',       'http://example/')");
            connection().execUpdate("INSERT INTO Prefixes VALUES ('ex',      'http://example.org/')");
            connection().execUpdate("INSERT INTO Prefixes VALUES ('rdf',     'http://www.w3.org/1999/02/22-rdf-syntax-ns#')");
            connection().execUpdate("INSERT INTO Prefixes VALUES ('rdfs',    'http://www.w3.org/2000/01/rdf-schema#')");
            connection().execUpdate("INSERT INTO Prefixes VALUES ('xsd',     'http://www.w3.org/2001/XMLSchema#')");
            connection().execUpdate("INSERT INTO Prefixes VALUES ('owl' ,    'http://www.w3.org/2002/07/owl#')");
            connection().execUpdate("INSERT INTO Prefixes VALUES ('foaf',    'http://xmlns.com/foaf/0.1/')");
            connection().execUpdate("INSERT INTO Prefixes VALUES ('dc',      'http://purl.org/dc/elements/1.1/')");
            connection().execUpdate("INSERT INTO Prefixes VALUES ('dcterms', 'http://purl.org/dc/terms/')");
        }
    } catch (SQLException ex) {
        log.warn("Exception resetting table 'Prefixes'");
        throw new SDBException("SQLException resetting table 'Prefixes'", ex);
    }
}
Also used : SQLException(java.sql.SQLException) SDBException(org.apache.jena.sdb.SDBException)

Example 9 with SDBException

use of org.apache.jena.sdb.SDBException in project jena by apache.

the class FormatterSimpleSQLServer method reformatDataWorker.

private void reformatDataWorker() {
    try {
        dropTable("Triples");
        connection().exec(sqlStr("CREATE TABLE Triples", "(", "  s " + colDecl + " ,", "  p " + colDecl + " ,", "  o " + colDecl + " ,", "  PRIMARY KEY (s,p,o)", ")"));
    } catch (SQLException ex) {
        log.warn("Exception resetting table 'Triples'");
        throw new SDBException("SQLException resetting table 'Triples'", ex);
    }
}
Also used : SQLException(java.sql.SQLException) SDBException(org.apache.jena.sdb.SDBException)

Example 10 with SDBException

use of org.apache.jena.sdb.SDBException in project jena by apache.

the class LoaderTuplesNodes method flushTriples.

/**
	 * Flush remain triples in queue to database. If threading this blocks until flush is complete.
	 */
private void flushTriples() {
    if (threading) {
        if (!commitThread.isAlive())
            throw new SDBException("Thread has died");
        // finish up threaded load
        try {
            synchronized (threadFlushing) {
                queue.put(flushSignal);
                threadFlushing.wait();
            }
        } catch (InterruptedException e) {
            log.error("Problem sending flush signal: " + e.getMessage());
            throw new SDBException("Problem sending flush signal", e);
        }
        checkThreadStatus();
    } else {
        commitTuples();
    }
}
Also used : SDBException(org.apache.jena.sdb.SDBException)

Aggregations

SDBException (org.apache.jena.sdb.SDBException)38 SQLException (java.sql.SQLException)30 Resource (org.apache.jena.rdf.model.Resource)2 ActionMatchString (org.apache.jena.sdb.exprmatch.ActionMatchString)2 ActionMatchVar (org.apache.jena.sdb.exprmatch.ActionMatchVar)2 MapResult (org.apache.jena.sdb.exprmatch.MapResult)2 Var (org.apache.jena.sparql.core.Var)2 ResultSet (java.sql.ResultSet)1 TerminationException (jena.cmd.TerminationException)1 StoreDesc (org.apache.jena.sdb.StoreDesc)1 SDBRequest (org.apache.jena.sdb.core.SDBRequest)1 ResultSetJDBC (org.apache.jena.sdb.sql.ResultSetJDBC)1 SDBConnectionDesc (org.apache.jena.sdb.sql.SDBConnectionDesc)1 SDBExceptionSQL (org.apache.jena.sdb.sql.SDBExceptionSQL)1 Feature (org.apache.jena.sdb.store.Feature)1 FeatureSet (org.apache.jena.sdb.store.FeatureSet)1 TupleLoader (org.apache.jena.sdb.store.TupleLoader)1 NotFoundException (org.apache.jena.shared.NotFoundException)1 Op (org.apache.jena.sparql.algebra.Op)1 TransformFilterEquality (org.apache.jena.sparql.algebra.optimize.TransformFilterEquality)1