Advertisement
Guest User

Untitled

a guest
May 27th, 2018
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 1.29 KB | None | 0 0
  1.     @SuppressWarnings("unchecked")
  2.     @Override
  3.     public List<Company> getByQuery(String companyName) throws SQLException
  4.     {
  5.         Session s = null;
  6.         CompanyDAOImpl company_dao = new CompanyDAOImpl();
  7.         List<Company> result = new ArrayList<Company>();
  8.         System.out.println("HELLLLO");
  9.         try {
  10.             s = session.openSession();
  11.             s.beginTransaction();
  12.  
  13.             String criteria = " where ";
  14.  
  15.             if (companyName != null)
  16.                 criteria += " company.name like '%" + companyName + "%' ";
  17.             else
  18.                 criteria += " true ";
  19.            
  20.             System.out.println(criteria);
  21.  
  22.             SQLQuery q = s.createSQLQuery("select distinct company.id, company.name from company" +
  23.                                                 criteria);
  24.             System.out.println(q);
  25.             List<Object[]> rows = q.list();
  26.             for(Object[] row : rows)
  27.             {
  28.                 int _id_ = (int) row[0];
  29.                 Company tmp = company_dao.getById(_id_);
  30.                 result.add(tmp);
  31.             }
  32.             s.getTransaction().commit();
  33.         }
  34.         finally
  35.         {
  36.             if (s != null && s.isOpen())
  37.                 s.close();
  38.         }
  39.         return result;
  40.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement