-
Notifications
You must be signed in to change notification settings - Fork 85
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
VIVO 3828: Remove SDB in preparation to moving to new Jena.
The Jena version being switched to (Jena 4) has removed support for SDB. The current forms of `DatasetWrapperFactory` and `StaticDatasetFactory` should no longer be needed. The SDB related code has been stripped out. Many of the classes with "SDB" in the name that actually provide more than just SDB have been re-created. These recreations are generally child classes of a similarly named Jena class. These recreates have "DB" in their name rather than "SDB". The `DatasetFactory.createMem()` is deprecated and may not be available in Jena 4. Attempts to replace this with `createTxnMem()` have revealed problems that are potentially transaction related. Replacing with `createGeneral()` might be possible but this is not done to avoid introducing more potential problems. Notable points in regards to replacing `DatasetFactory.createMem()`: 1) The method is deprecated. 2) The `DatasetFactory.createGeneral()` is the compatible equivalent. 3) The `DatasetFactory.createGeneral()` better supports TDB (which is the main reason for including in this commit set). 4) The `DatasetFactory.createTxnMem()` is the more recommended alternative and is transactional. 5) This better prepares the code for the upcoming Jena upgrade changes. There are some serious existing problems with closing dataset connections (and related). The (now removed) `DatasetWrapperFactory` probably should be rewritten to provide a new dataset each time rather than copying an existing one. The `close()` functionality appears to not be being called for TDB due to the SDB conditions. With this SDB condition the connections are now being closed. This has exposed several problems that both tests and runtime expose. This problem is considered out of scope for the changes and the close code is commented out with a FIXME statement. The documentation for `example.runtime.properties` refers to `VitroConnection.DataSource.*` only being used by SDB but this is incorrect. The OpenSocial code appears to talk directly to an SQL database using these properties. Update the documentation in this regard and replace the references to SDB with OpenSocial. Remove no longer necessary SDB helper code that is added to TDB as well because it "shouldn't hurt". Remove much of the documentation and installation functionality using or referencing SDB. The `IndividualDaoSDB.java` file is implemting `getAllIndividualUris()` and `getUpdatedSinceIterator()` via the now removed `IndivdiualSDB` class. This functionality is used by `RebuildIndexTask` and `UpdateUrisTask` classes. The new *DB classes now have java docs. These java docs have a bare-bones level of detail.
- Loading branch information
Showing
55 changed files
with
2,765 additions
and
4,110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoDB.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
/* $This file is distributed under the terms of the license in LICENSE$ */ | ||
|
||
package edu.cornell.mannlib.vitro.webapp.dao.jena; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import org.apache.jena.ontology.OntModel; | ||
import org.apache.jena.ontology.OntModelSpec; | ||
import org.apache.jena.query.Dataset; | ||
import org.apache.jena.query.QueryExecution; | ||
import org.apache.jena.query.QueryExecutionFactory; | ||
import org.apache.jena.query.QueryFactory; | ||
import org.apache.jena.rdf.model.Literal; | ||
import org.apache.jena.rdf.model.Model; | ||
import org.apache.jena.rdf.model.ModelFactory; | ||
import org.apache.jena.rdf.model.Resource; | ||
import org.apache.jena.rdf.model.Statement; | ||
import org.apache.jena.rdf.model.StmtIterator; | ||
import org.apache.jena.shared.Lock; | ||
import org.apache.jena.vocabulary.RDF; | ||
|
||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatement; | ||
import edu.cornell.mannlib.vitro.webapp.beans.DataPropertyStatementImpl; | ||
import edu.cornell.mannlib.vitro.webapp.beans.Individual; | ||
import edu.cornell.mannlib.vitro.webapp.dao.DataPropertyStatementDao; | ||
import edu.cornell.mannlib.vitro.webapp.dao.VitroVocabulary; | ||
|
||
/** | ||
* An extension of {@link DataPropertyStatementDaoJena} for databases, such as TDB. | ||
*/ | ||
public class DataPropertyStatementDaoDB extends DataPropertyStatementDaoJena implements DataPropertyStatementDao { | ||
|
||
/** | ||
* Initialize the data property statement DAO. | ||
* | ||
* @param dw The data wrapper. | ||
* @param wadf The web application DAO factory. | ||
*/ | ||
public DataPropertyStatementDaoDB(DatasetWrapper dw, WebappDaoFactoryDB wadf) { | ||
super (dw, wadf); | ||
} | ||
|
||
/** | ||
* Fill existing data property statements for an individual. | ||
* | ||
* @param entity The individual. | ||
* | ||
* @return A filled out individual. | ||
*/ | ||
public Individual fillExistingDataPropertyStatementsForIndividual(Individual entity) { | ||
if (entity.getURI() == null) { | ||
return entity; | ||
} | ||
|
||
String query = | ||
"CONSTRUCT { \n" + | ||
" <" + entity.getURI() + "> ?p ?o . \n" + | ||
"} WHERE { \n" + | ||
" <" + entity.getURI() + "> ?p ?o . \n" + | ||
" FILTER(isLiteral(?o)) \n" + | ||
"}" ; | ||
Model results = null; | ||
Dataset dataset = getDataWrapper().getDataset(); | ||
QueryExecution qexec = null; | ||
|
||
dataset.getLock().enterCriticalSection(Lock.READ); | ||
try { | ||
qexec = QueryExecutionFactory.create(QueryFactory.create(query), dataset); | ||
results = qexec.execConstruct(); | ||
} finally { | ||
if (qexec != null) qexec.close(); | ||
dataset.getLock().leaveCriticalSection(); | ||
getDataWrapper().close(); | ||
} | ||
|
||
OntModel ontModel = ModelFactory.createOntologyModel(OntModelSpec.OWL_MEM, results); | ||
ontModel.enterCriticalSection(Lock.READ); | ||
try { | ||
Resource ind = ontModel.getResource(entity.getURI()); | ||
List<DataPropertyStatement> edList = new ArrayList<>(); | ||
StmtIterator stmtIt = ind.listProperties(); | ||
|
||
while (stmtIt.hasNext()) { | ||
Statement st = stmtIt.next(); | ||
boolean addToList = st.getObject().isLiteral() && | ||
( | ||
( | ||
RDF.value.equals(st.getPredicate()) | ||
|| VitroVocabulary.value.equals(st.getPredicate().getURI())) | ||
|| MONIKER.equals(st.getPredicate()) | ||
|| !(NONUSER_NAMESPACES.contains(st.getPredicate().getNameSpace()) | ||
) | ||
); | ||
|
||
if (addToList) { | ||
DataPropertyStatement ed = new DataPropertyStatementImpl(); | ||
Literal lit = (Literal)st.getObject(); | ||
fillDataPropertyStatementWithJenaLiteral(ed,lit); | ||
ed.setDatapropURI(st.getPredicate().getURI()); | ||
ed.setIndividualURI(ind.getURI()); | ||
ed.setIndividual(entity); | ||
edList.add(ed); | ||
} | ||
} | ||
|
||
entity.setDataPropertyStatements(edList); | ||
return entity; | ||
} finally { | ||
ontModel.leaveCriticalSection(); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 0 additions & 118 deletions
118
api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/DataPropertyStatementDaoSDB.java
This file was deleted.
Oops, something went wrong.
22 changes: 22 additions & 0 deletions
22
api/src/main/java/edu/cornell/mannlib/vitro/webapp/dao/jena/DatasetMode.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package edu.cornell.mannlib.vitro.webapp.dao.jena; | ||
|
||
/** | ||
* Modes for optimizing database queries. | ||
*/ | ||
public enum DatasetMode { | ||
|
||
/** | ||
* Only perform assertions. | ||
*/ | ||
ASSERTIONS_ONLY, | ||
|
||
/** | ||
* Only perform inferences. | ||
*/ | ||
INFERENCES_ONLY, | ||
|
||
/** | ||
* Perform both assertions and inferences. | ||
*/ | ||
ASSERTIONS_AND_INFERENCES, | ||
} |
Oops, something went wrong.