public abstract class GenericDaoImpl<T> extends GenericAware<T> implements GenericDao<T>
EntityManager
. The EntityManager however depends
on the application using this DaoImpl. Hence the EntityManager is injected via Spring in the derived classes.Modifier and Type | Field and Description |
---|---|
protected javax.persistence.EntityManager |
em |
ct, t
Constructor and Description |
---|
GenericDaoImpl() |
GenericDaoImpl(Class<T> t) |
Modifier and Type | Method and Description |
---|---|
Long |
delete(Long id)
A special Delete operation on the entity that will remove the entity and related entities based on id.
|
void |
delete(T persistentObject) |
javax.persistence.EntityManager |
getEntityManager() |
protected String |
getNativeEntityName(String entityName)
Calling dao methods calls some native DB calls that executes
EntityManager.createNativeQuery(String) . |
T |
load(Object id) |
T |
load(Object id,
Class entityClass)
In some situations the DAO represents an Interface or perhaps a parent of the actual Entity./
The exact type of the entity would have to be Supplied.
|
protected Page<T> |
paginate(javax.persistence.Query q,
PageInfo pageInfo)
Create Page from the result
|
List |
query(String ql,
String dialect,
Object... params)
Execute a raw Query in the native implementation language.
|
Page |
query(String ql,
String dialect,
PageInfo pageInfo,
Object... params)
Execute a raw Query in the native implementation language.
|
T |
save(T transientObject) |
void |
setEntityManager(javax.persistence.EntityManager em) |
int |
update(String query,
boolean isNative,
Object... params)
An Update query with optional params
|
public void delete(T persistentObject)
delete
in interface GenericDao<T>
public T load(Object id, Class entityClass)
GenericDao
load
in interface GenericDao<T>
id
- as Id for EntityentityClass
- as Class
of entitypublic T load(Object id)
load
in interface GenericDao<T>
public T save(T transientObject)
save
in interface GenericDao<T>
public Long delete(Long id)
GenericDao
delete
in interface GenericDao<T>
Long
public javax.persistence.EntityManager getEntityManager()
public void setEntityManager(javax.persistence.EntityManager em)
public List query(String ql, String dialect, Object... params) throws Exception
query
in interface FreeQuery
ql
- as String in native Schema languagedialect
- as String. NULL or empty or "NATIVE" implies NATIVE, "JPA" implies JPA will be used. Additional dialects can be supported but they will be implementation dependent.params
- as Query parameters to the string.
List
Exception
protected final Page<T> paginate(javax.persistence.Query q, PageInfo pageInfo)
public Page query(String ql, String dialect, PageInfo pageInfo, Object... params) throws Exception
query
in interface FreeQuery
ql
- as String in native Schema languagedialect
- as String. NULL or empty or "NATIVE" implies NATIVE, "JPA" implies JPA will be used. Additional dialects can be supported but they will be implementation dependent.pageInfo
- as PageInfo
for pagination of resultparams
- as Query parameters to the string
Page
Exception
public int update(String query, boolean isNative, Object... params)
FreeQuery
protected String getNativeEntityName(String entityName)
EntityManager.createNativeQuery(String)
.
Which implies the entityName is case sensitive. If not careful can generate an error like
Caused by: com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Table 'needledu_ecom.Product' doesn't exist
Keeping name of entity name same as in DB to be safe.Copyright © 2018. All rights reserved.