Example usage for org.hibernate Query list

List of usage examples for org.hibernate Query list

Introduction

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

Prototype

List<R> list();

Source Link

Document

Return the query results as a List.

Usage

From source file:aseguradora.VistaVentana.java

private void buscarAsegurado(String nombre) {
    Session session = sesion.openSession();
    PolizasAsegurados pa;//from   w ww  .j av  a2  s . c  o m
    Query cons = session.createQuery("from pojo.PolizasAsegurados as pa " + "where upper(pa.id.na) LIKE ?");
    cons.setString(0, "%" + nombre.toUpperCase() + "%");
    List<PolizasAsegurados> lista = cons.list();
    DefaultTableModel model = (DefaultTableModel) tablaVista.getModel();
    if (!lista.isEmpty()) {
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        Iterator<PolizasAsegurados> iter = lista.iterator();
        while (iter.hasNext()) {
            pa = (PolizasAsegurados) iter.next();
            Hibernate.initialize(pa.getId());
            Vector row = new Vector();
            row.add(pa.getId().getCodP());
            row.add(pa.getId().getDatosP());
            row.add(pa.getId().getNum());
            row.add(pa.getId().getNa());
            row.add(formatDate(pa.getId().getFn().toString()));
            model.addRow(row);
        }
        tablaVista.setModel(model);
        session.close();
    } else {
        model.getDataVector().removeAllElements();
        model.fireTableDataChanged();
        JOptionPane.showMessageDialog(null, "No hay resultados para su bsqueda", "Informacin",
                JOptionPane.ERROR_MESSAGE);
        cargarVista();
    }

}

From source file:at.ac.tuwien.ifs.tita.dao.issuetracker.task.IssueTrackerTaskDao.java

License:Apache License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override/*from ww  w.j  a v a2 s. c o m*/
public List<IssueTrackerTask> findIssueTrackerTasksforUserProject(Long projectId, Long userId) {
    String queryString = "select distinct itt from Effort e " + "join e.issueTTask as itt "
            + "join itt.isstProject as itp " + "join itp.titaProject as tp " + "where e.user = " + userId
            + " and tp.id = " + projectId + " and e.deleted != true";

    Query q = getSession().createQuery(queryString);

    return q.list();
}

From source file:at.ac.tuwien.ifs.tita.dao.time.EffortDao.java

License:Apache License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
public List<Effort> getTimeEffortsDailyView(Date date, Long userId) {
    Calendar cal = Calendar.getInstance();
    cal.setTime(date);/*from  w w  w.  ja  v a  2  s. c om*/

    String query = "Select e from Effort e where e.deleted=false and " + " day(e.date) = "
            + cal.get(Calendar.DAY_OF_MONTH) + " and month(e.date) = " + (cal.get(Calendar.MONTH) + 1)
            + " and year(e.date)= " + cal.get(Calendar.YEAR) + " and e.user=" + userId + " order by e.date";

    Query q = getSession().createQuery(query);
    return q.list();
}

From source file:at.ac.tuwien.ifs.tita.dao.time.EffortDao.java

License:Apache License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
public List<Integer> getTimeEffortsYears(Long userId) {
    String query = "select distinct year(te.date) from Effort te where deleted=false " + " and te.user = "
            + userId + " order by 1 desc";
    Query q = getSession().createQuery(query);
    return q.list();
}

From source file:at.ac.tuwien.ifs.tita.dao.time.EffortDao.java

License:Apache License

/** {@inheritDoc} */
@Override/*from   w  w w. j a  va 2  s. c om*/
public List<Effort> findEffortsForTiTAProjectAndTiTAUser(Long projectId, Long userId) {

    String first = "select e " + "from Effort e " + "join e.titaTask as tt " + "join tt.titaProject as tp "
            + "where e.user = " + userId + " and tp.id = " + projectId + " and e.deleted != true";

    String second = "select e " + "from Effort e " + "join e.issueTTask as itt "
            + "join itt.isstProject as itp " + "join itp.titaProject as tp " + "where e.user = " + userId
            + " and tp.id = " + projectId + " and e.deleted != true";

    Query query1 = getSession().createQuery(first);
    Query query2 = getSession().createQuery(second);

    List<Effort> list1 = query1.list();
    List<Effort> list2 = query2.list();
    list1.addAll(list2);

    List<Effort> effortList = list1;
    return effortList;
}

From source file:at.ac.tuwien.ifs.tita.dao.user.UserDAO.java

