Example usage for org.hibernate SQLQuery setParameter

List of usage examples for org.hibernate SQLQuery setParameter

Introduction

In this page you can find the example usage for org.hibernate SQLQuery setParameter.

Prototype

@Override
    NativeQuery<T> setParameter(int position, Object val);

Source Link

Usage

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

License:Apache License

/** {@inheritDoc} */
@Override//from  ww  w .  j  a  v a2  s .c om
public IssueTrackerProject findIssueTrackerProjectForTiTAProject(Long tp, Long issueTrackerId, Long itp) {
    String queryString = "select * from issue_tracker_project itp "
            + "join tita_project tp on itp.tita_project_id = tp.id "
            + "where tp.id = ? and itp.isst_id = ? and itp.isst_project_id = ? ";

    org.hibernate.SQLQuery q = getSession().createSQLQuery(queryString.toUpperCase());
    q.addEntity(IssueTrackerProject.class);
    // CHECKSTYLE:OFF
    q.setParameter(0, tp);
    q.setParameter(1, issueTrackerId);
    q.setParameter(2, itp);
    // CHECKSTYLE:ON

    return (IssueTrackerProject) q.list().get(0);
}

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

License:Apache License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override/*w w w .j  a v  a  2  s.co m*/
public IssueTrackerTask findIssueTrackerTask(Long tp, Long it, Long itp, Long itt) {
    String queryString = "select * from issue_tracker_task itt "
            + "join issue_tracker_project itp on itt.issue_tracker_project_id = itp.id "
            + "join tita_project tp on itp.tita_project_id = tp.id "
            + "where tp.id = ? and itp.isst_id = ? and itp.isst_project_id = ? " + "and itt.isst_task_id = ? ";

    org.hibernate.SQLQuery q = getSession().createSQLQuery(queryString.toUpperCase());
    q.addEntity(IssueTrackerTask.class);
    // CHECKSTYLE:OFF
    q.setParameter(0, tp);
    q.setParameter(1, it);
    q.setParameter(2, itp);
    q.setParameter(3, itt);
    // CHECKSTYLE:ON

    List<IssueTrackerTask> task = q.list();

    if (task.size() != 0) {
        return task.get(0);
    } else {
        return null;
    }
}

From source file:at.ac.tuwien.ifs.tita.dao.project.TiTAProjectDao.java

License:Apache License

/** {@inheritDoc} */
@SuppressWarnings("unchecked")
@Override/*from www  .  j a  va 2s .com*/
public List<TiTAProject> findTiTAProjectsForUsername(String username) {
    String queryString = "select * from TITA_PROJECT tp, USER_PROJECT up, TITA_USER tu "
            + " where tp.id = up.tita_project_id and up.user_id = tu.id and tu.username = ? ";

    org.hibernate.SQLQuery query = getSession().createSQLQuery(queryString.toUpperCase());
    query.setParameter(0, username);
    query.addEntity(TiTAProject.class);

    return query.list();
}

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

License:Apache License

/** {@inheritDoc} */
@Override//from   w w  w .ja  va  2 s  .co  m
public Long findEffortsSumForIssueTrackerTask(Long tpId, String username, Long issTProjectId, Long isstTTaskId,
        Long isstId) {
    String queryString = "select sum(duration) as duration from effort e "
            + "join issue_tracker_task itt on e.issuet_task_id = itt.id "
            + "join issue_tracker_project itp on itt.issue_tracker_project_id = itp.id "
            + "join tita_project tp on itp.tita_project_id = tp.id " + "join tita_user tu on e.user_id = tu.id "
            + "where tp.id = ? and itp.isst_id = ? and itp.isst_project_id = ? "
            + "and itt.isst_task_id = ? and tu.username = ?";

    org.hibernate.SQLQuery q = getSession().createSQLQuery(queryString.toUpperCase());
    // q.addEntity(Long.class);
    // CHECKSTYLE:OFF
    q.setParameter(0, tpId);
    q.setParameter(1, isstId);
    q.setParameter(2, issTProjectId);
    q.setParameter(3, isstTTaskId);
    q.setParameter(4, username);
    // CHECKSTYLE:ON

    Object obj = q.uniqueResult();

    if (obj != null) {
        return new Long(((BigDecimal) obj).longValue());
    }
    return null;
}

From source file:bookstore.BookStoreManager.java

