AbstractPersistence (training-module-library 1.0.0-4.12.0-163223 API)
Date: 2018-07-19

org.gcube.portal.trainingmodule.persistence

## Class AbstractPersistence<T>

- java.lang.Object
- - org.gcube.portal.trainingmodule.persistence.AbstractPersistence<T>

- Type Parameters:
    `T` - the generic type
  All Implemented Interfaces:
    DaoUpdater<T>, DaoViewer<T>, JavaPersistenceHandler<T>
  Direct Known Subclasses:
    TrainingProgressUnitPersistence, TrainingProjectPersistence, TrainingUnitPersistence

      public abstract class AbstractPersistence<T>
      extends Object
      implements DaoUpdater<T>, DaoViewer<T>, JavaPersistenceHandler<T>

  The Class AbstractPersistence.
  Author:
    Francesco Mangiacrapa francesco.mangiacrapa@isti.cnr.it Jan 10, 2018

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `AbstractPersistence.SQL_ORDER` The Enum SQL_ORDER.

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `String` | `AND` The and.
    `protected javax.persistence.EntityManagerFactory` | `entityManagerFactory` The entity manager factory.
    `protected org.slf4j.Logger` | `logger` The logger.
    `protected String` | `tableName` The table name.

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `AbstractPersistence(javax.persistence.EntityManagerFactory factory, String tableName)` Instantiates a new abstract persistence.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `int` | `countItems()` Count items.
    `boolean` | `create(T item)` Creates the.
    `javax.persistence.EntityManager` | `createNewManager()` Creates the new manager.
    `int` | `deleteItemByInternalId(long internalId)` Delete item by internal id.
    `List<T>` | `executeCriteriaQuery(javax.persistence.criteria.CriteriaQuery<Object> criteriaQuery)` Execute criteria query.
    `List<T>` | `executeTypedQuery(javax.persistence.criteria.CriteriaQuery<Object> cq, int startIndex, int offset)` Execute typed query.
    `javax.persistence.criteria.CriteriaBuilder` | `getCriteriaBuilder()` Gets the criteria builder.
    `javax.persistence.EntityManagerFactory` | `getEntityManagerFactory()` Gets the entity manager factory.
    `T` | `getItemByKey(Long id, Class<T> t)` Gets the item by key.
    `List<T>` | `getItemForInternalID(long internalID)` Gets the item for internal ID.
    `List<T>` | `getRows()` Gets the rows.
    `List<T>` | `getRows(int startIndex, int offset)` Gets the rows.
    `List<T>` | `getRowsFiltered(Map<String,String> andFilterMap)` Gets the rows filtered.
    `List<T>` | `getRowsOrdered(String orderByField, AbstractPersistence.SQL_ORDER order)` Gets the rows ordered.
    `boolean` | `insert(T item)` Insert.
    `boolean` | `remove(T item, boolean transaction)` Removes the.
    `int` | `removeAll()` Removes the all.
    `abstract javax.persistence.criteria.Root<T>` | `rootFrom(javax.persistence.criteria.CriteriaQuery<Object> cq)` Root from.
    `T` | `update(T item)` Update.

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

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

