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;
}
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);
}
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);
}
}
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);
}
}
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();
}
}
Aggregations