Java Code Examples for javax.persistence.criteria.Join#get()

The following examples show how to use javax.persistence.criteria.Join#get() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TagDaoImpl.java    From herd with Apache License 2.0 6 votes vote down vote up
@Override
public List<TagEntity> getTags()
{
    // Create the criteria builder and the criteria.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<TagEntity> criteria = builder.createQuery(TagEntity.class);

    // The criteria root is the tag entity.
    Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);

    // Join on the other tables we can filter on.
    Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityRoot.join(TagEntity_.tagType);

    // Get the columns.
    Path<String> displayNameColumn = tagEntityRoot.get(TagEntity_.displayName);
    Path<Integer> tagTypeOrderNumberColumn = tagTypeEntityJoin.get(TagTypeEntity_.orderNumber);
    Path<String> tagTypeCodeColumn = tagTypeEntityJoin.get(TagTypeEntity_.code);

    // Add all clauses to the query.
    criteria.select(tagEntityRoot).orderBy(builder.asc(tagTypeOrderNumberColumn), builder.asc(tagTypeCodeColumn), builder.asc(displayNameColumn));

    // Run the query to get the results.
    return entityManager.createQuery(criteria).getResultList();
}
 
Example 2
Source File: DataViewerImpl.java    From cia with Apache License 2.0 5 votes vote down vote up
@Override
public <T, V> List<T> findOrderedListByEmbeddedProperty(final Class<T> clazz, final SingularAttribute<T, V> property,
		final Class<V> clazz2, final SingularAttribute<V, ? extends Object> property2, final Object value,
		final SingularAttribute<V, ? extends Object> orderByProperty) {
	final CriteriaQuery<T> criteriaQuery = criteriaBuilder
			.createQuery(clazz);
	final Root<T> root = criteriaQuery.from(clazz);
	criteriaQuery.select(root);

	final Join<T, V> join = root.join(property);

	final Path<? extends Object> path = join.get(property2);

	if (orderByProperty != null) {
		criteriaQuery.orderBy(criteriaBuilder.desc(join.get(orderByProperty)));
	}

	final Predicate condition = criteriaBuilder.equal(path, value);

	criteriaQuery.where(condition);

	final TypedQuery<T> typedQuery = entityManager
			.createQuery(criteriaQuery);

	addCacheHints(typedQuery, "findListByEmbeddedProperty." + clazz.getSimpleName());


	return typedQuery.getResultList();
}
 
Example 3
Source File: CommentCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(PullRequest.PROP_COMMENTS, JoinType.LEFT);
	Path<String> attribute = join.get(PullRequestComment.PROP_CONTENT);
	join.on(builder.like(builder.lower(attribute), "%" + value.toLowerCase() + "%"));
	return join.isNotNull();
}
 
Example 4
Source File: HasFailedBuildsCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<PullRequest> root, CriteriaBuilder builder) {
	Join<?, ?> join = root
			.join(PullRequest.PROP_VERIFICATIONS, JoinType.LEFT)
			.join(PullRequestVerification.PROP_BUILD, JoinType.INNER);
	Path<?> status = join.get(Build.STATUS);
	
	join.on(builder.or(
			builder.equal(status, Build.Status.FAILED), 
			builder.equal(status, Build.Status.CANCELLED), 
			builder.equal(status, Build.Status.TIMED_OUT)));
	return join.isNotNull();
}
 
Example 5
Source File: NumericFieldCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected Predicate getValuePredicate(Join<?, ?> field, CriteriaBuilder builder) {
	Path<Integer> attribute = field.get(IssueField.PROP_ORDINAL);
	if (operator == IssueQueryLexer.Is)
		return builder.equal(attribute, value);
	else if (operator == IssueQueryLexer.IsGreaterThan)
		return builder.greaterThan(attribute, value);
	else
		return builder.lessThan(attribute, value);
}
 
Example 6
Source File: CommentCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<Issue> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(Issue.PROP_COMMENTS, JoinType.LEFT);
	Path<String> attribute = join.get(IssueComment.PATH_CONTENT);
	join.on(builder.like(builder.lower(attribute), "%" + value.toLowerCase() + "%"));
	return join.isNotNull();
}
 