- - ### Field Detail

    - #### entityManagerFactory

          protected javax.persistence.EntityManagerFactory entityManagerFactory

      The entity manager factory.

    - #### AND

          public final String AND

      The and.
      See Also:
        Constant Field Values

    - #### logger

          protected org.slf4j.Logger logger

      The logger.

    - #### tableName

          protected String tableName

      The table name.

  - ### Constructor Detail

    - #### AbstractPersistence

          public AbstractPersistence(javax.persistence.EntityManagerFactory factory,
                                     String tableName)

      Instantiates a new abstract persistence.
      Parameters:
        `factory` - the factory
        `tableName` - the table name

  - ### Method Detail

    - #### rootFrom

          public abstract javax.persistence.criteria.Root<T> rootFrom(javax.persistence.criteria.CriteriaQuery<Object> cq)

      Description copied from interface: `JavaPersistenceHandler`
      Root from.
      Specified by:
        `rootFrom` in interface `JavaPersistenceHandler<T>`
      Parameters:
        `cq` - the cq
      Returns:
        the root

    - #### create

          public boolean create(T item)
                         throws DatabaseServiceException

      Description copied from interface: `DaoUpdater`
      Creates the.
      Specified by:
        `create` in interface `DaoUpdater<T>`
      Parameters:
        `item` - the item
      Returns:
        true, if successful
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### insert

          public boolean insert(T item)
                         throws DatabaseServiceException

      Description copied from interface: `DaoUpdater`
      Insert.
      Specified by:
        `insert` in interface `DaoUpdater<T>`
      Parameters:
        `item` - the item
      Returns:
        true, if successful
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### update

          public T update(T item)
                   throws DatabaseServiceException

      Description copied from interface: `DaoUpdater`
      Update.
      Specified by:
        `update` in interface `DaoUpdater<T>`
      Parameters:
        `item` - the item
      Returns:
        the t
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### remove

          public boolean remove(T item,
                                boolean transaction)
                         throws DatabaseServiceException

      Description copied from interface: `DaoUpdater`
      Removes the.
      Specified by:
        `remove` in interface `DaoUpdater<T>`
      Parameters:
        `item` - the item
        `transaction` - the transaction
      Returns:
        true, if successful
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### getRows

          public List<T> getRows()
                          throws DatabaseServiceException

      Description copied from interface: `DaoViewer`
      Gets the rows.
      Specified by:
        `getRows` in interface `DaoViewer<T>`
      Returns:
        the rows
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### getRowsOrdered

          public List<T> getRowsOrdered(String orderByField,
                                        AbstractPersistence.SQL_ORDER order)
                                 throws DatabaseServiceException

      Description copied from interface: `DaoViewer`
      Gets the rows ordered.
      Specified by:
        `getRowsOrdered` in interface `DaoViewer<T>`
      Parameters:
        `orderByField` - the order by field
        `order` - the order
      Returns:
        the rows ordered
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### getRows

          public List<T> getRows(int startIndex,
                                 int offset)
                          throws DatabaseServiceException

      Description copied from interface: `DaoViewer`
      Gets the rows.
      Specified by:
        `getRows` in interface `DaoViewer<T>`
      Parameters:
        `startIndex` - the start index
        `offset` - the offset
      Returns:
        the rows
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### countItems

          public int countItems()
                         throws DatabaseServiceException

      Description copied from interface: `DaoViewer`
      Count items.
      Specified by:
        `countItems` in interface `DaoViewer<T>`
      Returns:
        the int
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### getRowsFiltered

          public List<T> getRowsFiltered(Map<String,String> andFilterMap)
                                  throws DatabaseServiceException

      Description copied from interface: `DaoViewer`
      Gets the rows filtered.
      Specified by:
        `getRowsFiltered` in interface `DaoViewer<T>`
      Parameters:
        `andFilterMap` - the filter map
      Returns:
        the rows filtered
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### removeAll

          public int removeAll()
                        throws DatabaseServiceException

      Description copied from interface: `DaoUpdater`
      Removes the all.
      Specified by:
        `removeAll` in interface `DaoUpdater<T>`
      Returns:
        the int
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### getItemByKey

          public T getItemByKey(Long id,
                                Class<T> t)
                         throws DatabaseServiceException

      Description copied from interface: `DaoViewer`
      Gets the item by key.
      Specified by:
        `getItemByKey` in interface `DaoViewer<T>`
      Parameters:
        `id` - the id
        `t` - the t
      Returns:
        the item by key
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### getCriteriaBuilder

          public javax.persistence.criteria.CriteriaBuilder getCriteriaBuilder()
                                                                        throws DatabaseServiceException

      Description copied from interface: `JavaPersistenceHandler`
      Gets the criteria builder.
      Specified by:
        `getCriteriaBuilder` in interface `JavaPersistenceHandler<T>`
      Returns:
        the criteria builder
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### getEntityManagerFactory

          public javax.persistence.EntityManagerFactory getEntityManagerFactory()

      Description copied from interface: `JavaPersistenceHandler`
      Gets the entity manager factory.
      Specified by:
        `getEntityManagerFactory` in interface `JavaPersistenceHandler<T>`
      Returns:
        the entity manager factory

    - #### createNewManager

          public javax.persistence.EntityManager createNewManager()
                                                           throws DatabaseServiceException

      Description copied from interface: `JavaPersistenceHandler`
      Creates the new manager.
      Specified by:
        `createNewManager` in interface `JavaPersistenceHandler<T>`
      Returns:
        the entity manager
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### executeCriteriaQuery

          public List<T> executeCriteriaQuery(javax.persistence.criteria.CriteriaQuery<Object> criteriaQuery)
                                       throws DatabaseServiceException

      Description copied from interface: `JavaPersistenceHandler`
      Execute criteria query.
      Specified by:
        `executeCriteriaQuery` in interface `JavaPersistenceHandler<T>`
      Parameters:
        `criteriaQuery` - the criteria query
      Returns:
        the list
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### executeTypedQuery

          public List<T> executeTypedQuery(javax.persistence.criteria.CriteriaQuery<Object> cq,
                                           int startIndex,
                                           int offset)
                                    throws DatabaseServiceException

      Description copied from interface: `JavaPersistenceHandler`
      Execute typed query.
      Specified by:
        `executeTypedQuery` in interface `JavaPersistenceHandler<T>`
      Parameters:
        `cq` - the cq
        `startIndex` - the start index
        `offset` - the offset
      Returns:
        the list
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### deleteItemByInternalId

          public int deleteItemByInternalId(long internalId)
                                     throws DatabaseServiceException

      Description copied from interface: `DaoUpdater`
      Delete item by internal id.
      Specified by:
        `deleteItemByInternalId` in interface `DaoUpdater<T>`
      Parameters:
        `internalId` - the internal id
      Returns:
        the int
      Throws:
        `DatabaseServiceException` - the database service exception

    - #### getItemForInternalID

          public List<T> getItemForInternalID(long internalID)
                                       throws DatabaseServiceException

      Gets the item for internal ID.
      Parameters:
        `internalID` - the internal ID
      Returns:
        the item for internal ID
      Throws:
        `DatabaseServiceException` - the database service exception

Copyright © 2018. All Rights Reserved.