VIVO-906 Create the TripleSource hierarchy.

SingleSourceDataStructuresProvider becomes TripleSource
DataStructuresProvider becomes CombinedTripleSource
This commit is contained in:
Jim Blake 2014-11-13 17:06:05 -05:00
parent d18c9a38ca
commit e3dca6a699
16 changed files with 262 additions and 274 deletions

View file

@ -10,7 +10,7 @@ import org.apache.commons.logging.LogFactory;
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.ContextModelAccessImpl;
import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.RequestModelAccessImpl;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.DataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.triplesource.CombinedTripleSource;
/**
* The root access point for the RDF data structures: RDFServices, Datasets,
@ -136,18 +136,18 @@ public class ModelAccess {
// The factory
// ----------------------------------------------------------------------
private static volatile DataStructuresProvider dataStructuresProvider;
private static volatile CombinedTripleSource combinedTripleSource;
private static volatile ModelAccessFactory factory = new ModelAccessFactory();
/** These attributes should only be accessed through this class. */
private static final String ATTRIBUTE_NAME = ModelAccess.class.getName();
public static void setDataStructuresProvider(DataStructuresProvider provider) {
if (dataStructuresProvider != null) {
log.warn("Assigning DataStructuresProvider " + provider
+ ", but was already set to " + dataStructuresProvider);
public static void setCombinedTripleSource(CombinedTripleSource source) {
if (combinedTripleSource != null) {
log.warn("Assigning CombinedTripleSource " + source
+ ", but was already set to " + combinedTripleSource);
}
dataStructuresProvider = provider;
combinedTripleSource = source;
}
public static RequestModelAccess on(HttpServletRequest req) {
@ -182,7 +182,7 @@ public class ModelAccess {
public static class ModelAccessFactory {
public ContextModelAccess buildContextModelAccess(ServletContext ctx) {
return new ContextModelAccessImpl(ctx, dataStructuresProvider);
return new ContextModelAccessImpl(ctx, combinedTripleSource);
}
/**
@ -191,8 +191,7 @@ public class ModelAccess {
*/
public RequestModelAccess buildRequestModelAccess(HttpServletRequest req) {
return new RequestModelAccessImpl(req,
dataStructuresProvider
.getShortTermDataStructuresProvider(req));
combinedTripleSource.getShortTermCombinedTripleSource(req));
}
}
}

View file

@ -45,7 +45,7 @@ import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.ReasoningOption;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.DataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.triplesource.CombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
@ -66,7 +66,7 @@ public class ContextModelAccessImpl implements ContextModelAccess {
private final ConfigurationProperties props;
private final DataStructuresProvider factory;
private final CombinedTripleSource factory;
private final Map<WhichService, RDFService> rdfServiceMap;
private final Map<WhichService, Dataset> datasetMap;
@ -86,7 +86,7 @@ public class ContextModelAccessImpl implements ContextModelAccess {
* requested.
*/
public ContextModelAccessImpl(ServletContext ctx,
DataStructuresProvider factory) {
CombinedTripleSource factory) {
this.props = ConfigurationProperties.getBean(ctx);
this.factory = factory;

View file

@ -51,7 +51,7 @@ import edu.cornell.mannlib.vitro.webapp.modelaccess.impl.keys.WebappDaoFactoryKe
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringRDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.ShortTermDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.triplesource.ShortTermCombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
@ -89,14 +89,14 @@ public class RequestModelAccessImpl implements RequestModelAccess {
private final HttpServletRequest req;
private final ServletContext ctx;
private final ConfigurationProperties props;
private final ShortTermDataStructuresProvider provider;
private final ShortTermCombinedTripleSource source;
public RequestModelAccessImpl(HttpServletRequest req,
ShortTermDataStructuresProvider provider) {
ShortTermCombinedTripleSource source) {
this.req = req;
this.ctx = req.getSession().getServletContext();
this.props = ConfigurationProperties.getBean(req);
this.provider = provider;
this.source = source;
}
/**
@ -113,13 +113,13 @@ public class RequestModelAccessImpl implements RequestModelAccess {
@Override
public void close() {
this.provider.close();
this.source.close();
}
@Override
public String toString() {
return "RequestModelAccessImpl[" + ToString.hashHex(this) + ", req="
+ ToString.hashHex(req) + ", provider=" + provider + "]";
+ ToString.hashHex(req) + ", source=" + source + "]";
}
// ----------------------------------------------------------------------
@ -149,7 +149,7 @@ public class RequestModelAccessImpl implements RequestModelAccess {
if (key.getLanguageOption() == LANGUAGE_AWARE) {
return addLanguageAwareness(getRDFService(LANGUAGE_NEUTRAL));
} else {
return provider.getRDFService(key.getWhichService());
return source.getRDFService(key.getWhichService());
}
}
@ -222,7 +222,7 @@ public class RequestModelAccessImpl implements RequestModelAccess {
return addLanguageAwareness(getOntModel(key.getName(),
LANGUAGE_NEUTRAL));
} else {
return provider.getOntModelCache().getOntModel(key.getName());
return source.getOntModelCache().getOntModel(key.getName());
}
}
@ -313,7 +313,7 @@ public class RequestModelAccessImpl implements RequestModelAccess {
RDFService rdfService = getRDFService(key.rdfServiceKey());
OntModelSelector ontModelSelector = getOntModelSelector(key
.ontModelSelectorKey());
WebappDaoFactoryConfig config = provider.getWebappDaoFactoryConfig();
WebappDaoFactoryConfig config = source.getWebappDaoFactoryConfig();
switch (key.getReasoningOption()) {
case ASSERTIONS_ONLY:

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl;
package edu.cornell.mannlib.vitro.webapp.modules.tripleSource;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.DISPLAY;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.DISPLAY_DISPLAY;
@ -10,11 +10,9 @@ import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.USER_ACCOU
import com.hp.hpl.jena.rdf.model.ModelMaker;
/**
* The base class for a provider of configuration models. It just contains some
* useful constants and utility methods.
* A triple source for configuration models.
*/
public abstract class ConfigurationDataStructuresProvider implements
SingleSourceDataStructuresProvider {
public abstract class ConfigurationTripleSource implements TripleSource {
/**
* A list of all Configuration models, in case the implementation wants to
* add memory-mapping.
@ -33,5 +31,4 @@ public abstract class ConfigurationDataStructuresProvider implements
}
return sourceMM;
}
}

View file

@ -1,23 +1,20 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl;
package edu.cornell.mannlib.vitro.webapp.modules.tripleSource;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.APPLICATION_METADATA;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.FULL_UNION;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.TBOX_ASSERTIONS;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.*;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelNames.TBOX_INFERENCES;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.NamedDefaultModelMaker;
/**
* The base class for a provider of content models. It just contains some useful
* constants and utility methods.
* A triple source for content models.
*/
public abstract class ContentDataStructuresProvider implements
SingleSourceDataStructuresProvider {
public abstract class ContentTripleSource implements TripleSource {
/**
* These are the small content models that we want to keep in memory.
*/

View file

@ -1,22 +1,19 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl;
package edu.cornell.mannlib.vitro.webapp.modules.tripleSource;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
/**
* An RDFSource that provides Content models or Configuration models, but not
* both.
*
* Repeated calls for the same data structure should yield the same instance,
* except for the short-term OntModelCache.
* A provider of triples and the data structures by which they are accessed.
*/
public interface SingleSourceDataStructuresProvider extends AutoCloseable {
public interface TripleSource extends Application.Module{
RDFServiceFactory getRDFServiceFactory();
RDFService getRDFService();

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup;
package edu.cornell.mannlib.vitro.webapp.triplesource;
import javax.servlet.http.HttpServletRequest;
@ -17,11 +17,11 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
*
* Repeated calls for the same data structure should yield the same instance.
*
* Repeated calls for the ShortTermDataStructuresProvider need not yield the
* Repeated calls for the ShortTermCombinedTripleSource need not yield the
* same instance, but must yield an instance that will return the same
* structures as any other instance for the same request.
*/
public interface DataStructuresProvider {
public interface CombinedTripleSource {
RDFService getRDFService(WhichService whichService);
Dataset getDataset(WhichService whichService);
@ -30,6 +30,6 @@ public interface DataStructuresProvider {
OntModelCache getOntModelCache();
ShortTermDataStructuresProvider getShortTermDataStructuresProvider(
ShortTermCombinedTripleSource getShortTermCombinedTripleSource(
HttpServletRequest req);
}

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup;
package edu.cornell.mannlib.vitro.webapp.triplesource;
import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
@ -16,7 +16,7 @@ import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
* Repeated calls for the WebappDaoFactoryConfig need not yield the same
* instance.
*/
public interface ShortTermDataStructuresProvider {
public interface ShortTermCombinedTripleSource {
RDFService getRDFService(WhichService whichService);
OntModelCache getOntModelCache();

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT;
@ -27,23 +27,26 @@ import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.ModelMakerOntModel
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.UnionModelsOntModelsCache;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.UnionModelsOntModelsCache.UnionSpec;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ConfigurationTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.TripleSource;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.DataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.ShortTermDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.triplesource.CombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.triplesource.ShortTermCombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
* A simple implementation of DataStructuresProvider.
* A simple implementation of CombinedTripleSource.
*
* Note that we don't bother to cache the RDFServices, RDFServiceFactories, and
* ModelMakers, since the providers can be expected to cache them.
* ModelMakers, since the sources can be expected to cache them.
*
* We must cache the OntModelCache because it was created here. If we were to
* recreate it, we would lose any sub-models that had been attached in the
* meantime.
*/
public class BasicDataStructuresProvider implements DataStructuresProvider {
public class BasicCombinedTripleSource implements CombinedTripleSource {
/**
* Create union models for ABox and TBox, and full models for assertions and
* inferences. No need to create FULL_UNION, since it's the default model.
@ -58,16 +61,15 @@ public class BasicDataStructuresProvider implements DataStructuresProvider {
UnionSpec.base(ABOX_INFERENCES).plus(TBOX_INFERENCES)
.yields(FULL_INFERENCES) };
private final Map<WhichService, SingleSourceDataStructuresProvider> providers;
private final Map<WhichService, TripleSource> sources;
private final Map<WhichService, OntModelCache> ontModels;
private final OntModelCache ontModelCache;
public BasicDataStructuresProvider(
SingleSourceDataStructuresProvider contentProvider,
SingleSourceDataStructuresProvider configurationProvider) {
providers = new EnumMap<>(WhichService.class);
providers.put(CONTENT, contentProvider);
providers.put(CONFIGURATION, configurationProvider);
public BasicCombinedTripleSource(ContentTripleSource contentSource,
ConfigurationTripleSource configurationSource) {
sources = new EnumMap<>(WhichService.class);
sources.put(CONTENT, contentSource);
sources.put(CONFIGURATION, configurationSource);
ontModels = new EnumMap<>(WhichService.class);
ontModels.put(CONTENT, new ModelMakerOntModelCache(
@ -85,22 +87,22 @@ public class BasicDataStructuresProvider implements DataStructuresProvider {
}
protected RDFServiceFactory getRDFServiceFactory(WhichService whichService) {
return providers.get(whichService).getRDFServiceFactory();
return sources.get(whichService).getRDFServiceFactory();
}
@Override
public RDFService getRDFService(WhichService whichService) {
return providers.get(whichService).getRDFService();
return sources.get(whichService).getRDFService();
}
@Override
public Dataset getDataset(WhichService whichService) {
return providers.get(whichService).getDataset();
return sources.get(whichService).getDataset();
}
@Override
public ModelMaker getModelMaker(WhichService whichService) {
return providers.get(whichService).getModelMaker();
return sources.get(whichService).getModelMaker();
}
@Override
@ -109,16 +111,15 @@ public class BasicDataStructuresProvider implements DataStructuresProvider {
}
@Override
public ShortTermDataStructuresProvider getShortTermDataStructuresProvider(
public ShortTermCombinedTripleSource getShortTermCombinedTripleSource(
HttpServletRequest req) {
return new BasicShortTermDataStructuresProvider(req, this, providers);
return new BasicShortTermCombinedTripleSource(req, this, sources);
}
@Override
public String toString() {
return "BasicDataStructuresProvider[" + ToString.hashHex(this)
+ ", providers=" + providers + ", ontModels=" + ontModelCache
+ "]";
return "BasicCombinedTripleSource[" + ToString.hashHex(this)
+ ", sources=" + sources + ", ontModels=" + ontModelCache + "]";
}
}

View file

@ -1,6 +1,6 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONFIGURATION;
import static edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService.CONTENT;
@ -25,39 +25,39 @@ import edu.cornell.mannlib.vitro.webapp.dao.WebappDaoFactoryConfig;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ModelAccess.WhichService;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.JoinedOntModelCache;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.TripleSource;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.filter.LanguageFilteringUtils;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.ShortTermDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.triplesource.ShortTermCombinedTripleSource;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
* The simple implementation of ShortTermDataStructuresProvider.
* The simple implementation of ShortTermCombinedTripleSource.
*
* The short-term RDFServices are cached, lest we somehow create duplicates for
* the same request. Similarly with the short-term OntModels.
*/
public class BasicShortTermDataStructuresProvider implements
ShortTermDataStructuresProvider {
public class BasicShortTermCombinedTripleSource implements
ShortTermCombinedTripleSource {
private static final Log log = LogFactory
.getLog(BasicShortTermDataStructuresProvider.class);
.getLog(BasicShortTermCombinedTripleSource.class);
private final HttpServletRequest req;
private final ServletContext ctx;
private final ConfigurationProperties props;
private final BasicDataStructuresProvider parent;
private final Map<WhichService, SingleSourceDataStructuresProvider> providers;
private final BasicCombinedTripleSource parent;
private final Map<WhichService, TripleSource> sources;
private final Map<WhichService, RDFService> rdfServices;
private final OntModelCache ontModelCache;
public BasicShortTermDataStructuresProvider(
HttpServletRequest req,
BasicDataStructuresProvider parent,
final Map<WhichService, SingleSourceDataStructuresProvider> providers) {
public BasicShortTermCombinedTripleSource(HttpServletRequest req,
BasicCombinedTripleSource parent,
final Map<WhichService, TripleSource> sources) {
this.req = req;
this.ctx = req.getSession().getServletContext();
this.props = ConfigurationProperties.getBean(ctx);
this.parent = parent;
this.providers = providers;
this.sources = sources;
this.rdfServices = populateRdfServicesMap();
this.ontModelCache = createOntModelCache();
}
@ -77,12 +77,12 @@ public class BasicShortTermDataStructuresProvider implements
}
/**
* Ask each provider what short-term models should mask their long-term
* Ask each triple source what short-term models should mask their long-term
* counterparts.
*/
private OntModelCache shortModels(WhichService which) {
return providers.get(which).getShortTermOntModels(
rdfServices.get(which), parent.getOntModels(which));
return sources.get(which).getShortTermOntModels(rdfServices.get(which),
parent.getOntModels(which));
}
@Override
@ -142,8 +142,8 @@ public class BasicShortTermDataStructuresProvider implements
@Override
public String toString() {
return "BasicShortTermDataStructuresProvider[" + ToString.hashHex(this)
+ ", req=" + ToString.hashHex(req) + ", providers=" + providers
return "BasicShortTermCombinedTripleSource[" + ToString.hashHex(this)
+ ", req=" + ToString.hashHex(req) + ", sources=" + sources
+ ", ontModels=" + ontModelCache + "]";
}

View file

@ -1,14 +1,13 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.BasicDataStructuresProvider.CONTENT_UNIONS;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.BasicCombinedTripleSource.CONTENT_UNIONS;
import java.sql.SQLException;
import java.util.Arrays;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
import javax.sql.DataSource;
import org.apache.commons.logging.Log;
@ -36,13 +35,14 @@ import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.MaskingOntModelCac
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.ModelMakerOntModelCache;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.UnionModelsOntModelsCache;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.jena.sdb.RDFServiceFactorySDB;
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.servlet.setup.rdfsetup.impl.ContentDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
@ -51,10 +51,9 @@ import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
* Do some smoke-tests on the parameters, create the connection pool, and create
* the RDFServiceFactory.
*/
public class ContentDataStructuresProviderSDB extends
ContentDataStructuresProvider {
public class ContentTripleSourceSDB extends ContentTripleSource {
private static final Log log = LogFactory
.getLog(ContentDataStructuresProviderSDB.class);
.getLog(ContentTripleSourceSDB.class);
static final String PROPERTY_DB_URL = "VitroConnection.DataSource.url";
static final String PROPERTY_DB_USERNAME = "VitroConnection.DataSource.username";
@ -78,32 +77,28 @@ public class ContentDataStructuresProviderSDB extends
static final boolean DEFAULT_TESTONBORROW = true;
static final boolean DEFAULT_TESTONRETURN = true;
private final ServletContext ctx;
private final StartupStatus ss;
private final ComboPooledDataSource ds;
private final RDFServiceFactory rdfServiceFactory;
private final RDFService rdfService;
private final Dataset dataset;
private final ModelMaker modelMaker;
private ServletContext ctx;
private ComboPooledDataSource ds;
private RDFServiceFactory rdfServiceFactory;
private RDFService rdfService;
private Dataset dataset;
private ModelMaker modelMaker;
public ContentDataStructuresProviderSDB(ServletContext ctx,
ServletContextListener ctxListener) {
@Override
public void startup(Application application, ComponentStartupStatus ss) {
try {
this.ctx = ctx;
this.ss = StartupStatus.getBean(ctx);
this.ctx = application.getServletContext();
configureSDBContext();
new SDBConnectionSmokeTests(ctx, ctxListener)
.checkDatabaseConnection();
new SDBConnectionSmokeTests(ctx, ss).checkDatabaseConnection();
this.ds = new SDBDataSource(ctx).getDataSource();
this.rdfServiceFactory = createRdfServiceFactory();
this.rdfService = rdfServiceFactory.getRDFService();
this.dataset = new RDFServiceDataset(this.rdfService);
this.modelMaker = createModelMaker();
ss.info(ctxListener,
"Initialized the content data structures for SDB");
ss.info("Initialized the content data structures for SDB");
} catch (SQLException e) {
throw new RuntimeException(
"Failed to set up the content data structures for SDB", e);
@ -211,16 +206,15 @@ public class ContentDataStructuresProviderSDB extends
}
@Override
public void close() {
public String toString() {
return "ContentTripleSourceSDB[" + ToString.hashHex(this) + "]";
}
@Override
public void shutdown(Application application) {
if (ds != null) {
ds.close();
}
}
@Override
public String toString() {
return "ContentDataStructuresProviderSDB[" + ToString.hashHex(this)
+ "]";
}
}

View file

@ -1,13 +1,13 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_DRIVER_CLASS;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_DRIVER_CLASS_NAME;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_PASSWORD;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_TYPE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_URL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_USERNAME;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_DRIVER_CLASS;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_DRIVER_CLASS_NAME;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_PASSWORD;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_TYPE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_URL;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_USERNAME;
import java.io.UnsupportedEncodingException;
import java.sql.Connection;
@ -19,10 +19,9 @@ import java.sql.Statement;
import java.util.Properties;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
/**
* Smoke tests for the database connection that SDB will use.
@ -38,38 +37,31 @@ import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
* encoding. Don't know how well this works.
*/
public class SDBConnectionSmokeTests {
private final ServletContextListener parent;
private final ConfigurationProperties props;
private final StartupStatus ss;
private final ComponentStartupStatus ss;
public SDBConnectionSmokeTests(ServletContext ctx,
ServletContextListener parent) {
this.parent = parent;
public SDBConnectionSmokeTests(ServletContext ctx, ComponentStartupStatus ss) {
this.props = ConfigurationProperties.getBean(ctx);
this.ss = StartupStatus.getBean(ctx);
this.ss = ss;
}
public void checkDatabaseConnection() {
String url = props.getProperty(PROPERTY_DB_URL);
if (url == null || url.isEmpty()) {
ss.fatal(parent,
"runtime.properties does not contain a value for '"
+ PROPERTY_DB_URL + "'");
ss.fatal("runtime.properties does not contain a value for '"
+ PROPERTY_DB_URL + "'");
return;
}
String username = props.getProperty(PROPERTY_DB_USERNAME);
if (username == null || username.isEmpty()) {
ss.fatal(parent,
"runtime.properties does not contain a value for '"
+ PROPERTY_DB_USERNAME + "'");
ss.fatal("runtime.properties does not contain a value for '"
+ PROPERTY_DB_USERNAME + "'");
return;
}
String password = props.getProperty(PROPERTY_DB_PASSWORD);
if (password == null || password.isEmpty()) {
ss.fatal(parent,
"runtime.properties does not contain a value for '"
+ PROPERTY_DB_PASSWORD + "'");
ss.fatal("runtime.properties does not contain a value for '"
+ PROPERTY_DB_PASSWORD + "'");
return;
}
@ -79,16 +71,16 @@ public class SDBConnectionSmokeTests {
try {
Class.forName(DEFAULT_DRIVER_CLASS).newInstance();
} catch (Exception e) {
ss.fatal(parent, "The default Database Driver failed to load. "
+ "The driver class is '" + DEFAULT_DRIVER_CLASS
+ "'", e);
ss.fatal("The default Database Driver failed to load. "
+ "The driver class is '" + DEFAULT_DRIVER_CLASS + "'",
e);
return;
}
} else {
try {
Class.forName(driverClassName).newInstance();
} catch (Exception e) {
ss.fatal(parent, "The Database Driver failed to load. "
ss.fatal("The Database Driver failed to load. "
+ "The driver class was set by "
+ PROPERTY_DB_DRIVER_CLASS_NAME + " to be '"
+ driverClassName + "'", e);
@ -104,9 +96,9 @@ public class SDBConnectionSmokeTests {
.getConnection(url, connectionProps)) {
// Just open the connection and close it.
} catch (SQLException e) {
ss.fatal(parent, "Can't connect to the database: "
+ PROPERTY_DB_URL + "='" + url + "', "
+ PROPERTY_DB_USERNAME + "='" + username + "'", e);
ss.fatal("Can't connect to the database: " + PROPERTY_DB_URL + "='"
+ url + "', " + PROPERTY_DB_USERNAME + "='" + username
+ "'", e);
return;
}
@ -151,15 +143,14 @@ public class SDBConnectionSmokeTests {
+ "set on the database?";
if ("MySQL".equals(dbType)) {
// For MySQL, we know that this is a configuration problem.
ss.fatal(parent, message);
ss.fatal(message);
} else {
// For other databases, it might not be.
ss.warning(parent, message);
ss.warning(message);
}
}
} catch (SQLException e) {
ss.fatal(parent, "Failed to check handling of Unicode characters",
e);
ss.fatal("Failed to check handling of Unicode characters", e);
}
}

View file

@ -1,23 +1,23 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_DRIVER_CLASS;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_MAXACTIVE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_MAXIDLE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_TESTONBORROW;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_TESTONRETURN;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_TYPE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.DEFAULT_VALIDATION_QUERY;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.MINIMUM_MAXACTIVE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_DRIVER_CLASS_NAME;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_MAX_ACTIVE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_MAX_IDLE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_PASSWORD;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_TYPE;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_URL;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_USERNAME;
import static edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sdb.ContentDataStructuresProviderSDB.PROPERTY_DB_VALIDATION_QUERY;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_DRIVER_CLASS;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_MAXACTIVE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_MAXIDLE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TESTONBORROW;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TESTONRETURN;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_TYPE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.DEFAULT_VALIDATION_QUERY;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.MINIMUM_MAXACTIVE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_DRIVER_CLASS_NAME;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_MAX_ACTIVE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_MAX_IDLE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_PASSWORD;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_TYPE;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_URL;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_USERNAME;
import static edu.cornell.mannlib.vitro.webapp.triplesource.impl.sdb.ContentTripleSourceSDB.PROPERTY_DB_VALIDATION_QUERY;
import java.beans.PropertyVetoException;

View file

@ -1,26 +1,25 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.sparql;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.sparql;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
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.adapters.ListCachingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.MemoryMappingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
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.logging.LoggingRDFServiceFactory;
import edu.cornell.mannlib.vitro.webapp.rdfservice.impl.sparql.RDFServiceSparql;
import edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.ContentDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
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;
/**
@ -33,44 +32,59 @@ import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
*
* Memory-map the small content models, and add the standard decorators.
*/
public class ContentDataStructuresProviderSPARQL extends
ContentDataStructuresProvider {
public static final String PROPERTY_SPARQL_ENDPOINT_URI = "VitroConnection.DataSource.endpointURI";
public static final String PROPERTY_SPARQL_UPDATE_ENDPOINT_URI = "VitroConnection.DataSource.updateEndpointURI";
public class ContentTripleSourceSPARQL extends ContentTripleSource {
private String endpointURI;
private String updateEndpointURI; // Optional
private final ServletContextListener ctxListener;
private final ConfigurationProperties props;
private final StartupStatus ss;
private final String endpointURI;
private final String updateEndpointURI;
private RDFService rdfService;
private RDFServiceFactory rdfServiceFactory;
private Dataset dataset;
private ModelMaker modelMaker;
private final RDFService rdfService;
private final RDFServiceFactory rdfServiceFactory;
private final Dataset dataset;
private final ModelMaker modelMaker;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasEndpointURI")
public void setEndpointURI(String eUri) {
if (endpointURI == null) {
endpointURI = eUri;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of EndpointURI: "
+ endpointURI + ", and " + eUri);
}
}
public ContentDataStructuresProviderSPARQL(ServletContext ctx,
ServletContextListener ctxListener) {
this.ctxListener = ctxListener;
this.props = ConfigurationProperties.getBean(ctx);
this.ss = StartupStatus.getBean(ctx);
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasUpdateEndpointURI")
public void setUpdateEndpointURI(String ueUri) {
if (updateEndpointURI == null) {
updateEndpointURI = ueUri;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of UpdateEndpointURI: "
+ updateEndpointURI + ", and " + ueUri);
}
}
this.endpointURI = props.getProperty(PROPERTY_SPARQL_ENDPOINT_URI);
this.updateEndpointURI = props
.getProperty(PROPERTY_SPARQL_UPDATE_ENDPOINT_URI);
@Validation
public void validate() throws Exception {
if (endpointURI == null) {
throw new IllegalStateException(
"Configuration did not include an EndpointURI.");
}
}
this.rdfServiceFactory = createRDFServiceFactory(createRDFService());
@Override
public void startup(Application application, ComponentStartupStatus ss) {
this.rdfServiceFactory = createRDFServiceFactory(createRDFService(ss));
this.rdfService = this.rdfServiceFactory.getRDFService();
this.dataset = createDataset();
this.modelMaker = createModelMaker();
}
private RDFService createRDFService() {
private RDFService createRDFService(ComponentStartupStatus ss) {
if (updateEndpointURI == null) {
ss.info(ctxListener, "Using endpoint at " + endpointURI);
ss.info("Using endpoint at " + endpointURI);
return new RDFServiceSparql(endpointURI);
} else {
ss.info(ctxListener, "Using read endpoint at " + endpointURI
ss.info("Using read endpoint at " + endpointURI
+ " and update endpoint at " + updateEndpointURI);
return new RDFServiceSparql(endpointURI, updateEndpointURI);
}
@ -119,17 +133,17 @@ public class ContentDataStructuresProviderSPARQL extends
}
@Override
public void close() {
public String toString() {
return "ContentTripleSourceSPARQL[" + ToString.hashHex(this)
+ ", endpointURI=" + endpointURI + ", updateEndpointURI="
+ updateEndpointURI + "]";
}
@Override
public void shutdown(Application application) {
if (this.rdfService != null) {
this.rdfService.close();
}
}
@Override
public String toString() {
return "ContentDataStructuresProviderSPARQL[" + ToString.hashHex(this)
+ ", endpointURI=" + endpointURI + ", updateEndpointURI="
+ updateEndpointURI + "]";
}
}

View file

@ -1,30 +1,28 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.tdb;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.tdb;
import java.io.File;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
import java.nio.file.Path;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import com.hp.hpl.jena.tdb.TDB;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
import edu.cornell.mannlib.vitro.webapp.application.ApplicationUtils;
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.adapters.ListCachingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.MemoryMappingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ConfigurationTripleSource;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
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.rdfsetup.impl.ConfigurationDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
/**
@ -37,35 +35,29 @@ import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
*
* Memory-map all of the configuration models, and add the standard decorators.
*/
public class ConfigurationDataStructuresProviderTDB extends
ConfigurationDataStructuresProvider {
public class ConfigurationTripleSourceTDB extends ConfigurationTripleSource {
private static final String DIRECTORY_TDB = "tdbModels";
private final ConfigurationProperties props;
private final StartupStatus ss;
private final RDFServiceFactory rdfServiceFactory;
private final RDFService rdfService;
private final Dataset dataset;
private final ModelMaker modelMaker;
public ConfigurationDataStructuresProviderTDB(ServletContext ctx,
ServletContextListener ctxListener) {
this.props = ConfigurationProperties.getBean(ctx);
this.ss = StartupStatus.getBean(ctx);
private RDFServiceFactory rdfServiceFactory;
private RDFService rdfService;
private Dataset dataset;
private ModelMaker modelMaker;
@Override
public void startup(Application application, ComponentStartupStatus ss) {
configureTDB();
String tdbPath = props.getProperty("vitro.home") + File.separatorChar
+ DIRECTORY_TDB;
Path vitroHome = ApplicationUtils.instance().getHomeDirectory()
.getPath();
String tdbPath = vitroHome.resolve(DIRECTORY_TDB).toString();
try {
this.rdfServiceFactory = createRDFServiceFactory(tdbPath);
this.rdfService = this.rdfServiceFactory.getRDFService();
this.dataset = new RDFServiceDataset(this.rdfService);
this.modelMaker = createModelMaker();
ss.info(ctxListener, "Initialized the RDF source for TDB");
ss.info("Initialized the RDF source for TDB");
} catch (IOException e) {
throw new RuntimeException(
"Failed to set up the RDF source for TDB", e);
@ -117,15 +109,15 @@ public class ConfigurationDataStructuresProviderTDB extends
}
@Override
public void close() {
public String toString() {
return "ConfigurationTripleSourceTDB[" + ToString.hashHex(this) + "]";
}
@Override
public void shutdown(Application application) {
if (this.rdfService != null) {
this.rdfService.close();
}
}
@Override
public String toString() {
return "ConfigurationDataStructuresProviderTDB["
+ ToString.hashHex(this) + "]";
}
}

View file

@ -1,29 +1,28 @@
/* $This file is distributed under the terms of the license in /doc/license.txt$ */
package edu.cornell.mannlib.vitro.webapp.servlet.setup.rdfsetup.impl.tdb;
package edu.cornell.mannlib.vitro.webapp.triplesource.impl.tdb;
import java.io.IOException;
import javax.servlet.ServletContext;
import javax.servlet.ServletContextListener;
import com.hp.hpl.jena.query.Dataset;
import com.hp.hpl.jena.rdf.model.ModelMaker;
import com.hp.hpl.jena.tdb.TDB;
import edu.cornell.mannlib.vitro.webapp.config.ConfigurationProperties;
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.adapters.ListCachingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.adapters.MemoryMappingModelMaker;
import edu.cornell.mannlib.vitro.webapp.modelaccess.ontmodels.OntModelCache;
import edu.cornell.mannlib.vitro.webapp.modules.Application;
import edu.cornell.mannlib.vitro.webapp.modules.ComponentStartupStatus;
import edu.cornell.mannlib.vitro.webapp.modules.tripleSource.ContentTripleSource;
import edu.cornell.mannlib.vitro.webapp.rdfservice.RDFService;
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.rdfsetup.impl.ContentDataStructuresProvider;
import edu.cornell.mannlib.vitro.webapp.startup.StartupStatus;
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;
/**
@ -36,34 +35,42 @@ import edu.cornell.mannlib.vitro.webapp.utils.logging.ToString;
*
* Memory-map the small content models, and add the standard decorators.
*/
public class ContentDataStructuresProviderTDB extends
ContentDataStructuresProvider {
public class ContentTripleSourceTDB extends ContentTripleSource {
private String tdbPath;
public static final String PROPERTY_CONTENT_TDB_PATH = "VitroConnection.DataSource.tdbDirectory";
private RDFServiceFactory rdfServiceFactory;
private RDFService rdfService;
private Dataset dataset;
private ModelMaker modelMaker;
private final ConfigurationProperties props;
private final StartupStatus ss;
@Property(uri = "http://vitro.mannlib.cornell.edu/ns/vitro/ApplicationSetup#hasTdbDirectory")
public void setTdbPath(String path) {
if (tdbPath == null) {
tdbPath = path;
} else {
throw new IllegalStateException(
"Configuration includes multiple instances of TdbDirectory: "
+ tdbPath + ", and " + path);
}
}
private final RDFServiceFactory rdfServiceFactory;
private final RDFService rdfService;
private final Dataset dataset;
private final ModelMaker modelMaker;
public ContentDataStructuresProviderTDB(ServletContext ctx,
ServletContextListener ctxListener) {
this.props = ConfigurationProperties.getBean(ctx);
this.ss = StartupStatus.getBean(ctx);
@Validation
public void validate() throws Exception {
if (tdbPath == null) {
throw new IllegalStateException(
"Configuration did not include a TdbDirectory.");
}
}
@Override
public void startup(Application application, ComponentStartupStatus ss) {
configureTDB();
String tdbPath = props.getProperty(PROPERTY_CONTENT_TDB_PATH);
try {
this.rdfService = new RDFServiceTDB(tdbPath);
this.rdfServiceFactory = createRDFServiceFactory();
this.dataset = new RDFServiceDataset(this.rdfService);
this.modelMaker = createModelMaker();
ss.info(ctxListener, "Initialized the RDF source for TDB");
ss.info("Initialized the RDF source for TDB");
} catch (IOException e) {
throw new RuntimeException(
"Failed to set up the RDF source for TDB", e);
@ -113,16 +120,15 @@ public class ContentDataStructuresProviderTDB extends
}
@Override
public void close() {
public String toString() {
return "ContentTripleSourceTDB[" + ToString.hashHex(this) + "]";
}
@Override
public void shutdown(Application application) {
if (this.rdfService != null) {
this.rdfService.close();
}
}
@Override
public String toString() {
return "ContentDataStructuresProviderTDB[" + ToString.hashHex(this)
+ "]";
}
}