com.adaptrex.core.persistence
Interface AdaptrexPersistence

All Known Implementing Classes:
JpaPersistence

public interface AdaptrexPersistence

AdaptrexPersistence provides an interface to an variety of implementations that handle persistence between Adaptrex and an ORM. Currently only a standard JPA2 (via EclipseLink) implentation is included but he eventual goal is to allow nearly any ORM to be supported (Hibernate, Cayanne, TopLink, OpenJpa, etc, etc).

Some of the code in adaptrex-core that uses this API is currently JPA specific. com.adaptrex.core.ext.data.ModelInstance scans its target entity several times and reads JPA annotations to determine things like join types and the type of objects being retrieved. The AdaptrexPersistence interface should be made much more robust to handle this functionality and current functionality should move to the JPA specific implementation.

Because this API is not yet 100% stable, it should only be used inside other adaptrex-core code


Method Summary
 void closeNativeSession(Object session)
           
 Object deleteEntity(AdaptrexSession session, Object entity)
          This should delete an entity from the default persistence unit based on the supplied className and id
 Object getEntity(AdaptrexSession session, Class<?> clazz, Integer id)
          This should return a single entity object from the default persistence unit based on the supplied class and id
 Object getEntity(AdaptrexSession session, String className, Integer id)
          This should return a single entity object from the default persistence unit based on the supplied className and id
 Class<?> getEntityClass(String className)
          This should return the class for a specific className in the default persistence unit (JPA Persistence Unit, Hibernate session, etc, etc).
 List<Object> getEntityList(AdaptrexSession session, Store store)
          This should return a list of objects that comprise the data that is to be included in an ext.data.Store.
 Object getFactory()
           
 String getFieldType(Class<?> clazz, String fieldName)
           
 Object getFieldValue(Object entity, String fieldName)
           
 Object getNativeSession()
          This should return the default session entity manager for whichever implementation is being used.
 boolean isIdField(Class<?> clazz, String fieldName)
           
 boolean isManyToOne(Class<?> clazz, String fieldName)
           
 boolean isOneToMany(Class<?> clazz, String fieldName)
           
 Object saveEntity(AdaptrexSession session, Object entity)
          This should save (create or update) the supplied entity using the default persistence unit and return an updated instance of the entity
 

Method Detail

getEntityClass

Class<?> getEntityClass(String className)
This should return the class for a specific className in the default persistence unit (JPA Persistence Unit, Hibernate session, etc, etc). It should accept just the simple name assuming there is only one class with that name in the persistence unit. It should also accept a fully qualified name in situations where the persistence unit has multiple classes with the same name in different packages.

Parameters:
className -
Returns:

getEntityList

List<Object> getEntityList(AdaptrexSession session,
                           Store store)
This should return a list of objects that comprise the data that is to be included in an ext.data.Store. The Store object contains a significant number of configuration options that should be used to generate the store. Any implementation should support all possible store options.

TODO: document the possible store options each implementation should be aware of

Parameters:
store -
Returns:

getEntity

Object getEntity(AdaptrexSession session,
                 String className,
                 Integer id)
This should return a single entity object from the default persistence unit based on the supplied className and id

Parameters:
className -
id -
Returns:

getEntity

Object getEntity(AdaptrexSession session,
                 Class<?> clazz,
                 Integer id)
This should return a single entity object from the default persistence unit based on the supplied class and id

Parameters:
class -
id -
Returns:

saveEntity

Object saveEntity(AdaptrexSession session,
                  Object entity)
This should save (create or update) the supplied entity using the default persistence unit and return an updated instance of the entity

Parameters:
entity -
Returns:

deleteEntity

Object deleteEntity(AdaptrexSession session,
                    Object entity)
This should delete an entity from the default persistence unit based on the supplied className and id

Parameters:
className -
id -
Returns:

getNativeSession

Object getNativeSession()
This should return the default session entity manager for whichever implementation is being used. For example. JPA should return an EntityManager. Hibernate should return a Session. Cayenne should return an ObjectContext.

The AdaptrexPersistence interface currently contains a subset of functions required by adaptrex itself. Individual applications may require more control and access to the specific ORM implementation.

Returns:

getFactory

Object getFactory()

closeNativeSession

void closeNativeSession(Object session)

isIdField

boolean isIdField(Class<?> clazz,
                  String fieldName)

isOneToMany

boolean isOneToMany(Class<?> clazz,
                    String fieldName)

isManyToOne

boolean isManyToOne(Class<?> clazz,
                    String fieldName)

getFieldValue

Object getFieldValue(Object entity,
                     String fieldName)

getFieldType

String getFieldType(Class<?> clazz,
                    String fieldName)


Copyright © 2012 Adaptrex, LLC. All Rights Reserved.