Search in sources :

Example 1 with TerminationException

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);
    }
}
Also used : TerminationException(jena.cmd.TerminationException) SDBException(org.apache.jena.sdb.SDBException) NotFoundException(org.apache.jena.shared.NotFoundException)

Example 2 with TerminationException

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);
    }
}
Also used : TerminationException(jena.cmd.TerminationException) SQLException(java.sql.SQLException) ResultSetJDBC(org.apache.jena.sdb.sql.ResultSetJDBC)

Example 3 with TerminationException

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);
    }
}
Also used : CmdException(jena.cmd.CmdException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) RiotException(org.apache.jena.riot.RiotException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) CmdException(jena.cmd.CmdException) TerminationException(jena.cmd.TerminationException) JenaException(org.apache.jena.shared.JenaException) RiotNotFoundException(org.apache.jena.riot.RiotNotFoundException) IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) JenaException(org.apache.jena.shared.JenaException) TerminationException(jena.cmd.TerminationException) ResultSetException(org.apache.jena.sparql.resultset.ResultSetException) TransactionalNull(org.apache.jena.sparql.core.TransactionalNull) Transactional(org.apache.jena.sparql.core.Transactional)

Example 4 with TerminationException

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);
    }
}
Also used : TerminationException(jena.cmd.TerminationException) ARQInternalErrorException(org.apache.jena.sparql.ARQInternalErrorException) ResultSet(org.apache.jena.query.ResultSet) NotFoundException(org.apache.jena.shared.NotFoundException)

Example 5 with TerminationException

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));
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) PlanOp(org.apache.jena.sparql.engine.PlanOp) Op(org.apache.jena.sparql.algebra.Op) TerminationException(jena.cmd.TerminationException) QueryIterator(org.apache.jena.sparql.engine.QueryIterator) ModDataset(arq.cmdline.ModDataset) Dataset(org.apache.jena.query.Dataset) PlanOp(org.apache.jena.sparql.engine.PlanOp) Plan(org.apache.jena.sparql.engine.Plan) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Aggregations

TerminationException (jena.cmd.TerminationException)8 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)3 CmdException (jena.cmd.CmdException)2 NotFoundException (org.apache.jena.shared.NotFoundException)2 PrefixMapping (org.apache.jena.shared.PrefixMapping)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 ModDataset (arq.cmdline.ModDataset)1 SQLException (java.sql.SQLException)1 ArgDecl (jena.cmd.ArgDecl)1 CmdLineArgs (jena.cmd.CmdLineArgs)1 Node (org.apache.jena.graph.Node)1 Dataset (org.apache.jena.query.Dataset)1 QueryParseException (org.apache.jena.query.QueryParseException)1 ResultSet (org.apache.jena.query.ResultSet)1 Model (org.apache.jena.rdf.model.Model)1 RiotException (org.apache.jena.riot.RiotException)1 RiotNotFoundException (org.apache.jena.riot.RiotNotFoundException)1 SDBException (org.apache.jena.sdb.SDBException)1 ResultSetJDBC (org.apache.jena.sdb.sql.ResultSetJDBC)1 JenaException (org.apache.jena.shared.JenaException)1