Example 7
Source File: StringFieldCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
protected Predicate getValuePredicate(Join<?, ?> field, CriteriaBuilder builder) {
	Path<String> attribute = field.get(IssueField.PROP_VALUE);
	if (operator == IssueQueryLexer.Is)
		return builder.equal(builder.lower(attribute), value.toLowerCase());
	else 
		return builder.like(builder.lower(attribute), "%" + value.toLowerCase() + "%");
}
 
Example 8
Source File: BusinessObjectDefinitionDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public List<BusinessObjectDefinitionEntity> getAllBusinessObjectDefinitions(Integer startPosition, Integer maxResult)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder.createQuery(BusinessObjectDefinitionEntity.class);

    // The criteria root is the business object definition.
    Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityRoot = criteria.from(BusinessObjectDefinitionEntity.class);

    // Join to the other tables we can filter on.
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity =
        businessObjectDefinitionEntityRoot.join(BusinessObjectDefinitionEntity_.namespace);

    // Get the columns.
    Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
    Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntityRoot.get(BusinessObjectDefinitionEntity_.name);

    // Add all clauses to the query.
    criteria.select(businessObjectDefinitionEntityRoot).orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn));

    // Get an instance of the query ready for execution.
    TypedQuery<BusinessObjectDefinitionEntity> query = entityManager.createQuery(criteria);

    // If start position is specified, set it for the query.
    if (startPosition != null)
    {
        query.setFirstResult(startPosition.intValue());
    }

    // If start position is specified, set it for the query.
    if (maxResult != null)
    {
        query.setMaxResults(maxResult.intValue());
    }

    // Execute the query and return the results.
    return query.getResultList();
}
 
Example 9
Source File: ReplyCriteria.java    From onedev with MIT License 5 votes vote down vote up
@Override
public Predicate getPredicate(Root<CodeComment> root, CriteriaBuilder builder) {
	Join<?, ?> join = root.join(CodeComment.PROP_REPLIES, JoinType.LEFT);
	Path<String> attribute = join.get(CodeCommentReply.PROP_CONTENT);
	join.on(builder.like(builder.lower(attribute), "%" + value.toLowerCase().replace('*', '%') + "%"));
	return join.isNotNull();
}
 
Example 10
Source File: StorageUnitNotificationRegistrationDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public List<NotificationRegistrationKey> getStorageUnitNotificationRegistrationKeysByNamespace(String namespace)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the storage unit notification registration.
    Root<StorageUnitNotificationRegistrationEntity> businessObjectDataNotificationEntityRoot =
        criteria.from(StorageUnitNotificationRegistrationEntity.class);

    // Join to the other tables we can filter on.
    Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> namespaceEntityJoin =
        businessObjectDataNotificationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.namespace);

    // Get the columns.
    Path<String> notificationRegistrationNamespaceColumn = namespaceEntityJoin.get(NamespaceEntity_.code);
    Path<String> notificationRegistrationNameColumn = businessObjectDataNotificationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.name);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(namespaceEntityJoin.get(NamespaceEntity_.code)), namespace.toUpperCase());

    // Add the select clause.
    criteria.multiselect(notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn);

    // Add the where clause.
    criteria.where(queryRestriction);

    // Add the order by clause.
    criteria.orderBy(builder.asc(notificationRegistrationNameColumn));

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Populate the list of keys from the returned tuples.
    return getNotificationRegistrationKeys(tuples, notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn);
}
 
