org.sonar.jpa.session
Class JpaDatabaseSession
java.lang.Object
org.sonar.api.database.DatabaseSession
org.sonar.jpa.session.JpaDatabaseSession
- All Implemented Interfaces:
- BatchComponent
public class JpaDatabaseSession
- extends DatabaseSession
Method Summary |
void |
commit()
|
boolean |
contains(Object model)
|
javax.persistence.Query |
createNativeQuery(String sql)
|
javax.persistence.Query |
createQuery(String hql)
Note that not recommended to directly execute Query.getSingleResult() , because it will bypass exception handling,
which done in getSingleResult(Query, Object) . |
|
getEntity(Class<T> entityClass,
Object id)
|
javax.persistence.EntityManager |
getEntityManager()
Note that usage of this method is discouraged, because it allows to construct and execute queries without additional exception handling,
which done in methods of this class. |
|
getResults(Class<T> entityClass)
|
|
getResults(Class<T> entityClass,
Object... criterias)
|
|
getSingleResult(Class<T> entityClass,
Object... criterias)
|
|
getSingleResult(javax.persistence.Query query,
T defaultValue)
|
Object |
merge(Object model)
|
|
reattach(Class<T> entityClass,
Object primaryKey)
|
void |
remove(Object model)
|
void |
removeWithoutFlush(Object model)
|
void |
rollback()
|
void |
save(Object... models)
|
|
save(T model)
|
Object |
saveWithoutFlush(Object model)
|
void |
start()
|
void |
stop()
|
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
JpaDatabaseSession
public JpaDatabaseSession(DatabaseConnector connector)
getEntityManager
public javax.persistence.EntityManager getEntityManager()
- Note that usage of this method is discouraged, because it allows to construct and execute queries without additional exception handling,
which done in methods of this class.
- Specified by:
getEntityManager
in class DatabaseSession
start
public void start()
- Specified by:
start
in class DatabaseSession
stop
public void stop()
- Specified by:
stop
in class DatabaseSession
commit
public void commit()
- Specified by:
commit
in class DatabaseSession
rollback
public void rollback()
- Specified by:
rollback
in class DatabaseSession
save
public <T> T save(T model)
- Specified by:
save
in class DatabaseSession
saveWithoutFlush
public Object saveWithoutFlush(Object model)
- Specified by:
saveWithoutFlush
in class DatabaseSession
contains
public boolean contains(Object model)
- Specified by:
contains
in class DatabaseSession
save
public void save(Object... models)
- Specified by:
save
in class DatabaseSession
merge
public Object merge(Object model)
- Specified by:
merge
in class DatabaseSession
remove
public void remove(Object model)
- Specified by:
remove
in class DatabaseSession
removeWithoutFlush
public void removeWithoutFlush(Object model)
- Specified by:
removeWithoutFlush
in class DatabaseSession
reattach
public <T> T reattach(Class<T> entityClass,
Object primaryKey)
- Specified by:
reattach
in class DatabaseSession
createQuery
public javax.persistence.Query createQuery(String hql)
- Note that not recommended to directly execute
Query.getSingleResult()
, because it will bypass exception handling,
which done in getSingleResult(Query, Object)
.
- Specified by:
createQuery
in class DatabaseSession
createNativeQuery
public javax.persistence.Query createNativeQuery(String sql)
- Specified by:
createNativeQuery
in class DatabaseSession
getSingleResult
public <T> T getSingleResult(javax.persistence.Query query,
T defaultValue)
- Specified by:
getSingleResult
in class DatabaseSession
- Returns:
- the result or
defaultValue
, if not found
- Throws:
javax.persistence.NonUniqueResultException
- if more than one result
getEntity
public <T> T getEntity(Class<T> entityClass,
Object id)
- Specified by:
getEntity
in class DatabaseSession
getSingleResult
public <T> T getSingleResult(Class<T> entityClass,
Object... criterias)
- Specified by:
getSingleResult
in class DatabaseSession
- Returns:
- the result or
null
, if not found
- Throws:
javax.persistence.NonUniqueResultException
- if more than one result
getResults
public <T> List<T> getResults(Class<T> entityClass,
Object... criterias)
- Specified by:
getResults
in class DatabaseSession
getResults
public <T> List<T> getResults(Class<T> entityClass)
- Specified by:
getResults
in class DatabaseSession
Copyright © 2009-2012 SonarSource. All Rights Reserved.