List of usage examples for org.hibernate Session saveOrUpdate
void saveOrUpdate(Object object);
From source file:com.celements.payment.service.PayPalService.java
License:Open Source License
public void storePayPalObject(final PayPal payPalObj, boolean bTransaction) throws XWikiException { getStore().executeWrite(getContext(), bTransaction, new XWikiHibernateBaseStore.HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { LOGGER.debug("in doInHibernate with session: " + session); session.saveOrUpdate(payPalObj); LOGGER.debug("after saveOrUpdate in doInHibernate with session: " + session); return null; }/*from w w w . j av a2 s . c om*/ }); }
From source file:com.celements.payment.service.PostFinanceService.java
License:Open Source License
public void storePostFinanceObject(final PostFinance PostFinanceObj, boolean bTransaction) throws XWikiException { getStore().executeWrite(getContext(), bTransaction, new XWikiHibernateBaseStore.HibernateCallback<Object>() { public Object doInHibernate(Session session) throws HibernateException { LOGGER.debug("in doInHibernate with session: " + session); session.saveOrUpdate(PostFinanceObj); LOGGER.debug("after saveOrUpdate in doInHibernate with session: " + session); return null; }//from ww w.j a va 2 s. c om }); }
From source file:com.chevres.rss.restapi.dao.impl.AbstractGenericDAO.java
@Override public void create(Object o) { Session session = this.sessionFactory.openSession(); Transaction tx;// ww w . j a v a 2 s. com try { tx = session.beginTransaction(); session.saveOrUpdate(o); tx.commit(); } catch (Exception e) { throw e; } finally { session.close(); } }
From source file:com.cloud.bridge.persist.EntityDao.java
License:Open Source License
public T save(T entity) { Session session = PersistContext.getSession(isCloudStackSession); session.saveOrUpdate(entity); return entity; }
From source file:com.cloud.bridge.persist.EntityDao.java
License:Open Source License
public T update(T entity) { Session session = PersistContext.getSession(isCloudStackSession); session.saveOrUpdate(entity); return entity; }
From source file:com.cloud.gate.model.ModelTestCase.java
License:Apache License
public void testSHost() { SHost host;/*from w ww. j a v a 2 s . c o m*/ // create the record Session session = CloudSessionFactory.getInstance().openSession(); try { Transaction txn = session.beginTransaction(); host = new SHost(); host.setHost("localhost"); host.setExportRoot("/"); host.setUserOnHost("root"); host.setUserPassword("password"); session.saveOrUpdate(host); txn.commit(); } finally { session.close(); } Assert.assertTrue(host.getId() != 0); // retrive the record session = CloudSessionFactory.getInstance().openSession(); try { Transaction txn = session.beginTransaction(); host = (SHost) session.get(SHost.class, (long) host.getId()); txn.commit(); Assert.assertTrue(host.getHost().equals("localhost")); Assert.assertTrue(host.getUserOnHost().equals("root")); Assert.assertTrue(host.getUserPassword().equals("password")); logger.info("Retrived record, host:" + host.getHost() + ", user: " + host.getUserOnHost() + ", password: " + host.getUserPassword()); } finally { session.close(); } // delete the record session = CloudSessionFactory.getInstance().openSession(); try { Transaction txn = session.beginTransaction(); host = (SHost) session.get(SHost.class, (long) host.getId()); session.delete(host); txn.commit(); } finally { session.close(); } session = CloudSessionFactory.getInstance().openSession(); try { Transaction txn = session.beginTransaction(); host = (SHost) session.get(SHost.class, (long) host.getId()); txn.commit(); Assert.assertTrue(host == null); } finally { session.close(); } }
From source file:com.cms.utils.BaseFWDAOImpl.java
License:Open Source License
@Transactional public String saveList(List<T> obj, String methodName) { try {//from w w w. j ava2 s .co m // Class c = obj.get(0).getClass(); // Method method = c.getMethod("get" + StringUtils.upperFirstChar(methodName)); Session session = getSession(); for (T item : obj) { session.saveOrUpdate(item); // String value; // try { // value = String.valueOf(method.invoke(item)); // // } catch (IllegalAccessException | IllegalArgumentException | InvocationTargetException e) { // return ParamUtils.ERROR; // } // // if (value == "null") { // getSession().save(item); // } else { // getSession().update(item); // } } return ParamUtils.SUCCESS; } catch (Exception ex) { return ex.getMessage(); } }
From source file:com.controller.RegisterFacade.java
@Override public void edit(Register entity) { Transaction trs = null;//from www.j av a 2s .c o m Session session = getSessionFactory().openSession(); try { trs = session.beginTransaction(); session.saveOrUpdate(entity); session.getTransaction().commit(); } catch (RuntimeException e) { if (trs != null) { trs.rollback(); } } finally { session.flush(); session.close(); } }
From source file:com.controllers.OrdersFacade.java
@Override public void edit(Orders entity) { Transaction trs = null;/*from w w w. j av a2 s. c o m*/ Session session = getSessionFactory().openSession(); try { trs = session.beginTransaction(); session.saveOrUpdate(entity); session.getTransaction().commit(); } catch (RuntimeException e) { if (trs != null) { trs.rollback(); } } finally { session.flush(); session.close(); } }
From source file:com.copyright.common.hibernate.SimpleHibernateDao.java
License:Apache License
/** * ?.//from www . j av a2 s .c o m */ private void save1(final T entity) { Assert.notNull(entity, "entity?"); Session session = getSessionFactory().openSession(); Transaction tran = null; try { if (session != null) { tran = session.beginTransaction(); tran.begin(); session.saveOrUpdate(entity); tran.commit(); } } catch (Exception ex) { tran.rollback(); } finally { if (session != null) { session.close(); } } logger.debug("save entity: {}", entity); }