NIHVIVO-1449 add methods to JenaDataSourceSetupBase and remove VitroJenaModelMakerSetup listener
This commit is contained in:
parent
54395c6cb3
commit
6066180a6c
4 changed files with 65 additions and 47 deletions
|
@ -31,7 +31,9 @@ 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.SearchReindexingListener;
|
||||
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.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.jena.InitialJenaModelUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.NamespaceMapperJena;
|
||||
|
@ -110,6 +112,10 @@ public class JenaDataSourceSetup extends JenaDataSourceSetupBase implements java
|
|||
sce.getServletContext().setAttribute("NamespaceMapper", namespaceMapper);
|
||||
memModel.getBaseModel().register(namespaceMapper);
|
||||
|
||||
makeModelMakerFromConnectionProperties(TripleStoreType.RDB);
|
||||
VitroJenaModelMaker vjmm = getVitroJenaModelMaker();
|
||||
setVitroJenaModelMaker(vjmm,sce);
|
||||
|
||||
} catch (Throwable t) {
|
||||
log.error("Throwable in " + this.getClass().getName(), t);
|
||||
// printing the error because Tomcat doesn't print context listener
|
||||
|
|
|
@ -6,6 +6,7 @@ import java.io.InputStream;
|
|||
import java.util.Set;
|
||||
|
||||
import javax.servlet.ServletContext;
|
||||
import javax.servlet.ServletContextEvent;
|
||||
|
||||
import org.apache.commons.dbcp.BasicDataSource;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
@ -16,7 +17,10 @@ import com.hp.hpl.jena.ontology.OntModelSpec;
|
|||
import com.hp.hpl.jena.rdf.model.Model;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
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.sql.SDBConnection;
|
||||
import com.hp.hpl.jena.sdb.store.DatabaseType;
|
||||
import com.hp.hpl.jena.sdb.store.LayoutType;
|
||||
|
||||
|
@ -26,6 +30,8 @@ import edu.cornell.mannlib.vitro.webapp.dao.jena.JenaBaseDaoCon;
|
|||
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.VitroJenaModelMaker;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaSDBModelMaker;
|
||||
|
||||
public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
||||
private static final Log log = LogFactory.getLog(JenaDataSourceSetupBase.class);
|
||||
|
@ -261,5 +267,47 @@ public class JenaDataSourceSetupBase extends JenaBaseDaoCon {
|
|||
.createProperty(VitroVocabulary.USER_ROLE), model
|
||||
.createTypedLiteral("role:/50")));
|
||||
}
|
||||
|
||||
protected final static String DB_TYPE = "MySQL";
|
||||
private static VitroJenaModelMaker vjmm = null;
|
||||
private static VitroJenaSDBModelMaker vsmm = null;
|
||||
private static final String sdbModelMaker = "vitroJenaSDBModelMaker";
|
||||
private static final String rdbModelMaker = "vitroJenaModelMaker";
|
||||
|
||||
protected void makeModelMakerFromConnectionProperties(TripleStoreType type){
|
||||
String jdbcUrl = ConfigurationProperties.getProperty("VitroConnection.DataSource.url")
|
||||
+ "?useUnicode=yes&characterEncoding=utf8";
|
||||
String username = ConfigurationProperties.getProperty("VitroConnection.DataSource.username");
|
||||
String password = ConfigurationProperties.getProperty("VitroConnection.DataSource.password");
|
||||
|
||||
if (TripleStoreType.RDB.equals(type)){
|
||||
vjmm = new VitroJenaModelMaker(jdbcUrl, username, password, DB_TYPE);
|
||||
|
||||
}
|
||||
else if(TripleStoreType.SDB.equals(type)){
|
||||
StoreDesc storeDesc = new StoreDesc(LayoutType.LayoutTripleNodesHash,DatabaseType.MySQL);
|
||||
SDBConnection sdbConn = new SDBConnection(jdbcUrl,username,password);
|
||||
Store store = SDBFactory.connectStore(sdbConn, storeDesc);
|
||||
vsmm = new VitroJenaSDBModelMaker(store);
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
public static void setVitroJenaModelMaker(VitroJenaModelMaker vjmm, ServletContextEvent sce){
|
||||
sce.getServletContext().setAttribute(rdbModelMaker, vjmm);
|
||||
}
|
||||
|
||||
public static void setVitroJenaSDBModelMaker(VitroJenaSDBModelMaker vsmm, ServletContextEvent sce){
|
||||
sce.getServletContext().setAttribute(sdbModelMaker, vsmm);
|
||||
}
|
||||
|
||||
protected VitroJenaModelMaker getVitroJenaModelMaker(){
|
||||
return vjmm;
|
||||
}
|
||||
|
||||
protected VitroJenaSDBModelMaker getVitroJenaSDBModelMaker(){
|
||||
return vsmm;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -43,7 +43,10 @@ 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.ModelSynchronizer;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.OntModelSelectorImpl;
|
||||
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.WebappDaoFactorySDB;
|
||||
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.jena.InitialJenaModelUtils;
|
||||
import edu.cornell.mannlib.vitro.webapp.utils.jena.NamespaceMapperJena;
|
||||
|
@ -266,7 +269,14 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
|
|||
memModel.getBaseModel().register(namespaceMapper);
|
||||
|
||||
sce.getServletContext().setAttribute("defaultNamespace", defaultNamespace);
|
||||
|
||||
|
||||
makeModelMakerFromConnectionProperties(TripleStoreType.RDB);
|
||||
VitroJenaModelMaker vjmm = getVitroJenaModelMaker();
|
||||
setVitroJenaModelMaker(vjmm,sce);
|
||||
makeModelMakerFromConnectionProperties(TripleStoreType.SDB);
|
||||
VitroJenaSDBModelMaker vsmm = getVitroJenaSDBModelMaker();
|
||||
setVitroJenaSDBModelMaker(vsmm,sce);
|
||||
|
||||
} catch (Throwable t) {
|
||||
log.error("Throwable in " + this.getClass().getName(), t);
|
||||
// printing the error because Tomcat doesn't print context listener
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
|
||||
|
||||
package edu.cornell.mannlib.vitro.webapp.servlet.setup;
|
||||
|
||||
import javax.servlet.ServletContextEvent;
|
||||
import javax.servlet.ServletContextListener;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import com.hp.hpl.jena.db.DBConnection;
|
||||
import com.hp.hpl.jena.rdf.model.ModelFactory;
|
||||
import com.hp.hpl.jena.rdf.model.ModelMaker;
|
||||
|
||||
import edu.cornell.mannlib.vitro.webapp.ConfigurationProperties;
|
||||
import edu.cornell.mannlib.vitro.webapp.dao.jena.VitroJenaModelMaker;
|
||||
|
||||
public class VitroJenaModelMakerSetup implements ServletContextListener {
|
||||
private static final Log log = LogFactory
|
||||
.getLog(VitroJenaModelMakerSetup.class);
|
||||
|
||||
protected final static String DB_TYPE = "MySQL";
|
||||
|
||||
public void contextDestroyed(ServletContextEvent arg0) {
|
||||
// TODO Auto-generated method stub
|
||||
}
|
||||
|
||||
public void contextInitialized(ServletContextEvent arg0) {
|
||||
try {
|
||||
String jdbcUrl = ConfigurationProperties.getProperty("VitroConnection.DataSource.url")
|
||||
+ "?useUnicode=yes&characterEncoding=utf8";
|
||||
String username = ConfigurationProperties.getProperty("VitroConnection.DataSource.username");
|
||||
String password = ConfigurationProperties.getProperty("VitroConnection.DataSource.password");
|
||||
|
||||
DBConnection dbConn = new DBConnection(jdbcUrl, username, password, DB_TYPE);
|
||||
;
|
||||
VitroJenaModelMaker vjmm = new VitroJenaModelMaker(jdbcUrl, username, password, DB_TYPE);
|
||||
arg0.getServletContext().setAttribute("vitroJenaModelMaker", vjmm);
|
||||
log.debug("VitroJenaModelMaker set up");
|
||||
} catch (Throwable t) {
|
||||
log.error("Unable to set up default VitroJenaModelMaker", t);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue