当前位置: 首页>>代码示例>>Java>>正文


Java EntityManager.getCriteriaBuilder方法代码示例

本文整理汇总了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();
    }
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:19,代码来源:SecurityGroupEntityMgr.java

示例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;
    }
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:21,代码来源:DeploymentSpecEntityMgr.java

示例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();
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:17,代码来源:SecurityGroupEntityMgr.java

示例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;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:29,代码来源:PolicyEntityMgr.java

示例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);
	}
}
 
开发者ID:muxiangqiu,项目名称:linq,代码行数:16,代码来源:JpaUtil.java

示例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;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:18,代码来源:JobEntityManager.java

示例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();
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:16,代码来源:SecurityGroupMemberEntityMgr.java

示例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();
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:10,代码来源:ApplianceManagerConnectorEntityMgr.java

示例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<>();
}
 
开发者ID:jhonystein,项目名称:Pedidex,代码行数:8,代码来源:JpaCriteriaHelper.java

示例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;

}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:46,代码来源:TaskEntityMgr.java

示例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();

}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:22,代码来源:ApplianceSoftwareVersionEntityMgr.java

示例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);
    }
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:20,代码来源:DistributedApplianceInstanceEntityMgr.java

示例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);
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:23,代码来源:SecurityGroupInterfaceEntityMgr.java

示例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;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:22,代码来源:DistributedApplianceInstanceEntityMgr.java

示例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;
}
 
开发者ID:opensecuritycontroller,项目名称:osc-core,代码行数:19,代码来源:SecurityGroupInterfaceEntityMgr.java


注:本文中的javax.persistence.EntityManager.getCriteriaBuilder方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。