本文整理汇总了Java中javax.persistence.EntityManager.getCriteriaBuilder方法的典型用法代码示例。如果您正苦于以下问题:Java EntityManager.getCriteriaBuilder方法的具体用法?Java EntityManager.getCriteriaBuilder怎么用?Java EntityManager.getCriteriaBuilder使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类javax.persistence.EntityManager
的用法示例。
在下文中一共展示了EntityManager.getCriteriaBuilder方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: listByNetworkId
import javax.persistence.EntityManager; //导入方法依赖的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();
}
示例2: findDeploymentSpecByVirtualSystemProjectAndRegion
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static DeploymentSpec findDeploymentSpecByVirtualSystemProjectAndRegion(EntityManager em, VirtualSystem vs,
String projectId, String region) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<DeploymentSpec> query = cb.createQuery(DeploymentSpec.class);
Root<DeploymentSpec> root = query.from(DeploymentSpec.class);
query = query.select(root)
.where(cb.equal(root.get("projectId"), projectId),
cb.equal(root.get("region"), region),
cb.equal(root.get("virtualSystem"), vs));
try {
return em.createQuery(query).getSingleResult();
} catch (NoResultException nre) {
return null;
}
}
示例3: isSecurityGroupExistWithProtectAll
import javax.persistence.EntityManager; //导入方法依赖的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();
}
示例4: findPoliciesById
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Verifies if the request contains valid policies supported by security manager available on the OSC.
* If the request contains one or more invalid policies, throw an exception.
*/
// TODO Larkins: Improve the method not to do the validation
public static Set<Policy> findPoliciesById(EntityManager em, Set<Long> ids, ApplianceManagerConnector mc)
throws VmidcBrokerValidationException, Exception {
Set<Policy> policies = new HashSet<>();
Set<String> invalidPolicies = new HashSet<>();
for (Long id : ids) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Policy> query = cb.createQuery(Policy.class);
Root<Policy> root = query.from(Policy.class);
query = query.select(root).where(cb.equal(root.get("id"), id),
cb.equal(root.join("applianceManagerConnector").get("id"), mc.getId()));
try {
Policy policy = em.createQuery(query).getSingleResult();
policies.add(policy);
} catch (NoResultException nre) {
invalidPolicies.add(id.toString());
}
}
if (invalidPolicies.size() > 0) {
throw new VmidcBrokerValidationException(
"Invalid Request. Request contains invalid policies: " + String.join(", ", invalidPolicies));
}
return policies;
}
示例5: removeAll
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* 删除实体类对应的所有记录
* @param domainClass 领域类(实体类)
* @param <T> 领域类(实体类)范型
*/
public static <T> void removeAll(Class<T> domainClass) {
EntityManager em = getEntityManager(domainClass);
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<T> cq = cb.createQuery(domainClass);
cq.from(domainClass);
List<T> result = findAll(cq);
for (T element : result) {
remove(element);
}
}
示例6: getTotalJobFailCount
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Gets the total failed job count from the database
*
* @return failed job count
*/
public static Long getTotalJobFailCount(EntityManager em) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Long> query = cb.createQuery(Long.class);
Root<JobRecord> from = query.from(JobRecord.class);
query = query.select(cb.count(from))
.where(cb.equal(from.get("status"), FAILED));
Long totalJobFailCount = em.createQuery(query).getSingleResult();
return totalJobFailCount;
}
示例7: listActiveSecurityGroupMembersBySecurityGroup
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static List<SecurityGroupMember> listActiveSecurityGroupMembersBySecurityGroup(EntityManager em,
SecurityGroup sg) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SecurityGroupMember> query = cb.createQuery(SecurityGroupMember.class);
Root<SecurityGroupMember> root = query.from(SecurityGroupMember.class);
query = query.select(root).distinct(true)
.where(cb.equal(root.get("markedForDeletion"), false),
cb.equal(root.get("securityGroup"), sg))
.orderBy(cb.asc(root.get("type")));
return em.createQuery(query).getResultList();
}
示例8: listByManagerType
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static List<ApplianceManagerConnector> listByManagerType(EntityManager em, String type) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ApplianceManagerConnector> cq = cb.createQuery(ApplianceManagerConnector.class);
Root<ApplianceManagerConnector> from = cq.from(ApplianceManagerConnector.class);
cq = cq.select(from).distinct(true)
.where(cb.equal(from.get("managerType"), type));
return em.createQuery(cq).getResultList();
}
示例9: JpaCriteriaHelper
import javax.persistence.EntityManager; //导入方法依赖的package包/类
private JpaCriteriaHelper( EntityManager em, Class<T> entityClass ) {
this.em = em;
this.entityClass = entityClass;
this.criteriaBuilder = em.getCriteriaBuilder();
this.directFetches = new ArrayList<>();
this.listFetches = new ArrayList<>();
}
示例10: getUniqueTaskFailureStrings
import javax.persistence.EntityManager; //导入方法依赖的package包/类
/**
* Gets all the unique Task failures encountered since the from date.
*
* @param fromDate the start time to look for failed task
* @param session the hibernate session
*
* @return unique task failures since the from date
*/
public static List<TaskFailureRecordDto> getUniqueTaskFailureStrings(Date fromDate, EntityManager em) {
List<TaskFailureRecordDto> taskFailures = null;
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<Object[]> query = cb.createQuery(Object[].class);
Root<TaskRecord> root = query.from(TaskRecord.class);
Predicate restriction = null;
if(fromDate != null) {
restriction = cb.and(
cb.greaterThan(root.get("completedTimestamp"), fromDate),
cb.isNotNull(root.get("failReason")));
} else {
restriction = cb.isNotNull(root.get("failReason"));
}
query = query.multiselect(root.get("failReason"), cb.count(root))
.where(restriction);
List<?> results = em
.createQuery(query)
.getResultList();
if (!results.isEmpty()) {
taskFailures = new ArrayList<TaskFailureRecordDto>();
for (Object row : results) {
Object[] rowArray = (Object[]) row;
taskFailures.add(new TaskFailureRecordDto((String) rowArray[0], (long) rowArray[1]));
}
}
return taskFailures;
}
示例11: isExisting
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static boolean isExisting(EntityManager em, Long applianceId, String applianceSoftwareVersion,
VirtualizationType virtualizationType, String virtualizationSoftwareVersion) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<ApplianceSoftwareVersion> query = cb.createQuery(ApplianceSoftwareVersion.class);
Root<ApplianceSoftwareVersion> root = query.from(ApplianceSoftwareVersion.class);
query = query.select(root)
.where(cb.equal(root.join("appliance").get("id"), applianceId),
cb.equal(cb.upper(root.get("applianceSoftwareVersion")), applianceSoftwareVersion.toUpperCase()),
cb.equal(root.get("virtualizationType"), virtualizationType),
cb.equal(cb.upper(root.get("virtualizationSoftwareVersion")), virtualizationSoftwareVersion.toUpperCase())
);
List<ApplianceSoftwareVersion> items = em.createQuery(query).setMaxResults(1).getResultList();
return !items.isEmpty();
}
示例12: getByOSServerId
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static DistributedApplianceInstance getByOSServerId(EntityManager em, String osServerId) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<DistributedApplianceInstance> query = cb.createQuery(DistributedApplianceInstance.class);
Root<DistributedApplianceInstance> root = query.from(DistributedApplianceInstance.class);
query = query.select(root)
.where(cb.equal(root.get("externalId"), osServerId));
List<DistributedApplianceInstance> list = em.createQuery(query).getResultList();
if (list == null || list.size() == 0) {
return null;
}
return list.get(0);
}
示例13: findSecurityGroupInterfaceByVsTagAndPolicy
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static SecurityGroupInterface findSecurityGroupInterfaceByVsTagAndPolicy(EntityManager em, VirtualSystem vs,
String tag, Long policyId) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SecurityGroupInterface> query = cb.createQuery(SecurityGroupInterface.class);
Root<SecurityGroupInterface> root = query.from(SecurityGroupInterface.class);
query = query.select(root)
.where(cb.equal(root.get("tag"), tag),
cb.equal(root.get("virtualSystem"), vs),
cb.equal(root.join("policies").get("id"), policyId));
List<SecurityGroupInterface> list = em.createQuery(query).setMaxResults(1).getResultList();
if (list == null || list.size() == 0) {
return null;
}
return list.get(0);
}
示例14: listByDsIdAndAvailabilityZone
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static List<DistributedApplianceInstance> listByDsIdAndAvailabilityZone(EntityManager em, Long dsId,
String availabilityZone) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<DistributedApplianceInstance> query = cb.createQuery(DistributedApplianceInstance.class);
Root<DistributedApplianceInstance> root = query.from(DistributedApplianceInstance.class);
query = query.select(root).distinct(true)
.where(cb.equal(root.join("deploymentSpec").get("id"), dsId),
cb.equal(root.get("osAvailabilityZone"), availabilityZone));
List<DistributedApplianceInstance> list = em.createQuery(query).getResultList();
if (list == null || list.size() == 0) {
return null;
}
return list;
}
示例15: listSecurityGroupInterfaceByPolicy
import javax.persistence.EntityManager; //导入方法依赖的package包/类
public static List<SecurityGroupInterface> listSecurityGroupInterfaceByPolicy(EntityManager em, Long policyId) {
CriteriaBuilder cb = em.getCriteriaBuilder();
CriteriaQuery<SecurityGroupInterface> query = cb.createQuery(SecurityGroupInterface.class);
Root<SecurityGroupInterface> root = query.from(SecurityGroupInterface.class);
query = query.select(root).distinct(true)
.where(cb.equal(root.join("policies").get("id"), policyId));
List<SecurityGroupInterface> list = em.createQuery(query).getResultList();
if (list == null || list.size() == 0) {
return null;
}
return list;
}