@Test public void getByToken() { OAuthToken t = persistTestEntity(); OAuthToken retrievedToken = getTestDao().getByToken(t.getToken()); assertNotNull(retrievedToken); assertEquals(t.getToken(), retrievedToken.getToken()); assertEquals(t.getSecret(), retrievedToken.getSecret()); assertEquals(t.getPrincipal(), retrievedToken.getPrincipal()); assertEquals(t.isInRole("plcuser"), retrievedToken.isInRole("plcuser")); assertTrue(retrievedToken.getAttributes().isEmpty()); retrievedToken = getTestDao().getByToken("wrongToken"); assertNull(retrievedToken); }
@SuppressWarnings("unchecked") @Override public OAuthToken getByToken(String token) { StringBuilder builder = new StringBuilder(); builder.append("select t from ").append(getEntityType().getName()).append(" t where t.token = :token"); Query query = getEntityManager().createQuery(builder.toString()); query.setParameter("token", token); OAuthToken t = null; List<OAuthToken> results = query.getResultList(); if (CollectionUtils.isNotEmpty(results)) { t = results.get(0); } return t; }
TokenJPADao extends AbstractPLCEntityDao<OAuthToken> implements TokenDao { @SuppressWarnings("unchecked") @Override public OAuthToken getByToken(String token) { StringBuilder builder = new StringBuilder(); builder.append("select t from ").append(getEntityType().getName()).append(" t where t.token = :token"); Query query = getEntityManager().createQuery(builder.toString()); query.setParameter("token", token); OAuthToken t = null; List<OAuthToken> results = query.getResultList(); if (CollectionUtils.isNotEmpty(results)) { t = results.get(0); } return t; } }
TokenJPADao extends AbstractPLCEntityDao<OAuthToken> implements TokenDao { @SuppressWarnings("unchecked") @Override public OAuthToken getByToken(String token) { StringBuilder builder = new StringBuilder(); builder.append("select t from ").append(getEntityType().getName()).append(" t where t.token = :token"); Query query = getEntityManager().createQuery(builder.toString()); query.setParameter("token", token); OAuthToken t = null; List<OAuthToken> results = query.getResultList(); if (CollectionUtils.isNotEmpty(results)) { t = results.get(0); } return t; } @Inject  TokenJPADao(EntityManager em); }
TokenJPADao extends AbstractPLCEntityDao<OAuthToken> implements TokenDao { @SuppressWarnings("unchecked") @Override public OAuthToken getByToken(String token) { StringBuilder builder = new StringBuilder(); builder.append("select t from ").append(getEntityType().getName()).append(" t where t.token = :token"); Query query = getEntityManager().createQuery(builder.toString()); query.setParameter("token", token); OAuthToken t = null; List<OAuthToken> results = query.getResultList(); if (CollectionUtils.isNotEmpty(results)) { t = results.get(0); } return t; } @Inject  TokenJPADao(EntityManager em); @SuppressWarnings("unchecked") @Override OAuthToken getByToken(String token); }
TokenJPADao extends AbstractPLCEntityDao<OAuthToken> implements TokenDao { @SuppressWarnings("unchecked") @Override public OAuthToken getByToken(String token) { StringBuilder builder = new StringBuilder(); builder.append("select t from ").append(getEntityType().getName()).append(" t where t.token = :token"); Query query = getEntityManager().createQuery(builder.toString()); query.setParameter("token", token); OAuthToken t = null; List<OAuthToken> results = query.getResultList(); if (CollectionUtils.isNotEmpty(results)) { t = results.get(0); } return t; } @Inject  TokenJPADao(EntityManager em); @SuppressWarnings("unchecked") @Override OAuthToken getByToken(String token);  }