diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java index 9b82cd00f..f3f7d26e2 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/JenaIngestController.java @@ -1312,9 +1312,6 @@ private String doRename(String oldNamespace,String newNamespace,HttpServletRespo result = counter.toString() + " resources renamed"; return result; - } - public void prepareSmush (VitroRequest vreq) { - String smushPropURI = vreq.getParameter("smushPropURI"); - } + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/RDFUploadController.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/RDFUploadController.java index 86a1379fb..6869a2b7e 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/RDFUploadController.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/controller/jena/RDFUploadController.java @@ -10,11 +10,14 @@ import java.util.List; import java.util.Map; import javax.servlet.RequestDispatcher; +import javax.servlet.ServletContext; import javax.servlet.ServletException; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import org.apache.commons.fileupload.FileItem; +import org.apache.commons.fileupload.servlet.ServletFileUpload; import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; @@ -40,13 +43,14 @@ import edu.cornell.mannlib.vitro.webapp.filestorage.uploadrequest.FileUploadServ public class RDFUploadController extends BaseEditController { - private static int maxFileSizeInBytes = 1024 * 1024 * 2000; //2000mb + private static int maxFileSizeInBytes = 1024 * 1024 * 2000; //2000mb private static FileItem fileStream=null; private static final String INGEST_MENU_JSP = "/jenaIngest/ingestMenu.jsp"; private static final String LOAD_RDF_DATA_JSP = "/jenaIngest/loadRDFData.jsp"; public void doPost(HttpServletRequest rawRequest, HttpServletResponse response) throws ServletException, IOException { + FileUploadServletRequest req = FileUploadServletRequest.parseRequest(rawRequest, maxFileSizeInBytes); if (req.hasFileUploadException()) { @@ -85,6 +89,10 @@ public class RDFUploadController extends BaseEditController { boolean makeClassgroups = (request.getParameter("makeClassgroups") != null); + // add directly to the ABox model without reading first into + // a temporary in-memory model + boolean directRead = ("directAddABox".equals(request.getParameter("mode"))); + int[] portalArray = null; String individualCheckIn = request.getParameter("checkIndividualsIntoPortal"); if (individualCheckIn != null) { @@ -108,14 +116,21 @@ public class RDFUploadController extends BaseEditController { } String uploadDesc =""; - - OntModel tempModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + + OntModel uploadModel = (directRead) + ? getABoxModel(request.getSession(), getServletContext()) + : ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); /* ********************* GET RDF by URL ********************** */ String RDFUrlStr = request.getParameter("rdfUrl"); if (RDFUrlStr != null && RDFUrlStr.length() > 0) { try { - tempModel.read(RDFUrlStr, languageStr); // languageStr may be null and default would be RDF/XML + uploadModel.enterCriticalSection(Lock.WRITE); + try { + uploadModel.read(RDFUrlStr, languageStr); // languageStr may be null and default would be RDF/XML + } finally { + uploadModel.leaveCriticalSection(); + } uploadDesc = verb + " RDF from " + RDFUrlStr; } catch (JenaException ex){ forwardToFileUploadError("Could not parse file to " + languageStr + ": " + ex.getMessage(), req, response); @@ -129,7 +144,12 @@ public class RDFUploadController extends BaseEditController { if( fileStreams.get("rdfStream") != null && fileStreams.get("rdfStream").size() > 0 ){ FileItem rdfStream = fileStreams.get("rdfStream").get(0); try { - tempModel.read( rdfStream.getInputStream(), null, languageStr); + uploadModel.enterCriticalSection(Lock.WRITE); + try { + uploadModel.read( rdfStream.getInputStream(), null, languageStr); + } finally { + uploadModel.leaveCriticalSection(); + } uploadDesc = verb + " RDF from file " + rdfStream.getName(); } catch (IOException e) { forwardToFileUploadError("Could not read file: " + e.getLocalizedMessage(), req, response); @@ -145,43 +165,31 @@ public class RDFUploadController extends BaseEditController { } } } + /* ********** Do the model changes *********** */ - long tboxstmtCount = 0L; - long aboxstmtCount = 0L; - if( tempModel != null ){ + if( !directRead && uploadModel != null ){ + long tboxstmtCount = 0L; + long aboxstmtCount = 0L; + JenaModelUtils xutil = new JenaModelUtils(); - OntModel tboxModel=null; - OntModel aboxModel=null; + OntModel tboxModel = getTBoxModel( + request.getSession(), getServletContext()); + OntModel aboxModel = getABoxModel( + request.getSession(), getServletContext()); OntModel tboxChangeModel=null; Model aboxChangeModel=null; - - try { - tboxModel = ((OntModelSelector) request.getSession() - .getAttribute("baseOntModelSelector")).getTBoxModel(); - aboxModel = ((OntModelSelector) request.getSession() - .getAttribute("baseOntModelSelector")).getABoxModel(); - - } catch (Exception e) {} - if (tboxModel==null) { - tboxModel = ((OntModelSelector) getServletContext() - .getAttribute("baseOntModelSelector")).getTBoxModel(); - } - if (aboxModel==null) { - aboxModel = ((OntModelSelector) getServletContext() - .getAttribute("baseOntModelSelector")).getABoxModel(); - } if (tboxModel != null) { - tboxChangeModel = xutil.extractTBox(tempModel); + tboxChangeModel = xutil.extractTBox(uploadModel); tboxstmtCount = operateOnModel(request.getFullWebappDaoFactory(), tboxModel,tboxChangeModel,remove,makeClassgroups,portalArray,loginBean.getUserURI()); } if (aboxModel != null) { - aboxChangeModel = tempModel.remove(tboxChangeModel); + aboxChangeModel = uploadModel.remove(tboxChangeModel); aboxstmtCount = operateOnModel(request.getFullWebappDaoFactory(), aboxModel,aboxChangeModel,remove,makeClassgroups,portalArray,loginBean.getUserURI()); } - + request.setAttribute("uploadDesc", uploadDesc + ". " + verb + " " + (tboxstmtCount + aboxstmtCount) + " statements."); + } else { + request.setAttribute("uploadDesc", "RDF upload successful."); } - - request.setAttribute("uploadDesc", uploadDesc + ". " + verb + " " + (tboxstmtCount + aboxstmtCount) + " statements."); RequestDispatcher rd = request.getRequestDispatcher(Controllers.BASIC_JSP); request.setAttribute("bodyJsp","/templates/edit/specific/upload_rdf_result.jsp"); @@ -306,7 +314,33 @@ public class RDFUploadController extends BaseEditController { ModelMaker myVjmm = (ModelMaker) request.getSession().getAttribute("vitroJenaModelMaker"); myVjmm = (myVjmm == null) ? (ModelMaker) getServletContext().getAttribute("vitroJenaModelMaker") : myVjmm; return new VitroJenaSpecialModelMaker(myVjmm, request); - } + } + + private OntModel getABoxModel(HttpSession session, ServletContext ctx) { + if (session != null + && session.getAttribute("baseOntModelSelector") + instanceof OntModelSelector) { + return ((OntModelSelector) + session.getAttribute("baseOntModelSelector")) + .getABoxModel(); + } else { + return ((OntModelSelector) + ctx.getAttribute("baseOntModelSelector")).getABoxModel(); + } + } + + private OntModel getTBoxModel(HttpSession session, ServletContext ctx) { + if (session != null + && session.getAttribute("baseOntModelSelector") + instanceof OntModelSelector) { + return ((OntModelSelector) + session.getAttribute("baseOntModelSelector")) + .getTBoxModel(); + } else { + return ((OntModelSelector) + ctx.getAttribute("baseOntModelSelector")).getTBoxModel(); + } + } private static final Log log = LogFactory.getLog(RDFUploadController.class.getName()); } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoSDB.java index a8f208f50..f4ccc761c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoSDB.java @@ -35,11 +35,11 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena implements DataPropertyStatementDao { - private Dataset dataset; + private DatasetWrapperFactory dwf; - public DataPropertyStatementDaoSDB(Dataset dataset, WebappDaoFactoryJena wadf) { + public DataPropertyStatementDaoSDB(DatasetWrapperFactory datasetWrapperFactory, WebappDaoFactoryJena wadf) { super (wadf); - this.dataset = dataset; + this.dwf = datasetWrapperFactory; } @Override @@ -58,7 +58,16 @@ public class DataPropertyStatementDaoSDB extends DataPropertyStatementDaoJena " <" + entity.getURI() + "> ?p ?o . \n" + " FILTER(isLiteral(?o)) \n" + "} }" ; - Model results = QueryExecutionFactory.create(QueryFactory.create(query), dataset).execConstruct(); + Model results = null; + DatasetWrapper w = dwf.getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); + try { + results = QueryExecutionFactory.create(QueryFactory.create(query), dataset).execConstruct(); + } finally { + dataset.getLock().leaveCriticalSection(); + w.close(); + } OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, results); ontModel.enterCriticalSection(Lock.READ); try { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DatasetWrapper.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DatasetWrapper.java new file mode 100644 index 000000000..3f562ee78 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DatasetWrapper.java @@ -0,0 +1,34 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.dao.jena; + +import com.hp.hpl.jena.query.Dataset; +import com.hp.hpl.jena.sdb.sql.SDBConnection; + +public class DatasetWrapper { + + private SDBConnection conn; + private Dataset dataset; + private boolean closed = false; + + public DatasetWrapper(Dataset dataset) { + this.dataset = dataset; + } + + public Dataset getDataset() { + if (!closed) { + return dataset; + } else throw new RuntimeException("No operations on a closed dataset"); + } + + public void close() { + if (!closed) { + closed = true; + if (conn != null) { + dataset.close(); + conn.close(); + } + } + } + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DatasetWrapperFactory.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DatasetWrapperFactory.java new file mode 100644 index 000000000..344abdaa1 --- /dev/null +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/DatasetWrapperFactory.java @@ -0,0 +1,9 @@ +/* $This file is distributed under the terms of the license in /doc/license.txt$ */ + +package edu.cornell.mannlib.vitro.webapp.dao.jena; + +public interface DatasetWrapperFactory { + + public DatasetWrapper getDatasetWrapper(); + +} diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java index 6faaf3761..8b976ef09 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualDaoSDB.java @@ -41,26 +41,27 @@ import com.hp.hpl.jena.vocabulary.RDF; import com.hp.hpl.jena.vocabulary.RDFS; import edu.cornell.mannlib.vitro.webapp.beans.Individual; +import edu.cornell.mannlib.vitro.webapp.beans.IndividualImpl; import edu.cornell.mannlib.vitro.webapp.beans.ObjectPropertyStatement; import edu.cornell.mannlib.vitro.webapp.beans.VClass; import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; public class IndividualDaoSDB extends IndividualDaoJena { - private Dataset dataset; + private DatasetWrapperFactory dwf; private WebappDaoFactoryJena wadf; - public IndividualDaoSDB(Dataset dataset, WebappDaoFactoryJena wadf) { + public IndividualDaoSDB(DatasetWrapperFactory dwf, WebappDaoFactoryJena wadf) { super(wadf); - this.dataset = dataset; + this.dwf = dwf; } - protected Dataset getDataset() { - return this.dataset; + protected DatasetWrapper getDatasetWrapper() { + return dwf.getDatasetWrapper(); } protected Individual makeIndividual(String individualURI) { - return new IndividualSDB2(individualURI, getDataset(), getWebappDaoFactory()); + return new IndividualSDB(individualURI, this.dwf, getWebappDaoFactory()); } private static final Log log = LogFactory.getLog(IndividualDaoSDB.class.getName()); @@ -90,36 +91,49 @@ public class IndividualDaoSDB extends IndividualDaoJena { ents.addAll(getIndividualsByVClass(vc)); } } else { - Model model; - dataset.getLock().enterCriticalSection(Lock.READ); + Model model = null; try { - String query = - "CONSTRUCT " + - "{ ?ind <" + RDFS.label.getURI() + "> ?ooo. \n" + - "?ind a <" + theClass.getURI() + "> . \n" + - "?ind <" + VitroVocabulary.MONIKER + "> ?moniker \n" + - "} WHERE " + - "{ GRAPH ?g { \n" + - " ?ind a <" + theClass.getURI() + "> \n" + - "} \n" + - "OPTIONAL { GRAPH ?h { ?ind <" + RDFS.label.getURI() + "> ?ooo } }\n" + - "OPTIONAL { GRAPH ?i { ?ind <" + VitroVocabulary.MONIKER + "> ?moniker } } \n" + - "}"; - model = QueryExecutionFactory.create(QueryFactory.create(query), dataset).execConstruct(); - } finally { - dataset.getLock().leaveCriticalSection(); - } - ResIterator resIt = model.listSubjects(); - try { - while (resIt.hasNext()) { - Resource ind = resIt.nextResource(); - if (!ind.isAnon()) { - ents.add(new IndividualSDB(ind.getURI(), dataset, getWebappDaoFactory(), model)); + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); + try { + String query = + "CONSTRUCT " + + "{ ?ind <" + RDFS.label.getURI() + "> ?ooo. \n" + + "?ind a <" + theClass.getURI() + "> . \n" + + "?ind <" + VitroVocabulary.MONIKER + "> ?moniker \n" + + "} WHERE " + + "{ GRAPH ?g { \n" + + " ?ind a <" + theClass.getURI() + "> \n" + + "} \n" + + "OPTIONAL { GRAPH ?h { ?ind <" + RDFS.label.getURI() + "> ?ooo } }\n" + + "OPTIONAL { GRAPH ?i { ?ind <" + VitroVocabulary.MONIKER + "> ?moniker } } \n" + + "}"; + model = QueryExecutionFactory.create(QueryFactory.create(query), dataset).execConstruct(); + } finally { + dataset.getLock().leaveCriticalSection(); + w.close(); + } + ResIterator resIt = model.listSubjects(); + try { + while (resIt.hasNext()) { + Resource ind = resIt.nextResource(); + if (!ind.isAnon()) { + //Individual indd = new IndividualImpl(ind.getURI()); + //indd.setLocalName(ind.getLocalName()); + //indd.setName(ind.getLocalName()); + //ents.add(indd); + ents.add(new IndividualSDB(ind.getURI(), dataset, getWebappDaoFactory(), model)); + } } + } finally { + resIt.close(); } - } finally { - resIt.close(); - } + } finally { + if (model != null && !model.isClosed()) { + model.close(); + } + } } @@ -285,6 +299,9 @@ public class IndividualDaoSDB extends IndividualDaoJena { Query q = QueryFactory.create(query); + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); QueryExecution qe = QueryExecutionFactory.create(q, dataset); try { ResultSet rs = qe.execSelect(); @@ -295,7 +312,9 @@ public class IndividualDaoSDB extends IndividualDaoJena { } } } finally { - qe.close(); + qe.close(); + dataset.getLock().leaveCriticalSection(); + w.close(); } // getOntModel().enterCriticalSection(Lock.READ); diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java index 458af04ef..0ab755de6 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/IndividualSDB.java @@ -69,13 +69,13 @@ public class IndividualSDB extends IndividualImpl implements Individual { private WebappDaoFactoryJena webappDaoFactory = null; private Float _searchBoostJena = null; private boolean retreivedNullRdfsLabel = false; - private Dataset dataset = null; + private DatasetWrapperFactory dwf = null; private String individualURI = null; private Model model = null; - public IndividualSDB(String individualURI, Dataset dataset, WebappDaoFactoryJena wadf, Model initModel) { + public IndividualSDB(String individualURI, DatasetWrapperFactory datasetWrapperFactory, WebappDaoFactoryJena wadf, Model initModel) { this.individualURI = individualURI; - this.dataset = dataset; + this.dwf = datasetWrapperFactory; try { initModel.getLock().enterCriticalSection(Lock.READ); @@ -113,12 +113,14 @@ public class IndividualSDB extends IndividualImpl implements Individual { this.webappDaoFactory = wadf; } - public IndividualSDB(String individualURI, Dataset dataset, WebappDaoFactoryJena wadf) { + public IndividualSDB(String individualURI, DatasetWrapperFactory datasetWrapperFactory, WebappDaoFactoryJena wadf) { this.individualURI = individualURI; - this.dataset = dataset; + this.dwf = datasetWrapperFactory; + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); try { - this.dataset.getLock().enterCriticalSection(Lock.READ); + dataset.getLock().enterCriticalSection(Lock.READ); String getStatements = "CONSTRUCT " + "{ <"+individualURI+"> <" + RDFS.label.getURI() + "> ?ooo. \n" + @@ -133,7 +135,8 @@ public class IndividualSDB extends IndividualImpl implements Individual { "}"; model = QueryExecutionFactory.create(QueryFactory.create(getStatements), dataset).execConstruct(); } finally { - this.dataset.getLock().leaveCriticalSection(); + dataset.getLock().leaveCriticalSection(); + w.close(); } OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, model); @@ -155,6 +158,10 @@ public class IndividualSDB extends IndividualImpl implements Individual { this.webappDaoFactory = wadf; } + private DatasetWrapper getDatasetWrapper() { + return this.dwf.getDatasetWrapper(); + } + public String getName() { if (this.name != null) { return name; @@ -249,10 +256,11 @@ public class IndividualSDB extends IndividualImpl implements Individual { "http://vitro.mannlib.cornell.edu/ns/vitro/0.7#Flag1Value1Thing" */ public boolean doesFlag1Match(int flagBitMask) { - Long [] numerics = FlagMathUtils.numeric2numerics(flagBitMask); - this.dataset.getLock().enterCriticalSection(Lock.READ); - String Ask = null; - + Long [] numerics = FlagMathUtils.numeric2numerics(flagBitMask); + String Ask = null; + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); try{ for( Long numericPortal : numerics){ int portalid = FlagMathUtils.numeric2Portalid(numericPortal); @@ -262,19 +270,19 @@ public class IndividualSDB extends IndividualImpl implements Individual { return false; } }finally{ - - this.dataset.getLock().leaveCriticalSection(); + dataset.getLock().leaveCriticalSection(); + w.close(); } return true; } private void doFlag1() { - String getObjects = null; - - dataset.getLock().enterCriticalSection(Lock.READ); Model tempModel = ModelFactory.createDefaultModel(); OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); try { ClosableIterator typeIt = null; int portalNumeric = 0; @@ -310,16 +318,19 @@ public class IndividualSDB extends IndividualImpl implements Individual { } finally { tempModel.close(); ontModel.close(); - this.dataset.getLock().leaveCriticalSection(); + dataset.getLock().leaveCriticalSection(); + w.close(); } } private void doFlag2() { String getObjects = null; - dataset.getLock().enterCriticalSection(Lock.READ); - Model tempModel = ModelFactory.createDefaultModel(); + Model tempModel = ModelFactory.createDefaultModel(); OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); try { ClosableIterator typeIt=null; String flagSet = ""; @@ -352,7 +363,8 @@ public class IndividualSDB extends IndividualImpl implements Individual { } finally { tempModel.close(); ontModel.close(); - this.dataset.getLock().leaveCriticalSection(); + dataset.getLock().leaveCriticalSection(); + w.close(); } } @@ -566,7 +578,8 @@ public class IndividualSDB extends IndividualImpl implements Individual { String getPropertyValue = "SELECT ?value" + "WHERE { GRAPH ?g { <" + individualURI + ">" + webappDaoFactory.getJenaBaseDao().SEARCH_BOOST_ANNOT + "?value} }"; - + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); try{ try { @@ -577,8 +590,8 @@ public class IndividualSDB extends IndividualImpl implements Individual { } return searchBoost; }finally{ - dataset.getLock().leaveCriticalSection(); + w.close(); } } } @@ -646,10 +659,11 @@ public class IndividualSDB extends IndividualImpl implements Individual { } private void doUrlAndAnchor() { - - this.dataset.getLock().enterCriticalSection(Lock.READ); - Model tempModel = ModelFactory.createDefaultModel(); - OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + Model tempModel = ModelFactory.createDefaultModel(); + OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); try { if (webappDaoFactory.getJenaBaseDao().PRIMARY_LINK != null) { String listPropertyValues = @@ -685,7 +699,8 @@ public class IndividualSDB extends IndividualImpl implements Individual { } finally { tempModel.close(); ontModel.close(); - this.dataset.getLock().leaveCriticalSection(); + dataset.getLock().leaveCriticalSection(); + w.close(); } } @@ -766,12 +781,13 @@ public class IndividualSDB extends IndividualImpl implements Individual { return null; } List objectPropertyStatements = new ArrayList(); - + + Model tempModel = ModelFactory.createDefaultModel(); + OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); - Model tempModel = ModelFactory.createDefaultModel(); - OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM); try { - String valuesOfProperty = "CONSTRUCT{<" + this.individualURI + "> <" + propertyURI + "> ?object}" + "WHERE{ GRAPH ?g { <" + this.individualURI + "> <" + propertyURI + "> ?object} }"; @@ -784,8 +800,8 @@ public class IndividualSDB extends IndividualImpl implements Individual { if (!s.getSubject().canAs(OntResource.class) || !s.getObject().canAs(OntResource.class)) { continue; } - Individual subj = new IndividualSDB(((OntResource) s.getSubject().as(OntResource.class)).getURI(), dataset, webappDaoFactory); - Individual obj = new IndividualSDB(((OntResource) s.getObject().as(OntResource.class)).getURI(), dataset, webappDaoFactory); + Individual subj = new IndividualSDB(((OntResource) s.getSubject().as(OntResource.class)).getURI(), this.dwf, webappDaoFactory); + Individual obj = new IndividualSDB(((OntResource) s.getObject().as(OntResource.class)).getURI(), this.dwf, webappDaoFactory); ObjectProperty op = webappDaoFactory.getObjectPropertyDao().getObjectPropertyByURI(s.getPredicate().getURI()); if (subj != null && obj != null && op != null) { ObjectPropertyStatement ops = new ObjectPropertyStatementImpl(); @@ -802,6 +818,7 @@ public class IndividualSDB extends IndividualImpl implements Individual { tempModel.close(); ontModel.close(); dataset.getLock().leaveCriticalSection(); + w.close(); } return objectPropertyStatements; } @@ -813,6 +830,8 @@ public class IndividualSDB extends IndividualImpl implements Individual { } List relatedIndividuals = new ArrayList(); + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); try { String valuesOfProperty = @@ -825,11 +844,12 @@ public class IndividualSDB extends IndividualImpl implements Individual { RDFNode value = result.get("object"); if (value.canAs(OntResource.class)) { relatedIndividuals.add( - new IndividualSDB(((OntResource) value.as(OntResource.class)).getURI(), dataset, webappDaoFactory) ); + new IndividualSDB(((OntResource) value.as(OntResource.class)).getURI(), this.dwf, webappDaoFactory) ); } } } finally { dataset.getLock().leaveCriticalSection(); + w.close(); } return relatedIndividuals; } @@ -839,7 +859,8 @@ public class IndividualSDB extends IndividualImpl implements Individual { if (propertyURI == null) { return null; } - + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); dataset.getLock().enterCriticalSection(Lock.READ); try { String valueOfProperty = @@ -849,12 +870,13 @@ public class IndividualSDB extends IndividualImpl implements Individual { QuerySolution result = results.next(); RDFNode value = result.get("object"); if (value != null && value.canAs(OntResource.class)) { - return new IndividualSDB(((OntResource) value.as(OntResource.class)).getURI(), dataset, webappDaoFactory); + return new IndividualSDB(((OntResource) value.as(OntResource.class)).getURI(), dwf, webappDaoFactory); } else { return null; } } finally { dataset.getLock().leaveCriticalSection(); + w.close(); } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java index 5dbfab75e..cfaa11f6b 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/ObjectPropertyStatementDaoSDB.java @@ -31,11 +31,13 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; public class ObjectPropertyStatementDaoSDB extends ObjectPropertyStatementDaoJena implements ObjectPropertyStatementDao { - private Dataset dataset; + private DatasetWrapperFactory dwf; - public ObjectPropertyStatementDaoSDB(Dataset dataset, WebappDaoFactoryJena wadf) { + public ObjectPropertyStatementDaoSDB( + DatasetWrapperFactory datasetWrapperFactory, + WebappDaoFactoryJena wadf) { super (wadf); - this.dataset = dataset; + this.dwf = datasetWrapperFactory; } @Override @@ -56,12 +58,15 @@ public class ObjectPropertyStatementDaoSDB extends " OPTIONAL { ?o <" + VitroVocabulary.MONIKER + "> ?oMoniker } \n" + "} }"; long startTime = System.currentTimeMillis(); - dataset.getLock().enterCriticalSection(Lock.READ); Model m = null; + DatasetWrapper w = dwf.getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); try { m = QueryExecutionFactory.create(QueryFactory.create(query), dataset).execConstruct(); } finally { dataset.getLock().leaveCriticalSection(); + w.close(); } if (log.isDebugEnabled()) { log.debug("Time (ms) to query for related individuals: " + (System.currentTimeMillis() - startTime)); @@ -112,12 +117,18 @@ public class ObjectPropertyStatementDaoSDB extends continue; } if (objPropertyStmt.getObjectURI() != null) { - Individual objInd = new IndividualSDB(objPropertyStmt.getObjectURI(), dataset, getWebappDaoFactory(), m); + Individual objInd = new IndividualSDB( + objPropertyStmt.getObjectURI(), + this.dwf, + getWebappDaoFactory(), + m); objPropertyStmt.setObject(objInd); } //add object property statement to list for Individual - if ((objPropertyStmt.getSubjectURI() != null) && (objPropertyStmt.getPropertyURI() != null) && (objPropertyStmt.getObject() != null)){ + if ((objPropertyStmt.getSubjectURI() != null) + && (objPropertyStmt.getPropertyURI() != null) + && (objPropertyStmt.getObject() != null)){ objPropertyStmtList.add(objPropertyStmt); } } catch (Throwable t) { diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java index 14227aced..22abb8910 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/dao/jena/VClassDaoSDB.java @@ -26,16 +26,16 @@ import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; public class VClassDaoSDB extends VClassDaoJena { - private Dataset dataset; - private WebappDaoFactoryJena wadf; + private DatasetWrapperFactory dwf; - public VClassDaoSDB(Dataset dataset, WebappDaoFactoryJena wadf) { + public VClassDaoSDB(DatasetWrapperFactory datasetWrapperFactory, + WebappDaoFactoryJena wadf) { super(wadf); - this.dataset = dataset; + this.dwf = datasetWrapperFactory; } - protected Dataset getDataset() { - return this.dataset; + protected DatasetWrapper getDatasetWrapper() { + return dwf.getDatasetWrapper(); } @Deprecated @@ -63,9 +63,17 @@ public class VClassDaoSDB extends VClassDaoJena { String countQueryStr = "SELECT COUNT(*) WHERE \n" + "{ GRAPH ?g { ?s a <" + cls.getURI() + "> } } \n"; Query countQuery = QueryFactory.create(countQueryStr, Syntax.syntaxARQ); - QueryExecution qe = QueryExecutionFactory.create(countQuery, getDataset()); - ResultSet rs =qe.execSelect(); - count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm()); + DatasetWrapper w = getDatasetWrapper(); + Dataset dataset = w.getDataset(); + dataset.getLock().enterCriticalSection(Lock.READ); + try { + QueryExecution qe = QueryExecutionFactory.create(countQuery, dataset); + ResultSet rs = qe.execSelect(); + count = Integer.parseInt(((Literal) rs.nextSolution().get(".1")).getLexicalForm()); + } finally { + dataset.getLock().leaveCriticalSection(); + w.close(); + } } finally { aboxModel.leaveCriticalSection(); } 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 2bc0ac092..e450cfa13 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 @@ -13,16 +13,28 @@ import edu.cornell.mannlib.vitro.webapp.dao.VClassDao; public class WebappDaoFactorySDB extends WebappDaoFactoryJena { - private Dataset dataset; + private DatasetWrapperFactory dwf; + /** + * For use when any database connection associated with the Dataset + * is managed externally + * @param ontModelSelector + * @param dataset + */ public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset) { super(ontModelSelector); - this.dataset = dataset; + this.dwf = new StaticDatasetFactory(dataset); } + /** + * For use when any database connection associated with the Dataset + * is managed externally + * @param ontModelSelector + * @param dataset + */ public WebappDaoFactorySDB(OntModelSelector ontModelSelector, Dataset dataset, String defaultNamespace, HashSet nonuserNamespaces, String[] preferredLanguages) { super(ontModelSelector, defaultNamespace, nonuserNamespaces, preferredLanguages); - this.dataset = dataset; + this.dwf = new StaticDatasetFactory(dataset); } @Override @@ -30,7 +42,7 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { if (entityWebappDao != null) return entityWebappDao; else - return entityWebappDao = new IndividualDaoSDB(dataset, this); + return entityWebappDao = new IndividualDaoSDB(dwf, this); } @Override @@ -38,7 +50,7 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { if (dataPropertyStatementDao != null) return dataPropertyStatementDao; else - return dataPropertyStatementDao = new DataPropertyStatementDaoSDB(dataset, this); + return dataPropertyStatementDao = new DataPropertyStatementDaoSDB(dwf, this); } @Override @@ -46,7 +58,7 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { if (objectPropertyStatementDao != null) return objectPropertyStatementDao; else - return objectPropertyStatementDao = new ObjectPropertyStatementDaoSDB(dataset, this); + return objectPropertyStatementDao = new ObjectPropertyStatementDaoSDB(dwf, this); } @Override @@ -54,7 +66,21 @@ public class WebappDaoFactorySDB extends WebappDaoFactoryJena { if (vClassDao != null) return vClassDao; else - return vClassDao = new VClassDaoSDB(dataset, this); + return vClassDao = new VClassDaoSDB(dwf, this); + } + + private class StaticDatasetFactory implements DatasetWrapperFactory { + + private Dataset dataset; + + public StaticDatasetFactory (Dataset dataset) { + this.dataset = dataset; + } + + public DatasetWrapper getDatasetWrapper() { + return new DatasetWrapper(dataset); + } + } } diff --git a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/MultipartHttpServletRequest.java b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/MultipartHttpServletRequest.java index 305fd6a43..2df1daa0c 100644 --- a/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/MultipartHttpServletRequest.java +++ b/webapp/src/edu/cornell/mannlib/vitro/webapp/filestorage/uploadrequest/MultipartHttpServletRequest.java @@ -137,7 +137,7 @@ class MultipartHttpServletRequest extends FileUploadServletRequest { */ private ServletFileUpload createUploadHandler(int maxFileSize, File tempDir) { DiskFileItemFactory factory = new DiskFileItemFactory(); - factory.setSizeThreshold(maxFileSize); + factory.setSizeThreshold(DiskFileItemFactory.DEFAULT_SIZE_THRESHOLD); factory.setRepository(tempDir); ServletFileUpload upload = new ServletFileUpload(factory); diff --git a/webapp/web/templates/edit/specific/upload_rdf.jsp b/webapp/web/templates/edit/specific/upload_rdf.jsp index 60be0e433..683154c08 100644 --- a/webapp/web/templates/edit/specific/upload_rdf.jsp +++ b/webapp/web/templates/edit/specific/upload_rdf.jsp @@ -13,13 +13,18 @@

${errMsg}

-

Enter Web-accessible URL of RDF document:

+

Enter Web-accessible URL of document containing RDF to add or remove:

Or upload a file from your computer:

-

add RDF remove RDF

+
    +
  • add instance data (supports large data files)
  • +
  • add mixed RDF (instances and/or ontology)
  • +
  • remove mixed RDF (instances and/or ontology)
  • +
+