use of org.apache.jena.sdb.sql.ResultSetJDBC in project jena by apache.
the class sdbsql method execOneSQL.
private void execOneSQL(String sqlStmt) {
if (isVerbose()) {
System.out.print(sqlStmt);
if (!sqlStmt.endsWith("\n"))
System.out.println();
}
if (sqlStmt.startsWith("@"))
sqlStmt = FileManager.get().readWholeFileAsUTF8(sqlStmt.substring(1));
getModTime().startTimer();
long queryTime = 0;
ResultSetJDBC rs = null;
try {
rs = getModStore().getConnection().exec(sqlStmt);
queryTime = getModTime().readTimer();
if (rs == null)
System.out.println("Executed with no errors or results");
else {
if (isQuiet())
RS.consume(rs.get());
else
RS.printResultSet(rs.get());
}
} catch (SQLException ex) {
System.err.println("SQL Exception: " + ex.getMessage());
throw new TerminationException(9);
} finally {
RS.close(rs);
}
long time = getModTime().endTimer();
long fmtTime = time - queryTime;
if (getModTime().timingEnabled()) {
String totalTimeStr = getModTime().timeStr(time);
String queryTimeStr = getModTime().timeStr(queryTime);
String fmtTimeStr = getModTime().timeStr(fmtTime);
System.out.printf("Query: %s (query %s, formatting %s)\n", totalTimeStr, queryTimeStr, fmtTimeStr);
}
}
use of org.apache.jena.sdb.sql.ResultSetJDBC in project jena by apache.
the class TupleTable method getDesc.
private static TableDesc getDesc(Store store, String tableName) {
ResultSetJDBC tableData = null;
List<String> colVars = new ArrayList<String>();
try {
// Need to portable get the column names.
tableData = store.getConnection().execQuery("SELECT * FROM " + tableName);
java.sql.ResultSetMetaData meta = tableData.get().getMetaData();
int N = meta.getColumnCount();
for (int i = 1; i <= N; i++) {
String colName = meta.getColumnName(i);
colVars.add(colName);
}
return new TableDesc(tableName, colVars);
} catch (SQLException ex) {
throw new SDBExceptionSQL(ex);
} finally {
RS.close(tableData);
}
}
use of org.apache.jena.sdb.sql.ResultSetJDBC in project jena by apache.
the class TupleTable method iterator.
public QueryIterator iterator() {
SDBRequest request = new SDBRequest(store, null);
String tableName = desc.getTableName();
SQLBridge b = store.getSQLBridgeFactory().create(request, sqlTable, vars);
b.build();
try {
String sqlStr = store.getSQLGenerator().generateSQL(request, b.getSqlNode());
//System.out.println(sqlStr) ;
ResultSetJDBC tableData = store.getConnection().execQuery(sqlStr);
ExecutionContext execCxt = new ExecutionContext(new Context(), null, null, null);
return b.assembleResults(tableData, BindingRoot.create(), execCxt);
} catch (SQLException ex) {
throw new SDBExceptionSQL(ex);
}
}
use of org.apache.jena.sdb.sql.ResultSetJDBC in project jena by apache.
the class TupleLoaderOneHash method insertNode.
@Override
public SqlConstant insertNode(Node node) throws SQLException {
int typeId = NodeLayout2.nodeToType(node);
String lex = NodeLayout2.nodeToLex(node);
String lang = "";
String datatype = "";
if (node.isLiteral()) {
lang = node.getLiteralLanguage();
datatype = node.getLiteralDatatypeURI();
if (NodeUtils.isSimpleString(node) || NodeUtils.isLangString(node))
datatype = "";
}
long hash = NodeLayout2.hash(lex, lang, datatype, typeId);
// Existance check
String sqlStmtTest = strjoinNL("SELECT hash FROM " + TableDescNodes.name(), "WHERE hash = " + hash);
ResultSetJDBC rsx = null;
try {
rsx = connection().execQuery(sqlStmtTest);
ResultSet rs = rsx.get();
boolean b = rs.next();
if (b)
// Exists
return new SqlConstant(hash);
} finally {
RS.close(rsx);
}
String sqlStmt = strjoinNL("INSERT INTO " + TableDescNodes.name() + "(hash,lex,lang,datatype,type) VALUES", " (" + hash + ", ", " " + SQLUtils.quoteStr(lex) + ", ", " " + SQLUtils.quoteStr(lang) + ", ", " " + SQLUtils.quoteStr(datatype) + ", ", " " + typeId, ")");
connection().execUpdate(sqlStmt);
return new SqlConstant(hash);
}
use of org.apache.jena.sdb.sql.ResultSetJDBC in project jena by apache.
the class SDB_QC method exec.
// ---- Execute an OpSQL.
public static QueryIterator exec(OpSQL opSQL, SDBRequest request, Binding binding, ExecutionContext execCxt) {
String sqlStmtStr = toSqlString(opSQL, request);
if (PrintSQL)
System.out.println(sqlStmtStr);
String str = null;
if (execCxt != null)
str = execCxt.getContext().getAsString(SDB.jdbcFetchSize);
int fetchSize = SDBConstants.jdbcFetchSizeOff;
if (str != null)
try {
fetchSize = Integer.parseInt(str);
} catch (NumberFormatException ex) {
log.warn("Bad number for fetch size: " + str);
}
try {
ResultSetJDBC jdbcResultSet = request.getStore().getConnection().execQuery(sqlStmtStr, fetchSize);
try {
// And check this is called once per SQL.
if (opSQL.getBridge() == null)
log.error("Null bridge");
return opSQL.getBridge().assembleResults(jdbcResultSet, binding, execCxt);
} finally {
// ResultSet closed inside assembleResults or by the iterator returned.
jdbcResultSet = null;
}
} catch (SQLException ex) {
throw new SDBExceptionSQL("SQLException in executing SQL statement", ex);
}
}
Aggregations