com.spoledge.audao.db.dao.gae
Class GaeAbstractDaoImpl<T>

java.lang.Object
  extended by com.spoledge.audao.db.dao.RootDaoImpl
      extended by com.spoledge.audao.db.dao.gae.GaeAbstractDaoImpl<T>

public abstract class GaeAbstractDaoImpl<T>
extends RootDaoImpl

This is the parent of all DAO implementation classes. It uses all common generic methods and utilities. The implementation is not thread safe - we assume that the client creates one DAO impl per thread.


Field Summary
protected  DatastoreService ds
          The assigned datastore service.
protected static DtoCache<Key,Entity> entityCache
          Caching of entities - a short term cache allowing to optimize the calls find + update.
protected  GQLDynamicQuery gqlDynamicQuery
          GQLDynamicQuery is used to preocess dynamic queries and static queries containing "!=" or "IN" operators.
protected  int iteratorCount
           
protected  boolean multipleQueries
          Flag indicating that "!=" or "IN" operators are used in conditions.
protected  Transaction tx
          The last known transaction.
protected  DtoCache<Key,Entity> txEntityCache
          Caching of entities - a short term cache allowing to optimize the calls find + update.
 
Fields inherited from class com.spoledge.audao.db.dao.RootDaoImpl
log
 
Constructor Summary
protected GaeAbstractDaoImpl(DatastoreService ds)
          Creates a new DAO implementation.
 
Method Summary
protected  Blob blob(byte[] val)
           
protected  Blob blob(java.lang.Object val)
           
protected  java.util.List<Blob> blobs(java.util.List list)
           
static void clearEntityCache()
          Clears entity cache.
protected  int count(Query query, java.lang.String cond, java.lang.Object... params)
          Counts records by filled query.
protected  java.util.Date date(java.sql.Date val)
          This method crops time to emulate same behavior as JDBC drivers.
protected  java.util.Date date(int year, int month, int day)
           
protected  java.util.Date date(java.sql.Timestamp val)
           
protected  java.util.List<java.util.Date> datesOfDate(java.util.List<? extends java.sql.Date> list)
           
protected  java.util.List<java.util.Date> datesOfTimestamp(java.util.List<? extends java.sql.Timestamp> list)
           
protected  java.util.Date datetime(int year, int month, int day, int hour, int min, int sec)
           
protected  int deleteMany(Query query, java.lang.String cond, int offset, int count, java.lang.Object... params)
          Deletes records by filled query.
protected  boolean deleteOne(Query query, java.lang.String cond, int offset, int count, java.lang.Object... params)
          Deletes a record by filled query.
protected  void entityDelete(java.lang.Iterable<Key> keys)
          Removes entities from datastore.
protected  boolean entityDelete(Key key)
          Removes entity from datastore.
protected  Entity entityGet(Key key)
          Reads entity from datastore by its key.
protected  Key entityPut(Entity ent, java.lang.Object dto, java.lang.String operation)
          Writes entity to datastore.
protected  java.util.List<Key> entityPut(java.lang.Iterable<Entity> ents, java.lang.Iterable<?> dtos, java.lang.String operation)
          Writes several entities to datastore.
protected  T fetch(Entity ent)
          Fetches data from generic entity into typesafe DTO.
protected abstract  T fetch(T dto, Entity ent)
          Fetches data from generic entity into typesafe DTO.
protected  T[] fetchArray(java.util.Iterator<Entity> iterator)
          Fetches data from generic entities into typesafe DTOs.
protected  java.util.ArrayList<T> fetchList(java.util.Iterator<Entity> iterator)
          Fetches data from generic entities into typesafe DTOs.
protected  T[] findManyArray(Query query, java.lang.String cond, int offset, int count, java.lang.Object... params)
           
protected  java.util.ArrayList<T> findManyImpl(Query query, java.lang.String cond, int offset, int count, java.lang.Object[] params)
          Finds more than one record by filled query.
