Example usage for org.hibernate SQLQuery setParameterList

List of usage examples for org.hibernate SQLQuery setParameterList

Introduction

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

Prototype

@Override
    NativeQuery<T> setParameterList(String name, Object[] values, Type type);

Source Link

Usage

From source file:lt.emasina.resthub.server.handler.Handler.java

License:Open Source License

public void applyParameters(SQLQuery query) throws SQLException {
    for (Map.Entry<QueryParameter, Object> e : parameters.entrySet()) {

        QueryParameter p = e.getKey();//from w ww  . j  av a  2 s .co  m
        Object value = e.getValue();
        String name = p.getSqlName();

        if (value != null && p.getArray()) {

            switch (p.getType()) {
            case DATE:
                query.setParameterList(name, (Object[]) value, new DateType());
                break;
            case NUMBER:
                query.setParameterList(name, (Object[]) value, new BigDecimalType());
                break;
            case STRING:
                query.setParameterList(name, (Object[]) value, new StringType());
                break;
            case CLOB:
            case BLOB:
                throw new ClientErrorException(Status.CLIENT_ERROR_BAD_REQUEST,
                        String.format("LOBs are not supported as parameters: %s", name));
            }

        } else {

            switch (p.getType()) {
            case DATE:
                query.setDate(name, (Date) value);
                break;
            case NUMBER:
                query.setBigDecimal(name, (BigDecimal) value);
                break;
            case STRING:
                query.setString(name, (String) value);
                break;
            case CLOB:
            case BLOB:
                throw new ClientErrorException(Status.CLIENT_ERROR_BAD_REQUEST,
                        String.format("LOBs are not supported as parameters: %s", name));
            }
        }
    }
}

From source file:org.squashtest.tm.service.internal.repository.hibernate.HibernateCampaignFolderDao.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public List<Long[]> findPairedContentForList(final List<Long> ids) {

    if (ids.isEmpty()) {
        return Collections.emptyList();
    }/*from  w w  w .  j ava2s  . c om*/

    SQLQuery query = currentSession()
            .createSQLQuery(NativeQueries.CAMPAIGN_FOLDER_SQL_FIND_PAIRED_CONTENT_FOR_FOLDERS);
    query.setParameterList("folderIds", ids, LongType.INSTANCE);
    query.addScalar("ancestor_id", LongType.INSTANCE);
    query.addScalar("descendant_id", LongType.INSTANCE);

    List<Object[]> result = query.list();

    return toArrayOfLong(result);
}

From source file:org.squashtest.tm.service.internal.repository.hibernate.HibernateCampaignFolderDao.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/* w  w w. jav  a 2s . c  o m*/
public List<Long> findContentForList(List<Long> ids) {
    if (ids.isEmpty()) {
        return Collections.emptyList();
    }

    SQLQuery query = currentSession().createSQLQuery(NativeQueries.CAMPAIGN_FOLDER_SQL_FIND_CONTENT_FOR_FOLDER);
    query.setParameterList("folderIds", ids, LongType.INSTANCE);
    query.addScalar("descendant_id", LongType.INSTANCE);

    return query.list();
}

From source file:org.squashtest.tm.service.internal.repository.hibernate.HibernateRequirementFolderDao.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override/*from  w  ww  .  java 2  s. c  o m*/
public List<Long[]> findPairedContentForList(final List<Long> ids) {

    if (ids.isEmpty()) {
        return Collections.emptyList();
    }

    SQLQuery query = currentSession()
            .createSQLQuery(NativeQueries.REQUIREMENT_FOLDER_SQL_FIND_PAIRED_CONTENT_FOR_FOLDERS);
    query.setParameterList("folderIds", ids, LongType.INSTANCE);
    query.addScalar("ancestor_id", LongType.INSTANCE);
    query.addScalar("descendant_id", LongType.INSTANCE);

    List<Object[]> result = query.list();

    return toArrayOfLong(result);
}

From source file:org.squashtest.tm.service.internal.repository.hibernate.HibernateRequirementFolderDao.java

License:Open Source License

@SuppressWarnings("unchecked")
@Override//from w  w  w.j a va 2 s.  c  om
public List<Long> findContentForList(List<Long> ids) {
    if (ids.isEmpty()) {
        return Collections.emptyList();
    }

    SQLQuery query = currentSession()
            .createSQLQuery(NativeQueries.REQUIREMENT_FOLDER_SQL_FIND_CONTENT_FOR_FOLDER);
    query.setParameterList("folderIds", ids, LongType.INSTANCE);
    query.addScalar("descendant_id", LongType.INSTANCE);

    return query.list();
}

From source file:org.squashtest.tm.service.internal.repository.hibernate.HibernateTestCaseDeletionDao.java

License:Open Source License

