Example usage for org.hibernate.criterion CriteriaSpecification ALIAS_TO_ENTITY_MAP

List of usage examples for org.hibernate.criterion CriteriaSpecification ALIAS_TO_ENTITY_MAP

Introduction

In this page you can find the example usage for org.hibernate.criterion CriteriaSpecification ALIAS_TO_ENTITY_MAP.

Prototype

ResultTransformer ALIAS_TO_ENTITY_MAP

To view the source code for org.hibernate.criterion CriteriaSpecification ALIAS_TO_ENTITY_MAP.

Click Source Link

Document

Each row of results is a Map from alias to entity instance

Usage

From source file:com.jeysan.modules.orm.hibernate.SimpleHibernateDao.java

License:Apache License

/**
 * ?SQL?Query./*from www .  j  a  v  a 2 s  .c o m*/
 * find()???.
 * 
 * @param values ????,?.
 */
public Query createSqlQuery(final String queryString, final Object... values) {
    Assert.hasText(queryString, "queryString?");
    Query query = getSession().createSQLQuery(queryString)
            .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
    if (values != null) {
        for (int i = 0; i < values.length; i++) {
            query.setParameter(i, values[i]);
        }
    }
    return query;
}

From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java

public List findByHQL(String hql, Object[] params) {
    Query query = createQuery(hql, params);
    if (hql.indexOf("select") >= 0) {
        query.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
    }//from   w w w .  java2s .c  o  m
    if (query != null)
        return query.list();
    return null;
}

From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java

public List executeSQLQuery(String sql, Object[] params) {
    Query query = initHqlParams(getCurrentSession().createSQLQuery(sql), params);
    query.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
    return query.list();
}

From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java

public PageModel toPageQuery(Integer curPage, Integer pageSize, String hql, Object[] params) {
    if (curPage == null)
        curPage = SystemConstant.DEF_PAGE_BEG;
    if (pageSize == null)
        pageSize = SystemConstant.DEF_PAGE_SIZE;
    if (!BaseUtil.isEmpty(hql)) {
        Session session = getCurrentSession();
        long rows = getCount(session, hql, params);
        System.out.println("rows := " + rows);
        PageModel pm = new PageModel(curPage, pageSize, rows);
        Query pageQuery = initHqlParams(session.createQuery(hql), params);
        pageQuery.setFirstResult(pm.getStartNum());
        pageQuery.setMaxResults(pageSize);
        pageQuery.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
        pm.setDatas(pageQuery.list());//from ww w.java 2 s .co  m
        return pm;
    }
    return null;
}

From source file:com.myapp.core.base.dao.impl.AbstractBaseDao.java

public PageModel toPageSqlQuery(Integer curPage, Integer pageSize, String sql, Object[] params) {
    if (curPage == null)
        curPage = SystemConstant.DEF_PAGE_BEG;
    if (pageSize == null)
        pageSize = SystemConstant.DEF_PAGE_SIZE;
    if (!BaseUtil.isEmpty(sql)) {
        Session session = getCurrentSession();
        long rows = getSqlCount(session, sql, params);
        System.out.println("rows := " + rows);
        PageModel pm = new PageModel(curPage, pageSize, rows);
        Query pageQuery = initHqlParams(session.createSQLQuery(sql), params);
        pageQuery.setFirstResult(pm.getStartNum());
        pageQuery.setMaxResults(pageSize);
        pageQuery.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
        pm.setDatas(pageQuery.list());/*from  w  ww . j a va 2s  . co m*/
        return pm;
    }
    return null;
}

From source file:gemlite.core.internal.support.jpa.files.dao.GmBatchDaoImpl.java

License:Apache License

@Override
public List<Map> queryJobExecutions(String status) {
    String where = "";
    if (!StringUtils.isEmpty(status)) {
        where = " where e.status='" + status + "'";
    }/*from  w ww . j  av  a  2s .co m*/
    String getjobs = "select e.job_execution_id as job_execution_id, e.start_time as start_time, e.end_time, e.status, e.exit_code, e.exit_message, e.create_time, e.last_updated, e.version, i.job_instance_id, i.job_name from batch_job_execution e join batch_job_instance i on e.job_instance_id=i.job_instance_id "
            + where + " order by job_execution_id desc";
    Query query = em.createNativeQuery(getjobs);
    SQLQuery nativeQuery = query.unwrap(SQLQuery.class);
    nativeQuery.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
    List<Map> list = null;
    try {
        list = nativeQuery.list();
    } catch (Exception e) {
        LogUtil.getCoreLog().warn("SQL {} Error {}", getjobs, e.getMessage());
    }
    //?
    List<Map> newlist = new ArrayList<Map>();
    if (list != null) {
        for (Map map : list) {
            //duration
            Timestamp t1 = (Timestamp) map.get("START_TIME");
            Timestamp t2 = (Timestamp) map.get("END_TIME");
            String duration = "";
            if (t2 != null)
                duration = format(new Date(t2.getTime() - t1.getTime()), "HH:mm:ss");

            Map newmap = new HashMap<String, Object>();
            newmap.put("duration", duration);

            Iterator<Entry<String, Object>> it = map.entrySet().iterator();
            while (it.hasNext()) {
                Entry<String, Object> entry = it.next();
                newmap.put(entry.getKey().toLowerCase(), entry.getValue());
            }
            newlist.add(newmap);
        }
    }

    return newlist;
}

