Example usage for org.hibernate Query setResultTransformer

List of usage examples for org.hibernate Query setResultTransformer

Introduction

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

Prototype

@Deprecated
Query<R> setResultTransformer(ResultTransformer transformer);

Source Link

Document

Set a strategy for handling the query results.

Usage

From source file:Dao.DaoTPromocion.java

@Override
public List<Promocion> getPromocionesMaestriasDocente(int idDocente) throws Exception {
    this.sesion = null;
    this.tx = null;
    iniciaOperacion();/* www  . j a v  a  2s .c o m*/

    String hql = "from Promocion pr inner join fetch pr.maestria m inner join fetch pr.modulos mod inner join fetch mod.usuario user \n"
            + "where pr.estado = '1' and m.estado='1' and \n"
            + "(year(current_date) >= year(pr.fechaInicio) and \n"
            + "year(current_date)<= year(pr.fechaFin)) and \n" + "user.id = " + idDocente
            + " and user.estado='1' order by pr.id desc";
    Query query = sesion.createQuery(hql);
    query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Promocion> lstPermiso = (List<Promocion>) query.list();
    sesion.close();
    return lstPermiso;
}

From source file:daoImpl.GroupsDAOImpl.java

@Override
public Groups findGroupById(int id) {
    Session session = sFac.openSession();
    Query query = session.createQuery(
            "from Groups G left join fetch G.usersGroupses left join fetch G.tagses where G.id = :group_id");
    query.setParameter("group_id", id);
    query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    Groups group = (Groups) query.uniqueResult();
    session.close();/*from w  w w  .j  a va2  s .c  o m*/
    return group;
}

From source file:daoImpl.GroupsDAOImpl.java

@Override
public Groups findGroupByName(String groupName) {
    Session session = sFac.openSession();
    Query query = session.createQuery(
            "from Groups G left join fetch G.usersGroupses left join fetch G.tagses where G.groupname = :group_name");
    query.setParameter("group_name", groupName);
    query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    Groups group = (Groups) query.uniqueResult();
    session.close();//from  w  ww  .j  a  v a  2 s  .  c o m
    return group;
}

From source file:daoImpl.GroupsDAOImpl.java

@Override
public List<Groups> findGroupsByName(String groupName) {
    Session session = sFac.openSession();
    Query query = session.createQuery(
            "from Groups G left join fetch G.usersGroupses left join fetch G.tagses where G.groupname like concat('%', :group_name , '%')")
            .setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);
    query.setParameter("group_name", groupName);
    query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Groups> groups = query.list();
    session.close();/* w  w  w  . j a v a  2s. c  om*/
    return groups;
}

From source file:daoImpl.GroupsDAOImpl.java

@Override
public List<Groups> findGroupsByDesc(String desc) {
    Session session = sFac.openSession();
    Query query = session.createQuery(
            "from Groups G left join fetch G.usersGroupses left join fetch G.tagses where G.description like concat('%', :desc , '%')")
            .setResultTransformer(DistinctRootEntityResultTransformer.INSTANCE);
    query.setParameter("desc", desc);
    query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Groups> groups = query.list();
    session.close();//ww w.  java2s .  c o m
    return groups;
}

From source file:daoImpl.GroupsDAOImpl.java

@Override
public List<Groups> findGroupsByUserId(int userId) {
    Session session = sFac.openSession();
    Query query = session.createQuery(
            "from Groups G left join fetch G.usersGroupses UG left join fetch G.tagses where UG.users.userId = :user_id");
    query.setParameter("user_id", userId);
    query.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Groups> groups = query.list();
    session.close();// w  ww.j  a  v  a 2  s  .co m
    return groups;
}

From source file:daoImpl.GroupsDAOImpl.java

@Override
public List<SearchResult> findNearestGroups(float lati, float longi, float maxDistance) {
    Session session = sFac.openSession();
    SQLQuery getDistances = session.createSQLQuery("Select groups.group_id, "
            + "(6371 * acos( cos( radians(:lati )) * cos( radians( groups.latitude ) ) * cos( radians( groups.longitude ) - radians(:longi) ) + sin( radians(:lati) ) * sin( radians( groups.latitude ) ) ) ) as distance "
            + "from groups having distance < :maxDistance order by distance;");
    getDistances.setParameter("lati", lati);
    getDistances.setParameter("longi", longi);
    getDistances.setParameter("maxDistance", maxDistance);
    getDistances.addScalar("group_id", StandardBasicTypes.INTEGER);
    getDistances.addScalar("distance", StandardBasicTypes.FLOAT);

    List<Object[]> closestGroups = getDistances.list();

    if (closestGroups.isEmpty())
        return new ArrayList<>();

    ArrayList groupsToGet = new ArrayList<>();

    for (Object[] r : closestGroups) {
        int i = (int) r[0];
        groupsToGet.add(i);//  w  ww  .  j  av a  2  s.com
    }

    Query getGroups = session.createQuery(
            "from Groups G left join fetch G.tagses left join fetch G.usersGroupses where G.groupId in (:ids)");
    getGroups.setParameterList("ids", groupsToGet);
    getGroups.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Groups> groupsFound = getGroups.list();

    ArrayList<SearchResult> results = new ArrayList<>();

    for (int i = 0; i < groupsFound.size(); i++) {
        SearchResult s = new SearchResult(groupsFound.get(i), (float) (closestGroups.get(i)[1]));
        results.add(s);
    }
    session.close();
    return results;
}

From source file:daoImpl.GroupsDAOImpl.java

