NIHVIVO-1734 assertions-only DAO fixes for SDB

This commit is contained in:
bjl23 2011-01-17 22:17:07 +00:00
parent 03db8dae59
commit 855ea3663f
7 changed files with 170 additions and 44 deletions

View file

@ -31,15 +31,21 @@ import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.beans.Individual; import edu.cornell.mannlib.vitro.webapp.beans.Individual;
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena
implements DataPropertyStatementDao { implements DataPropertyStatementDao {
private DatasetWrapperFactory dwf; private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
public DataPropertyStatementDaoSDB(DatasetWrapperFactory datasetWrapperFactory, WebappDaoFactoryJena wadf) { public DataPropertyStatementDaoSDB(
DatasetWrapperFactory datasetWrapperFactory,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) {
super (datasetWrapperFactory, wadf); super (datasetWrapperFactory, wadf);
this.dwf = datasetWrapperFactory; this.dwf = datasetWrapperFactory;
this.datasetMode = datasetMode;
} }
@Override @Override
@ -51,12 +57,14 @@ public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena
} }
else else
{ {
String[] graphVars = { "?g" };
String query = String query =
"CONSTRUCT { \n" + "CONSTRUCT { \n" +
" <" + entity.getURI() + "> ?p ?o . \n" + " <" + entity.getURI() + "> ?p ?o . \n" +
"} WHERE { GRAPH ?g { \n" + "} WHERE { GRAPH ?g { \n" +
" <" + entity.getURI() + "> ?p ?o . \n" + " <" + entity.getURI() + "> ?p ?o . \n" +
" FILTER(isLiteral(?o)) \n" + " FILTER(isLiteral(?o)) \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"} }" ; "} }" ;
Model results = null; Model results = null;
DatasetWrapper w = dwf.getDatasetWrapper(); DatasetWrapper w = dwf.getDatasetWrapper();

View file

