Search in sources :

Example 6 with CmdException

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

the class textindexdump 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);
    }
    textIndex = (TextIndex) AssemblerUtils.build(file, TextVocab.textIndex);
}
Also used : CmdException(jena.cmd.CmdException)

Example 7 with CmdException

use of jena.cmd.CmdException 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 8 with CmdException

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

the class ModLangOutput method processArgs.

@Override
public void processArgs(CmdArgModule cmdLine) {
    if (cmdLine.contains(argPretty)) {
        String langName = cmdLine.getValue(argPretty);
        Lang lang = RDFLanguages.nameToLang(langName);
        if (lang == null)
            throw new CmdException("Not recognized as an RDF language : '" + langName + "'");
        formattedOutput = RDFWriterRegistry.defaultSerialization(lang);
        if (formattedOutput == null) {
            System.err.println("Language '" + lang.getLabel() + "' not registered.");
            printRegistered(System.err);
            throw new CmdException("No output set: '" + langName + "'");
        }
    }
    if (cmdLine.contains(argStream)) {
        String langName = cmdLine.getValue(argStream);
        Lang lang = RDFLanguages.nameToLang(langName);
        if (lang == null)
            throw new CmdException("Not recognized as an RDF language : '" + langName + "'");
        streamOutput = StreamRDFWriter.defaultSerialization(lang);
        if (streamOutput == null) {
            System.err.println("Language '" + lang.getLabel() + "' not registered for streaming.");
            printRegistered(System.err);
            throw new CmdException("No output set: '" + langName + "'");
        }
    }
    if (cmdLine.contains(argOutput)) {
        String langName = cmdLine.getValue(argOutput);
        Lang lang = RDFLanguages.nameToLang(langName);
        if (lang == null)
            throw new CmdException("Not recognized as an RDF language : '" + langName + "'");
        if (StreamRDFWriter.registered(lang)) {
            streamOutput = StreamRDFWriter.defaultSerialization(lang);
        } else {
            formattedOutput = RDFWriterRegistry.defaultSerialization(lang);
            if (formattedOutput == null) {
                System.err.println("Language '" + lang.getLabel() + "' not recognized.");
                printRegistered(System.err);
                throw new CmdException("No output set: '" + langName + "'");
            }
        }
    }
    if (cmdLine.contains(argCompress))
        compressedOutput = true;
    if (streamOutput == null && formattedOutput == null)
        streamOutput = RDFFormat.NQUADS;
}
Also used : CmdException(jena.cmd.CmdException) Lang(org.apache.jena.riot.Lang)

Example 9 with CmdException

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

the class load method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    if (containsMultiple(graphNameArg))
        throw new CmdException("At most one --graph allowed");
    graphName = getValue(graphNameArg);
    loadFiles = super.getPositional();
    dump = contains(dumpArg);
    super.processModulesAndArgs();
}
Also used : CmdException(jena.cmd.CmdException)

Example 10 with CmdException

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

the class CmdNodeTableBuilder method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    if (!super.contains(argLocation))
        throw new CmdException("Required: --loc DIR");
    //        if ( !super.contains(argTriplesOut) ) throw new CmdException("Required: --triples FILE") ;
    //        if ( !super.contains(argQuadsOut) ) throw new CmdException("Required: --quads FILE") ;
    locationString = super.getValue(argLocation);
    location = Location.create(locationString);
    dataFileTriples = super.getValue(argTriplesOut);
    if (dataFileTriples == null)
        dataFileTriples = location.getPath("triples", "tmp");
    dataFileQuads = super.getValue(argQuadsOut);
    if (dataFileQuads == null)
        dataFileQuads = location.getPath("quads", "tmp");
    if (Objects.equals(dataFileTriples, dataFileQuads))
        cmdError("Triples and Quads work files are the same");
    if (super.contains(argNoStats))
        collectStats = false;
    //datafiles  = getPositionalOrStdin() ;
    datafiles = getPositional();
    if (datafiles.isEmpty())
        datafiles = Arrays.asList("-");
    // ---- Checking.
    for (String filename : datafiles) {
        Lang lang = RDFLanguages.filenameToLang(filename, RDFLanguages.NQUADS);
        if (lang == null)
            // Does not happen due to default above.
            cmdError("File suffix not recognized: " + filename);
        if (!filename.equals("-") && !FileOps.exists(filename))
            cmdError("File does not exist: " + filename);
    }
}
Also used : CmdException(jena.cmd.CmdException) Lang(org.apache.jena.riot.Lang)

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