use of jena.cmd.TerminationException in project jena by apache.
the class ModStore method processArgs.
@Override
public void processArgs(CmdArgModule cmdLine) {
if (!cmdLine.contains(argDeclSDBdesc)) {
System.err.println("No store description");
throw new TerminationException(1);
}
String f = cmdLine.getArg(argDeclSDBdesc).getValue();
try {
storeDesc = StoreDesc.read(f);
if (storeDesc.getLayout() == null) {
System.err.println("No layout or unrecognized layout");
throw new TerminationException(1);
}
} catch (SDBException ex) {
System.err.println("Failed to read the store description");
System.err.println(ex.getMessage());
throw new TerminationException(1);
} catch (NotFoundException ex) {
System.err.println(f + " : Store description not found");
throw new TerminationException(1);
}
// Overrides.
if (cmdLine.contains(argDeclDbHost))
storeDesc.connDesc.setHost(cmdLine.getArg(argDeclDbHost).getValue());
if (cmdLine.contains(argDeclDbName))
storeDesc.connDesc.setName(cmdLine.getArg(argDeclDbName).getValue());
if (cmdLine.contains(argDeclDbType))
storeDesc.connDesc.setType(cmdLine.getArg(argDeclDbType).getValue());
if (cmdLine.contains(argDeclDbUser))
storeDesc.connDesc.setUser(cmdLine.getArg(argDeclDbUser).getValue());
if (cmdLine.contains(argDeclDbPassword))
storeDesc.connDesc.setPassword(cmdLine.getArg(argDeclDbPassword).getValue());
if (cmdLine.contains(argDeclMySQLEngine))
storeDesc.engineType = MySQLEngineType.convert(cmdLine.getArg(argDeclMySQLEngine).getValue());
if (cmdLine.contains(argDeclSAPStorage))
storeDesc.storageType = SAPStorageType.convert(cmdLine.getArg(argDeclSAPStorage).getValue());
if (cmdLine.contains(argDeclLayout)) {
String layoutName = cmdLine.getArg(argDeclLayout).getValue();
storeDesc.setLayout(LayoutType.fetch(layoutName));
if (storeDesc.getLayout() == null) {
System.err.println("Don't recognize layout name '" + layoutName + "'");
throw new TerminationException(2);
}
}
if (false) {
//System.out.println("URL = " + storeDesc.connDesc.URL);
System.out.println("Type = " + storeDesc.connDesc.getType());
System.out.println("Host = " + storeDesc.connDesc.getHost());
System.out.println("Database = " + storeDesc.connDesc.getName());
System.out.println("User = " + storeDesc.connDesc.getUser());
System.out.println("Password = " + storeDesc.connDesc.getPassword());
// if ( storeDesc.connDesc.getArgStr() != null )
// System.out.println("Args = " + storeDesc.connDesc.getArgStr());
System.out.println("Layout = " + storeDesc.getLayout().getName());
//System.out.println("Name = " + argModelName);
SDBConnection.logSQLExceptions = true;
SDBConnection.logSQLStatements = true;
}
if (cmdLine.contains(argDeclJdbcDriver)) {
String driverName = cmdLine.getArg(argDeclJdbcDriver).getValue();
storeDesc.connDesc.setDriver(driverName);
}
}
use of jena.cmd.TerminationException 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 jena.cmd.TerminationException in project jena by apache.
the class query method queryExec.
protected void queryExec(boolean timed, ResultsFormat fmt) {
try {
Query query = modQuery.getQuery();
if (isVerbose()) {
IndentedWriter out = new IndentedWriter(System.out, true);
query.serialize(out);
out.flush();
System.out.println();
}
if (isQuiet())
LogCtl.setError(SysRIOT.riotLoggerName);
Dataset dataset = getDataset(query);
// The default policy is to create an empty one - convenience for VALUES and BIND providing the data.
if (dataset == null && !query.hasDatasetDescription()) {
System.err.println("Dataset not specified in query nor provided on command line.");
throw new TerminationException(1);
}
Transactional transactional = (dataset != null && dataset.supportsTransactionAbort()) ? dataset : new TransactionalNull();
Txn.executeRead(transactional, () -> {
modTime.startTimer();
try (QueryExecution qe = QueryExecutionFactory.create(query, dataset)) {
try {
QueryExecUtils.executeQuery(query, qe, fmt);
} catch (QueryCancelledException ex) {
System.out.flush();
System.err.println("Query timed out");
}
long time = modTime.endTimer();
if (timed) {
totalTime += time;
System.err.println("Time: " + modTime.timeStr(time) + " sec");
}
} catch (ResultSetException ex) {
System.err.println(ex.getMessage());
ex.printStackTrace(System.err);
} catch (QueryException qEx) {
// System.err.println(qEx.getMessage()) ;
throw new CmdException("Query Exeception", qEx);
}
});
} catch (ARQInternalErrorException intEx) {
System.err.println(intEx.getMessage());
if (intEx.getCause() != null) {
System.err.println("Cause:");
intEx.getCause().printStackTrace(System.err);
System.err.println();
}
intEx.printStackTrace(System.err);
} catch (JenaException | CmdException ex) {
throw ex;
} catch (Exception ex) {
throw new CmdException("Exception", ex);
}
}
use of jena.cmd.TerminationException in project jena by apache.
the class ModResultsIn method getResultSet.
public ResultSet getResultSet() {
if (resultSet != null)
return resultSet;
if (resultsFilename == null) {
System.err.println("No result file name");
throw new TerminationException(1);
}
try {
if (resultsFilename.equals("-"))
return ResultSetFactory.load(System.in, inputFormat);
ResultSet rs = ResultSetFactory.load(resultsFilename, inputFormat);
if (rs == null) {
System.err.println("Failed to read the result set");
throw new TerminationException(9);
}
resultSet = rs;
return resultSet;
} catch (NotFoundException ex) {
System.err.println("File not found: " + resultsFilename);
throw new TerminationException(9);
} catch (ARQInternalErrorException intEx) {
System.err.println(intEx.getMessage());
if (intEx.getCause() != null) {
System.err.println("Cause:");
intEx.getCause().printStackTrace(System.err);
System.err.println();
}
intEx.printStackTrace(System.err);
throw new TerminationException(99);
}
}
use of jena.cmd.TerminationException in project jena by apache.
the class sse_query method exec.
@Override
protected void exec() {
Op op = modAlgebra.getOp();
if (op == null) {
System.err.println("No query expression to execute");
throw new TerminationException(9);
}
Dataset dataset = modDataset.getDataset();
// Check there is a dataset.
if (dataset == null)
dataset = DatasetFactory.createGeneral();
modTime.startTimer();
DatasetGraph dsg = dataset.asDatasetGraph();
if (printOp || printPlan) {
if (printOp) {
divider();
IndentedWriter out = new IndentedWriter(System.out, true);
op.output(out);
out.flush();
}
if (printPlan) {
QueryIterator qIter = Algebra.exec(op, dsg);
Plan plan = new PlanOp(op, null, qIter);
divider();
IndentedWriter out = new IndentedWriter(System.out, false);
plan.output(out);
out.flush();
}
//return ;
}
// Do not optimize. Execute as-is.
QueryExecUtils.execute(op, dsg, modResults.getResultsFormat());
long time = modTime.endTimer();
if (modTime.timingEnabled())
System.out.println("Time: " + modTime.timeStr(time));
}
Aggregations