本文整理匯總了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();
}