@Override
public List<SearchResult> findNearestGroupsByName(float lati, float longi, float maxDistance,
        String searchTerm) {//from   w w w .  j  ava  2 s.  co m
    Session session = sFac.openSession();
    SQLQuery getDistances = session.createSQLQuery("Select groups.group_id, "
            + "(6371 * acos( cos( radians(:lati )) * cos( radians( groups.latitude ) ) * cos( radians( groups.longitude ) - radians(:longi) ) + sin( radians(:lati) ) * sin( radians( groups.latitude ) ) ) ) as distance "
            + "from groups where groups.groupname like concat('%', :name , '%') having distance < :maxDistance order by distance;");
    getDistances.setParameter("lati", lati);
    getDistances.setParameter("longi", longi);
    getDistances.setParameter("maxDistance", maxDistance);
    getDistances.setParameter("name", searchTerm);
    getDistances.addScalar("group_id", StandardBasicTypes.INTEGER);
    getDistances.addScalar("distance", StandardBasicTypes.FLOAT);
    List<Object[]> closestGroups = getDistances.list();

    if (closestGroups.isEmpty())
        return new ArrayList<>();

    ArrayList groupsToGet = new ArrayList<>();

    for (Object[] r : closestGroups) {
        int i = (int) r[0];
        groupsToGet.add(i);
    }

    Query getGroups = session.createQuery(
            "from Groups G left join fetch G.tagses left join fetch G.usersGroupses where G.groupId in (:ids)");
    getGroups.setParameterList("ids", groupsToGet);
    getGroups.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Groups> groupsFound = getGroups.list();

    ArrayList<SearchResult> results = new ArrayList<>();

    for (int i = 0; i < groupsFound.size(); i++) {
        SearchResult s = new SearchResult(groupsFound.get(i), (float) (closestGroups.get(i)[1]));
        results.add(s);
    }
    session.close();
    return results;
}

From source file:daoImpl.GroupsDAOImpl.java

@Override
public List<SearchResult> findNearestGroupsByDesc(float lati, float longi, float maxDistance,
        String description) {/* ww  w .j  a  va  2 s  . co  m*/
    Session session = sFac.openSession();
    SQLQuery getDistances = session.createSQLQuery("Select groups.group_id, "
            + "(6371 * acos( cos( radians(:lati )) * cos( radians( groups.latitude ) ) * cos( radians( groups.longitude ) - radians(:longi) ) + sin( radians(:lati) ) * sin( radians( groups.latitude ) ) ) ) as distance "
            + "from groups where groups.description like concat('%', :name , '%') having distance < :maxDistance order by distance;");
    getDistances.setParameter("lati", lati);
    getDistances.setParameter("longi", longi);
    getDistances.setParameter("maxDistance", maxDistance);
    getDistances.setParameter("name", description);
    getDistances.addScalar("group_id", StandardBasicTypes.INTEGER);
    getDistances.addScalar("distance", StandardBasicTypes.FLOAT);
    List<Object[]> closestGroups = getDistances.list();

    if (closestGroups.isEmpty())
        return new ArrayList<>();

    ArrayList groupsToGet = new ArrayList<>();

    for (Object[] r : closestGroups) {
        int i = (int) r[0];
        groupsToGet.add(i);
    }

    Query getGroups = session.createQuery(
            "from Groups G left join fetch G.tagses left join fetch G.usersGroupses where G.groupId in (:ids)");
    getGroups.setParameterList("ids", groupsToGet);
    getGroups.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Groups> groupsFound = getGroups.list();

    ArrayList<SearchResult> results = new ArrayList<>();

    for (int i = 0; i < groupsFound.size(); i++) {
        SearchResult s = new SearchResult(groupsFound.get(i), (float) (closestGroups.get(i)[1]));
        results.add(s);
    }
    session.close();
    return results;
}

From source file:daoImpl.GroupsDAOImpl.java

@Override
public List<SearchResult> findNearestGroupsByTag(float latitude, float longitude, float maxDistance,
        String tag) {/*from  w  w  w . ja  v  a  2 s.  co m*/
    Session session = sFac.openSession();
    SQLQuery query = session.createSQLQuery(
            "Select groups.group_id, (6371 * acos( cos( radians(:lati )) * cos( radians( groups.latitude ) ) * cos( radians( groups.longitude ) - radians(:longi) ) + sin( radians(:lati) ) * sin( radians( groups.latitude ) ) ) ) as distance from groups join groups_tags on (groups.group_id=groups_tags.group_id_fk) join tags on (groups_tags.tag_id_fk=tags.tag_id) where tags.tag_name = :tagname having distance < :dist order by distance;");
    query.setParameter("lati", latitude);
    query.setParameter("longi", longitude);
    query.setParameter("tagname", tag);
    query.setParameter("dist", maxDistance);
    query.addScalar("group_id", StandardBasicTypes.INTEGER);
    query.addScalar("group_id", StandardBasicTypes.FLOAT);

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

    if (closestGroups.isEmpty())
        return new ArrayList<>();

    ArrayList groupsToGet = new ArrayList<>();

    for (Object[] r : closestGroups) {
        int i = (int) r[0];
        groupsToGet.add(i);
    }

    Query getGroups = session.createQuery(
            "from Groups G left join fetch G.tagses left join fetch G.usersGroupses where G.groupId in (:ids)");
    getGroups.setParameterList("ids", groupsToGet);
    getGroups.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY);
    List<Groups> groupsFound = getGroups.list();

    ArrayList<SearchResult> results = new ArrayList<>();

    for (int i = 0; i < groupsFound.size(); i++) {
        SearchResult s = new SearchResult(groupsFound.get(i), (float) (closestGroups.get(i)[1]));
        results.add(s);
    }
    session.close();
    return results;
}