NIHVIVO-2066 unregistering external namespace listeners

This commit is contained in:
bjl23 2011-02-08 19:01:45 +00:00
parent 788f1c9ecc
commit ffafb81ab7
6 changed files with 51 additions and 37 deletions

View file

@ -138,4 +138,6 @@ public interface WebappDaoFactory {
public PageDao getPageDao();
public MenuDao getMenuDao();
public void close();
}

View file

@ -316,4 +316,9 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory {
public DisplayModelDao getDisplayModelDao(){
return innerWebappDaoFactory.getDisplayModelDao();
}
@Override
public void close() {
innerWebappDaoFactory.close();
}
}

View file

@ -8,6 +8,7 @@ import java.util.List;
import com.hp.hpl.jena.ontology.OntModel;
import com.hp.hpl.jena.rdf.listeners.StatementListener;
import com.hp.hpl.jena.rdf.model.Literal;
import com.hp.hpl.jena.rdf.model.ModelChangedListener;
import com.hp.hpl.jena.rdf.model.NodeIterator;
import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode;
@ -26,14 +27,20 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
Integer portalCount = null;
List<String> externallyLinkedNamespaces = null;
ModelChangedListener modelChangedListener = null;
public ApplicationDaoJena(WebappDaoFactoryJena wadf) {
super(wadf);
getOntModelSelector().getDisplayModel().register(
new ExternalNamespacesChangeListener());
modelChangedListener = new ExternalNamespacesChangeListener();
getOntModelSelector().getDisplayModel().register(modelChangedListener);
}
public void close() {
if (modelChangedListener != null) {
getOntModelSelector().getDisplayModel().unregister(modelChangedListener);
}
}
public boolean isFlag1Active() {
boolean somePortalIsFiltering=false;
if (portalCount == null) {

View file

@ -73,7 +73,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
protected KeywordDao keywordDao;
protected LinksDao linksDao;
protected LinktypeDao linktypeDao;
protected ApplicationDao applicationDao;
protected ApplicationDaoJena applicationDao;
protected PortalDao portalDao;
protected TabDao tabDao;
protected TabIndividualRelationDao tabs2EntsDao;
@ -658,5 +658,12 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
public DisplayModelDao getDisplayModelDao(){
return new DisplayModelDaoJena( this );
}
@Override
public void close() {
if (applicationDao != null) {
applicationDao.close();
}
}
}

View file

@ -198,6 +198,6 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena {
}
}
}
}
}

View file

@ -85,31 +85,28 @@ public class WebappDaoFactorySDBPrep implements Filter {
SDBConnection conn = null;
Store store = null;
Dataset dataset = null;
WebappDaoFactory wadf = null;
try {
if ( request instanceof HttpServletRequest
&& JenaDataSourceSetupBase.isSDBActive()) {
if (bds == null || storeDesc == null || oms == null) {
throw new RuntimeException("SDB store not property set up");
}
try {
sqlConn = bds.getConnection();
conn = new SDBConnection(sqlConn) ;
} catch (SQLException sqe) {
throw new RuntimeException("Unable to connect to database", sqe);
}
if (conn != null) {
store = SDBFactory.connectStore(conn, storeDesc);
dataset = SDBFactory.connectDataset(store);
VitroRequest vreq = new VitroRequest((HttpServletRequest) request);
WebappDaoFactory wadf =
new WebappDaoFactorySDB(oms, dataset, defaultNamespace, null, null);
vreq.setWebappDaoFactory(wadf);
vreq.setFullWebappDaoFactory(wadf);
vreq.setDataset(dataset);
}
try {
if (bds == null || storeDesc == null || oms == null) {
throw new RuntimeException("SDB store not property set up");
}
try {
sqlConn = bds.getConnection();
conn = new SDBConnection(sqlConn) ;
} catch (SQLException sqe) {
throw new RuntimeException("Unable to connect to database", sqe);
}
if (conn != null) {
store = SDBFactory.connectStore(conn, storeDesc);
dataset = SDBFactory.connectDataset(store);
VitroRequest vreq = new VitroRequest((HttpServletRequest) request);
wadf =
new WebappDaoFactorySDB(oms, dataset, defaultNamespace, null, null);
vreq.setWebappDaoFactory(wadf);
vreq.setFullWebappDaoFactory(wadf);
vreq.setDataset(dataset);
}
} catch (Throwable t) {
log.error("Unable to filter request to set up SDB connection", t);
@ -124,19 +121,15 @@ public class WebappDaoFactorySDBPrep implements Filter {
if (conn != null) {
conn.close();
}
if (sqlConn != null) {
try {
sqlConn.close();
} catch (SQLException e) {
log.error("Unable to close SQL connection", e);
}
}
if (dataset != null) {
dataset.close();
}
if (store != null) {
store.close();
}
if (wadf != null) {
wadf.close();
}
}
}