This project has retired. For details please refer to its Attic page.
DataStoreBase (Apache Gora 0.2 API)

org.apache.gora.store.impl
Class DataStoreBase<K,T extends Persistent>

java.lang.Object
  extended by org.apache.gora.store.impl.DataStoreBase<K,T>
All Implemented Interfaces:
Closeable, DataStore<K,T>, org.apache.hadoop.conf.Configurable, org.apache.hadoop.io.Writable
Direct Known Subclasses:
AccumuloStore, CassandraStore, FileBackedDataStoreBase, HBaseStore, MemStore, SqlStore

public abstract class DataStoreBase<K,T extends Persistent>
extends Object
implements DataStore<K,T>

A Base class for DataStores.


Field Summary
protected  boolean autoCreateSchema
           
protected  BeanFactory<K,T> beanFactory
           
protected  org.apache.hadoop.conf.Configuration conf
           
protected  PersistentDatumReader<T> datumReader
           
protected  PersistentDatumWriter<T> datumWriter
           
protected  Map<String,org.apache.avro.Schema.Field> fieldMap
          A map of field names to Field objects containing schema's fields
protected  Class<K> keyClass
           
protected  Class<T> persistentClass
           
protected  Properties properties
           
protected  org.apache.avro.Schema schema
          The schema of the persistent class
 
Constructor Summary
DataStoreBase()
           
 
Method Summary
 boolean equals(Object obj)
           
 T get(K key)
          Returns the object corresponding to the given key fetching all the fields.
 BeanFactory<K,T> getBeanFactory()
          Returns the BeanFactory used by the DataStore
 org.apache.hadoop.conf.Configuration getConf()
           
protected  String[] getFieldsToQuery(String[] fields)
          Checks whether the fields argument is null, and if so returns all the fields of the Persistent object, else returns the argument.
 Class<K> getKeyClass()
          Returns the class of the keys
protected  org.apache.hadoop.conf.Configuration getOrCreateConf()
           
 Class<T> getPersistentClass()
          Returns the class of the persistent objects
protected  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> persistentClass, Properties properties)
          Initializes this DataStore.
 K newKey()
          Returns a new instance of the key object.
 T newPersistent()
          Returns a new instance of the managed persistent object.
 void readFields(DataInput in)
           
 void setBeanFactory(BeanFactory<K,T> beanFactory)
          Sets the BeanFactory to use by the DataStore.
 void setConf(org.apache.hadoop.conf.Configuration conf)
           
 void setKeyClass(Class<K> keyClass)
          Sets the class of the keys
 void setPersistentClass(Class<T> persistentClass)
          Sets the class of the persistent objects
 void truncateSchema()
          Deletes all the data associated with the schema, but keeps the schema (table or similar) intact.
 void write(DataOutput out)
           
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.apache.gora.store.DataStore
close, createSchema, delete, deleteByQuery, deleteSchema, execute, flush, get, getPartitions, getSchemaName, newQuery, put, schemaExists
 

Field Detail

beanFactory

protected BeanFactory<K,T extends Persistent> beanFactory

keyClass

protected Class<K> keyClass

persistentClass

protected Class<T extends Persistent> persistentClass

schema

protected org.apache.avro.Schema schema
The schema of the persistent class


fieldMap

protected Map<String,org.apache.avro.Schema.Field> fieldMap
A map of field names to Field objects containing schema's fields


conf

protected org.apache.hadoop.conf.Configuration conf

autoCreateSchema

protected boolean autoCreateSchema

properties

protected Properties properties

datumReader

protected PersistentDatumReader<T extends Persistent> datumReader

datumWriter

protected PersistentDatumWriter<T extends Persistent> datumWriter
Constructor Detail

DataStoreBase

public DataStoreBase()
Method Detail

initialize

public void initialize(Class<K> keyClass,
                       Class<T> persistentClass,
                       Properties properties)
                throws IOException
Description copied from interface: DataStore
Initializes this DataStore.

Specified by:
initialize in interface DataStore<K,T extends Persistent>
Parameters:
keyClass - the class of the keys
persistentClass - the class of the persistent objects
properties - extra metadata
Throws:
IOException

setPersistentClass

public void setPersistentClass(Class<T> persistentClass)
Description copied from interface: DataStore
Sets the class of the persistent objects

