Search in sources :

Example 26 with CmdException

use of jena.cmd.CmdException in project jena by apache.

the class rsparql method exec.

@Override
protected void exec() {
    Query query = modQuery.getQuery();
    try {
        String serviceURL = modRemote.getServiceURL();
        QueryExecution qe = QueryExecutionFactory.sparqlService(serviceURL, query);
        if (modRemote.usePost())
            HttpQuery.urlLimit = 0;
        QueryExecUtils.executeQuery(query, qe, modResults.getResultsFormat());
    } catch (QueryExceptionHTTP ex) {
        throw new CmdException("HTTP Exeception", ex);
    } catch (Exception ex) {
        System.out.flush();
        ex.printStackTrace(System.err);
    }
}
Also used : HttpQuery(org.apache.jena.sparql.engine.http.HttpQuery) Query(org.apache.jena.query.Query) CmdException(jena.cmd.CmdException) QueryExceptionHTTP(org.apache.jena.sparql.engine.http.QueryExceptionHTTP) QueryExecution(org.apache.jena.query.QueryExecution) CmdException(jena.cmd.CmdException)

Example 27 with CmdException

use of jena.cmd.CmdException in project jena by apache.

the class tdbloader method exec.

@Override
protected void exec() {
    if (isVerbose()) {
        System.out.println("Java maximum memory: " + Runtime.getRuntime().maxMemory());
        System.out.println(ARQ.getContext());
    }
    if (isVerbose())
        showProgress = true;
    if (isQuiet())
        showProgress = false;
    if (super.contains(argStats)) {
        if (!hasValueOfTrue(argStats) && !hasValueOfFalse(argStats))
            throw new CmdException("Not a boolean value: " + getValue(argStats));
        generateStats = super.hasValueOfTrue(argStats);
    }
    if (super.contains(argNoStats))
        generateStats = false;
    List<String> urls = getPositional();
    if (urls.size() == 0)
        urls.add("-");
    if (graphName == null) {
        loadQuads(urls);
        return;
    }
    for (String url : urls) {
        Lang lang = RDFLanguages.filenameToLang(url);
        if (lang != null && RDFLanguages.isQuads(lang)) {
            System.err.println("Warning: Quads format given - only the default graph is loaded into the graph for --graph");
            break;
        }
    }
    loadNamedGraph(urls);
}
Also used : CmdException(jena.cmd.CmdException) Lang(org.apache.jena.riot.Lang)

Example 28 with CmdException

use of jena.cmd.CmdException in project jena by apache.

the class spatialindexer method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    super.processModulesAndArgs();
    // Two forms : with and without arg.
    // Maximises similarity with other tools.
    String file;
    if (super.contains(assemblerDescDecl)) {
        if (getValues(assemblerDescDecl).size() != 1)
            throw new CmdException("Multiple assembler descriptions given");
        if (getPositional().size() != 0)
            throw new CmdException("Additional assembler descriptions given");
        file = getValue(assemblerDescDecl);
    } else {
        if (getNumPositional() != 1)
            throw new CmdException("Multiple assembler descriptions given");
        file = getPositionalArg(0);
    }
    if (file == null)
        throw new CmdException("No dataset specified");
    // Assumes a single test daatset description in the assembler file.
    Dataset ds = SpatialDatasetFactory.create(file);
    if (ds == null)
        throw new CmdException("No dataset description found");
    // get index.
    dataset = (DatasetGraphSpatial) (ds.asDatasetGraph());
    spatialIndex = dataset.getSpatialIndex();
    if (spatialIndex == null)
        throw new CmdException("Dataset has no spatial index");
    context = new SpatialIndexContext(spatialIndex);
}
Also used : CmdException(jena.cmd.CmdException) Dataset(org.apache.jena.query.Dataset) SpatialIndexContext(org.apache.jena.query.spatial.SpatialIndexContext)

Example 29 with CmdException

use of jena.cmd.CmdException in project jena by apache.

the class load method execUpdate.

@Override
protected void execUpdate(DatasetGraph graphStore) {
    if (loadFiles.size() == 0)
        throw new CmdException("Nothing to do");
    UpdateRequest req = new UpdateRequest();
    for (String filename : loadFiles) {
        UpdateLoad loadReq = new UpdateLoad(filename, graphName);
        req.add(loadReq);
    }
    if (true) {
        // Need a better way
        monitor(graphStore.getDefaultGraph());
        for (Iterator<Node> iter = graphStore.listGraphNodes(); iter.hasNext(); ) {
            Graph g = graphStore.getGraph(iter.next());
            monitor(g);
        }
    }
    UpdateExecutionFactory.create(req, graphStore).execute();
    if (dump) {
        IndentedWriter out = IndentedWriter.stdout;
        SSE.write(graphStore);
        out.flush();
    }
}
Also used : IndentedWriter(org.apache.jena.atlas.io.IndentedWriter) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph) Graph(org.apache.jena.graph.Graph) CmdException(jena.cmd.CmdException) UpdateRequest(org.apache.jena.update.UpdateRequest) UpdateLoad(org.apache.jena.sparql.modify.request.UpdateLoad) Node(org.apache.jena.graph.Node)

Example 30 with CmdException

use of jena.cmd.CmdException in project jena by apache.

the class qexpr method main2.