Example 11
Source File: SecurityRoleFunctionDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public List<SecurityRoleFunctionKey> getSecurityRoleFunctionKeys()
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the security role to function mapping.
    Root<SecurityRoleFunctionEntity> securityRoleFunctionEntityRoot = criteria.from(SecurityRoleFunctionEntity.class);

    // Join to the other tables.
    Join<SecurityRoleFunctionEntity, SecurityRoleEntity> securityRoleEntityJoin =
        securityRoleFunctionEntityRoot.join(SecurityRoleFunctionEntity_.securityRole);
    Join<SecurityRoleFunctionEntity, SecurityFunctionEntity> securityFunctionEntityJoin =
        securityRoleFunctionEntityRoot.join(SecurityRoleFunctionEntity_.securityFunction);

    // Get the columns.
    Path<String> securityRoleNameColumn = securityRoleEntityJoin.get(SecurityRoleEntity_.code);
    Path<String> securityFunctionNameColumn = securityFunctionEntityJoin.get(SecurityFunctionEntity_.code);

    // Add all clauses to the query.
    criteria.multiselect(securityRoleNameColumn, securityFunctionNameColumn)
        .orderBy(builder.asc(securityRoleNameColumn), builder.asc(securityFunctionNameColumn));

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<SecurityRoleFunctionKey> securityRoleFunctionKeys = new ArrayList<>();
    for (Tuple tuple : tuples)
    {
        securityRoleFunctionKeys.add(new SecurityRoleFunctionKey(tuple.get(securityRoleNameColumn), tuple.get(securityFunctionNameColumn)));
    }

    // Return the result list.
    return securityRoleFunctionKeys;
}
 
Example 12
Source File: SecurityRoleFunctionDaoImpl.java    From herd with Apache License 2.0 5 votes vote down vote up
@Override
public List<SecurityRoleFunctionKey> getSecurityRoleFunctionKeysBySecurityRole(String securityRoleName)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the security role to function mapping.
    Root<SecurityRoleFunctionEntity> securityRoleFunctionEntityRoot = criteria.from(SecurityRoleFunctionEntity.class);

    // Join to the other tables.
    Join<SecurityRoleFunctionEntity, SecurityRoleEntity> securityRoleEntityJoin =
        securityRoleFunctionEntityRoot.join(SecurityRoleFunctionEntity_.securityRole);
    Join<SecurityRoleFunctionEntity, SecurityFunctionEntity> securityFunctionEntityJoin =
        securityRoleFunctionEntityRoot.join(SecurityRoleFunctionEntity_.securityFunction);

    // Get the columns.
    Path<String> securityRoleNameColumn = securityRoleEntityJoin.get(SecurityRoleEntity_.code);
    Path<String> securityFunctionNameColumn = securityFunctionEntityJoin.get(SecurityFunctionEntity_.code);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction = builder.equal(builder.upper(securityRoleEntityJoin.get(SecurityRoleEntity_.code)), securityRoleName.toUpperCase());

    // Add all clauses to the query.
    criteria.multiselect(securityRoleNameColumn, securityFunctionNameColumn).where(queryRestriction).orderBy(builder.asc(securityFunctionNameColumn));

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<SecurityRoleFunctionKey> securityRoleFunctionKeys = new ArrayList<>();
    for (Tuple tuple : tuples)
    {
        securityRoleFunctionKeys.add(new SecurityRoleFunctionKey(tuple.get(securityRoleNameColumn), tuple.get(securityFunctionNameColumn)));
    }

    // Return the result list.
    return securityRoleFunctionKeys;
}
 