Specified by:
setPersistentClass in interface DataStore<K,T extends Persistent>
Parameters:
persistentClass - class of persistent objects

getPersistentClass

public Class<T> getPersistentClass()
Description copied from interface: DataStore
Returns the class of the persistent objects

Specified by:
getPersistentClass in interface DataStore<K,T extends Persistent>
Returns:
class of the persistent objects

getKeyClass

public Class<K> getKeyClass()
Description copied from interface: DataStore
Returns the class of the keys

Specified by:
getKeyClass in interface DataStore<K,T extends Persistent>
Returns:
class of the keys

setKeyClass

public void setKeyClass(Class<K> keyClass)
Description copied from interface: DataStore
Sets the class of the keys

Specified by:
setKeyClass in interface DataStore<K,T extends Persistent>
Parameters:
keyClass - the class of keys

newKey

public K newKey()
         throws IOException
Description copied from interface: DataStore
Returns a new instance of the key object. If the object cannot be instantiated (it the class is a Java primitive wrapper, or does not have no-arg constructor) it throws an exception. Only use this function if you can make sure that the key class has a no-arg constructor.

Specified by:
newKey in interface DataStore<K,T extends Persistent>
Returns:
a new instance of the key object.
Throws:
IOException

newPersistent

public T newPersistent()
                                   throws IOException
Description copied from interface: DataStore
Returns a new instance of the managed persistent object.

Specified by:
newPersistent in interface DataStore<K,T extends Persistent>
Returns:
a new instance of the managed persistent object.
Throws:
IOException

setBeanFactory

public void setBeanFactory(BeanFactory<K,T> beanFactory)
Description copied from interface: DataStore
Sets the BeanFactory to use by the DataStore.

Specified by:
setBeanFactory in interface DataStore<K,T extends Persistent>
Parameters:
beanFactory - the BeanFactory to use

getBeanFactory

public BeanFactory<K,T> getBeanFactory()
Description copied from interface: DataStore
Returns the BeanFactory used by the DataStore

Specified by:
getBeanFactory in interface DataStore<K,T extends Persistent>
Returns:
the BeanFactory used by the DataStore

get

public T get(K key)
                         throws IOException
Description copied from interface: DataStore
Returns the object corresponding to the given key fetching all the fields.

Specified by:
get in interface DataStore<K,T extends Persistent>
Parameters:
key - the key of the object
Returns:
the Object corresponding to the key or null if it cannot be found
Throws:
IOException

getFieldsToQuery

protected String[] getFieldsToQuery(String[] fields)
Checks whether the fields argument is null, and if so returns all the fields of the Persistent object, else returns the argument.


getConf

public org.apache.hadoop.conf.Configuration getConf()
Specified by:
getConf in interface DataStore<K,T extends Persistent>
Specified by:
getConf in interface org.apache.hadoop.conf.Configurable

setConf

public void setConf(org.apache.hadoop.conf.Configuration conf)
Specified by:
setConf in interface DataStore<K,T extends Persistent>
Specified by:
setConf in interface org.apache.hadoop.conf.Configurable

getOrCreateConf

protected org.apache.hadoop.conf.Configuration getOrCreateConf()

readFields

public void readFields(DataInput in)
                throws IOException
Specified by:
readFields in interface DataStore<K,T extends Persistent>
Specified by:
readFields in interface org.apache.hadoop.io.Writable
Throws:
IOException

write

public void write(DataOutput out)
           throws IOException
Specified by:
write in interface DataStore<K,T extends Persistent>
Specified by:
write in interface org.apache.hadoop.io.Writable
Throws:
IOException

equals

public boolean equals(Object obj)
Overrides:
equals in class Object

truncateSchema

public void truncateSchema()
                    throws IOException
Description copied from interface: DataStore
Deletes all the data associated with the schema, but keeps the schema (table or similar) intact.

Specified by:
truncateSchema in interface DataStore<K,T extends Persistent>
Throws:
IOException

getSchemaName

protected String getSchemaName(String mappingSchemaName,
                               Class<?> persistentClass)
Returns the name of the schema to use for the persistent class. First 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.

Parameters:
mappingSchemaName - the name of the schema as read from the mapping file
persistentClass - persistent class


Copyright © 2010-2013 The Apache Software Foundation. All Rights Reserved.