Merge branch 'develop' of https://github.com/vivo-project/Vitro into develop

This commit is contained in:
hudajkhan 2015-03-30 16:24:29 -04:00
commit 0e54b7bb43
6 changed files with 50 additions and 44 deletions

View file

@ -16,9 +16,7 @@ import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.shared.JenaException;
import com.hp.hpl.jena.shared.Lock;
import com.hp.hpl.jena.tdb.TDB;
import com.hp.hpl.jena.query.ReadWrite;
import com.hp.hpl.jena.tdb.TDBFactory;
import edu.cornell.mannlib.vitro.webapp.dao.jena.DatasetWrapper;
@ -65,6 +63,7 @@ public class RDFServiceTDB extends RDFServiceJena {
return false;
}
dataset.begin(ReadWrite.WRITE);
try {
insureThatInputStreamsAreResettable(changeSet);
@ -75,23 +74,20 @@ public class RDFServiceTDB extends RDFServiceJena {
applyChangeSetToModel(changeSet, dataset);
dataset.getLock().enterCriticalSection(Lock.WRITE);
try {
TDB.sync(dataset);
} finally {
dataset.getLock().leaveCriticalSection();
}
notifyListenersOfChanges(changeSet);
notifyListenersOfPostChangeEvents(changeSet);
dataset.commit();
return true;
} catch (Exception e) {
log.error(e, e);
throw new RDFServiceException(e);
} finally {
dataset.end();
}
}
@Override
public void close() {
if (this.dataset != null) {
@ -102,75 +98,75 @@ public class RDFServiceTDB extends RDFServiceJena {
@Override
public InputStream sparqlConstructQuery(String query,
ModelSerializationFormat resultFormat) throws RDFServiceException {
dataset.getLock().enterCriticalSection(Lock.READ);
dataset.begin(ReadWrite.READ);
try {
return super.sparqlConstructQuery(query, resultFormat);
} finally {
dataset.getLock().leaveCriticalSection();
dataset.end();
}
}
@Override
public InputStream sparqlDescribeQuery(String query,
ModelSerializationFormat resultFormat) throws RDFServiceException {
dataset.getLock().enterCriticalSection(Lock.READ);
dataset.begin(ReadWrite.READ);
try {
return super.sparqlDescribeQuery(query, resultFormat);
} finally {
dataset.getLock().leaveCriticalSection();
dataset.end();
}
}
@Override
public InputStream sparqlSelectQuery(String query, ResultFormat resultFormat)
throws RDFServiceException {
dataset.getLock().enterCriticalSection(Lock.READ);
dataset.begin(ReadWrite.READ);
try {
return super.sparqlSelectQuery(query, resultFormat);
} finally {
dataset.getLock().leaveCriticalSection();
dataset.end();
}
}
@Override
public boolean sparqlAskQuery(String query) throws RDFServiceException {
dataset.getLock().enterCriticalSection(Lock.READ);
dataset.begin(ReadWrite.READ);
try {
return super.sparqlAskQuery(query);
} finally {
dataset.getLock().leaveCriticalSection();
dataset.end();
}
}
@Override
public List<String> getGraphURIs() throws RDFServiceException {
dataset.getLock().enterCriticalSection(Lock.READ);
dataset.begin(ReadWrite.READ);
try {
return super.getGraphURIs();
} finally {
dataset.getLock().leaveCriticalSection();
dataset.end();
}
}
@Override
public void serializeAll(OutputStream outputStream)
throws RDFServiceException {
dataset.getLock().enterCriticalSection(Lock.READ);
dataset.begin(ReadWrite.READ);
try {
super.serializeAll(outputStream);
} finally {
dataset.getLock().leaveCriticalSection();
dataset.end();
}
}
@Override
public void serializeGraph(String graphURI, OutputStream outputStream)
throws RDFServiceException {
dataset.getLock().enterCriticalSection(Lock.READ);
dataset.begin(ReadWrite.READ);
try {
super.serializeGraph(graphURI, outputStream);
} finally {
dataset.getLock().leaveCriticalSection();
dataset.end();
}
}

View file

@ -53,24 +53,22 @@ public class ContentModelSetup extends JenaDataSourceSetupBase
Model applicationMetadataModel = models.getOntModel(APPLICATION_METADATA);
if (applicationMetadataModel.size()== 0) {
thisIsFirstStartup();
initializeApplicationMetadata(ctx, applicationMetadataModel);
} else {
checkForNamespaceMismatch( applicationMetadataModel, ctx );
}
OntModel baseABoxModel = models.getOntModel(ABOX_ASSERTIONS);
OntModel baseTBoxModel = models.getOntModel(TBOX_ASSERTIONS);
if (isFirstStartup()) {
initializeApplicationMetadata(ctx, applicationMetadataModel);
if (baseABoxModel.size() == 0) {
RDFFilesLoader.loadFirstTimeFiles("abox", baseABoxModel, true);
RDFFilesLoader.loadFirstTimeFiles("tbox", baseTBoxModel, true);
} else {
checkForNamespaceMismatch( applicationMetadataModel, ctx );
}
RDFFilesLoader.loadEveryTimeFiles("abox", baseABoxModel);
RDFFilesLoader.loadEveryTimeFiles("tbox", baseTBoxModel);
RDFFilesLoader.loadEveryTimeFiles("abox", baseABoxModel);
log.info("Setting up DAO factories");
OntModel baseTBoxModel = models.getOntModel(TBOX_ASSERTIONS);
if (baseTBoxModel.size() == 0) {
RDFFilesLoader.loadFirstTimeFiles("tbox", baseTBoxModel, true);
}
RDFFilesLoader.loadEveryTimeFiles("tbox", baseTBoxModel);
}
private long secondsSince(long startTime) {

View file

@ -67,9 +67,10 @@ public class RDFFilesLoader {
public static void loadFirstTimeFiles(String modelPath, Model model,
boolean firstTime) {
if (firstTime) {
Set<Path> paths = getPaths(locateHomeDirectory(), RDF, modelPath,
FIRST_TIME);
String home = locateHomeDirectory();
Set<Path> paths = getPaths(home, RDF, modelPath, FIRST_TIME);
for (Path p : paths) {
log.info("Loading " + relativePath(p, home));
readOntologyFileIntoModel(p, model);
}
} else {

View file

@ -72,14 +72,14 @@ public class BasicCombinedTripleSource implements CombinedTripleSource {
sources.put(CONFIGURATION, configurationSource);
ontModels = new EnumMap<>(WhichService.class);
ontModels.put(CONTENT, new ModelMakerOntModelCache(
getModelMaker(CONTENT)));
ontModels.put(CONTENT, new UnionModelsOntModelsCache(
new ModelMakerOntModelCache(getModelMaker(CONTENT)),
CONTENT_UNIONS));
ontModels.put(CONFIGURATION, new ModelMakerOntModelCache(
getModelMaker(CONFIGURATION)));
ontModelCache = new UnionModelsOntModelsCache(new JoinedOntModelCache(
ontModels.get(CONTENT), ontModels.get(CONFIGURATION)),
CONTENT_UNIONS);
ontModelCache = new JoinedOntModelCache(ontModels.get(CONTENT),
ontModels.get(CONFIGURATION));
}
protected OntModelCache getOntModels(WhichService whichService) {

View file

@ -4,7 +4,6 @@ package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.BasicCombinedTripleSource.CONTENT_UNIONS;
import java.lang.reflect.Method;
import java.sql.Driver;
import java.sql.DriverManager;
import java.sql.SQLException;
@ -194,6 +193,9 @@ public class ContentTripleSourceSDB extends ContentTripleSource {
* Use models from the short-term RDFService, since there is less contention
* for the database connections that way. The exceptions are the
* memory-mapped models. By keeping them, we also keep their sub-models.
*
* Set up the Union models again also, so they will reference the short-term
* models.
*/
@Override
public OntModelCache getShortTermOntModels(RDFService shortTermRdfService,

View file

@ -10,6 +10,7 @@ import com.hp.hpl.jena.tdb.TDB;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceDataset;
import edu.cornell.mannlib.vitro.webapp.dao.jena.RDFServiceModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.ListCachingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.MemoryMappingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
@ -21,6 +22,7 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.RDFServiceFactorySingle;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.tdb.RDFServiceTDB;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.logging.LoggingRDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.JenaDataSourceSetupBase;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Property;
import edu.cornell.mannlib.vitro.webapp.utils.configuration.Validation;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
@ -75,6 +77,7 @@ public class ContentTripleSourceTDB extends ContentTripleSource {
this.unclosableRdfService = this.rdfServiceFactory.getRDFService();
this.dataset = new RDFServiceDataset(this.unclosableRdfService);
this.modelMaker = createModelMaker();
checkForFirstTimeStartup();
ss.info("Initialized the RDF source for TDB");
} catch (IOException e) {
throw new RuntimeException(
@ -102,6 +105,12 @@ public class ContentTripleSourceTDB extends ContentTripleSource {
this.unclosableRdfService), SMALL_CONTENT_MODELS)));
}
private void checkForFirstTimeStartup() {
if (this.dataset.getNamedModel(ModelNames.TBOX_ASSERTIONS).size() == 0) {
JenaDataSourceSetupBase.thisIsFirstStartup();
}
}
@Override
public RDFServiceFactory getRDFServiceFactory() {
return this.rdfServiceFactory;