License:Apache License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override/*from  w ww.  j  a v a 2 s.  c  o  m*/
public List<TiTAUser> findUsersForTiTAProject(TiTAProject project) {

    String queryString = "select u.* from tita_user u join user_project up on "
            + "u.id = up.user_id join tita_project tp on up.tita_project_id = tp.id " + " where tp.name in ("
            + ")";

    // String first =
    // "select e.id, e.description, e.date, e.startTime, e.endTime, e.duration, e.deleted "
    // + "from Effort e "
    // + "join e.titaTask as tt "
    // + "join tt.titaProject as tp "
    // + "where e.user = "
    // + userId
    // + " and tp.id = "
    // + projectId
    // + " and e.deleted != true";

    queryString = "select u " + "from TiTAUserProject tup," + " TiTAUser as u "
            + "where tup.user = u.id and tup.project = " + project.getId();

    // u.id = r.id and - , Role as r

    Query query = getSession().createQuery(queryString);
    List<TiTAUser> users = new ArrayList<TiTAUser>();

    try {
        users = query.list();
    } catch (NoResultException e) {
        // nothing to do
    }

    // List<TiTAUser> newUsers = new ArrayList<TiTAUser>();
    //
    // for (int i = 0; i < users.size(); i++) {
    // newUsers.add(this.findById(users.get(0).getId()));
    // }

    return users;
}

From source file:at.ac.tuwien.ifs.tita.dao.user.UserDAO.java

License:Apache License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override//w w  w .j  a v a2  s .  co  m
public List<TiTAUser> findUsersForTiTAProjectByRole(TiTAProject project, Role role) {
    String queryString = "select u " + "from TiTAUserProject tup," + " TiTAUser as u "
            + "where tup.user = u.id and tup.project = " + project.getId() + " and u.role=" + role.getId();
    Query query = getSession().createQuery(queryString);
    return query.list();
}

From source file:at.ac.tuwien.infosys.jcloudscale.datastore.hibernate.work.AbstractWork.java

License:Apache License

protected List<DatastoreModel> getDatastoreModelsForEntity(Session session, Object entity) {
    Query query = session.getNamedQuery("datastoreModel.getModelForEntity");
    query.setParameter("entityClassName", entity.getClass().getSimpleName());
    query.setParameter("entityID", String.valueOf(EntityUtil.getID(entity)));
    return query.list();
}

From source file:at.gv.egovernment.moa.id.moduls.SSOManager.java

License:EUPL

public String existsOldSSOSession(String ssoId) {

    Logger.trace("Check that the SSOID has already been used");
    Session session = MOASessionDBUtils.getCurrentSession();

    List<OldSSOSessionIDStore> result;

    synchronized (session) {

        session.beginTransaction();//w w w  .j  av a 2 s  .co  m
        Query query = session.getNamedQuery("getSSOSessionWithOldSessionID");
        query.setParameter("sessionid", ssoId);
        result = query.list();

        // send transaction

    }

    Logger.trace("Found entries: " + result.size());

    // Assertion requires an unique artifact
    if (result.size() == 0) {
        session.getTransaction().commit();
        return null;
    }

    OldSSOSessionIDStore oldSSOSession = result.get(0);

    AuthenticatedSessionStore correspondingMoaSession = oldSSOSession.getMoasession();

    if (correspondingMoaSession == null) {
        Logger.info("Get request with old SSO SessionID but no corresponding SSO Session is found.");
        return null;
    }

    String moasessionid = correspondingMoaSession.getSessionid();

    session.getTransaction().commit();

    return moasessionid;

}

From source file:at.gv.egovernment.moa.id.monitoring.DatabaseTestModule.java

License:EUPL

private String testMOASessionDatabase() throws Exception {
    Logger.trace("Start Test: MOASessionDatabase");

    Date expioredate = new Date(new Date().getTime() - 120);

    try {//  w w w  .j av a  2 s. c om
        List<AssertionStore> results;
        Session session = MOASessionDBUtils.getCurrentSession();

        synchronized (session) {
            session.beginTransaction();
            Query query = session.getNamedQuery("getAssertionWithTimeOut");
            query.setTimestamp("timeout", expioredate);
            results = query.list();
            session.getTransaction().commit();
        }

        Logger.trace("Finish Test: MOASessionDatabase");
        return null;

    } catch (Throwable e) {
        Logger.warn("Failed Test: MOASessionDatabase", e);
        return "MOASessionDatabase: " + e.getMessage();
    }
}