Example usage for org.hibernate Query setDate

List of usage examples for org.hibernate Query setDate

Introduction

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

Prototype

@Deprecated
@SuppressWarnings("unchecked")
default Query<R> setDate(String name, Date val) 

Source Link

Document

Bind the val (time is truncated) of a given Date object to a named query parameter.

Usage

From source file:com.timesheet.data.SearchImp.java

@Override
public List<Booking> searchResult(Search searchOb) {
    List<Booking> searchResult = new ArrayList<Booking>();

    System.out.println(" @@@@@@@@@@@@@@@@@@@@@@ :" + searchOb.getSearchProjectId() + " ,"
            + searchOb.getSearchFromDate() + "," + searchOb.getSearchUser());

    String searchSQL = utils.generatSearchSQL(searchOb);

    System.out.println("@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ : Search SQL : " + searchSQL);

    if (StringUtils.isNotBlank(searchSQL)) {
        Query searchQuery = sessionFactory.getCurrentSession().createQuery(searchSQL);

        if (searchSQL.contains("userId")) {
            searchQuery.setInteger("userId", searchOb.getSearchUser());
        }//w ww . j  a  va 2  s. c  o m

        if (searchSQL.contains("projectId")) {
            searchQuery.setInteger("projectId", searchOb.getSearchProjectId());
        }

        if (searchSQL.contains("optionId")) {
            searchQuery.setInteger("optionId", searchOb.getSearchOptionId());
        }

        if (searchSQL.contains("startDate")) {
            Date startDate = utils.getFirstDateOfMonth(searchOb.getSearchMonth());

            searchQuery.setDate("startDate", startDate);
        }

        if (searchSQL.contains("endDate")) {
            Date endDate = utils.getLastDateOfMonth(searchOb.getSearchMonth());

            searchQuery.setDate("endDate", endDate);
        }

        if (searchSQL.contains("fromDate")) {
            searchQuery.setDate("fromDate", searchOb.getSearchFromDate());
        }

        if (searchSQL.contains("toDate")) {

            searchQuery.setDate("toDate", searchOb.getSearchToDate());
        }

        searchResult = searchQuery.list();
    }

    return searchResult;
    //throw new UnsupportedOperationException("Not supported yet."); //To change body of generated methods, choose Tools | Templates.
}

From source file:dao.customer.CustomerDao.java

License:Apache License

public ArrayList<Object[]> search(SearchBean searchbean) throws ParseException {

    Session session = sessionFactory.openSession();
    Transaction trx = null;//from   w ww  . j a  v  a  2s .co m
    trx = session.beginTransaction();
    DateFormat formatter;
    Date date;
    formatter = new SimpleDateFormat("dd/MM/YYYY");
    ArrayList<Object[]> vehicles;
    if (!(searchbean.getVehicleType().isEmpty()) && !(searchbean.getVehicleName().isEmpty())) {
        Query query = session.createSQLQuery(
                "select * from ata_tbl_vehicle where vehicle_number not in(select vehicle_number from ata_tbl_booking where journey_date=?) and vehicle_type=? and vehicle_name=?");
        query.setDate(0, formatter.parse(searchbean.getJourneyDate()));
        query.setString(1, searchbean.getVehicleType());
        query.setString(2, searchbean.getVehicleName());
        //  System.out.println(searchbean.getVehicleType()+"   "+searchbean.getVehicleName());

        //  System.out.println("both not null");
        vehicles = (ArrayList<Object[]>) query.list();
    }

    else if (searchbean.getVehicleType().isEmpty() && searchbean.getVehicleName().isEmpty()) {
        Query query = session.createSQLQuery(
                "select * from ata_tbl_vehicle where vehicle_number not in(select vehicle_number from ata_tbl_booking where journey_date=?)");
        query.setDate(0, formatter.parse(searchbean.getJourneyDate()));
        // System.out.println("both null");
        vehicles = (ArrayList<Object[]>) query.list();
    }

    else if (searchbean.getVehicleType().isEmpty()) {
        Query query = session.createSQLQuery(
                "select * from ata_tbl_vehicle where vehicle_number not in(select vehicle_number from ata_tbl_booking where journey_date=?) and vehicle_name=?");
        query.setDate(0, formatter.parse(searchbean.getJourneyDate()));
        // System.out.println("name not null");
        query.setString(1, searchbean.getVehicleName());

        vehicles = (ArrayList<Object[]>) query.list();
    } else {
        Query query = session.createSQLQuery(
                "select * from ata_tbl_vehicle where vehicle_number not in(select vehicle_number from ata_tbl_booking where journey_date=?) and vehicle_type=?");
        query.setDate(0, formatter.parse(searchbean.getJourneyDate()));
        query.setString(1, searchbean.getVehicleType());
        // System.out.println("type not null");
        vehicles = (ArrayList<Object[]>) query.list();
    }

    trx.commit();
    session.close();
    return vehicles;
}

From source file:DAO.PedidosDAO.java

@Override
public List<Pedidos> listarComFiltroEData(int id, Date data) {
    String hql = "select t from Pedidos t where t.tipo like :nomeA and t.data = :data";
    Query consulta = this.sessao.createQuery(hql);
    consulta.setInteger("nomeA", id);
    consulta.setDate("data", data);
    return (List<Pedidos>) consulta.list();
}

From source file:DAO.PedidosDAO.java

@Override
public Pedidos buscarData(Date data) {
    String hql = "select t from Pedidos t where t.data = :matA";
    Query consulta = this.sessao.createQuery(hql);
    consulta.setDate("matA", data);
    return (Pedidos) consulta.uniqueResult();
}

