public class StaticDataSource extends java.lang.Object implements javax.inject.Provider<DataAccessObject>, Describable
Layout and builder for DAOs backed by static files. This is used to read CSV files and the like; it controls a composite DAO that reads from files, caches them in memory, and can compute some derived entities from others (e.g. extracting items from the item IDs in a rating data set).
Constructor and Description |
---|
StaticDataSource()
Construct a new data layout object.
|
StaticDataSource(java.lang.String name)
Construct a new data layout object.
|
Modifier and Type | Method and Description |
---|---|
void |
addDerivedEntity(EntityDerivation deriv)
Add a derived entity to the data source.
|
void |
addDerivedEntity(EntityType derived,
EntityType source,
TypedName<java.lang.Long> attr)
Add a derived entity to the data source.
|
void |
addIndex(EntityType type,
TypedName<?> attr)
Index entities by an attribute.
|
void |
addSource(java.util.Collection<? extends Entity> data)
Add a collection data source.
|
void |
addSource(java.util.Collection<? extends Entity> data,
java.util.Map<java.lang.String,java.lang.Object> metadata)
Add a collection data source.
|
void |
addSource(EntitySource source)
Add an entity source.
|
static StaticDataSource |
csvRatingFile(java.nio.file.Path file)
Create a static data source from a CSV rating file.
|
void |
describeTo(DescriptionWriter writer)
Write this class’s description to a sink.
|
static StaticDataSource |
fromJSON(com.fasterxml.jackson.databind.JsonNode object,
java.net.URI base)
Parse a JSON description of a data set.
|
static StaticDataSource |
fromJSON(java.lang.String name,
com.fasterxml.jackson.databind.JsonNode object,
java.net.URI base)
Parse a JSON description of a data set.
|
static StaticDataSource |
fromList(java.util.Collection<? extends Entity> entities)
Create a static data source from a list/collection.
|
DataAccessObject |
get()
Get the data access object.
|
java.lang.String |
getName()
Get the name of this source.
|
PreferenceDomain |
getPreferenceDomain() |
java.util.List<EntitySource> |
getSources()
Get the list of entity sources.
|
java.util.List<EntitySource> |
getSourcesForType(EntityType type)
Get the entity sources producing a particular type.
|
static StaticDataSource |
load(java.nio.file.Path path)
Load a static file data set from a file.
|
static StaticDataSource |
load(java.nio.file.Path path,
java.lang.String name)
Load a static file data set from a file.
|
static StaticDataSource |
load(java.net.URI uri,
java.lang.String name)
Load a static file data set from a URI.
|
java.lang.String |
toString() |
public StaticDataSource()
Construct a new data layout object.
public StaticDataSource(java.lang.String name)
Construct a new data layout object.
name
- The name of the data source.public java.lang.String getName()
Get the name of this source.
public void addSource(java.util.Collection<? extends Entity> data)
Add a collection data source.
data
- The entities to add.public void addSource(java.util.Collection<? extends Entity> data, java.util.Map<java.lang.String,java.lang.Object> metadata)
Add a collection data source.
data
- The entities to add.metadata
- The entity source metadata.public void addSource(EntitySource source)
Add an entity source.
source
- The entity source to add.public void addIndex(EntityType type, TypedName<?> attr)
Index entities by an attribute.
type
- The entity type to index.attr
- The attribute to index.public void addDerivedEntity(EntityType derived, EntityType source, TypedName<java.lang.Long> attr)
Add a derived entity to the data source. Derived entities are synthesized from IDs found in attributes of other entities (effectively foreign keys). This allows for things such as extracting the set of users or items from a file of ratings.
The derived entities will not overwrite entities from other sources with the same ID.
derived
- The derived entity type.source
- The type from which to derive it.attr
- The attribute to derive the entity type from.public void addDerivedEntity(EntityDerivation deriv)
Add a derived entity to the data source. Derived entities are synthesized from IDs found in attributes of other entities (effectively foreign keys). This allows for things such as extracting the set of users or items from a file of ratings.
The derived entities will not overwrite entities from other sources with the same ID.
deriv
- The entity derivation.public java.util.List<EntitySource> getSources()
Get the list of entity sources.
@Nonnull public java.util.List<EntitySource> getSourcesForType(EntityType type)
Get the entity sources producing a particular type.
type
- The entity type to look for.type
.public DataAccessObject get()
Get the data access object. This method is thread-safe.
get
in interface javax.inject.Provider<DataAccessObject>
@Nullable public PreferenceDomain getPreferenceDomain()
public java.lang.String toString()
toString
in class java.lang.Object
public void describeTo(DescriptionWriter writer)
Describable
Write this class’s description to a sink. Anything relevant to this object’s identity should be digested; the idea is that, barring hash collisions, two objects with the same digest are equivalent. Used for things like deterministically generating cache file names.
describeTo
in interface Describable
writer
- The description writer to use.public static StaticDataSource fromJSON(com.fasterxml.jackson.databind.JsonNode object, java.net.URI base)
Parse a JSON description of a data set.
object
- The JSON object.public static StaticDataSource fromJSON(java.lang.String name, com.fasterxml.jackson.databind.JsonNode object, java.net.URI base)
Parse a JSON description of a data set.
object
- The JSON object.public static StaticDataSource load(java.nio.file.Path path) throws java.io.IOException
Load a static file data set from a file.
path
- The file to load.java.io.IOException
- If there is an error loading the data source.public static StaticDataSource load(java.nio.file.Path path, java.lang.String name) throws java.io.IOException
Load a static file data set from a file.
path
- The file to load.name
- The source name.java.io.IOException
- If there is an error loading the data source.public static StaticDataSource load(java.net.URI uri, java.lang.String name) throws java.io.IOException
Load a static file data set from a URI.
uri
- The URI to load.name
- The source name.java.io.IOException
- If there is an error loading the data source.public static StaticDataSource csvRatingFile(java.nio.file.Path file)
Create a static data source from a CSV rating file.
file
- The CSV rating file.public static StaticDataSource fromList(java.util.Collection<? extends Entity> entities)
Create a static data source from a list/collection.
entities
- The collection of entities.