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.bloatit.data.DaoTeam.java

License:Open Source License

/**
 * Get a team using its name.//from w ww  . j a  v  a2 s.c  o  m
 * 
 * @param name the name of the team we are lookong for.
 * @return the team named <code>name<code> or null if not found.
 */
public static DaoTeam getByName(final String name) {
    final Session session = SessionManager.getSessionFactory().getCurrentSession();
    final Query q = session.getNamedQuery("team.byName");
    q.setString("login", name);
    return (DaoTeam) q.uniqueResult();
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

License:Open Source License

/**
 * Gets the completed task list for the specified actor
 * //from  w  w  w .j  a  v  a2 s .co m
 * @param jbpmContext  the jbpm context
 * @param actorId  the actor to retrieve tasks for
 * @return  the tasks
 */
@SuppressWarnings("unchecked")
private List<TaskInstance> findCompletedTaskInstances(JbpmContext jbpmContext, String actorId) {
    List<TaskInstance> result = null;
    try {
        Session session = jbpmContext.getSession();
        Query query = session.createQuery(COMPLETED_TASKS_QUERY);
        query.setString("actorId", actorId);
        result = query.list();
    } catch (Exception e) {
        String msg = messageService.getMessage(ERR_FIND_COMPLETED_TASK_INSTS, actorId);
        throw new JbpmException(msg, e);
    }
    return result;
}

From source file:com.bluexml.side.Framework.alfresco.jbpm.CustomJBPMEngine.java

License:Open Source License

@SuppressWarnings("unchecked")
private List<WorkflowTask> findActiveTaskInstances(final String authority, JbpmContext context) {
    Session session = context.getSession();
    Query query = session.getNamedQuery("org.alfresco.repo.workflow.findTaskInstancesByActorId");
    query.setString("actorId", authority);
    query.setBoolean("true", true);
    List<WorkflowTask> workflowTasks = getWorkflowTasks(session, query.list());
    // Do we need to clear a session here? It takes 3 seconds with 2000 workflows.
    // session.clear();
    return workflowTasks;
}

From source file:com.bolao.persistencia.dao.ApostadorDAO.java

public List<Apostador> list(ModoConsulta mc, Object object) {
    Session session = HibernateFactory.getSessionFactory();
    session.beginTransaction();/*from   ww w.  java2 s. com*/
    if (mc == ModoConsulta.DEFAULT || object == null) {
        lista.clear();
        Query query = session.createQuery(" from Apostador");
        lista = query.list();
    } else if (mc == ModoConsulta.NOME_APOSTADOR && object != null) {
        lista.clear();
        Query query = session.createQuery(" from Apostador where nome like :XNOME");
        query.setString("XNOME", "%" + String.valueOf(object) + "%");
        lista = query.list();
    } else if (mc == ModoConsulta.DATA_NASC && object != null) {
        lista.clear();
        Query query = session.createQuery(" from Apostador where datanascimento =:XDATA");
        query.setDate("XDATA", conversorData.converterData(String.valueOf(object)));
        lista = query.list();
    } else if (mc == ModoConsulta.EMAIL && object != null) {
        lista.clear();
        Query query = session.createQuery(" from Apostador where email like :XEMAIL");
        query.setString("XEMAIL", "%" + String.valueOf(object) + "%");
        lista = query.list();
    } else if (mc == ModoConsulta.APELIDO && object != null) {
        lista.clear();
        Query query = session.createQuery(" from Apostador where apelido like :XAPELIDO");
        query.setString("XAPELIDO", "%" + String.valueOf(object) + "%");
        lista = query.list();
    }
    session.getTransaction().commit();
    session.close();
    return lista;
}

From source file:com.bolao.persistencia.dao.GrupoDAO.java

public List<Grupo> list(ModoConsulta mc, Object object) {
    Session session = HibernateFactory.getSessionFactory();
    session.beginTransaction();// www.  ja v a2  s.co m
    if (mc == ModoConsulta.DEFAULT || object == null) {
        lista.clear();
        Query query = session.createQuery(" from Grupo");
        lista = query.list();
    } else if (mc == ModoConsulta.CODIGO && object != null) {
        lista.clear();
        Query query = session.createQuery(" from Grupo where codigo =:XCODIGO");
        query.setInteger("XCODIGO", Integer.parseInt(String.valueOf(object)));
        lista = query.list();
    } else if (mc == ModoConsulta.GRUPO && object != null) {
        lista.clear();
        Query query = session.createQuery(" from Grupo where descricao like :XDESCRICAO");
        query.setString("XDESCRICAO", "%" + String.valueOf(object) + "%");
        lista = query.list();
    }
    session.getTransaction().commit();
    session.close();
    return lista;
}

From source file:com.bolao.persistencia.dao.TimeDAO.java

public List<Time> list(ModoConsulta modoConsulta, Object object, Object dataObject) {
    try {/*ww  w  . j a v a 2  s.co m*/
        Session session = HibernateFactory.getSessionFactory();
        session.beginTransaction();
        if (modoConsulta == ModoConsulta.CIDADE && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.cidade like :XCIDADE order by t.codigo,t.cidade ");
            query.setString("XCIDADE", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.CODIGO && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.codigo =:xcodigo order by t.cidade asc,t.codigo desc");
            query.setInteger("xcodigo", Integer.parseInt(String.valueOf(object)));
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.DATA_CADASTRO && object != null && !object.toString().isEmpty()
                && dataObject != null && !dataObject.toString().isEmpty()) {
            lista.clear();
            Query query = session.createQuery(
                    " from Time t where t.datacadastro between :XDATAINI AND :XDATAFIM  order by t.cidade asc,t.codigo desc");
            query.setDate("XDATAINI", conversorData.converterData(String.valueOf(object)));
            query.setDate("XDATAFIM", conversorData.converterData(String.valueOf(dataObject)));
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.DATA_FUNDACAO && object != null && !object.toString().isEmpty()
                && dataObject != null && !dataObject.toString().isEmpty()) {
            lista.clear();
            Query query = session.createQuery(
                    " from Time t where t.datafundacao between :XDATAINI AND :XDATAFIM order by t.cidade asc,t.codigo desc");
            query.setDate("XDATAINI", conversorData.converterData(String.valueOf(object)));
            query.setDate("XDATAFIM", conversorData.converterData(String.valueOf(dataObject)));
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.DEFAULT || object == null || object.toString().isEmpty()) {
            lista.clear();
            Query query = session.createQuery(" from Time t order by t.codigo,t.cidade ");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.EMAIL && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.email like :XEMAIL order by t.codigo,t.cidade");
            query.setString("XEMAIL", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.ENDERECO && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.endereco like :XENDERECO order by t.codigo,t.cidade");
            query.setString("XENDERECO", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.SITE && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.site like :XSITE order by t.codigo,t.cidade");
            query.setString("XSITE", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.TELEFONE && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.telefone like :XTELEFONE order by t.codigo,t.cidade");
            query.setString("XTELEFONE", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.TIME && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.nome like :XNOME order by t.codigo,t.cidade");
            query.setString("XNOME", "%" + String.valueOf(object) + "%");
            lista = query.list();
        } else if (modoConsulta == ModoConsulta.DESCRICAO && object != null && !object.toString().isEmpty()) {
            lista.clear();
            Query query = session
                    .createQuery(" from Time t where t.descricao like :XNOME order by t.codigo,t.cidade");
            query.setString("XNOME", "%" + String.valueOf(object) + "%");
            lista = query.list();
        }
        session.getTransaction().commit();
        session.close();
    } catch (Exception e) {
    }
    return lista;
}

From source file:com.br.uepb.dao.LoginDAO.java

License:Open Source License

/**
 * Mtodo para obter o objeto LoginDomain de acordo com a identificao de usurio e senha
 * @param usuario Nome de usurio para realizar o login
 * @param senha Senha do usurio/*from   w w w . ja  va  2 s  .c o m*/
 * @return LoginDomain
 */
public LoginDomain obtemLogin(String usuario, String senha) {
    Query query = SessaoAtual().createQuery("FROM LoginDomain WHERE login = :usuario AND senha = :senha");
    query.setString("usuario", usuario);
    query.setString("senha", senha);
    LoginDomain login = (LoginDomain) query.uniqueResult();

    return login;
}

From source file:com.br.uepb.dao.LoginDAO.java

License:Open Source License

/**
 * Mtodo para verificar se um usurio ja existe, 
 * se o usurio existir o retorno ser true, caso contrrio ser false
 * @param usuario Nome do usurio/*from  w w  w  .  j a v a  2 s .c o m*/
 * @return Boolean
 */
public boolean jaExisteUsuario(String usuario) {
    Query query = SessaoAtual().createQuery("FROM LoginDomain WHERE login = :usuario");
    query.setString("usuario", usuario);
    return (query.uniqueResult() != null);
}

From source file:com.bsc.collect.dao.UserDaoImpl.java

public void deleteUserBySsn(String user_id) {
    Query query = getSession().createSQLQuery("delete from user where user_id = :user_id");
    query.setString("user_id", user_id);
    query.executeUpdate();//w w w . java 2  s . c  o m
}

From source file:com.cabable.inventory.db.DriverDAO.java

public int delete(Driver driver) {
    Query q = namedQuery("Driver.delete");
    q.setString("driver_license_no", driver.getDriver_license_no());
    return q.executeUpdate();
}