本文整理汇总了Java中javax.persistence.criteria.CriteriaQuery.distinct方法的典型用法代码示例。如果您正苦于以下问题:Java CriteriaQuery.distinct方法的具体用法?Java CriteriaQuery.distinct怎么用?Java CriteriaQuery.distinct使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.criteria.CriteriaQuery
的用法示例。
在下文中一共展示了CriteriaQuery.distinct方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getGuardianByEmail
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@GET
@Path("/guardian/{guardianEmail}")
@Produces({"application/xml", "application/json"})
@RolesAllowed({"Guardian", "Administrator"})
public Guardian getGuardianByEmail(@PathParam("guardianEmail") String email) {
logger.log(Level.INFO, "Principal is: {0}", ctx.getCallerPrincipal().getName());
CriteriaQuery<Guardian> cq = cb.createQuery(Guardian.class);
Root<Guardian> guardian = cq.from(Guardian.class);
cq.select(guardian);
cq.where(cb.equal(guardian.get(Guardian_.email), email));
cq.distinct(true);
TypedQuery<Guardian> q = em.createQuery(cq);
return q.getSingleResult();
}
示例2: getStatusByGuardianEmail
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@GET
@Path("email/{guardianEmail}")
@Produces({"application/xml", "application/json"})
@RolesAllowed({"Guardian", "Administrator"})
public List<Student> getStatusByGuardianEmail(@PathParam("guardianEmail") String email) {
logger.log(Level.INFO, "Principal is: {0}", ctx.getCallerPrincipal().getName());
CriteriaQuery<Student> cq = cb.createQuery(Student.class);
Root<Student> student = cq.from(Student.class);
Join<Student, Guardian> guardian = student.join(Student_.guardians);
cq.select(student);
cq.where(cb.equal(guardian.get(Guardian_.email), email));
cq.distinct(true);
TypedQuery<Student> q = em.createQuery(cq);
List<Student> results = q.getResultList();
logger.log(Level.INFO, "Guardian {0}has {1} students.", new Object[]{email, results.size()});
return results;
}
示例3: getStatusByGuardianId
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
@GET
@Path("id/{guardianId}")
@Produces({"application/xml", "application/json"})
public List<Student> getStatusByGuardianId(@PathParam("guardianId") Long id) {
logger.log(Level.INFO, "Principal is: {0}", ctx.getCallerPrincipal().getName());
CriteriaQuery<Student> cq = cb.createQuery(Student.class);
Root<Student> student = cq.from(Student.class);
Join<Student, Guardian> guardian = student.join(Student_.guardians);
cq.select(student);
cq.where(cb.equal(guardian.get(Guardian_.id), id));
cq.distinct(true);
TypedQuery<Student> q = em.createQuery(cq);
return q.getResultList();
}
示例4: getAllGuardians
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<Guardian> getAllGuardians() {
CriteriaQuery<Guardian> cq = em.getCriteriaBuilder().createQuery(Guardian.class);
Root<Guardian> guardian = cq.from(Guardian.class);
cq.select(guardian);
cq.distinct(true);
TypedQuery<Guardian> q = em.createQuery(cq);
return q.getResultList();
}
示例5: getAllStudents
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<Student> getAllStudents() {
CriteriaQuery<Student> cq = em.getCriteriaBuilder().createQuery(Student.class);
Root<Student> student = cq.from(Student.class);
cq.select(student);
cq.where(cb.isTrue(student.get(Student_.active)));
cq.distinct(true);
TypedQuery<Student> q = em.createQuery(cq);
return q.getResultList();
}
示例6: getStudentByName
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public Student getStudentByName(String lastName, String firstName) {
CriteriaQuery<Student> cq = em.getCriteriaBuilder().createQuery(Student.class);
Root<Student> student = cq.from(Student.class);
cq.select(student);
cq.where(cb.equal(student.get(Student_.lastName), lastName));
cq.where(cb.equal(student.get(Student_.firstName), firstName));
cq.distinct(true);
TypedQuery<Student> q = em.createQuery(cq);
return q.getSingleResult();
}
示例7: getAllTutoringSessions
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<TutoringSession> getAllTutoringSessions() {
CriteriaQuery<TutoringSession> cq = cb.createQuery(TutoringSession.class);
Root<TutoringSession> session = cq.from(TutoringSession.class);
cq.select(session);
cq.distinct(true);
TypedQuery<TutoringSession> q = em.createQuery(cq);
List<TutoringSession> sessions = q.getResultList();
logger.log(Level.INFO, "Total number of sessions: {0}", sessions.size());
return sessions;
}
示例8: getTodaysSession
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public TutoringSession getTodaysSession() {
// get today's date and trim the time information
Calendar today = Calendar.getInstance();
CalendarUtil.stripTime(today);
// find today's session
SimpleDateFormat formatter = new SimpleDateFormat("E, MMM d, yyyy");
logger.log(Level.INFO, "Finding tutoring session for {0}", formatter.format(today.getTime()));
CriteriaQuery<TutoringSession> cq = cb.createQuery(TutoringSession.class);
Root<TutoringSession> tutoringSession = cq.from(TutoringSession.class);
cq.select(tutoringSession);
cq.where(cb.equal(tutoringSession.get(TutoringSession_.sessionDate), today));
cq.distinct(true);
TypedQuery<TutoringSession> q = em.createQuery(cq);
TutoringSession session;
try {
session = q.getSingleResult();
logger.info("Found session for today.");
} catch (NoResultException e) {
logger.info("Today's session not found. Creating a new session.");
session = new TutoringSession();
em.persist(session);
}
return session;
}
示例9: getStatusEntriesByDate
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<StatusEntry> getStatusEntriesByDate(Date date) {
Calendar cal = Calendar.getInstance();
cal.setTime(date);
CriteriaQuery<StatusEntry> cq = cb.createQuery(StatusEntry.class);
Root<StatusEntry> statusEntry = cq.from(StatusEntry.class);
cq.select(statusEntry);
cq.where(cb.equal(statusEntry.get(StatusEntry_.statusDate), cal));
cq.distinct(true);
TypedQuery<StatusEntry> q = em.createQuery(cq);
return q.getResultList();
}
示例10: getStudentsByStatus
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
private List<Student> getStudentsByStatus(StatusType statusType) {
CriteriaQuery<Student> cq = cb.createQuery(Student.class);
Root<Student> student = cq.from(Student.class);
cq.select(student);
cq.where(cb.equal(student.get(Student_.status),
statusType));
cq.distinct(true);
TypedQuery<Student> q = em.createQuery(cq);
return q.getResultList();
}
示例11: getAllAddresses
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<Address> getAllAddresses() {
CriteriaQuery<Address> cq = em.getCriteriaBuilder().createQuery(Address.class);
Root<Address> address = cq.from(Address.class);
cq.select(address);
cq.where(cb.isTrue(address.get(Address_.active)));
cq.distinct(true);
TypedQuery<Address> q = em.createQuery(cq);
return q.getResultList();
}
示例12: getAllInactiveStudents
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<Student> getAllInactiveStudents() {
CriteriaQuery<Student> cq = em.getCriteriaBuilder().createQuery(Student.class);
Root<Student> student = cq.from(Student.class);
cq.select(student);
cq.where(cb.isFalse(student.get(Student_.active)));
cq.distinct(true);
TypedQuery<Student> q = em.createQuery(cq);
return q.getResultList();
}
示例13: findStudentById
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public Student findStudentById(long id) {
logger.log(Level.INFO, "Finding student with ID: {0}", id);
CriteriaQuery<Student> cq = em.getCriteriaBuilder().createQuery(Student.class);
Root<Student> student = cq.from(Student.class);
cq.select(student);
cq.where(cb.isTrue(student.get(Student_.active)));
cq.where(cb.equal(student.get(Student_.id), id));
cq.distinct(true);
TypedQuery<Student> q = em.createQuery(cq);
return q.getSingleResult();
}
示例14: getCurrentStatusEntries
import javax.persistence.criteria.CriteriaQuery; //导入方法依赖的package包/类
public List<StatusEntry> getCurrentStatusEntries() {
CriteriaQuery<StatusEntry> cq = cb.createQuery(StatusEntry.class);
Root<StatusEntry> statusEntry = cq.from(StatusEntry.class);
cq.select(statusEntry);
cq.where(cb.equal(statusEntry.get(StatusEntry_.tutoringSession), this.getTodaysSession()));
cq.distinct(true);
TypedQuery<StatusEntry> q = em.createQuery(cq);
return q.getResultList();
}