寻找一些关于在认证时查询用户的反馈。在编写下面的代码时,我的第一个想法是通过查询数据库中的所有用户名并检查提供的用户名是否属于用户列表来获取用户名。当用户表增长时,这种类型的检查会成为性能问题吗?
EntityManager entityManager = factory.createEntityManager();
/*Create a data structure to hold a list of users in our database*/
List<String> allUsernames = new ArrayList<String>();
allUsernames = entityManager.createQuery("SELECT user.username FROM Users user").getResultList();
/*Loop through each user in our available usernames checking if the username passed exists*/
for (String user : allUsernames) {
if (user.equals(username)) {
System.out.println("Found real user\n");
userFoundFLAG = 1; // set the flag equal to 1 when this user is found
}
}