K
- class to be used for the keyT
- class to be persisted within the storepublic class MongoStore<K,T extends PersistentBase> extends DataStoreBase<K,T>
Modifier and Type | Field and Description |
---|---|
static String |
DEFAULT_MAPPING_FILE
Default value for mapping file
|
static org.slf4j.Logger |
LOG |
static String |
PROP_MAPPING_FILE
Property pointing to the file for the mapping
|
static String |
PROP_MONGO_DB
Property to select the database
|
static String |
PROP_MONGO_LOGIN
Property pointing to the username to connect to the server
|
static String |
PROP_MONGO_SECRET
Property pointing to the secret to connect to the server
|
static String |
PROP_MONGO_SERVERS
Property pointing to the host where the server is running
|
static String |
PROP_OVERRIDING
Property indicating if the hadoop configuration has priority or not
|
autoCreateSchema, beanFactory, conf, datumReader, datumWriter, fieldMap, keyClass, persistentClass, properties, schema
Constructor and Description |
---|
MongoStore() |
Modifier and Type | Method and Description |
---|---|
void |
close()
Release the resources linked to this collection
|
void |
createSchema()
Create a new collection in MongoDB if necessary.
|
String |
decodeFieldKey(String key)
Ensure Key decoding -> middle dots replaced with dots
|
boolean |
delete(K key)
Deletes the object with the given key
|
long |
deleteByQuery(Query<K,T> query)
Deletes all the objects matching the query.
|
void |
deleteSchema()
Drop the collection.
|
String |
encodeFieldKey(String key)
Ensure Key encoding -> dots replaced with middle dots
|
Result<K,T> |
execute(Query<K,T> query)
Execute the query and return the result.
|
void |
flush()
Ensure the data is synced to disk.
|
T |
get(K key,
String[] fields)
Retrieve an entry from the store with only selected fields.
|
MongoMapping |
getMapping() |
List<PartitionQuery<K,T>> |
getPartitions(Query<K,T> query)
Partitions the given query and returns a list of PartitionQuerys, which
will execute on local data.
|
String |
getSchemaName()
Accessor to the name of the collection used.
|
String |
getSchemaName(String mappingSchemaName,
Class<?> persistentClass)
Returns the name of the schema to use for the persistent class.
|
void |
initialize(Class<K> keyClass,
Class<T> pPersistentClass,
Properties properties)
Initialize the data store by reading the credentials, setting the client's
properties up and reading the mapping file.
|
T |
newInstance(com.mongodb.DBObject obj,
String[] fields)
Build a new instance of the persisted class from the
DBObject
retrieved from the database. |
Query<K,T> |
newQuery()
Create a new
Query to query the datastore. |
void |
put(K key,
T obj)
Persist an object into the store.
|
boolean |
schemaExists()
Check if the collection already exists or should be created.
|
equals, get, getBeanFactory, getConf, getFields, getFieldsToQuery, getKeyClass, getOrCreateConf, getPersistentClass, newKey, newPersistent, readFields, setBeanFactory, setConf, setKeyClass, setPersistentClass, truncateSchema, write
public static final org.slf4j.Logger LOG
public static final String PROP_OVERRIDING
public static final String PROP_MAPPING_FILE
public static final String PROP_MONGO_SERVERS
public static final String PROP_MONGO_LOGIN
public static final String PROP_MONGO_SECRET
public static final String DEFAULT_MAPPING_FILE
public static String PROP_MONGO_DB
public void initialize(Class<K> keyClass, Class<T> pPersistentClass, Properties properties)
initialize
in interface DataStore<K,T extends PersistentBase>
initialize
in class DataStoreBase<K,T extends PersistentBase>
keyClass
- the class of the keyspPersistentClass
- the class of the persistent objectsproperties
- extra metadatapublic MongoMapping getMapping()
public String getSchemaName()
public String getSchemaName(String mappingSchemaName, Class<?> persistentClass)
DataStoreBase
Configuration
is used. If null,
the schema name in the defined properties is returned. If null then
the provided mappingSchemaName is returned. If this is null too,
the class name, without the package, of the persistent class is returned.getSchemaName
in class DataStoreBase<K,T extends PersistentBase>
mappingSchemaName
- the name of the schema as read from the mapping filepersistentClass
- persistent classpublic void createSchema()
public void deleteSchema()
public boolean schemaExists()
public void flush()
public void close()
public T get(K key, String[] fields)
key
- identifier of the document in the databasefields
- list of fields to be loaded from the databaseIOException
public void put(K key, T obj)
key
- identifier of the object in the storeobj
- the object to be insertedpublic boolean delete(K key)
DataStore
key
- the key of the objectpublic long deleteByQuery(Query<K,T> query)
DataStore
query
- matching records to this query will be deletedpublic Result<K,T> execute(Query<K,T> query)
query
- the query to execute.Result
object.public Query<K,T> newQuery()
Query
to query the datastore.public List<PartitionQuery<K,T>> getPartitions(Query<K,T> query) throws IOException
query
- the base query to create the partitions for. If the query
is null, then the data store returns the partitions for the default query
(returning every object)IOException
public T newInstance(com.mongodb.DBObject obj, String[] fields)
DBObject
retrieved from the database.obj
- the DBObject
that results from the query to the databasefields
- the list of fields to be mapped to the persistence class instanceDBObject
IOException
public String encodeFieldKey(String key)
key
- char with only dots.Copyright © 2010-2015 The Apache Software Foundation. All Rights Reserved.