本文整理汇总了Java中javax.persistence.criteria.Root.join方法的典型用法代码示例。如果您正苦于以下问题:Java Root.join方法的具体用法?Java Root.join怎么用?Java Root.join使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.criteria.Root
的用法示例。
在下文中一共展示了Root.join方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getPlayersBySport
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public List<PlayerDetails> getPlayersBySport(String sport) {
logger.info("getPlayersByLeagueId");
List<Player> players = null;
try {
CriteriaQuery<Player> cq = cb.createQuery(Player.class);
if (cq != null) {
Root<Player> player = cq.from(Player.class);
Join<Player, Team> team = player.join(Player_.teams);
Join<Team, League> league = team.join(Team_.league);
// Get MetaModel from Root
//EntityType<Player> Player_ = player.getModel();
// set the where clause
cq.where(cb.equal(league.get(League_.sport), sport));
cq.select(player).distinct(true);
TypedQuery<Player> q = em.createQuery(cq);
players = q.getResultList();
}
return copyPlayersToDetails(players);
} catch (Exception ex) {
throw new EJBException(ex);
}
}
示例2: byKeyword
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public static Specification<User> byKeyword(String keyword, String role, String active){
return (Root<User> root, CriteriaQuery<?> query, CriteriaBuilder cb) -> {
List<Predicate> predicates = new ArrayList<>();
if (StringUtils.hasText(keyword)) {
predicates.add(
cb.or(
cb.like(root.get(User_.email), "%" + keyword + "%"),
cb.like(root.get(User_.username), "%" + keyword + "%")
));
}
if (StringUtils.hasText(role) && !"ALL".equals(role)) {
ListJoin<User, String> roleJoin = root.join(User_.roles);
predicates.add(cb.equal(roleJoin, role));
}
if (StringUtils.hasText(active)) {
predicates.add(cb.equal(root.get(User_.active), Boolean.valueOf(active)));
}
return cb.and(predicates.toArray(new Predicate[predicates.size()]));
};
}
示例3: findByWordAndPackageNo
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public Collection<ExtGraph> findByWordAndPackageNo(String word, int packageno) {
Long pkg = new Long(packageno);
CriteriaBuilder criteriaBuilder = getEntityManager().getCriteriaBuilder();
CriteriaQuery<ExtGraph> criteriaQuery = criteriaBuilder.createQuery(ExtGraph.class
);
Root<ExtGraph> root = criteriaQuery.from(ExtGraph.class);
Join<ExtGraph, Synset> synset = root.join("synset", JoinType.INNER);
Join<Synset, Sense> sts = synset.join("sense", JoinType.LEFT);
List<Predicate> criteriaList = new ArrayList<>();
Predicate firstCondition = criteriaBuilder.equal(root.get("word"), word);
criteriaList.add(firstCondition);
Predicate secondCondition = criteriaBuilder.equal(root.get("packageno"), pkg);
criteriaList.add(secondCondition);
Predicate thirdCondition = criteriaBuilder.equal(sts.get("senseIndex"), 0);
criteriaList.add(thirdCondition);
criteriaQuery.where(criteriaBuilder.and(criteriaList.toArray(new Predicate[0])));
final TypedQuery<ExtGraph> query = getEntityManager().createQuery(criteriaQuery);
return query.getResultList();
}
示例4: main
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public static void main(String[] args) {
EntityManagerFactory entityManagerFactory = Persistence
.createEntityManagerFactory("pl.edu.bogdan.training.db.entity");
EntityManager em = entityManagerFactory.createEntityManager();
em.getTransaction().begin();
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<User> cq = cb.createQuery(User.class);
Root<User> from = cq.from(User.class);
Join<User, Role> join = from.join("role", JoinType.LEFT);
cq.where(cb.equal(join.get("name"), "ordinary"));
TypedQuery<User> tq = em.createQuery(cq);
List<User> users = tq.getResultList();
for (User u : users) {
System.out.println(u.getLastName());
}
em.getTransaction().commit();
em.close();
entityManagerFactory.close();
}
示例5: listByNetworkId
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public static List<SecurityGroup> listByNetworkId(EntityManager em, String sgId, String networkId) {
// get Network or VM from port ID then Verify SGM ID and get GD ID...
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SecurityGroup> query = cb.createQuery(SecurityGroup.class);
Root<SecurityGroup> root = query.from(SecurityGroup.class);
Join<SecurityGroup, Object> join = root.join("securityGroupMembers");
query = query.select(root)
.distinct(true)
.where(cb.and(
cb.equal(root.get("id"), sgId),
cb.equal(join.get("network").get("openstackId"), networkId)));
return em.createQuery(query).getResultList();
}
示例6: isSecurityGroupExistWithProtectAll
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public static boolean isSecurityGroupExistWithProtectAll(EntityManager em, String projectId, Long vcId) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SecurityGroup> query = cb.createQuery(SecurityGroup.class);
Root<SecurityGroup> root = query.from(SecurityGroup.class);
Join<SecurityGroup, Object> join = root.join("virtualizationConnector");
query = query.select(root)
.distinct(true)
.where(cb.and(
cb.equal(root.get("projectId"), projectId),
cb.equal(root.get("protectAll"), true),
cb.equal(join.get("id"), vcId)));
return !em.createQuery(query).setMaxResults(1).getResultList().isEmpty();
}
示例7: getPlayersBySport
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public List<PlayerDetails> getPlayersBySport(String sport) {
logger.info("getPlayersByLeagueId");
List<Player> players = null;
try {
CriteriaQuery<Player> cq = cb.createQuery(Player.class);
if (cq != null) {
Root<Player> player = cq.from(Player.class);
Join<Player, Team> team = player.join(Player_.team);
Join<Team, League> league = team.join(Team_.league);
// Get MetaModel from Root
//EntityType<Player> Player_ = player.getModel();
// set the where clause
cq.where(cb.equal(league.get(League_.sport), sport));
cq.select(player).distinct(true);
TypedQuery<Player> q = em.createQuery(cq);
players = q.getResultList();
}
return copyPlayersToDetails(players);
} catch (Exception ex) {
throw new EJBException(ex);
}
}
示例8: getStatusByGuardianEmail
import javax.persistence.criteria.Root; //导入方法依赖的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;
}
示例9: getStatusByGuardianId
import javax.persistence.criteria.Root; //导入方法依赖的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();
}
示例10: getPlayersByLeagueId
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public List<PlayerDetails> getPlayersByLeagueId(String leagueId) {
logger.info("getPlayersByLeagueId");
List<Player> players = null;
try {
CriteriaQuery<Player> cq = cb.createQuery(Player.class);
if (cq != null) {
Root<Player> player = cq.from(Player.class);
Join<Player, Team> team = player.join(Player_.teams);
Join<Team, League> league = team.join(Team_.league);
// Get MetaModel from Root
//EntityType<Player> Player_ = player.getModel();
// set the where clause
cq.where(cb.equal(league.get(League_.id), leagueId));
cq.select(player).distinct(true);
TypedQuery<Player> q = em.createQuery(cq);
players = q.getResultList();
}
return copyPlayersToDetails(players);
} catch (Exception ex) {
throw new EJBException(ex);
}
}
示例11: getPlayersByLeagueId
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public List<PlayerDetails> getPlayersByLeagueId(String leagueId) {
logger.info("getPlayersByLeagueId");
List<Player> players = null;
try {
CriteriaQuery<Player> cq = cb.createQuery(Player.class);
if (cq != null) {
Root<Player> player = cq.from(Player.class);
Join<Player, Team> team = player.join(Player_.team);
Join<Team, League> league = team.join(Team_.league);
// Get MetaModel from Root
//EntityType<Player> Player_ = player.getModel();
// set the where clause
cq.where(cb.equal(league.get(League_.id), leagueId));
cq.select(player).distinct(true);
TypedQuery<Player> q = em.createQuery(cq);
players = q.getResultList();
}
return copyPlayersToDetails(players);
} catch (Exception ex) {
throw new EJBException(ex);
}
}
示例12: getPlayersByCity
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public List<PlayerDetails> getPlayersByCity(String city) {
logger.info("getPlayersByCity");
List<Player> players = null;
try {
CriteriaQuery<Player> cq = cb.createQuery(Player.class);
if (cq != null) {
Root<Player> player = cq.from(Player.class);
Join<Player, Team> team = player.join(Player_.team);
// Get MetaModel from Root
//EntityType<Player> Player_ = player.getModel();
// set the where clause
cq.where(cb.equal(team.get(Team_.city), city));
cq.select(player).distinct(true);
TypedQuery<Player> q = em.createQuery(cq);
players = q.getResultList();
}
return copyPlayersToDetails(players);
} catch (Exception ex) {
throw new EJBException(ex);
}
}
示例13: hasSGMRemoved
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
/**
* @param em
* Hibernate EntityManager
* @param sg
* Security Group
* @return
* true if any SGM was deleted
* false if no SGM was deleted
*/
public static boolean hasSGMRemoved(EntityManager em, SecurityGroup sg) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SecurityGroup> query = cb.createQuery(SecurityGroup.class);
Root<SecurityGroup> root = query.from(SecurityGroup.class);
Join<SecurityGroup, Object> join = root.join("securityGroupMembers");
query = query.select(root)
.distinct(true)
.where(cb.equal(join.get("markedForDeletion"), true));
return !em.createQuery(query).setMaxResults(1).getResultList().isEmpty();
}
示例14: listByDeviceId
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public static List<SecurityGroup> listByDeviceId(EntityManager em, String sgId, String deviceId) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SecurityGroup> query = cb.createQuery(SecurityGroup.class);
Root<SecurityGroup> root = query.from(SecurityGroup.class);
Join<SecurityGroup, Object> join = root.join("securityGroupMembers");
query = query.select(root)
.distinct(true)
.where(cb.and(
cb.equal(root.get("id"), sgId),
cb.equal(join.get("openstackId"), deviceId)));
return em.createQuery(query).getResultList();
}
示例15: getPlayersByCity
import javax.persistence.criteria.Root; //导入方法依赖的package包/类
public List<PlayerDetails> getPlayersByCity(String city) {
logger.info("getPlayersByCity");
List<Player> players = null;
try {
CriteriaQuery<Player> cq = cb.createQuery(Player.class);
if (cq != null) {
Root<Player> player = cq.from(Player.class);
Join<Player, Team> team = player.join(Player_.teams);
// Get MetaModel from Root
//EntityType<Player> Player_ = player.getModel();
// set the where clause
cq.where(cb.equal(team.get(Team_.city), city));
cq.select(player).distinct(true);
TypedQuery<Player> q = em.createQuery(cq);
players = q.getResultList();
}
return copyPlayersToDetails(players);
} catch (Exception ex) {
throw new EJBException(ex);
}
}