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

org.apache.gora.persistency.impl
Class PersistentBase

java.lang.Object
  extended by org.apache.gora.persistency.impl.PersistentBase
All Implemented Interfaces:
Cloneable, org.apache.avro.generic.GenericContainer, org.apache.avro.generic.IndexedRecord, org.apache.avro.specific.SpecificRecord, Persistent
Direct Known Subclasses:
Employee, Metadata, MetricDatum, Pageview, TokenDatum, WebPage

public abstract class PersistentBase
extends Object
implements Persistent

Base classs implementing common functionality for Persistent classes.


Field Summary
protected static PersistentDatumReader<Persistent> datumReader
           
protected static Map<Class<?>,Map<String,Integer>> FIELD_MAP
           
protected static Map<Class<?>,String[]> FIELDS
           
 
Constructor Summary
protected PersistentBase()
           
protected PersistentBase(StateManager stateManager)
           
 
Method Summary
 void clear()
          Clears the inner state of the object without any modification to the actual data on the data store.
 void clearDirty()
          Clears the dirty state.
 void clearDirty(int fieldIndex)
          Clears the field as dirty.
 void clearDirty(String field)
          Clears the field as dirty.
 void clearNew()
          Clears the new state
 void clearReadable()
          Clears the readable state.
 void clearReadable(int fieldIndex)
          Clears the field as readable.
 void clearReadable(String field)
          Sets the field as readable.
 Persistent clone()
           
 boolean equals(Object o)
           
 String getField(int index)
          Returns the field name with the given index
 int getFieldIndex(String field)
          Returns the index of the field with the given name
 String[] getFields()
          Returns sorted field names of the object
 StateManager getStateManager()
          Returns the StateManager which manages the persistent state of the object.
 int hashCode()
           
 boolean isDirty()
          Returns whether any of the fields of the object has been modified after construction or loading.
 boolean isDirty(int fieldIndex)
          Returns whether the field has been modified.
 boolean isDirty(String field)
          Returns whether the field has been modified.
protected  boolean isFieldEqual(int index, Object value)
           
 boolean isNew()
          Returns whether the object is newly constructed.
 boolean isReadable(int fieldIndex)
          Returns whether the field has been loaded from the datastore.
 boolean isReadable(String field)
          Returns whether the field has been loaded from the datastore.
protected static void registerFields(Class<?> clazz, String... fields)
          Subclasses should call this function for all the persistable fields in the class to register them.
 void setDirty()
          Sets all the fields of the object as dirty.
 void setDirty(int fieldIndex)
          Sets the field as dirty.
 void setDirty(String field)
          Sets the field as dirty.
 void setNew()
          Sets the state of the object as new for persistency
 void setReadable(int fieldIndex)
          Sets the field as readable.
 void setReadable(String field)
          Sets the field as readable.
 String toString()
           
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.apache.gora.persistency.Persistent
newInstance
 
Methods inherited from interface org.apache.avro.generic.IndexedRecord
get, put
 
Methods inherited from interface org.apache.avro.generic.GenericContainer
getSchema
 

Field Detail

FIELD_MAP

protected static Map<Class<?>,Map<String,Integer>> FIELD_MAP

FIELDS

protected static Map<Class<?>,String[]> FIELDS

datumReader

protected static final PersistentDatumReader<Persistent> datumReader
Constructor Detail

PersistentBase

protected PersistentBase()

PersistentBase

protected PersistentBase(StateManager stateManager)
Method Detail

registerFields

protected static void registerFields(Class<?> clazz,
                                     String... fields)
Subclasses should call this function for all the persistable fields in the class to register them.

Parameters:
clazz - the Persistent class
fields - the name of the fields of the class

getStateManager

public StateManager getStateManager()
Description copied from interface: Persistent
Returns the StateManager which manages the persistent state of the object.

Specified by:
getStateManager in interface Persistent
Returns:
the StateManager of the object

getFields

public String[] getFields()
Description copied from interface: Persistent
Returns sorted field names of the object

Specified by:
getFields in interface Persistent
Returns:
the field names of the object as a String[]

getField

public String getField(int index)
Description copied from interface: Persistent
Returns the field name with the given index

Specified by:
getField in interface Persistent
Parameters:
index - the index of the field
Returns:
the name of the field

getFieldIndex

public int getFieldIndex(String field)
Description copied from interface: Persistent
Returns the index of the field with the given name

