com.h3c.util.dao

## Class AbstractDao<I extends Serializable,P extends Storable<I>,T extends Transportable<? super T,I>,F,S>

- java.lang.Object
- - com.h3c.util.dao.AbstractBaseDao<I,P,T,F,S>
  - - com.h3c.util.dao.AbstractDao<I,P,T,F,S>

- Type Parameters:
    `I` - type of the persistent object and transport object id. This type should be immutable. It is critical this type implements equals() and hashCode() correctly.
    `P` - type of model persistent object.
    `T` - type of the transport object.
    `F` - type of the associated filter.
    `S` - type of the associated sort specification type.
  All Implemented Interfaces:
    Converter<P,T>, BaseDao<I,P,T,F,S>, Dao<I,P,T,F,S>

      public abstract class AbstractDao<I extends Serializable,P extends Storable<I>,T extends Transportable<? super T,I>,F,S>
      extends AbstractBaseDao<I,P,T,F,S>
      implements Dao<I,P,T,F,S>

  JPA Abstract Data Access Object.

  This class must remain state-less so it is thread safe.

- - ### Constructor Summary

    Constructors
    Modifier | Constructor and Description
    --- | ---
    `protected` | `AbstractDao(Class<P> entityClass)` Construct DAO and initialize query predicate generator.
    `protected` | `AbstractDao(Class<P> entityClass, UpdateStrategy<P,T> updateStrategy)` Construct DAO and initialize query predicate generator.

  - ### Method Summary

    Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected abstract void` | `conform(P target, T source)` Synchronizes the transport object and the persistent object state.
    `T` | `convert(P source)` Converts an instance of type S to an instance of type T
    `P` | `create(T transportable, DataStoreContext context)` Creates a new persistent object with the data from the given transport object.
    `protected abstract P` | `createStorableInstance(T transportable)` Creates the instance of the persistent object (Entity).
    `long` | `delete(F filter, DataStoreContext context)` Deletes all persistent objects matching the given filter.
    `boolean` | `delete(Id<T,I> id, DataStoreContext context)` Deletes the persistent object with the given id.
    `void` | `delete(P storable, DataStoreContext context)` Deletes a persistent object.
    `long` | `deleteAll(DataStoreContext context)` Deletes all the persistent objects.
    `protected abstract T` | `doConvert(P source)` Converts the persistent object to a transport object.
    `P` | `update(T transportable, DataStoreContext context)` Updates the persistent object related to the given transport object.

    - ### Methods inherited from class com.h3c.util.dao.AbstractBaseDao

      `count, find, find, findAll, get, getQueryPredicate, getQueryPredicateGenerator, getSingularAttribute, updateDependents`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

    - ### Methods inherited from interface com.h3c.util.dao.BaseDao

      `count, find, find, findAll, get`

- - ### Constructor Detail

    - #### AbstractDao

          protected AbstractDao(Class<P> entityClass)

      Construct DAO and initialize query predicate generator.
      Parameters:
        `entityClass` - persistent object class.

    - #### AbstractDao

          protected AbstractDao(Class<P> entityClass,
                     UpdateStrategy<P,T> updateStrategy)

      Construct DAO and initialize query predicate generator.
      Parameters:
        `entityClass` - persistent object class.
        `updateStrategy` - update strategy.

  - ### Method Detail

    - #### create

          public P create(T transportable,
                 DataStoreContext context)

      Description copied from interface: `Dao`
      Creates a new persistent object with the data from the given transport object.
      Specified by:
        `create` in interface `Dao<I extends Serializable,P extends Storable<I>,T extends Transportable<? super T,I>,F,S>`
      Parameters:
        `transportable` - transport object to get the data from
        `context` - data store context
      Returns:
        the new created persistent object

    - #### update

          public P update(T transportable,
                 DataStoreContext context)

      Description copied from interface: `Dao`
      Updates the persistent object related to the given transport object.
      Specified by:
        `update` in interface `Dao<I extends Serializable,P extends Storable<I>,T extends Transportable<? super T,I>,F,S>`
      Parameters:
        `transportable` - transport object to get the data from
        `context` - data store context
      Returns:
        the updated persistent object

    - #### delete

          public void delete(P storable,
                    DataStoreContext context)

      Description copied from interface: `Dao`
      Deletes a persistent object.

      Concrete classes could override this method to do any pre-processing / post-processing work.

      Specified by:
        `delete` in interface `Dao<I extends Serializable,P extends Storable<I>,T extends Transportable<? super T,I>,F,S>`
      Parameters:
        `storable` - the persistent object to delete
        `context` - data store context

    - #### delete

          public boolean delete(Id<T,I> id,
                       DataStoreContext context)

      Description copied from interface: `Dao`
      Deletes the persistent object with the given id.
      Specified by:
        `delete` in interface `Dao<I extends Serializable,P extends Storable<I>,T extends Transportable<? super T,I>,F,S>`
      Parameters:
        `id` - persistent object's id
        `context` - data store context
      Returns:
        `true` if the persistent object was found and deleted, `false` if it was not found

    - #### delete

          public long delete(F filter,
                    DataStoreContext context)

      Description copied from interface: `Dao`
      Deletes all persistent objects matching the given filter.
      Specified by:
        `delete` in interface `Dao<I extends Serializable,P extends Storable<I>,T extends Transportable<? super T,I>,F,S>`
      Parameters:
        `filter` - filter
        `context` - data store context
      Returns:
        number of deleted objects

    - #### deleteAll

          public long deleteAll(DataStoreContext context)

      Description copied from interface: `Dao`
      Deletes all the persistent objects.
      Specified by:
        `deleteAll` in interface `Dao<I extends Serializable,P extends Storable<I>,T extends Transportable<? super T,I>,F,S>`
      Parameters:
        `context` - data store context
      Returns:
        the count of entries deleted

    - #### convert

          public T convert(P source)

      Description copied from interface: `Converter`
      Converts an instance of type S to an instance of type T
      Specified by:
        `convert` in interface `Converter<P extends Storable<I>,T extends Transportable<? super T,I>>`
      Parameters:
        `source` - the source object to be converted
      Returns:
        an instance of the target type T converted from the source

    - #### createStorableInstance

          protected abstract P createStorableInstance(T transportable)

      Creates the instance of the persistent object (Entity).
      Parameters:
        `transportable` - transport object to get the data from.
      Returns:
        a new instance of the persistent object.

    - #### doConvert

          protected abstract T doConvert(P source)

      Converts the persistent object to a transport object.
      Parameters:
        `source` - persistent object to convert.
      Returns:
        a transport object with the same data than `source`

    - #### conform

          protected abstract void conform(P target,
                     T source)

      Synchronizes the transport object and the persistent object state. This method is called from `update(Transportable, DataStoreContext)`, thus if `update(Transportable, DataStoreContext)` is overwritten this method could have an empty implementation.
      Parameters:
        `target` - object to update.
        `source` - object to take the data from.

Copyright © 2014. All Rights Reserved.