@ -45,15 +45,20 @@ import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
public class IndividualDaoSDB extends IndividualDaoJena { public class IndividualDaoSDB extends IndividualDaoJena {
private DatasetWrapperFactory dwf; private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
private WebappDaoFactoryJena wadf; private WebappDaoFactoryJena wadf;
public IndividualDaoSDB(DatasetWrapperFactory dwf, WebappDaoFactoryJena wadf) { public IndividualDaoSDB(DatasetWrapperFactory dwf,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) {
super(wadf); super(wadf);
this.dwf = dwf; this.dwf = dwf;
this.datasetMode = datasetMode;
} }
protected DatasetWrapper getDatasetWrapper() { protected DatasetWrapper getDatasetWrapper() {
@ -61,7 +66,7 @@ public class IndividualDaoSDB extends IndividualDaoJena {
} }
protected Individual makeIndividual(String individualURI) { protected Individual makeIndividual(String individualURI) {
return new IndividualSDB(individualURI, this.dwf, getWebappDaoFactory()); return new IndividualSDB(individualURI, this.dwf, datasetMode, getWebappDaoFactory());
} }
private static final Log log = LogFactory.getLog(IndividualDaoSDB.class.getName()); private static final Log log = LogFactory.getLog(IndividualDaoSDB.class.getName());
@ -97,6 +102,7 @@ public class IndividualDaoSDB extends IndividualDaoJena {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String[] graphVars = {"?g", "?h", "?i"};
String query = String query =
"SELECT DISTINCT ?ind ?label ?moniker " + "SELECT DISTINCT ?ind ?label ?moniker " +
"WHERE " + "WHERE " +
@ -105,6 +111,7 @@ public class IndividualDaoSDB extends IndividualDaoJena {
"} \n" + "} \n" +
"OPTIONAL { GRAPH ?h { ?ind <" + RDFS.label.getURI() + "> ?label } }\n" + "OPTIONAL { GRAPH ?h { ?ind <" + RDFS.label.getURI() + "> ?label } }\n" +
"OPTIONAL { GRAPH ?i { ?ind <" + VitroVocabulary.MONIKER + "> ?moniker } } \n" + "OPTIONAL { GRAPH ?i { ?ind <" + VitroVocabulary.MONIKER + "> ?moniker } } \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"} ORDER BY ?label"; "} ORDER BY ?label";
ResultSet rs =QueryExecutionFactory.create( ResultSet rs =QueryExecutionFactory.create(
QueryFactory.create(query), dataset) QueryFactory.create(query), dataset)
@ -117,7 +124,7 @@ public class IndividualDaoSDB extends IndividualDaoJena {
&& !currRes.isAnon()) { && !currRes.isAnon()) {
res = currRes; res = currRes;
Individual ent = new IndividualSDB(currRes.getURI(), Individual ent = new IndividualSDB(currRes.getURI(),
this.dwf, getWebappDaoFactory(), this.dwf, datasetMode, getWebappDaoFactory(),
SKIP_INITIALIZATION); SKIP_INITIALIZATION);
Literal label = sol.getLiteral("label"); Literal label = sol.getLiteral("label");
if (label != null) { if (label != null) {

View file

@ -2,8 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.dao.jena; package edu.cornell.mannlib.vitro.webapp.dao.jena;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.sql.Timestamp; import java.sql.Timestamp;
import java.text.Collator; import java.text.Collator;
import java.util.ArrayList; import java.util.ArrayList;
@ -30,21 +28,16 @@ import com.hp.hpl.jena.query.QueryExecutionFactory;
import com.hp.hpl.jena.query.QueryFactory; import com.hp.hpl.jena.query.QueryFactory;
import com.hp.hpl.jena.query.QuerySolution; import com.hp.hpl.jena.query.QuerySolution;
import com.hp.hpl.jena.query.ResultSet; import com.hp.hpl.jena.query.ResultSet;
import com.hp.hpl.jena.query.ResultSetFormatter;
import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.Model; import com.hp.hpl.jena.rdf.model.Model;
import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
import com.hp.hpl.jena.rdf.model.ResIterator;
import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.Resource;
import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.ResourceFactory;
import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.rdf.model.StmtIterator;
import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.util.iterator.ClosableIterator; import com.hp.hpl.jena.util.iterator.ClosableIterator;
import com.hp.hpl.jena.vocabulary.OWL;
import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDF;
import com.hp.hpl.jena.vocabulary.RDFS; import com.hp.hpl.jena.vocabulary.RDFS;
@ -60,6 +53,7 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo; import edu.cornell.mannlib.vitro.webapp.filestorage.model.ImageInfo;
import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.search.beans.ProhibitedFromSearch;
import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils; import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils;
@ -73,12 +67,16 @@ public class IndividualSDB extends IndividualImpl implements Individual {
private Float _searchBoostJena = null; private Float _searchBoostJena = null;
private boolean retreivedNullRdfsLabel = false; private boolean retreivedNullRdfsLabel = false;
private DatasetWrapperFactory dwf = null; private DatasetWrapperFactory dwf = null;
private SDBDatasetMode datasetMode =
SDBDatasetMode.ASSERTIONS_AND_INFERENCES;
private String individualURI = null; private String individualURI = null;
private Model model = null; private Model model = null;
public IndividualSDB(String individualURI, public IndividualSDB(String individualURI,
DatasetWrapperFactory datasetWrapperFactory, DatasetWrapperFactory datasetWrapperFactory,
WebappDaoFactoryJena wadf, Model initModel) { SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf,
Model initModel) {
this.individualURI = individualURI; this.individualURI = individualURI;
this.dwf = datasetWrapperFactory; this.dwf = datasetWrapperFactory;
@ -115,9 +113,11 @@ public class IndividualSDB extends IndividualImpl implements Individual {
public IndividualSDB(String individualURI, public IndividualSDB(String individualURI,
DatasetWrapperFactory datasetWrapperFactory, DatasetWrapperFactory datasetWrapperFactory,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf, WebappDaoFactoryJena wadf,
boolean skipInitialization) { boolean skipInitialization) {
this.individualURI = individualURI; this.individualURI = individualURI;
this.datasetMode = datasetMode;
this.dwf = datasetWrapperFactory; this.dwf = datasetWrapperFactory;
if (skipInitialization) { if (skipInitialization) {
@ -129,6 +129,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
try { try {
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
String[] graphVars = {"?g", "?h", "?i"};
String getStatements = String getStatements =
"CONSTRUCT " + "CONSTRUCT " +
"{ <"+individualURI+"> <" + RDFS.label.getURI() + "{ <"+individualURI+"> <" + RDFS.label.getURI() +
@ -146,6 +147,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
"} } \n" + "} } \n" +
"UNION { GRAPH ?i { <" "UNION { GRAPH ?i { <"
+ individualURI + "> a ?type } } \n" + + individualURI + "> a ?type } } \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}"; "}";
model = QueryExecutionFactory.create( model = QueryExecutionFactory.create(
QueryFactory.create(getStatements), dataset) QueryFactory.create(getStatements), dataset)
@ -167,9 +169,14 @@ public class IndividualSDB extends IndividualImpl implements Individual {
private static final boolean SKIP_INITIALIZATION = true; private static final boolean SKIP_INITIALIZATION = true;
public IndividualSDB(String individualURI, public IndividualSDB(String individualURI,
DatasetWrapperFactory datasetWrapperFactory, DatasetWrapperFactory datasetWrapperFactory,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) { WebappDaoFactoryJena wadf) {
this(individualURI, datasetWrapperFactory, wadf, !SKIP_INITIALIZATION); this(individualURI,
datasetWrapperFactory,
datasetMode,
wadf,
!SKIP_INITIALIZATION);
} }
private void setUpURIParts(OntResource ind) { private void setUpURIParts(OntResource ind) {
@ -589,10 +596,13 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String[] graphVars = { "?g" };
String queryStr = "CONSTRUCT { ?ind <" + String queryStr = "CONSTRUCT { ?ind <" +
propertyURI + "> ?value } \n" + propertyURI + "> ?value } \n" +
"WHERE { GRAPH ?g { ?ind <" + "WHERE { GRAPH ?g { ?ind <" +
propertyURI + "> ?value } } \n"; propertyURI + "> ?value } \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"\n} \n";
Query query = QueryFactory.create(queryStr); Query query = QueryFactory.create(queryStr);
QueryExecution qe = QueryExecutionFactory.create( QueryExecution qe = QueryExecutionFactory.create(
query, dataset); query, dataset);
@ -607,11 +617,14 @@ public class IndividualSDB extends IndividualImpl implements Individual {
if( this._searchBoostJena != null ){ if( this._searchBoostJena != null ){
return this._searchBoostJena; return this._searchBoostJena;
}else{ }else{
String[] graphVars = { "?g" };
String getPropertyValue = String getPropertyValue =
"SELECT ?value" + "SELECT ?value" +
"WHERE { GRAPH ?g { <" + individualURI + ">" + "WHERE { GRAPH ?g { <" + individualURI + ">" +
webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT + webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT +
"?value} }"; "?value} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
@ -704,6 +717,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String graphVars[] = { "?g" };
StringBuffer selectPrimaryLinkQueryBuff = new StringBuffer().append( StringBuffer selectPrimaryLinkQueryBuff = new StringBuffer().append(
"SELECT ?url ?anchor \n" ).append( "SELECT ?url ?anchor \n" ).append(
"WHERE{ GRAPH ?g { \n " ).append( "WHERE{ GRAPH ?g { \n " ).append(
@ -714,7 +728,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
).append( ).append(
" ?link <" + VitroVocabulary.LINK_ANCHOR + "> ?anchor . \n" " ?link <" + VitroVocabulary.LINK_ANCHOR + "> ?anchor . \n"
).append( ).append(
"} }"); "} \n")
.append(WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode))
.append("}");
QueryExecution qexec = QueryExecutionFactory.create( QueryExecution qexec = QueryExecutionFactory.create(
QueryFactory.create(selectPrimaryLinkQueryBuff.toString()) QueryFactory.create(selectPrimaryLinkQueryBuff.toString())
, dataset); , dataset);
@ -827,9 +843,12 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String[] graphVars = { "?g" };
String valuesOfProperty = String valuesOfProperty =
"CONSTRUCT{<" + this.individualURI + "> <" + propertyURI + "> ?object}" + "CONSTRUCT{<" + this.individualURI + "> <" + propertyURI + "> ?object}" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} }"; "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
tempModel = QueryExecutionFactory.create(QueryFactory.create(valuesOfProperty), dataset).execConstruct(); tempModel = QueryExecutionFactory.create(QueryFactory.create(valuesOfProperty), dataset).execConstruct();
ontModel.add(tempModel.listStatements()); ontModel.add(tempModel.listStatements());
Resource ontRes = ontModel.getResource(this.individualURI); Resource ontRes = ontModel.getResource(this.individualURI);
@ -839,8 +858,8 @@ public class IndividualSDB extends IndividualImpl implements Individual {
if (!s.getSubject().canAs(OntResource.class) || !s.getObject().canAs(OntResource.class)) { if (!s.getSubject().canAs(OntResource.class) || !s.getObject().canAs(OntResource.class)) {
continue; continue;
} }
Individual subj = new IndividualSDB(((OntResource) s.getSubject().as(OntResource.class)).getURI(), this.dwf, webappDaoFactory); Individual subj = new IndividualSDB(((OntResource) s.getSubject().as(OntResource.class)).getURI(), this.dwf, datasetMode, webappDaoFactory);
Individual obj = new IndividualSDB(((OntResource) s.getObject().as(OntResource.class)).getURI(), this.dwf, webappDaoFactory); Individual obj = new IndividualSDB(((OntResource) s.getObject().as(OntResource.class)).getURI(), this.dwf, datasetMode, webappDaoFactory);
ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI()); ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI());
if (subj != null && obj != null && op != null) { if (subj != null && obj != null && op != null) {
ObjectPropertyStatement ops = new ObjectPropertyStatementImpl(); ObjectPropertyStatement ops = new ObjectPropertyStatementImpl();
@ -873,10 +892,13 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String[] graphVars = { "?g" };
String valuesOfProperty = String valuesOfProperty =
"SELECT ?object" + "SELECT ?object" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
propertyURI + "> ?object} }"; propertyURI + "> ?object} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
ResultSet values = QueryExecutionFactory.create( ResultSet values = QueryExecutionFactory.create(
QueryFactory.create(valuesOfProperty), dataset) QueryFactory.create(valuesOfProperty), dataset)
.execSelect(); .execSelect();
@ -889,7 +911,9 @@ public class IndividualSDB extends IndividualImpl implements Individual {
new IndividualSDB( new IndividualSDB(
((OntResource) value.as(OntResource.class)) ((OntResource) value.as(OntResource.class))
.getURI(), .getURI(),
this.dwf, webappDaoFactory) ); this.dwf,
datasetMode,
webappDaoFactory) );
} }
} }
} finally { } finally {
@ -908,10 +932,13 @@ public class IndividualSDB extends IndividualImpl implements Individual {
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);
try { try {
String[] graphVars = { "?g" };
String valueOfProperty = String valueOfProperty =
"SELECT ?object" + "SELECT ?object" +
"WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" +
propertyURI + "> ?object} }"; propertyURI + "> ?object} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
ResultSet results = QueryExecutionFactory.create( ResultSet results = QueryExecutionFactory.create(
QueryFactory.create(valueOfProperty), dataset).execSelect(); QueryFactory.create(valueOfProperty), dataset).execSelect();
QuerySolution result = results.next(); QuerySolution result = results.next();
@ -919,7 +946,7 @@ public class IndividualSDB extends IndividualImpl implements Individual {
if (value != null && value.canAs(OntResource.class)) { if (value != null && value.canAs(OntResource.class)) {
return new IndividualSDB( return new IndividualSDB(
((OntResource) value.as(OntResource.class)).getURI(), ((OntResource) value.as(OntResource.class)).getURI(),
dwf, webappDaoFactory); dwf, datasetMode, webappDaoFactory);
} else { } else {
return null; return null;
} }
@ -1088,8 +1115,14 @@ public class IndividualSDB extends IndividualImpl implements Individual {
((direct) ((direct)
? "<http://vitro.mannlib.cornell.edu/default/vitro-kb-2>" ? "<http://vitro.mannlib.cornell.edu/default/vitro-kb-2>"
: "?g") : "?g")
+ " { <" + this.individualURI +"> <" +RDF.type+ "> ?types \n" + + " { <" + this.individualURI +"> <" +RDF.type+ "> ?types } \n" ;
"} } \n";
if (!direct) {
String[] graphVars = { "?g" };
getTypes += WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode);
}
getTypes += "} \n";
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ); dataset.getLock().enterCriticalSection(Lock.READ);

View file

@ -27,17 +27,21 @@ import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement;
import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatementImpl;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
public class ObjectPropertyStatementDaoSDB extends public class ObjectPropertyStatementDaoSDB extends
ObjectPropertyStatementDaoJena implements ObjectPropertyStatementDao { ObjectPropertyStatementDaoJena implements ObjectPropertyStatementDao {
private DatasetWrapperFactory dwf; private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
public ObjectPropertyStatementDaoSDB( public ObjectPropertyStatementDaoSDB(
DatasetWrapperFactory dwf, DatasetWrapperFactory dwf,
SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) { WebappDaoFactoryJena wadf) {
super (dwf, wadf); super (dwf, wadf);
this.dwf = dwf; this.dwf = dwf;
this.datasetMode = datasetMode;
} }
@Override @Override
@ -46,6 +50,7 @@ public class ObjectPropertyStatementDaoSDB extends
return entity; return entity;
else { else {
Map<String, ObjectProperty> uriToObjectProperty = new HashMap<String,ObjectProperty>(); Map<String, ObjectProperty> uriToObjectProperty = new HashMap<String,ObjectProperty>();
String[] graphVars = { "?g", "?h", "?i", "?j" };
String query = "CONSTRUCT { \n" + String query = "CONSTRUCT { \n" +
" <" + entity.getURI() + "> ?p ?o . \n" + " <" + entity.getURI() + "> ?p ?o . \n" +
" ?o a ?oType . \n" + " ?o a ?oType . \n" +
@ -56,7 +61,9 @@ public class ObjectPropertyStatementDaoSDB extends
" OPTIONAL { GRAPH ?h { ?o a ?oType } } \n" + " OPTIONAL { GRAPH ?h { ?o a ?oType } } \n" +
" OPTIONAL { GRAPH ?i { ?o <" + RDFS.label.getURI() + "> ?oLabel } } \n" + " OPTIONAL { GRAPH ?i { ?o <" + RDFS.label.getURI() + "> ?oLabel } } \n" +
" OPTIONAL { GRAPH ?j { ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker } } \n" + " OPTIONAL { GRAPH ?j { ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker } } \n" +
"} }"; "} \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"}";
long startTime = System.currentTimeMillis(); long startTime = System.currentTimeMillis();
Model m = null; Model m = null;
DatasetWrapper w = dwf.getDatasetWrapper(); DatasetWrapper w = dwf.getDatasetWrapper();
@ -119,6 +126,7 @@ public class ObjectPropertyStatementDaoSDB extends
Individual objInd = new IndividualSDB( Individual objInd = new IndividualSDB(
objPropertyStmt.getObjectURI(), objPropertyStmt.getObjectURI(),
this.dwf, this.dwf,
datasetMode,
getWebappDaoFactory(), getWebappDaoFactory(),
m); m);
objPropertyStmt.setObject(objInd); objPropertyStmt.setObject(objInd);

View file

@ -23,15 +23,19 @@ import com.hp.hpl.jena.vocabulary.RDF;
import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup; import edu.cornell.mannlib.vitro.webapp.beans.VClassGroup;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
public class VClassDaoSDB extends VClassDaoJena { public class VClassDaoSDB extends VClassDaoJena {
private DatasetWrapperFactory dwf; private DatasetWrapperFactory dwf;
private SDBDatasetMode datasetMode;
public VClassDaoSDB(DatasetWrapperFactory datasetWrapperFactory, public VClassDaoSDB(DatasetWrapperFactory datasetWrapperFactory,
WebappDaoFactoryJena wadf) { SDBDatasetMode datasetMode,
WebappDaoFactoryJena wadf) {
super(wadf); super(wadf);
this.dwf = datasetWrapperFactory; this.dwf = datasetWrapperFactory;
this.datasetMode = datasetMode;
} }
protected DatasetWrapper getDatasetWrapper() { protected DatasetWrapper getDatasetWrapper() {
@ -60,8 +64,11 @@ public class VClassDaoSDB extends VClassDaoJena {
aboxModel.enterCriticalSection(Lock.READ); aboxModel.enterCriticalSection(Lock.READ);
int count = 0; int count = 0;
try { try {
String[] graphVars = { "?g" };
String countQueryStr = "SELECT COUNT(*) WHERE \n" + String countQueryStr = "SELECT COUNT(*) WHERE \n" +
"{ GRAPH ?g { ?s a <" + cls.getURI() + "> } } \n"; "{ GRAPH ?g { ?s a <" + cls.getURI() + "> } \n" +
WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) +
"} \n";
Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ); Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ);
DatasetWrapper w = getDatasetWrapper(); DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset(); Dataset dataset = w.getDataset();

View file

@ -19,14 +19,15 @@ import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao;
import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao;
import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
public class WebappDaoFactorySDB extends WebappDaoFactoryJena { public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
private SDBDatasetMode datasetMode = SDBDatasetMode.ASSERTIONS_AND_INFERENCES;
/** /**
* For use when any database connection associated with the Dataset * For use when any database connection associated with the Dataset
* is managed externally * is managed externally
* @param ontModelSelector
* @param dataset
*/ */
public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset) { public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset) {
super(ontModelSelector); super(ontModelSelector);
@ -36,8 +37,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
/** /**
* For use when any database connection associated with the Dataset * For use when any database connection associated with the Dataset
* is managed externally * is managed externally
* @param ontModelSelector
* @param dataset
*/ */
public WebappDaoFactorySDB(OntModelSelector ontModelSelector, public WebappDaoFactorySDB(OntModelSelector ontModelSelector,
Dataset dataset, Dataset dataset,
@ -51,8 +50,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
/** /**
* For use when any Dataset access should get a temporary DB connection * For use when any Dataset access should get a temporary DB connection
* from a pool * from a pool
* @param ontModelSelector
* @param dataset
*/ */
public WebappDaoFactorySDB(OntModelSelector ontModelSelector, public WebappDaoFactorySDB(OntModelSelector ontModelSelector,
BasicDataSource bds, BasicDataSource bds,
@ -64,6 +61,23 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
this.dwf = new ReconnectingDatasetFactory(bds, storeDesc); this.dwf = new ReconnectingDatasetFactory(bds, storeDesc);
} }
/**
* For use when any Dataset access should get a temporary DB connection
* from a pool, and access to the inference graph needs to be specified.
*/
public WebappDaoFactorySDB(OntModelSelector ontModelSelector,
BasicDataSource bds,
StoreDesc storeDesc,
String defaultNamespace,
HashSet<String> nonuserNamespaces,
String[] preferredLanguages,
SDBDatasetMode datasetMode) {
super(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages);
this.dwf = new ReconnectingDatasetFactory(bds, storeDesc);
this.datasetMode = datasetMode;
}
public WebappDaoFactorySDB(WebappDaoFactorySDB base, String userURI) { public WebappDaoFactorySDB(WebappDaoFactorySDB base, String userURI) {
super(base.ontModelSelector); super(base.ontModelSelector);
this.ontModelSelector = base.ontModelSelector; this.ontModelSelector = base.ontModelSelector;
@ -81,7 +95,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
if (entityWebappDao != null) if (entityWebappDao != null)
return entityWebappDao; return entityWebappDao;
else else
return entityWebappDao = new IndividualDaoSDB(dwf, this); return entityWebappDao = new IndividualDaoSDB(
dwf, datasetMode, this);
} }
@Override @Override
@ -89,7 +104,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
if (dataPropertyStatementDao != null) if (dataPropertyStatementDao != null)
return dataPropertyStatementDao; return dataPropertyStatementDao;
else else
return dataPropertyStatementDao = new DataPropertyStatementDaoSDB(dwf, this); return dataPropertyStatementDao = new DataPropertyStatementDaoSDB(
dwf, datasetMode, this);
} }
@Override @Override
@ -97,7 +113,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
if (objectPropertyStatementDao != null) if (objectPropertyStatementDao != null)
return objectPropertyStatementDao; return objectPropertyStatementDao;
else else
return objectPropertyStatementDao = new ObjectPropertyStatementDaoSDB(dwf, this); return objectPropertyStatementDao =
new ObjectPropertyStatementDaoSDB(dwf, datasetMode, this);
} }
@Override @Override
@ -105,7 +122,7 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
if (vClassDao != null) if (vClassDao != null)
return vClassDao; return vClassDao;
else else
return vClassDao = new VClassDaoSDB(dwf, this); return vClassDao = new VClassDaoSDB(dwf, datasetMode, this);
} }
public WebappDaoFactory getUserAwareDaoFactory(String userURI) { public WebappDaoFactory getUserAwareDaoFactory(String userURI) {
@ -113,6 +130,40 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
return new WebappDaoFactorySDB(this, userURI); return new WebappDaoFactorySDB(this, userURI);
} }
public enum SDBDatasetMode {
ASSERTIONS_ONLY, INFERENCES_ONLY, ASSERTIONS_AND_INFERENCES
}
public static String getFilterBlock(String[] graphVars,
SDBDatasetMode datasetMode) {
StringBuffer filterBlock = new StringBuffer();
for (int i = 0; i < graphVars.length; i++) {
switch (datasetMode) {
case ASSERTIONS_ONLY :
filterBlock.append("FILTER (").append(graphVars[i])
.append(" != <")
.append(JenaDataSourceSetupBase.JENA_INF_MODEL)
.append("> && ").append(graphVars[i])
.append(" != <")
.append(JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL)
.append(">) \n");
break;
case INFERENCES_ONLY :
filterBlock.append("FILTER (").append(graphVars[i])
.append(" = <")
.append(JenaDataSourceSetupBase.JENA_INF_MODEL)
.append("> || ").append(graphVars[i])
.append(" = <")
.append(JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL)
.append(">) \n");
break;
default:
break;
}
}
return filterBlock.toString();
}
private class ReconnectingDatasetFactory implements DatasetWrapperFactory { private class ReconnectingDatasetFactory implements DatasetWrapperFactory {
private BasicDataSource _bds; private BasicDataSource _bds;

View file

@ -187,16 +187,28 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
ModelFactory.createUnion(baseOms.getABoxModel(), baseOms.getTBoxModel())); ModelFactory.createUnion(baseOms.getABoxModel(), baseOms.getTBoxModel()));
baseOms.setFullModel(baseUnion); baseOms.setFullModel(baseUnion);
ModelContext.setBaseOntModel(baseOms.getFullModel(), sce.getServletContext()); ModelContext.setBaseOntModel(baseOms.getFullModel(), sce.getServletContext());
WebappDaoFactory baseWadf = new WebappDaoFactorySDB(baseOms, bds, storeDesc, defaultNamespace, null, null); WebappDaoFactory baseWadf = new WebappDaoFactorySDB(
//WebappDaoFactory baseWadf = new WebappDaoFactorySDB(baseOms, dataset, defaultNamespace, null, null); baseOms,
bds,
storeDesc,
defaultNamespace,
null,
null,
WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY);
sce.getServletContext().setAttribute("assertionsWebappDaoFactory",baseWadf); sce.getServletContext().setAttribute("assertionsWebappDaoFactory",baseWadf);
OntModel inferenceUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, OntModel inferenceUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
ModelFactory.createUnion(inferenceOms.getABoxModel(), inferenceOms.getTBoxModel())); ModelFactory.createUnion(inferenceOms.getABoxModel(), inferenceOms.getTBoxModel()));
inferenceOms.setFullModel(inferenceUnion); inferenceOms.setFullModel(inferenceUnion);
ModelContext.setInferenceOntModel(inferenceOms.getFullModel(), sce.getServletContext()); ModelContext.setInferenceOntModel(inferenceOms.getFullModel(), sce.getServletContext());
WebappDaoFactory infWadf = new WebappDaoFactorySDB(inferenceOms, bds, storeDesc, defaultNamespace, null, null); WebappDaoFactory infWadf = new WebappDaoFactorySDB(
//WebappDaoFactory infWadf = new WebappDaoFactorySDB(inferenceOms, dataset, defaultNamespace, null, null); inferenceOms,
bds,
storeDesc,
defaultNamespace,
null,
null,
WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY);
sce.getServletContext().setAttribute("deductionsWebappDaoFactory", infWadf); sce.getServletContext().setAttribute("deductionsWebappDaoFactory", infWadf);
OntModel masterUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, OntModel masterUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,