use of javax.persistence.EntityTransaction in project oxTrust by GluuFederation.
the class InumService method addInum.
/**
* Add an Inum to the DB
*
* @return True if user exist
*/
public boolean addInum(EntityManager inumEntryManager, String inum, String type) {
boolean successs = false;
EntityTransaction entityTransaction = inumEntryManager.getTransaction();
entityTransaction.begin();
try {
// Prepare inum
InumSqlEntry inumEntry = new InumSqlEntry();
inumEntry.setInum(inum);
inumEntry.setType(type);
// add inum
inumEntryManager.persist(inumEntry);
successs = true;
} finally {
if (successs) {
// Commit transaction
entityTransaction.commit();
} else {
// Rollback transaction
entityTransaction.rollback();
}
}
return successs;
}
use of javax.persistence.EntityTransaction in project oxTrust by GluuFederation.
the class InumService method addInumByObject.
/**
* Add an Inum to the DB by object
*
* @return True if user exist
*/
public boolean addInumByObject(EntityManager inumEntryManager, InumSqlEntry inumEntry) {
boolean successs = false;
EntityTransaction entityTransaction = inumEntryManager.getTransaction();
entityTransaction.begin();
try {
// add inum
inumEntryManager.persist(inumEntry);
successs = true;
} finally {
if (successs) {
// Commit transaction
entityTransaction.commit();
} else {
// Rollback transaction
entityTransaction.rollback();
}
}
return successs;
}
use of javax.persistence.EntityTransaction in project tomee by apache.
the class JpaServlet method doGet.
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/plain");
ServletOutputStream out = response.getOutputStream();
out.println("@PersistenceUnit=" + emf);
EntityManager em = emf.createEntityManager();
EntityTransaction transaction = em.getTransaction();
transaction.begin();
JpaBean jpaBean = new JpaBean();
jpaBean.setName("JpaBean");
em.persist(jpaBean);
transaction.commit();
transaction.begin();
Query query = em.createQuery("SELECT j FROM JpaBean j WHERE j.name='JpaBean'");
jpaBean = (JpaBean) query.getSingleResult();
out.println("Loaded " + jpaBean);
em.remove(jpaBean);
transaction.commit();
transaction.begin();
query = em.createQuery("SELECT count(j) FROM JpaBean j WHERE j.name='JpaBean'");
int count = ((Number) query.getSingleResult()).intValue();
if (count == 0) {
out.println("Removed " + jpaBean);
} else {
out.println("ERROR: unable to remove" + jpaBean);
}
transaction.commit();
}
use of javax.persistence.EntityTransaction in project hibernate-orm by hibernate.
the class IdentifierReuseTest method saveUpdateAndRemoveEntity.
private void saveUpdateAndRemoveEntity(EntityManager entityManager, Integer id) {
EntityTransaction transaction = entityManager.getTransaction();
transaction.begin();
IntNoAutoIdTestEntity entity = new IntNoAutoIdTestEntity(0, id);
entityManager.persist(entity);
assertEquals(id, entity.getId());
transaction.commit();
transaction.begin();
entity = entityManager.find(IntNoAutoIdTestEntity.class, id);
entity.setNumVal(1);
entity = entityManager.merge(entity);
assertEquals(id, entity.getId());
transaction.commit();
transaction.begin();
entity = entityManager.find(IntNoAutoIdTestEntity.class, id);
assertNotNull(entity);
entityManager.remove(entity);
transaction.commit();
}
use of javax.persistence.EntityTransaction in project Truck-Factor by aserg-ufmg.
the class NewFileInfoDAO method cleanFilter.
public int cleanFilter() {
String hql = "UPDATE newfileinfo " + "SET filtered = \'FALSE', filterinfo = \'\';";
Query q = em.createNativeQuery(hql);
int rows = 0;
EntityTransaction tx = this.em.getTransaction();
try {
tx.begin();
rows = q.executeUpdate();
tx.commit();
} catch (RuntimeException e) {
if (tx != null && tx.isActive())
tx.rollback();
throw e;
} finally {
this.em.clear();
}
return rows;
}
Aggregations