org.dasein.persist
Class RelationalHSCache<T extends org.dasein.util.CachedItem>

java.lang.Object
  extended by org.dasein.persist.PersistentCache<T>
      extended by org.dasein.persist.RelationalHSCache<T>
Type Parameters:
T -

public final class RelationalHSCache<T extends org.dasein.util.CachedItem>
extends PersistentCache<T>

A relational AND HandlerSocket cache. Only use this if you are running Percona MySQL!.

TODO:

Author:
morgan

Nested Class Summary
static class RelationalHSCache.OrderedColumn
           
 
Nested classes/interfaces inherited from class org.dasein.persist.PersistentCache
PersistentCache.EntityJoin
 
Field Summary
static org.apache.log4j.Logger logger
           
 
Constructor Summary
RelationalHSCache()
           
 
Method Summary
 long count()
          Counts the total number of objects governed by this factory in the database.
 long count(SearchTerm... terms)
           
 T create(Transaction xaction, Map<String,Object> state)
          Creates the specified object with the data provided in the specified state under the governance of the specified transaction.
 Collection<T> find(SearchTerm[] terms, org.dasein.util.JiteratorFilter<T> filter, Boolean orderDesc, String... orderFields)
           
 T get(Object primaryKeyValue)
          Retrieves the object uniquely identified by the value for the specified ID field.
protected  String getSqlName(Class<?> cls)
           
protected  String getSqlName(String nom)
           
protected  String getSqlNameForClassName(String cname)
           
protected  Map<String,Class<?>> getTypes()
           
 Object getValue(String col, int i, ResultSet rs)
           
 Collection<T> hsFind(String index, AutomatedSql.Operator operator, int limit, int offset, String... indexValues)
          Hits the HandlerSocket index directly, caching objects it finds.
 Collection<T> hsFind(String index, AutomatedSql.Operator operator, String... indexValues)
           
 Collection<T> hsFind(String index, String... indexValues)
           
protected  void init(Class<T> cls, Key... keys)
          Constructs a new persistent factory for objects of the specified class with the named unique identifier attributes as well as with reading the persistence properties file to find out the HandlerSocket host, database, port and pool size.
 Collection<T> list()
          Loads all elements of this class from the data store.
 void remove(Transaction xaction, T item)
          Removes the specified item from the system permanently.
 String toString()
           
 void update(Transaction xaction, T item, Map<String,Object> state)
          Updates the specified object with the data provided in the specified state under the governance of the specified transaction.
 
Methods inherited from class org.dasein.persist.PersistentCache
addJoinEntity, find, getCache, getCache, getJoin, getJoins, getKeyValue, getKeyValue, getKeyValue, getKeyValues, getNewKeyValue, getPrimaryKey, getPrimaryKeyField, getSecondaryKeys, getTarget, initBase, list, matchKeys
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

public static final org.apache.log4j.Logger logger
Constructor Detail

RelationalHSCache

public RelationalHSCache()
Method Detail

init

protected void init(Class<T> cls,
                    Key... keys)
Constructs a new persistent factory for objects of the specified class with the named unique identifier attributes as well as with reading the persistence properties file to find out the HandlerSocket host, database, port and pool size.

Overrides:
init in class PersistentCache<T extends org.dasein.util.CachedItem>
Parameters:
cls - the class of objects managed by this factory
keys - a list of unique identifiers for instances of the specified class

count

public long count()
           throws PersistenceException
Counts the total number of objects governed by this factory in the database.

Overrides:
count in class PersistentCache<T extends org.dasein.util.CachedItem>
Returns:
the number of objects in the database
Throws:
PersistenceException - an error occurred counting the elements in the database

count

public long count(SearchTerm... terms)
           throws PersistenceException
Overrides:
count in class PersistentCache<T extends org.dasein.util.CachedItem>
Throws:
PersistenceException

create

public T create(Transaction xaction,
                Map<String,Object> state)
                                            throws PersistenceException
Creates the specified object with the data provided in the specified state under the governance of the specified transaction.

Specified by:
create in class PersistentCache<T extends org.dasein.util.CachedItem>
Parameters:
xaction - the transaction governing this event
state - the new state for the new object
Throws:
PersistenceException - an error occurred talking to the data store, or creates are not supported

find

public Collection<T> find(SearchTerm[] terms,
                          org.dasein.util.JiteratorFilter<T> filter,
                          Boolean orderDesc,
                          String... orderFields)
                                                      throws PersistenceException
Specified by:
find in class PersistentCache<T extends org.dasein.util.CachedItem>
Throws:
PersistenceException

get

public T get(Object primaryKeyValue)
                                         throws PersistenceException
Retrieves the object uniquely identified by the value for the specified ID field.

Specified by:
get in class PersistentCache<T extends org.dasein.util.CachedItem>
Parameters:
primaryKeyValue - the ID field identifying the object
Returns:
the object matching the query criterion
Throws:
PersistenceException - an error occurred talking to the data store

list

public Collection<T> list()
                                                      throws PersistenceException
Loads all elements of this class from the data store. Use this method only when you know exactly what you are doing. Otherwise, you will pull a lot of data.

Specified by:
list in class PersistentCache<T extends org.dasein.util.CachedItem>
Returns:
all objects from the database
Throws:
PersistenceException - an error occurred executing the query

remove

public void remove(Transaction xaction,
                   T item)
            throws PersistenceException
Removes the specified item from the system permanently.

Specified by:
remove in class PersistentCache<T extends org.dasein.util.CachedItem>
Parameters:
xaction - the transaction under which this event is occurring
item - the item to be removed
Throws:
PersistenceException - an error occurred talking to the data store or removal of these objects is prohibited

toString

public String toString()
Overrides:
toString in class Object

update

public void update(Transaction xaction,
                   T item,
                   Map<String,Object> state)
            throws PersistenceException
Updates the specified object with the data provided in the specified state under the governance of the specified transaction.

Specified by:
update in class PersistentCache<T extends org.dasein.util.CachedItem>
Parameters:
xaction - the transaction governing this event
item - the item to be updated
state - the new state for the updated object
Throws:
PersistenceException - an error occurred talking to the data store, or updates are not supported

hsFind

public Collection<T> hsFind(String index,
                            String... indexValues)
                                                        throws PersistenceException
Throws:
PersistenceException

hsFind

public Collection<T> hsFind(String index,
                            AutomatedSql.Operator operator,
                            String... indexValues)
                                                        throws PersistenceException
Throws:
PersistenceException

hsFind

public Collection<T> hsFind(String index,
                            AutomatedSql.Operator operator,
                            int limit,
                            int offset,
                            String... indexValues)
                                                        throws PersistenceException
Hits the HandlerSocket index directly, caching objects it finds.

Parameters:
index - One of the table's indexes to hit.
operator - What type of comparison the query will make.
limit - The number of results to return.
offset - Where to start to return the results.
indexValues - The values of the index to find values for. MAY NOT BE EMPTY!
Returns:
The found objects.
Throws:
PersistenceException - Thrown if there's an issue.

getSqlNameForClassName

protected String getSqlNameForClassName(String cname)

getSqlName

protected String getSqlName(Class<?> cls)

getSqlName

protected String getSqlName(String nom)

getTypes

protected Map<String,Class<?>> getTypes()

getValue

public Object getValue(String col,
                       int i,
                       ResultSet rs)
                throws SQLException
Throws:
SQLException


Copyright © 2011 enStratus Networks LLC. All Rights Reserved.