@Test public void getByUsernameDoesntExist() { PLCUser retrievedUser = getTestDao().getByUsername("wrong"); assertNull(retrievedUser); }
@SuppressWarnings("unchecked") @Transactional public PLCUser getByUsername(String username) { StringBuilder builder = new StringBuilder(); builder.append("select u from ").append(getEntityType().getName()).append(" u where u.username = :username"); Query query = getEntityManager().createQuery(builder.toString()); query.setParameter("username", username); List<PLCUser> results = query.getResultList(); PLCUser result = null; if (CollectionUtils.isNotEmpty(results)) { result = results.get(0); } return result; }
PLCUserJPADao extends AbstractPLCEntityDao<PLCUser> implements PLCUserDao { @SuppressWarnings("unchecked") @Transactional public PLCUser getByUsername(String username) { StringBuilder builder = new StringBuilder(); builder.append("select u from ").append(getEntityType().getName()).append(" u where u.username = :username"); Query query = getEntityManager().createQuery(builder.toString()); query.setParameter("username", username); List<PLCUser> results = query.getResultList(); PLCUser result = null; if (CollectionUtils.isNotEmpty(results)) { result = results.get(0); } return result; } }
PLCUserJPADao extends AbstractPLCEntityDao<PLCUser> implements PLCUserDao { @SuppressWarnings("unchecked") @Transactional public PLCUser getByUsername(String username) { StringBuilder builder = new StringBuilder(); builder.append("select u from ").append(getEntityType().getName()).append(" u where u.username = :username"); Query query = getEntityManager().createQuery(builder.toString()); query.setParameter("username", username); List<PLCUser> results = query.getResultList(); PLCUser result = null; if (CollectionUtils.isNotEmpty(results)) { result = results.get(0); } return result; } @Inject  PLCUserJPADao(EntityManager em); }
PLCUserJPADao extends AbstractPLCEntityDao<PLCUser> implements PLCUserDao { @SuppressWarnings("unchecked") @Transactional public PLCUser getByUsername(String username) { StringBuilder builder = new StringBuilder(); builder.append("select u from ").append(getEntityType().getName()).append(" u where u.username = :username"); Query query = getEntityManager().createQuery(builder.toString()); query.setParameter("username", username); List<PLCUser> results = query.getResultList(); PLCUser result = null; if (CollectionUtils.isNotEmpty(results)) { result = results.get(0); } return result; } @Inject  PLCUserJPADao(EntityManager em); @SuppressWarnings("unchecked") @Transactional PLCUser getByUsername(String username); }
PLCUserJPADao extends AbstractPLCEntityDao<PLCUser> implements PLCUserDao { @SuppressWarnings("unchecked") @Transactional public PLCUser getByUsername(String username) { StringBuilder builder = new StringBuilder(); builder.append("select u from ").append(getEntityType().getName()).append(" u where u.username = :username"); Query query = getEntityManager().createQuery(builder.toString()); query.setParameter("username", username); List<PLCUser> results = query.getResultList(); PLCUser result = null; if (CollectionUtils.isNotEmpty(results)) { result = results.get(0); } return result; } @Inject  PLCUserJPADao(EntityManager em); @SuppressWarnings("unchecked") @Transactional PLCUser getByUsername(String username);  }