improvement to app metadata setup to avoid null model if empty

This commit is contained in:
bjl23 2011-01-25 19:22:06 +00:00
parent 4c1bbde7d9
commit d6f19324f8

View file

@ -101,6 +101,9 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
// SDB setup // SDB setup
// union default graph
SDB.getContext().set(SDB.unionDefaultGraph, true) ;
StoreDesc storeDesc = makeStoreDesc(); StoreDesc storeDesc = makeStoreDesc();
setApplicationStoreDesc(storeDesc, sce.getServletContext()); setApplicationStoreDesc(storeDesc, sce.getServletContext());
@ -182,26 +185,24 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
// Application metadata model is cached in memory. // Application metadata model is cached in memory.
try { try {
Model applicationMetadataModelDB = makeDBModel(bds, JENA_APPLICATION_METADATA_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB); Model applicationMetadataModelDB = makeDBModel(bds, JENA_APPLICATION_METADATA_MODEL, DB_ONT_MODEL_SPEC, TripleStoreType.SDB);
if (applicationMetadataModelDB == null || applicationMetadataModelDB.size() == 0) {
repairAppMetadataModel(store, aboxAssertions, aboxInferences);
}
OntModel applicationMetadataModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); OntModel applicationMetadataModel = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
if (applicationMetadataModelDB != null && applicationMetadataModelDB.size() > 0) { long startTime = System.currentTimeMillis();
long startTime = System.currentTimeMillis(); System.out.println("Copying cached application metadata model into memory");
System.out.println("Copying cached application metadata model into memory"); applicationMetadataModel.add(applicationMetadataModelDB);
applicationMetadataModel.add(applicationMetadataModelDB); System.out.println((System.currentTimeMillis()-startTime)/1000+" seconds to load application metadata model assertions of size " + applicationMetadataModel.size());
System.out.println((System.currentTimeMillis()-startTime)/1000+" seconds to load application metadata model assertions of size " + applicationMetadataModel.size()); applicationMetadataModel.getBaseModel().register(new ModelSynchronizer(applicationMetadataModelDB));
applicationMetadataModel.getBaseModel().register(new ModelSynchronizer(applicationMetadataModelDB));
baseOms.setApplicationMetadataModel(applicationMetadataModel); if (applicationMetadataModelDB.size() == 0) {
inferenceOms.setApplicationMetadataModel(baseOms.getApplicationMetadataModel()); repairAppMetadataModel(applicationMetadataModel, aboxAssertions, aboxInferences);
unionOms.setApplicationMetadataModel(baseOms.getApplicationMetadataModel());
} else {
log.error("The application metadata model was not found");
} }
baseOms.setApplicationMetadataModel(applicationMetadataModel);
inferenceOms.setApplicationMetadataModel(baseOms.getApplicationMetadataModel());
unionOms.setApplicationMetadataModel(baseOms.getApplicationMetadataModel());
} catch (Throwable e) { } catch (Throwable e) {
log.error("Unable to load application metadata model cache from DB", e); log.error("Unable to load application metadata model cache from DB", e);
} }
@ -498,10 +499,11 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
return; return;
} }
private static void repairAppMetadataModel(Store store, Model aboxAssertions, Model aboxInferences) { private static void repairAppMetadataModel(Model applicationMetadataModel,
Model aboxAssertions,
Model aboxInferences) {
log.info("Repairing the application metadata model"); log.info("Moving application metadata from ABox to dedicated model");
Model applicationMetadataModel = SDBFactory.connectNamedModel(store, JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL);
getAppMetadata(aboxAssertions, applicationMetadataModel); getAppMetadata(aboxAssertions, applicationMetadataModel);
getAppMetadata(aboxInferences, applicationMetadataModel); getAppMetadata(aboxInferences, applicationMetadataModel);
aboxAssertions.remove(applicationMetadataModel); aboxAssertions.remove(applicationMetadataModel);
@ -534,46 +536,60 @@ public class JenaDataSourceSetupSDB extends JenaDataSourceSetupBase implements j
store.getTableFormatter().create(); store.getTableFormatter().create();
store.getTableFormatter().truncate(); store.getTableFormatter().truncate();
// This is a one-time copy of stored KB data - from a Jena RDB store store.getTableFormatter().dropIndexes(); // improve load performance
// to a Jena SDB store. In the process, we will also separate out the
// TBox from the Abox; these are in the same graph in pre 1.2 VIVO
// versions and will now be stored and maintained in separate models
// Access to the Jena RDB data is through the OntModelSelectors that have
// been set up earlier in the current session by
// JenaPersistentDataSourceSetup.java
// In the code below, note that the current getABoxModel() methods on
// the OntModelSelectors return a graph with both ABox and TBox data.
OntModel submodels = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC); try {
readOntologyFilesInPathSet(SUBMODELS, ctx, submodels);
Model tboxAssertions = SDBFactory.connectNamedModel(store, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL); // This is a one-time copy of stored KB data - from a Jena RDB store
// initially putting the results in memory so we have a // to a Jena SDB store. In the process, we will also separate out the
// cheaper way of computing the difference when we copy the ABox // TBox from the Abox; these are in the same graph in pre 1.2 VIVO
Model memTboxAssertions = ModelFactory.createDefaultModel(); // versions and will now be stored and maintained in separate models
getTBoxModel(memModel, submodels, memTboxAssertions); // Access to the Jena RDB data is through the OntModelSelectors that have
tboxAssertions.add(memTboxAssertions); // been set up earlier in the current session by
// JenaPersistentDataSourceSetup.java
// In the code below, note that the current getABoxModel() methods on
// the OntModelSelectors return a graph with both ABox and TBox data.
Model tboxInferences = SDBFactory.connectNamedModel(store, JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL); OntModel submodels = ModelFactory.createOntologyModel(MEM_ONT_MODEL_SPEC);
// initially putting the results in memory so we have a readOntologyFilesInPathSet(SUBMODELS, ctx, submodels);
// cheaper way of computing the difference when we copy the ABox
Model memTboxInferences = ModelFactory.createDefaultModel();
getTBoxModel(inferenceModel, submodels, memTboxInferences);
tboxInferences.add(memTboxInferences);
Model aboxAssertions = SDBFactory.connectNamedModel(store, JenaDataSourceSetupBase.JENA_DB_MODEL); Model tboxAssertions = SDBFactory.connectNamedModel(
copyDifference(memModel, memTboxAssertions, aboxAssertions); store, JenaDataSourceSetupBase.JENA_TBOX_ASSERTIONS_MODEL);
// initially putting the results in memory so we have a
// cheaper way of computing the difference when we copy the ABox
Model memTboxAssertions = ModelFactory.createDefaultModel();
getTBoxModel(memModel, submodels, memTboxAssertions);
tboxAssertions.add(memTboxAssertions);
Model aboxInferences = SDBFactory.connectNamedModel(store, JenaDataSourceSetupBase.JENA_INF_MODEL); Model tboxInferences = SDBFactory.connectNamedModel(
copyDifference(inferenceModel, memTboxInferences, aboxInferences); store, JenaDataSourceSetupBase.JENA_TBOX_INF_MODEL);
// initially putting the results in memory so we have a
// cheaper way of computing the difference when we copy the ABox
Model memTboxInferences = ModelFactory.createDefaultModel();
getTBoxModel(inferenceModel, submodels, memTboxInferences);
tboxInferences.add(memTboxInferences);
// Set up the application metadata model Model aboxAssertions = SDBFactory.connectNamedModel(
Model applicationMetadataModel = SDBFactory.connectNamedModel(store, JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL); store, JenaDataSourceSetupBase.JENA_DB_MODEL);
getAppMetadata(memModel, applicationMetadataModel); copyDifference(memModel, memTboxAssertions, aboxAssertions);
log.info("During initial SDB setup, created an application metadata model of size " + applicationMetadataModel.size());
// Make sure the reasoner takes into account the newly-set-up data. Model aboxInferences = SDBFactory.connectNamedModel(
SimpleReasonerSetup.setRecomputeRequired(ctx); store, JenaDataSourceSetupBase.JENA_INF_MODEL);
copyDifference(inferenceModel, memTboxInferences, aboxInferences);
// Set up the application metadata model
Model applicationMetadataModel = SDBFactory.connectNamedModel(
store, JenaDataSourceSetupBase.JENA_APPLICATION_METADATA_MODEL);
getAppMetadata(memModel, applicationMetadataModel);
log.info("During initial SDB setup, created an application metadata model of size "
+ applicationMetadataModel.size());
// Make sure the reasoner takes into account the newly-set-up data.
SimpleReasonerSetup.setRecomputeRequired(ctx);
} finally {
store.getTableFormatter().addIndexes();
}
} }
/** /**