Example 13
Source File: BusinessObjectDefinitionTagDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<BusinessObjectDefinitionTagKey> getBusinessObjectDefinitionTagsByTagEntities(List<TagEntity> tagEntities)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the business object definition tag entity.
    Root<BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityRoot = criteria.from(BusinessObjectDefinitionTagEntity.class);

    // Join to the other tables we can filter on.
    Join<BusinessObjectDefinitionTagEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin =
        businessObjectDefinitionTagEntityRoot.join(BusinessObjectDefinitionTagEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntityJoin =
        businessObjectDefinitionEntityJoin.join(BusinessObjectDefinitionEntity_.namespace);
    Join<BusinessObjectDefinitionTagEntity, TagEntity> tagEntityJoin = businessObjectDefinitionTagEntityRoot.join(BusinessObjectDefinitionTagEntity_.tag);
    Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityJoin.join(TagEntity_.tagType);

    // Get the columns.
    Path<String> namespaceCodeColumn = namespaceEntityJoin.get(NamespaceEntity_.code);
    Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.name);
    Path<String> businessObjectDefinitionDisplayNameColumn = businessObjectDefinitionEntityJoin.get(BusinessObjectDefinitionEntity_.displayName);
    Path<String> tagTypeCodeColumn = tagTypeEntityJoin.get(TagTypeEntity_.code);
    Path<String> tagCodeColumn = tagEntityJoin.get(TagEntity_.tagCode);
    Path<String> tagDisplayNameColumn = tagEntityJoin.get(TagEntity_.displayName);

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate predicate = getPredicateForInClause(builder, businessObjectDefinitionTagEntityRoot.get(BusinessObjectDefinitionTagEntity_.tag), tagEntities);

    // Order the results by business object definition display name (an optional column),
    // business object definition namespace, business object definition name, tag display name,
    // and tag type code (since tag display name is unique across a tag type).
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(businessObjectDefinitionDisplayNameColumn));
    orderBy.add(builder.asc(namespaceCodeColumn));
    orderBy.add(builder.asc(businessObjectDefinitionNameColumn));
    orderBy.add(builder.asc(tagDisplayNameColumn));
    orderBy.add(builder.asc(tagTypeCodeColumn));

    // Add the clauses for the query.
    criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn, tagTypeCodeColumn, tagCodeColumn).where(predicate).orderBy(orderBy);

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<BusinessObjectDefinitionTagKey> businessObjectDefinitionTagKeys = new ArrayList<>();
    for (Tuple tuple : tuples)
    {
        businessObjectDefinitionTagKeys.add(new BusinessObjectDefinitionTagKey(
            new BusinessObjectDefinitionKey(tuple.get(namespaceCodeColumn), tuple.get(businessObjectDefinitionNameColumn)),
            new TagKey(tuple.get(tagTypeCodeColumn), tuple.get(tagCodeColumn))));
    }

    return businessObjectDefinitionTagKeys;
}
 
Example 14
Source File: BusinessObjectDefinitionTagDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<BusinessObjectDefinitionTagKey> getBusinessObjectDefinitionTagsByBusinessObjectDefinitionEntity(
    BusinessObjectDefinitionEntity businessObjectDefinitionEntity)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the business object definition.
    Root<TagEntity> tagEntityRoot = criteria.from(TagEntity.class);

    // Join to the other tables we can filter on.
    Join<TagEntity, TagTypeEntity> tagTypeEntityJoin = tagEntityRoot.join(TagEntity_.tagType);
    Join<TagEntity, BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityJoin = tagEntityRoot.join(TagEntity_.businessObjectDefinitionTags);
    Join<BusinessObjectDefinitionTagEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntityJoin =
        businessObjectDefinitionTagEntityJoin.join(BusinessObjectDefinitionTagEntity_.businessObjectDefinition);

    // Get the columns.
    Path<String> tagTypeCodeColumn = tagTypeEntityJoin.get(TagTypeEntity_.code);
    Path<String> tagCodeColumn = tagEntityRoot.get(TagEntity_.tagCode);
    Path<String> tagDisplayNameColumn = tagEntityRoot.get(TagEntity_.displayName);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(businessObjectDefinitionEntityJoin, businessObjectDefinitionEntity));

    // Add the clauses for the query.
    criteria.multiselect(tagTypeCodeColumn, tagCodeColumn).where(builder.and(predicates.toArray(new Predicate[predicates.size()])))
        .orderBy(builder.asc(tagDisplayNameColumn));

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Get the business object definition key.
    BusinessObjectDefinitionKey businessObjectDefinitionKey =
        new BusinessObjectDefinitionKey(businessObjectDefinitionEntity.getNamespace().getCode(), businessObjectDefinitionEntity.getName());

    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<BusinessObjectDefinitionTagKey> businessObjectDefinitionTagKeys = new ArrayList<>();
    for (Tuple tuple : tuples)
    {
        businessObjectDefinitionTagKeys
            .add(new BusinessObjectDefinitionTagKey(businessObjectDefinitionKey, new TagKey(tuple.get(tagTypeCodeColumn), tuple.get(tagCodeColumn))));
    }

    return businessObjectDefinitionTagKeys;
}
 
