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 oxTrust by GluuFederation.
the class InumService method findInum.
/**
* get an inum from inum DB by inum value
*
* @return InumSqlEntry
*/
public InumSqlEntry findInum(EntityManager inumEntryManager, String inum) {
boolean successs = false;
EntityTransaction entityTransaction = inumEntryManager.getTransaction();
entityTransaction.begin();
InumSqlEntry result = null;
try {
@SuppressWarnings("unchecked") List<InumSqlEntry> inumList = inumEntryManager.createQuery("select u from inumTable u where u.inum = :inum").setParameter("inum", inum).setMaxResults(1).getResultList();
if (inumList.size() == 0) {
result = null;
} else {
result = inumList.get(0);
successs = true;
}
} finally {
if (successs) {
// Commit transaction
entityTransaction.commit();
} else {
// Rollback transaction
entityTransaction.rollback();
}
}
return result;
}
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 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 webpieces by deanhiller.
the class TestAjaxHibernate method loadDataInDb.
public static UserTestDbo loadDataInDb() {
String email = "dean2@sync.xsoftware.biz";
//populate database....
EntityManagerFactory factory = Persistence.createEntityManagerFactory(HibernateAppMeta.PERSISTENCE_TEST_UNIT);
EntityManager mgr = factory.createEntityManager();
EntityTransaction tx = mgr.getTransaction();
tx.begin();
UserTestDbo user = new UserTestDbo();
user.setEmail(email);
user.setName("SomeName");
user.setFirstName("Dean");
user.setLastName("Hill");
mgr.persist(user);
mgr.flush();
tx.commit();
return user;
}
Aggregations