protected  java.util.ArrayList<T> findManyList(Query query, java.lang.String cond, int offset, int count, java.lang.Object... params)
           
protected  T findOne(Query query, java.lang.String cond, int offset, java.lang.Object... params)
          Finds one record by filled query.
protected  GeoPt geopt(java.lang.Number latitude, java.lang.Number longitude)
           
protected  java.lang.Boolean getBoolean(Entity ent, java.lang.String prop)
           
protected  byte[] getByteArray(Entity ent, java.lang.String prop)
           
protected
<S> S
getCoreObject(Entity ent, java.lang.String prop, java.lang.Class<S> clazz)
           
protected  java.sql.Date getDate(Entity ent, java.lang.String prop)
           
protected  java.lang.Double getDouble(Entity ent, java.lang.String prop)
           
protected  DtoCache<Key,Entity> getEntityCache()
           
protected  FetchOptions getFetchOptions(int offset, int count)
           
protected  GQLDynamicQuery getGQLDynamicQuery()
           
protected  java.lang.Integer getInteger(Entity ent, java.lang.String prop)
           
protected
<S> java.util.List<S>
getList(Entity ent, java.lang.String prop)
          Returns native list - as fetched by GAE API.
protected
<S> java.util.List<S>
getList(Entity ent, java.lang.String prop, java.lang.Class<S> clazz)
          Returns native list - as fetched by GAE API.
protected
<S> java.util.List<S>
getListOfObjects(Entity ent, java.lang.String prop)
          Returns list of deserialized object.
protected
<S> java.util.List<S>
getListOfObjects(Entity ent, java.lang.String prop, java.lang.Class<S> clazz)
          Returns list of deserialized object.
protected  java.lang.Long getLong(Entity ent, java.lang.String prop)
           
protected
<S> S
getObject(Entity ent, java.lang.String prop, java.lang.Class<S> clazz)
           
protected  Query getQuery()
           
protected  Query getQueryCond(Query q, java.lang.String cond, java.lang.Object... params)
           
protected  Query getQueryCond(java.lang.String cond, java.lang.Object... params)
           
protected  java.lang.Short getShort(Entity ent, java.lang.String prop)
           
protected  java.lang.String getString(Entity ent, java.lang.String prop)
           
protected  java.sql.Timestamp getTimestamp(Entity ent, java.lang.String prop)
           
protected  void handleException(java.lang.Exception e)
           
protected  void invalidType(Entity ent, java.lang.String prop, java.lang.Class<?> expected)
           
protected  boolean isLimit(int count)
           
protected  Key key(Key parent, java.lang.String kind, long id)
           
protected  Key key(Key parent, java.lang.String kind, java.lang.String name)
           
protected  Key key(long id)
           
protected  Key key(java.lang.String name)
           
protected  Key key(java.lang.String kind, long id)
           
protected  Key key(java.lang.String kind, java.lang.String name)
           
protected  java.lang.Iterable<Key> keyIterable(java.lang.Iterable<Entity> ie)
           
protected  java.util.Iterator<Key> keyIterator(java.util.Iterator<Entity> ie)
           
protected  java.util.List<java.lang.String> names(java.util.List<? extends java.lang.Enum> list)
           
protected  java.util.List<java.lang.Integer> ordinals(java.util.List<? extends java.lang.Enum> list)
           
protected  Key parentKey(Key key)
           
protected  Key parentKey(Key key, int depth)
           
protected  java.lang.Long parentKeyAsLong(Key key, int depth)
           
protected  java.lang.String parentKeyAsString(Key key, int depth)
           
protected  PreparedQuery prepare(Query query)
          Prepares query.
protected  PreparedQuery prepare(Query query, boolean keysOnly)
          Prepares query.
protected  ShortBlob shortBlob(byte[] val)
           
protected  ShortBlob shortBlob(java.lang.Object val)
           
