use of com.blazebit.persistence.spi.JpaMetamodelAccessor in project blaze-persistence by Blazebit.
the class JoinManager method createOrUpdateNode.
private JoinResult createOrUpdateNode(JoinNode baseNode, List<String> joinRelationAttributes, String treatType, String alias, JoinType joinType, JoinNode currentJoinNode, boolean implicit, boolean defaultJoin, boolean joinAllowed, boolean singularJoinAllowed) {
Type<?> baseNodeType = baseNode.getNodeType();
String joinRelationName = StringUtils.join(".", joinRelationAttributes);
JpaMetamodelAccessor jpaMetamodelAccessor = mainQuery.jpaProvider.getJpaMetamodelAccessor();
AttributeHolder attrJoinResult = JpaUtils.getAttributeForJoining(metamodel, baseNodeType, expressionFactory.createJoinPathExpression(joinRelationName), null);
Attribute<?, ?> attr = attrJoinResult.getAttribute();
if (attr == null) {
throw new IllegalArgumentException("Field with name " + joinRelationName + " was not found within class " + JpaMetamodelUtils.getTypeName(baseNodeType));
}
if (!jpaMetamodelAccessor.isJoinable(attr)) {
if (LOG.isLoggable(Level.FINE)) {
LOG.fine(new StringBuilder("Field with name ").append(joinRelationName).append(" of class ").append(JpaMetamodelUtils.getTypeName(baseNodeType)).append(" is parseable and therefore it has not to be fetched explicitly.").toString());
}
return new JoinResult(baseNode, joinRelationAttributes, attrJoinResult.getAttributeType(), -1, -1);
}
// Don't throw implicit join not allowed exception when the currentJoinNode contains the node that we would create in this method
if (!joinAllowed && !baseNode.hasDefaultJoin(joinRelationName) && (currentJoinNode == null || currentJoinNode == baseNode || !currentJoinNode.containsNode(baseNode, joinRelationName) && (!singularJoinAllowed || attr instanceof PluralAttribute<?, ?, ?>))) {
throw new ImplicitJoinNotAllowedException(baseNode, joinRelationAttributes, treatType);
}
if (implicit || (defaultJoin && alias == null)) {
String aliasToUse = alias == null ? attr.getName() : alias;
alias = baseNode.getAliasInfo().getAliasOwner().generateJoinAlias(aliasToUse);
}
if (joinType == null) {
joinType = getModelAwareType(baseNode, attr);
}
Type<?> joinRelationType = attrJoinResult.getAttributeType();
JoinNode newNode = getOrCreate(baseNode, joinRelationName, joinRelationType, treatType, alias, joinType, "Ambiguous implicit join", implicit, defaultJoin, attr);
return new JoinResult(newNode);
}
Aggregations