Refactorings to improve RDFService and Models setups.

Create ModelNames, and centralize all of the references to model names there.
Separate JenaPersistentDataSourceSetup from JenaDataSourceSetupBase. Refactor.
Remove SpecialBulkUpdatingGraph. - not used
This commit is contained in:
Jim Blake 2014-06-20 15:20:31 -04:00
parent 59ddbe15ec
commit c53dd9ea70
22 changed files with 233 additions and 529 deletions

View file

@ -51,8 +51,8 @@ import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.FileGraphSetup;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
public class RefactorOperationController extends BaseEditController {
@ -234,10 +234,10 @@ public class RefactorOperationController extends BaseEditController {
boolean doNotify = false;
Model model = null;
if (JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL.equals(graphURI)) {
if (ModelNames.TBOX_ASSERTIONS.equals(graphURI)) {
model = ModelAccess.on(getServletContext()).getOntModel(ModelID.BASE_TBOX);
doNotify = true;
} else if (JenaDataSourceSetupBase.JENA_DB_MODEL.equals(graphURI)) {
} else if (ModelNames.ABOX_ASSERTIONS.equals(graphURI)) {
model = ModelAccess.on(getServletContext()).getOntModel(ModelID.BASE_ABOX);
doNotify = true;
} else {

View file

@ -32,10 +32,10 @@ import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaOutputUtils;
public class JenaExportController extends BaseEditController {
@ -157,7 +157,7 @@ public class JenaExportController extends BaseEditController {
else if("full".equals(subgraphParam)){
if("inferred".equals(assertedOrInferredParam)){
ontModel = xutil.extractTBox(
dataset, ontologyURI, INFERENCE_GRAPH);
dataset, ontologyURI, ModelNames.ABOX_INFERENCES);
ontModel.addSubModel(ModelAccess.on(getServletContext()).getOntModel(ModelID.INFERRED_ABOX));
ontModel.addSubModel(ModelAccess.on(getServletContext()).getOntModel(ModelID.INFERRED_TBOX));
}
@ -278,9 +278,6 @@ public class JenaExportController extends BaseEditController {
}
static final String FULL_GRAPH = "?g";
static final String ASSERTIONS_GRAPH = "<http://vitro.mannlib.cornell.edu/default/vitro-kb-2>";
static final String INFERENCE_GRAPH = "<http://vitro.mannlib.cornell.edu/default/vitro-kb-inf>";
static Map<String,String> formatToExtension;
static Map<String,String> formatToMimetype;
@ -304,13 +301,13 @@ public class JenaExportController extends BaseEditController {
private static final String ABOX_FULL_CONSTRUCT = "CONSTRUCT { ?s ?p ?o } " +
"WHERE { GRAPH ?g { ?s ?p ?o } FILTER (!regex(str(?g), \"tbox\")) " +
"FILTER (?g != <" + JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL + ">) " +
"FILTER (?g != <" + ModelNames.APPLICATION_METADATA + ">) " +
"FILTER (?g != <" + RDFServiceModelMaker.METADATA_MODEL_URI + ">) }";
private static final String ABOX_ASSERTED_CONSTRUCT = "CONSTRUCT { ?s ?p ?o } " +
"WHERE { GRAPH ?g { ?s ?p ?o } FILTER (!regex(str(?g), \"tbox\")) " +
"FILTER (?g != <" + JenaDataSourceSetupBase.JENA_INF_MODEL + ">) " +
"FILTER (?g != <" + JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL + ">) " +
"FILTER (?g != <" + ModelNames.ABOX_INFERENCES + ">) " +
"FILTER (?g != <" + ModelNames.APPLICATION_METADATA + ">) " +
"FILTER (?g != <" + RDFServiceModelMaker.METADATA_MODEL_URI + ">) }";
private static final String FULL_FULL_CONSTRUCT = "CONSTRUCT { ?s ?p ?o } " +
@ -318,7 +315,7 @@ public class JenaExportController extends BaseEditController {
private static final String FULL_ASSERTED_CONSTRUCT = "CONSTRUCT { ?s ?p ?o } " +
"WHERE { GRAPH ?g { ?s ?p ?o } " +
"FILTER (?g != <" + JenaDataSourceSetupBase.JENA_INF_MODEL + ">) " +
"FILTER (?g != <" + JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL + ">) }";
"FILTER (?g != <" + ModelNames.ABOX_INFERENCES + ">) " +
"FILTER (?g != <" + ModelNames.TBOX_INFERENCES + ">) }";
}

View file

@ -16,7 +16,6 @@ import java.net.URISyntaxException;
import java.text.Collator;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.HashMap;
import java.util.Iterator;
@ -56,7 +55,6 @@ 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.sdb.store.DatabaseType;
import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.util.iterator.ClosableIterator;
@ -65,18 +63,17 @@ import edu.cornell.mannlib.vitro.webapp.auth.permissions.SimplePermission;
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
import edu.cornell.mannlib.vitro.webapp.controller.VitroRequest;
import edu.cornell.mannlib.vitro.webapp.controller.freemarker.UrlBuilder;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID;
import edu.cornell.mannlib.vitro.webapp.dao.OntologyDao;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.utils.SparqlQueryUtils;
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils.MergeResult;
@ -1079,7 +1076,7 @@ public class JenaIngestController extends BaseEditController {
try {
Model baseOntModel = RDFServiceGraph.createRDFServiceModel
(new RDFServiceGraph(
rdfService, JenaDataSourceSetupBase.JENA_DB_MODEL));
rdfService, ModelNames.ABOX_ASSERTIONS));
OntModel ontModel = ModelAccess.on(getServletContext()).getJenaOntModel();
List<String> urisToChange = new LinkedList<String>();
ontModel.enterCriticalSection(Lock.READ);
@ -1118,7 +1115,7 @@ public class JenaIngestController extends BaseEditController {
log.debug("Renaming "+ oldURIStr + " to " + newURIStr);
String whereClause = "} WHERE { \n" +
" GRAPH <" + JenaDataSourceSetupBase.JENA_DB_MODEL + "> { \n" +
" GRAPH <" + ModelNames.ABOX_ASSERTIONS + "> { \n" +
" { <" + oldURIStr + "> ?p <" + oldURIStr + "> } \n " +
" UNION \n" +
" { <" + oldURIStr + "> ?q ?o } \n " +
@ -1141,11 +1138,11 @@ public class JenaIngestController extends BaseEditController {
cs.addAddition(rdfService.sparqlConstructQuery(
addQuery, RDFService.ModelSerializationFormat.N3),
RDFService.ModelSerializationFormat.N3,
JenaDataSourceSetupBase.JENA_DB_MODEL);
ModelNames.ABOX_ASSERTIONS);
cs.addRemoval(rdfService.sparqlConstructQuery(
removeQuery, RDFService.ModelSerializationFormat.N3),
RDFService.ModelSerializationFormat.N3,
JenaDataSourceSetupBase.JENA_DB_MODEL);
ModelNames.ABOX_ASSERTIONS);
rdfService.changeSetUpdate(cs);
} catch (RDFServiceException e) {
throw new RuntimeException(e);

View file

@ -2,8 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.controller.jena;
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONFIGURATION;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@ -45,12 +43,12 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceGraph;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.BulkUpdateEvent;
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
public class RDFUploadController extends JenaIngestController {
@ -236,7 +234,7 @@ public class RDFUploadController extends JenaIngestController {
? RDFService.ModelSerializationFormat.RDFXML
: RDFService.ModelSerializationFormat.N3;
changeSet.addAddition(in, format,
JenaDataSourceSetupBase.JENA_DB_MODEL);
ModelNames.ABOX_ASSERTIONS);
try {
rdfService.changeSetUpdate(changeSet);
} catch (RDFServiceException rdfse) {
@ -437,7 +435,7 @@ public class RDFUploadController extends JenaIngestController {
private OntModel getABoxModel(HttpSession session, ServletContext ctx) {
RDFService rdfService = RDFServiceUtils.getRDFServiceFactory(ctx).getRDFService();
Model abox = RDFServiceGraph.createRDFServiceModel(
new RDFServiceGraph(rdfService, JenaDataSourceSetupBase.JENA_DB_MODEL));
new RDFServiceGraph(rdfService, ModelNames.ABOX_ASSERTIONS));
return ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, abox);
}

View file

@ -15,10 +15,6 @@ public class DisplayVocabulary {
/** <p>The ontology model that holds the vocabulary terms</p> */
private static OntModel m_model = ModelFactory.createOntologyModel( OntModelSpec.OWL_MEM, null );
/*Uris for Models for Display*/
public static final String DISPLAY_TBOX_MODEL_URI = "http://vitro.mannlib.cornell.edu/default/vitro-kb-displayMetadataTBOX";
public static final String DISPLAY_DISPLAY_MODEL_URI = "http://vitro.mannlib.cornell.edu/default/vitro-kb-displayMetadata-displayModel";
/* Namespace for display vocabulary */
public static final String DISPLAY_NS = "http://vitro.mannlib.cornell.edu/ontologies/display/1.1#";
private static final String NS = DISPLAY_NS;

View file

@ -39,7 +39,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
* VitroModelSource.openModel(name)
* VitroModelSource.openModelIfPresent(string)
* ServletContext.getAttribute("pelletOntModel")
* JenaDataSourceSetupBase.getApplicationDataSource(ctx)
* JenaDataSourceSetupBase.getStartupDataset()
* HttpSession.getAttribute("jenaAuditModel")
* </pre>

View file

@ -4,15 +4,15 @@ package edu.cornell.mannlib.vitro.webapp.dao.jena;
import com.hp.hpl.jena.rdf.model.ModelChangedListener;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
public class ABoxJenaChangeListener extends JenaChangeListener {
public ABoxJenaChangeListener(ModelChangedListener listener) {
super(listener);
ignoredGraphs.add(JenaDataSourceSetupBase.JENA_INF_MODEL);
ignoredGraphs.add(JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
ignoredGraphs.add(JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL);
ignoredGraphs.add(ModelNames.ABOX_INFERENCES);
ignoredGraphs.add(ModelNames.TBOX_ASSERTIONS);
ignoredGraphs.add(ModelNames.TBOX_INFERENCES);
}
@Override
@ -31,7 +31,7 @@ public class ABoxJenaChangeListener extends JenaChangeListener {
private boolean isABoxGraph(String graphURI) {
return (graphURI == null ||
JenaDataSourceSetupBase.JENA_DB_MODEL.equals(graphURI)
ModelNames.ABOX_ASSERTIONS.equals(graphURI)
|| (!ignoredGraphs.contains(graphURI)
&& !graphURI.contains("filegraph")
&& !graphURI.contains("tbox")));

View file

@ -45,9 +45,9 @@ import edu.cornell.mannlib.vitro.webapp.beans.VClass;
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.IndividualSDB.IndividualNotFoundException;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceException;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
public class IndividualDaoSDB extends IndividualDaoJena {
@ -448,8 +448,7 @@ public class IndividualDaoSDB extends IndividualDaoJena {
" UNION { " +
" GRAPH ?g { ?ind <" + RDFS.label.getURI() +
"> ?label } \n" +
" FILTER (?g != <" + JenaDataSourceSetupBase
.JENA_APPLICATION_METADATA_MODEL + "> " +
" FILTER (?g != <" + ModelNames.APPLICATION_METADATA + "> " +
" && !regex(str(?g),\"tbox\")) \n " +
" } " +
"}";

View file

@ -48,9 +48,9 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.model.RDFServiceModel;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.utils.jena.URIUtils;
public class WebappDaoFactoryJena implements WebappDaoFactory {
@ -158,11 +158,11 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
OntModel union = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM);
if (assertions != null) {
dataset.addNamedModel(
JenaDataSourceSetupBase.JENA_DB_MODEL, assertions);
ModelNames.ABOX_ASSERTIONS, assertions);
union.addSubModel(assertions);
}
if (inferences != null) {
dataset.addNamedModel(JenaDataSourceSetupBase.JENA_INF_MODEL,
dataset.addNamedModel(ModelNames.ABOX_INFERENCES,
inferences);
union.addSubModel(inferences);
}

View file

@ -19,8 +19,8 @@ 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.dao.WebappDaoFactoryConfig;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.SimpleReasonerSetup;
public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
@ -117,10 +117,10 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
.append(")) || (")
.append(graphVars[i])
.append(" != <")
.append(JenaDataSourceSetupBase.JENA_INF_MODEL)
.append(ModelNames.ABOX_INFERENCES)
.append("> ")
.append("&& ").append(graphVars[i]).append(" != <")
.append(JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL)
.append(ModelNames.TBOX_INFERENCES)
.append(">")
.append("&& ").append(graphVars[i]).append(" != <")
.append(SimpleReasonerSetup.JENA_INF_MODEL_REBUILD)
@ -136,10 +136,10 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
.append(")) || (")
.append(graphVars[i])
.append(" = <")
.append(JenaDataSourceSetupBase.JENA_INF_MODEL)
.append(ModelNames.ABOX_INFERENCES)
.append("> || ").append(graphVars[i])
.append(" = <")
.append(JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL)
.append(ModelNames.TBOX_INFERENCES)
.append(">) )\n");
break;
default:

View file

@ -2,9 +2,6 @@
package edu.cornell.mannlib.vitro.webapp.filters;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_DB_MODEL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_INF_MODEL;
import java.io.IOException;
import java.text.Collator;
import java.util.Enumeration;
@ -29,7 +26,6 @@ import org.apache.commons.logging.LogFactory;
import org.apache.jena.atlas.lib.Pair;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.ontology.OntModelSpec;
import com.hp.hpl.jena.query.Dataset;
//import com.hp.hpl.jena.rdf.model.ModelFactory;
@ -51,6 +47,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelectorImpl;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB.SDBDatasetMode;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringRDFService;
@ -195,9 +192,9 @@ public class RequestModelsPrep implements Filter {
// Anything derived from the ABOX is not memory-mapped, so create
// versions from the short-term RDF service.
OntModel baseABoxModel = VitroModelFactory.createOntologyModel(dataset
.getNamedModel(JENA_DB_MODEL));
.getNamedModel(ModelNames.ABOX_ASSERTIONS));
OntModel inferenceABoxModel = VitroModelFactory
.createOntologyModel(dataset.getNamedModel(JENA_INF_MODEL));
.createOntologyModel(dataset.getNamedModel(ModelNames.ABOX_INFERENCES));
OntModel unionABoxModel = VitroModelFactory.createUnion(
baseABoxModel, inferenceABoxModel);

View file

@ -0,0 +1,18 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.modelaccess;
/**
* A central place to record the URIs of the models that we rely on.
*/
public class ModelNames {
public static final String ABOX_ASSERTIONS = "http://vitro.mannlib.cornell.edu/default/vitro-kb-2";
public static final String ABOX_INFERENCES = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf";
public static final String TBOX_ASSERTIONS = "http://vitro.mannlib.cornell.edu/default/asserted-tbox";
public static final String TBOX_INFERENCES = "http://vitro.mannlib.cornell.edu/default/inferred-tbox";
public static final String USER_ACCOUNTS = "http://vitro.mannlib.cornell.edu/default/vitro-kb-userAccounts";
public static final String DISPLAY = "http://vitro.mannlib.cornell.edu/default/vitro-kb-displayMetadata";
public static final String DISPLAY_TBOX = "http://vitro.mannlib.cornell.edu/default/vitro-kb-displayMetadataTBOX";
public static final String DISPLAY_DISPLAY = "http://vitro.mannlib.cornell.edu/default/vitro-kb-displayMetadata-displayModel";
public static final String APPLICATION_METADATA = "http://vitro.mannlib.cornell.edu/default/vitro-kb-applicationMetadata";
}

View file

@ -31,6 +31,7 @@ import com.hp.hpl.jena.rdf.model.Statement;
import com.hp.hpl.jena.rdf.model.StmtIterator;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.ChangeSet;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService.ModelSerializationFormat;
@ -238,7 +239,7 @@ public class KnowledgeBaseUpdater {
record.recordRetractions(anonModel);
//log.info("removed " + anonModel.size() + " statements from SPARQL CONSTRUCTs");
} else {
Model writeModel = dataset.getNamedModel(JenaDataSourceSetupBase.JENA_DB_MODEL);
Model writeModel = dataset.getNamedModel(ModelNames.ABOX_ASSERTIONS);
Model dedupeModel = dataset.getDefaultModel();
Model additions = jiu.renameBNodes(
anonModel, settings.getDefaultNamespace() + "n", dedupeModel);
@ -385,7 +386,7 @@ public class KnowledgeBaseUpdater {
ChangeSet changeSet = rdfService.manufactureChangeSet();
File successAssertionsFile = new File(settings.getSuccessAssertionsFile());
InputStream inStream = new FileInputStream(successAssertionsFile);
changeSet.addAddition(inStream, RDFService.ModelSerializationFormat.N3, JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL);
changeSet.addAddition(inStream, RDFService.ModelSerializationFormat.N3, ModelNames.APPLICATION_METADATA);
rdfService.changeSetUpdate(changeSet);
} catch (Exception e) {
log.error("unable to make RDF assertions about successful " +

View file

@ -1,132 +0,0 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.rdfservice.adapters;
import com.hp.hpl.jena.graph.BulkUpdateHandler;
import com.hp.hpl.jena.graph.Capabilities;
import com.hp.hpl.jena.graph.Graph;
import com.hp.hpl.jena.graph.GraphEventManager;
import com.hp.hpl.jena.graph.GraphStatisticsHandler;
import com.hp.hpl.jena.graph.Node;
import com.hp.hpl.jena.graph.TransactionHandler;
import com.hp.hpl.jena.graph.Triple;
import com.hp.hpl.jena.graph.TripleMatch;
import com.hp.hpl.jena.shared.AddDeniedException;
import com.hp.hpl.jena.shared.DeleteDeniedException;
import com.hp.hpl.jena.shared.PrefixMapping;
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
/**
* This Graph wrapper uses a BulkUpdatingHandler different from the one owned by
* the wrapped Graph.
*/
public class SpecialBulkUpdatingGraph implements Graph {
private Graph g;
private BulkUpdateHandler b;
public SpecialBulkUpdatingGraph(Graph g, BulkUpdateHandler b) {
this.g = g;
this.b = b;
}
@Override
public void add(Triple arg0) throws AddDeniedException {
g.add(arg0);
}
@Override
public void close() {
g.close();
}
@Override
public boolean contains(Node arg0, Node arg1, Node arg2) {
return g.contains(arg0, arg1, arg2);
}
@Override
public boolean contains(Triple arg0) {
return g.contains(arg0);
}
@Override
public void delete(Triple arg0) throws DeleteDeniedException {
g.delete(arg0);
}
@Override
public boolean dependsOn(Graph arg0) {
return g.dependsOn(arg0);
}
@Override
public ExtendedIterator<Triple> find(Node arg0, Node arg1, Node arg2) {
return g.find(arg0, arg1, arg2);
}
@Override
public ExtendedIterator<Triple> find(TripleMatch arg0) {
return g.find(arg0);
}
@Override
public BulkUpdateHandler getBulkUpdateHandler() {
return b;
}
@Override
public Capabilities getCapabilities() {
return g.getCapabilities();
}
@Override
public GraphEventManager getEventManager() {
return g.getEventManager();
}
@Override
public PrefixMapping getPrefixMapping() {
return g.getPrefixMapping();
}
@Override
public GraphStatisticsHandler getStatisticsHandler() {
return g.getStatisticsHandler();
}
@Override
public TransactionHandler getTransactionHandler() {
return g.getTransactionHandler();
}
@Override
public boolean isClosed() {
return g.isClosed();
}
@Override
public boolean isEmpty() {
return g.isEmpty();
}
@Override
public boolean isIsomorphicWith(Graph arg0) {
return g.isIsomorphicWith(arg0);
}
@Override
public int size() {
return g.size();
}
@Override
public void clear() {
g.clear();
}
@Override
public void remove(Node arg0, Node arg1, Node arg2) {
g.remove(arg0, arg1, arg2);
}
}

View file

@ -10,7 +10,7 @@ import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.rdf.listeners.StatementListener;
import com.hp.hpl.jena.rdf.model.Statement;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.utils.threads.VitroBackgroundThread;
/**
@ -50,14 +50,14 @@ public class SimpleReasonerTBoxListener extends StatementListener {
@Override
public void addedStatement(Statement statement) {
ModelUpdate mu = new ModelUpdate(statement, ModelUpdate.Operation.ADD, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
ModelUpdate mu = new ModelUpdate(statement, ModelUpdate.Operation.ADD, ModelNames.TBOX_ASSERTIONS);
processUpdate(mu);
}
@Override
public void removedStatement(Statement statement) {
ModelUpdate mu = new ModelUpdate(statement, ModelUpdate.Operation.RETRACT, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
ModelUpdate mu = new ModelUpdate(statement, ModelUpdate.Operation.RETRACT, ModelNames.TBOX_ASSERTIONS);
processUpdate(mu);
}

View file

@ -16,6 +16,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID;
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
@ -24,31 +25,26 @@ import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/**
* Set up the models that use the CONFIGURATION RDFService. They are all mapped
* to memory-based models.
*
* TODO This should be divorced from JenaDataSourceSetupBase, which it only uses
* for constants.
*/
public class ConfigurationModelsSetup extends JenaDataSourceSetupBase implements
ServletContextListener {
public class ConfigurationModelsSetup implements ServletContextListener {
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
try {
setupModel(ctx, JENA_DISPLAY_METADATA_MODEL, "display",
setupModel(ctx, ModelNames.DISPLAY, "display",
ModelID.DISPLAY);
setupModel(ctx, JENA_DISPLAY_TBOX_MODEL, "displayTbox",
setupModel(ctx, ModelNames.DISPLAY_TBOX, "displayTbox",
ModelID.DISPLAY_TBOX);
setupModel(ctx, JENA_DISPLAY_DISPLAY_MODEL, "displayDisplay",
setupModel(ctx, ModelNames.DISPLAY_DISPLAY, "displayDisplay",
ModelID.DISPLAY_DISPLAY);
ss.info(this, "Set up the display models.");
setupModel(ctx, JENA_USER_ACCOUNTS_MODEL, "auth",
setupModel(ctx, ModelNames.USER_ACCOUNTS, "auth",
ModelID.USER_ACCOUNTS);
ss.info(this, "Set up the user accounts model.");

View file

@ -33,6 +33,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelSynchronizer;
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactorySDB;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.adapters.VitroModelFactory;
@ -63,16 +64,16 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
Dataset dataset = new RDFServiceDataset(rdfService);
setStartupDataset(dataset, ctx);
OntModel applicationMetadataModel = createdMemoryMappedModel(dataset, JENA_APPLICATION_METADATA_MODEL, "application metadata model");
OntModel applicationMetadataModel = createdMemoryMappedModel(dataset, ModelNames.APPLICATION_METADATA, "application metadata model");
if (applicationMetadataModel.size()== 0) {
JenaDataSourceSetupBase.thisIsFirstStartup();
}
ModelAccess models = ModelAccess.on(ctx);
OntModel baseABoxModel = createNamedModelFromDataset(dataset, JENA_DB_MODEL);
OntModel inferenceABoxModel = createNamedModelFromDataset(dataset, JENA_INF_MODEL);
OntModel baseTBoxModel = createdMemoryMappedModel(dataset, JENA_TBOX_ASSERTIONS_MODEL, "tbox assertions");
OntModel inferenceTBoxModel = createdMemoryMappedModel(dataset, JENA_TBOX_INF_MODEL, "tbox inferences");
OntModel baseABoxModel = createNamedModelFromDataset(dataset, ModelNames.ABOX_ASSERTIONS);
OntModel inferenceABoxModel = createNamedModelFromDataset(dataset, ModelNames.ABOX_INFERENCES);
OntModel baseTBoxModel = createdMemoryMappedModel(dataset, ModelNames.TBOX_ASSERTIONS, "tbox assertions");
OntModel inferenceTBoxModel = createdMemoryMappedModel(dataset, ModelNames.TBOX_INFERENCES, "tbox inferences");
OntModel unionABoxModel = VitroModelFactory.createUnion(baseABoxModel, inferenceABoxModel);
OntModel unionTBoxModel = VitroModelFactory.createUnion(baseTBoxModel, inferenceTBoxModel);

View file

@ -2,261 +2,25 @@
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
import java.beans.PropertyVetoException;
import javax.servlet.ServletContext;
import javax.sql.DataSource;
import org.apache.commons.dbcp.BasicDataSource;
import org.apache.commons.lang.StringUtils;
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.sdb.Store;
import com.hp.hpl.jena.sdb.StoreDesc;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.dao.DisplayVocabulary;
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDaoCon;
public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
private static final Log log = LogFactory.getLog(
JenaDataSourceSetupBase.class);
private static final String VITRO_DEFAULT_NAMESPACE = "Vitro.defaultNamespace";
private static final Log log = LogFactory.getLog(
JenaDataSourceSetupBase.class);
protected final static String MAX_ACTIVE_PROPERTY =
"VitroConnection.DataSource.pool.maxActive";
protected final static String MAX_IDLE_PROPERTY =
"VitroConnection.DataSource.pool.maxIdle";
protected final static int DEFAULT_MAXWAIT = 10000, // ms
DEFAULT_MAXACTIVE = 40,
MINIMUM_MAXACTIVE = 20,
DEFAULT_MAXIDLE = 10,
DEFAULT_TIMEBETWEENEVICTIONS = 180 * 1000, // ms
DEFAULT_TESTSPEREVICTION = DEFAULT_MAXACTIVE,
DEFAULT_MINEVICTIONIDLETIME = 180 * 1000; // ms
private static boolean firstStartup = false;
protected final static boolean DEFAULT_TESTONBORROW = true,
DEFAULT_TESTONRETURN = true, DEFAULT_TESTWHILEIDLE = true;
protected static boolean firstStartup = false;
String DB_USER = "jenatest"; // database user id
String DB_PASSWD = "jenatest"; // database password
// ABox assertions. These are stored in a database (Jena SDB) and the
// application works (queries and updates) with the ABox data from the DB -
// this model is not maintained in memory. For query performance reasons,
// there won't be any submodels for the ABox data.
public static final String JENA_DB_MODEL =
"http://vitro.mannlib.cornell.edu/default/vitro-kb-2";
// ABox inferences. This is ABox data that is inferred, using VIVO's native
// simple, specific-purpose reasoning based on the combination of the ABox
// (assertion and inferences) data and the TBox (assertions and inferences)
// data.
public static final String JENA_INF_MODEL =
"http://vitro.mannlib.cornell.edu/default/vitro-kb-inf";
// TBox assertions.
// Some of these (the local extensions) are stored and maintained in a Jena
// database and are also maintained in memory while the application is
// running. Other parts of the TBox, the 'VIVO Core,' are also backed by a
// Jena DB, but they are read fresh from files each time the application
// starts. While the application is running, they are kept in memory, as
// submodels of the in memory copy of this named graph.
public static final String JENA_TBOX_ASSERTIONS_MODEL =
"http://vitro.mannlib.cornell.edu/default/asserted-tbox";
// Inferred TBox. This is TBox data that is inferred from the combination of
// VIVO core TBox and any local extension TBox assertions. Pellet computes
// these inferences. These are stored in the DB.
public static final String JENA_TBOX_INF_MODEL =
"http://vitro.mannlib.cornell.edu/default/inferred-tbox";
// Model for tracking edit changes. Obsolete.
static final String JENA_AUDIT_MODEL =
"http://vitro.mannlib.cornell.edu/ns/db/experimental/audit";
// User accounts data
public static final String JENA_USER_ACCOUNTS_MODEL =
"http://vitro.mannlib.cornell.edu/default/vitro-kb-userAccounts";
// This model doesn't exist yet. It's a placeholder for the application
// ontology.
public static final String JENA_APPLICATION_METADATA_MODEL =
"http://vitro.mannlib.cornell.edu/default/vitro-kb-applicationMetadata";
// This is Brian C's application.owl file. We may not have to be concerned
// with this for release 1.2.
public static final String JENA_DISPLAY_METADATA_MODEL =
"http://vitro.mannlib.cornell.edu/default/vitro-kb-displayMetadata";
//TBox and display model related
public static final String JENA_DISPLAY_TBOX_MODEL =
DisplayVocabulary.DISPLAY_TBOX_MODEL_URI;
public static final String JENA_DISPLAY_DISPLAY_MODEL =
DisplayVocabulary.DISPLAY_DISPLAY_MODEL_URI;
// use OWL models with no reasoning
static final OntModelSpec DB_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
static final OntModelSpec MEM_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
protected String getJdbcUrl(ServletContext ctx) {
String jdbcUrl = ConfigurationProperties.getBean(ctx).getProperty(
"VitroConnection.DataSource.url");
// Ensure that MySQL handles unicode properly, else all kinds of
// horrible nastiness ensues.
if ("MySQL".equals(getDbType(ctx)) && !jdbcUrl.contains("?")) {
jdbcUrl += "?useUnicode=yes&characterEncoding=utf8";
}
return jdbcUrl;
}
/**
* Sets up a DataSource using values from
* a properties file.
*/
protected final DataSource makeDataSourceFromConfigurationProperties(
ServletContext ctx) {
String dbDriverClassname = ConfigurationProperties.getBean(ctx)
.getProperty("VitroConnection.DataSource.driver",
getDbDriverClassName(ctx));
String jdbcUrl = getJdbcUrl(ctx);
String username = ConfigurationProperties.getBean(ctx).getProperty(
"VitroConnection.DataSource.username");
String password = ConfigurationProperties.getBean(ctx).getProperty(
"VitroConnection.DataSource.password");
return makeC3poDataSource(
dbDriverClassname, jdbcUrl, username, password, ctx);
// makeBasicDataSource(
// dbDriverClassname, jdbcUrl, username, password, ctx);
}
public void setApplicationDataSource(DataSource ds,
ServletContext ctx) {
ctx.setAttribute(getDataSourceAttributeName(), ds);
}
public static DataSource getApplicationDataSource(ServletContext ctx) {
return (DataSource) ctx.getAttribute(getDataSourceAttributeName());
}
private static String getDataSourceAttributeName() {
return JenaDataSourceSetupBase.class.getName() + ".dataSource";
}
public static DataSource makeC3poDataSource(String dbDriverClassname,
String jdbcUrl,
String username,
String password,
ServletContext ctx) {
ComboPooledDataSource cpds = new ComboPooledDataSource();
try {
cpds.setDriverClass(dbDriverClassname);
} catch (PropertyVetoException pve) {
throw new RuntimeException(pve);
}
cpds.setJdbcUrl(jdbcUrl);
cpds.setUser(username);
cpds.setPassword(password);
int[] maxActiveAndIdle = getMaxActiveAndIdle(ctx);
cpds.setMaxPoolSize(maxActiveAndIdle[0]);
cpds.setMinPoolSize(maxActiveAndIdle[1]);
cpds.setMaxIdleTime(43200); // s
cpds.setMaxIdleTimeExcessConnections(300);
cpds.setAcquireIncrement(5);
cpds.setNumHelperThreads(6);
cpds.setTestConnectionOnCheckout(DEFAULT_TESTONBORROW);
cpds.setTestConnectionOnCheckin(DEFAULT_TESTONRETURN);
cpds.setPreferredTestQuery(getValidationQuery(ctx));
return cpds;
}
private static int[] getMaxActiveAndIdle(ServletContext ctx) {
int maxActiveInt = DEFAULT_MAXACTIVE;
String maxActiveStr = ConfigurationProperties.getBean(ctx).getProperty(
MAX_ACTIVE_PROPERTY);
if (!StringUtils.isEmpty(maxActiveStr)) {
try {
int maxActiveIntFromConfigProperties = Integer.parseInt(maxActiveStr);
if (maxActiveIntFromConfigProperties < MINIMUM_MAXACTIVE) {
log.warn("Specified value for " + MAX_ACTIVE_PROPERTY +
" is too low. Using minimum value of " +
MINIMUM_MAXACTIVE);
maxActiveInt = MINIMUM_MAXACTIVE;
} else {
maxActiveInt = maxActiveIntFromConfigProperties;
}
} catch (NumberFormatException nfe) {
log.error("Unable to parse connection pool maxActive setting "
+ maxActiveStr + " as an integer");
}
}
String maxIdleStr = ConfigurationProperties.getBean(ctx).getProperty(
MAX_IDLE_PROPERTY);
int maxIdleInt = (maxActiveInt > DEFAULT_MAXACTIVE)
? maxActiveInt / 4
: DEFAULT_MAXIDLE;
if (!StringUtils.isEmpty(maxIdleStr)) {
try {
maxIdleInt = Integer.parseInt(maxIdleStr);
} catch (NumberFormatException nfe) {
log.error("Unable to parse connection pool maxIdle setting "
+ maxIdleStr + " as an integer");
}
}
int[] result = new int[2];
result[0] = maxActiveInt;
result[1] = maxIdleInt;
return result;
}
public static DataSource makeBasicDataSource(String dbDriverClassname,
String jdbcUrl,
String username,
String password,
ServletContext ctx) {
log.debug("makeBasicDataSource('" + dbDriverClassname + "', '"
+ jdbcUrl + "', '" + username + "', '" + password + "')");
BasicDataSource ds = new BasicDataSource();
ds.setDriverClassName(dbDriverClassname);
ds.setUrl(jdbcUrl);
ds.setUsername(username);
ds.setPassword(password);
int[] maxActiveAndIdle = getMaxActiveAndIdle(ctx);
ds.setMaxActive(maxActiveAndIdle[0]);
ds.setMaxIdle(maxActiveAndIdle[1]);
ds.setMaxWait(DEFAULT_MAXWAIT);
ds.setValidationQuery(getValidationQuery(ctx));
ds.setTestOnBorrow(DEFAULT_TESTONBORROW);
ds.setTestOnReturn(DEFAULT_TESTONRETURN);
ds.setMinEvictableIdleTimeMillis(DEFAULT_MINEVICTIONIDLETIME);
ds.setNumTestsPerEvictionRun(maxActiveAndIdle[0]);
ds.setTimeBetweenEvictionRunsMillis(DEFAULT_TIMEBETWEENEVICTIONS);
ds.setInitialSize(ds.getMaxActive() / 10);
try {
ds.getConnection().close();
} catch (Exception e) {
e.printStackTrace();
}
return ds;
}
public static boolean isFirstStartup() {
return firstStartup;
}
@ -276,22 +40,6 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
}
}
private static String getDbType(ServletContext ctx) {
return ConfigurationProperties.getBean(ctx).getProperty(
"VitroConnection.DataSource.dbtype", "MySQL");
}
private static String getDbDriverClassName(ServletContext ctx) {
return ConfigurationProperties.getBean(ctx).getProperty(
"VitroConnection.DataSource.driver", "com.mysql.jdbc.Driver");
}
private static String getValidationQuery(ServletContext ctx) {
return ConfigurationProperties.getBean(ctx).getProperty(
"VitroConnection.DataSource.validationQuery", "SELECT 1");
}
public static void setStartupDataset(Dataset dataset, ServletContext ctx) {
ctx.setAttribute("startupDataset", dataset);
}
@ -301,25 +49,4 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
return (o instanceof Dataset) ? ((Dataset) o) : null;
}
private static final String STOREDESC_ATTR = "storeDesc";
private static final String STORE_ATTR = "kbStore";
public static void setApplicationStoreDesc(StoreDesc storeDesc,
ServletContext ctx) {
ctx.setAttribute(STOREDESC_ATTR, storeDesc);
}
public static StoreDesc getApplicationStoreDesc(ServletContext ctx) {
return (StoreDesc) ctx.getAttribute(STOREDESC_ATTR);
}
public static void setApplicationStore(Store store,
ServletContext ctx) {
ctx.setAttribute(STORE_ATTR, store);
}
public static Store getApplicationStore(ServletContext ctx) {
return (Store) ctx.getAttribute(STORE_ATTR);
}
}

View file

@ -2,43 +2,162 @@
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
import java.beans.PropertyVetoException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.sql.DataSource;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.ontology.OntDocumentManager;
import com.mchange.v2.c3p0.ComboPooledDataSource;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
/**
/**
* Create connection to DB and DataSource, put them in the context.
*/
public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
implements ServletContextListener {
private static final Log log = LogFactory.getLog(
JenaPersistentDataSourceSetup.class.getName());
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext();
StartupStatus ss = StartupStatus.getBean(ctx);
// we do not want to fetch imports when we wrap Models in OntModels
OntDocumentManager.getInstance().setProcessImports(false);
DataSource bds = makeDataSourceFromConfigurationProperties(ctx);
setApplicationDataSource(bds, ctx);
}
public class JenaPersistentDataSourceSetup implements ServletContextListener {
private static final Log log = LogFactory
.getLog(JenaPersistentDataSourceSetup.class.getName());
@Override
private static final String PROPERTY_DBTYPE = "VitroConnection.DataSource.dbtype";
private static final String PROPERTY_JDBC_URL = "VitroConnection.DataSource.url";
private static final String PROPERTY_DRIVER_CLASS = "VitroConnection.DataSource.driver";
private static final String PROPERTY_PASSWORD = "VitroConnection.DataSource.password";
private static final String PROPERTY_USERNAME = "VitroConnection.DataSource.username";
private static final String PROPERTY_MAX_ACTIVE = "VitroConnection.DataSource.pool.maxActive";
private static final String PROPERTY_MAX_IDLE = "VitroConnection.DataSource.pool.maxIdle";
private static final String PROPERTY_VALIDATION_QUERY = "VitroConnection.DataSource.validationQuery";
private static final String DEFAULT_DBTYPE = "MySQL";
private static final String DEFAULT_DRIVER_CLASS = "com.mysql.jdbc.Driver";
private static final String DEFAULT_VALIDATION_QUERY = "SELECT 1";
private static final int DEFAULT_MAXACTIVE = 40; //ms
private static final int MINIMUM_MAXACTIVE = 20; //ms
private static final int DEFAULT_MAXIDLE = 10; //ms
private static final boolean DEFAULT_TESTONBORROW = true;
private static final boolean DEFAULT_TESTONRETURN = true;
private ConfigurationProperties configProps;
private static ComboPooledDataSource ds;
@Override
public void contextInitialized(ServletContextEvent sce) {
ServletContext ctx = sce.getServletContext();
configProps = ConfigurationProperties.getBean(ctx);
// we do not want to fetch imports when we wrap Models in OntModels
OntDocumentManager.getInstance().setProcessImports(false);
JenaPersistentDataSourceSetup.ds = makeC3poDataSource();
}
private ComboPooledDataSource makeC3poDataSource() {
try {
ComboPooledDataSource cpds = new ComboPooledDataSource();
cpds.setDriverClass(getDbDriverClassName());
cpds.setJdbcUrl(getJdbcUrl());
cpds.setUser(configProps.getProperty(PROPERTY_USERNAME));
cpds.setPassword(configProps.getProperty(PROPERTY_PASSWORD));
cpds.setMaxPoolSize(getMaxActive());
cpds.setMinPoolSize(getMaxIdle());
cpds.setMaxIdleTime(43200); // s
cpds.setMaxIdleTimeExcessConnections(300);
cpds.setAcquireIncrement(5);
cpds.setNumHelperThreads(6);
cpds.setTestConnectionOnCheckout(DEFAULT_TESTONBORROW);
cpds.setTestConnectionOnCheckin(DEFAULT_TESTONRETURN);
cpds.setPreferredTestQuery(getValidationQuery());
return cpds;
} catch (PropertyVetoException pve) {
throw new RuntimeException(pve);
}
}
private String getDbDriverClassName() {
return configProps.getProperty(PROPERTY_DRIVER_CLASS,
DEFAULT_DRIVER_CLASS);
}
private String getDbType() {
return configProps.getProperty(PROPERTY_DBTYPE, DEFAULT_DBTYPE);
}
private String getJdbcUrl() {
String url = configProps.getProperty(PROPERTY_JDBC_URL);
// Ensure that MySQL handles unicode properly, else all kinds of
// horrible nastiness ensues.
if (DEFAULT_DBTYPE.equals(getDbType()) && !url.contains("?")) {
url += "?useUnicode=yes&characterEncoding=utf8";
}
return url;
}
private String getValidationQuery() {
return configProps.getProperty(PROPERTY_VALIDATION_QUERY,
DEFAULT_VALIDATION_QUERY);
}
private int getMaxActive() {
String maxActiveStr = configProps.getProperty(PROPERTY_MAX_ACTIVE);
if (StringUtils.isEmpty(maxActiveStr)) {
return DEFAULT_MAXACTIVE;
}
int maxActive = DEFAULT_MAXACTIVE;
try {
maxActive = Integer.parseInt(maxActiveStr);
} catch (NumberFormatException nfe) {
log.error("Unable to parse connection pool maxActive setting "
+ maxActiveStr + " as an integer");
return DEFAULT_MAXACTIVE;
}
if (maxActive >= MINIMUM_MAXACTIVE) {
return maxActive;
}
log.warn("Specified value for " + PROPERTY_MAX_ACTIVE
+ " is too low. Using minimum value of " + MINIMUM_MAXACTIVE);
return MINIMUM_MAXACTIVE;
}
private int getMaxIdle() {
int maxIdleInt = Math.max(getMaxActive() / 4, DEFAULT_MAXIDLE);
String maxIdleStr = configProps.getProperty(PROPERTY_MAX_IDLE);
if (StringUtils.isEmpty(maxIdleStr)) {
return maxIdleInt;
}
try {
return Integer.parseInt(maxIdleStr);
} catch (NumberFormatException nfe) {
log.error("Unable to parse connection pool maxIdle setting "
+ maxIdleStr + " as an integer");
return maxIdleInt;
}
}
public static DataSource getApplicationDataSource() {
return JenaPersistentDataSourceSetup.ds;
}
@Override
public void contextDestroyed(ServletContextEvent sce) {
// Nothing to do.
}
if (JenaPersistentDataSourceSetup.ds != null) {
JenaPersistentDataSourceSetup.ds.close();
}
}
}

View file

@ -14,15 +14,7 @@ import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.UNION_FUL
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelID.USER_ACCOUNTS;
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONFIGURATION;
import static edu.cornell.mannlib.vitro.webapp.dao.ModelAccess.ModelMakerID.CONTENT;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_DISPLAY_DISPLAY_MODEL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_DISPLAY_METADATA_MODEL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_DISPLAY_TBOX_MODEL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.JENA_USER_ACCOUNTS_MODEL;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
@ -37,6 +29,7 @@ import com.hp.hpl.jena.rdf.model.Model;
import edu.cornell.mannlib.vitro.webapp.dao.ModelAccess;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker;
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroInterceptingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils.WhichService;
@ -45,8 +38,7 @@ import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
/**
* Sets up the content models, OntModelSelectors and webapp DAO factories.
*/
public class ModelMakerSetup extends JenaDataSourceSetupBase implements
javax.servlet.ServletContextListener {
public class ModelMakerSetup implements javax.servlet.ServletContextListener {
private static final Log log = LogFactory.getLog(ModelMakerSetup.class);
@Override
@ -85,13 +77,13 @@ public class ModelMakerSetup extends JenaDataSourceSetupBase implements
private Map<String, Model> populateConfigurationSpecialMap(
ServletContext ctx) {
Map<String, Model> map = new HashMap<>();
map.put(JENA_DISPLAY_METADATA_MODEL,
map.put(ModelNames.DISPLAY,
ModelAccess.on(ctx).getOntModel(DISPLAY));
map.put(JENA_DISPLAY_TBOX_MODEL,
map.put(ModelNames.DISPLAY_TBOX,
ModelAccess.on(ctx).getOntModel(DISPLAY_TBOX));
map.put(JENA_DISPLAY_DISPLAY_MODEL,
map.put(ModelNames.DISPLAY_DISPLAY,
ModelAccess.on(ctx).getOntModel(DISPLAY_DISPLAY));
map.put(JENA_USER_ACCOUNTS_MODEL,
map.put(ModelNames.USER_ACCOUNTS,
ModelAccess.on(ctx).getOntModel(USER_ACCOUNTS));
return map;
}
@ -105,11 +97,11 @@ public class ModelMakerSetup extends JenaDataSourceSetupBase implements
.getOntModel(BASE_FULL));
map.put("vitro:inferenceOntModel",
ModelAccess.on(ctx).getOntModel(INFERRED_FULL));
map.put(JENA_TBOX_ASSERTIONS_MODEL,
map.put(ModelNames.TBOX_ASSERTIONS,
ModelAccess.on(ctx).getOntModel(BASE_TBOX));
map.put(JENA_TBOX_INF_MODEL,
map.put(ModelNames.TBOX_INFERENCES,
ModelAccess.on(ctx).getOntModel(INFERRED_TBOX));
map.put(JENA_APPLICATION_METADATA_MODEL, ModelAccess.on(ctx)
map.put(ModelNames.APPLICATION_METADATA, ModelAccess.on(ctx)
.getOntModel(APPLICATION_METADATA));
return map;

View file

@ -24,6 +24,7 @@ import com.hp.hpl.jena.sdb.store.LayoutType;
import com.hp.hpl.jena.sdb.util.StoreUtils;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle;
@ -98,7 +99,7 @@ implements javax.servlet.ServletContextListener {
}
private void useSDB(ServletContext ctx, StartupStatus ss) throws SQLException {
DataSource ds = getApplicationDataSource(ctx);
DataSource ds = JenaPersistentDataSourceSetup.getApplicationDataSource();
if( ds == null ){
ss.fatal(this, "A DataSource must be setup before SDBSetup "+
"is run. Make sure that JenaPersistentDataSourceSetup runs before "+
@ -110,13 +111,10 @@ implements javax.servlet.ServletContextListener {
SDB.getContext().set(SDB.unionDefaultGraph, true) ;
StoreDesc storeDesc = makeStoreDesc(ctx);
setApplicationStoreDesc(storeDesc, ctx);
Store store = connectStore(ds, storeDesc);
setApplicationStore(store, ctx);
if (!isSetUp(store)) {
JenaPersistentDataSourceSetup.thisIsFirstStartup();
JenaDataSourceSetupBase.thisIsFirstStartup();
setupSDB(ctx, store);
}
@ -146,7 +144,7 @@ implements javax.servlet.ServletContextListener {
try {
return (SDBFactory.connectNamedModel(
store,
JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL))
ModelNames.TBOX_ASSERTIONS))
.size() > 0;
} catch (Exception e) {
return false;

View file

@ -27,6 +27,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.PelletListener;
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.ReasonerConfiguration;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceUtils;
import edu.cornell.mannlib.vitro.webapp.reasoner.ReasonerPlugin;
@ -89,7 +90,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
Model rebuildModel = dataset.getNamedModel(JENA_INF_MODEL_REBUILD);
Model scratchModel = dataset.getNamedModel(JENA_INF_MODEL_SCRATCHPAD);
Model inferenceModel = dataset.getNamedModel(JenaDataSourceSetupBase.JENA_INF_MODEL);
Model inferenceModel = dataset.getNamedModel(ModelNames.ABOX_INFERENCES);
// the simple reasoner will register itself as a listener to the ABox assertions
SimpleReasoner simpleReasoner = new SimpleReasoner(