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 PageDao getPageDao();
public MenuDao getMenuDao(); public MenuDao getMenuDao();
public void close();
} }

View file

@ -316,4 +316,9 @@ public class WebappDaoFactoryFiltering implements WebappDaoFactory {
public DisplayModelDao getDisplayModelDao(){ public DisplayModelDao getDisplayModelDao(){
return innerWebappDaoFactory.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.ontology.OntModel;
import com.hp.hpl.jena.rdf.listeners.StatementListener; import com.hp.hpl.jena.rdf.listeners.StatementListener;
import com.hp.hpl.jena.rdf.model.Literal; 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.NodeIterator;
import com.hp.hpl.jena.rdf.model.Property; import com.hp.hpl.jena.rdf.model.Property;
import com.hp.hpl.jena.rdf.model.RDFNode; import com.hp.hpl.jena.rdf.model.RDFNode;
@ -26,14 +27,20 @@ public class ApplicationDaoJena extends JenaBaseDao implements ApplicationDao {
Integer portalCount = null; Integer portalCount = null;
List<String> externallyLinkedNamespaces = null; List<String> externallyLinkedNamespaces = null;
ModelChangedListener modelChangedListener = null;
public ApplicationDaoJena(WebappDaoFactoryJena wadf) { public ApplicationDaoJena(WebappDaoFactoryJena wadf) {
super(wadf); super(wadf);
getOntModelSelector().getDisplayModel().register( modelChangedListener = new ExternalNamespacesChangeListener();
new ExternalNamespacesChangeListener()); getOntModelSelector().getDisplayModel().register(modelChangedListener);
} }
public void close() {
if (modelChangedListener != null) {
getOntModelSelector().getDisplayModel().unregister(modelChangedListener);
}
}
public boolean isFlag1Active() { public boolean isFlag1Active() {
boolean somePortalIsFiltering=false; boolean somePortalIsFiltering=false;
if (portalCount == null) { if (portalCount == null) {

View file

@ -73,7 +73,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
protected KeywordDao keywordDao; protected KeywordDao keywordDao;
protected LinksDao linksDao; protected LinksDao linksDao;
protected LinktypeDao linktypeDao; protected LinktypeDao linktypeDao;
protected ApplicationDao applicationDao; protected ApplicationDaoJena applicationDao;
protected PortalDao portalDao; protected PortalDao portalDao;
protected TabDao tabDao; protected TabDao tabDao;
protected TabIndividualRelationDao tabs2EntsDao; protected TabIndividualRelationDao tabs2EntsDao;
@ -658,5 +658,12 @@ public class WebappDaoFactoryJena implements WebappDaoFactory {
public DisplayModelDao getDisplayModelDao(){ public DisplayModelDao getDisplayModelDao(){
return new DisplayModelDaoJena( this ); 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; SDBConnection conn = null;
Store store = null; Store store = null;
Dataset dataset = null; Dataset dataset = null;
WebappDaoFactory wadf = null;
try { try {
if ( request instanceof HttpServletRequest if (bds == null || storeDesc == null || oms == null) {
&& JenaDataSourceSetupBase.isSDBActive()) { throw new RuntimeException("SDB store not property set up");
}
if (bds == null || storeDesc == null || oms == null) {
throw new RuntimeException("SDB store not property set up"); try {
} sqlConn = bds.getConnection();
conn = new SDBConnection(sqlConn) ;
try { } catch (SQLException sqe) {
sqlConn = bds.getConnection(); throw new RuntimeException("Unable to connect to database", sqe);
conn = new SDBConnection(sqlConn) ; }
} catch (SQLException sqe) { if (conn != null) {
throw new RuntimeException("Unable to connect to database", sqe); store = SDBFactory.connectStore(conn, storeDesc);
} dataset = SDBFactory.connectDataset(store);
if (conn != null) { VitroRequest vreq = new VitroRequest((HttpServletRequest) request);
store = SDBFactory.connectStore(conn, storeDesc); wadf =
dataset = SDBFactory.connectDataset(store); new WebappDaoFactorySDB(oms, dataset, defaultNamespace, null, null);
VitroRequest vreq = new VitroRequest((HttpServletRequest) request); vreq.setWebappDaoFactory(wadf);
WebappDaoFactory wadf = vreq.setFullWebappDaoFactory(wadf);
new WebappDaoFactorySDB(oms, dataset, defaultNamespace, null, null); vreq.setDataset(dataset);
vreq.setWebappDaoFactory(wadf);
vreq.setFullWebappDaoFactory(wadf);
vreq.setDataset(dataset);
}
} }
} catch (Throwable t) { } catch (Throwable t) {
log.error("Unable to filter request to set up SDB connection", 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) { if (conn != null) {
conn.close(); conn.close();
} }
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();
} }
if (store != null) { if (store != null) {
store.close(); store.close();
} }
if (wadf != null) {
wadf.close();
}
} }
} }