Skip to content

Commit

Permalink
apacheGH-3014: Support both possible TDB dataset type names
Browse files Browse the repository at this point in the history
  • Loading branch information
afs committed Feb 21, 2025
1 parent 25044b1 commit d4e5772
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -142,14 +142,14 @@ public static Object build(String assemblerFile, Resource type) {
}

public static Object build(Model assemblerModel, Resource type) {
Resource root = null ;
Resource root = null;
try {
root = GraphUtils.findRootByType(assemblerModel, type) ;
root = GraphUtils.findRootByType(assemblerModel, type);
if ( root == null )
throw new ARQException("No such type: <"+type+">");

} catch (TypeNotUniqueException ex)
{ throw new ARQException("Multiple types for: "+tDataset) ; }
throw new ARQException("No such type: <" + type + ">");
} catch (TypeNotUniqueException ex) {
throw new ARQException("Multiple types for: " + tDataset);
}
return Assembler.general.open(root) ;
}
/** Look for and build context declarations.
Expand Down
23 changes: 20 additions & 3 deletions jena-cmds/src/main/java/tdb/cmdline/ModTDBDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,17 +22,21 @@
import java.util.List;

import arq.cmdline.ModDataset;
import org.apache.jena.assembler.Assembler;
import org.apache.jena.atlas.logging.Log;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdArgModule;
import org.apache.jena.cmd.CmdException;
import org.apache.jena.cmd.CmdGeneral;
import org.apache.jena.query.*;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.shared.JenaException;
import org.apache.jena.sparql.ARQException;
import org.apache.jena.sparql.core.assembler.AssemblerUtils;
import org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab;
import org.apache.jena.sparql.util.graph.GraphUtils;
import org.apache.jena.tdb1.TDB1Factory;
import org.apache.jena.tdb1.assembler.VocabTDB1;
import org.apache.jena.tdb1.base.file.Location;
Expand All @@ -41,11 +45,11 @@
public class ModTDBDataset extends ModDataset {
// Mixes assembler, location and "tdb"
// Can make a single model or a dataset

private ArgDecl argMem = new ArgDecl(ArgDecl.HasValue, "mem", "data") ;
private ModTDBAssembler modAssembler = new ModTDBAssembler() ;
private String inMemFile = null ;

public ModTDBDataset() {}

@Override
Expand Down Expand Up @@ -73,7 +77,7 @@ public Dataset createDataset() {
Dataset thing = null;
// Two variants: plain dataset with a TDB graph or a TDB dataset.
try {
thing = (Dataset)AssemblerUtils.build(modAssembler.getAssemblerFile(), VocabTDB1.tDatasetTDB);
thing = buildDataset(modAssembler);
if ( thing != null && !(thing.asDatasetGraph() instanceof DatasetGraphTransaction) )
Log.warn(this, "Unexpected: Not a TDB dataset for type DatasetTDB");

Expand All @@ -97,6 +101,19 @@ public Dataset createDataset() {
return ds;
}

/** Build a dataset - several possible names (legacy) */
private static Dataset buildDataset(ModTDBAssembler modAssembler) {
Model spec = AssemblerUtils.readAssemblerFile(modAssembler.getAssemblerFile());
// throws ARQException("Multiple types for: " + tDataset);
Resource root = GraphUtils.findRootByType(spec, VocabTDB1.tDatasetTDB);
if ( root == null )
// Not found - try again.
root = GraphUtils.findRootByType(spec, VocabTDB1.tDatasetTDB1);
if ( root == null )
throw new ARQException("Not found: No such type: <" + VocabTDB1.tDatasetTDB + ">");
return (Dataset)Assembler.general.open(root) ;
}

