List of usage examples for org.hibernate Criteria uniqueResult
public Object uniqueResult() throws HibernateException;
From source file:com.actop.model.UserManagement.java
public boolean checkUser(String un) { Session s = Connection.getSessionFactory().openSession(); Criteria c = s.createCriteria(UserLogin.class); c.add(Restrictions.eq("un", convertToBytes(un))); UserLogin ul = (UserLogin) c.uniqueResult(); s.flush();//from www . j a va2s . c o m s.close(); if (ul != null) { return false; } else { return true; } }
From source file:com.actop.model.UserManagement.java
public UserLogin checkLogin(String un, String pw) { Session s = Connection.getSessionFactory().openSession(); Criteria c = s.createCriteria(UserLogin.class); c.add(Restrictions.eq("un", convertToBytes(un))); c.add(Restrictions.eq("pw", convertToBytes(pw))); UserLogin ul = (UserLogin) c.uniqueResult(); s.flush();/*from w ww . j a v a 2 s . c o m*/ s.close(); return ul; }
From source file:com.actop.model.UserManagement.java
public DepartmentsHasDesignation saveDepartmentHasDesignation(Departments department, Designation designation, Employers emp) {/*w w w. ja v a 2 s .c om*/ Session s = Connection.getSessionFactory().openSession(); Criteria c = s.createCriteria(DepartmentsHasDesignation.class); c.add(Restrictions.eq("employers", emp)); DepartmentsHasDesignation departmentsHasDesignation; departmentsHasDesignation = (DepartmentsHasDesignation) c.uniqueResult(); if (departmentsHasDesignation == null) { Transaction t = s.beginTransaction(); departmentsHasDesignation = new DepartmentsHasDesignation(); try { departmentsHasDesignation.setDepartments(department); departmentsHasDesignation.setDesignation(designation); departmentsHasDesignation.setEmployers(emp); s.save(departmentsHasDesignation); } catch (Exception e) { t.rollback(); e.printStackTrace(); } t.commit(); } s.flush(); s.close(); return departmentsHasDesignation; }
From source file:com.actop.model.UserManagement.java
public DepartmentsHasDesignation getDepartmentHasDesignation(Employers emp) { Session s = Connection.getSessionFactory().openSession(); Criteria c = s.createCriteria(DepartmentsHasDesignation.class); c.add(Restrictions.eq("employers", emp)); DepartmentsHasDesignation departmentsHasDesignation; departmentsHasDesignation = (DepartmentsHasDesignation) c.uniqueResult(); s.flush();/*from w w w . jav a2 s. com*/ s.close(); return departmentsHasDesignation; }
From source file:com.age.core.orm.hibernate.SimpleHibernateDao.java
License:Apache License
public T findUnique(final Criteria criteria) { return (T) criteria.uniqueResult(); }
From source file:com.algomedica.dao.LicenseDaoImpl.java
License:Open Source License
@Override public LicenseDetail getLicenceByMacAddress(String macAddress) { LicenseDetail licenseDetail = null;/* w ww . j a v a 2 s . c om*/ try { Criteria criteria = createEntityCriteria(); criteria.add(Restrictions.eq("lsMacAddress", macAddress)); criteria.add(Restrictions.eq("lsStatus", (byte) 1)); licenseDetail = (LicenseDetail) criteria.uniqueResult(); } catch (Exception ex) { System.out.println(ex); throw new ORMException(ex); } return licenseDetail != null ? licenseDetail : null; }
From source file:com.algomedica.dao.LicenseDaoImpl.java
License:Open Source License
@Override public LicenseDetail getLicenseById(long id) { LicenseDetail licenseDetail = null;/*from ww w . ja va 2 s . co m*/ try { //licenseDetail=getByKey(id); Criteria criteria = createEntityCriteria(); criteria.add(Restrictions.eq("id", id)); licenseDetail = (LicenseDetail) criteria.uniqueResult(); } catch (Exception e) { throw new ORMException(e); } return licenseDetail != null ? licenseDetail : null; }
From source file:com.all.client.model.LocalModelDao.java
License:Apache License
public TrackFile findTrackFileByPath(final String path) { return hibernateTemplate.execute(new HibernateCallback<TrackFile>() { @Override//w w w . j a v a 2 s. c o m public TrackFile doInHibernate(Session session) throws SQLException { Criteria criteria = session.createCriteria(TrackFile.class); criteria.add(Restrictions.eq("filename", path)); return (TrackFile) criteria.uniqueResult(); } }); }
From source file:com.all.client.model.LocalModelDao.java
License:Apache License
public LocalTrack findByUrnSha1(final String hashcode) { return hibernateTemplate.execute(new HibernateCallback<LocalTrack>() { @Override// w w w . java 2 s . co m public LocalTrack doInHibernate(Session session) throws HibernateException, SQLException { Criteria criteria = session.createCriteria(LocalTrack.class); criteria.add(Restrictions.like("downloadString", "%urnsha1=" + hashcode + "%")); return (LocalTrack) criteria.uniqueResult(); } }); }
From source file:com.anite.zebra.hivemind.manager.impl.HibernateTimeManager.java
License:Apache License
public Time createOrFetchTime(int hours, int mins) { Criteria criteria = getSession().createCriteria(Time.class); criteria.add(Restrictions.eq("hour", hours)); criteria.add(Restrictions.eq("minute", mins)); Time result = (Time) criteria.uniqueResult(); if (result == null) { result = new Time(); result.setHour(hours);//from w ww .j a va 2 s . c om result.setMinute(mins); this.saveOrUpdate(result); } return result; }