Search in sources :

Example 11 with CmdException

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

the class CmdSub method exec.

protected void exec() {
    Exec exec = dispatch.get(subCmd);
    if (exec == null)
        throw new CmdException("No subcommand: " + subCmd);
    exec.exec(args);
}
Also used : CmdException(jena.cmd.CmdException)

Example 12 with CmdException

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

the class uparse method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    requestFiles = getValues(fileArg);
    super.processModulesAndArgs();
    if (super.cmdStrictMode)
        updateSyntax = Syntax.syntaxSPARQL_11;
    // Set syntax
    if (super.contains(syntaxArg)) {
        // short name
        String s = super.getValue(syntaxArg);
        Syntax syn = Syntax.lookup(s);
        if (syn == null)
            super.cmdError("Unrecognized syntax: " + s);
        updateSyntax = syn;
    }
    for (String arg : getValues(argDeclPrint)) {
        if (arg.equalsIgnoreCase("query"))
            printUpdate = true;
        else if (arg.equalsIgnoreCase("none"))
            printNone = true;
        else
            throw new CmdException("Not a recognized print form: " + arg + " : Choices are: update, none");
    }
    if (!printUpdate && !printNone)
        printUpdate = true;
}
Also used : CmdException(jena.cmd.CmdException) Syntax(org.apache.jena.query.Syntax)

Example 13 with CmdException

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

the class update method execUpdate.

// Subclass for specialised commands making common updates more convenient
@Override
protected void execUpdate(DatasetGraph graphStore) {
    if (requestFiles.size() == 0 && getPositional().size() == 0)
        throw new CmdException("Nothing to do");
    Transactional transactional = (graphStore.supportsTransactionAbort()) ? graphStore : new TransactionalNull();
    for (String filename : requestFiles) {
        try {
            transactional.begin(ReadWrite.WRITE);
            execOneFile(filename, graphStore);
            transactional.commit();
        } catch (Throwable ex) {
            try {
                transactional.abort();
            } catch (Exception ex2) {
            }
            throw ex;
        } finally {
            transactional.end();
        }
    }
    for (String requestString : super.getPositional()) {
        String requestString2 = indirect(requestString);
        Txn.executeWrite(transactional, () -> execOne(requestString2, graphStore));
    }
    if (!(transactional instanceof DatasetGraph))
        SystemARQ.sync(graphStore);
    if (dump)
        RDFDataMgr.write(System.out, graphStore, Lang.NQUADS);
}
Also used : TransactionalNull(org.apache.jena.sparql.core.TransactionalNull) CmdException(jena.cmd.CmdException) CmdException(jena.cmd.CmdException) Transactional(org.apache.jena.sparql.core.Transactional) DatasetGraph(org.apache.jena.sparql.core.DatasetGraph)

Example 14 with CmdException

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

the class rupdate method exec.

@Override
protected void exec() {
    if (modRemote.getServiceURL() == null) {
        throw new CmdException("No endpoint given");
    }
    String endpoint = modRemote.getServiceURL();
    for (String filename : requestFiles) {
        UpdateRequest req = UpdateFactory.read(filename);
        exec(endpoint, req);
    }
    for (String requestString : super.getPositional()) {
        requestString = indirect(requestString);
        UpdateRequest req = UpdateFactory.create(requestString);
        exec(endpoint, req);
    }
}
Also used : CmdException(jena.cmd.CmdException) UpdateRequest(org.apache.jena.update.UpdateRequest)

Example 15 with CmdException

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

