@Override public Customer getByLoginAndPassword(final String login, final String password) { Session session = null; Transaction transaction = null; Customer customer = null; try { session = sf.openSession(); transaction = session.beginTransaction(); Query query = session.createQuery("from Customer where login = "******":login and password = :password"); query.setString("login", login); query.setString("password", PASSWORD_ENCRYPTOR.getCryptString(password)); customer = (Customer) query.uniqueResult(); transaction.commit(); } catch (RuntimeException e) { try { transaction.rollback(); } catch (RuntimeException re) { LOGGER.error(ROLLBACK_EXC_MSG, re); } throw e; } finally { if (session != null) { session.close(); } } return customer; }
@Override public boolean save(final Customer... customers) { Session session = null; Transaction transaction = null; try { session = sf.openSession(); transaction = session.beginTransaction(); for (Customer c : customers) { c.setPassword(PASSWORD_ENCRYPTOR.getCryptString(c.getPassword())); c.setId((Integer) session.save(c)); } transaction.commit(); } catch (RuntimeException e) { try { transaction.rollback(); } catch (RuntimeException re) { LOGGER.error(ROLLBACK_EXC_MSG, re); } throw e; } finally { if (session != null) { session.close(); } } return true; }