Example 15
Source File: BusinessObjectFormatDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<BusinessObjectFormatKey> getBusinessObjectFormatsWithFilters(BusinessObjectDefinitionKey businessObjectDefinitionKey,
    String businessObjectFormatUsage, boolean latestBusinessObjectFormatVersion)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the business object format.
    Root<BusinessObjectFormatEntity> businessObjectFormatEntity = criteria.from(BusinessObjectFormatEntity.class);

    // Join to the other tables we can filter on.
    Join<BusinessObjectFormatEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity =
        businessObjectFormatEntity.join(BusinessObjectFormatEntity_.businessObjectDefinition);
    Join<BusinessObjectFormatEntity, FileTypeEntity> fileTypeEntity = businessObjectFormatEntity.join(BusinessObjectFormatEntity_.fileType);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);

    // Get the columns.
    Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
    Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name);
    Path<String> businessObjectFormatUsageColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage);
    Path<String> fileTypeCodeColumn = fileTypeEntity.get(FileTypeEntity_.code);
    Path<Integer> businessObjectFormatVersionColumn = businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion);
    Expression<Integer> maxBusinessObjectFormatVersionExpression =
        builder.max(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.businessObjectFormatVersion));

    // Create the standard restrictions (i.e. the standard where clauses).
    Predicate queryRestriction =
        builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), businessObjectDefinitionKey.getNamespace().toUpperCase());
    queryRestriction = builder.and(queryRestriction, builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)),
        businessObjectDefinitionKey.getBusinessObjectDefinitionName().toUpperCase()));

    // Add the business object format usage where parameter is not empty
    if (StringUtils.isNotEmpty(businessObjectFormatUsage))
    {
        queryRestriction = builder.and(queryRestriction,
            builder.equal(builder.upper(businessObjectFormatEntity.get(BusinessObjectFormatEntity_.usage)), businessObjectFormatUsage.toUpperCase()));
    }

    // Add the select clause.
    criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn, businessObjectFormatUsageColumn, fileTypeCodeColumn,
        latestBusinessObjectFormatVersion ? maxBusinessObjectFormatVersionExpression : businessObjectFormatVersionColumn);

    // Add the where clause.
    criteria.where(queryRestriction);

    // If only the latest (maximum) business object format versions to be returned, create and apply the group by clause.
    if (latestBusinessObjectFormatVersion)
    {
        List<Expression<?>> grouping = new ArrayList<>();
        grouping.add(namespaceCodeColumn);
        grouping.add(businessObjectDefinitionNameColumn);
        grouping.add(businessObjectFormatUsageColumn);
        grouping.add(fileTypeCodeColumn);
        criteria.groupBy(grouping);
    }

    // Add the order by clause.
    List<Order> orderBy = new ArrayList<>();
    orderBy.add(builder.asc(businessObjectFormatUsageColumn));
    orderBy.add(builder.asc(fileTypeCodeColumn));
    if (!latestBusinessObjectFormatVersion)
    {
        orderBy.add(builder.asc(businessObjectFormatVersionColumn));
    }
    criteria.orderBy(orderBy);

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<BusinessObjectFormatKey> businessObjectFormatKeys = new ArrayList<>();
    for (Tuple tuple : tuples)
    {
        BusinessObjectFormatKey businessObjectFormatKey = new BusinessObjectFormatKey();
        businessObjectFormatKeys.add(businessObjectFormatKey);
        businessObjectFormatKey.setNamespace(tuple.get(namespaceCodeColumn));
        businessObjectFormatKey.setBusinessObjectDefinitionName(tuple.get(businessObjectDefinitionNameColumn));
        businessObjectFormatKey.setBusinessObjectFormatUsage(tuple.get(businessObjectFormatUsageColumn));
        businessObjectFormatKey.setBusinessObjectFormatFileType(tuple.get(fileTypeCodeColumn));
        businessObjectFormatKey.setBusinessObjectFormatVersion(
            tuple.get(latestBusinessObjectFormatVersion ? maxBusinessObjectFormatVersionExpression : businessObjectFormatVersionColumn));
    }

    return businessObjectFormatKeys;
}
 
