Example usage for org.hibernate Query setParameterList

List of usage examples for org.hibernate Query setParameterList

Introduction

In this page you can find the example usage for org.hibernate Query setParameterList.

Prototype

Query<R> setParameterList(int position, Object[] values);

Source Link

Usage

From source file:ar.com.zauber.commons.web.cache.impl.repo.hibernate.HibernateLastModifiedRepository.java

License:Apache License

/** @see LastModifiedRepository#getMaxTimestamp(List) */
public final Long getMaxTimestamp(final List<StringEntityKey> keys) {
    if (keys.size() == 0) {
        return this.getTimestamp(keys.get(0));
    }//from   ww  w .  ja v  a 2s.c  o  m

    String[] keyStrings = new String[keys.size()];
    for (int i = 0; i < keys.size(); i++) {
        keyStrings[i] = keys.get(i).getAsString();
    }

    Query query = this.sessionFactory.getCurrentSession()
            .getNamedQuery("lastModified.orderedTimestampsForEntities");

    query.setParameterList("entitiesKey", keyStrings);
    query.setMaxResults(1);
    return (Long) query.uniqueResult();
}

From source file:au.com.nicta.ct.solution.tracking.CtTrackingModel.java

License:Open Source License

protected void deleteTracks(boolean showProgress) { // i.e. all tracks

    if (!valid())
        return;/*from   w w w.  j av a  2s. com*/

    //        CtSolutions solution = (CtSolutions)CtObjectDirectory.get( "solution" );

    //        String hql1 = " DELETE FROM CtTracksDetections td "
    //                    + " WHERE td.ctTracks IN ( "
    //                    + " SELECT t FROM CtTracks t "
    //                    + " INNER JOIN t.ctSolutions s "
    //                    + " WHERE s.pkSolution = " + solution.getPkSolution() +" ) ";

    String hql1 = " SELECT td FROM CtTracksDetections td " + " WHERE td.ctTracks IN ( "
            + " SELECT t FROM CtTracks t " + " INNER JOIN t.ctSolutions s " + " WHERE s.pkSolution = "
            + _s.getPkSolution() + " ) ";

    //        String hql1 = " SELECT t FROM CtTracks t "
    //                    + " INNER JOIN t.ctSolutions s "
    //                    + " WHERE s.pkSolution = " + solution.getPkSolution();// +" ) ";
    String hql2 = " DELETE FROM CtTracksDetections td " + " WHERE td IN (:vals) ";

    String hql3 = " DELETE FROM CtTracks t " + " WHERE t.ctSolutions = " + _s.getPkSolution();

    //        clear();

    Session session = CtSession.Current();
    session.beginTransaction();

    Query q1 = session.createQuery(hql1);
    List results = q1.list();

    if (results.isEmpty()) {
        session.getTransaction().commit();
        return; // mnothing changed
    }

    Query q2 = session.createQuery(hql2);

    q2.setParameterList("vals", results);

    int rowCount2 = q2.executeUpdate(); // this query fails

    Query q3 = session.createQuery(hql3);
    int rowCount3 = q3.executeUpdate();

    session.getTransaction().commit();
    session.refresh(_s);

    ////////////////////////////////////////////////////////////////////////
    // Manually refresh detections and tracks as seems to be a bug with 
    // their consistency
    ////////////////////////////////////////////////////////////////////////
    CtPageFrame.showWaitCursor();

    Set<CtDetections> cd = _s.getCtDetectionses();
    Set<CtTracks> ct = _s.getCtTrackses();

    for (CtDetections d : cd) {
        session.refresh(d);
    }

    for (CtTracks t : ct) {
        session.refresh(t);
    }

    CtPageFrame.showDefaultCursor();
    ////////////////////////////////////////////////////////////////////////

    refresh(_cc, _ism, _twm, _s, showProgress);
    //        fireModelChanged(); in update anyway
}

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  va 2 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.PublicationId.java

License:Open Source License

/**
 * Retrieve the first authors//from w  w w .  java 2s  . c  o  m
 * 
 * @param publicationCodes The publication codes
 * @return The first named authors
 */
public String[] getFirstAuthors(String[] publicationCodes) {
    Session session = AriesHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session
                .createQuery("from ResearchOutputsData1 where chrOutput6code in :publicationCodes");
        query.setParameterList("publicationCodes", publicationCodes);

        @SuppressWarnings("unchecked")
        List<ResearchOutputsData1> researchOutputs = query.list();

        List<String> firstAuthors = new ArrayList<String>();
        for (ResearchOutputsData1 researchOutput : researchOutputs) {
            if (researchOutput != null && researchOutput.getChrFirstNamedAuthor() != null) {
                firstAuthors.add(researchOutput.getChrFirstNamedAuthor());
            }
        }

        return firstAuthors.toArray(new String[0]);
    } finally {
        session.close();
    }
}

From source file:au.edu.anu.metadatastores.store.people.PersonService.java

License:Open Source License

/**
 * Retrieves a list of people with the given ids
 * /*from  www .  j a v  a 2  s.  c  o  m*/
 * @param extIds The ids to retrieve information about people for
 * @param extraInfo Indicates whether to also retrieve the type, institution, country and organisational unit about the person
 * @return A list of people containing basic information
 */
