public class DBKt
| Modifier and Type | Method and Description |
|---|---|
static <R> R |
db(kotlin.jvm.functions.Function1<? super eu.vaadinonkotlin.vaadin8.jpa.PersistenceContext,? extends R> block)
Makes sure given block is executed in a DB transaction. When the block finishes normally, the transaction commits;
if the block throws any exception, the transaction is rolled back.
|
static boolean |
delete(javax.persistence.EntityManager $receiver,
java.lang.Object entity)
Deletes given entity, regardless of whether it is detached or attached. If the entity was detached and meanwhile
deleted from the database, does nothing and return false.
|
static java.sql.Connection |
getConnection(javax.persistence.EntityManager $receiver)
Provides the JDBC connection used by this entity manager.
|
static javax.sql.DataSource |
getDataSource(eu.vaadinonkotlin.VaadinOnKotlin $receiver)
Shorthand for
DBKt.getEntityManagerFactory.toDataSource() |
static java.lang.Object |
getDbId(java.lang.Object $receiver)
Returns the entity ID of this JPA bean. Fails if not invoked on a JPA bean.
|
static javax.persistence.EntityManagerFactory |
getEntityManagerFactory(eu.vaadinonkotlin.VaadinOnKotlin $receiver)
Used for data persistence - the JDBC/EntityManager/JPA thingy. By default uses the "sample" persistence unit
present in
META-INF/persistence.xml but you can of course use any factory you wish. |
static javax.persistence.EntityManager |
getExtendedEntityManager()
The extended entity manager, which stays valid even after the transaction is committed and
the servlet request finishes. Automatically allocates and releases a delegate EntityManager.
|
static void |
setEntityManagerFactory(eu.vaadinonkotlin.VaadinOnKotlin $receiver,
javax.persistence.EntityManagerFactory value)
Used for data persistence - the JDBC/EntityManager/JPA thingy. By default uses the "sample" persistence unit
present in
META-INF/persistence.xml but you can of course use any factory you wish. |
static <T> T |
singleOrNull(javax.persistence.TypedQuery<T> $receiver)
TypedQuery.getSingleResult works only for simple types such as Long - it does not work when retrieving a single JPA entity
and will fail with
NoResultException: No entity found for query when no entities are found. Often, null is a better alternative. |
static javax.sql.DataSource |
toDataSource(javax.persistence.EntityManagerFactory $receiver)
Provides a DataSource which creates JDBC connections using this factory.
|
static javax.persistence.EntityManager |
withTransactionControlDisabled(javax.persistence.EntityManager $receiver)
Returns a new EntityManager which delegates all calls
this, with the following exceptions: |
public static javax.persistence.EntityManagerFactory getEntityManagerFactory(eu.vaadinonkotlin.VaadinOnKotlin $receiver)
Used for data persistence - the JDBC/EntityManager/JPA thingy. By default uses the "sample" persistence unit
present in META-INF/persistence.xml but you can of course use any factory you wish.
public static void setEntityManagerFactory(eu.vaadinonkotlin.VaadinOnKotlin $receiver,
javax.persistence.EntityManagerFactory value)
Used for data persistence - the JDBC/EntityManager/JPA thingy. By default uses the "sample" persistence unit
present in META-INF/persistence.xml but you can of course use any factory you wish.
public static javax.sql.DataSource getDataSource(eu.vaadinonkotlin.VaadinOnKotlin $receiver)
Shorthand for DBKt.getEntityManagerFactory.toDataSource()
DBKt.getEntityManagerFactorypublic static javax.persistence.EntityManager withTransactionControlDisabled(javax.persistence.EntityManager $receiver)
Returns a new EntityManager which delegates all calls this, with the following exceptions:
The EntityManager.getTransaction will fail with IllegalStateException.
public static javax.sql.DataSource toDataSource(javax.persistence.EntityManagerFactory $receiver)
Provides a DataSource which creates JDBC connections using this factory.
public static java.sql.Connection getConnection(javax.persistence.EntityManager $receiver)
Provides the JDBC connection used by this entity manager.
public static <R> R db(kotlin.jvm.functions.Function1<? super eu.vaadinonkotlin.vaadin8.jpa.PersistenceContext,? extends R> block)
Makes sure given block is executed in a DB transaction. When the block finishes normally, the transaction commits; if the block throws any exception, the transaction is rolled back.
Example of use: db { em.persist() }
block - the block to run in the transaction. Builder-style provides helpful methods and values, e.g. PersistenceContext.empublic static boolean delete(javax.persistence.EntityManager $receiver,
java.lang.Object entity)
Deletes given entity, regardless of whether it is detached or attached. If the entity was detached and meanwhile deleted from the database, does nothing and return false.
Triggers the CascadeType.REMOVE properly.
public static <T> T singleOrNull(javax.persistence.TypedQuery<T> $receiver)
TypedQuery.getSingleResult works only for simple types such as Long - it does not work when retrieving a single JPA entity
and will fail with NoResultException: No entity found for query when no entities are found. Often, null is a better alternative.
public static javax.persistence.EntityManager getExtendedEntityManager()
The extended entity manager, which stays valid even after the transaction is committed and the servlet request finishes. Automatically allocates and releases a delegate EntityManager.
Can only be used from Vaadin/web servlet thread - cannot be used from async threads.
public static java.lang.Object getDbId(java.lang.Object $receiver)
Returns the entity ID of this JPA bean. Fails if not invoked on a JPA bean.