public static void main2(String... argv) {
    CmdLineArgs cl = new CmdLineArgs(argv);
    ArgDecl helpDecl = new ArgDecl(ArgDecl.NoValue, "h", "help");
    cl.add(helpDecl);
    ArgDecl verboseDecl = new ArgDecl(ArgDecl.NoValue, "v", "verbose");
    cl.add(verboseDecl);
    ArgDecl versionDecl = new ArgDecl(ArgDecl.NoValue, "ver", "version", "V");
    cl.add(versionDecl);
    ArgDecl quietDecl = new ArgDecl(ArgDecl.NoValue, "q", "quiet");
    cl.add(quietDecl);
    ArgDecl reduceDecl = new ArgDecl(ArgDecl.NoValue, "reduce", "fold", "simplify");
    cl.add(reduceDecl);
    ArgDecl strictDecl = new ArgDecl(ArgDecl.NoValue, "strict");
    cl.add(strictDecl);
    ArgDecl printDecl = new ArgDecl(ArgDecl.HasValue, "print");
    cl.add(printDecl);
    try {
        cl.process();
    } catch (IllegalArgumentException ex) {
        System.err.println(ex.getMessage());
        usage(System.err);
        throw new CmdException();
    }
    if (cl.contains(helpDecl)) {
        usage();
        throw new TerminationException(0);
    }
    if (cl.contains(versionDecl)) {
        System.out.println("ARQ Version: " + ARQ.VERSION + " (Jena: " + Jena.VERSION + ")");
        throw new TerminationException(0);
    }
    // ==== General things
    boolean verbose = cl.contains(verboseDecl);
    boolean quiet = cl.contains(quietDecl);
    if (cl.contains(strictDecl))
        ARQ.setStrictMode();
    boolean actionCopySubstitute = cl.contains(reduceDecl);
    boolean actionPrintPrefix = false;
    boolean actionPrintSPARQL = false;
    boolean actionPrint = cl.contains(printDecl);
    for (String v : cl.getValues(printDecl)) {
        if (v.equalsIgnoreCase("prefix") || v.equalsIgnoreCase("op")) {
            actionPrintPrefix = true;
        } else if (v.equalsIgnoreCase("expr")) {
            actionPrintSPARQL = true;
        } else {
            System.err.println("Unknown print form: " + v);
            throw new TerminationException(0);
        }
    }
    for (int i = 0; i < cl.getNumPositional(); i++) {
        String exprStr = cl.getPositionalArg(i);
        exprStr = cl.indirect(exprStr);
        try {
            PrefixMapping pmap = PrefixMapping.Factory.create();
            pmap.setNsPrefixes(ARQConstants.getGlobalPrefixMap());
            pmap.setNsPrefix("", "http://example/");
            pmap.setNsPrefix("ex", "http://example/ns#");
            //              Node n = asNode() ;
            //              return makeNode(n) ;
            Expr expr = ExprUtils.parse(exprStr, pmap);
            if (verbose)
                System.out.print(expr.toString() + " => ");
            if (actionPrint) {
                if (actionPrintSPARQL)
                    System.out.println(ExprUtils.fmtSPARQL(expr));
                if (actionPrintPrefix)
                    WriterSSE.out(IndentedWriter.stdout, expr, new Prologue(pmap));
                continue;
            }
            try {
                if (actionCopySubstitute) {
                    Expr e = ExprLib.foldConstants(expr);
                    System.out.println(e);
                } else {
                    // Default action
                    ARQ.getContext().set(ARQConstants.sysCurrentTime, NodeFactoryExtra.nowAsDateTime());
                    FunctionEnv env = new ExecutionContext(ARQ.getContext(), null, null, null);
                    NodeValue r = expr.eval(null, env);
                    //System.out.println(r.asQuotedString()) ;
                    Node n = r.asNode();
                    String s = NodeFmtLib.displayStr(n);
                    System.out.println(s);
                }
            } catch (ExprEvalException ex) {
                System.out.println("Exception: " + ex.getMessage());
                throw new TerminationException(2);
            }
        } catch (QueryParseException ex) {
            System.err.println("Parse error: " + ex.getMessage());
            throw new TerminationException(2);
        }
    }
}
Also used : NodeValue(org.apache.jena.sparql.expr.NodeValue) CmdException(jena.cmd.CmdException) Node(org.apache.jena.graph.Node) ArgDecl(jena.cmd.ArgDecl) CmdLineArgs(jena.cmd.CmdLineArgs) QueryParseException(org.apache.jena.query.QueryParseException) FunctionEnv(org.apache.jena.sparql.function.FunctionEnv) PrefixMapping(org.apache.jena.shared.PrefixMapping) TerminationException(jena.cmd.TerminationException) Prologue(org.apache.jena.sparql.core.Prologue) ExecutionContext(org.apache.jena.sparql.engine.ExecutionContext) Expr(org.apache.jena.sparql.expr.Expr) ExprEvalException(org.apache.jena.sparql.expr.ExprEvalException)

Aggregations

CmdException (jena.cmd.CmdException)32 Lang (org.apache.jena.riot.Lang)8 Dataset (org.apache.jena.query.Dataset)6 Node (org.apache.jena.graph.Node)3 Model (org.apache.jena.rdf.model.Model)3 JenaException (org.apache.jena.shared.JenaException)3 DatasetGraph (org.apache.jena.sparql.core.DatasetGraph)3 ArgDecl (jena.cmd.ArgDecl)2 TerminationException (jena.cmd.TerminationException)2 IndentedWriter (org.apache.jena.atlas.io.IndentedWriter)2 Graph (org.apache.jena.graph.Graph)2 RiotException (org.apache.jena.riot.RiotException)2 PrefixMapping (org.apache.jena.shared.PrefixMapping)2 ARQInternalErrorException (org.apache.jena.sparql.ARQInternalErrorException)2 Transactional (org.apache.jena.sparql.core.Transactional)2 TransactionalNull (org.apache.jena.sparql.core.TransactionalNull)2 ResultSetException (org.apache.jena.sparql.resultset.ResultSetException)2 UpdateRequest (org.apache.jena.update.UpdateRequest)2 ModDataset (arq.cmdline.ModDataset)1 IOException (java.io.IOException)1