public void deleteManyToMany() throws IOException {
    try {/*  w  w w  .  ja v a 2  s  . c  o m*/
        //Tao session va bat dau lam viec voi session do
        Session session = sf.openSession();
        session.beginTransaction();

        //nguoi dung nhap ma cuon sach muon xoa
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        System.out.println("Input ID Book want delete");
        int isbm = Integer.parseInt(input.readLine());

        //Viet cau lenh sql de xoa lien ket giua cuon sach voi tac gia trong bang bookauthor
        String sql = "delete from bookauthor where isbm = :isbm";
        SQLQuery query = session.createSQLQuery(sql);
        query.setParameter("isbm", isbm);
        query.executeUpdate();

        //Viet cau lenh xoa mot cuon sach co ma isbm vua nhap
        sql = "delete from book where isbm =:isbm";
        query = session.createSQLQuery(sql);
        //set paramete cho cau truy van tren
        query.setParameter("isbm", isbm);
        //dung executeUpdate() de thuc thi cau truy van
        query.executeUpdate();
        session.getTransaction().commit();
        //sau khi thuc hien xong cong viec thi dong session lai
        session.close();
        System.out.println("done");
        //            hql = "delete from Book where isbm =:isbm";
        //            q1 = session.createQuery(hql);
        //            q1.setParameter("isbm", isbm);
        //            q1.executeUpdate();

        session.getTransaction().commit();
        session.close();
        System.out.println("Done");
    } catch (Exception e) {
    }
}

From source file:br.com.financeiro.dao.LancamentoDAOHibernate.java

@Override
public float saldo(Conta conta, Date data) {
    StringBuffer sql = new StringBuffer();

    sql.append("select sum(l.valor * c.fator)");
    sql.append("from LANCAMENTO l,");
    sql.append("  CATEGORIA c");
    sql.append(" where l.categoria = c.codigo");
    sql.append("  and l.conta = :conta");
    sql.append("  and l.data <= :data");
    SQLQuery query = this.session.createSQLQuery(sql.toString());
    query.setParameter("conta", conta.getConta());
    query.setParameter("data", data);
    BigDecimal saldo = (BigDecimal) query.uniqueResult();
    if (saldo != null) {
        return saldo.floatValue();
    }//from  w  w  w.ja v  a  2 s  .  com

    return 0f;
}

From source file:br.com.gvt.eng.vod.dao.MenuDAO.java

public void disableEnableMenus(IpvodVisualMenu parentMenu, Integer active) {
    StringBuilder sql = new StringBuilder("update IPVOD_VISUAL_MENU set ACTIVE = :active where menu_id in ( "
            + "   select unique m.menu_id from IPVOD_VISUAL_MENU m "
            + "   left join IPVOD_VISUAL_MENU m2 on m.menu_sup_id = m2.menu_sup_id "
            + "   start with m.menu_id = 503548 connect by prior m.menu_id = m2.menu_sup_id) ");
    SQLQuery query = super.getSession().createSQLQuery(sql.toString());
    query.setParameter("active", active);
    query.executeUpdate();//  ww  w  . j a  v a  2s .  c  o m
}

From source file:br.com.jn.dao.CandidatoDAO.java

public List<Candidato> listar() {
    Authentication a = SecurityContextHolder.getContext().getAuthentication();
    //Authentication authentication = context.getAuthentication();
    Object principal = a.getPrincipal();
    String username = "";
    username = (((User) a.getPrincipal()).getUsername());
    //username = ((UserDetails) principal).getUsername();
    System.out.println("login selecionado:" + username);

    Session session = HibernateUtil.getSessionFactory().getCurrentSession();
    session.beginTransaction();// w  ww  .  j  a  v  a  2s  . c o  m

    String sql = "select * from users where username = :username";
    SQLQuery query = session.createSQLQuery(sql);
    query.addEntity(Users.class);
    query.setParameter("username", username);
    //Users usuario = (Users) query.uniqueResult();
    List logado = query.list();
    //List<Users> results = query.getResultList();

    String UserId = logado.get(0).toString();
    String usuario = "4";
    //System.out.println("Id do usuario selecionado:" + usuario.getUserId());
    //System.out.println("Id do usuario selecionado:" + usuario.getNome());

    //Integer UserId = usuario.getUserId();
    System.out.println("Id do usuario selecionado:" + UserId);

    Criteria crit = session.createCriteria(Candidato.class);
    crit.add(Restrictions.ge("notaEliminatoria", (5.0)));
    crit.add(Restrictions.eq("orientador1", username));
    crit.addOrder(Order.asc("nome"));

    List<Candidato> lista = crit.list();
    session.close();
    return lista;
}

From source file:br.com.sgejs.dao.DaoDependente.java

public List<Dependente> listDependentes(long id) {
    SQLQuery q = sessao.createSQLQuery(
            "select * from Dependente d where d.id in (select sd.aluno_id from servidor_dependente sd where sd.servidor_id=:id)")
            .addEntity(classe);/*from  ww  w.  j av  a  2  s . co m*/
    q.setParameter("id", id);
    return q.list();
}

From source file:br.com.sgejs.dao.DaoDependente.java

public boolean deleterDependente(Dependente d) {
    try {//from  w w  w .ja v a2  s.  co  m
        SQLQuery q1 = sessao.createSQLQuery("delete from servidor_dependente where aluno_id=:id");
        q1.setParameter("id", d.getId());
        q1.executeUpdate();
        return remove(d);
    } catch (HibernateException e) {
        System.out.println("causa: " + e.getCause());
        return false;
    }
}