From source file:gemlite.core.internal.support.jpa.files.dao.GmBatchDaoImpl.java

License:Apache License

@Override
public Map queryJobExecutionById(Long executionId) {
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT a.*,b.job_name");
    sb.append(/*from  www.ja  v a  2  s  . c om*/
            " from BATCH_JOB_EXECUTION a left join batch_job_instance b on a.job_instance_id = b.job_instance_id where a.JOB_EXECUTION_ID = ?");

    Query query = em.createNativeQuery(sb.toString());
    SQLQuery nativeQuery = query.unwrap(SQLQuery.class);
    nativeQuery.setParameter(0, executionId);
    nativeQuery.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
    List<Map> list = nativeQuery.list();

    return (list == null || list.isEmpty()) ? null : toLowerCaseKey(list).get(0);
}

From source file:gemlite.core.internal.support.jpa.files.dao.GmBatchDaoImpl.java

License:Apache License

@Override
public List<Map> queryStepNamesForJob(String jobName) {
    String sql = "SELECT E.JOB_EXECUTION_ID, E.START_TIME, E.END_TIME, E.STATUS, E.EXIT_CODE, E.EXIT_MESSAGE, E.CREATE_TIME, E.LAST_UPDATED, E.VERSION, I.JOB_INSTANCE_ID, I.JOB_NAME"
            + " FROM BATCH_JOB_EXECUTION E, BATCH_JOB_INSTANCE I WHERE E.JOB_INSTANCE_ID=I.JOB_INSTANCE_ID and I.JOB_NAME=? ORDER BY JOB_EXECUTION_ID DESC";

    Query query = em.createNativeQuery(sql);
    SQLQuery nativeQuery = query.unwrap(SQLQuery.class);
    nativeQuery.setParameter(0, jobName);
    nativeQuery.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);
    List<Map> list = nativeQuery.list();

    return toLowerCaseKey(list);
}

From source file:gemlite.core.internal.support.jpa.files.dao.GmBatchDaoImpl.java

License:Apache License

@Override
public List<Map> queryStepExecutionsById(Long jobExecutionId) {
    StringBuilder sb = new StringBuilder();
    sb.append("SELECT STEP_EXECUTION_ID, STEP_NAME, START_TIME, END_TIME, STATUS, COMMIT_COUNT,");
    sb.append(" READ_COUNT, FILTER_COUNT, WRITE_COUNT, EXIT_CODE, EXIT_MESSAGE, READ_SKIP_COUNT,");
    sb.append(" WRITE_SKIP_COUNT, PROCESS_SKIP_COUNT, ROLLBACK_COUNT, LAST_UPDATED, VERSION from ");
    sb.append(" BATCH_STEP_EXECUTION where JOB_EXECUTION_ID = ?");
    sb.append(" order by STEP_EXECUTION_ID");

    Query query = em.createNativeQuery(sb.toString());
    SQLQuery nativeQuery = query.unwrap(SQLQuery.class);
    nativeQuery.setParameter(0, jobExecutionId);
    nativeQuery.setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP);

    List<Map> list = nativeQuery.list();
    return toLowerCaseKey(list);
}

From source file:org.generationcp.middleware.dao.dms.PhenotypeDao.java

License:Open Source License

public List<Phenotype> getDatasetDraftData(final Integer datasetId) {
    final List<Map<String, Object>> results = this.getSession()
            .createSQLQuery("select {ph.*}, {e.*}, " + " (select exists( "
                    + "     select 1 from formula where target_variable_id = ph.observable_id and active = 1"
                    + " )) as isDerivedTrait " + " from phenotype ph"
                    + " inner join nd_experiment e on ph.nd_experiment_id = e.nd_experiment_id"
                    + " inner join project p on e.project_id = p.project_id "
                    + " where p.project_id = :datasetId "
                    + " and (ph.draft_value is not null or ph.draft_cvalue_id is not null)")
            .addEntity("ph", Phenotype.class).addEntity("e", ExperimentModel.class)
            .addScalar("isDerivedTrait", new BooleanType()).setParameter("datasetId", datasetId)
            .setResultTransformer(CriteriaSpecification.ALIAS_TO_ENTITY_MAP).list();

    final List<Phenotype> phenotypes = new ArrayList<>();

    for (final Map<String, Object> result : results) {
        final Phenotype phenotype = (Phenotype) result.get("ph");
        final ExperimentModel experimentModel = (ExperimentModel) result.get("e");
        phenotype.setExperiment(experimentModel);
        phenotype.setDerivedTrait((Boolean) result.get("isDerivedTrait"));
        phenotypes.add(phenotype);//  w  ww  .  ja va2  s  . c  o m
    }
    return phenotypes;
}