Example 16
Source File: BusinessObjectDefinitionDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<BusinessObjectDefinitionKey> getBusinessObjectDefinitionKeysByNamespace(String namespaceCode)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the business object definition.
    Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntity = criteria.from(BusinessObjectDefinitionEntity.class);

    // Join to the other tables we can filter on.
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity = businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);

    // Get the columns.
    Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
    Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name);

    // Add the select clause.
    criteria.multiselect(namespaceCodeColumn, businessObjectDefinitionNameColumn);

    // If namespace code is specified, add the where clause.
    if (StringUtils.isNotBlank(namespaceCode))
    {
        criteria.where(builder.equal(builder.upper(namespaceEntity.get(NamespaceEntity_.code)), namespaceCode.toUpperCase()));
    }

    // Add the order by clause.
    if (StringUtils.isNotBlank(namespaceCode))
    {
        criteria.orderBy(builder.asc(businessObjectDefinitionNameColumn));
    }
    else
    {
        criteria.orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn));
    }

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Populate the "keys" objects from the returned tuples (i.e. 1 tuple for each row).
    List<BusinessObjectDefinitionKey> businessObjectDefinitionKeys = new ArrayList<>();
    for (Tuple tuple : tuples)
    {
        BusinessObjectDefinitionKey businessObjectDefinitionKey = new BusinessObjectDefinitionKey();
        businessObjectDefinitionKeys.add(businessObjectDefinitionKey);
        businessObjectDefinitionKey.setNamespace(tuple.get(namespaceCodeColumn));
        businessObjectDefinitionKey.setBusinessObjectDefinitionName(tuple.get(businessObjectDefinitionNameColumn));
    }

    return businessObjectDefinitionKeys;
}
 
Example 17
Source File: StorageUnitNotificationRegistrationDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<NotificationRegistrationKey> getStorageUnitNotificationRegistrationKeysByNotificationFilter(
    StorageUnitNotificationFilter businessObjectDataNotificationFilter)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the storage unit notification registration.
    Root<StorageUnitNotificationRegistrationEntity> notificationRegistrationEntityRoot = criteria.from(StorageUnitNotificationRegistrationEntity.class);

    // Join to the other tables we can filter on.
    Join<StorageUnitNotificationRegistrationEntity, NamespaceEntity> notificationRegistrationNamespaceEntityJoin =
        notificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.namespace);
    Join<StorageUnitNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity =
        notificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntity =
        businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
    Join<StorageUnitNotificationRegistrationEntity, FileTypeEntity> fileTypeEntity =
        notificationRegistrationEntityRoot.join(StorageUnitNotificationRegistrationEntity_.fileType, JoinType.LEFT);

    // Get the columns.
    Path<String> notificationRegistrationNamespaceColumn = notificationRegistrationNamespaceEntityJoin.get(NamespaceEntity_.code);
    Path<String> notificationRegistrationNameColumn = notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.name);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionNamespaceEntity.get(NamespaceEntity_.code)),
        businessObjectDataNotificationFilter.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)),
        businessObjectDataNotificationFilter.getBusinessObjectDefinitionName().toUpperCase()));
    if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatUsage()))
    {
        predicates.add(builder.or(builder.isNull(notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.usage)), builder
            .equal(builder.upper(notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.usage)),
                businessObjectDataNotificationFilter.getBusinessObjectFormatUsage().toUpperCase())));
    }
    if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatFileType()))
    {
        predicates.add(builder.or(builder.isNull(notificationRegistrationEntityRoot.get(StorageUnitNotificationRegistrationEntity_.fileType)), builder
            .equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)),
                businessObjectDataNotificationFilter.getBusinessObjectFormatFileType().toUpperCase())));
    }

    // Add the select and where clauses to the query.
    criteria.multiselect(notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn)
        .where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

    // Add the order by clause to the query.
    criteria.orderBy(builder.asc(notificationRegistrationNamespaceColumn), builder.asc(notificationRegistrationNameColumn));

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Populate the list of keys from the returned tuples.
    return getNotificationRegistrationKeys(tuples, notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn);
}
 