@Override
@SuppressWarnings("unchecked")
public void removeOrSetIterationTestPlanInboundReferencesToNull(List<Long> testCaseIds) {

    if (!testCaseIds.isEmpty()) {
        SQLQuery query1 = getSession()
                .createSQLQuery(NativeQueries.TESTCASE_SQL_SELECTCALLINGITERATIONITEMTESTPLANHAVINGEXECUTIONS);
        query1.addScalar("item_test_plan_id", LongType.INSTANCE);
        query1.setParameterList(TEST_CASES_IDS, testCaseIds, LongType.INSTANCE);
        List<Long> itpHavingExecIds = query1.list();

        SQLQuery query2 = getSession().createSQLQuery(
                NativeQueries.TESTCASE_SQL_SELECTCALLINGITERATIONITEMTESTPLANHAVINGNOEXECUTIONS);
        query2.addScalar("item_test_plan_id", LongType.INSTANCE);
        query2.setParameterList(TEST_CASES_IDS, testCaseIds, LongType.INSTANCE);
        List<Long> itpHavingNoExecIds = query2.list();

        setNullCallingIterationItemTestPlanHavingExecutions(itpHavingExecIds);
        removeCallingIterationItemTestPlanHavingNoExecutions(itpHavingNoExecIds);
    }/*  ww  w  .  j av  a 2  s.  c o m*/

}

From source file:org.squashtest.tm.service.internal.repository.hibernate.HibernateTestCaseFolderDao.java

License:Open Source License

@Override
public List<Long[]> findPairedContentForList(final List<Long> ids) {
    if (ids.isEmpty()) {
        return Collections.emptyList();
    }// w ww .  j  ava 2s  .  c  om

    SQLQuery query = currentSession()
            .createSQLQuery(NativeQueries.TEST_CASE_FOLDER_SQL_FIND_PAIRED_CONTENT_FOR_FOLDERS);
    query.setParameterList("folderIds", ids, LongType.INSTANCE);
    query.addScalar("ancestor_id", LongType.INSTANCE);
    query.addScalar("descendant_id", LongType.INSTANCE);

    List<Object[]> result = query.list();

    return toArrayOfLong(result);
}

From source file:org.squashtest.tm.service.internal.repository.hibernate.HibernateTestCaseFolderDao.java

License:Open Source License

@Override
public List<Long> findContentForList(List<Long> ids) {
    if (ids.isEmpty()) {
        return Collections.emptyList();
    }//w w w . j  a  v a 2s. c om

    SQLQuery query = currentSession()
            .createSQLQuery(NativeQueries.TEST_CASE_FOLDER_SQL_FIND_CONTENT_FOR_FOLDER);
    query.setParameterList("folderIds", ids, LongType.INSTANCE);
    query.addScalar("descendant_id", LongType.INSTANCE);

    return query.list();
}

From source file:ubic.gemma.persistence.util.CommonQueries.java

License:Apache License

/**
 * @param session session// w w  w.  j av  a2 s.co  m
 * @param probes  probes
 * @return map of probes to all the genes 'detected' by those probes. Probes that don't map to genes will have an
 * empty gene collection.
 */
public static Map<Long, Collection<Long>> getCs2GeneMapForProbes(Collection<Long> probes, Session session) {
    if (probes.isEmpty())
        return new HashMap<>();

    Map<Long, Collection<Long>> cs2genes = new HashMap<>();

    String queryString = "SELECT CS AS csid, GENE AS geneId FROM GENE2CS g WHERE g.CS IN (:probes) ";
    org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString);
    queryObject.addScalar("csid", LongType.INSTANCE);
    queryObject.addScalar("geneId", LongType.INSTANCE);
    queryObject.setParameterList("probes", probes, LongType.INSTANCE);
    queryObject.setReadOnly(true);
    queryObject.setFlushMode(FlushMode.MANUAL);

    ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY);
    CommonQueries.addGeneIds(cs2genes, results);
    results.close();

    return cs2genes;
}

From source file:ubic.gemma.persistence.util.CommonQueries.java

License:Apache License

public static Collection<Long> filterProbesByPlatform(Collection<Long> probes, Collection<Long> arrayDesignIds,
        Session session) {//from   www . j a  v a 2  s  . c  o  m
    assert probes != null && !probes.isEmpty();
    assert arrayDesignIds != null && !arrayDesignIds.isEmpty();
    String queryString = "SELECT CS AS csid FROM GENE2CS WHERE AD IN (:adids) AND CS IN (:probes)";
    org.hibernate.SQLQuery queryObject = session.createSQLQuery(queryString);
    queryObject.addScalar("csid", LongType.INSTANCE);
    queryObject.setParameterList("probes", probes, LongType.INSTANCE);
    queryObject.setParameterList("adids", arrayDesignIds, LongType.INSTANCE);

    ScrollableResults results = queryObject.scroll(ScrollMode.FORWARD_ONLY);
    List<Long> r = new ArrayList<>();
    while (results.next()) {
        r.add(results.getLong(0));

    }
    results.close();
    return r;
}