NIHVIVO-2717 fixed graph keyword tokenization bug and switched WebappDaoFactorySDBPrep to set SDB union graph as JenaOntModel

This commit is contained in:
brianjlowe 2011-06-20 19:56:19 +00:00
parent 8170eadaa3
commit 1dd7d3c1d1
6 changed files with 29 additions and 29 deletions

View file

@ -151,18 +151,13 @@ public class SparqlQueryServlet extends BaseEditController {
String queryParam = vreq.getParameter("query");
boolean graphPresent = false;
StringTokenizer tokenizer = new StringTokenizer(queryParam, " ");
while(tokenizer.hasMoreTokens()){
if("graph".equalsIgnoreCase(tokenizer.nextToken())){
graphPresent = true;
break;
String[] tokens = queryParam.split("\\s");
for(int i = 0; i < tokens.length; i++){
if("graph".equalsIgnoreCase(tokens[i])){
return vreq.getDataset();
}
}
Dataset dataset = vreq.getDataset();
if (dataset != null && graphPresent) {
return dataset;
}
DataSource dataSource = DatasetFactory.create();
dataSource.setDefaultModel(vreq.getJenaOntModel());
return dataSource;

View file

@ -70,6 +70,10 @@ public class VitroRequest extends HttpServletRequestWrapper {
setAttribute("dataset", dataset);
}
public void setJenaOntModel(OntModel ontModel) {
setAttribute("jenaOntModel", ontModel);
}
/** gets assertions + inferences WebappDaoFactory with no filtering **/
public WebappDaoFactory getFullWebappDaoFactory() {
Object webappDaoFactoryAttr = _req.getAttribute("fullWebappDaoFactory");
@ -106,6 +110,10 @@ public class VitroRequest extends HttpServletRequestWrapper {
}
public OntModel getJenaOntModel() {
Object ontModel = getAttribute("jenaOntModel");
if (ontModel instanceof OntModel) {
return (OntModel) ontModel;
}
OntModel jenaOntModel = (OntModel)_req.getSession().getAttribute( JenaBaseDao.JENA_ONT_MODEL_ATTRIBUTE_NAME );
if ( jenaOntModel == null ) {
jenaOntModel = (OntModel)_req.getSession().getServletContext().getAttribute( JenaBaseDao.JENA_ONT_MODEL_ATTRIBUTE_NAME );

View file

@ -334,13 +334,7 @@ public class IndividualController extends FreemarkerHttpServlet {
private ResponseValues doRdf(VitroRequest vreq, Individual individual,
ContentType rdfFormat) throws IOException, ServletException {
OntModel ontModel = null;
HttpSession session = vreq.getSession(false);
if( session != null )
ontModel = (OntModel)session.getAttribute("jenaOntModel");
if( ontModel == null)
ontModel = (OntModel)getServletContext().getAttribute("jenaOntModel");
OntModel ontModel = vreq.getJenaOntModel();
String[] includes = vreq.getParameterValues("include");
Model newModel = getRDF(individual,ontModel,ModelFactory.createDefaultModel(),0,includes);

View file

@ -933,21 +933,18 @@ public class IndividualSDB extends IndividualImpl implements Individual {
if (ind.getModel().contains((Resource) null, RDF.type, (RDFNode) null)){
tempModel = ind.getModel();
} else {
String[] graphVars = { "?g" };
String getTypes =
"CONSTRUCT{ <" + this.individualURI + "> <" + RDF.type +
"> ?types }\n" +
"WHERE{ GRAPH " +
((direct)
? "<http://vitro.mannlib.cornell.edu/default/vitro-kb-2>"
: "?g")
+ " { <" + this.individualURI +"> <" +RDF.type+ "> ?types } \n" ;
if (!direct) {
String[] graphVars = { "?g" };
getTypes += WebappDaoFactorySDB.getFilterBlock(graphVars, datasetMode);
}
getTypes += "} \n";
"WHERE{ GRAPH ?g"
+ " { <" + this.individualURI +"> <" +RDF.type+ "> ?types } \n"
+ WebappDaoFactorySDB.getFilterBlock(
graphVars, (direct
? WebappDaoFactorySDB.SDBDatasetMode
.ASSERTIONS_ONLY
: datasetMode))
+ "} \n";
DatasetWrapper w = getDatasetWrapper();
Dataset dataset = w.getDataset();
dataset.getLock().enterCriticalSection(Lock.READ);

View file

@ -23,6 +23,7 @@ import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
public static final String UNION_GRAPH = "urn:x-arq:UnionGraph";
private SDBDatasetMode datasetMode = SDBDatasetMode.ASSERTIONS_AND_INFERENCES;
/**

View file

@ -21,7 +21,9 @@ import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ModelFactory;
import com.hp.hpl.jena.sdb.SDBFactory;
import com.hp.hpl.jena.sdb.Store;
import com.hp.hpl.jena.sdb.StoreDesc;
@ -106,6 +108,9 @@ public class WebappDaoFactorySDBPrep implements Filter {
vreq.setWebappDaoFactory(wadf);
vreq.setFullWebappDaoFactory(wadf);
vreq.setDataset(dataset);
vreq.setJenaOntModel(ModelFactory.createOntologyModel(
OntModelSpec.OWL_MEM, dataset.getNamedModel(
WebappDaoFactorySDB.UNION_GRAPH)));
}
} catch (Throwable t) {
log.error("Unable to filter request to set up SDB connection", t);