Example 18
Source File: BusinessObjectDataNotificationRegistrationDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<NotificationRegistrationKey> getBusinessObjectDataNotificationRegistrationKeysByNotificationFilter(
    BusinessObjectDataNotificationFilter businessObjectDataNotificationFilter)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<Tuple> criteria = builder.createTupleQuery();

    // The criteria root is the business object data notification registration.
    Root<BusinessObjectDataNotificationRegistrationEntity> notificationRegistrationEntityRoot =
        criteria.from(BusinessObjectDataNotificationRegistrationEntity.class);

    // Join to the other tables we can filter on.
    Join<BusinessObjectDataNotificationRegistrationEntity, NamespaceEntity> notificationRegistrationNamespaceEntityJoin =
        notificationRegistrationEntityRoot.join(BusinessObjectDataNotificationRegistrationEntity_.namespace);
    Join<BusinessObjectDataNotificationRegistrationEntity, BusinessObjectDefinitionEntity> businessObjectDefinitionEntity =
        notificationRegistrationEntityRoot.join(BusinessObjectDataNotificationRegistrationEntity_.businessObjectDefinition);
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> businessObjectDefinitionNamespaceEntity =
        businessObjectDefinitionEntity.join(BusinessObjectDefinitionEntity_.namespace);
    Join<BusinessObjectDataNotificationRegistrationEntity, FileTypeEntity> fileTypeEntity =
        notificationRegistrationEntityRoot.join(BusinessObjectDataNotificationRegistrationEntity_.fileType, JoinType.LEFT);

    // Get the columns.
    Path<String> notificationRegistrationNamespaceColumn = notificationRegistrationNamespaceEntityJoin.get(NamespaceEntity_.code);
    Path<String> notificationRegistrationNameColumn = notificationRegistrationEntityRoot.get(BusinessObjectDataNotificationRegistrationEntity_.name);

    // Create the standard restrictions (i.e. the standard where clauses).
    List<Predicate> predicates = new ArrayList<>();
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionNamespaceEntity.get(NamespaceEntity_.code)),
        businessObjectDataNotificationFilter.getNamespace().toUpperCase()));
    predicates.add(builder.equal(builder.upper(businessObjectDefinitionEntity.get(BusinessObjectDefinitionEntity_.name)),
        businessObjectDataNotificationFilter.getBusinessObjectDefinitionName().toUpperCase()));
    if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatUsage()))
    {
        predicates.add(builder.or(builder.isNull(notificationRegistrationEntityRoot.get(BusinessObjectDataNotificationRegistrationEntity_.usage)), builder
            .equal(builder.upper(notificationRegistrationEntityRoot.get(BusinessObjectDataNotificationRegistrationEntity_.usage)),
                businessObjectDataNotificationFilter.getBusinessObjectFormatUsage().toUpperCase())));
    }
    if (StringUtils.isNotBlank(businessObjectDataNotificationFilter.getBusinessObjectFormatFileType()))
    {
        predicates.add(builder.or(builder.isNull(notificationRegistrationEntityRoot.get(BusinessObjectDataNotificationRegistrationEntity_.fileType)),
            builder.equal(builder.upper(fileTypeEntity.get(FileTypeEntity_.code)),
                businessObjectDataNotificationFilter.getBusinessObjectFormatFileType().toUpperCase())));
    }

    // Add the select and where clauses to the query.
    criteria.multiselect(notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn)
        .where(builder.and(predicates.toArray(new Predicate[predicates.size()])));

    // Add the order by clause to the query.
    criteria.orderBy(builder.asc(notificationRegistrationNamespaceColumn), builder.asc(notificationRegistrationNameColumn));

    // Run the query to get a list of tuples back.
    List<Tuple> tuples = entityManager.createQuery(criteria).getResultList();

    // Populate the list of keys from the returned tuples.
    return getNotificationRegistrationKeys(tuples, notificationRegistrationNamespaceColumn, notificationRegistrationNameColumn);
}
 