public Location getLocation() {
List<String> x = locations();
if ( x.size() == 0 )
Expand Down
25 changes: 21 additions & 4 deletions jena-cmds/src/main/java/tdb2/cmdline/ModTDBDataset.java
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
import java.util.List;

import arq.cmdline.ModDataset;
import org.apache.jena.assembler.Assembler;
import org.apache.jena.atlas.logging.Log;
import org.apache.jena.cmd.ArgDecl;
import org.apache.jena.cmd.CmdArgModule;
Expand All @@ -30,11 +31,14 @@
import org.apache.jena.dboe.base.file.Location;
import org.apache.jena.query.*;
import org.apache.jena.rdf.model.Model;
import org.apache.jena.rdf.model.Resource;
import org.apache.jena.riot.RDFDataMgr;
import org.apache.jena.shared.JenaException;
import org.apache.jena.sparql.ARQException;
import org.apache.jena.sparql.core.DatasetGraph;
import org.apache.jena.sparql.core.assembler.AssemblerUtils;
import org.apache.jena.sparql.core.assembler.DatasetAssemblerVocab;
import org.apache.jena.sparql.util.graph.GraphUtils;
import org.apache.jena.tdb2.TDB2Factory;
import org.apache.jena.tdb2.assembler.VocabTDB2;
import org.apache.jena.tdb2.store.DatasetGraphSwitchable;
Expand All @@ -43,11 +47,11 @@
public class ModTDBDataset extends ModDataset {
// Mixes assembler, location and "tdb"
// Can make a single model or a dataset

private ArgDecl argMem = new ArgDecl(ArgDecl.HasValue, "mem", "data") ;
private ModTDBAssembler modAssembler = new ModTDBAssembler() ;
private String inMemFile = null ;

public ModTDBDataset() {}

@Override
Expand Down Expand Up @@ -75,11 +79,11 @@ public Dataset createDataset() {
// Two variants: plain dataset with TDB2 dataset or plain building
// (which may go wrong later if TDB2 directly is needed).
try {
thing = (Dataset)AssemblerUtils.build(modAssembler.getAssemblerFile(), VocabTDB2.tDatasetTDB);
thing = buildDataset(modAssembler);
if ( thing != null ) {
DatasetGraph dsg = thing.asDatasetGraph();
if ( !(dsg instanceof DatasetGraphSwitchable) && !(dsg instanceof DatasetGraphTDB) )
Log.warn(this, "Unexpected: Not a TDB2 dataset for type DatasetTDB2");
Log.warn(this, "Unexpected: Not a TDB2 dataset");
}
if ( thing == null )
// Should use assembler inheritance but how do we assert
Expand All @@ -101,6 +105,19 @@ public Dataset createDataset() {
return ds;
}

/** Build a dataset - several possible names (legacy) */
private static Dataset buildDataset(ModTDBAssembler modAssembler) {
Model spec = AssemblerUtils.readAssemblerFile(modAssembler.getAssemblerFile());
// throws ARQException("Multiple types for: " + tDataset);
Resource root = GraphUtils.findRootByType(spec, VocabTDB2.tDatasetTDB);
if ( root == null )
// Not found - try again.
root = GraphUtils.findRootByType(spec, VocabTDB2.tDatasetTDB2);
if ( root == null )
throw new ARQException("Not found: No such type: <" + VocabTDB2.tDatasetTDB + ">");
return (Dataset)Assembler.general.open(root) ;
}

public Location getLocation() {
List<String> x = locations();
if ( x.size() == 0 )
Expand Down
2 changes: 1 addition & 1 deletion jena-fuseki2/examples/config-inference-2.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ PREFIX tdb2: <http://jena.apache.org/2016/tdb#>
tdb2:dataset :tdbDataset .

## Base data in TDB.
:tdbDataset rdf:type tdb2:DatasetTDB2 ;
:tdbDataset rdf:type tdb2:DatasetTDB ;
tdb2:location "DB" ;
# If the unionDefaultGraph is used, then the "update" service should be removed.
# tdb:unionDefaultGraph true ;
Expand Down
2 changes: 1 addition & 1 deletion jena-fuseki2/examples/config-tdb2.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ PREFIX tdb2: <http://jena.apache.org/2016/tdb#>
fuseki:dataset :dataset_tdb2 ;
.

:dataset_tdb2 rdf:type tdb2:DatasetTDB2 ;
:dataset_tdb2 rdf:type tdb2:DatasetTDB ;
tdb2:location "DB2" ;
## Optional - with union default for query and update WHERE matching.
## tdb2:unionDefaultGraph true ;
Expand Down
2 changes: 1 addition & 1 deletion jena-fuseki2/examples/config-text-tdb2.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ PREFIX text: <http://jena.apache.org/text#>
text:index :indexLucene ;
.

:base_dataset rdf:type tdb2:DatasetTDB2 ;
:base_dataset rdf:type tdb2:DatasetTDB ;
tdb2:location "DB2"
.

Expand Down
2 changes: 1 addition & 1 deletion jena-fuseki2/examples/tdb2-select-graphs.ttl
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,6 @@ PREFIX tdb2: <http://jena.apache.org/2016/tdb#>

## The database

:dataset_tdb2 rdf:type tdb2:DatasetTDB2 ;
:dataset_tdb2 rdf:type tdb2:DatasetTDB ;
tdb2:location "DB2" ;
.
Original file line number Diff line number Diff line change
Expand Up @@ -35,16 +35,20 @@ public class VocabTDB2

// Types

// Preferred
public static final Resource tDatasetTDB = Vocab.type(NS, "DatasetTDB");
// Another accept name.
public static final Resource tDatasetTDB2 = Vocab.type(NS, "DatasetTDB2");

/** @deprecated Use {@link #tDatasetTDB} */
@Deprecated(forRemoval = true)
public static final Resource tDatasetTDB_alt = Vocab.type(NS, "DatasetTDB");

public static final Resource tGraphTDB = Vocab.type(NS, "GraphTDB");
public static final Resource tGraphTDB2 = Vocab.type(NS, "GraphTDB2");

/** @deprecated Use {@link #tGraphTDB} */
@Deprecated
@Deprecated(forRemoval = true)
public static final Resource tGraphTDB_alt = Vocab.type(NS, "GraphTDB");

// public static final Resource tTupleIndex = Vocab.type(NS, "TupleIndex");
Expand Down

0 comments on commit d4e5772

Please sign in to comment.