Example usage for org.hibernate Query setString

List of usage examples for org.hibernate Query setString

Introduction

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

Prototype

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

Source Link

Document

Bind a named String-valued parameter.

Usage

From source file:com.flexcore.dao_orm.ClienteDAO.java

@Override
public int obtenerCantidadClientesJuridicosBusqueda(String entrada) throws Exception {
    int cantidadClientes = 0;
    Transaction trans = session.beginTransaction();
    Query q = session.createSQLQuery(" { call obtenerCantidadClientesJuridicosBusqueda (?) }");
    q.setString(0, entrada); // first parameter, index starts with 0
    q.executeUpdate();//from w ww  .  j  a  v  a 2  s. c o m
    cantidadClientes = Integer.parseInt(q.list().get(0).toString());
    System.out.println("Obteniendo cantidad cliente Juridico");
    System.out.println(q.list().get(0));
    trans.commit();
    session.close();

    return cantidadClientes;
}

From source file:com.flexcore.dao_orm.CuentaAhorroAutomaticoDAO.java

@Override
public List<Cuentaahorroautomatico> verCuentasAhorroAutomatico(int pagina, String busqueda, int customerIF) {
    List<Cuentaahorroautomatico> listacuentaAhorro = new ArrayList<>();

    int datoInicial = (pagina - 1) * 10;
    int datoFinal = pagina * 10;

    Transaction trans = session.beginTransaction();

    Query q = session.createSQLQuery(" { call obtenerCuentasAhorroAutomatico(?,?,?,?) }")
            .setResultTransformer(Criteria.ALIAS_TO_ENTITY_MAP)

    ;//from   w w  w . ja v a 2 s. com
    q.setInteger(0, datoInicial);
    q.setInteger(1, datoFinal);
    q.setString(2, busqueda);
    q.setInteger(3, customerIF);
    q.executeUpdate();

    listacuentaAhorro = q.list();
    trans.commit();
    session.close();

    return listacuentaAhorro;
}

From source file:com.flexcore.dao_orm.CuentaAhorroAutomaticoDAO.java

public int obtenerCantidadCuentasAhorroAutomatico(String entrada, int customerIF) {
    int cantidadCuentasAhorro = 0;
    Transaction trans = session.beginTransaction();
    Query q = session.createSQLQuery(" { call obtenerCantidadCuentasAhorroAutomatico (?,?) }");
    q.setString(0, entrada);
    q.setInteger(1, customerIF);//from w w w  .  j  ava 2s  . c  om
    q.executeUpdate();
    cantidadCuentasAhorro = Integer.parseInt(q.list().get(0).toString());

    trans.commit();
    session.close();

    return cantidadCuentasAhorro;
}

From source file:com.flipkart.flux.dao.StatesDAOImpl.java

License:Apache License

@Override
@Transactional/*from  w  ww.  ja v  a  2 s .  c  om*/
public void updateStatus(Long stateId, Long stateMachineId, Status status) {
    Query query = currentSession().createQuery(
            "update State set status = :status where id = :stateId and stateMachineId = :stateMachineId");
    query.setString("status", status != null ? status.toString() : null);
    query.setLong("stateId", stateId);
    query.setLong("stateMachineId", stateMachineId);
    query.executeUpdate();
}

From source file:com.flipkart.flux.dao.StatesDAOImpl.java

License:Apache License

@Override
@Transactional/*from   w  w w.  ja v  a2 s.  com*/
public void updateRollbackStatus(Long stateId, Long stateMachineId, Status rollbackStatus) {
    Query query = currentSession().createQuery(
            "update State set rollbackStatus = :rollbackStatus where id = :stateId and stateMachineId = :stateMachineId");
    query.setString("rollbackStatus", rollbackStatus != null ? rollbackStatus.toString() : null);
    query.setLong("stateId", stateId);
    query.setLong("stateMachineId", stateMachineId);
    query.executeUpdate();
}

From source file:com.flipkart.flux.dao.StatesDAOImpl.java

License:Apache License

@Override
@Transactional/*from w  w w .j  a v a 2s.  c om*/
@SelectDataSource(DataSourceType.READ_ONLY)
public List findErroredStates(String stateMachineName, Long fromStateMachineId, Long toStateMachineId) {
    Query query = currentSession().createQuery(
            "select state.stateMachineId, state.id, state.status from StateMachine sm join sm.states state "
                    + "where sm.id between :fromStateMachineId and :toStateMachineId and sm.name = :stateMachineName and state.status in ('errored', 'sidelined', 'cancelled')");

    query.setLong("fromStateMachineId", fromStateMachineId);
    query.setLong("toStateMachineId", toStateMachineId);
    query.setString("stateMachineName", stateMachineName);

    return query.list();
}

From source file:com.flipkart.flux.dao.StatesDAOImpl.java

License:Apache License

@Override
@Transactional//from   w w w  .  j a  v  a2 s .  co m
@SelectDataSource(DataSourceType.READ_ONLY)
public List findErroredStates(String stateMachineName, Timestamp fromTime, Timestamp toTime, String stateName) {
    Query query;
    if (stateName == null) {
        query = currentSession().createQuery(
                "select state.stateMachineId, state.id, state.status from StateMachine sm join sm.states state "
                        + "where sm.id between (select min(id) from StateMachine where createdAt >= :fromTime) and (select max(id) from StateMachine where createdAt <= :toTime) "
                        + "and sm.name = :stateMachineName and state.status in ('errored', 'sidelined', 'cancelled')");
    } else {
        query = currentSession().createQuery(
                "select state.stateMachineId, state.id, state.status from StateMachine sm join sm.states state "
                        + "where sm.id between (select min(id) from StateMachine where createdAt >= :fromTime) and (select max(id) from StateMachine where createdAt <= :toTime) "
                        + "and sm.name = :stateMachineName and state.name = :stateName and state.status in ('errored', 'sidelined', 'cancelled')");
        query.setString("stateName", stateName);
    }

    query.setString("stateMachineName", stateMachineName);
    query.setTimestamp("fromTime", fromTime);
    query.setTimestamp("toTime", toTime);

    return query.list();
}

From source file:com.fordoctor.sqlimpl.HibernateUtil.java

public static List<?> getListBy_Date(String date) {

    Session ses = getSessionFactory().openSession();
    //        ses.createQuery("Seanse.findBysDate",date);
    ses.beginTransaction();//  ww w  . ja  v a2s . c o  m
    Query query = ses.getNamedQuery("Seanse.findBySDate");
    query.setString("sDate", date);
    List<Seanse> res = query.list();

    ses.getTransaction().commit();
    ses.flush();
    try {
        ses.close();
    } catch (HibernateException he) {
        JOptionPane.showMessageDialog(null, he.getMessage());
    }

    return res;
}

From source file:com.fordoctor.sqlimpl.HibernateUtil.java

public List<?> getListByName(String name) {
    Session ses = getSessionFactory().openSession();
    ses.beginTransaction();//from w  ww .j  av  a 2  s. c  om
    Query query = ses.getNamedQuery("Seanse.findByPacientName");
    query.setString("pacientName", name);
    List<Seanse> res = query.list();
    ses.getTransaction().commit();
    try {
        ses.close();
    } catch (HibernateException he) {

    }
    return res;
}

From source file:com.fortune.mypos.dao.ProductDaoImpl.java

@Override
public void deleteProductByCode(String productCode) {
    Query query = getSession().createSQLQuery("delete from Product where productCode = :productCode");
    query.setString("productCode", productCode);
    query.executeUpdate();/*from  w  ww .  ja  va  2 s  . c o m*/

}