Example 19
Source File: BusinessObjectDefinitionDaoImpl.java    From herd with Apache License 2.0 4 votes vote down vote up
@Override
public List<BusinessObjectDefinitionEntity> getBusinessObjectDefinitions(List<TagEntity> tagEntities)
{
    // Create the criteria builder and a tuple style criteria query.
    CriteriaBuilder builder = entityManager.getCriteriaBuilder();
    CriteriaQuery<BusinessObjectDefinitionEntity> criteria = builder.createQuery(BusinessObjectDefinitionEntity.class);

    // The criteria root is the business object definition.
    Root<BusinessObjectDefinitionEntity> businessObjectDefinitionEntityRoot = criteria.from(BusinessObjectDefinitionEntity.class);

    // Join to the other tables we can filter on.
    Join<BusinessObjectDefinitionEntity, NamespaceEntity> namespaceEntity =
        businessObjectDefinitionEntityRoot.join(BusinessObjectDefinitionEntity_.namespace);

    // Get the columns.
    Path<String> namespaceCodeColumn = namespaceEntity.get(NamespaceEntity_.code);
    Path<String> businessObjectDefinitionNameColumn = businessObjectDefinitionEntityRoot.get(BusinessObjectDefinitionEntity_.name);

    Predicate predicate;

    if (!CollectionUtils.isEmpty(tagEntities))
    {
        //join the business object definition tags
        Join<BusinessObjectDefinitionEntity, BusinessObjectDefinitionTagEntity> businessObjectDefinitionTagEntityJoin =
            businessObjectDefinitionEntityRoot.join(BusinessObjectDefinitionEntity_.businessObjectDefinitionTags);

        // Create the standard restrictions (i.e. the standard where clauses).
        predicate = getPredicateForInClause(builder, businessObjectDefinitionTagEntityJoin.get(BusinessObjectDefinitionTagEntity_.tag), tagEntities);

        // Add all clauses to the query.
        criteria.select(businessObjectDefinitionEntityRoot).where(predicate)
            .orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn));
    }
    else
    {
        criteria.select(businessObjectDefinitionEntityRoot).orderBy(builder.asc(businessObjectDefinitionNameColumn), builder.asc(namespaceCodeColumn));
    }

    //Returns duplicate business object definition. When a bdef is associated with multiple tags.
    return entityManager.createQuery(criteria).getResultList();
}
 
Example 20
Source File: AbstractGenericDAOImpl.java    From cia with Apache License 2.0 3 votes vote down vote up
@Override
public <V> List<T> findOrderedByPropertyListByEmbeddedProperty(final SingularAttribute<T, V> property,
		final Class<V> clazz2, final SingularAttribute<V, ? extends Object> property2, final Object value,
		final SingularAttribute<T, ? extends Object> orderByProperty) {
	final CriteriaQuery<T> criteriaQuery = criteriaBuilder
			.createQuery(persistentClass);
	final Root<T> root = criteriaQuery.from(persistentClass);
	criteriaQuery.select(root);

	if (orderByProperty != null) {
		criteriaQuery.orderBy(criteriaBuilder.desc(root.get(orderByProperty)));
	}


	final Join<T, V> join = root.join(property);

	final Path<? extends Object> path = join.get(property2);

	final Predicate condition = criteriaBuilder.equal(path, value);

	criteriaQuery.where(condition);

	final TypedQuery<T> typedQuery = entityManager
			.createQuery(criteriaQuery);

	addCacheHints(typedQuery, "findListByEmbeddedProperty." + persistentClass.getSimpleName());


	return typedQuery.getResultList();
}