List of usage examples for org.hibernate Query uniqueResult
R uniqueResult();
From source file:at.thinkingco2.databasemanager.CarAccess.java
/** * This function returns a CarBean specified by its LicenseNumber * /*from w w w .j a v a 2 s .c o m*/ * @param licenseNumber * the LicenseNumber of the searched Car * @return the CarBean */ public CarBean getCarByLicenseNumber(String licenseNumber) { Session session = getSession(); CarBean bean = null; Query q = null; q = session.createQuery("FROM CarBean WHERE licenseNumber = :licenseNumber"); q.setParameter("licenseNumber", licenseNumber); bean = (CarBean) q.uniqueResult(); session.close(); return bean; }
From source file:at.thinkingco2.databasemanager.JourneyAccess.java
public JourneyBean getJourney(int id) { Session session = getSession();/*from w w w.j a v a 2s .c om*/ Query q = session.createQuery("FROM JourneyBean WHERE journeyId = :id"); q.setParameter("id", id); JourneyBean res = (JourneyBean) q.uniqueResult(); session.close(); return res; }
From source file:at.thinkingco2.databasemanager.JourneyAccess.java
public JourneyBean getJourney(JourneyBean journeyBean) { Session session = getSession();/*from www . j a va 2s .c o m*/ Query q = session .createQuery("FROM JourneyBean WHERE description = :description AND arrivleTime = :arrivleTime"); q.setParameter("description", journeyBean.getDescription()); q.setParameter("arrivleTime", journeyBean.getArrivleTime()); JourneyBean res = (JourneyBean) q.uniqueResult(); session.close(); return res; }
From source file:attendance.ui.TakeAttendence.java
private void updateAttendance() { try {//from w ww.j a v a2s. co m Session session = HibernateUtil.getSessionFactory().openSession(); session.beginTransaction(); for (int i = 1; i < jTable1.getRowCount(); i++) { if (jTable1.getValueAt(i, 4).equals(false)) { continue; } else { String rollNo = (String) jTable1.getValueAt(i, 2); Query q = session.createQuery("from Attendance a where a.student=" + rollNo); Attendance a = (Attendance) q.uniqueResult(); a.setIsPresent(true); } } session.getTransaction().commit(); JOptionPane.showMessageDialog(this, "Attendance Updated Successfully"); } catch (HibernateException he) { he.printStackTrace(); } }
From source file:au.edu.anu.metadatastores.datamodel.aries.grants.ForCodesTest.java
License:Open Source License
/** * Queries for the fields of research in the database and prints them out *//*from w w w . j av a 2 s . c om*/ @Test public void test() { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("FROM ForCodes WHERE chrForObjectiveCode = :code"); query.setParameter("code", "111706"); ForCodes forSubject = (ForCodes) query.uniqueResult(); assertNotNull("No Field of Research Found", forSubject); assertEquals("No subject description found", "Epidemiology", forSubject.getChrForDescription()); assertEquals("No subject division code found", "11", forSubject.getChrForDivisionCode()); assertEquals("No subject group code found", "1117", forSubject.getChrForGroupCode()); assertEquals("No subject objective code found", "111706", forSubject.getChrForObjectiveCode()); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.harvester.Harvest.java
License:Open Source License
/** * Harvest the records from the given system * /* ww w . ja v a2 s . c o m*/ * @param harvestSystem The string of the system to harvest records for * @throws HarvestException */ public void harvest(String harvestSystem) throws HarvestException { Session session = HarvesterHibernateUtil.getSessionFactory().openSession(); Location location = null; try { Query query = session.createQuery("FROM Location WHERE system = :system"); query.setParameter("system", harvestSystem); location = (Location) query.uniqueResult(); } finally { session.close(); } if (location == null) { harvest(location); } else { throw new HarvestException("No location found for the system: " + harvestSystem); } }
From source file:au.edu.anu.metadatastores.services.aries.PublicationId.java
License:Open Source License
/** * Get a single publication with the given aries publication id * //from www .j av a 2 s .c o m * @param publicationId The publication id * @return The publication */ public Publication getSinglePublication(String publicationId) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from ResearchOutputsData1 where chrOutput6code = :publicationId"); query.setParameter("publicationId", publicationId); ResearchOutputsData1 researchOutput = (ResearchOutputsData1) query.uniqueResult(); Publication tempPublication = getPublication(researchOutput); return tempPublication; } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Get the information about the staff member * //from w w w . j a v a2 s .c o m * @param staffId The staff member to get information about * @return The staff members information */ public ANUStaff getStaffInformation(String staffId) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from Useraccounts where lower(chrStaffNumber) = :staffId"); query.setParameter("staffId", staffId.toLowerCase()); Useraccounts userAccount = (Useraccounts) query.uniqueResult(); if (userAccount == null) { return null; } ANUStaff staff = setStaffInformation(userAccount, session); return staff; } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Get external staff members information * /*from w w w. j a v a2s .c om*/ * @param staffId The id of the person to get staff information from * @return The external staff member information */ public ExternalStaff getExternalStaffInformation(String staffId) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from ExternalUsers where lower(chrCode) = :staffId"); query.setParameter("staffId", staffId); ExternalUsers externalUser = (ExternalUsers) query.uniqueResult(); if (externalUser == null) { return null; } ExternalStaff externalStaff = setExternalStaffInformation(externalUser); return externalStaff; } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Populates the ANUStaff object with the staff information from aries * /* w ww . j a v a2 s.co m*/ * @param userAccount The useraccount * @param session The hibernate session object * @return The ANUStaff information */ private ANUStaff setStaffInformation(Useraccounts userAccount, Session session) { ANUStaff staff = new ANUStaffImpl(); staff.setAriesId(userAccount.getIntSystemCounter()); staff.setUniId(userAccount.getChrStaffNumber()); staff.setTitle(userAccount.getChrTitle()); staff.setGivenName(userAccount.getChrFirstname()); staff.setSurname(userAccount.getChrSurname()); staff.setFax(userAccount.getChrFax()); staff.setPhone(userAccount.getChrTelephone()); staff.setEmail(userAccount.getChrEmail()); if (userAccount.getForCodes1() != null) { Subject forSubject = new FORSubjectImpl(userAccount.getForCodes1().getChrForObjectiveCode(), userAccount.getForCodes1().getChrForDescription(), userAccount.getChrForpercentage1()); staff.setForSubject1(forSubject); } if (userAccount.getForCodes2() != null) { Subject forSubject = new FORSubjectImpl(userAccount.getForCodes2().getChrForObjectiveCode(), userAccount.getForCodes2().getChrForDescription(), userAccount.getChrForpercentage2()); staff.setForSubject2(forSubject); } if (userAccount.getForCodes3() != null) { Subject forSubject = new FORSubjectImpl(userAccount.getForCodes3().getChrForObjectiveCode(), userAccount.getForCodes3().getChrForDescription(), userAccount.getChrForpercentage3()); staff.setForSubject3(forSubject); } Query departmentQuery = session.createQuery("from Departments where chrTier3Code = :departmentId"); departmentQuery.setParameter("departmentId", userAccount.getChrDepartmentCode()); Departments departmentRes = (Departments) departmentQuery.uniqueResult(); if (departmentRes != null) { Departments department = (Departments) departmentRes; staff.setDepartmentName(department.getId().getChrTier3name()); } return staff; }