List of usage examples for org.hibernate Session clear
void clear();
From source file:com.iaito.atsws.services.ClientServiceImpl.java
@Override public String tagArrived(TagMovement movement) { Transaction tx;// w w w .j a v a 2 s . co m Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { tx = session.beginTransaction(); TagLog tagLog = new TagLog(movement.getTagData(), movement.getReader_id(), 1, movement.getTime(), 0, "null", 0, 0); session.save(tagLog); session.flush(); session.clear(); tx.commit(); return "successfully entered"; } catch (Exception e) { session.getTransaction().rollback(); System.out.println( "Exception from -------------ClientServiceImpl.java----tagArrived()--" + e.getMessage()); } return "fail"; }
From source file:com.iaito.atsws.services.ClientServiceImpl.java
@Override public String tagDeparted(TagMovement movement) { Transaction tx;/*from w w w . j a v a 2 s. c o m*/ Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { tx = session.beginTransaction(); String s = "select * from tag_log w where tag_data='" + movement.getTagData() + "' and at_reader='" + movement.getReader_id() + "' and arrival=1 and departure=0"; Query query = session.createSQLQuery(s).addEntity(TagLog.class); List<TagLog> tagLogList = (List<TagLog>) query.list(); for (TagLog t : tagLogList) { t.setDeparture(1); t.setDepartureTime(movement.getTime()); session.update(t); } session.flush(); session.clear(); tx.commit(); return "successfully entered"; } catch (Exception e) { session.getTransaction().rollback(); System.out.println( "Exception from -------------ClientServiceImpl.java----tagDeparted()--" + e.getMessage()); } return "fail"; }
From source file:com.iaito.atsws.services.ClientServiceImpl.java
@Override public String tabArrived(TagMovement movement) { Transaction tx;/*from w w w .j a va 2 s . com*/ Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { tx = session.beginTransaction(); String s = "select * from tab_position w where tab_mac_address='" + movement.getTagData() + "'"; Query query = session.createSQLQuery(s).addEntity(TabPosition.class); List<TabPosition> tabPositionList = (List<TabPosition>) query.list(); if (tabPositionList.isEmpty()) { TabPosition tabPosition = new TabPosition(movement.getTagData(), movement.getReader_id()); session.save(tabPosition); } else { for (TabPosition tb : tabPositionList) { tb.setReader(movement.getReader_id()); session.update(tb); } } session.flush(); session.clear(); tx.commit(); return "success"; } catch (Exception e) { session.getTransaction().rollback(); System.out.println( "Exception from -------------ClientServiceImpl.java----tabArrived()--" + e.getMessage()); } return "fail"; }
From source file:com.iaito.atsws.services.ClientServiceImpl.java
@Override public String tabDeparted(TagMovement movement) { Transaction tx;/*from w ww.j av a 2 s . c o m*/ Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { tx = session.beginTransaction(); String s = "select * from tab_position w where tab_mac_address='" + movement.getTagData() + "'"; Query query = session.createSQLQuery(s).addEntity(TabPosition.class); List<TabPosition> tabPositionList = (List<TabPosition>) query.list(); if (tabPositionList.isEmpty()) { TabPosition tabPosition = new TabPosition(movement.getTagData(), "null"); session.save(tabPosition); } else { for (TabPosition tb : tabPositionList) { tb.setReader("null"); session.update(tb); } } session.flush(); session.clear(); tx.commit(); return "success"; } catch (Exception e) { session.getTransaction().rollback(); System.out.println( "Exception from -------------ClientServiceImpl.java----tabDeparted()--" + e.getMessage()); } return "fail"; }
From source file:com.iaito.atsws.services.ClientServiceImpl.java
@Override public TagListToTab getTagsAtTabNew(String tab) { Transaction tx;/* w w w . j a v a 2s .c o m*/ Session session = HibernateUtil.getSessionFactory().getCurrentSession(); TagListToTab tagListTotab = null; List<TagLog> tagLogList = null; List<TagLog> entryTagLogList = new ArrayList<>(); List<TagLog> exitTagLogList = new ArrayList<>(); List<SkippedTag> skippedTagLogList = new ArrayList<>(); try { tx = session.beginTransaction(); String s = "select * from tab_position w where tab_mac_address='" + tab + "'"; Query query = session.createSQLQuery(s).addEntity(TabPosition.class); List<TabPosition> tabPositionList = (List<TabPosition>) query.list(); if (tabPositionList == null || tabPositionList.isEmpty()) { tagLogList = null; } else { TabPosition tabPosition = tabPositionList.get(tabPositionList.size() - 1); String s1 = "select * from tag_log w where at_reader='" + tabPosition.getReader() + "' and arrival=1 and departure=0 and entry_done=0"; Query query1 = session.createSQLQuery(s1).addEntity(TagLog.class); tagLogList = (List<TagLog>) query1.list(); for (TagLog taglog : tagLogList) { String s2 = "select * from tag_log w where tag_data='" + taglog.getTagData() + "' and arrival=1 and departure=1 and entry_done!=0 ORDER BY arrival_time desc limit 1"; Query query2 = session.createSQLQuery(s2).addEntity(TagLog.class); List<TagLog> tagLogList2 = (List<TagLog>) query2.list(); if (tagLogList2 != null && !tagLogList2.isEmpty()) { TagLog tagLog2 = tagLogList2.get(tagLogList2.size() - 1); if (tagLog2.getAtReader().equals(taglog.getAtReader())) { if (tagLog2.getEntryDone() == 1) { exitTagLogList.add(taglog); } else if (tagLog2.getEntryDone() == 2) { // Again entering at same reader position entryTagLogList.add(taglog); } } else if (!tagLog2.getAtReader().equals(taglog.getAtReader())) { if (tagLog2.getEntryDone() == 1) { //Should exit from tagLog2.getAtReader() first skippedTagLogList.add(new SkippedTag(tagLog2.getAtReader(), "2", tagLog2)); } else if (tagLog2.getEntryDone() == 2) { entryTagLogList.add(taglog); } } } else { // This arrived tags never enter or exited before now. entryTagLogList.add(taglog); } } tagListTotab = new TagListToTab(tab, tabPosition.getReader()); tagListTotab.setEntryTagLogList(entryTagLogList); tagListTotab.setExitTagLogList(exitTagLogList); tagListTotab.setSkippedTagLogList(skippedTagLogList); } session.flush(); session.clear(); tx.commit(); return tagListTotab; } catch (Exception e) { session.getTransaction().rollback(); System.out.println( "Exception from -------------ClientServiceImpl.java----getTagsAtTabNew()--" + e.getMessage()); } return null; }
From source file:com.iaito.atsws.services.ClientServiceImpl.java
@Override public String postTags(EntryData entryData) { Transaction tx;//from w w w . j a v a2 s . c o m Session session = HibernateUtil.getSessionFactory().getCurrentSession(); try { tx = session.beginTransaction(); TagEntry tagentry = new TagEntry(new Date().toString(), entryData.getEntry_by(), entryData.getEntries().length, entryData.getTab(), entryData.getEntry_type()); Integer tagentryId = (Integer) session.save(tagentry); TagEntry tEntry = (TagEntry) session.get(TagEntry.class, tagentryId); for (Entry e : entryData.getEntries()) { TagLog tagLog = (TagLog) session.get(TagLog.class, Integer.parseInt(e.getTaglogId())); tagLog.setEntryDone(entryData.getEntry_type()); tagLog.setTagEntryId(tagentryId.intValue()); session.update(tagLog); } session.flush(); session.clear(); tx.commit(); return "successfully entered"; } catch (Exception e) { session.getTransaction().rollback(); System.out .println("Exception from -------------ClientServiceImpl.java----postTags()--" + e.getMessage()); } return "fail"; }
From source file:com.jdon.persistence.hibernate.HibernateTemplate.java
License:Apache License
public void clearSession() throws Exception { doHibernate(new HibernateCallback() { public Object execute(Session session) { session.clear(); return null; }/* www .j a v a 2 s. c o m*/ }); }
From source file:com.jfootball.dao.hibernate.ContinentDaoImpl.java
License:Open Source License
/** * Method to delete a nation//from w ww . j a v a 2s. co m * * @param nationId the nation id */ public void deleteContinent(Long continentId) { Session session = hibernateTemplate.getSessionFactory().getCurrentSession(); session.clear(); Continent continent = (Continent) hibernateTemplate.get(Continent.class, continentId); hibernateTemplate.delete(continent); }
From source file:com.jfootball.dao.hibernate.NationDaoImpl.java
License:Open Source License
/** * Method to delete a nation/* w ww . j a v a2 s . co m*/ * * @param nationId * the nation id */ public void deleteNation(Long nationId) { Session session = hibernateTemplate.getSessionFactory().getCurrentSession(); session.clear(); Nation nation = (Nation) hibernateTemplate.get(Nation.class, nationId); hibernateTemplate.delete(nation); }
From source file:com.jfootball.dao.hibernate.TeamDaoImpl.java
License:Open Source License
/** * Method to delete a team/*w w w .ja va2 s . c o m*/ * * @param teamId * the team id */ @Transactional public void deleteTeam(Long teamId) { logger.info("Delete team " + teamId); Session session = hibernateTemplate.getSessionFactory().getCurrentSession(); session.clear(); Team team = getTeamByID(teamId); hibernateTemplate.delete(team); logger.info("Team deleted"); }