List of usage examples for org.hibernate Session createQuery
@Override org.hibernate.query.Query createQuery(CriteriaDelete deleteQuery);
From source file:au.edu.anu.metadatastores.rdf.RDFService.java
License:Open Source License
public void updateFromSpecifiedSystem(String extSystem) { Session session = StoreHibernateUtil.getSessionFactory().openSession(); try {/*from w w w . j av a 2s . co m*/ org.hibernate.Query query = session.createQuery("FROM Item WHERE extSystem = :extSystem"); query.setParameter("extSystem", extSystem); @SuppressWarnings("unchecked") List<Item> items = query.list(); update(items); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.rdf.RDFService.java
License:Open Source License
/** * Update the system types/*from w ww . j av a 2s . c o m*/ */ public void updateSystemTypes() { Session session = StoreHibernateUtil.getSessionFactory().openSession(); try { org.hibernate.Query query = session.createQuery("FROM SystemType"); //TODO add graph capabilities into code! @SuppressWarnings("unchecked") List<SystemType> systemTypes = query.list(); for (SystemType sysType : systemTypes) { save(sysType.getExtSystem(), sysType); } } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.ContractId.java
License:Open Source License
/** * Get the university ids of the investigators for the given contract * /*from w w w .j a v a 2s.co m*/ * @param contractId The id of the contract to retrieve university ids for * @return The associated university ids */ public String[] getInvestigatorUniId(String contractId) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session .createQuery("from ContractsGrantsInvestigators where chrContractCode = :contractId"); query.setParameter("contractId", contractId); @SuppressWarnings("unchecked") List<ContractsGrantsInvestigators> investigators = query.list(); List<String> staffIds = new ArrayList<String>(); for (ContractsGrantsInvestigators investigator : investigators) { if (investigator != null) { if (investigator.getChrStaffNumber() != null && !staffIds.contains(investigator.getChrStaffNumber())) { staffIds.add(investigator.getChrStaffNumber()); } } } return staffIds.toArray(new String[0]); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.ContractId.java
License:Open Source License
/** * Get the funds provider reference number of the grant * /*from w ww . jav a2s . com*/ * @param anuActivityId The grant id * @return The reference number */ public String getANUActivityAuthorizeID(String anuActivityId) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from ContractsGrantsMain where chrContractCode = :activityId"); query.setParameter("activityId", anuActivityId); @SuppressWarnings("unchecked") List<ContractsGrantsMain> grants = query.list(); String authorId = null; if (grants != null && grants.size() > 0) { authorId = grants.get(0).getChrSchemeRef(); } return authorId; } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.ContractId.java
License:Open Source License
/** * Get the grant description/*from ww w . j a va2 s.c o m*/ * * @param anuActivityId The grant id * @return The description */ public String getANUActivityDesc(String anuActivityId) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from ContractsGrantsMain where chrContractCode = :activityId"); query.setParameter("activityId", anuActivityId); @SuppressWarnings("unchecked") List<ContractsGrantsMain> grants = query.list(); String description = null; if (grants != null && grants.size() > 0) { description = grants.get(0).getChrShortTitle(); } return description; } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.ContractId.java
License:Open Source License
/** * Get all the ids of the people that are involved in grants * /*from ww w. jav a2s. c o m*/ * @return The array of grant ids */ public String[] getAllContractInvestigatorCode() { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { @SuppressWarnings("unchecked") List<ContractsGrantsInvestigators> investigators = session .createQuery("from ContractsGrantsInvestigators").list(); List<String> codes = new ArrayList<String>(); String investigatorCode = null; for (ContractsGrantsInvestigators investigator : investigators) { if (investigator != null) { investigatorCode = investigator.getChrContractInvestigatorCode(); if (investigatorCode != null && !codes.contains(investigatorCode)) { codes.add(investigatorCode); } } } return codes.toArray(new String[0]); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.ContractId.java
License:Open Source License
/** * Get the grants associated with the given university * /*from w w w. j av a 2 s .c o m*/ * @param uniID The university id * @return The array of grants */ public ANUActivity[] getActivitiesByUniID(String uniID) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from ContractsGrantsInvestigators where chrStaffNumber = :uniID"); query.setParameter("uniID", uniID); @SuppressWarnings("unchecked") List<ContractsGrantsInvestigators> investigators = query.list(); List<ANUActivity> activities = new ArrayList<ANUActivity>(); ANUActivityImpl tempActivity = null; String investigatorCode = null; for (ContractsGrantsInvestigators investigator : investigators) { investigatorCode = investigator.getChrContractInvestigatorCode(); investigatorCode = investigatorCode.substring(0, investigatorCode.indexOf(uniID)); if (investigatorCode != null) { tempActivity = new ANUActivityImpl(); tempActivity.setActivityId(investigatorCode); //TODO flesh this out // tempActivity.setFirstInvestigatorId(uniID); activities.add(tempActivity); } } return activities.toArray(new ANUActivity[0]); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.DepartmentId.java
License:Open Source License
/** * Get a list of department ids/*from w ww .ja v a 2 s. co m*/ * * @return The department ids */ public String[] getDepartmentIDs() { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { @SuppressWarnings("unchecked") List<ContractsGrantsDepartments> departments = session.createQuery("from ContractsGrantsDepartments") .list(); List<String> departmentIds = new ArrayList<String>(); for (ContractsGrantsDepartments department : departments) { if (department != null && department.getId() != null && !departmentIds.contains(department.getId().getChrDepartmentCode())) { departmentIds.add(department.getId().getChrDepartmentCode()); } } return departmentIds.toArray(new String[0]); } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.DepartmentId.java
License:Open Source License
/** * Get an array of department names given the department ids * //from w ww .j a va2 s . c om * @param departmentIDs The department ids to get the name of * @return The array of department names */ public String[] getDepartmentNames(String[] departmentIDs) { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { Query query = session.createQuery("from Departments where trim(chrTier3code) in :departmentIDs"); query.setParameterList("departmentIDs", departmentIDs); @SuppressWarnings("unchecked") List<Departments> departments = query.list(); String[] departmentNames = new String[departmentIDs.length]; boolean foundDepartment = false; String departmentName = null; for (int i = 0; i < departmentIDs.length; i++) { for (Departments department : departments) { if (department != null) { department.getId().getChrTier3code().trim(); if (department.getId().getChrTier3code().trim().equals(departmentIDs[i])) { departmentName = department.getId().getChrTier3name(); foundDepartment = true; break; } } } if (foundDepartment) { departmentNames[i] = departmentName; } else { departmentNames[i] = "No name found for this department ID"; } foundDepartment = false; } return departmentNames; } finally { session.close(); } }
From source file:au.edu.anu.metadatastores.services.aries.OutputId.java
License:Open Source License
/** * Returns all the output 6 codes found in Aries * /*from ww w . j a v a 2s . com*/ * @return The output 6 codes */ public String[] getAllOutput6Codes() { Session session = AriesHibernateUtil.getSessionFactory().openSession(); try { @SuppressWarnings("unchecked") List<ResearchOutputsData1> researchOutputs = session.createQuery("from ResearchOutputsData1").list(); List<String> outputCodes = new ArrayList<String>(); for (ResearchOutputsData1 researchOutput : researchOutputs) { if (researchOutput != null && researchOutput.getChrOutput6code() != null && !outputCodes.contains(researchOutput.getChrOutput6code())) { outputCodes.add(researchOutput.getChrOutput6code()); } } return outputCodes.toArray(new String[0]); } finally { session.close(); } }