VIVO-1009 Rely less on JenaDataSourceSetupBase.isFirstStartup()

In general, we can read firsttime files iff a model is empty. This provides more flexibility than relying on isFirstStartup().
However, the KnowledgeBaseUpdater still relies on isFirstStartup(), so we need to be sure that we set it when appropriate.
This commit is contained in:
Jim Blake 2015-03-30 11:40:02 -04:00
parent 0362770961
commit 6981838348
3 changed files with 22 additions and 14 deletions

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

@ -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;