protected  java.util.List<ShortBlob> shortBlobs(java.util.List list)
           
protected  java.util.List<ShortBlob> shortBlobsOfByteArray(java.util.List<byte[]> list)
           
protected  java.util.Date time(int hour, int min, int sec)
           
protected abstract  T[] toArray(java.util.ArrayList<T> list)
          Converts list to array.
protected  User user(java.lang.String email)
           
 
Methods inherited from class com.spoledge.audao.db.dao.RootDaoImpl
checkLength, checkLength, checkLength, checkMaxLength, checkMaxLength, checkMaxLength, checkNull, debugSql, debugSql, debugSql, deserialize, dtoKey, errorSql, errorSql, errorSql, getTableName, pageOffset, serialize, sqlLog
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

entityCache

protected static DtoCache<Key,Entity> entityCache
Caching of entities - a short term cache allowing to optimize the calls find + update.


txEntityCache

protected DtoCache<Key,Entity> txEntityCache
Caching of entities - a short term cache allowing to optimize the calls find + update.


tx

protected Transaction tx
The last known transaction.


ds

protected DatastoreService ds
The assigned datastore service.


multipleQueries

protected boolean multipleQueries
Flag indicating that "!=" or "IN" operators are used in conditions. THe query must be processed by GQLDynamicQuery.


gqlDynamicQuery

protected GQLDynamicQuery gqlDynamicQuery
GQLDynamicQuery is used to preocess dynamic queries and static queries containing "!=" or "IN" operators.


iteratorCount

protected int iteratorCount
Constructor Detail

GaeAbstractDaoImpl

protected GaeAbstractDaoImpl(DatastoreService ds)
Creates a new DAO implementation.

Throws:
java.lang.NullPointerException - when the passed DS is null.
Method Detail

clearEntityCache

public static void clearEntityCache()
Clears entity cache. This method is useful when testing.


findOne

protected T findOne(Query query,
                    java.lang.String cond,
                    int offset,
                    java.lang.Object... params)
Finds one record by filled query.

Parameters:
query - the query ready for execution
cond - the SQL/GQL condition used only for logging
offset - the offset of the result set starting at 0
params - the parameters used only for logging
Returns:
the record found or null

findManyArray

protected T[] findManyArray(Query query,
                            java.lang.String cond,
                            int offset,
                            int count,
                            java.lang.Object... params)

findManyList

protected java.util.ArrayList<T> findManyList(Query query,
                                              java.lang.String cond,
                                              int offset,
                                              int count,
                                              java.lang.Object... params)

findManyImpl

protected java.util.ArrayList<T> findManyImpl(Query query,
                                              java.lang.String cond,
                                              int offset,
                                              int count,
                                              java.lang.Object[] params)
Finds more than one record by filled query.

Parameters:
query - the query ready for execution
cond - the SQL/GQL condition used only for logging
offset - the offset of the result set starting at 0
count - the max number of returned records; -1 or Integer.MAX_VALUE mean no limit
params - the parameters used only for logging
Returns:
the result list (even empty)

count

protected int count(Query query,
                    java.lang.String cond,
                    java.lang.Object... params)
Counts records by filled query.

Parameters:
query - the query ready for execution
cond - the SQL/GQL condition used only for logging
params - the parameters used only for logging
Returns:
the number of records found

deleteOne

protected boolean deleteOne(Query query,
                            java.lang.String cond,
                            int offset,
                            int count,
                            java.lang.Object... params)
                     throws DaoException
Deletes a record by filled query.

Parameters:
query - the query ready for execution
cond - the SQL/GQL condition used only for logging
offset - the offset of the result set starting at 0
count - the max number of deleted records; -1 or Integer.MAX_VALUE mean no limit
params - the parameters used only for logging
Returns:
true if the record was really deleted
Throws:
DaoException - when more than one record was deleted

deleteMany

