/** {@inheritDoc} */ @Override public void put(@Nullable GridCacheTx tx, K key, @Nullable V val) throws GridException { init(); if (log.isDebugEnabled()) log.debug("Store put [key=" + key + ", val=" + val + ", tx=" + tx + ']'); if (val == null) { remove(tx, key); return; } Session ses = session(tx); try { GridCacheHibernateBlobStoreEntry entry = new GridCacheHibernateBlobStoreEntry(toBytes(key), toBytes(val)); ses.saveOrUpdate(entry); } catch (HibernateException e) { rollback(ses, tx); throw new GridException( "Failed to put value to cache store [key=" + key + ", val" + val + "]", e); } finally { end(ses, tx); } }
public boolean createUser(User user) { boolean result = false; if (user.getEmployeeId() != null) { User userById = getUserByEmployeeId(user.getEmployeeId()); if (userById != null) { MessageUtils.createMessage("Brugeren eksisterer allerede."); return false; } } Session session = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction = session.beginTransaction(); try { session.saveOrUpdate(user); result = true; session.flush(); transaction.commit(); } catch (StaleObjectStateException sose) { System.out.println("StaleObjectException"); transaction.rollback(); } catch (HibernateException e) { e.printStackTrace(); transaction.rollback(); result = false; } finally { if (session.isOpen()) { session.close(); } } return result; }
public Boolean addOrUpdateMedia(Session session, Media media) { try { // Need to save the loans before saving the media Map<Integer, Loan> tabEx = media.getTabExemplaries(); for (Iterator<Loan> i = tabEx.values().iterator(); i.hasNext(); ) session.saveOrUpdate(i.next()); // Persist the media session.saveOrUpdate(media); } catch (HibernateException pe) { System.err.println("Problème dans la sauvegarde "); pe.printStackTrace(); return false; } return true; }
public void guardaActualiza(TbAplicativo tbAplicativo) { try { iniciaOperacion(); sesion.saveOrUpdate(tbAplicativo); tx.commit(); sesion.flush(); } catch (HibernateException he) { manejaExcepcion(he); throw he; } finally { sesion.close(); } }
public void saveObject(Object entity) { Session session = SessionFactoryUtil.getInstance().getCurrentSession(); Transaction transaction = null; try { transaction = session.beginTransaction(); session.saveOrUpdate(entity); transaction.commit(); } catch (HibernateException e) { transaction.rollback(); e.printStackTrace(); } finally { if (session.isOpen()) { session.disconnect(); session.close(); } } }
@Override public void saveSubscription(Subscription subscription) { // TODO Auto-generated method stub Session session = this.sessionFactory.openSession(); Transaction tx = null; try { tx = session.beginTransaction(); session.saveOrUpdate(subscription); tx.commit(); // System.out.println("Subscription Committed.."); } catch (HibernateException e) { if (tx != null) { tx.rollback(); e.printStackTrace(); } } finally { session.close(); } }
@Override public void saveOrUpdate(Collection<T> entities) { Session session = getSession(); for (T item : entities) session.saveOrUpdate(item); }