use of com.blazebit.persistence.spi.ExtendedAttribute in project blaze-persistence by Blazebit.
the class EmbeddableSplittingVisitor method collectSplittedOffExpressions.
protected boolean collectSplittedOffExpressions(Expression expression) {
splittedOffExpressions.clear();
if (expressionToSplit != null) {
JoinNode baseNode;
String field;
if (expressionToSplit instanceof PathExpression) {
PathReference pathReference = ((PathExpression) expressionToSplit).getPathReference();
baseNode = (JoinNode) pathReference.getBaseNode();
field = pathReference.getField();
} else if (expressionToSplit instanceof MapKeyExpression) {
baseNode = ((JoinNode) ((MapKeyExpression) expressionToSplit).getPath().getBaseNode()).getKeyJoinNode();
field = null;
} else {
// This should never happen
return false;
}
String fieldPrefix = field == null ? "" : field + ".";
ExtendedManagedType<?> managedType = metamodel.getManagedType(ExtendedManagedType.class, baseNode.getManagedType());
Map<String, Boolean> orderedAttributes = new TreeMap<>();
EntityType<?> ownerType;
if ((baseNode.getParentTreeNode() == null || splitEntity && baseNode.getManagedType() instanceof EntityType<?>) && field == null) {
ownerType = baseNode.getEntityType();
for (SingularAttribute<?, ?> idAttribute : managedType.getIdAttributes()) {
addAttributes(ownerType, null, fieldPrefix, "", idAttribute, orderedAttributes);
}
} else {
Map<String, ? extends ExtendedAttribute<?, ?>> ownedAttributes;
String prefix = field;
if (baseNode.getParentTreeNode() != null && jpaProvider.getJpaMetamodelAccessor().isElementCollection(baseNode.getParentTreeNode().getAttribute())) {
String elementCollectionPath = baseNode.getParentTreeNode().getRelationName();
ExtendedManagedType entityManagedType = metamodel.getManagedType(ExtendedManagedType.class, baseNode.getParent().getEntityType());
ownedAttributes = entityManagedType.getAttributes();
if (prefix == null) {
prefix = elementCollectionPath;
} else {
prefix = elementCollectionPath + "." + prefix;
}
} else {
ownedAttributes = managedType.getOwnedSingularAttributes();
}
for (String embeddedPropertyPath : JpaUtils.getEmbeddedPropertyPaths((Map<String, ExtendedAttribute<?, ?>>) ownedAttributes, prefix, false, false)) {
orderedAttributes.put(embeddedPropertyPath, Boolean.FALSE);
}
}
// Signal the caller that the expression was eliminated
if (orderedAttributes.isEmpty()) {
return true;
}
for (String orderedAttribute : orderedAttributes.keySet()) {
splittedOffExpressions.add(splittingVisitor.splitOff(expression, expressionToSplit, orderedAttribute));
}
}
return false;
}
Aggregations