protected int deleteMany(Query query,
                         java.lang.String cond,
                         int offset,
                         int count,
                         java.lang.Object... params)
                  throws DaoException
Deletes records by filled query.

Parameters:
query - the query ready for execution
cond - the SQL/GQL condition used only for logging
offset - the offset of the result set starting at 0
count - the max number of deleted records; -1 or Integer.MAX_VALUE mean no limit
params - the parameters used only for logging
Returns:
the number of deleted records
Throws:
DaoException

fetch

protected T fetch(Entity ent)
Fetches data from generic entity into typesafe DTO.

Parameters:
ent - the source generic entity
Returns:
the typesafe DTO

fetch

protected abstract T fetch(T dto,
                           Entity ent)
Fetches data from generic entity into typesafe DTO.

Parameters:
dto - the typesafe DTO which is filled and returned; can be null
ent - the source generic entity
Returns:
the typesafe DTO

fetchArray

protected T[] fetchArray(java.util.Iterator<Entity> iterator)
Fetches data from generic entities into typesafe DTOs.


fetchList

protected java.util.ArrayList<T> fetchList(java.util.Iterator<Entity> iterator)
Fetches data from generic entities into typesafe DTOs.


toArray

protected abstract T[] toArray(java.util.ArrayList<T> list)
Converts list to array.


entityGet

protected Entity entityGet(Key key)
Reads entity from datastore by its key.


entityPut

protected Key entityPut(Entity ent,
                        java.lang.Object dto,
                        java.lang.String operation)
                 throws DaoException
Writes entity to datastore.

Parameters:
ent - the entity to be written
dto - the dto used only for logging; also can be a simple parameter
operation - the operation (insert/update) used only for logging
Throws:
DaoException

entityPut

protected java.util.List<Key> entityPut(java.lang.Iterable<Entity> ents,
                                        java.lang.Iterable<?> dtos,
                                        java.lang.String operation)
                                 throws DaoException
Writes several entities to datastore.

Parameters:
ents - the entities to be written
dtos - the dtos used only for logging
operation - the operation (insert/update) used only for logging
Throws:
DaoException

entityDelete

protected boolean entityDelete(Key key)
                        throws DaoException
Removes entity from datastore.

Returns:
true if the entity was really deleted
Throws:
DaoException

entityDelete

protected void entityDelete(java.lang.Iterable<Key> keys)
                     throws DaoException
Removes entities from datastore.

Throws:
DaoException

prepare

protected PreparedQuery prepare(Query query)
Prepares query.


prepare

protected PreparedQuery prepare(Query query,
                                boolean keysOnly)
Prepares query.


getBoolean

protected java.lang.Boolean getBoolean(Entity ent,
                                       java.lang.String prop)

getShort

protected java.lang.Short getShort(Entity ent,
                                   java.lang.String prop)

getInteger

protected java.lang.Integer getInteger(Entity ent,
                                       java.lang.String prop)

getLong

protected java.lang.Long getLong(Entity ent,
                                 java.lang.String prop)

getDouble

protected java.lang.Double getDouble(Entity ent,
                                     java.lang.String prop)

getString

protected java.lang.String getString(Entity ent,
                                     java.lang.String prop)

getDate

protected java.sql.Date getDate(Entity ent,
                                java.lang.String prop)

getTimestamp

protected java.sql.Timestamp getTimestamp(Entity ent,
                                          java.lang.String prop)

getByteArray

protected byte[] getByteArray(Entity ent,
                              java.lang.String prop)

getObject

protected <S> S getObject(Entity ent,
                          java.lang.String prop,
                          java.lang.Class<S> clazz)

getCoreObject

protected <S> S getCoreObject(Entity ent,
                              java.lang.String prop,
                              java.lang.Class<S> clazz)

getList

protected <S> java.util.List<S> getList(Entity ent,
                                        java.lang.String prop)
Returns native list - as fetched by GAE API.


getList