public List<Person> getBasicPeople(List<String> extIds, boolean extraInfo) {
    Session session = StoreHibernateUtil.getSessionFactory().openSession();
    try {
        Query query = session.createQuery(
                "select distinct pi from PersonItem as pi left join fetch pi.itemAttributes where pi.extId in (:extIds)");
        query.setParameterList("extIds", extIds);

        @SuppressWarnings("unchecked")
        List<PersonItem> personItems = query.list();
        LOGGER.debug("Number of People Found: {}", personItems.size());
        List<Person> people = new ArrayList<Person>();
        for (PersonItem personItem : personItems) {
            Person person = getBasicPerson(personItem, extraInfo);
            if (!people.contains(person)) {
                people.add(person);
            }
        }

        return people;
    } finally {
        session.close();
    }
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public long countNumberOfSubjectsThatAlreadyExistWithTheseUIDs(Study study, Collection<String> subjectUids) {
    String queryString = "select count(*) " + "from LinkSubjectStudy subject " + "where study =:study "
            + "and subjectUID in  (:subjects) ";
    Query query = getSession().createQuery(queryString);
    query.setParameter("study", study);
    query.setParameterList("subjects", subjectUids);

    return (Long) query.uniqueResult();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

public List<String> getSubjectUIDsThatAlreadyExistWithTheseUIDs(Study study, Collection<String> subjectUids) {
    String queryString = "select subject.subjectUID " + "from LinkSubjectStudy subject "
            + "where study =:study " + "and subjectUID in  (:subjects) ";
    Query query = getSession().createQuery(queryString);
    query.setParameter("study", study);
    query.setParameterList("subjects", subjectUids);

    return query.list();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

/**
 * based on sql concept of;4 select id from custom_field_display where custom_field_id in (SELECT id FROM custom_field where name='AGE' and
 * study_id = 1 and ark_function_id = 5)
 * //from  w  w w  . j av  a  2s  .com
 * @param fieldNameCollection
 * @param study
 * @return
 */
@SuppressWarnings("unchecked")
public List<CustomFieldDisplay> getCustomFieldDisplaysIn(List<String> fieldNameCollection, Study study,
        ArkFunction arkFunction) {

    if (fieldNameCollection == null || fieldNameCollection.isEmpty()) {
        return new ArrayList<CustomFieldDisplay>();
    } else {
        List<String> lowerCaseNames = new ArrayList<String>();
        for (String name : fieldNameCollection) {
            lowerCaseNames.add(name.toLowerCase());
        }
        String queryString = "select cfd " + "from CustomFieldDisplay cfd " + "where customField.id in ( "
                + " SELECT id from CustomField cf " + " where cf.study =:study "
                + " and lower(cf.name) in (:names) " + " and cf.arkFunction =:arkFunction )";
        Query query = getSession().createQuery(queryString);
        query.setParameter("study", study);
        // query.setParameterList("names", fieldNameCollection);
        query.setParameterList("names", lowerCaseNames);
        query.setParameter("arkFunction", arkFunction);
        return query.list();
    }
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

/**
 * based on sql concept of; select id from custom_field_display where custom_field_id in (SELECT id FROM custom_field where name='AGE' and study_id
 * = 1 and ark_function_id = 5)//from  www . j a v  a 2s  . c  om
 * 
 * @param fieldNameCollection
 * @param study
 * @return
 */
/*@SuppressWarnings("unchecked")
public List<CustomFieldDisplay> getCustomFieldDisplaysIn(List<String> fieldNameCollection, Study study, ArkFunction arkFunction, CustomFieldGroup customFieldGroup) {
        
   if (fieldNameCollection == null || fieldNameCollection.isEmpty()) {
 return new ArrayList<CustomFieldDisplay>();
   }
   else {
 List<String> lowerCaseNames = new ArrayList<String>();
 for (String name : fieldNameCollection) {
    lowerCaseNames.add(name.toLowerCase());
 }
 String queryString = "select cfd from CustomFieldDisplay cfd " + 
       " where cfd.customFieldGroup =:customFieldGroup and customField.id in ( " + 
       " SELECT id from CustomField cf " + 
       " where cf.study =:study " + " and lower(cf.name) in (:names) " + " and cf.arkFunction =:arkFunction )";
 Query query = getSession().createQuery(queryString); 
 query.setParameter("study", study);
 // query.setParameterList("names", fieldNameCollection);
 query.setParameterList("names", lowerCaseNames);
 query.setParameter("arkFunction", arkFunction);
 query.setParameter("customFieldGroup", customFieldGroup);
 return query.list();
   }
}*/

@SuppressWarnings("unchecked")
public List<LinkSubjectStudy> getSubjectsThatAlreadyExistWithTheseUIDs(Study study, Collection subjectUids) {
    String queryString = "select subject " + "from LinkSubjectStudy subject " + "where study =:study "
            + "and subjectUID in  (:subjects) ";
    Query query = getSession().createQuery(queryString);
    query.setParameter("study", study);
    query.setParameterList("subjects", subjectUids);

    return query.list();
}

From source file:au.org.theark.core.dao.StudyDao.java

License:Open Source License

@SuppressWarnings("unchecked")
public List<SubjectCustomFieldData> getSubjectCustomFieldDataFor(Collection customFieldDisplaysThatWeNeed,
        List subjectUIDsToBeIncluded) {
    if (customFieldDisplaysThatWeNeed == null || customFieldDisplaysThatWeNeed.isEmpty()
            || subjectUIDsToBeIncluded == null || subjectUIDsToBeIncluded.isEmpty()) {
        return new ArrayList<SubjectCustomFieldData>();
    } else {//from   www  .j a v a  2 s. com
        String queryString = "select scfd " + " from SubjectCustomFieldData scfd "
                + " where scfd.linkSubjectStudy in (:subjectUIDsToBeIncluded) "
                + " and scfd.customFieldDisplay in (:customFieldDisplaysThatWeNeed) ";
        Query query = getSession().createQuery(queryString);
        query.setParameterList("subjectUIDsToBeIncluded", subjectUIDsToBeIncluded);
        query.setParameterList("customFieldDisplaysThatWeNeed", customFieldDisplaysThatWeNeed);
        return query.list();
    }
}