Java 类org.hibernate.transform.AliasToEntityMapResultTransformer 实例源码

项目:springJpaKata    文件:JpaPerformanceTransformerTest.java   
@Test
public void shouldTransformerMapWork() {
    Session session = em.unwrap(Session.class);
    List<Map> result =  session.createQuery("Select c.id as id, c.name as name  ,count(j) as countJob from Customer c join c.jobs j WHERE c.id = :id")
             .setParameter("id", 5l)
            .setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE)
            .list();
    log.info("customer summary : {}",result);
    for (Map map : result) {
        Long id =  (Long) map.get("id");
        String name =  (String) map.get("name");
        long count =  (long) map.get("countJob");
        log.info("+++ id {} , name : {} , count : {}",id,name,count);
    }

}
项目:monasca-api    文件:AlarmDefinitionSqlRepoImpl.java   
private static ResultTransformer getAlarmDefResultTransformer() {
  return new ResultTransformer() {
    private static final long serialVersionUID = -3052468375925339521L;

    @Override
    public Object transformTuple(final Object[] tuple, final String[] aliases) {
      for (int i = 0, length = aliases.length; i < length; i++) {
        aliases[i] = aliases[i].toUpperCase();
      }
      return AliasToEntityMapResultTransformer
          .INSTANCE
          .transformTuple(tuple, aliases);
    }

    @Override
    public List transformList(final List collection) {
      return AliasToEntityMapResultTransformer
          .INSTANCE
          .transformList(collection);
    }
  };
}
项目:enterprise-app    文件:HqlQueryBrowser.java   
protected void executeQuery() {
    try {
        if(queryTextArea.getValue() != null && !queryTextArea.getValue().toString().trim().isEmpty()) {
            Query query = Db.getCurrentSession().createQuery(queryTextArea.getValue().toString());
            query.setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE);
            setQueryParams(query);

            if(!maxResultsTextField.getValue().toString().isEmpty()) {
                query.setMaxResults(new Integer(maxResultsTextField.getValue().toString()));
            }

            showResult(query.list());
        }

    } catch(Exception e) {
        logger.debug("Error executing query", e);
        Notification.show(Constants.uiError, e.getMessage(), Notification.TYPE_ERROR_MESSAGE);
    }
}
项目:singular-server    文件:RequirementDAO.java   
private List<Map<String, Serializable>> quickSearchMap(RequirementSearchContext query) {
    return makeRequirementSearchQuery(query)
            .setFirstResult(query.getQuickFilter().getFirst())
            .setMaxResults(query.getQuickFilter().getCount())
            .setResultTransformer(AliasToEntityMapResultTransformer.INSTANCE)
            .list();
}