diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoSDB.java index 6ad4a59c3..a93ac88ae 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoSDB.java @@ -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.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode; public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena implements DataPropertyStatementDao { private DatasetWrapperFactory dwf; + private SDBDatasetMode datasetMode; - public DataPropertyStatementDaoSDB(DatasetWrapperFactory datasetWrapperFactory, WebappDaoFactoryJena wadf) { + public DataPropertyStatementDaoSDB( + DatasetWrapperFactory datasetWrapperFactory, + SDBDatasetMode datasetMode, + WebappDaoFactoryJena wadf) { super (datasetWrapperFactory, wadf); this.dwf = datasetWrapperFactory; + this.datasetMode = datasetMode; } @Override @@ -51,12 +57,14 @@ public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena } else { + String[] graphVars = { "?g" }; String query = "CONSTRUCT { \n" + " <" + entity.getURI() + "> ?p ?o . \n" + "} WHERE { GRAPH ?g { \n" + " <" + entity.getURI() + "> ?p ?o . \n" + " FILTER(isLiteral(?o)) \n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + "} }" ; Model results = null; DatasetWrapper w = dwf.getDatasetWrapper(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java index 1128f40fd..60fd6602e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java @@ -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.VClass; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode; public class IndividualDaoSDB extends IndividualDaoJena { private DatasetWrapperFactory dwf; + private SDBDatasetMode datasetMode; private WebappDaoFactoryJena wadf; - public IndividualDaoSDB(DatasetWrapperFactory dwf, WebappDaoFactoryJena wadf) { + public IndividualDaoSDB(DatasetWrapperFactory dwf, + SDBDatasetMode datasetMode, + WebappDaoFactoryJena wadf) { super(wadf); this.dwf = dwf; + this.datasetMode = datasetMode; } protected DatasetWrapper getDatasetWrapper() { @@ -61,7 +66,7 @@ public class IndividualDaoSDB extends IndividualDaoJena { } 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()); @@ -97,6 +102,7 @@ public class IndividualDaoSDB extends IndividualDaoJena { Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); try { + String[] graphVars = {"?g", "?h", "?i"}; String query = "SELECT DISTINCT ?ind ?label ?moniker " + "WHERE " + @@ -105,6 +111,7 @@ public class IndividualDaoSDB extends IndividualDaoJena { "} \n" + "OPTIONAL { GRAPH ?h { ?ind <" + RDFS.label.getURI() + "> ?label } }\n" + "OPTIONAL { GRAPH ?i { ?ind <" + VitroVocabulary.MONIKER + "> ?moniker } } \n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + "} ORDER BY ?label"; ResultSet rs =QueryExecutionFactory.create( QueryFactory.create(query), dataset) @@ -117,7 +124,7 @@ public class IndividualDaoSDB extends IndividualDaoJena { && !currRes.isAnon()) { res = currRes; Individual ent = new IndividualSDB(currRes.getURI(), - this.dwf, getWebappDaoFactory(), + this.dwf, datasetMode, getWebappDaoFactory(), SKIP_INITIALIZATION); Literal label = sol.getLiteral("label"); if (label != null) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java index a49ced467..cf9b802a4 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java @@ -2,8 +2,6 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena; -import java.io.UnsupportedEncodingException; -import java.net.URLDecoder; import java.sql.Timestamp; import java.text.Collator; 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.QuerySolution; 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.Model; 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.ResIterator; import com.hp.hpl.jena.rdf.model.Resource; import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.rdf.model.StmtIterator; import com.hp.hpl.jena.shared.Lock; 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.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.dao.VClassDao; 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.search.beans.ProhibitedFromSearch; import edu.cornell.mannlib.vitro.webapp.utils.FlagMathUtils; @@ -73,12 +67,16 @@ public class IndividualSDB extends IndividualImpl implements Individual { private Float _searchBoostJena = null; private boolean retreivedNullRdfsLabel = false; private DatasetWrapperFactory dwf = null; + private SDBDatasetMode datasetMode = + SDBDatasetMode.ASSERTIONS_AND_INFERENCES; private String individualURI = null; private Model model = null; public IndividualSDB(String individualURI, - DatasetWrapperFactory datasetWrapperFactory, - WebappDaoFactoryJena wadf, Model initModel) { + DatasetWrapperFactory datasetWrapperFactory, + SDBDatasetMode datasetMode, + WebappDaoFactoryJena wadf, + Model initModel) { this.individualURI = individualURI; this.dwf = datasetWrapperFactory; @@ -115,9 +113,11 @@ public class IndividualSDB extends IndividualImpl implements Individual { public IndividualSDB(String individualURI, DatasetWrapperFactory datasetWrapperFactory, + SDBDatasetMode datasetMode, WebappDaoFactoryJena wadf, boolean skipInitialization) { this.individualURI = individualURI; + this.datasetMode = datasetMode; this.dwf = datasetWrapperFactory; if (skipInitialization) { @@ -129,6 +129,7 @@ public class IndividualSDB extends IndividualImpl implements Individual { Dataset dataset = w.getDataset(); try { dataset.getLock().enterCriticalSection(Lock.READ); + String[] graphVars = {"?g", "?h", "?i"}; String getStatements = "CONSTRUCT " + "{ <"+individualURI+"> <" + RDFS.label.getURI() + @@ -146,6 +147,7 @@ public class IndividualSDB extends IndividualImpl implements Individual { "} } \n" + "UNION { GRAPH ?i { <" + individualURI + "> a ?type } } \n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + "}"; model = QueryExecutionFactory.create( QueryFactory.create(getStatements), dataset) @@ -167,9 +169,14 @@ public class IndividualSDB extends IndividualImpl implements Individual { private static final boolean SKIP_INITIALIZATION = true; public IndividualSDB(String individualURI, - DatasetWrapperFactory datasetWrapperFactory, + DatasetWrapperFactory datasetWrapperFactory, + SDBDatasetMode datasetMode, WebappDaoFactoryJena wadf) { - this(individualURI, datasetWrapperFactory, wadf, !SKIP_INITIALIZATION); + this(individualURI, + datasetWrapperFactory, + datasetMode, + wadf, + !SKIP_INITIALIZATION); } private void setUpURIParts(OntResource ind) { @@ -589,10 +596,13 @@ public class IndividualSDB extends IndividualImpl implements Individual { Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); try { + String[] graphVars = { "?g" }; String queryStr = "CONSTRUCT { ?ind <" + propertyURI + "> ?value } \n" + "WHERE { GRAPH ?g { ?ind <" + - propertyURI + "> ?value } } \n"; + propertyURI + "> ?value } \n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + + "\n} \n"; Query query = QueryFactory.create(queryStr); QueryExecution qe = QueryExecutionFactory.create( query, dataset); @@ -607,11 +617,14 @@ public class IndividualSDB extends IndividualImpl implements Individual { if( this._searchBoostJena != null ){ return this._searchBoostJena; }else{ + String[] graphVars = { "?g" }; String getPropertyValue = "SELECT ?value" + "WHERE { GRAPH ?g { <" + individualURI + ">" + webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT + - "?value} }"; + "?value} \n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + + "}"; DatasetWrapper w = getDatasetWrapper(); Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); @@ -704,6 +717,7 @@ public class IndividualSDB extends IndividualImpl implements Individual { Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); try { + String graphVars[] = { "?g" }; StringBuffer selectPrimaryLinkQueryBuff = new StringBuffer().append( "SELECT ?url ?anchor \n" ).append( "WHERE{ GRAPH ?g { \n " ).append( @@ -714,7 +728,9 @@ public class IndividualSDB extends IndividualImpl implements Individual { ).append( " ?link <" + VitroVocabulary.LINK_ANCHOR + "> ?anchor . \n" ).append( - "} }"); + "} \n") + .append(WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode)) + .append("}"); QueryExecution qexec = QueryExecutionFactory.create( QueryFactory.create(selectPrimaryLinkQueryBuff.toString()) , dataset); @@ -827,9 +843,12 @@ public class IndividualSDB extends IndividualImpl implements Individual { Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); try { + String[] graphVars = { "?g" }; String valuesOfProperty = "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(); ontModel.add(tempModel.listStatements()); 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)) { continue; } - Individual subj = new IndividualSDB(((OntResource) s.getSubject().as(OntResource.class)).getURI(), this.dwf, webappDaoFactory); - Individual obj = new IndividualSDB(((OntResource) s.getObject().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, datasetMode, webappDaoFactory); ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI()); if (subj != null && obj != null && op != null) { ObjectPropertyStatement ops = new ObjectPropertyStatementImpl(); @@ -873,10 +892,13 @@ public class IndividualSDB extends IndividualImpl implements Individual { Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); try { + String[] graphVars = { "?g" }; String valuesOfProperty = "SELECT ?object" + "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + - propertyURI + "> ?object} }"; + propertyURI + "> ?object} \n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + + "}"; ResultSet values = QueryExecutionFactory.create( QueryFactory.create(valuesOfProperty), dataset) .execSelect(); @@ -889,7 +911,9 @@ public class IndividualSDB extends IndividualImpl implements Individual { new IndividualSDB( ((OntResource) value.as(OntResource.class)) .getURI(), - this.dwf, webappDaoFactory) ); + this.dwf, + datasetMode, + webappDaoFactory) ); } } } finally { @@ -908,10 +932,13 @@ public class IndividualSDB extends IndividualImpl implements Individual { Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); try { + String[] graphVars = { "?g" }; String valueOfProperty = "SELECT ?object" + "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + - propertyURI + "> ?object} }"; + propertyURI + "> ?object} \n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + + "}"; ResultSet results = QueryExecutionFactory.create( QueryFactory.create(valueOfProperty), dataset).execSelect(); QuerySolution result = results.next(); @@ -919,7 +946,7 @@ public class IndividualSDB extends IndividualImpl implements Individual { if (value != null && value.canAs(OntResource.class)) { return new IndividualSDB( ((OntResource) value.as(OntResource.class)).getURI(), - dwf, webappDaoFactory); + dwf, datasetMode, webappDaoFactory); } else { return null; } @@ -1088,8 +1115,14 @@ public class IndividualSDB extends IndividualImpl implements Individual { ((direct) ? "" : "?g") - + " { <" + this.individualURI +"> <" +RDF.type+ "> ?types \n" + - "} } \n"; + + " { <" + this.individualURI +"> <" +RDF.type+ "> ?types } \n" ; + + if (!direct) { + String[] graphVars = { "?g" }; + getTypes += WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode); + } + + getTypes += "} \n"; DatasetWrapper w = getDatasetWrapper(); Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java index a93ab8ee0..30ca46f6b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java @@ -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.dao.ObjectPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode; public class ObjectPropertyStatementDaoSDB extends ObjectPropertyStatementDaoJena implements ObjectPropertyStatementDao { private DatasetWrapperFactory dwf; + private SDBDatasetMode datasetMode; public ObjectPropertyStatementDaoSDB( DatasetWrapperFactory dwf, + SDBDatasetMode datasetMode, WebappDaoFactoryJena wadf) { super (dwf, wadf); this.dwf = dwf; + this.datasetMode = datasetMode; } @Override @@ -46,6 +50,7 @@ public class ObjectPropertyStatementDaoSDB extends return entity; else { Map uriToObjectProperty = new HashMap(); + String[] graphVars = { "?g", "?h", "?i", "?j" }; String query = "CONSTRUCT { \n" + " <" + entity.getURI() + "> ?p ?o . \n" + " ?o a ?oType . \n" + @@ -56,7 +61,9 @@ public class ObjectPropertyStatementDaoSDB extends " OPTIONAL { GRAPH ?h { ?o a ?oType } } \n" + " OPTIONAL { GRAPH ?i { ?o <" + RDFS.label.getURI() + "> ?oLabel } } \n" + " OPTIONAL { GRAPH ?j { ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker } } \n" + - "} }"; + "} \n" + + WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode) + + "}"; long startTime = System.currentTimeMillis(); Model m = null; DatasetWrapper w = dwf.getDatasetWrapper(); @@ -119,6 +126,7 @@ public class ObjectPropertyStatementDaoSDB extends Individual objInd = new IndividualSDB( objPropertyStmt.getObjectURI(), this.dwf, + datasetMode, getWebappDaoFactory(), m); objPropertyStmt.setObject(objInd); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java index 22abb8910..e40668db1 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java @@ -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.VClassGroup; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; +import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode; public class VClassDaoSDB extends VClassDaoJena { private DatasetWrapperFactory dwf; + private SDBDatasetMode datasetMode; public VClassDaoSDB(DatasetWrapperFactory datasetWrapperFactory, - WebappDaoFactoryJena wadf) { + SDBDatasetMode datasetMode, + WebappDaoFactoryJena wadf) { super(wadf); this.dwf = datasetWrapperFactory; + this.datasetMode = datasetMode; } protected DatasetWrapper getDatasetWrapper() { @@ -60,8 +64,11 @@ public class VClassDaoSDB extends VClassDaoJena { aboxModel.enterCriticalSection(Lock.READ); int count = 0; try { + String[] graphVars = { "?g" }; 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); DatasetWrapper w = getDatasetWrapper(); Dataset dataset = w.getDataset(); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java index 769263327..5b98873f9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java @@ -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.VClassDao; import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; +import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase; public class WebappDaoFactorySDB extends WebappDaoFactoryJena { + private SDBDatasetMode datasetMode = SDBDatasetMode.ASSERTIONS_AND_INFERENCES; + /** * For use when any database connection associated with the Dataset * is managed externally - * @param ontModelSelector - * @param dataset */ public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset) { super(ontModelSelector); @@ -36,8 +37,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { /** * For use when any database connection associated with the Dataset * is managed externally - * @param ontModelSelector - * @param dataset */ public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset, @@ -51,8 +50,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { /** * For use when any Dataset access should get a temporary DB connection * from a pool - * @param ontModelSelector - * @param dataset */ public WebappDaoFactorySDB(OntModelSelector ontModelSelector, BasicDataSource bds, @@ -64,6 +61,23 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { 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 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) { super(base.ontModelSelector); this.ontModelSelector = base.ontModelSelector; @@ -81,7 +95,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { if (entityWebappDao != null) return entityWebappDao; else - return entityWebappDao = new IndividualDaoSDB(dwf, this); + return entityWebappDao = new IndividualDaoSDB( + dwf, datasetMode, this); } @Override @@ -89,7 +104,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { if (dataPropertyStatementDao != null) return dataPropertyStatementDao; else - return dataPropertyStatementDao = new DataPropertyStatementDaoSDB(dwf, this); + return dataPropertyStatementDao = new DataPropertyStatementDaoSDB( + dwf, datasetMode, this); } @Override @@ -97,7 +113,8 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { if (objectPropertyStatementDao != null) return objectPropertyStatementDao; else - return objectPropertyStatementDao = new ObjectPropertyStatementDaoSDB(dwf, this); + return objectPropertyStatementDao = + new ObjectPropertyStatementDaoSDB(dwf, datasetMode, this); } @Override @@ -105,7 +122,7 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { if (vClassDao != null) return vClassDao; else - return vClassDao = new VClassDaoSDB(dwf, this); + return vClassDao = new VClassDaoSDB(dwf, datasetMode, this); } public WebappDaoFactory getUserAwareDaoFactory(String userURI) { @@ -113,6 +130,40 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { 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 BasicDataSource _bds; diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupSDB.java index 01b347a44..89cf95385 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/servlet/setup/JenaDataSourceSetupSDB.java @@ -187,16 +187,28 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j ModelFactory.createUnion(baseOms.getABoxModel(), baseOms.getTBoxModel())); baseOms.setFullModel(baseUnion); ModelContext.setBaseOntModel(baseOms.getFullModel(), sce.getServletContext()); - WebappDaoFactory baseWadf = new WebappDaoFactorySDB(baseOms, bds, storeDesc, defaultNamespace, null, null); - //WebappDaoFactory baseWadf = new WebappDaoFactorySDB(baseOms, dataset, defaultNamespace, null, null); + WebappDaoFactory baseWadf = new WebappDaoFactorySDB( + baseOms, + bds, + storeDesc, + defaultNamespace, + null, + null, + WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY); sce.getServletContext().setAttribute("assertionsWebappDaoFactory",baseWadf); OntModel inferenceUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, ModelFactory.createUnion(inferenceOms.getABoxModel(), inferenceOms.getTBoxModel())); inferenceOms.setFullModel(inferenceUnion); ModelContext.setInferenceOntModel(inferenceOms.getFullModel(), sce.getServletContext()); - WebappDaoFactory infWadf = new WebappDaoFactorySDB(inferenceOms, bds, storeDesc, defaultNamespace, null, null); - //WebappDaoFactory infWadf = new WebappDaoFactorySDB(inferenceOms, dataset, defaultNamespace, null, null); + WebappDaoFactory infWadf = new WebappDaoFactorySDB( + inferenceOms, + bds, + storeDesc, + defaultNamespace, + null, + null, + WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY); sce.getServletContext().setAttribute("deductionsWebappDaoFactory", infWadf); OntModel masterUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,