NIHVIVO-1261 Pass the ServletContext down the chain to methods in JenaDataSourceSetupBase, to prepare for the change in ConfigurationProperties.
This commit is contained in:
parent
f16c1826be
commit
2d714c54b8
12 changed files with 199 additions and 173 deletions
|
@ -90,7 +90,7 @@ public class SDBSetupController extends FreemarkerHttpServlet {
|
||||||
Boolean done = true;
|
Boolean done = true;
|
||||||
getServletContext().setAttribute("done",done);
|
getServletContext().setAttribute("done",done);
|
||||||
StoreDesc storeDesc = jenaDataSourceSetupSDB.makeStoreDesc();
|
StoreDesc storeDesc = jenaDataSourceSetupSDB.makeStoreDesc();
|
||||||
BasicDataSource bds = jenaDataSourceSetupSDB.makeDataSourceFromConfigurationProperties();
|
BasicDataSource bds = jenaDataSourceSetupSDB.makeDataSourceFromConfigurationProperties(getServletContext());
|
||||||
Store store = null;
|
Store store = null;
|
||||||
try {
|
try {
|
||||||
store = JenaDataSourceSetupSDB.connectStore(bds, storeDesc);
|
store = JenaDataSourceSetupSDB.connectStore(bds, storeDesc);
|
||||||
|
|
|
@ -97,7 +97,7 @@ public class JenaExportController extends BaseEditController {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
String mode = (JenaDataSourceSetupBase.isSDBActive()) ? "SDB" : "RDB";
|
String mode = (JenaDataSourceSetupBase.isSDBActive(vreq)) ? "SDB" : "RDB";
|
||||||
if( "abox".equals(subgraphParam)){
|
if( "abox".equals(subgraphParam)){
|
||||||
model = ModelFactory.createDefaultModel();
|
model = ModelFactory.createDefaultModel();
|
||||||
if("inferred".equals(assertedOrInferredParam)){
|
if("inferred".equals(assertedOrInferredParam)){
|
||||||
|
|
|
@ -13,18 +13,15 @@ import java.text.Collator;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.Comparator;
|
import java.util.Comparator;
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.HashSet;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.LinkedList;
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Set;
|
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
|
||||||
import javax.servlet.RequestDispatcher;
|
import javax.servlet.RequestDispatcher;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import javax.servlet.http.HttpServletResponse;
|
import javax.servlet.http.HttpServletResponse;
|
||||||
|
|
||||||
|
@ -55,12 +52,8 @@ 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.sdb.SDBFactory;
|
|
||||||
import com.hp.hpl.jena.sdb.Store;
|
|
||||||
import com.hp.hpl.jena.sdb.StoreDesc;
|
import com.hp.hpl.jena.sdb.StoreDesc;
|
||||||
import com.hp.hpl.jena.sdb.sql.JDBC;
|
import com.hp.hpl.jena.sdb.sql.JDBC;
|
||||||
import com.hp.hpl.jena.sdb.sql.SDBConnection;
|
|
||||||
import com.hp.hpl.jena.sdb.store.DatabaseType;
|
import com.hp.hpl.jena.sdb.store.DatabaseType;
|
||||||
import com.hp.hpl.jena.sdb.store.LayoutType;
|
import com.hp.hpl.jena.sdb.store.LayoutType;
|
||||||
import com.hp.hpl.jena.shared.Lock;
|
import com.hp.hpl.jena.shared.Lock;
|
||||||
|
@ -68,7 +61,6 @@ import com.hp.hpl.jena.util.ResourceUtils;
|
||||||
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
import edu.cornell.mannlib.vedit.controller.BaseEditController;
|
||||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
import edu.cornell.mannlib.vitro.webapp.beans.Ontology;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
||||||
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
import edu.cornell.mannlib.vitro.webapp.controller.Controllers;
|
||||||
|
@ -82,7 +74,6 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSpecialModelMaker;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.event.EditEvent;
|
||||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup;
|
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetup;
|
||||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
|
||||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupSDB;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestWorkflowProcessor;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.JenaIngestWorkflowProcessor;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.WorkflowOntology;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.WorkflowOntology;
|
||||||
|
@ -117,6 +108,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
private static final String RENAME_RESOURCE = "/jenaIngest/renameResource.jsp";
|
private static final String RENAME_RESOURCE = "/jenaIngest/renameResource.jsp";
|
||||||
private static final String RENAME_RESULT = "/jenaIngest/renameResult.jsp";
|
private static final String RENAME_RESULT = "/jenaIngest/renameResult.jsp";
|
||||||
|
|
||||||
|
@Override
|
||||||
public void doGet (HttpServletRequest request, HttpServletResponse response) {
|
public void doGet (HttpServletRequest request, HttpServletResponse response) {
|
||||||
|
|
||||||
if (!checkLoginStatus(request,response)) {
|
if (!checkLoginStatus(request,response)) {
|
||||||
|
@ -134,7 +126,7 @@ public class JenaIngestController extends BaseEditController {
|
||||||
String modelT = (String)getServletContext().getAttribute("modelT");
|
String modelT = (String)getServletContext().getAttribute("modelT");
|
||||||
String info = (String)getServletContext().getAttribute("info");
|
String info = (String)getServletContext().getAttribute("info");
|
||||||
if(modelT == null){
|
if(modelT == null){
|
||||||
boolean initialSwitch = new JenaDataSourceSetupBase().isSDBActive();
|
boolean initialSwitch = JenaDataSourceSetupBase.isSDBActive(vreq);
|
||||||
if(initialSwitch){
|
if(initialSwitch){
|
||||||
VitroJenaSDBModelMaker vsmm = (VitroJenaSDBModelMaker) getServletContext().getAttribute("vitroJenaSDBModelMaker");
|
VitroJenaSDBModelMaker vsmm = (VitroJenaSDBModelMaker) getServletContext().getAttribute("vitroJenaSDBModelMaker");
|
||||||
vreq.getSession().setAttribute("vitroJenaModelMaker", vsmm);
|
vreq.getSession().setAttribute("vitroJenaModelMaker", vsmm);
|
||||||
|
@ -909,11 +901,12 @@ public class JenaIngestController extends BaseEditController {
|
||||||
String driver = loadDriver(dbTypeObj);
|
String driver = loadDriver(dbTypeObj);
|
||||||
System.out.println("Connecting to DB at "+jdbcUrl);
|
System.out.println("Connecting to DB at "+jdbcUrl);
|
||||||
StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash,dbTypeObj) ;
|
StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash,dbTypeObj) ;
|
||||||
|
ServletContext ctx = vreq.getSession().getServletContext();
|
||||||
BasicDataSource bds = JenaDataSourceSetup.makeBasicDataSource(
|
BasicDataSource bds = JenaDataSourceSetup.makeBasicDataSource(
|
||||||
driver, jdbcUrl, username, password);
|
driver, jdbcUrl, username, password, ctx);
|
||||||
try {
|
try {
|
||||||
VitroJenaSDBModelMaker vsmm = new VitroJenaSDBModelMaker(storeDesc, bds);
|
VitroJenaSDBModelMaker vsmm = new VitroJenaSDBModelMaker(storeDesc, bds);
|
||||||
VitroJenaModelMaker vjmm = new VitroJenaModelMaker(jdbcUrl, username, password, dbType);
|
VitroJenaModelMaker vjmm = new VitroJenaModelMaker(jdbcUrl, username, password, dbType, ctx);
|
||||||
getServletContext().setAttribute("vitroJenaSDBModelMaker", vsmm);
|
getServletContext().setAttribute("vitroJenaSDBModelMaker", vsmm);
|
||||||
getServletContext().setAttribute("vitroJenaModelMaker", vjmm);
|
getServletContext().setAttribute("vitroJenaModelMaker", vjmm);
|
||||||
if("SDB".equals(tripleStore))
|
if("SDB".equals(tripleStore))
|
||||||
|
|
|
@ -6,6 +6,7 @@ import java.sql.SQLException;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.dbcp.BasicDataSource;
|
import org.apache.commons.dbcp.BasicDataSource;
|
||||||
|
@ -23,7 +24,6 @@ import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||||
import com.hp.hpl.jena.rdf.model.ModelReader;
|
import com.hp.hpl.jena.rdf.model.ModelReader;
|
||||||
import com.hp.hpl.jena.rdf.model.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
import com.hp.hpl.jena.util.iterator.ExtendedIterator;
|
||||||
import com.hp.hpl.jena.util.iterator.NiceIterator;
|
|
||||||
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
import com.hp.hpl.jena.util.iterator.WrappedIterator;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
|
@ -51,7 +51,7 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
private HashMap<String,Model> modelCache;
|
private HashMap<String,Model> modelCache;
|
||||||
private HttpServletRequest request = null;
|
private HttpServletRequest request = null;
|
||||||
|
|
||||||
public VitroJenaModelMaker(String jdbcUrl, String username, String password, String dbTypeStr) {
|
public VitroJenaModelMaker(String jdbcUrl, String username, String password, String dbTypeStr, ServletContext ctx) {
|
||||||
this.jdbcUrl = jdbcUrl;
|
this.jdbcUrl = jdbcUrl;
|
||||||
this.username = username;
|
this.username = username;
|
||||||
this.password = password;
|
this.password = password;
|
||||||
|
@ -65,7 +65,7 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
}
|
}
|
||||||
this.dataSource = JenaDataSourceSetupBase.makeBasicDataSource(
|
this.dataSource = JenaDataSourceSetupBase.makeBasicDataSource(
|
||||||
driverName,
|
driverName,
|
||||||
jdbcUrl, username, password);
|
jdbcUrl, username, password, ctx);
|
||||||
modelCache = new HashMap<String,Model>();
|
modelCache = new HashMap<String,Model>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,12 +89,14 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
return this.modelCache;
|
return this.modelCache;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void close() {
|
public void close() {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
// So, in theory, this should close database connections and drop references
|
// So, in theory, this should close database connections and drop references
|
||||||
// to in-memory models and all that kind of stuff.
|
// to in-memory models and all that kind of stuff.
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Model createModel(String arg0) {
|
public Model createModel(String arg0) {
|
||||||
Model specialModel = null;
|
Model specialModel = null;
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
||||||
|
@ -110,6 +112,7 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Model createModel(String arg0, boolean arg1) {
|
public Model createModel(String arg0, boolean arg1) {
|
||||||
Model specialModel = null;
|
Model specialModel = null;
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
||||||
|
@ -123,11 +126,13 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public GraphMaker getGraphMaker() {
|
public GraphMaker getGraphMaker() {
|
||||||
throw new UnsupportedOperationException(this.getClass().getName() +
|
throw new UnsupportedOperationException(this.getClass().getName() +
|
||||||
" does not support getGraphMaker()");
|
" does not support getGraphMaker()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public boolean hasModel(String arg0) {
|
public boolean hasModel(String arg0) {
|
||||||
DBConnection conn = new DBConnection(jdbcUrl, username, password, dbTypeStr);
|
DBConnection conn = new DBConnection(jdbcUrl, username, password, dbTypeStr);
|
||||||
try {
|
try {
|
||||||
|
@ -141,6 +146,7 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public ExtendedIterator listModels() {
|
public ExtendedIterator listModels() {
|
||||||
DBConnection conn = new DBConnection(jdbcUrl, username, password, dbTypeStr);
|
DBConnection conn = new DBConnection(jdbcUrl, username, password, dbTypeStr);
|
||||||
try {
|
try {
|
||||||
|
@ -155,6 +161,7 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Model openModel(String arg0, boolean arg1) {
|
public Model openModel(String arg0, boolean arg1) {
|
||||||
Model specialModel = null;
|
Model specialModel = null;
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
||||||
|
@ -168,6 +175,7 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void removeModel(String arg0) {
|
public void removeModel(String arg0) {
|
||||||
Model m = modelCache.get(arg0);
|
Model m = modelCache.get(arg0);
|
||||||
if (m != null) {
|
if (m != null) {
|
||||||
|
@ -210,12 +218,14 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public Model createDefaultModel() {
|
public Model createDefaultModel() {
|
||||||
throw new UnsupportedOperationException(this.getClass().getName() +
|
throw new UnsupportedOperationException(this.getClass().getName() +
|
||||||
" does not support createDefaultModel()");
|
" does not support createDefaultModel()");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public Model createFreshModel() {
|
public Model createFreshModel() {
|
||||||
throw new UnsupportedOperationException(this.getClass().getName() +
|
throw new UnsupportedOperationException(this.getClass().getName() +
|
||||||
" does not support createFreshModel()"); }
|
" does not support createFreshModel()"); }
|
||||||
|
@ -233,6 +243,7 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public Model openModel(String arg0) {
|
public Model openModel(String arg0) {
|
||||||
Model specialModel = null;
|
Model specialModel = null;
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
||||||
|
@ -247,6 +258,7 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public Model openModelIfPresent(String arg0) {
|
public Model openModelIfPresent(String arg0) {
|
||||||
Model specialModel = null;
|
Model specialModel = null;
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
||||||
|
@ -261,6 +273,7 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public Model getModel(String arg0) {
|
public Model getModel(String arg0) {
|
||||||
Model specialModel = null;
|
Model specialModel = null;
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
||||||
|
@ -275,6 +288,7 @@ public class VitroJenaModelMaker implements ModelMaker {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public Model getModel(String arg0, ModelReader arg1) {
|
public Model getModel(String arg0, ModelReader arg1) {
|
||||||
Model specialModel = null;
|
Model specialModel = null;
|
||||||
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
if ( (specialModel = getSpecialModel(arg0)) != null ) { return specialModel; }
|
||||||
|
|
|
@ -57,10 +57,11 @@ public class WebappDaoFactorySDBPrep implements Filter {
|
||||||
Pattern.compile("/.*/images/.*")
|
Pattern.compile("/.*/images/.*")
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@Override
|
||||||
public void doFilter(ServletRequest request, ServletResponse response,
|
public void doFilter(ServletRequest request, ServletResponse response,
|
||||||
FilterChain filterChain) throws IOException, ServletException {
|
FilterChain filterChain) throws IOException, ServletException {
|
||||||
|
|
||||||
if ( (!(JenaDataSourceSetupBase.isSDBActive())) ||
|
if ( (!(JenaDataSourceSetupBase.isSDBActive(request))) ||
|
||||||
(request.getAttribute(
|
(request.getAttribute(
|
||||||
"WebappDaoFactorySDBPrep.setup") != null) ) {
|
"WebappDaoFactorySDBPrep.setup") != null) ) {
|
||||||
// don't run multiple times or if SDB is not active
|
// don't run multiple times or if SDB is not active
|
||||||
|
@ -134,6 +135,7 @@ public class WebappDaoFactorySDBPrep implements Filter {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void init(FilterConfig filterConfig) throws ServletException {
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
try {
|
try {
|
||||||
_ctx = filterConfig.getServletContext();
|
_ctx = filterConfig.getServletContext();
|
||||||
|
@ -142,6 +144,7 @@ public class WebappDaoFactorySDBPrep implements Filter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
// no destroy actions
|
// no destroy actions
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,7 +3,6 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.Iterator;
|
import java.util.Iterator;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -24,18 +23,15 @@ import com.hp.hpl.jena.util.iterator.ClosableIterator;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
import edu.cornell.mannlib.vitro.webapp.beans.ApplicationBean;
|
||||||
import edu.cornell.mannlib.vitro.webapp.beans.Portal;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDaoCon;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDaoCon;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaModelUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelContext;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SearchReindexingListener;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SimpleOntModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.SimpleOntModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSDBModelMaker;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSDBModelMaker;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
||||||
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase.TripleStoreType;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
|
import edu.cornell.mannlib.vitro.webapp.utils.NamespaceMapper;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.InitialJenaModelUtils;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.InitialJenaModelUtils;
|
||||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.NamespaceMapperJena;
|
import edu.cornell.mannlib.vitro.webapp.utils.jena.NamespaceMapperJena;
|
||||||
|
@ -44,7 +40,9 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(JenaDataSourceSetup.class.getName());
|
private static final Log log = LogFactory.getLog(JenaDataSourceSetup.class.getName());
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
|
ServletContext ctx = sce.getServletContext();
|
||||||
|
|
||||||
String tripleStoreTypeStr =
|
String tripleStoreTypeStr =
|
||||||
ConfigurationProperties.getProperty(
|
ConfigurationProperties.getProperty(
|
||||||
|
@ -56,23 +54,23 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
|
if (AbortStartup.isStartupAborted(ctx)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
||||||
OntModel memModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
|
OntModel memModel = (OntModel) ctx.getAttribute("jenaOntModel");
|
||||||
if (memModel == null) {
|
if (memModel == null) {
|
||||||
memModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
memModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
log.warn("WARNING: no database connected. Changes will disappear after context restart.");
|
log.warn("WARNING: no database connected. Changes will disappear after context restart.");
|
||||||
sce.getServletContext().setAttribute("jenaOntModel",memModel);
|
ctx.setAttribute("jenaOntModel",memModel);
|
||||||
}
|
}
|
||||||
memModel.addSubModel((new JenaBaseDaoCon()).getConstModel()); // add the vitro tbox to the model
|
memModel.addSubModel((new JenaBaseDaoCon()).getConstModel()); // add the vitro tbox to the model
|
||||||
|
|
||||||
OntModel inferenceModel = ontModelFromContextAttribute(sce.getServletContext(), "inferenceOntModel");
|
OntModel inferenceModel = ontModelFromContextAttribute(ctx, "inferenceOntModel");
|
||||||
|
|
||||||
OntModel userAccountsModel = ontModelFromContextAttribute(sce.getServletContext(), "userAccountsOntModel");
|
OntModel userAccountsModel = ontModelFromContextAttribute(ctx, "userAccountsOntModel");
|
||||||
if (userAccountsModel.size() == 0) {
|
if (userAccountsModel.size() == 0) {
|
||||||
checkMainModelForUserAccounts(memModel, userAccountsModel);
|
checkMainModelForUserAccounts(memModel, userAccountsModel);
|
||||||
}
|
}
|
||||||
|
@ -86,57 +84,57 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
|
||||||
inferenceOms.setUserAccountsModel(userAccountsModel);
|
inferenceOms.setUserAccountsModel(userAccountsModel);
|
||||||
unionOms.setUserAccountsModel(userAccountsModel);
|
unionOms.setUserAccountsModel(userAccountsModel);
|
||||||
|
|
||||||
OntModel displayModel = ontModelFromContextAttribute(sce.getServletContext(),"displayOntModel");
|
OntModel displayModel = ontModelFromContextAttribute(ctx,"displayOntModel");
|
||||||
baseOms.setDisplayModel(displayModel);
|
baseOms.setDisplayModel(displayModel);
|
||||||
inferenceOms.setDisplayModel(displayModel);
|
inferenceOms.setDisplayModel(displayModel);
|
||||||
unionOms.setDisplayModel(displayModel);
|
unionOms.setDisplayModel(displayModel);
|
||||||
|
|
||||||
checkForNamespaceMismatch( memModel, defaultNamespace );
|
checkForNamespaceMismatch( memModel, defaultNamespace );
|
||||||
|
|
||||||
sce.getServletContext().setAttribute("baseOntModel", memModel);
|
ctx.setAttribute("baseOntModel", memModel);
|
||||||
WebappDaoFactory baseWadf = new WebappDaoFactoryJena(
|
WebappDaoFactory baseWadf = new WebappDaoFactoryJena(
|
||||||
baseOms, defaultNamespace, null, null);
|
baseOms, defaultNamespace, null, null);
|
||||||
sce.getServletContext().setAttribute("assertionsWebappDaoFactory",baseWadf);
|
ctx.setAttribute("assertionsWebappDaoFactory",baseWadf);
|
||||||
ModelContext.setBaseOntModelSelector(baseOms, sce.getServletContext());
|
ModelContext.setBaseOntModelSelector(baseOms, ctx);
|
||||||
|
|
||||||
sce.getServletContext().setAttribute("inferenceOntModel", inferenceModel);
|
ctx.setAttribute("inferenceOntModel", inferenceModel);
|
||||||
WebappDaoFactory infWadf = new WebappDaoFactoryJena(
|
WebappDaoFactory infWadf = new WebappDaoFactoryJena(
|
||||||
inferenceOms, defaultNamespace, null, null);
|
inferenceOms, defaultNamespace, null, null);
|
||||||
sce.getServletContext().setAttribute("deductionsWebappDaoFactory", infWadf);
|
ctx.setAttribute("deductionsWebappDaoFactory", infWadf);
|
||||||
ModelContext.setInferenceOntModelSelector(inferenceOms, sce.getServletContext());
|
ModelContext.setInferenceOntModelSelector(inferenceOms, ctx);
|
||||||
|
|
||||||
sce.getServletContext().setAttribute("jenaOntModel", unionModel);
|
ctx.setAttribute("jenaOntModel", unionModel);
|
||||||
WebappDaoFactory wadf = new WebappDaoFactoryJena(
|
WebappDaoFactory wadf = new WebappDaoFactoryJena(
|
||||||
unionOms, baseOms, inferenceOms, defaultNamespace, null, null);
|
unionOms, baseOms, inferenceOms, defaultNamespace, null, null);
|
||||||
sce.getServletContext().setAttribute("webappDaoFactory",wadf);
|
ctx.setAttribute("webappDaoFactory",wadf);
|
||||||
ModelContext.setUnionOntModelSelector(unionOms, sce.getServletContext());
|
ModelContext.setUnionOntModelSelector(unionOms, ctx);
|
||||||
|
|
||||||
ApplicationBean appBean = getApplicationBeanFromOntModel(memModel,wadf);
|
ApplicationBean appBean = getApplicationBeanFromOntModel(memModel,wadf);
|
||||||
if (appBean != null) {
|
if (appBean != null) {
|
||||||
sce.getServletContext().setAttribute("applicationBean", appBean);
|
ctx.setAttribute("applicationBean", appBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (isEmpty(memModel)) {
|
if (isEmpty(memModel)) {
|
||||||
loadDataFromFilesystem(memModel, sce.getServletContext());
|
loadDataFromFilesystem(memModel, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (userAccountsModel.size() == 0) {
|
if (userAccountsModel.size() == 0) {
|
||||||
readOntologyFilesInPathSet(AUTHPATH, sce.getServletContext(), userAccountsModel);
|
readOntologyFilesInPathSet(AUTHPATH, ctx, userAccountsModel);
|
||||||
if (userAccountsModel.size() == 0) {
|
if (userAccountsModel.size() == 0) {
|
||||||
createInitialAdminUser(userAccountsModel);
|
createInitialAdminUser(userAccountsModel, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ensureEssentialInterfaceData(memModel, sce, wadf);
|
ensureEssentialInterfaceData(memModel, sce, wadf);
|
||||||
|
|
||||||
NamespaceMapper namespaceMapper = new NamespaceMapperJena(unionModel, unionModel, defaultNamespace);
|
NamespaceMapper namespaceMapper = new NamespaceMapperJena(unionModel, unionModel, defaultNamespace);
|
||||||
sce.getServletContext().setAttribute("NamespaceMapper", namespaceMapper);
|
ctx.setAttribute("NamespaceMapper", namespaceMapper);
|
||||||
memModel.getBaseModel().register(namespaceMapper);
|
memModel.getBaseModel().register(namespaceMapper);
|
||||||
|
|
||||||
makeModelMakerFromConnectionProperties(TripleStoreType.RDB);
|
makeModelMakerFromConnectionProperties(TripleStoreType.RDB, ctx);
|
||||||
VitroJenaModelMaker vjmm = getVitroJenaModelMaker();
|
VitroJenaModelMaker vjmm = getVitroJenaModelMaker();
|
||||||
setVitroJenaModelMaker(vjmm,sce);
|
setVitroJenaModelMaker(vjmm,sce);
|
||||||
makeModelMakerFromConnectionProperties(TripleStoreType.SDB);
|
makeModelMakerFromConnectionProperties(TripleStoreType.SDB, ctx);
|
||||||
VitroJenaSDBModelMaker vsmm = getVitroJenaSDBModelMaker();
|
VitroJenaSDBModelMaker vsmm = getVitroJenaSDBModelMaker();
|
||||||
setVitroJenaSDBModelMaker(vsmm,sce);
|
setVitroJenaSDBModelMaker(vsmm,sce);
|
||||||
|
|
||||||
|
@ -185,7 +183,9 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
|
||||||
/* ====================================================================== */
|
/* ====================================================================== */
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent sce) {
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
|
// Nothing to do
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApplicationBean getApplicationBeanFromOntModel(OntModel ontModel,WebappDaoFactory wadf) {
|
private ApplicationBean getApplicationBeanFromOntModel(OntModel ontModel,WebappDaoFactory wadf) {
|
||||||
|
|
|
@ -8,6 +8,8 @@ import java.util.Set;
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
|
import javax.servlet.ServletRequest;
|
||||||
|
import javax.servlet.http.HttpServletRequest;
|
||||||
|
|
||||||
import org.apache.commons.dbcp.BasicDataSource;
|
import org.apache.commons.dbcp.BasicDataSource;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
|
@ -18,10 +20,7 @@ import com.hp.hpl.jena.ontology.OntModelSpec;
|
||||||
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.Resource;
|
import com.hp.hpl.jena.rdf.model.Resource;
|
||||||
import com.hp.hpl.jena.sdb.SDBFactory;
|
|
||||||
import com.hp.hpl.jena.sdb.Store;
|
|
||||||
import com.hp.hpl.jena.sdb.StoreDesc;
|
import com.hp.hpl.jena.sdb.StoreDesc;
|
||||||
import com.hp.hpl.jena.sdb.sql.SDBConnection;
|
|
||||||
import com.hp.hpl.jena.sdb.store.DatabaseType;
|
import com.hp.hpl.jena.sdb.store.DatabaseType;
|
||||||
import com.hp.hpl.jena.sdb.store.LayoutType;
|
import com.hp.hpl.jena.sdb.store.LayoutType;
|
||||||
|
|
||||||
|
@ -47,10 +46,6 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
DEFAULT_TESTSPEREVICTION = 3,
|
DEFAULT_TESTSPEREVICTION = 3,
|
||||||
DEFAULT_MINEVICTIONIDLETIME = 1000 * 60 * 30; // ms
|
DEFAULT_MINEVICTIONIDLETIME = 1000 * 60 * 30; // ms
|
||||||
|
|
||||||
protected final static String VALIDATIONQUERY =
|
|
||||||
ConfigurationProperties.getProperty(
|
|
||||||
"VitroConnection.DataSource.validationQuery", "SELECT 1");
|
|
||||||
|
|
||||||
protected final static boolean DEFAULT_TESTONBORROW = true,
|
protected final static boolean DEFAULT_TESTONBORROW = true,
|
||||||
DEFAULT_TESTONRETURN = true, DEFAULT_TESTWHILEIDLE = true;
|
DEFAULT_TESTONRETURN = true, DEFAULT_TESTWHILEIDLE = true;
|
||||||
|
|
||||||
|
@ -63,11 +58,6 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
|
|
||||||
String DB_USER = "jenatest"; // database user id
|
String DB_USER = "jenatest"; // database user id
|
||||||
String DB_PASSWD = "jenatest"; // database password
|
String DB_PASSWD = "jenatest"; // database password
|
||||||
String DB = ConfigurationProperties.getProperty( // database type
|
|
||||||
"VitroConnection.DataSource.dbtype","MySQL");
|
|
||||||
String DB_DRIVER_CLASS_NAME = ConfigurationProperties.getProperty(
|
|
||||||
"VitroConnection.DataSource.driver",
|
|
||||||
"com.mysql.jdbc.Driver");
|
|
||||||
|
|
||||||
// ABox assertions. These are stored in a database (Jena SDB) and the
|
// ABox assertions. These are stored in a database (Jena SDB) and the
|
||||||
// application works (queries and updates) with the ABox data from the DB -
|
// application works (queries and updates) with the ABox data from the DB -
|
||||||
|
@ -128,14 +118,13 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
static final OntModelSpec DB_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
static final OntModelSpec DB_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
||||||
static final OntModelSpec MEM_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
static final OntModelSpec MEM_ONT_MODEL_SPEC = OntModelSpec.OWL_MEM;
|
||||||
|
|
||||||
private String getJdbcUrl() {
|
private String getJdbcUrl(ServletContext ctx) {
|
||||||
|
|
||||||
String jdbcUrl = ConfigurationProperties.getProperty(
|
String jdbcUrl = ConfigurationProperties.getProperty(
|
||||||
"VitroConnection.DataSource.url");
|
"VitroConnection.DataSource.url");
|
||||||
|
|
||||||
// Ensure that MySQL handles unicode properly, else all kinds of
|
// Ensure that MySQL handles unicode properly, else all kinds of
|
||||||
// horrible nastiness ensues.
|
// horrible nastiness ensues.
|
||||||
if ("MySQL".equals(DB) && !jdbcUrl.contains("?")) {
|
if ("MySQL".equals(getDbType(ctx)) && !jdbcUrl.contains("?")) {
|
||||||
jdbcUrl += "?useUnicode=yes&characterEncoding=utf8";
|
jdbcUrl += "?useUnicode=yes&characterEncoding=utf8";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -149,16 +138,16 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
*/
|
*/
|
||||||
public final Model makeDBModelFromConfigurationProperties(
|
public final Model makeDBModelFromConfigurationProperties(
|
||||||
String jenaDbModelName,
|
String jenaDbModelName,
|
||||||
OntModelSpec jenaDbOntModelSpec) {
|
OntModelSpec jenaDbOntModelSpec, ServletContext ctx) {
|
||||||
|
|
||||||
String jdbcUrl = getJdbcUrl();
|
String jdbcUrl = getJdbcUrl(ctx);
|
||||||
|
|
||||||
String username = ConfigurationProperties.getProperty(
|
String username = ConfigurationProperties.getProperty(
|
||||||
"VitroConnection.DataSource.username");
|
"VitroConnection.DataSource.username");
|
||||||
String password = ConfigurationProperties.getProperty(
|
String password = ConfigurationProperties.getProperty(
|
||||||
"VitroConnection.DataSource.password");
|
"VitroConnection.DataSource.password");
|
||||||
BasicDataSource ds = makeBasicDataSource(
|
BasicDataSource ds = makeBasicDataSource(
|
||||||
DB_DRIVER_CLASS_NAME, jdbcUrl, username, password);
|
getDbDriverClassName(ctx), jdbcUrl, username, password, ctx);
|
||||||
|
|
||||||
String dns = ConfigurationProperties.getProperty(
|
String dns = ConfigurationProperties.getProperty(
|
||||||
"Vitro.defaultNamespace");
|
"Vitro.defaultNamespace");
|
||||||
|
@ -168,7 +157,7 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
? jenaDbOntModelSpec
|
? jenaDbOntModelSpec
|
||||||
: DB_ONT_MODEL_SPEC;
|
: DB_ONT_MODEL_SPEC;
|
||||||
|
|
||||||
return makeDBModel(ds, jenaDbModelName, jenaDbOntModelSpec);
|
return makeDBModel(ds, jenaDbModelName, jenaDbOntModelSpec, ctx);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -176,16 +165,16 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
* Sets up a BasicDataSource using values from
|
* Sets up a BasicDataSource using values from
|
||||||
* a properties file.
|
* a properties file.
|
||||||
*/
|
*/
|
||||||
public final BasicDataSource makeDataSourceFromConfigurationProperties(){
|
public final BasicDataSource makeDataSourceFromConfigurationProperties(ServletContext ctx){
|
||||||
String dbDriverClassname = ConfigurationProperties.getProperty(
|
String dbDriverClassname = ConfigurationProperties.getProperty(
|
||||||
"VitroConnection.DataSource.driver", DB_DRIVER_CLASS_NAME);
|
"VitroConnection.DataSource.driver", getDbDriverClassName(ctx));
|
||||||
String jdbcUrl = getJdbcUrl();
|
String jdbcUrl = getJdbcUrl(ctx);
|
||||||
String username = ConfigurationProperties.getProperty(
|
String username = ConfigurationProperties.getProperty(
|
||||||
"VitroConnection.DataSource.username");
|
"VitroConnection.DataSource.username");
|
||||||
String password = ConfigurationProperties.getProperty(
|
String password = ConfigurationProperties.getProperty(
|
||||||
"VitroConnection.DataSource.password");
|
"VitroConnection.DataSource.password");
|
||||||
return makeBasicDataSource(
|
return makeBasicDataSource(
|
||||||
dbDriverClassname, jdbcUrl, username, password);
|
dbDriverClassname, jdbcUrl, username, password, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setApplicationDataSource(BasicDataSource bds,
|
public void setApplicationDataSource(BasicDataSource bds,
|
||||||
|
@ -204,7 +193,8 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
public static BasicDataSource makeBasicDataSource(String dbDriverClassname,
|
public static BasicDataSource makeBasicDataSource(String dbDriverClassname,
|
||||||
String jdbcUrl,
|
String jdbcUrl,
|
||||||
String username,
|
String username,
|
||||||
String password) {
|
String password,
|
||||||
|
ServletContext ctx) {
|
||||||
log.debug("makeBasicDataSource('" + dbDriverClassname + "', '"
|
log.debug("makeBasicDataSource('" + dbDriverClassname + "', '"
|
||||||
+ jdbcUrl + "', '" + username + "', '" + password + "')");
|
+ jdbcUrl + "', '" + username + "', '" + password + "')");
|
||||||
BasicDataSource ds = new BasicDataSource();
|
BasicDataSource ds = new BasicDataSource();
|
||||||
|
@ -239,7 +229,7 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
ds.setMaxActive(maxActiveInt);
|
ds.setMaxActive(maxActiveInt);
|
||||||
ds.setMaxIdle(maxIdleInt);
|
ds.setMaxIdle(maxIdleInt);
|
||||||
ds.setMaxWait(DEFAULT_MAXWAIT);
|
ds.setMaxWait(DEFAULT_MAXWAIT);
|
||||||
ds.setValidationQuery(VALIDATIONQUERY);
|
ds.setValidationQuery(getValidationQuery(ctx));
|
||||||
ds.setTestOnBorrow(DEFAULT_TESTONBORROW);
|
ds.setTestOnBorrow(DEFAULT_TESTONBORROW);
|
||||||
ds.setTestOnReturn(DEFAULT_TESTONRETURN);
|
ds.setTestOnReturn(DEFAULT_TESTONRETURN);
|
||||||
ds.setMinEvictableIdleTimeMillis(DEFAULT_MINEVICTIONIDLETIME);
|
ds.setMinEvictableIdleTimeMillis(DEFAULT_MINEVICTIONIDLETIME);
|
||||||
|
@ -261,23 +251,25 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
|
|
||||||
protected Model makeDBModel(BasicDataSource ds,
|
protected Model makeDBModel(BasicDataSource ds,
|
||||||
String jenaDbModelname,
|
String jenaDbModelname,
|
||||||
OntModelSpec jenaDbOntModelSpec) {
|
OntModelSpec jenaDbOntModelSpec,
|
||||||
|
ServletContext ctx) {
|
||||||
return makeDBModel(
|
return makeDBModel(
|
||||||
ds, jenaDbModelname, jenaDbOntModelSpec, TripleStoreType.RDB);
|
ds, jenaDbModelname, jenaDbOntModelSpec, TripleStoreType.RDB, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Model makeDBModel(BasicDataSource ds,
|
protected Model makeDBModel(BasicDataSource ds,
|
||||||
String jenaDbModelName,
|
String jenaDbModelName,
|
||||||
OntModelSpec jenaDbOntModelSpec,
|
OntModelSpec jenaDbOntModelSpec,
|
||||||
TripleStoreType storeType) {
|
TripleStoreType storeType, ServletContext ctx) {
|
||||||
return makeDBModel (
|
return makeDBModel (
|
||||||
ds, jenaDbModelName, jenaDbOntModelSpec, storeType, DB);
|
ds, jenaDbModelName, jenaDbOntModelSpec, storeType, getDbType(ctx), ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static Model makeDBModel(BasicDataSource ds,
|
public static Model makeDBModel(BasicDataSource ds,
|
||||||
String jenaDbModelName,
|
String jenaDbModelName,
|
||||||
OntModelSpec jenaDbOntModelSpec,
|
OntModelSpec jenaDbOntModelSpec,
|
||||||
TripleStoreType storeType, String dbType) {
|
TripleStoreType storeType, String dbType,
|
||||||
|
ServletContext ctx) {
|
||||||
Model dbModel = null;
|
Model dbModel = null;
|
||||||
try {
|
try {
|
||||||
// open the db model
|
// open the db model
|
||||||
|
@ -352,7 +344,7 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
* If the {@link ConfigurationProperties} has a name for the initial admin
|
* If the {@link ConfigurationProperties} has a name for the initial admin
|
||||||
* user, create the user and add it to the model.
|
* user, create the user and add it to the model.
|
||||||
*/
|
*/
|
||||||
protected void createInitialAdminUser(Model model) {
|
protected void createInitialAdminUser(Model model, ServletContext ctx) {
|
||||||
String initialAdminUsername = ConfigurationProperties
|
String initialAdminUsername = ConfigurationProperties
|
||||||
.getProperty("initialAdminUser");
|
.getProperty("initialAdminUser");
|
||||||
if (initialAdminUsername == null) {
|
if (initialAdminUsername == null) {
|
||||||
|
@ -386,8 +378,8 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
private static final String sdbModelMaker = "vitroJenaSDBModelMaker";
|
private static final String sdbModelMaker = "vitroJenaSDBModelMaker";
|
||||||
private static final String rdbModelMaker = "vitroJenaModelMaker";
|
private static final String rdbModelMaker = "vitroJenaModelMaker";
|
||||||
|
|
||||||
protected void makeModelMakerFromConnectionProperties(TripleStoreType type){
|
protected void makeModelMakerFromConnectionProperties(TripleStoreType type, ServletContext ctx){
|
||||||
String jdbcUrl = getJdbcUrl();
|
String jdbcUrl = getJdbcUrl(ctx);
|
||||||
String username = ConfigurationProperties.getProperty(
|
String username = ConfigurationProperties.getProperty(
|
||||||
"VitroConnection.DataSource.username");
|
"VitroConnection.DataSource.username");
|
||||||
String password = ConfigurationProperties.getProperty(
|
String password = ConfigurationProperties.getProperty(
|
||||||
|
@ -395,14 +387,14 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
|
|
||||||
if (TripleStoreType.RDB.equals(type)){
|
if (TripleStoreType.RDB.equals(type)){
|
||||||
vjmm = new VitroJenaModelMaker(
|
vjmm = new VitroJenaModelMaker(
|
||||||
jdbcUrl, username, password, DB_TYPE);
|
jdbcUrl, username, password, DB_TYPE, ctx);
|
||||||
}
|
}
|
||||||
|
|
||||||
else if(TripleStoreType.SDB.equals(type)){
|
else if(TripleStoreType.SDB.equals(type)){
|
||||||
StoreDesc storeDesc = new StoreDesc(
|
StoreDesc storeDesc = new StoreDesc(
|
||||||
LayoutType.LayoutTripleNodesHash, DatabaseType.MySQL);
|
LayoutType.LayoutTripleNodesHash, DatabaseType.MySQL);
|
||||||
BasicDataSource bds = JenaDataSourceSetup.makeBasicDataSource(
|
BasicDataSource bds = JenaDataSourceSetup.makeBasicDataSource(
|
||||||
DB_DRIVER_CLASS_NAME, jdbcUrl, username, password);
|
getDbDriverClassName(ctx), jdbcUrl, username, password, ctx);
|
||||||
try {
|
try {
|
||||||
vsmm = new VitroJenaSDBModelMaker(storeDesc, bds);
|
vsmm = new VitroJenaSDBModelMaker(storeDesc, bds);
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
|
@ -424,7 +416,15 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
sce.getServletContext().setAttribute(sdbModelMaker, vsmm);
|
sce.getServletContext().setAttribute(sdbModelMaker, vsmm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static boolean isSDBActive() {
|
public static boolean isSDBActive(ServletRequest req) {
|
||||||
|
if (!(req instanceof HttpServletRequest)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
HttpServletRequest hreq = (HttpServletRequest) req;
|
||||||
|
return isSDBActive(hreq.getSession().getServletContext());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static boolean isSDBActive(ServletContext ctx) {
|
||||||
String tripleStoreTypeStr =
|
String tripleStoreTypeStr =
|
||||||
ConfigurationProperties.getProperty(
|
ConfigurationProperties.getProperty(
|
||||||
"VitroConnection.DataSource.tripleStoreType", "RDB");
|
"VitroConnection.DataSource.tripleStoreType", "RDB");
|
||||||
|
@ -439,4 +439,21 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||||
return vsmm;
|
return vsmm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static String getDbType(ServletContext ctx) {
|
||||||
|
return ConfigurationProperties.getProperty( // database type
|
||||||
|
"VitroConnection.DataSource.dbtype","MySQL");
|
||||||
|
}
|
||||||
|
|
||||||
|
private static String getDbDriverClassName(ServletContext ctx) {
|
||||||
|
return ConfigurationProperties.getProperty(
|
||||||
|
"VitroConnection.DataSource.driver",
|
||||||
|
"com.mysql.jdbc.Driver");
|
||||||
|
|
||||||
|
}
|
||||||
|
private static String getValidationQuery(ServletContext ctx) {
|
||||||
|
return ConfigurationProperties.getProperty(
|
||||||
|
"VitroConnection.DataSource.validationQuery", "SELECT 1");
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -62,9 +62,11 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(JenaDataSourceSetupSDB.class);
|
private static final Log log = LogFactory.getLog(JenaDataSourceSetupSDB.class);
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
|
ServletContext ctx = sce.getServletContext();
|
||||||
|
|
||||||
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
|
if (AbortStartup.isStartupAborted(ctx)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -74,28 +76,28 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
// up things related to the DB.
|
// up things related to the DB.
|
||||||
// TODO: I would like to make this code (before the sdb try/catch conditional so
|
// TODO: I would like to make this code (before the sdb try/catch conditional so
|
||||||
// that it is not executed in a post-sdb-conversion environment.
|
// that it is not executed in a post-sdb-conversion environment.
|
||||||
OntModel memModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
|
OntModel memModel = (OntModel) ctx.getAttribute("jenaOntModel");
|
||||||
|
|
||||||
//memModel.writeAll(System.out,"N3",null);
|
//memModel.writeAll(System.out,"N3",null);
|
||||||
|
|
||||||
if ( updateRequired(sce.getServletContext(), memModel)) {
|
if ( updateRequired(ctx, memModel)) {
|
||||||
log.error(getMigrationErrString());
|
log.error(getMigrationErrString());
|
||||||
System.out.println(getMigrationErrString());
|
System.out.println(getMigrationErrString());
|
||||||
// The rest of the application should not
|
// The rest of the application should not
|
||||||
// start if this condition is encountered
|
// start if this condition is encountered
|
||||||
AbortStartup.abortStartup(sce.getServletContext());
|
AbortStartup.abortStartup(ctx);
|
||||||
throw new MigrationRequiredError(getMigrationErrString());
|
throw new MigrationRequiredError(getMigrationErrString());
|
||||||
}
|
}
|
||||||
|
|
||||||
if (memModel == null) {
|
if (memModel == null) {
|
||||||
memModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
memModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
log.warn("WARNING: no database connected. Changes will disappear after context restart.");
|
log.warn("WARNING: no database connected. Changes will disappear after context restart.");
|
||||||
sce.getServletContext().setAttribute("jenaOntModel",memModel);
|
ctx.setAttribute("jenaOntModel",memModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
OntModel inferenceModel = ontModelFromContextAttribute(sce.getServletContext(), "inferenceOntModel");
|
OntModel inferenceModel = ontModelFromContextAttribute(ctx, "inferenceOntModel");
|
||||||
|
|
||||||
OntModel userAccountsModel = ontModelFromContextAttribute(sce.getServletContext(), "userAccountsOntModel");
|
OntModel userAccountsModel = ontModelFromContextAttribute(ctx, "userAccountsOntModel");
|
||||||
if (userAccountsModel.size() == 0) {
|
if (userAccountsModel.size() == 0) {
|
||||||
checkMainModelForUserAccounts(memModel, userAccountsModel);
|
checkMainModelForUserAccounts(memModel, userAccountsModel);
|
||||||
}
|
}
|
||||||
|
@ -110,7 +112,7 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
inferenceOms.setUserAccountsModel(userAccountsModel);
|
inferenceOms.setUserAccountsModel(userAccountsModel);
|
||||||
unionOms.setUserAccountsModel(userAccountsModel);
|
unionOms.setUserAccountsModel(userAccountsModel);
|
||||||
|
|
||||||
OntModel displayModel = ontModelFromContextAttribute(sce.getServletContext(),"displayOntModel");
|
OntModel displayModel = ontModelFromContextAttribute(ctx,"displayOntModel");
|
||||||
baseOms.setDisplayModel(displayModel);
|
baseOms.setDisplayModel(displayModel);
|
||||||
inferenceOms.setDisplayModel(displayModel);
|
inferenceOms.setDisplayModel(displayModel);
|
||||||
unionOms.setDisplayModel(displayModel);
|
unionOms.setDisplayModel(displayModel);
|
||||||
|
@ -123,17 +125,17 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
SDB.getContext().set(SDB.unionDefaultGraph, true) ;
|
SDB.getContext().set(SDB.unionDefaultGraph, true) ;
|
||||||
|
|
||||||
StoreDesc storeDesc = makeStoreDesc();
|
StoreDesc storeDesc = makeStoreDesc();
|
||||||
setApplicationStoreDesc(storeDesc, sce.getServletContext());
|
setApplicationStoreDesc(storeDesc, ctx);
|
||||||
|
|
||||||
BasicDataSource bds = makeDataSourceFromConfigurationProperties();
|
BasicDataSource bds = makeDataSourceFromConfigurationProperties(ctx);
|
||||||
this.setApplicationDataSource(bds, sce.getServletContext());
|
this.setApplicationDataSource(bds, ctx);
|
||||||
|
|
||||||
Store store = connectStore(bds, storeDesc);
|
Store store = connectStore(bds, storeDesc);
|
||||||
setApplicationStore(store, sce.getServletContext());
|
setApplicationStore(store, ctx);
|
||||||
|
|
||||||
if (!isSetUp(store)) {
|
if (!isSetUp(store)) {
|
||||||
log.info("Non-SDB system detected. Setting up SDB store");
|
log.info("Non-SDB system detected. Setting up SDB store");
|
||||||
setupSDB(sce.getServletContext(), store, memModel, inferenceModel);
|
setupSDB(ctx, store, memModel, inferenceModel);
|
||||||
}
|
}
|
||||||
|
|
||||||
// The code below, which sets up the OntModelSelectors, controls whether each
|
// The code below, which sets up the OntModelSelectors, controls whether each
|
||||||
|
@ -144,12 +146,12 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
// and JenaOntModel=union of assertions and inferences) with the post-SDB-conversion models.
|
// and JenaOntModel=union of assertions and inferences) with the post-SDB-conversion models.
|
||||||
|
|
||||||
// ABox assertions
|
// ABox assertions
|
||||||
Model aboxAssertions = makeDBModel(bds, JenaDataSourceSetupBase.JENA_DB_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB);
|
Model aboxAssertions = makeDBModel(bds, JenaDataSourceSetupBase.JENA_DB_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx);
|
||||||
Model listenableAboxAssertions = ModelFactory.createUnion(aboxAssertions, ModelFactory.createDefaultModel());
|
Model listenableAboxAssertions = ModelFactory.createUnion(aboxAssertions, ModelFactory.createDefaultModel());
|
||||||
baseOms.setABoxModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, listenableAboxAssertions));
|
baseOms.setABoxModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, listenableAboxAssertions));
|
||||||
|
|
||||||
// ABox inferences
|
// ABox inferences
|
||||||
Model aboxInferences = makeDBModel(bds, JenaDataSourceSetupBase.JENA_INF_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB);
|
Model aboxInferences = makeDBModel(bds, JenaDataSourceSetupBase.JENA_INF_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx);
|
||||||
Model listenableAboxInferences = ModelFactory.createUnion(aboxInferences, ModelFactory.createDefaultModel());
|
Model listenableAboxInferences = ModelFactory.createUnion(aboxInferences, ModelFactory.createDefaultModel());
|
||||||
inferenceOms.setABoxModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, listenableAboxInferences));
|
inferenceOms.setABoxModel(ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, listenableAboxInferences));
|
||||||
|
|
||||||
|
@ -158,7 +160,7 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
// ABox models do (and so don't need the extra step to make them listenable).
|
// ABox models do (and so don't need the extra step to make them listenable).
|
||||||
// TBox assertions
|
// TBox assertions
|
||||||
try {
|
try {
|
||||||
Model tboxAssertionsDB = makeDBModel(bds, JENA_TBOX_ASSERTIONS_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB);
|
Model tboxAssertionsDB = makeDBModel(bds, JENA_TBOX_ASSERTIONS_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx);
|
||||||
OntModel tboxAssertions = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
OntModel tboxAssertions = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
|
|
||||||
if (tboxAssertionsDB != null) {
|
if (tboxAssertionsDB != null) {
|
||||||
|
@ -176,7 +178,7 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
|
|
||||||
// TBox inferences
|
// TBox inferences
|
||||||
try {
|
try {
|
||||||
Model tboxInferencesDB = makeDBModel(bds, JENA_TBOX_INF_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB);
|
Model tboxInferencesDB = makeDBModel(bds, JENA_TBOX_INF_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx);
|
||||||
OntModel tboxInferences = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
OntModel tboxInferences = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
|
|
||||||
if (tboxInferencesDB != null) {
|
if (tboxInferencesDB != null) {
|
||||||
|
@ -204,7 +206,7 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
// Application metadata model is cached in memory.
|
// Application metadata model is cached in memory.
|
||||||
try {
|
try {
|
||||||
|
|
||||||
Model applicationMetadataModelDB = makeDBModel(bds, JENA_APPLICATION_METADATA_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB);
|
Model applicationMetadataModelDB = makeDBModel(bds, JENA_APPLICATION_METADATA_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB, ctx);
|
||||||
OntModel applicationMetadataModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
OntModel applicationMetadataModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
|
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
|
@ -239,7 +241,7 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
OntModel baseUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
OntModel baseUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
||||||
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(), ctx);
|
||||||
WebappDaoFactory baseWadf = new WebappDaoFactorySDB(
|
WebappDaoFactory baseWadf = new WebappDaoFactorySDB(
|
||||||
baseOms,
|
baseOms,
|
||||||
bds,
|
bds,
|
||||||
|
@ -248,12 +250,12 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY);
|
WebappDaoFactorySDB.SDBDatasetMode.ASSERTIONS_ONLY);
|
||||||
sce.getServletContext().setAttribute("assertionsWebappDaoFactory",baseWadf);
|
ctx.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(), ctx);
|
||||||
WebappDaoFactory infWadf = new WebappDaoFactorySDB(
|
WebappDaoFactory infWadf = new WebappDaoFactorySDB(
|
||||||
inferenceOms,
|
inferenceOms,
|
||||||
bds,
|
bds,
|
||||||
|
@ -262,34 +264,34 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
null,
|
null,
|
||||||
null,
|
null,
|
||||||
WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY);
|
WebappDaoFactorySDB.SDBDatasetMode.INFERENCES_ONLY);
|
||||||
sce.getServletContext().setAttribute("deductionsWebappDaoFactory", infWadf);
|
ctx.setAttribute("deductionsWebappDaoFactory", infWadf);
|
||||||
|
|
||||||
OntModel masterUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
OntModel masterUnion = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM,
|
||||||
ModelFactory.createUnion(unionABoxModel, unionTBoxModel));
|
ModelFactory.createUnion(unionABoxModel, unionTBoxModel));
|
||||||
unionOms.setFullModel(masterUnion);
|
unionOms.setFullModel(masterUnion);
|
||||||
sce.getServletContext().setAttribute("jenaOntModel", masterUnion);
|
ctx.setAttribute("jenaOntModel", masterUnion);
|
||||||
WebappDaoFactory wadf = new WebappDaoFactorySDB(unionOms, bds, storeDesc, defaultNamespace, null, null);
|
WebappDaoFactory wadf = new WebappDaoFactorySDB(unionOms, bds, storeDesc, defaultNamespace, null, null);
|
||||||
sce.getServletContext().setAttribute("webappDaoFactory",wadf);
|
ctx.setAttribute("webappDaoFactory",wadf);
|
||||||
|
|
||||||
ModelContext.setUnionOntModelSelector(unionOms, sce.getServletContext()); // assertions and inferences
|
ModelContext.setUnionOntModelSelector(unionOms, ctx); // assertions and inferences
|
||||||
ModelContext.setBaseOntModelSelector(baseOms, sce.getServletContext()); // assertions
|
ModelContext.setBaseOntModelSelector(baseOms, ctx); // assertions
|
||||||
ModelContext.setInferenceOntModelSelector(inferenceOms, sce.getServletContext()); // inferences
|
ModelContext.setInferenceOntModelSelector(inferenceOms, ctx); // inferences
|
||||||
|
|
||||||
ApplicationBean appBean = getApplicationBeanFromOntModel(unionOms.getFullModel(),wadf);
|
ApplicationBean appBean = getApplicationBeanFromOntModel(unionOms.getFullModel(),wadf);
|
||||||
if (appBean != null) {
|
if (appBean != null) {
|
||||||
sce.getServletContext().setAttribute("applicationBean", appBean);
|
ctx.setAttribute("applicationBean", appBean);
|
||||||
}
|
}
|
||||||
|
|
||||||
//if (isEmpty(unionOms.getFullModel())) {
|
//if (isEmpty(unionOms.getFullModel())) {
|
||||||
// loadDataFromFilesystem(unionOms.getFullModel(), sce.getServletContext());
|
// loadDataFromFilesystem(unionOms.getFullModel(), ctx);
|
||||||
//}
|
//}
|
||||||
|
|
||||||
log.info("Checking for user account data");
|
log.info("Checking for user account data");
|
||||||
|
|
||||||
if (userAccountsModel.size() == 0) {
|
if (userAccountsModel.size() == 0) {
|
||||||
readOntologyFilesInPathSet(AUTHPATH, sce.getServletContext(), userAccountsModel);
|
readOntologyFilesInPathSet(AUTHPATH, ctx, userAccountsModel);
|
||||||
if (userAccountsModel.size() == 0) {
|
if (userAccountsModel.size() == 0) {
|
||||||
createInitialAdminUser(userAccountsModel);
|
createInitialAdminUser(userAccountsModel, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -300,17 +302,17 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
log.info("Setting up namespace mapper");
|
log.info("Setting up namespace mapper");
|
||||||
|
|
||||||
NamespaceMapper namespaceMapper = new NamespaceMapperJena(masterUnion, masterUnion, defaultNamespace);
|
NamespaceMapper namespaceMapper = new NamespaceMapperJena(masterUnion, masterUnion, defaultNamespace);
|
||||||
sce.getServletContext().setAttribute("NamespaceMapper", namespaceMapper);
|
ctx.setAttribute("NamespaceMapper", namespaceMapper);
|
||||||
unionOms.getFullModel().getBaseModel().register(namespaceMapper);
|
unionOms.getFullModel().getBaseModel().register(namespaceMapper);
|
||||||
|
|
||||||
sce.getServletContext().setAttribute("defaultNamespace", defaultNamespace);
|
ctx.setAttribute("defaultNamespace", defaultNamespace);
|
||||||
|
|
||||||
log.info("SDB store ready for use");
|
log.info("SDB store ready for use");
|
||||||
|
|
||||||
makeModelMakerFromConnectionProperties(TripleStoreType.RDB);
|
makeModelMakerFromConnectionProperties(TripleStoreType.RDB, ctx);
|
||||||
VitroJenaModelMaker vjmm = getVitroJenaModelMaker();
|
VitroJenaModelMaker vjmm = getVitroJenaModelMaker();
|
||||||
setVitroJenaModelMaker(vjmm,sce);
|
setVitroJenaModelMaker(vjmm,sce);
|
||||||
makeModelMakerFromConnectionProperties(TripleStoreType.SDB);
|
makeModelMakerFromConnectionProperties(TripleStoreType.SDB, ctx);
|
||||||
VitroJenaSDBModelMaker vsmm = getVitroJenaSDBModelMaker();
|
VitroJenaSDBModelMaker vsmm = getVitroJenaSDBModelMaker();
|
||||||
setVitroJenaSDBModelMaker(vsmm,sce);
|
setVitroJenaSDBModelMaker(vsmm,sce);
|
||||||
|
|
||||||
|
@ -321,7 +323,7 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
} catch (SQLException sqle) {
|
} catch (SQLException sqle) {
|
||||||
|
|
||||||
// SQL exceptions are fatal and should halt startup
|
// SQL exceptions are fatal and should halt startup
|
||||||
AbortStartup.abortStartup(sce.getServletContext());
|
AbortStartup.abortStartup(ctx);
|
||||||
|
|
||||||
log.error("Error using SQL database; startup aborted.", sqle);
|
log.error("Error using SQL database; startup aborted.", sqle);
|
||||||
|
|
||||||
|
@ -375,7 +377,9 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
/* ====================================================================== */
|
/* ====================================================================== */
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent sce) {
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
|
// Nothing to do.
|
||||||
}
|
}
|
||||||
|
|
||||||
private ApplicationBean getApplicationBeanFromOntModel(OntModel ontModel,WebappDaoFactory wadf) {
|
private ApplicationBean getApplicationBeanFromOntModel(OntModel ontModel,WebappDaoFactory wadf) {
|
||||||
|
@ -383,7 +387,7 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
ResourceFactory.createResource(VitroVocabulary.APPLICATION));
|
ResourceFactory.createResource(VitroVocabulary.APPLICATION));
|
||||||
try {
|
try {
|
||||||
if (appIt.hasNext()) {
|
if (appIt.hasNext()) {
|
||||||
Individual appInd = (Individual) appIt.next();
|
Individual appInd = appIt.next();
|
||||||
ApplicationBean appBean = new ApplicationBean();
|
ApplicationBean appBean = new ApplicationBean();
|
||||||
try {
|
try {
|
||||||
appBean.setMaxPortalId(Integer.decode( ((Literal)appInd.getPropertyValue(ResourceFactory.createProperty(VitroVocabulary.APPLICATION_MAXPORTALID))).getLexicalForm()));
|
appBean.setMaxPortalId(Integer.decode( ((Literal)appInd.getPropertyValue(ResourceFactory.createProperty(VitroVocabulary.APPLICATION_MAXPORTALID))).getLexicalForm()));
|
||||||
|
@ -424,7 +428,7 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
||||||
//Set the default namespace to the namespace of the first portal object we find.
|
//Set the default namespace to the namespace of the first portal object we find.
|
||||||
//This will keep existing applications from dying when the default namespace
|
//This will keep existing applications from dying when the default namespace
|
||||||
//config option is missing.
|
//config option is missing.
|
||||||
Individual portal = (Individual) portalIt.next();
|
Individual portal = portalIt.next();
|
||||||
if (portal.getNameSpace() != null) {
|
if (portal.getNameSpace() != null) {
|
||||||
defaultNamespace = portal.getNameSpace();
|
defaultNamespace = portal.getNameSpace();
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,11 +23,14 @@ public class JenaPersistentDBOnlyDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(JenaPersistentDataSourceSetup.class.getName());
|
private static final Log log = LogFactory.getLog(JenaPersistentDataSourceSetup.class.getName());
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
|
ServletContext ctx = sce.getServletContext();
|
||||||
|
|
||||||
OntModel memModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
OntModel memModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
|
||||||
OntModel dbModel = null;
|
OntModel dbModel = null;
|
||||||
try {
|
try {
|
||||||
Model dbPlainModel = makeDBModelFromConfigurationProperties(JENA_DB_MODEL, DB_ONT_MODEL_SPEC);
|
Model dbPlainModel = makeDBModelFromConfigurationProperties(JENA_DB_MODEL, DB_ONT_MODEL_SPEC, ctx);
|
||||||
dbModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,dbPlainModel);
|
dbModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,dbPlainModel);
|
||||||
boolean isEmpty = true;
|
boolean isEmpty = true;
|
||||||
ClosableIterator stmtIt = dbModel.listStatements();
|
ClosableIterator stmtIt = dbModel.listStatements();
|
||||||
|
@ -42,15 +45,14 @@ public class JenaPersistentDBOnlyDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
if (isEmpty) {
|
if (isEmpty) {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
System.out.println("Reading ontology files into database");
|
System.out.println("Reading ontology files into database");
|
||||||
ServletContext ctx = sce.getServletContext();
|
|
||||||
readOntologyFilesInPathSet(USERPATH, ctx, dbModel);
|
readOntologyFilesInPathSet(USERPATH, ctx, dbModel);
|
||||||
readOntologyFilesInPathSet(AUTHPATH, ctx, dbModel);
|
readOntologyFilesInPathSet(AUTHPATH, ctx, dbModel);
|
||||||
readOntologyFilesInPathSet(SYSTEMPATH, ctx, dbModel);
|
readOntologyFilesInPathSet(SYSTEMPATH, ctx, dbModel);
|
||||||
System.out.println((System.currentTimeMillis()-startTime)/1000+" seconds to populate DB");
|
System.out.println((System.currentTimeMillis()-startTime)/1000+" seconds to populate DB");
|
||||||
}
|
}
|
||||||
|
|
||||||
//readOntologyFilesInPathSet(sce.getServletContext().getResourcePaths(AUTHPATH), sce, dbModel);
|
//readOntologyFilesInPathSet(ctx.getResourcePaths(AUTHPATH), sce, dbModel);
|
||||||
//readOntologyFilesInPathSet(sce.getServletContext().getResourcePaths(SYSTEMPATH), sce, dbModel);
|
//readOntologyFilesInPathSet(ctx.getResourcePaths(SYSTEMPATH), sce, dbModel);
|
||||||
|
|
||||||
memModel = dbModel;
|
memModel = dbModel;
|
||||||
|
|
||||||
|
@ -65,7 +67,6 @@ public class JenaPersistentDBOnlyDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
try {
|
try {
|
||||||
if (dbModel==null) {
|
if (dbModel==null) {
|
||||||
System.out.println("Reading ontology files");
|
System.out.println("Reading ontology files");
|
||||||
ServletContext ctx = sce.getServletContext();
|
|
||||||
readOntologyFilesInPathSet(USERPATH, ctx, dbModel);
|
readOntologyFilesInPathSet(USERPATH, ctx, dbModel);
|
||||||
readOntologyFilesInPathSet(AUTHPATH, ctx, dbModel);
|
readOntologyFilesInPathSet(AUTHPATH, ctx, dbModel);
|
||||||
readOntologyFilesInPathSet(SYSTEMPATH, ctx, dbModel);
|
readOntologyFilesInPathSet(SYSTEMPATH, ctx, dbModel);
|
||||||
|
@ -77,20 +78,21 @@ public class JenaPersistentDBOnlyDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
|
|
||||||
// default inference graph
|
// default inference graph
|
||||||
try {
|
try {
|
||||||
Model infDbPlainModel = makeDBModelFromConfigurationProperties(JENA_INF_MODEL, DB_ONT_MODEL_SPEC);
|
Model infDbPlainModel = makeDBModelFromConfigurationProperties(JENA_INF_MODEL, DB_ONT_MODEL_SPEC, ctx);
|
||||||
OntModel infDbModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,infDbPlainModel);
|
OntModel infDbModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,infDbPlainModel);
|
||||||
sce.getServletContext().setAttribute("inferenceOntModel",infDbModel);
|
ctx.setAttribute("inferenceOntModel",infDbModel);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error(e, e);
|
log.error(e, e);
|
||||||
}
|
}
|
||||||
|
|
||||||
sce.getServletContext().setAttribute("jenaOntModel", memModel);
|
ctx.setAttribute("jenaOntModel", memModel);
|
||||||
sce.getServletContext().setAttribute("persistentOntModel", dbModel);
|
ctx.setAttribute("persistentOntModel", dbModel);
|
||||||
|
|
||||||
// BJL23: This is a funky hack until I completely rework how the models get set up in a more sane fashion
|
// BJL23: This is a funky hack until I completely rework how the models get set up in a more sane fashion
|
||||||
sce.getServletContext().setAttribute("useModelSynchronizers", "false");
|
ctx.setAttribute("useModelSynchronizers", "false");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent sce) {
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
//Close the database connection
|
//Close the database connection
|
||||||
//try {
|
//try {
|
||||||
|
|
|
@ -6,7 +6,6 @@ import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
import org.apache.commons.dbcp.BasicDataSource;
|
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
|
|
||||||
|
@ -26,9 +25,11 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
private static final Log log = LogFactory.getLog(
|
private static final Log log = LogFactory.getLog(
|
||||||
JenaPersistentDataSourceSetup.class.getName());
|
JenaPersistentDataSourceSetup.class.getName());
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
|
ServletContext ctx = sce.getServletContext();
|
||||||
|
|
||||||
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
|
if (AbortStartup.isStartupAborted(ctx)) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -39,14 +40,13 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
try {
|
try {
|
||||||
|
|
||||||
dbModel = makeDBModelFromConfigurationProperties(
|
dbModel = makeDBModelFromConfigurationProperties(
|
||||||
JENA_DB_MODEL, DB_ONT_MODEL_SPEC);
|
JENA_DB_MODEL, DB_ONT_MODEL_SPEC, ctx);
|
||||||
|
|
||||||
boolean firstStartup = isFirstStartup(dbModel);
|
boolean firstStartup = isFirstStartup(dbModel);
|
||||||
|
|
||||||
if (firstStartup) {
|
if (firstStartup) {
|
||||||
long startTime = System.currentTimeMillis();
|
long startTime = System.currentTimeMillis();
|
||||||
System.out.println("Reading ontology files into database");
|
System.out.println("Reading ontology files into database");
|
||||||
ServletContext ctx = sce.getServletContext();
|
|
||||||
readOntologyFilesInPathSet(USERPATH, ctx, dbModel);
|
readOntologyFilesInPathSet(USERPATH, ctx, dbModel);
|
||||||
readOntologyFilesInPathSet(SYSTEMPATH, ctx, dbModel);
|
readOntologyFilesInPathSet(SYSTEMPATH, ctx, dbModel);
|
||||||
System.out.println(
|
System.out.println(
|
||||||
|
@ -55,7 +55,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (isSDBActive()) {
|
if (isSDBActive(ctx)) {
|
||||||
memModel = ModelFactory.createOntologyModel(
|
memModel = ModelFactory.createOntologyModel(
|
||||||
this.DB_ONT_MODEL_SPEC, dbModel);
|
this.DB_ONT_MODEL_SPEC, dbModel);
|
||||||
// no in-memory copying
|
// no in-memory copying
|
||||||
|
@ -94,10 +94,10 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
// default inference graph
|
// default inference graph
|
||||||
try {
|
try {
|
||||||
Model infDbModel = makeDBModelFromConfigurationProperties(
|
Model infDbModel = makeDBModelFromConfigurationProperties(
|
||||||
JENA_INF_MODEL, DB_ONT_MODEL_SPEC);
|
JENA_INF_MODEL, DB_ONT_MODEL_SPEC, ctx);
|
||||||
OntModel infModel = null;
|
OntModel infModel = null;
|
||||||
if (infDbModel != null) {
|
if (infDbModel != null) {
|
||||||
if (isSDBActive()) {
|
if (isSDBActive(ctx)) {
|
||||||
infModel = ModelFactory.createOntologyModel(
|
infModel = ModelFactory.createOntologyModel(
|
||||||
MEM_ONT_MODEL_SPEC, infDbModel);
|
MEM_ONT_MODEL_SPEC, infDbModel);
|
||||||
} else {
|
} else {
|
||||||
|
@ -112,7 +112,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
infModel.getBaseModel().register(new ModelSynchronizer(infDbModel));
|
infModel.getBaseModel().register(new ModelSynchronizer(infDbModel));
|
||||||
sce.getServletContext().setAttribute("inferenceOntModel",infModel);
|
ctx.setAttribute("inferenceOntModel",infModel);
|
||||||
} catch (Throwable e) {
|
} catch (Throwable e) {
|
||||||
log.error("Unable to load inference cache from DB", e);
|
log.error("Unable to load inference cache from DB", e);
|
||||||
}
|
}
|
||||||
|
@ -120,12 +120,12 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
// user accounts Model
|
// user accounts Model
|
||||||
try {
|
try {
|
||||||
Model userAccountsDbModel = makeDBModelFromConfigurationProperties(
|
Model userAccountsDbModel = makeDBModelFromConfigurationProperties(
|
||||||
JENA_USER_ACCOUNTS_MODEL, DB_ONT_MODEL_SPEC);
|
JENA_USER_ACCOUNTS_MODEL, DB_ONT_MODEL_SPEC, ctx);
|
||||||
if (userAccountsDbModel.size() == 0) {
|
if (userAccountsDbModel.size() == 0) {
|
||||||
readOntologyFilesInPathSet(AUTHPATH, sce.getServletContext(),
|
readOntologyFilesInPathSet(AUTHPATH, sce.getServletContext(),
|
||||||
userAccountsDbModel);
|
userAccountsDbModel);
|
||||||
if (userAccountsDbModel.size() == 0) {
|
if (userAccountsDbModel.size() == 0) {
|
||||||
createInitialAdminUser(userAccountsDbModel);
|
createInitialAdminUser(userAccountsDbModel, ctx);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
OntModel userAccountsModel = ModelFactory.createOntologyModel(
|
OntModel userAccountsModel = ModelFactory.createOntologyModel(
|
||||||
|
@ -142,7 +142,7 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
// display, editing and navigation Model
|
// display, editing and navigation Model
|
||||||
try {
|
try {
|
||||||
Model appDbModel = makeDBModelFromConfigurationProperties(
|
Model appDbModel = makeDBModelFromConfigurationProperties(
|
||||||
JENA_DISPLAY_METADATA_MODEL, DB_ONT_MODEL_SPEC);
|
JENA_DISPLAY_METADATA_MODEL, DB_ONT_MODEL_SPEC, ctx);
|
||||||
if (appDbModel.size() == 0)
|
if (appDbModel.size() == 0)
|
||||||
readOntologyFilesInPathSet(
|
readOntologyFilesInPathSet(
|
||||||
APPPATH, sce.getServletContext(),appDbModel);
|
APPPATH, sce.getServletContext(),appDbModel);
|
||||||
|
@ -150,12 +150,12 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
MEM_ONT_MODEL_SPEC);
|
MEM_ONT_MODEL_SPEC);
|
||||||
appModel.add(appDbModel);
|
appModel.add(appDbModel);
|
||||||
appModel.getBaseModel().register(new ModelSynchronizer(appDbModel));
|
appModel.getBaseModel().register(new ModelSynchronizer(appDbModel));
|
||||||
sce.getServletContext().setAttribute("displayOntModel", appModel);
|
ctx.setAttribute("displayOntModel", appModel);
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error("Unable to load user application configuration model from DB", t);
|
log.error("Unable to load user application configuration model from DB", t);
|
||||||
}
|
}
|
||||||
|
|
||||||
sce.getServletContext().setAttribute("jenaOntModel", memModel);
|
ctx.setAttribute("jenaOntModel", memModel);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -171,7 +171,9 @@ public class JenaPersistentDataSourceSetup extends JenaDataSourceSetupBase
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent sce) {
|
public void contextDestroyed(ServletContextEvent sce) {
|
||||||
|
// Nothing to do.
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -2,6 +2,7 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
|
|
||||||
|
@ -12,28 +13,30 @@ import com.hp.hpl.jena.ontology.OntModel;
|
||||||
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 edu.cornell.mannlib.vitro.webapp.auth.policy.JenaNetidPolicy.ContextSetup;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelAuditor;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.ModelAuditor;
|
||||||
|
|
||||||
public class ModelAuditorSetup extends JenaDataSourceSetupBase implements ServletContextListener {
|
public class ModelAuditorSetup extends JenaDataSourceSetupBase implements ServletContextListener {
|
||||||
|
|
||||||
private static final Log log = LogFactory.getLog(ModelAuditorSetup.class.getName());
|
private static final Log log = LogFactory.getLog(ModelAuditorSetup.class.getName());
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent arg0) {
|
public void contextDestroyed(ServletContextEvent arg0) {
|
||||||
// TODO Auto-generated method stub
|
// TODO Auto-generated method stub
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
|
ServletContext ctx = sce.getServletContext();
|
||||||
try {
|
try {
|
||||||
// the events don't seem to filter down to the writable model of a dynamic union. Bummer. For now we have the ugly workaround of registering twice and recording some duplication.
|
// the events don't seem to filter down to the writable model of a dynamic union. Bummer. For now we have the ugly workaround of registering twice and recording some duplication.
|
||||||
OntModel ontModel = (OntModel) sce.getServletContext().getAttribute("baseOntModel");
|
OntModel ontModel = (OntModel) ctx.getAttribute("baseOntModel");
|
||||||
Model baseModel = ontModel.getBaseModel();
|
Model baseModel = ontModel.getBaseModel();
|
||||||
OntModel dynamicUnionModel = (OntModel) sce.getServletContext().getAttribute("jenaOntModel");
|
OntModel dynamicUnionModel = (OntModel) ctx.getAttribute("jenaOntModel");
|
||||||
log.debug("Setting model auditor database...");
|
log.debug("Setting model auditor database...");
|
||||||
OntModel auditModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,makeDBModelFromConfigurationProperties(JENA_AUDIT_MODEL, DB_ONT_MODEL_SPEC));
|
OntModel auditModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC,makeDBModelFromConfigurationProperties(JENA_AUDIT_MODEL, DB_ONT_MODEL_SPEC, ctx));
|
||||||
sce.getServletContext().setAttribute("jenaAuditModel", auditModel);
|
ctx.setAttribute("jenaAuditModel", auditModel);
|
||||||
ModelAuditor ma = new ModelAuditor(auditModel,ontModel);
|
ModelAuditor ma = new ModelAuditor(auditModel,ontModel);
|
||||||
baseModel.register(ma);
|
baseModel.register(ma);
|
||||||
dynamicUnionModel.getBaseModel().register(ma);
|
dynamicUnionModel.getBaseModel().register(ma);
|
||||||
|
|
|
@ -2,8 +2,6 @@
|
||||||
|
|
||||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||||
|
|
||||||
import java.sql.Connection;
|
|
||||||
|
|
||||||
import javax.servlet.ServletContext;
|
import javax.servlet.ServletContext;
|
||||||
import javax.servlet.ServletContextEvent;
|
import javax.servlet.ServletContextEvent;
|
||||||
import javax.servlet.ServletContextListener;
|
import javax.servlet.ServletContextListener;
|
||||||
|
@ -13,23 +11,11 @@ import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.mindswap.pellet.PelletOptions;
|
import org.mindswap.pellet.PelletOptions;
|
||||||
|
|
||||||
import com.hp.hpl.jena.graph.Graph;
|
|
||||||
import com.hp.hpl.jena.ontology.OntModelSpec;
|
|
||||||
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.sdb.SDBFactory;
|
|
||||||
import com.hp.hpl.jena.sdb.Store;
|
|
||||||
import com.hp.hpl.jena.sdb.StoreDesc;
|
|
||||||
import com.hp.hpl.jena.sdb.sql.SDBConnection;
|
|
||||||
import com.hp.hpl.jena.sdb.store.DatabaseType;
|
|
||||||
import com.hp.hpl.jena.sdb.store.LayoutType;
|
|
||||||
import com.hp.hpl.jena.vocabulary.OWL;
|
import com.hp.hpl.jena.vocabulary.OWL;
|
||||||
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelector;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDBGraphGenerator;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.RegeneratingGraph;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.SDBGraphGenerator;
|
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.WebappDaoFactoryJena;
|
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.PelletListener;
|
||||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.ReasonerConfiguration;
|
import edu.cornell.mannlib.vitro.webapp.dao.jena.pellet.ReasonerConfiguration;
|
||||||
|
@ -45,6 +31,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
static final String JENA_INF_MODEL_REBUILD = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf-rebuild";
|
static final String JENA_INF_MODEL_REBUILD = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf-rebuild";
|
||||||
static final String JENA_INF_MODEL_SCRATCHPAD = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf-scratchpad";
|
static final String JENA_INF_MODEL_SCRATCHPAD = "http://vitro.mannlib.cornell.edu/default/vitro-kb-inf-scratchpad";
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextInitialized(ServletContextEvent sce) {
|
public void contextInitialized(ServletContextEvent sce) {
|
||||||
|
|
||||||
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
|
if (AbortStartup.isStartupAborted(sce.getServletContext())) {
|
||||||
|
@ -97,13 +84,13 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
JENA_INF_MODEL_REBUILD,
|
JENA_INF_MODEL_REBUILD,
|
||||||
JenaDataSourceSetupBase.DB_ONT_MODEL_SPEC,
|
JenaDataSourceSetupBase.DB_ONT_MODEL_SPEC,
|
||||||
TripleStoreType.SDB,
|
TripleStoreType.SDB,
|
||||||
dbType);
|
dbType, ctx);
|
||||||
Model scratchModel = JenaDataSourceSetupBase.makeDBModel(
|
Model scratchModel = JenaDataSourceSetupBase.makeDBModel(
|
||||||
bds,
|
bds,
|
||||||
JENA_INF_MODEL_SCRATCHPAD,
|
JENA_INF_MODEL_SCRATCHPAD,
|
||||||
JenaDataSourceSetupBase.DB_ONT_MODEL_SPEC,
|
JenaDataSourceSetupBase.DB_ONT_MODEL_SPEC,
|
||||||
TripleStoreType.SDB,
|
TripleStoreType.SDB,
|
||||||
dbType);
|
dbType, ctx);
|
||||||
|
|
||||||
|
|
||||||
// the simple reasoner will register itself as a listener to the ABox assertions
|
// the simple reasoner will register itself as a listener to the ABox assertions
|
||||||
|
@ -137,6 +124,7 @@ public class SimpleReasonerSetup implements ServletContextListener {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
public void contextDestroyed(ServletContextEvent arg0) {
|
public void contextDestroyed(ServletContextEvent arg0) {
|
||||||
// nothing to do
|
// nothing to do
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue