List of usage examples for org.hibernate Session saveOrUpdate
void saveOrUpdate(Object object);
From source file:com.forexnepal.dao.impl.CurrencyDAOImpl.java
@Override public int insertOrUpdate(Currency c) { Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); session.saveOrUpdate(c); transaction.commit();//from w w w. j a v a 2 s . com session.close(); return 1; }
From source file:com.forexnepal.dao.impl.ExchangeRatesDAOImpl.java
@Override public int insertOrUpdate(ExchangeRates e) { Session session = sessionFactory.openSession(); Transaction transaction = session.beginTransaction(); session.saveOrUpdate(e); //session.save(e); transaction.commit();/*from w w w . java 2 s . c o m*/ session.close(); return 1; }
From source file:com.gemstone.gemfire.modules.HibernateJUnitTest.java
License:Apache License
@Ignore @Test// w w w . j a v a 2s . co m public void testQueryCache() throws Exception { Session session = getSessionFactory(null).openSession(); Query q = session.createQuery("from Event"); q.setCacheable(true); List l = q.list(); log.info("list:" + l); // log.info("Sleeping for 10 seconds"); // Thread.sleep(10000); l = q.list(); log.info("list2:" + l); log.info("updating an event"); session.beginTransaction(); Event e = (Event) l.get(0); e.setDate(new Date()); session.saveOrUpdate(e); session.getTransaction().commit(); l = q.list(); log.info("list3:" + l); }
From source file:com.gianburga.servicios.model.TecnicoDAOImpl.java
@Override public Integer save(Tecnico tecnico) { Session session = mySessionFactory.getCurrentSession(); session.beginTransaction();// w ww . j a v a 2 s . c om session.saveOrUpdate(tecnico); session.getTransaction().commit(); return tecnico.getId(); }
From source file:com.github.leonardoxh.temporeal.model.dao.Dao.java
License:Apache License
public static void saveOrUpdate(Model model) { Session currentSession = HibernateUtils.getCurrentSession(); Transaction transaction = initTransaction(currentSession); try {// ww w . ja v a 2s. c o m currentSession.saveOrUpdate(model); transaction.commit(); } catch (Exception e) { e.printStackTrace(); transaction.rollback(); } }
From source file:com.glaf.jbpm.dao.JbpmEntityDAO.java
License:Apache License
public void saveOrUpdate(JbpmContext jbpmContext, Object model) { Session session = jbpmContext.getSession(); session.saveOrUpdate(model); }
From source file:com.globalsight.calendar.CalendarManagerLocal.java
License:Apache License
/** * @see CalendarManager.createCalendar(FluxCalendar) *///w ww . ja v a 2 s . c o m public FluxCalendar createCalendar(FluxCalendar p_calendar, String p_creatorUserId) throws RemoteException, CalendarManagerException { Session session = HibernateUtil.getSession(); Transaction tx = session.beginTransaction(); try { List holidays = p_calendar.getHolidaysList(); p_calendar.clearHolidayList(); p_calendar.setLastUpdatedBy(p_creatorUserId); p_calendar.setLastUpdatedTime(new Date()); session.save(p_calendar); for (int i = 0; i < holidays.size(); i++) { Holiday holiday = (Holiday) holidays.get(i); session.saveOrUpdate(holiday); p_calendar.addHoliday(holiday); } tx.commit(); } catch (Exception e) { tx.rollback(); throw new CalendarManagerException(CalendarManagerException.MSG_CREATE_CALENDAR_FAILED, null, e); } return findCalendarById(p_calendar.getId()); }
From source file:com.globalsight.calendar.CalendarManagerLocal.java
License:Apache License
/** * @see CalendarManager.importEntries(List) *//*from ww w . j a va2s . com*/ public void importEntries(List p_entries) throws RemoteException, CalendarManagerException { Session session = HibernateUtil.getSession(); Transaction tx = session.beginTransaction(); try { int size = p_entries.size(); HashMap map = new HashMap(); for (int i = 0; i < size; i++) { Entry entry = (Entry) p_entries.get(i); if (entry.isEntryValid()) { String username = entry.getUsername(); UserFluxCalendar cal = (UserFluxCalendar) map.get(username); if (cal == null) { cal = findUserCalendarByOwner(username, true); session.saveOrUpdate(cal); map.put(username, cal); } TimeZone tz = cal.getTimeZone(); // imported entry would be 'event' type. ReservedTime rt = new ReservedTime(entry.getSubject(), ReservedTime.TYPE_EVENT, createTimestamp(entry.getStartDate(), entry.getStartDateFormatType(), tz), 0, 0, createTimestamp(entry.getEndDate(), entry.getEndDateFormatType(), tz), 0, 0, null); session.save(rt); cal.addReservedTime(rt); session.saveOrUpdate(cal); } } tx.commit(); } catch (Exception e) { tx.rollback(); throw new CalendarManagerException(CalendarManagerException.MSG_FAILED_TO_IMPORT_ENTRIES, null, e); } }
From source file:com.globalsight.calendar.CalendarManagerLocal.java
License:Apache License
/** * @see CalendarManager.modifyHoliday(Holiday) *///from ww w .jav a 2 s . co m public Holiday modifyHoliday(Holiday p_holiday) throws RemoteException, CalendarManagerException { Session session = HibernateUtil.getSession(); Transaction tx = session.beginTransaction(); try { Holiday holiday = HibernateUtil.get(Holiday.class, p_holiday.getIdAsLong()); holiday.setName(p_holiday.getName()); holiday.setDayOfMonth(p_holiday.getDayOfMonth()); holiday.setDayOfWeek(p_holiday.getDayOfWeek()); holiday.setDescription(p_holiday.getDescription()); holiday.setEndingYear(p_holiday.getEndingYear()); holiday.setIsAbsolute(p_holiday.getIsAbsolute()); holiday.setMonth(p_holiday.getMonth()); holiday.setWeekOfMonth(p_holiday.getWeekOfMonth()); buildHolidayTimeExpression(holiday); session.saveOrUpdate(holiday); tx.commit(); return holiday; } catch (Exception e) { tx.rollback(); String[] args = { String.valueOf(p_holiday.getId()) }; throw new CalendarManagerException(CalendarManagerException.MSG_MODIFY_HOLIDAY_FAILED, args, e); } }
From source file:com.globalsight.everest.comment.CommentManagerLocal.java
License:Apache License
public Issue editIssue(long p_issueId, String p_title, String p_priority, String p_status, String p_category, String p_reportedBy, String p_comment, boolean share, boolean overwrite) throws RemoteException, CommentException { IssueImpl issue = null;/*from w ww . j a va2 s . c om*/ Session session = HibernateUtil.getSession(); Transaction tx = session.beginTransaction(); Connection conn = null; PreparedStatement stmt = null; try { issue = (IssueImpl) session.get(IssueImpl.class, new Long(p_issueId)); issue.setTitle(p_title); issue.setPriority(p_priority); issue.setStatus(p_status); issue.setCategory(p_category); issue.setOverwrite(overwrite); issue.setShare(share); if (p_reportedBy != null) { // edit the latest history if the user is the same // the latest history is the first in the list IssueHistoryImpl ih = (IssueHistoryImpl) issue.getHistory().get(0); if (ih.reportedBy().equals(p_reportedBy)) { // For the "changing comments not saved" issue, use jdbc to // update ISSUE_HISTORY table. conn = SqlUtil.hireConnection(); conn.setAutoCommit(false); String sqlUpdate = "update ISSUE_HISTORY set DESCRIPTION= ? ," + "REPORTED_DATE = ? " + " Where REPORTED_BY = ? and REPORTED_DATE = ?"; stmt = conn.prepareStatement(sqlUpdate); Date date = ih.dateReportedAsDate(); Date currentDate = Calendar.getInstance().getTime(); ih.dateReported(Calendar.getInstance().getTime()); ih.setComment(p_comment); session.saveOrUpdate(ih); stmt.setString(1, p_comment); stmt.setDate(2, new java.sql.Date(currentDate.getTime())); stmt.setString(3, p_reportedBy); stmt.setDate(4, new java.sql.Date(date.getTime())); stmt.executeUpdate(); conn.commit(); } } tx.commit(); } catch (Exception ex) { CATEGORY.error("Failed to edit issue.", ex); String[] args = { String.valueOf(p_issueId), p_reportedBy }; throw new CommentException(CommentException.MSG_FAILED_TO_EDIT_ISSUE, args, ex); } finally { DbUtil.silentClose(stmt); SqlUtil.fireConnection(conn); // session.close(); } return issue; }