From aad1ea806b33f20acad2453d5ba1fea2f61753b7 Mon Sep 17 00:00:00 2001 From: bjl23 Date: Mon, 17 Jan 2011 21:09:32 +0000 Subject: [PATCH] NIHVIVO-1761 bugfix for backend property deletion --- .../vedit/controller/OperationController.java | 5 +- .../mannlib/vedit/util/OperationUtils.java | 56 +++++++++----- .../jena/DataPropertyStatementDaoJena.java | 76 ++++++++++++------- .../vitro/webapp/dao/jena/IndividualSDB.java | 32 ++++++-- .../vitro/webapp/dao/jena/JenaBaseDao.java | 1 - .../webapp/dao/jena/PropertyDaoJena.java | 4 +- .../webapp/dao/jena/WebappDaoFactoryJena.java | 1 + .../webapp/dao/jena/WebappDaoFactorySDB.java | 18 +++++ 8 files changed, 139 insertions(+), 54 deletions(-) diff --git a/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java b/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java index 184e1ed5c..6fa6e745c 100644 --- a/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java +++ b/webapp/src/edu/cornell/mannlib/vedit/controller/OperationController.java @@ -215,7 +215,10 @@ public class OperationController extends BaseEditController { Object newObj = null; if (epo.getOriginalBean() != null) { // we're updating or deleting an existing bean if (epo.getImplementationClass() != null) { - newObj = OperationUtils.cloneBean(epo.getOriginalBean(), epo.getImplementationClass()); + newObj = OperationUtils.cloneBean( + epo.getOriginalBean(), + epo.getImplementationClass(), + epo.getBeanClass()); } else { newObj = OperationUtils.cloneBean(epo.getOriginalBean()); } diff --git a/webapp/src/edu/cornell/mannlib/vedit/util/OperationUtils.java b/webapp/src/edu/cornell/mannlib/vedit/util/OperationUtils.java index fad1cd6fa..63b024cb8 100644 --- a/webapp/src/edu/cornell/mannlib/vedit/util/OperationUtils.java +++ b/webapp/src/edu/cornell/mannlib/vedit/util/OperationUtils.java @@ -67,7 +67,7 @@ public class OperationUtils{ * @return */ public static Object cloneBean (Object bean) { - return cloneBean(bean, bean.getClass()); + return cloneBean(bean, bean.getClass(), bean.getClass()); } /** @@ -76,39 +76,61 @@ public class OperationUtils{ * @param bean * @return */ - public static Object cloneBean (Object bean, Class beanClass){ + public static Object cloneBean (Object bean, Class beanClass, Class iface){ Object newBean = null; try { newBean = beanClass.newInstance(); - Method[] beanMeths = beanClass.getMethods(); - for (int i=0; i ?value } \n" + + "WHERE { GRAPH ?g { ?ind <" + + propertyURI + "> ?value } } \n"; + Query query = QueryFactory.create(queryStr); + QueryExecution qe = QueryExecutionFactory.create( + query, dataset); + qe.execConstruct(ind.getModel()); + } finally { + dataset.getLock().leaveCriticalSection(); + w.close(); + } + } public Float getSearchBoost(){ if( this._searchBoostJena != null ){ diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java index e9a580058..3f1344536 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/JenaBaseDao.java @@ -142,7 +142,6 @@ public class JenaBaseDao extends JenaBaseDaoCon { protected void addPropertyStringValue(Resource res, Property dataprop, String value, Model model) { if (res != null && dataprop != null && value != null && value.length()>0) { model.add(res, dataprop, value, XSDDatatype.XSDstring); - System.out.println("JenaBaseDao" + value); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java index 8c78ce6cd..301334011 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/PropertyDaoJena.java @@ -48,7 +48,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao { "PREFIX owl: \n" + "PREFIX afn: "; - private DatasetWrapperFactory dwf; + protected DatasetWrapperFactory dwf; public PropertyDaoJena(DatasetWrapperFactory dwf, WebappDaoFactoryJena wadf) { @@ -396,7 +396,7 @@ public class PropertyDaoJena extends JenaBaseDao implements PropertyDao { subjectBinding.add("subject", ResourceFactory.createResource(subjectUri)); - // Run the SPARQL query to get the properties + // Run the SPARQL query to get the properties DatasetWrapper w = dwf.getDatasetWrapper(); Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java index 489a96f28..6807768b9 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactoryJena.java @@ -118,6 +118,7 @@ public class WebappDaoFactoryJena implements WebappDaoFactory { this.userURI = userURI; this.flag2ValueMap = base.flag2ValueMap; this.flag2ClassLabelMap = base.flag2ClassLabelMap; + this.dwf = base.dwf; } public WebappDaoFactoryJena(OntModelSelector ontModelSelector, diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java index 348dd1235..769263327 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/WebappDaoFactorySDB.java @@ -18,6 +18,7 @@ import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.IndividualDao; import edu.cornell.mannlib.vitro.webapp.dao.ObjectPropertyStatementDao; import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; +import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactory; public class WebappDaoFactorySDB extends WebappDaoFactoryJena { @@ -62,6 +63,18 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { super(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages); this.dwf = new ReconnectingDatasetFactory(bds, storeDesc); } + + public WebappDaoFactorySDB(WebappDaoFactorySDB base, String userURI) { + super(base.ontModelSelector); + this.ontModelSelector = base.ontModelSelector; + this.defaultNamespace = base.defaultNamespace; + this.nonuserNamespaces = base.nonuserNamespaces; + this.preferredLanguages = base.preferredLanguages; + this.userURI = userURI; + this.flag2ValueMap = base.flag2ValueMap; + this.flag2ClassLabelMap = base.flag2ClassLabelMap; + this.dwf = base.dwf; + } @Override public IndividualDao getIndividualDao() { @@ -95,6 +108,11 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { return vClassDao = new VClassDaoSDB(dwf, this); } + public WebappDaoFactory getUserAwareDaoFactory(String userURI) { + // TODO: put the user-aware factories in a hashmap so we don't keep re-creating them + return new WebappDaoFactorySDB(this, userURI); + } + private class ReconnectingDatasetFactory implements DatasetWrapperFactory { private BasicDataSource _bds;