Specified by:
getFieldIndex in interface Persistent
Parameters:
field - the name of the field
Returns:
the index of the field

clear

public void clear()
Description copied from interface: Persistent
Clears the inner state of the object without any modification to the actual data on the data store. This method should be called before re-using the object to hold the data for another result.

Specified by:
clear in interface Persistent

isNew

public boolean isNew()
Description copied from interface: Persistent
Returns whether the object is newly constructed.

Specified by:
isNew in interface Persistent
Returns:
true if the object is newly constructed, false if retrieved from a datastore.

setNew

public void setNew()
Description copied from interface: Persistent
Sets the state of the object as new for persistency

Specified by:
setNew in interface Persistent

clearNew

public void clearNew()
Description copied from interface: Persistent
Clears the new state

Specified by:
clearNew in interface Persistent

isDirty

public boolean isDirty()
Description copied from interface: Persistent
Returns whether any of the fields of the object has been modified after construction or loading.

Specified by:
isDirty in interface Persistent
Returns:
whether any of the fields of the object has changed

isDirty

public boolean isDirty(int fieldIndex)
Description copied from interface: Persistent
Returns whether the field has been modified.

Specified by:
isDirty in interface Persistent
Parameters:
fieldIndex - the offset of the field in the object
Returns:
whether the field has been modified.

isDirty

public boolean isDirty(String field)
Description copied from interface: Persistent
Returns whether the field has been modified.

Specified by:
isDirty in interface Persistent
Parameters:
field - the name of the field
Returns:
whether the field has been modified.

setDirty

public void setDirty()
Description copied from interface: Persistent
Sets all the fields of the object as dirty.

Specified by:
setDirty in interface Persistent

setDirty

public void setDirty(int fieldIndex)
Description copied from interface: Persistent
Sets the field as dirty.

Specified by:
setDirty in interface Persistent
Parameters:
fieldIndex - the offset of the field in the object

setDirty

public void setDirty(String field)
Description copied from interface: Persistent
Sets the field as dirty.

Specified by:
setDirty in interface Persistent
Parameters:
field - the name of the field

clearDirty

public void clearDirty(int fieldIndex)
Description copied from interface: Persistent
Clears the field as dirty.

Specified by:
clearDirty in interface Persistent
Parameters:
fieldIndex - the offset of the field in the object

clearDirty

public void clearDirty(String field)
Description copied from interface: Persistent
Clears the field as dirty.

Specified by:
clearDirty in interface Persistent
Parameters:
field - the name of the field

clearDirty

public void clearDirty()
Description copied from interface: Persistent
Clears the dirty state.

Specified by:
clearDirty in interface Persistent

isReadable

public boolean isReadable(int fieldIndex)
Description copied from interface: Persistent
Returns whether the field has been loaded from the datastore.

Specified by:
isReadable in interface Persistent
Parameters:
fieldIndex - the offset of the field in the object
Returns:
whether the field has been loaded

isReadable

public boolean isReadable(String field)
Description copied from interface: Persistent
Returns whether the field has been loaded from the datastore.

Specified by:
isReadable in interface Persistent
Parameters:
field - the name of the field
Returns:
whether the field has been loaded

setReadable

public void setReadable(int fieldIndex)
Description copied from interface: Persistent
Sets the field as readable.

Specified by:
setReadable in interface Persistent
Parameters:
fieldIndex - the offset of the field in the object

setReadable

public void setReadable(String field)
Description copied from interface: Persistent
Sets the field as readable.

Specified by:
setReadable in interface Persistent
Parameters:
field - the name of the field

clearReadable

public void clearReadable()
Description copied from interface: Persistent
Clears the readable state.

Specified by:
clearReadable in interface Persistent

clearReadable

public void clearReadable(int fieldIndex)
Description copied from interface: Persistent
Clears the field as readable.

Specified by:
clearReadable in interface Persistent
Parameters:
fieldIndex - the offset of the field in the object

clearReadable

public void clearReadable(String field)
Description copied from interface: Persistent
Sets the field as readable.

Specified by:
clearReadable in interface Persistent
Parameters:
field - the name of the field

equals

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

hashCode

public int hashCode()
Overrides:
hashCode in class Object

clone

public Persistent clone()
Specified by:
clone in interface Persistent
Overrides:
clone in class Object

toString

public String toString()
Overrides:
toString in class Object

isFieldEqual

protected boolean isFieldEqual(int index,
                               Object value)


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