package net.trajano.jee.domain.dao.impl;

import java.security.Principal;

import javax.ejb.Local;
import javax.ejb.Stateless;
import javax.enterprise.context.Dependent;
import javax.persistence.TypedQuery;

import net.trajano.jee.domain.dao.UserDAO;
import net.trajano.jee.domain.entity.User;

@Local
@Stateless
@Dependent
public class DefaultUserDAO extends BaseDAO implements
    UserDAO {

    @Override
    public User getByPrincipal(final Principal p) {

        final TypedQuery<User> q = em.createNamedQuery(NamedQueries.USER_GET_BY_USERNAME, User.class);
        q.setParameter("username", p.getName());
        return q.getSingleResult();
    }

    @Override
    public User getByUsername(final String username) {

        final TypedQuery<User> q = em.createNamedQuery(NamedQueries.USER_GET_BY_USERNAME, User.class);
        q.setParameter("username", username);
        return q.getSingleResult();
    }

    @Override
    public boolean isUsernameExist(final String username) {

        final TypedQuery<Long> q = em.createNamedQuery(NamedQueries.USER_COUNT_BY_USERNAME, Long.class);
        q.setParameter("username", username);
        return q.getSingleResult().longValue() == 1L;
    }

}

@@ -383,24 +383,137 @@
  UserDAO %7B%0A%0A
+    /**%0A     * %7B@code username%7D parameter.%0A     */%0A    private static final String PARAM_USERNAME = %22username%22;%0A%0A
     @Overrid
@@ -506,32 +506,32 @@
 %0A%0A    @Override%0A
-
     public User 
@@ -693,26 +693,30 @@
 rameter(
-%22username%22
+PARAM_USERNAME
 , p.getN
@@ -958,34 +958,38 @@
 etParameter(
-%22username%22
+PARAM_USERNAME
 , username);
@@ -1235,26 +1235,30 @@
 rameter(
-%22username%22
+PARAM_USERNAME
 , userna

Extract constant