From source file:dao.TimeDao.java

/**
 * Obtm lista com todos os times do banco
 *
 * @param dataIni Data inicial a ser filtrada
 * @param dataFin Data final a ser filtrada
 * @return Lista com todos os times do banco
 *///from w  w  w  .java 2 s.c o m
public List<Time> listarPorDataFundacao(Date dataIni, Date dataFin) {
    try {
        Session sessao = Hibernate4Util.getSessionFactory();
        Transaction transacao = sessao.beginTransaction();
        Query consulta = sessao.createQuery(
                "from Time where dataFundacao between :dataini AND :datafin order by dataFundacao desc, codigo");
        consulta.setDate("dataini", dataIni);
        consulta.setDate("datafin", dataFin);

        List<Time> resultado = consulta.list();
        transacao.commit();
        return resultado;
    } catch (HibernateException e) {
        System.out.println("No foi possvel selecionar times. Erro: " + e.getMessage());
        throw new HibernateException(e);
    }
}

From source file:Datos.ConsultaDAO.java

public List<Consulta> obtenerTodosPorFecha(Date fechaInicial, Date fechaFinal) throws HibernateException {
    List<Consulta> lista = null;

    try {//from   ww w  .  ja  va 2s.com
        iniciarOperacion();
        Query query = sesion.createQuery("from Consulta where fecha between :fechaInicial and :fechaFinal");
        query.setDate("fechaInicial", fechaInicial);
        query.setDate("fechaFinal", fechaFinal);

        lista = query.list();
    } finally {
        sesion.close();
    }

    return lista;
}

From source file:Datos.PacienteDAO.java

public Paciente verificarExistencia(Paciente pte) {
    Paciente paciente = null;//from   www  . j a va  2 s  .  com

    try {
        iniciarOperacion();

        Query query = sesion.createQuery("FROM Paciente WHERE " + "apellidoPaterno=:apellidoPaterno AND "
                + "apellidoMaterno=:apellidoMaterno AND " + "nombres=:nombres AND " + "fechaNacimiento=:fecha");

        query.setText("apellidoPaterno", pte.getApellidoPaterno());
        query.setText("apellidoMaterno", pte.getApellidoMaterno());
        query.setText("nombres", pte.getNombres());
        query.setDate("fecha", pte.getFechaNacimiento());

        if (query.list().size() > 0) {
            paciente = (Paciente) query.list().get(0);
        } else {
            paciente = null;
        }
    } catch (HibernateException he) {
        manejaExcepcion(he);
    } finally {
        sesion.close();
    }

    return paciente;
}

From source file:Datos.ProcedimientoDAO.java

public List<Procedimiento> obtenerTodosPorFecha(Date fechaInicial, Date fechaFinal) throws HibernateException {
    List<Procedimiento> listaCubiculos = null;

    try {//from ww  w  .j a v a  2 s.c  o m
        iniciarOperacion();
        Query query = sesion
                .createQuery("from Procedimiento where fecha between :fechaInicial and :fechaFinal");
        query.setDate("fechaInicial", fechaInicial);
        query.setDate("fechaFinal", fechaFinal);

        listaCubiculos = query.list();
    } finally {
        sesion.close();
    }

    return listaCubiculos;
}

From source file:db.Database.java

public ArrayList<PaymentPosition> getPaymentPositionsByCategory(Category cat, Date from, Date to) {
    ArrayList<PaymentPosition> positions = new ArrayList<>();
    String sql = "select *\n" + "from paymentposition pp\n"
            + "inner join payment p on(pp.payment_paymentid = p.paymentid)\n"
            + "inner join cashflow cf on(p.PaymentID = cf.id)\n"
            + "WHERE pp.category_categoryID = :id AND cf.date between :from AND :to " + "order by p.paymentid";
    session = sessionFactory.openSession();
    Query query = session.createSQLQuery(sql).addEntity(PaymentPosition.class);
    query.setInteger("id", cat.getCategoryID());
    query.setDate("from", from);
    query.setDate("to", to);

    positions.addAll(query.list());/*  ww w  .  j a  v  a  2 s  . c o m*/

    session.close();

    return positions;
}

From source file:de.eod.jliki.users.utils.UserDBScheduler.java

License:Open Source License

/**
 * @see java.util.TimerTask#run()/*from   w ww. j a  v a  2 s  .co  m*/
 * {@inheritDoc}
 */
@Override
public final void run() {
    final SessionFactory sf = DBSetup.getDbManager().getSessionFactory();
    final Session session = sf.openSession();
    final Transaction trx = session.beginTransaction();

    // delete inactive users older than 24 hours
    final Calendar yesterday = Calendar.getInstance();
    yesterday.add(Calendar.DATE, -1);
    final Query deleteInactive = session
            .createQuery("delete User as u where u.active=:active " + "and u.registerdate < :yesterday");
    deleteInactive.setInteger("active", ActiveState.INACTIVE.ordinal());
    deleteInactive.setDate("yesterday", yesterday.getTime());
    deleteInactive.executeUpdate();

    // delete session id if invalid
    final int aWeek = -7;
    final Calendar aWeekAgo = Calendar.getInstance();
    aWeekAgo.add(Calendar.DATE, aWeek);
    final Query deleteCookieId = session
            .createQuery("from User as u where u.cookieid is not empty and u.lastlogin < :aweekago");
    deleteCookieId.setDate("aweekago", aWeekAgo.getTime());

    final Iterator<?> it = deleteCookieId.iterate();
    while (it.hasNext()) {
        final User user = (User) it.next();
        user.setCookieid("");
        session.update(user);
    }

    trx.commit();
    session.close();
}