Example usage for org.hibernate Criteria uniqueResult

List of usage examples for org.hibernate Criteria uniqueResult

Introduction

In this page you can find the example usage for org.hibernate Criteria uniqueResult.

Prototype

public Object uniqueResult() throws HibernateException;

Source Link

Document

Convenience method to return a single instance that matches the query, or null if the query returns no results.

Usage

From source file:com.app.billingapp.dao.impl.CategotyImpl.java

@Override
public Categories findByName(String name) {
    Criteria crit = createEntityCriteria();
    crit.add(Restrictions.eq("name", name));
    return (Categories) crit.uniqueResult();
}

From source file:com.app.billingapp.dao.impl.RolesImpl.java

@Override
public Set<Roles> fildAllRoles() {
    Criteria crit = createEntityCriteria();
    //crit.add(Restrictions.eq("username", name) );
    return (Set<Roles>) (Roles) crit.uniqueResult();
}

From source file:com.app.billingapp.dao.impl.UserImpl.java

@Override
public User findByName(String name) {
    Criteria crit = createEntityCriteria();
    crit.add(Restrictions.eq("username", name));
    return (User) crit.uniqueResult();
}

From source file:com.app.billingapp.dao.impl.UserImpl.java

@Override
public User findByEmail(String email) {
    Criteria crit = createEntityCriteria();
    crit.add(Restrictions.eq("email", email));
    return (User) crit.uniqueResult();
}

From source file:com.app.gpo.dao.OrderItemDAO.java

License:Open Source License

public boolean isInDbByOrderNumber(String orderNumber) {
    Criteria criteria = getSession().createCriteria(OrderItem.class);
    criteria.add(Restrictions.like("orderNumber", orderNumber + "%"));
    criteria.setProjection(Projections.rowCount());
    long count = (Long) criteria.uniqueResult();
    logger.info("DB count " + count + " for order items with order number " + orderNumber);
    if (count != 0) {
        logger.info("In DB exist" + count + " order items with order number " + orderNumber);
        return true;
    } else {/*from w  w  w.  j a  v  a2  s  .  c o  m*/
        logger.info("In DB no exist order items with order number " + orderNumber);
        return false;
    }
}

From source file:com.app.inventario.dao.ProveedorDAOImpl.java

public Proveedor obtenerProveedorNombre(String nombreProveedor) {
    Proveedor proveedor = null;//from   w ww .jav a 2s.c o m
    try {
        this.iniciaOperacion();
        Criteria criteria = session.createCriteria(Proveedor.class)
                .add(Restrictions.eq("nombreProveedor", nombreProveedor));
        proveedor = (Proveedor) criteria.uniqueResult();
    } catch (HibernateException he) {
        Logger.getLogger(ProveedorDAOImpl.class.getName()).log(Level.SEVERE, null, he);
        //tx.rollback();
        throw he;
    } finally {
        // Cerrar la session
    }
    return proveedor;
}

From source file:com.app.inventario.dao.UsuarioDAOImpl.java

public boolean validarUsername(String username) {
    Usuario result = null;//from   www . j ava  2 s. c o  m
    try {
        this.iniciaOperacion();
        Criteria criteria = session.createCriteria(Usuario.class).add(Restrictions.eq("username", username));
        result = (Usuario) criteria.uniqueResult();
    } catch (HibernateException he) {
        this.manejaExcepcion(he);
    } finally {
        // Cerrar la session
    }
    return result == null;
}

From source file:com.app.inventario.dao.UsuarioDAOImpl.java

public Usuario obtenerUsuarioUsername(String username) {
    Usuario usuario = null;//w  ww  .j  a va 2s  .  c o  m
    try {
        this.iniciaOperacion();
        Criteria criteria = session.createCriteria(Usuario.class).add(Restrictions.eq("username", username));
        usuario = (Usuario) criteria.uniqueResult();
    } catch (HibernateException he) {
        this.manejaExcepcion(he);
    } finally {
        // Cerrar la session
    }
    usuario.setPassword("");
    usuario.setConfirmarContrasena("");
    usuario.setFacturas(null);
    return usuario;
}

From source file:com.app.inventario.dao.UsuarioDAOImpl.java

public UserDetails loadUserByUsername(String username) {
    Usuario usuario = null;/*from  w w w .  j av  a2  s.c  o  m*/
    try {
        this.iniciaOperacion();
        Criteria criteria = session.createCriteria(Usuario.class).add(Restrictions.eq("username", username));
        usuario = (Usuario) criteria.uniqueResult();
    } catch (HibernateException he) {
        this.manejaExcepcion(he);
    } finally {
    }
    return usuario;
}

From source file:com.apt.facade.SubmitFacade.java

public Submit findSubmit(Assignment assignment, Student student) {
    Session session = null;// w  w w .  j av  a  2  s .co m
    Transaction trans = null;
    Submit submit = new Submit();

    try {

        session = HibernateUtil.getSessionFactory().getCurrentSession();
        trans = session.beginTransaction();

        Criteria crit = session.createCriteria(Submit.class);
        crit.add(Restrictions.eq("assignment", assignment));
        crit.add(Restrictions.eq("student", student));
        submit = (Submit) crit.uniqueResult();

        trans.commit();

    } catch (Exception e) {
        e.printStackTrace();
        if (trans != null) {
            trans.rollback();
        }
    } finally {
        if (session != null && session.isConnected()) {
            session.close();
        }
    }
    return submit;
}