the class FusekiCmd method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    int x = 0;
    Logger log = Fuseki.serverLog;
    if (contains(argFusekiConfig))
        fusekiConfigFile = getValue(argFusekiConfig);
    ArgDecl assemblerDescDecl = new ArgDecl(ArgDecl.HasValue, "desc", "dataset");
    if (contains(argMem))
        x++;
    if (contains(argFile))
        x++;
    if (contains(assemblerDescDecl))
        x++;
    if (contains(argTDB))
        x++;
    if (contains(argMemTDB))
        x++;
    if (fusekiConfigFile != null) {
        if (x >= 1)
            throw new CmdException("Dataset specified on the command line but a configuration file also given.");
    } else {
        if (x != 1)
            throw new CmdException("Required: either --config=FILE or one of --mem, --file, --loc or --desc");
    }
    if (contains(argMem)) {
        log.info("Dataset: in-memory");
        dsg = DatasetGraphFactory.create();
    }
    if (contains(argFile)) {
        dsg = DatasetGraphFactory.create();
        // replace by RiotLoader after ARQ refresh.
        String filename = getValue(argFile);
        log.info("Dataset: in-memory: load file: " + filename);
        if (!FileOps.exists(filename))
            throw new CmdException("File not found: " + filename);
        Lang language = RDFLanguages.filenameToLang(filename);
        if (language == null)
            throw new CmdException("Can't guess language for file: " + filename);
        InputStream input = IO.openFile(filename);
        if (RDFLanguages.isQuads(language))
            RDFDataMgr.read(dsg, filename);
        else
            RDFDataMgr.read(dsg.getDefaultGraph(), filename);
    }
    if (contains(argMemTDB)) {
        log.info("TDB dataset: in-memory");
        dsg = TDBFactory.createDatasetGraph();
    }
    if (contains(argTDB)) {
        String dir = getValue(argTDB);
        if (Objects.equals(dir, Names.memName)) {
            log.info("TDB dataset: in-memory");
        } else {
            if (!FileOps.exists(dir))
                throw new CmdException("Directory not found: " + dir);
            log.info("TDB dataset: directory=" + dir);
        }
        dsg = TDBFactory.createDatasetGraph(dir);
    }
    // Otherwise
    if (contains(assemblerDescDecl)) {
        log.info("Dataset from assembler");
        Dataset ds = modDataset.createDataset();
        if (ds != null)
            dsg = ds.asDatasetGraph();
    }
    if (contains(argFusekiConfig)) {
        if (dsg != null)
            throw new CmdException("(internal error) Dataset specificed on the command line but a a configuration file also given.");
        fusekiConfigFile = getValue(argFusekiConfig);
    }
    if (contains(argPort)) {
        String portStr = getValue(argPort);
        try {
            port = Integer.parseInt(portStr);
        } catch (NumberFormatException ex) {
            throw new CmdException(argPort.getKeyName() + " : bad port number: " + portStr);
        }
    }
    if (contains(argMgtPort)) {
        String mgtPortStr = getValue(argMgtPort);
        try {
            mgtPort = Integer.parseInt(mgtPortStr);
        } catch (NumberFormatException ex) {
            throw new CmdException(argMgtPort.getKeyName() + " : bad port number: " + mgtPortStr);
        }
    }
    if (contains(argLocalhost))
        listenLocal = true;
    if (fusekiConfigFile == null && dsg == null)
        throw new CmdException("No dataset defined and no configuration file: " + argUsage);
    if (dsg != null) {
        if (getPositional().size() == 0)
            throw new CmdException("No dataset path name given");
        if (getPositional().size() > 1)
            throw new CmdException("Multiple dataset path names given");
        datasetPath = getPositionalArg(0);
        if (datasetPath.length() > 0 && !datasetPath.startsWith("/"))
            throw new CmdException("Dataset path name must begin with a /: " + datasetPath);
        allowUpdate = contains(argAllowUpdate);
    }
    if (contains(argTimeout)) {
        String str = getValue(argTimeout);
        ARQ.getContext().set(ARQ.queryTimeout, str);
    }
    if (contains(argJettyConfig)) {
        jettyConfigFile = getValue(argJettyConfig);
        if (!FileOps.exists(jettyConfigFile))
            throw new CmdException("No such file: " + jettyConfigFile);
    }
    if (contains(argBasicAuth)) {
        authConfigFile = getValue(argBasicAuth);
        if (!FileOps.exists(authConfigFile))
            throw new CmdException("No such file: " + authConfigFile);
    }
    if (contains(argHome)) {
        List<String> args = super.getValues(argHome);
        homeDir = args.get(args.size() - 1);
    }
    if (contains(argPages)) {
        List<String> args = super.getValues(argPages);
        pagesDir = args.get(args.size() - 1);
    }
    if (contains(argGZip)) {
        if (!hasValueOfTrue(argGZip) && !hasValueOfFalse(argGZip))
            throw new CmdException(argGZip.getNames().get(0) + ": Not understood: " + getValue(argGZip));
        enableCompression = super.hasValueOfTrue(argGZip);
    }
    if (contains(argUber))
        SPARQLServer.überServlet = true;
    if (contains(argGSP)) {
        SPARQLServer.überServlet = true;
        Fuseki.graphStoreProtocolPostCreate = true;
    }
}
Also used : CmdException(jena.cmd.CmdException) InputStream(java.io.InputStream) Dataset(org.apache.jena.query.Dataset) ArgDecl(jena.cmd.ArgDecl) Lang(org.apache.jena.riot.Lang) Logger(org.slf4j.Logger)

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