removing erroneous instance variables from WebappDaoFactorySDBPrep
This commit is contained in:
parent
0055398674
commit
f07999fc14
1 changed files with 27 additions and 25 deletions
|
@ -3,6 +3,7 @@
|
||||||
package edu.cornell.mannlib.vitro.webapp.filters;
|
package edu.cornell.mannlib.vitro.webapp.filters;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
import java.sql.Connection;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
import java.util.regex.Matcher;
|
import java.util.regex.Matcher;
|
||||||
import java.util.regex.Pattern;
|
import java.util.regex.Pattern;
|
||||||
|
@ -36,11 +37,7 @@ public class WebappDaoFactorySDBPrep implements Filter {
|
||||||
|
|
||||||
private final static Log log = LogFactory.getLog(WebappDaoFactorySDBPrep.class);
|
private final static Log log = LogFactory.getLog(WebappDaoFactorySDBPrep.class);
|
||||||
|
|
||||||
BasicDataSource _bds;
|
ServletContext _ctx;
|
||||||
StoreDesc _storeDesc;
|
|
||||||
SDBConnection _conn;
|
|
||||||
OntModelSelector _oms;
|
|
||||||
String _defaultNamespace;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The filter will be applied to all incoming urls,
|
* The filter will be applied to all incoming urls,
|
||||||
|
@ -80,25 +77,35 @@ public class WebappDaoFactorySDBPrep implements Filter {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
BasicDataSource bds = JenaDataSourceSetupBase.getApplicationDataSource(_ctx);
|
||||||
|
StoreDesc storeDesc = (StoreDesc) _ctx.getAttribute("storeDesc");
|
||||||
|
OntModelSelector oms = (OntModelSelector) _ctx.getAttribute("unionOntModelSelector");
|
||||||
|
String defaultNamespace = (String) _ctx.getAttribute("defaultNamespace");
|
||||||
|
Connection sqlConn = null;
|
||||||
SDBConnection conn = null;
|
SDBConnection conn = null;
|
||||||
Store store = null;
|
Store store = null;
|
||||||
Dataset dataset = null;
|
Dataset dataset = null;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (
|
if ( request instanceof HttpServletRequest
|
||||||
request instanceof HttpServletRequest &&
|
&& JenaDataSourceSetupBase.isSDBActive()) {
|
||||||
_bds != null && _storeDesc != null && _oms != null) {
|
|
||||||
|
if (bds == null || storeDesc == null || oms == null) {
|
||||||
|
throw new RuntimeException("SDB store not property set up");
|
||||||
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
conn = new SDBConnection(_bds.getConnection()) ;
|
sqlConn = bds.getConnection();
|
||||||
|
conn = new SDBConnection(sqlConn) ;
|
||||||
} catch (SQLException sqe) {
|
} catch (SQLException sqe) {
|
||||||
throw new RuntimeException("Unable to connect to database", sqe);
|
throw new RuntimeException("Unable to connect to database", sqe);
|
||||||
}
|
}
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
store = SDBFactory.connectStore(conn, _storeDesc);
|
store = SDBFactory.connectStore(conn, storeDesc);
|
||||||
dataset = SDBFactory.connectDataset(store);
|
dataset = SDBFactory.connectDataset(store);
|
||||||
VitroRequest vreq = new VitroRequest((HttpServletRequest) request);
|
VitroRequest vreq = new VitroRequest((HttpServletRequest) request);
|
||||||
WebappDaoFactory wadf =
|
WebappDaoFactory wadf =
|
||||||
new WebappDaoFactorySDB(_oms, dataset, _defaultNamespace, null, null);
|
new WebappDaoFactorySDB(oms, dataset, defaultNamespace, null, null);
|
||||||
vreq.setWebappDaoFactory(wadf);
|
vreq.setWebappDaoFactory(wadf);
|
||||||
vreq.setFullWebappDaoFactory(wadf);
|
vreq.setFullWebappDaoFactory(wadf);
|
||||||
vreq.setDataset(dataset);
|
vreq.setDataset(dataset);
|
||||||
|
@ -116,34 +123,29 @@ public class WebappDaoFactorySDBPrep implements Filter {
|
||||||
} finally {
|
} finally {
|
||||||
if (conn != null) {
|
if (conn != null) {
|
||||||
conn.close();
|
conn.close();
|
||||||
conn = null;
|
}
|
||||||
|
if (sqlConn != null) {
|
||||||
|
try {
|
||||||
|
sqlConn.close();
|
||||||
|
} catch (SQLException e) {
|
||||||
|
log.error("Unable to close SQL connection", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if (dataset != null) {
|
if (dataset != null) {
|
||||||
dataset.close();
|
dataset.close();
|
||||||
dataset = null;
|
|
||||||
}
|
}
|
||||||
if (store != null) {
|
if (store != null) {
|
||||||
store.close();
|
store.close();
|
||||||
store = null;
|
|
||||||
}
|
}
|
||||||
_bds = null;
|
|
||||||
_storeDesc = null;
|
|
||||||
_conn = null;
|
|
||||||
_oms = null;
|
|
||||||
_defaultNamespace = null;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public void init(FilterConfig filterConfig) throws ServletException {
|
public void init(FilterConfig filterConfig) throws ServletException {
|
||||||
try {
|
try {
|
||||||
ServletContext ctx = filterConfig.getServletContext();
|
_ctx = filterConfig.getServletContext();
|
||||||
_bds = JenaDataSourceSetupBase.getApplicationDataSource(ctx);
|
|
||||||
_storeDesc = (StoreDesc) ctx.getAttribute("storeDesc");
|
|
||||||
_oms = (OntModelSelector) ctx.getAttribute("unionOntModelSelector");
|
|
||||||
_defaultNamespace = (String) ctx.getAttribute("defaultNamespace");
|
|
||||||
} catch (Throwable t) {
|
} catch (Throwable t) {
|
||||||
log.error("Unable to set up SDB WebappDaoFactory for request", t);
|
log.error("Unable to initialize WebappDaoFactorySDBPrep", t);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue