Class MongoStore<K,T extends ai.platon.gora.persistency.impl.PersistentBase>

java.lang.Object
ai.platon.gora.store.impl.DataStoreBase<K,T>
ai.platon.gora.mongodb.store.MongoStore<K,T>
Type Parameters:
K - class to be used for the key
T - class to be persisted within the store
All Implemented Interfaces:
ai.platon.gora.store.DataStore<K,T>, Closeable, AutoCloseable, org.apache.hadoop.conf.Configurable, org.apache.hadoop.io.Writable

public class MongoStore<K,T extends ai.platon.gora.persistency.impl.PersistentBase> extends ai.platon.gora.store.impl.DataStoreBase<K,T>
Implementation of a MongoDB data store to be used by gora.
Author:
Fabien Poulard fpoulard@dictanova.com, Damien Raude-Morvan draudemorvan@dictanova.com
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    Default value for mapping file
    static final org.slf4j.Logger
     
    static final String
    Key at DataStore Properties (same as gora.properties) to hold a mapping loaded from memory, instead from filesystem like the one at PARSE_MAPPING_FILE_KEY.

    Fields inherited from class ai.platon.gora.store.impl.DataStoreBase

    autoCreateSchema, beanFactory, conf, datumReader, datumWriter, fieldMap, keyClass, persistentClass, properties, schema
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    Release the resources linked to this collection
    void
    Create a new collection in MongoDB if necessary.
    Ensure Key decoding -> middle dots replaced with dots
    boolean
    delete(K key)
     
    void
    Drop the collection.
    Ensure Key encoding -> dots replaced with middle dots
    ai.platon.gora.query.Result<K,T>
    executeQuery(ai.platon.gora.query.Query<K,T> query)
    Execute the query and return the result.
    boolean
    exists(K key)
     
    void
    Ensure the data is synced to disk.
    get(K key, String[] fields)
    Retrieve an entry from the store with only selected fields.
    static com.mongodb.client.MongoClient
    Retrieve a client connected to the MongoDB server to be used.
     
    List<ai.platon.gora.query.PartitionQuery<K,T>>
    getPartitions(ai.platon.gora.query.Query<K,T> query)
    Partitions the given query and returns a list of PartitionQuerys, which will execute on local data.
    Accessor to the name of the collection used.
    getSchemaName(String mappingSchemaName, Class<?> persistentClass)
     
    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.
    newInstance(org.bson.Document obj, String[] fields)
    Build a new instance of the persisted class from the Document retrieved from the database.
    ai.platon.gora.query.Query<K,T>
    Create a new Query to query the datastore.
    void
    put(K key, T obj)
    Persist an object into the store.
    boolean
    Check if the collection already exists or should be created.

    Methods inherited from class ai.platon.gora.store.impl.DataStoreBase

    equals, get, getBeanFactory, getConf, getFields, getFieldsToQuery, getKeyClass, getOrCreateConf, getPersistentClass, newKey, newPersistent, readFields, setBeanFactory, setConf, setKeyClass, setPersistentClass, truncateSchema, write

    Methods inherited from class java.lang.Object

    clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

    • LOG

      public static final org.slf4j.Logger LOG
    • DEFAULT_MAPPING_FILE

      public static final String DEFAULT_MAPPING_FILE
      Default value for mapping file
      See Also:
    • XML_MAPPING_DEFINITION

      public static final String XML_MAPPING_DEFINITION
      Key at DataStore Properties (same as gora.properties) to hold a mapping loaded from memory, instead from filesystem like the one at PARSE_MAPPING_FILE_KEY. If this key is present, the mapping is loaded from the value instead of gora-mongodb-mapping.xml
      See Also:
  • Constructor Details

    • MongoStore

      public MongoStore()
  • Method Details

    • initialize

      public void initialize(Class<K> keyClass, Class<T> pPersistentClass, Properties properties) throws ai.platon.gora.util.GoraException
      Initialize the data store by reading the credentials, setting the client's properties up and reading the mapping file.
      Specified by:
      initialize in interface ai.platon.gora.store.DataStore<K,T extends ai.platon.gora.persistency.impl.PersistentBase>
      Overrides:
      initialize in class ai.platon.gora.store.impl.DataStoreBase<K,T extends ai.platon.gora.persistency.impl.PersistentBase>
      Throws:
      ai.platon.gora.util.GoraException
    • getClient

      public static com.mongodb.client.MongoClient getClient(MongoStoreParameters params)
      Retrieve a client connected to the MongoDB server to be used.
      Parameters:
      params - This value should specify the host:port (at least one) for connecting to remote MongoDB.
      Returns:
      a MongoClient instance connected to the server
    • getMapping

      public MongoMapping getMapping()
    • getSchemaName

      public String getSchemaName()
      Accessor to the name of the collection used.
    • getSchemaName

      public String getSchemaName(String mappingSchemaName, Class<?> persistentClass)
      Overrides:
      getSchemaName in class ai.platon.gora.store.impl.DataStoreBase<K,T extends ai.platon.gora.persistency.impl.PersistentBase>
    • createSchema

      public void createSchema() throws ai.platon.gora.util.GoraException
      Create a new collection in MongoDB if necessary.
      Throws:
      ai.platon.gora.util.GoraException
    • deleteSchema

      public void deleteSchema() throws ai.platon.gora.util.GoraException
      Drop the collection.
      Throws:
      ai.platon.gora.util.GoraException
    • schemaExists

      public boolean schemaExists() throws ai.platon.gora.util.GoraException
      Check if the collection already exists or should be created.
      Throws:
      ai.platon.gora.util.GoraException
    • flush

      public void flush() throws ai.platon.gora.util.GoraException
      Ensure the data is synced to disk.
      Throws:
      ai.platon.gora.util.GoraException
    • close

      public void close()
      Release the resources linked to this collection
    • get

      public T get(K key, String[] fields) throws ai.platon.gora.util.GoraException
      Retrieve an entry from the store with only selected fields.
      Parameters:
      key - identifier of the document in the database
      fields - list of fields to be loaded from the database
      Throws:
      ai.platon.gora.util.GoraException
    • exists

      public boolean exists(K key) throws ai.platon.gora.util.GoraException
      Throws:
      ai.platon.gora.util.GoraException
    • put

      public void put(K key, T obj) throws ai.platon.gora.util.GoraException
      Persist an object into the store.
      Parameters:
      key - identifier of the object in the store
      obj - the object to be inserted
      Throws:
      ai.platon.gora.util.GoraException
    • delete

      public boolean delete(K key) throws ai.platon.gora.util.GoraException
      Throws:
      ai.platon.gora.util.GoraException
    • executeQuery

      public ai.platon.gora.query.Result<K,T> executeQuery(ai.platon.gora.query.Query<K,T> query) throws IOException
      Execute the query and return the result.
      Specified by:
      executeQuery in class ai.platon.gora.store.impl.DataStoreBase<K,T extends ai.platon.gora.persistency.impl.PersistentBase>
      Throws:
      IOException
    • newQuery

      public ai.platon.gora.query.Query<K,T> newQuery()
      Create a new Query to query the datastore.
      Specified by:
      newQuery in class ai.platon.gora.store.impl.DataStoreBase<K,T extends ai.platon.gora.persistency.impl.PersistentBase>
    • getPartitions

      public List<ai.platon.gora.query.PartitionQuery<K,T>> getPartitions(ai.platon.gora.query.Query<K,T> query) throws IOException
      Partitions the given query and returns a list of PartitionQuerys, which will execute on local data.
      Throws:
      IOException
    • newInstance

      public T newInstance(org.bson.Document obj, String[] fields) throws ai.platon.gora.util.GoraException
      Build a new instance of the persisted class from the Document retrieved from the database.
      Parameters:
      obj - the Document that results from the query to the database
      fields - the list of fields to be mapped to the persistence class instance
      Returns:
      a persistence class instance which content was deserialized from the Document
      Throws:
      ai.platon.gora.util.GoraException
    • encodeFieldKey

      public String encodeFieldKey(String key)
      Ensure Key encoding -> dots replaced with middle dots
      Parameters:
      key - char with only dots.
      Returns:
      encoded string with "·" chars..
    • decodeFieldKey

      public String decodeFieldKey(String key)
      Ensure Key decoding -> middle dots replaced with dots
      Parameters:
      key - encoded string with "·" chars.
      Returns:
      Cleanup up char with only dots.