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);
}
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;
}
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);
}
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);
}
}
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;
}
}
Aggregations