Search in sources :

Example 1 with CmdException

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

the class sdbdump method execCmd.

@Override
protected void execCmd(List<String> args) {
    // This is a streamable syntax.
    String syntax = "N-QUADS";
    if (contains(argDeclSyntax))
        syntax = getArg(argDeclSyntax).getValue();
    Lang lang = RDFLanguages.nameToLang(syntax);
    try {
        if (modGraph.getGraphName() == null) {
            if (!RDFLanguages.isQuads(lang))
                cmdError("Not a 'quads' language (try 'N-Quads' or 'TriG')", true);
            Dataset dataset = getModStore().getDataset();
            RDFDataMgr.write(System.out, dataset, lang);
        } else {
            Model model = modGraph.getModel(getStore());
            RDFDataMgr.write(System.out, model, lang);
        }
    } catch (CmdException ex) {
        throw ex;
    } catch (Exception ex) {
        System.err.println("Exception: " + ex + " :: " + ex.getMessage());
        ex.printStackTrace(System.err);
    }
}
Also used : CmdException(jena.cmd.CmdException) Dataset(org.apache.jena.query.Dataset) Model(org.apache.jena.rdf.model.Model) Lang(org.apache.jena.riot.Lang) CmdException(jena.cmd.CmdException)

Example 2 with CmdException

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

the class sdbload method loadOne.

private void loadOne(String filename, boolean replace) {
    Model model = null;
    Dataset dataset = null;
    PrefixMapping pmap;
    Lang lang = RDFLanguages.filenameToLang(filename);
    if (lang == null)
        throw new CmdException("Data syntax not recognized: " + filename);
    // --graph or not
    if (modGraph.getGraphName() != null) {
        model = modGraph.getModel(getStore());
        pmap = model;
    } else {
        dataset = SDBFactory.connectDataset(getStore());
        pmap = dataset.asDatasetGraph().getDefaultGraph().getPrefixMapping();
    }
    // For monitoring only.
    Graph monitorGraph = (model == null) ? null : model.getGraph();
    if (replace) {
        if (model != null)
            model.removeAll();
        else
            dataset.asDatasetGraph().clear();
    }
    boolean showProgress = isVerbose() || getModTime().timingEnabled();
    if (showProgress)
        output.print("Start load: %s", filename);
    StreamRDF stream = streamToStore(pmap, getStore());
    if (modGraph.getGraphName() != null) {
        Node gn = NodeFactory.createURI(modGraph.getGraphName());
        stream = StreamRDFLib.extendTriplesToQuads(gn, stream);
    }
    ProgressMonitor progress = null;
    if (showProgress) {
        progress = new ProgressMonitor(filename, 100_000, 10, output);
        stream = new ProgressStreamRDF(stream, progress);
    }
    if (progress != null)
        progress.start();
    // Load!
    RDFDataMgr.parse(stream, filename, lang);
    if (progress != null) {
        progress.finish();
        progress.finishMessage();
    }
}
Also used : ProgressMonitor(org.apache.jena.atlas.lib.ProgressMonitor) PrefixMapping(org.apache.jena.shared.PrefixMapping) Graph(org.apache.jena.graph.Graph) ModGraph(sdb.cmd.ModGraph) ProgressStreamRDF(org.apache.jena.riot.system.ProgressStreamRDF) CmdException(jena.cmd.CmdException) ProgressStreamRDF(org.apache.jena.riot.system.ProgressStreamRDF) StreamRDF(org.apache.jena.riot.system.StreamRDF) Dataset(org.apache.jena.query.Dataset) Node(org.apache.jena.graph.Node) Model(org.apache.jena.rdf.model.Model) Lang(org.apache.jena.riot.Lang)

Example 3 with CmdException

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

the class sdbmeta method execPut.

private void execPut(StoreConfig conf, String tag, List<String> positionalArgs) {
    if (positionalArgs.size() == 0)
        throw new CmdException("No file to load");
    Model model = conf.getModel(tag);
    if (model == null)
        model = ModelFactory.createDefaultModel();
    for (String filename : positionalArgs) FileManager.get().readModel(model, filename);
    conf.setModel(tag, model);
}
Also used : CmdException(jena.cmd.CmdException) Model(org.apache.jena.rdf.model.Model)

Example 4 with CmdException

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

the class sdbprint method processModulesAndArgs.

@Override
protected void processModulesAndArgs() {
    // Force the connection to be a null one.
    // Known to be called after arg module initialization.
    StoreDesc storeDesc = getModStore().getStoreDesc();
    storeDesc.connDesc.setJdbcURL(JDBC.jdbcNone);
    if (storeDesc.getLayout() == null)
        storeDesc.setLayout(layoutDefault);
    printSQL = contains(argDeclPrintSQL);
    List<String> strList = getValues(argDeclPrint);
    for (String arg : strList) {
        if (arg.equalsIgnoreCase("query")) {
            printQuery = true;
        } else if (arg.equalsIgnoreCase("Op")) {
            printOp = true;
        } else if (arg.equalsIgnoreCase("SqlNode")) {
            printSqlNode = true;
        } else if (arg.equalsIgnoreCase("sql")) {
            printSQL = true;
        } else if (arg.equalsIgnoreCase("plan")) {
            printPlan = true;
        } else
            throw new CmdException("Not a recognized print form: " + arg + " : Choices are: query, prefix, op, sqlNode, sql");
    }
}
Also used : CmdException(jena.cmd.CmdException) StoreDesc(org.apache.jena.sdb.StoreDesc)

Example 5 with CmdException

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

the class sdbupdate method execCmd.

@Override
protected void execCmd(List<String> positionalArgs) {
    if (isVerbose())
        SDB_QC.PrintSQL = true;
    getStore();
    Dataset dataset = getModStore().getDataset();
    List<String> requestFiles = getValues(updateArg);
    if (requestFiles.size() == 0 && getPositional().size() == 0)
        throw new CmdException("Nothing to do");
    for (String filename : requestFiles) execOneFile(filename, dataset);
    for (String requestString : super.getPositional()) {
        requestString = indirect(requestString);
        execOne(requestString, dataset);
    }
}
Also used : CmdException(jena.cmd.CmdException) Dataset(org.apache.jena.query.Dataset)

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