protected <S> java.util.List<S> getList(Entity ent,
                                        java.lang.String prop,
                                        java.lang.Class<S> clazz)
Returns native list - as fetched by GAE API.


getListOfObjects

protected <S> java.util.List<S> getListOfObjects(Entity ent,
                                                 java.lang.String prop)
Returns list of deserialized object.


getListOfObjects

protected <S> java.util.List<S> getListOfObjects(Entity ent,
                                                 java.lang.String prop,
                                                 java.lang.Class<S> clazz)
Returns list of deserialized object.


invalidType

protected void invalidType(Entity ent,
                           java.lang.String prop,
                           java.lang.Class<?> expected)

date

protected java.util.Date date(int year,
                              int month,
                              int day)

datetime

protected java.util.Date datetime(int year,
                                  int month,
                                  int day,
                                  int hour,
                                  int min,
                                  int sec)

time

protected java.util.Date time(int hour,
                              int min,
                              int sec)

date

protected java.util.Date date(java.sql.Date val)
This method crops time to emulate same behavior as JDBC drivers.


date

protected java.util.Date date(java.sql.Timestamp val)

blob

protected Blob blob(byte[] val)

blob

protected Blob blob(java.lang.Object val)

shortBlob

protected ShortBlob shortBlob(byte[] val)

shortBlob

protected ShortBlob shortBlob(java.lang.Object val)

geopt

protected GeoPt geopt(java.lang.Number latitude,
                      java.lang.Number longitude)

user

protected User user(java.lang.String email)

blobs

protected java.util.List<Blob> blobs(java.util.List list)

shortBlobs

protected java.util.List<ShortBlob> shortBlobs(java.util.List list)

shortBlobsOfByteArray

protected java.util.List<ShortBlob> shortBlobsOfByteArray(java.util.List<byte[]> list)

datesOfDate

protected java.util.List<java.util.Date> datesOfDate(java.util.List<? extends java.sql.Date> list)

datesOfTimestamp

protected java.util.List<java.util.Date> datesOfTimestamp(java.util.List<? extends java.sql.Timestamp> list)

ordinals

protected java.util.List<java.lang.Integer> ordinals(java.util.List<? extends java.lang.Enum> list)

names

protected java.util.List<java.lang.String> names(java.util.List<? extends java.lang.Enum> list)

handleException

protected void handleException(java.lang.Exception e)

getQueryCond

protected Query getQueryCond(java.lang.String cond,
                             java.lang.Object... params)

getQueryCond

protected Query getQueryCond(Query q,
                             java.lang.String cond,
                             java.lang.Object... params)

getQuery

protected Query getQuery()

key

protected Key key(long id)

key

protected Key key(java.lang.String name)

key

protected Key key(java.lang.String kind,
                  long id)

key

protected Key key(java.lang.String kind,
                  java.lang.String name)

key

protected Key key(Key parent,
                  java.lang.String kind,
                  long id)

key

protected Key key(Key parent,
                  java.lang.String kind,
                  java.lang.String name)

parentKey

protected Key parentKey(Key key)

parentKey

protected Key parentKey(Key key,
                        int depth)

parentKeyAsLong

protected java.lang.Long parentKeyAsLong(Key key,
                                         int depth)

parentKeyAsString

protected java.lang.String parentKeyAsString(Key key,
                                             int depth)

keyIterable

protected java.lang.Iterable<Key> keyIterable(java.lang.Iterable<Entity> ie)

keyIterator

protected java.util.Iterator<Key> keyIterator(java.util.Iterator<Entity> ie)

getFetchOptions

protected FetchOptions getFetchOptions(int offset,
                                       int count)

isLimit

protected boolean isLimit(int count)

getGQLDynamicQuery

protected GQLDynamicQuery getGQLDynamicQuery()

getEntityCache

protected DtoCache<Key,Entity> getEntityCache()


Copyright © 2010 Spolecne s.r.o. All Rights Reserved.