use of org.apache.jena.query.Dataset in project jena by apache.
the class TestDatasetTDBPersist method dataset2.
@Test
public void dataset2() {
Dataset ds = graphLocation.getDataset();
Graph g1 = ds.getDefaultModel().getGraph();
Graph g2 = ds.getNamedModel("http://example/").getGraph();
g1.add(new Triple(n0, n1, n2));
assertTrue(g1.contains(n0, n1, n2));
assertFalse(g2.contains(n0, n1, n2));
}
use of org.apache.jena.query.Dataset in project jena by apache.
the class TestDatasetTDBPersist method dataset1.
@Test
public void dataset1() {
Dataset ds = graphLocation.getDataset();
assertTrue(ds.getDefaultModel().getGraph() instanceof GraphTDB);
assertTrue(ds.getNamedModel("http://example/").getGraph() instanceof GraphTDB);
}
use of org.apache.jena.query.Dataset 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;
}
}
use of org.apache.jena.query.Dataset in project jena by apache.
the class ResponseDataset method doResponseModel.
public static void doResponseModel(HttpAction action, Model model) {
Dataset ds = DatasetFactory.create(model);
ResponseDataset.doResponseDataset(action, ds);
}
use of org.apache.jena.query.Dataset in project jena by apache.
the class SPARQL_QueryGeneral method datasetFromDescriptionWeb.
/**
* Construct a Dataset based on a dataset description. Loads graph from the
* web.
*/
protected Dataset datasetFromDescriptionWeb(HttpAction action, DatasetDescription datasetDesc) {
try {
if (datasetDesc == null)
return null;
if (datasetDesc.isEmpty())
return null;
List<String> graphURLs = datasetDesc.getDefaultGraphURIs();
List<String> namedGraphs = datasetDesc.getNamedGraphURIs();
if (graphURLs.size() == 0 && namedGraphs.size() == 0)
return null;
Dataset dataset = DatasetFactory.create();
// Look in cache for loaded graphs!!
// ---- Default graph
{
Model model = ModelFactory.createDefaultModel();
for (String uri : graphURLs) {
if (uri == null || uri.equals(""))
throw new InternalErrorException("Default graph URI is null or the empty string");
try {
GraphLoadUtils.loadModel(model, uri, MaxTriples);
action.log.info(format("[%d] Load (default graph) %s", action.id, uri));
} catch (RiotException ex) {
action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
} catch (Exception ex) {
action.log.info(format("[%d] Failed to load (default) %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL " + uri);
}
}
dataset.setDefaultModel(model);
}
// ---- Named graphs
if (namedGraphs != null) {
for (String uri : namedGraphs) {
if (uri == null || uri.equals(""))
throw new InternalErrorException("Named graph URI is null or the empty string");
try {
Model model = ModelFactory.createDefaultModel();
GraphLoadUtils.loadModel(model, uri, MaxTriples);
action.log.info(format("[%d] Load (named graph) %s", action.id, uri));
dataset.addNamedModel(uri, model);
} catch (RiotException ex) {
action.log.info(format("[%d] Parsing error loading %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL (parse error) " + uri + " : " + ex.getMessage());
} catch (Exception ex) {
action.log.info(format("[%d] Failed to load (named graph) %s: %s", action.id, uri, ex.getMessage()));
ServletOps.errorBadRequest("Failed to load URL " + uri);
}
}
}
return dataset;
} catch (ActionErrorException ex) {
throw ex;
} catch (Exception ex) {
action.log.info(format("[%d] SPARQL parameter error: " + ex.getMessage(), action.id, ex));
ServletOps.errorBadRequest("Parameter error: " + ex.getMessage());
return null;
}
}
Aggregations