From 1713933e9354942fa178822767e4b62ba7204fd5 Mon Sep 17 00:00:00 2001 From: brianjlowe Date: Fri, 22 Jul 2011 18:05:43 +0000 Subject: [PATCH] NIHVIVO-3029 fixes deletion of class groups and property groups, and fixes excessive locking during VClassGroupCache rebuild --- .../webapp/dao/jena/PropertyGroupDaoJena.java | 10 +++ .../webapp/dao/jena/VClassGroupDaoJena.java | 65 ++++++++----------- 2 files changed, 38 insertions(+), 37 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyGroupDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyGroupDaoJena.java index dc1a80d8d..40b9bb1ad 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyGroupDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyGroupDaoJena.java @@ -19,6 +19,7 @@ import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.ModelFactory; import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.rdf.model.Statement; import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.util.iterator.ClosableIterator; @@ -56,6 +57,15 @@ public class PropertyGroupDaoJena extends JenaBaseDao implements PropertyGroupDa } finally { getOntModel().leaveCriticalSection(); } + OntModel tboxModel = getOntModelSelector().getTBoxModel(); + tboxModel.enterCriticalSection(Lock.WRITE); + try { + Resource groupRes = ResourceFactory.createResource(group.getURI()); + tboxModel.removeAll(groupRes, null, null); + tboxModel.removeAll(null, null, groupRes); + } finally { + tboxModel.leaveCriticalSection(); + } } public PropertyGroup getGroupByURI(String uri) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupDaoJena.java index 292648e0c..e99689808 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassGroupDaoJena.java @@ -20,6 +20,8 @@ import com.hp.hpl.jena.ontology.OntModel; import com.hp.hpl.jena.ontology.OntModelSpec; import com.hp.hpl.jena.rdf.model.Literal; import com.hp.hpl.jena.rdf.model.ModelFactory; +import com.hp.hpl.jena.rdf.model.Resource; +import com.hp.hpl.jena.rdf.model.ResourceFactory; import com.hp.hpl.jena.shared.Lock; import com.hp.hpl.jena.util.iterator.ClosableIterator; @@ -61,6 +63,15 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao { } finally { ontModel.leaveCriticalSection(); } + OntModel tboxModel = getOntModelSelector().getTBoxModel(); + tboxModel.enterCriticalSection(Lock.WRITE); + try { + Resource groupRes = ResourceFactory.createResource(vcg.getURI()); + tboxModel.removeAll(groupRes, null, null); + tboxModel.removeAll(null, null, groupRes); + } finally { + tboxModel.leaveCriticalSection(); + } } public LinkedHashMap getClassGroupMap() { @@ -123,16 +134,15 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao { public List getPublicGroupsWithVClasses(boolean displayOrder, boolean includeUninstantiatedClasses, boolean getIndividualCount) { VClassDao classDao = getWebappDaoFactory().getVClassDao(); + List groups = new ArrayList(); getOntModel().enterCriticalSection(Lock.READ); try { - List groups = new ArrayList(); ClosableIterator groupIt = getOntModel().listIndividuals(CLASSGROUP); try { while (groupIt.hasNext()) { Individual grp = (Individual) groupIt.next(); VClassGroup vgrp = groupFromGroupIndividual(grp); - if (vgrp!=null) { - classDao.addVClassesToGroup(vgrp, includeUninstantiatedClasses, getIndividualCount); + if (vgrp != null) { groups.add(vgrp); } } @@ -140,43 +150,24 @@ public class VClassGroupDaoJena extends JenaBaseDao implements VClassGroupDao { } finally { groupIt.close(); } - // BJL23 2008-12-18 - // It's often problematic that classes don't show up in editing picklists until they're in a classgroup. - // I'm going to try adding all other classes to a classgroup called "ungrouped" - // We really need to rework these methods and move the filtering behavior into the nice filtering framework - /* commenting this out until I rework the filtering DAO to use this method */ - /* - List ungroupedClasses = new ArrayList(); - List allClassList = getWebappDaoFactory().getVClassDao().getAllVclasses(); - Iterator allClassIt = allClassList.iterator(); - while (allClassIt.hasNext()) { - VClass cls = allClassIt.next(); - if (cls.getGroupURI()==null) { - ungroupedClasses.add(cls); - } - } - if (ungroupedClasses.size()>0) { - VClassGroup ungrouped = new VClassGroup(); - ungrouped.setPublicName("ungrouped"); - groups.add(ungrouped); - } - */ - if (groups.size()>0) { - return groups; - } else { - /* bdc34: the effect of the following code is that - * classgroups will get empty vclasses added to them - * when includeUninstantiatedClasses == false and all - * the vclasses are empty. - * This may not be the desired behavior. - */ - classDao.addVClassesToGroups(groups); - return groups; - } } finally { getOntModel().leaveCriticalSection(); } - + for (VClassGroup vgrp : groups) { + classDao.addVClassesToGroup(vgrp, includeUninstantiatedClasses, getIndividualCount); + } + if (groups.size()>0) { + return groups; + } else { + /* bdc34: the effect of the following code is that + * classgroups will get empty vclasses added to them + * when includeUninstantiatedClasses == false and all + * the vclasses are empty. + * This may not be the desired behavior. + */ + classDao.addVClassesToGroups(groups); + return groups; + } }