List of usage examples for org.hibernate Session createQuery
@Override org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Find staff by their surname//w ww . j a v a 2s.co m * * @param surname The surname of the people to find * @return Staff members with the given surname */ public ANUStaff[] findStaffBySurname(String surname) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from Useraccounts where lower(chrSurname) = :surname"); query.setParameter("surname", surname.toLowerCase()); @SuppressWarnings("unchecked") List<Useraccounts> users = query.list(); List<ANUStaff> anuStaff = new ArrayList<ANUStaff>(); ANUStaff staff = null; for (Useraccounts user : users) { staff = setStaffInformation(user, session); anuStaff.add(staff); } return anuStaff.toArray(new ANUStaff[0]); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Find staff by their given name/*from ww w. ja v a 2 s. c om*/ * * @param givenName The given name of the people to find * @return Staff members with the provided given name */ public ANUStaff[] findStaffByGivenName(String givenName) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from Useraccounts where lower(chrFirstname) = :firstname"); query.setParameter("firstname", givenName.toLowerCase()); @SuppressWarnings("unchecked") List<Useraccounts> users = query.list(); List<ANUStaff> anuStaff = new ArrayList<ANUStaff>(); ANUStaff staff = null; for (Useraccounts user : users) { staff = setStaffInformation(user, session); anuStaff.add(staff); } return anuStaff.toArray(new ANUStaff[0]); } 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 * /*from w w w .j av a 2 s .c o 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; }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Find external staff by their name//from w w w .ja v a 2 s . co m * * @param surname The surname of the person to find * @param givenName The given name of the person to find * @return A list of external staff members who match the provided name */ public ExternalStaff[] findExternalStaff(String surname, String givenName) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { List<ExternalStaff> externalStaff = new ArrayList<ExternalStaff>(); Query query = session.createQuery( "from ExternalUsers where lower(chrFirstname) = :firstname and lower(chrSurname) = :surname"); query.setParameter("firstname", givenName); query.setParameter("surname", surname); @SuppressWarnings("unchecked") List<ExternalUsers> users = query.list(); ExternalStaff staff = null; for (ExternalUsers user : users) { staff = setExternalStaffInformation(user); externalStaff.add(staff); } return externalStaff.toArray(new ExternalStaff[0]); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Find external staff by their surname//from ww w . j a va 2 s. co m * * @param surname The surname to search on * @return The external staff members with the provided surname */ public ExternalStaff[] findExternalStaffBySurname(String surname) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { List<ExternalStaff> externalStaff = new ArrayList<ExternalStaff>(); Query query = session.createQuery("from ExternalUsers where lower(chrSurname) = :surname"); query.setParameter("surname", surname.toLowerCase()); @SuppressWarnings("unchecked") List<ExternalUsers> users = query.list(); ExternalStaff staff = null; for (ExternalUsers user : users) { staff = setExternalStaffInformation(user); externalStaff.add(staff); } return externalStaff.toArray(new ExternalStaff[0]); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.StaffId.java
License:Open Source License
/** * Find external staff by their given name * /*from ww w . ja v a2s. co m*/ * @param givenName The given name to search on * @return The external staff members with the provided given name */ public ExternalStaff[] findExternalStaffByGivenName(String givenName) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { List<ExternalStaff> externalStaff = new ArrayList<ExternalStaff>(); Query query = session.createQuery("from ExternalUsers where lower(chrFirstname) = :firstname"); query.setParameter("firstname", givenName.toLowerCase()); @SuppressWarnings("unchecked") List<ExternalUsers> users = query.list(); ExternalStaff staff = null; for (ExternalUsers user : users) { staff = setExternalStaffInformation(user); externalStaff.add(staff); } return externalStaff.toArray(new ExternalStaff[0]); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.store.datacommons.DataCommonsService.java
License:Open Source License
/** * Process records that have the deleted status from oai-pmh * //from ww w . j a va 2 s .c om * @param content The harvested record to process */ private void processDeleted(HarvestContent content) { Session session = StoreHibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); Query query = session .createQuery("FROM DataCommonsItem WHERE extSystem = :extSystem AND extId = :extId"); query.setParameter("extSystem", extSystem); query.setParameter("extId", content.getIdentifier()); DataCommonsItem item = (DataCommonsItem) query.uniqueResult(); if (item != null) { item.setDeleted(Boolean.TRUE); session.merge(item); } else { LOGGER.debug("No record to be deleted: {}", content.getIdentifier()); } session.getTransaction().commit(); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.store.datacommons.DataCommonsService.java
License:Open Source License
/** * Process a record that has not been deleted * /*from w w w .jav a2 s. c o m*/ * @param content The harvested record to process */ private void processRecord(HarvestContent content) { Session session = StoreHibernateUtil.getSessionFactory().openSession(); try { session.beginTransaction(); session.enableFilter("attributes"); Query query = session .createQuery("FROM DataCommonsItem WHERE extSystem = :extSystem AND extId = :extId"); query.setParameter("extSystem", extSystem); query.setParameter("extId", content.getIdentifier()); DataCommonsItem item = (DataCommonsItem) query.uniqueResult(); if (item == null) { item = new DataCommonsItem(); item.setExtId(content.getIdentifier()); session.save(item); } try { JAXBContext context = JAXBContext.newInstance(DublinCore.class); Unmarshaller unmarshaller = context.createUnmarshaller(); DublinCore dublinCore = (DublinCore) unmarshaller.unmarshal(new StringReader(content.getContent())); Date lastModified = new Date(); super.processRecord((DublinCoreItem) item, dublinCore, session, lastModified); } catch (JAXBException e) { LOGGER.error("Exception transforming document", e); } catch (InvocationTargetException e) { LOGGER.error("Error invoking method", e); } catch (IllegalAccessException e) { LOGGER.error("Error accessing method", e); } session.merge(item); LOGGER.debug("Item Numbers: {}", item.getItemAttributes().size()); session.getTransaction().commit(); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.store.datacommons.DataCommonsService.java
License:Open Source License
/** * Add relationships based on identifiers in the item * /* ww w .j a v a 2s. co m*/ * @param item The item to add relationships to * @param relationParts The relationship parts * @param itemRelations The existing relationships * @param session The session */ private void setIdentifierRelations(Item item, List<RelationPart> relationParts, List<ItemRelation> itemRelations, Session session) { Query query = session.createQuery( "SELECT i FROM Item i join i.itemAttributes ia WHERE ia.attrType = :attrType AND ia.attrValue = :attrValue"); query.setParameter("attrType", StoreAttributes.IDENTIFIER); for (RelationPart relationPart : relationParts) { query.setParameter("attrValue", relationPart.getValue()); LOGGER.debug("Item: {}, Value: {}", relationPart.getValue(), relationPart.getType()); @SuppressWarnings("unchecked") List<Item> relItems = query.list(); String relationType = getRelationType(relationPart.getType()); for (Item relItem : relItems) { ItemRelationId itemRelationId = new ItemRelationId(item.getIid(), relationType, relItem.getIid()); ItemRelation itemRelation = new ItemRelation(); itemRelation.setId(itemRelationId); itemRelations.add(itemRelation); } } }
From source file:au.edu.anu.metadatastores.store.datacommons.DataCommonsService.java
License:Open Source License
/** * Set the grant identifier relationships * /*from w ww . j ava 2 s. co m*/ * @param item The item to add relationships to * @param relationParts The relationship parts * @param itemRelations The existing item relations * @param session The session * @param fundsPrefix The prefix of the grant * @param fundsProvider The name of the funds provider */ private void setGrantIdentifierRelations(Item item, List<RelationPart> relationParts, List<ItemRelation> itemRelations, Session session, String fundsPrefix, String fundsProvider) { Query query = session.createQuery( "SELECT gr from GrantItem gr join gr.itemAttributes fundProv join gr.itemAttributes refNum where fundProv.attrType = :fundType and fundProv.attrValue = :fundProvValue and refNum.attrType = :refType and refNum.attrValue = :refValue"); query.setParameter("fundType", StoreAttributes.FUNDS_PROVIDER); query.setParameter("refType", StoreAttributes.REFERENCE_NUMBER); query.setParameter("fundProvValue", fundsProvider); int prefixLength = fundsPrefix.length(); for (RelationPart relationPart : relationParts) { LOGGER.debug("Relation: {}, {}", relationPart.getValue(), relationPart.getType()); if (relationPart.getValue().startsWith(fundsPrefix)) { LOGGER.debug("Is a Grant: {}", relationPart.getValue()); String id = relationPart.getValue().substring(prefixLength); query.setParameter("refValue", id); @SuppressWarnings("unchecked") List<Item> grants = query.list(); String relationType = getRelationType(relationPart.getType()); for (Item grant : grants) { LOGGER.debug("ID: {}, Title: {}", grant.getIid(), grant.getTitle()); ItemRelationId itemRelationId = new ItemRelationId(item.getIid(), relationType, grant.getIid()); ItemRelation itemRelation = new ItemRelation(); itemRelation.setId(itemRelationId); itemRelations.add(itemRelation); } } } }