List of usage examples for org.hibernate Session clear
void clear();
From source file:com.lzw.work.cms.services.AnjianDBMannager.java
public Integer getMaxNumber() { String sql = "select isnull(Max(Times),0)+1 from T_PoliceCheckYC b where (b.License=:licence) and (b.LicType=:licType) "; Session session = this.getHibernateTemplate().getSessionFactory().openSession(); try {// w w w . j a v a 2 s . c o m Query query = session.createQuery(sql); Long number = (Long) query.uniqueResult(); return number.intValue(); } finally { session.clear(); session.close(); } }
From source file:com.manages.AgentManage.java
public void add1(AgentBean a) { Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction();//from w ww .j av a2s. c o m Agent aa = new Agent(); aa.setFirstName(a.getFirst_name()); aa.setLastName(a.getLast_name()); aa.setAddress(a.getAddress()); aa.setTelephone(a.getTelephone()); aa.setEmail(a.getEmail()); aa.setImportAmmount(a.getImport_ammount()); aa.setImportType(a.getImport_type()); session.save(aa); session.getTransaction().commit(); session.flush(); session.clear(); session.close(); }
From source file:com.mercatis.lighthouse3.persistence.commons.hibernate.UnitOfWorkImplementation.java
License:Apache License
public void flush() { Session session = null; try {//from w ww . j a v a2 s .co m session = threadLocalSessions.get(); if (session == null) { return; } if (log.isDebugEnabled()) { log.debug("UnitOfWork: Flush Session: " + System.identityHashCode(session)); } session.flush(); session.clear(); } catch (Exception cause) { throw new PersistenceException("Could not flush unit of work", cause); } }
From source file:com.mg.framework.service.PersistentManagerHibernateImpl.java
License:Open Source License
public void flush() { Session s = getCurrentSession(); try {/*w ww. ja va2s .co m*/ s.flush(); } catch (JDBCException e) { s.clear(); throw SQLExceptionTranslatorManagerLocator.locate().translate(e.getSQLException()); } catch (CallbackException e) { throw convertCallbackExceptionToDatabaseException(e); } catch (Exception e) { try { ServerUtils.getCurrentTransaction().setRollbackOnly(); } catch (Exception ee) { //we do not want the subsequent exception to swallow the original one log.error("Unable to mark for rollback on Exception: ", ee); } if (e instanceof ApplicationException) throw (ApplicationException) e; else throw new DataAccessException(e); } }
From source file:com.mss.mirage.recruitment.ConsultantServiceImpl.java
License:Open Source License
public boolean attachResume(ConsultantAction consultantAction) throws ServiceLocatorException { boolean isInsert = false; try {// w w w . j a v a2s . c o m //for get session factory instance from hibernate service locator Session session = HibernateServiceLocator.getInstance().getSession(); Transaction trns = session.beginTransaction(); trns.begin(); // consultantAction.setDate(new Timestamp(new java.util.Date().getTime())); consultantAction.setDate(DateUtility.getInstance().getCurrentMySqlDateTime()); consultantAction.setObjectIdinInt(Integer.parseInt(consultantAction.getObjectId().trim())); //Save values in DataBase session.save(consultantAction); session.flush(); trns.commit(); isInsert = true; session.clear(); session.close(); } catch (Exception ex) { //System.err.println("Impl Catch "+ex.getMessage()); throw new ServiceLocatorException(ex); } return isInsert; }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public Map getGreenSheetClientBillingRate(String greenSheetCurrencykey) throws ServiceLocatorException { Map greenSheetCurrencyMap = new TreeMap();//key-Description if (CacheManager.getCache().containsKey(greenSheetCurrencykey)) { greenSheetCurrencyMap = (Map) CacheManager.getCache().get(greenSheetCurrencykey); } else {//from w ww . jav a 2 s .c o m //getting sessionFactory for the HibernateUtil class. Session session = HibernateServiceLocator.getInstance().getSession(); //Genarating a quary for retrieving the data from the database. String SQL_STG = "select tp.bdmID,tp.description from CrmGreenSheetCurrencyData as tp"; Query query = session.createQuery(SQL_STG); for (Iterator it = query.iterate(); it.hasNext();) { Object[] row = (Object[]) it.next(); //Storing values into the TreeMap. greenSheetCurrencyMap.put(row[0].toString(), row[1].toString()); } // closing for loop. CacheManager.getCache().put(greenSheetCurrencykey, greenSheetCurrencyMap); session.clear(); // Closing hibernate session try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } } } } // closing if condition. return greenSheetCurrencyMap;// returning the object. }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public List getGreenSheetStatus(String greenSheetStatuskey) throws ServiceLocatorException { List greenSheetStatusMap = new ArrayList();//Description if (CacheManager.getCache().containsKey(greenSheetStatuskey)) { greenSheetStatusMap = (List) CacheManager.getCache().get(greenSheetStatuskey); } else {// ww w.ja va2 s . c o m //getting sessionFactory for the HibernateUtil class. Session session = HibernateServiceLocator.getInstance().getSession(); //Genarating a quary for retrieving the data from the database. String SQL_STG = "select tp.description from CrmGreenSheetStatusData as tp"; Query query = session.createQuery(SQL_STG); for (Iterator it = query.iterate(); it.hasNext();) { String desc = (String) it.next(); //Storing values into the TreeMap. greenSheetStatusMap.add(desc); } // closing for loop. CacheManager.getCache().put(greenSheetStatuskey, greenSheetStatusMap); session.clear(); // Closing hibernate session try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } } } } // closing if condition. return greenSheetStatusMap;// returning the object. }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public List getGreenSheetPOStatus(String greenSheetPOStatuskey) throws ServiceLocatorException { List greenSheetPOStautsMap = new ArrayList();//Description if (CacheManager.getCache().containsKey(greenSheetPOStatuskey)) { greenSheetPOStautsMap = (List) CacheManager.getCache().get(greenSheetPOStatuskey); } else {//from ww w . j a v a 2 s . c o m //getting sessionFactory for the HibernateUtil class. Session session = HibernateServiceLocator.getInstance().getSession(); //Genarating a quary for retrieving the data from the database. String SQL_STG = "select tp.description from CrmGreenSheetPOStatusData as tp"; Query query = session.createQuery(SQL_STG); for (Iterator it = query.iterate(); it.hasNext();) { String desc = (String) it.next(); //Storing values into the TreeMap. greenSheetPOStautsMap.add(desc); } // closing for loop. CacheManager.getCache().put(greenSheetPOStatuskey, greenSheetPOStautsMap); session.clear(); // Closing hibernate session try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } } } } // closing if condition. return greenSheetPOStautsMap;// returning the object. }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public Map getGreenSheetScopeOfWorkList(String greenSheetScopeOfWorkkey) throws ServiceLocatorException { Map greenSheetScopeOfWork = new TreeMap();//key-Description if (CacheManager.getCache().containsKey(greenSheetScopeOfWorkkey)) { greenSheetScopeOfWork = (Map) CacheManager.getCache().get(greenSheetScopeOfWorkkey); } else {/*from w ww . ja va 2s . c o m*/ //getting sessionFactory for the HibernateUtil class. Session session = HibernateServiceLocator.getInstance().getSession(); //Genarating a quary for retrieving the data from the database. String SQL_STG = "select tp.bdmID,tp.description from CrmGreenSheetScopeOfWorkData as tp"; Query query = session.createQuery(SQL_STG); for (Iterator it = query.iterate(); it.hasNext();) { Object[] row = (Object[]) it.next(); //Storing values into the TreeMap. greenSheetScopeOfWork.put(row[0].toString(), row[1].toString()); } // closing for loop. CacheManager.getCache().put(greenSheetScopeOfWorkkey, greenSheetScopeOfWork); session.clear(); // Closing hibernate session try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } } } } // closing if condition. return greenSheetScopeOfWork;// returning the object. }
From source file:com.mss.mirage.util.HibernateDataProvider.java
License:Open Source License
public List getGreenSheetVPSalesList(String greenSheetVPSaleskey) throws ServiceLocatorException { List greenSheetVPSalesList = new ArrayList();//Description if (CacheManager.getCache().containsKey(greenSheetVPSaleskey)) { greenSheetVPSalesList = (List) CacheManager.getCache().get(greenSheetVPSaleskey); } else {/*from w w w. j av a 2 s . co m*/ //getting sessionFactory for the HibernateUtil class. Session session = HibernateServiceLocator.getInstance().getSession(); //Genarating a quary for retrieving the data from the database. String SQL_STG = "select tp.description from CrmGreenSheetVPSalesData as tp"; Query query = session.createQuery(SQL_STG); for (Iterator it = query.iterate(); it.hasNext();) { String desc = (String) it.next(); //Storing values into the TreeMap. greenSheetVPSalesList.add(desc); } // closing for loop. CacheManager.getCache().put(greenSheetVPSaleskey, greenSheetVPSalesList); session.clear(); // Closing hibernate session try { // Closing hibernate session session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } finally { if (session != null) { try { session.close(); session = null; } catch (HibernateException he) { throw new ServiceLocatorException(he); } } } } // closing if condition. return greenSheetVPSalesList;// returning the object. }