EmbeddedIdentifierMappingImpl implements SingleAttributeIdentifierMapping

This commit is contained in:
Andrea Boriero 2020-08-13 09:34:47 +01:00
parent 638d1b2d46
commit 4806398ecc
2 changed files with 48 additions and 51 deletions

View File

@ -37,7 +37,8 @@ import org.hibernate.sql.ast.tree.from.TableReference;
*
* @author Andrea Boriero
*/
public class EmbeddedIdentifierMappingImpl extends AbstractCompositeIdentifierMapping {
public class EmbeddedIdentifierMappingImpl extends AbstractCompositeIdentifierMapping
implements SingleAttributeIdentifierMapping {
private final String name;
private final PropertyAccess propertyAccess;
@ -177,4 +178,14 @@ public class EmbeddedIdentifierMappingImpl extends AbstractCompositeIdentifierMa
return (Collection) getEmbeddableTypeDescriptor().getAttributeMappings();
}
@Override
public PropertyAccess getPropertyAccess() {
return propertyAccess;
}
@Override
public String getAttributeName() {
return name;
}
}

View File

@ -6,8 +6,6 @@
*/
package org.hibernate.sql.results.graph.entity;
import java.util.ArrayList;
import org.hibernate.LockMode;
import org.hibernate.metamodel.mapping.EntityDiscriminatorMapping;
import org.hibernate.metamodel.mapping.EntityIdentifierMapping;
@ -16,7 +14,7 @@ import org.hibernate.metamodel.mapping.EntityRowIdMapping;
import org.hibernate.metamodel.mapping.EntityValuedModelPart;
import org.hibernate.metamodel.mapping.EntityVersionMapping;
import org.hibernate.metamodel.mapping.ManagedMappingType;
import org.hibernate.metamodel.mapping.internal.SingleAttributeIdentifierMapping;
import org.hibernate.metamodel.mapping.MappingType;
import org.hibernate.metamodel.mapping.internal.ToOneAttributeMapping;
import org.hibernate.persister.entity.AbstractEntityPersister;
import org.hibernate.query.EntityIdentifierNavigablePath;
@ -70,29 +68,14 @@ public abstract class AbstractEntityResultGraphNode extends AbstractFetchParent
final EntityIdentifierMapping identifierMapping = entityDescriptor.getIdentifierMapping();
final EntityIdentifierNavigablePath identifierNavigablePath = new EntityIdentifierNavigablePath( navigablePath, attributeName( identifierMapping ) );
if ( navigablePath.getParent() == null && !creationState.forceIdentifierSelection() ) {
identifierResult = null;
if ( identifierMapping instanceof SingleAttributeIdentifierMapping ) {
identifierMapping.createDomainResult(
new EntityIdentifierNavigablePath(
navigablePath,
attributeName( identifierMapping )
),
entityTableGroup,
null,
creationState
);
}
else {
visitCompositeIdentifierMapping( navigablePath, creationState, identifierMapping, entityTableGroup );
}
visitIdentifierMapping( identifierNavigablePath, creationState, identifierMapping, entityTableGroup );
}
else {
identifierResult = identifierMapping.createDomainResult(
new EntityIdentifierNavigablePath(
navigablePath,
attributeName( identifierMapping )
),
identifierNavigablePath,
entityTableGroup,
null,
creationState
@ -139,21 +122,18 @@ public abstract class AbstractEntityResultGraphNode extends AbstractFetchParent
}
}
private void visitCompositeIdentifierMapping(
NavigablePath navigablePath,
private void visitIdentifierMapping(
EntityIdentifierNavigablePath navigablePath,
DomainResultCreationState creationState,
EntityIdentifierMapping identifierMapping,
TableGroup entityTableGroup) {
ManagedMappingType mappingType = (ManagedMappingType) identifierMapping.getPartMappingType();
fetches = new ArrayList<>();
mappingType.visitAttributeMappings(
final MappingType mappingType = identifierMapping.getPartMappingType();
if ( mappingType instanceof ManagedMappingType ) {
( (ManagedMappingType) mappingType ).visitAttributeMappings(
attributeMapping -> {
if ( attributeMapping instanceof ToOneAttributeMapping ) {
( (ToOneAttributeMapping) attributeMapping ).getForeignKeyDescriptor().createDomainResult(
new EntityIdentifierNavigablePath(
navigablePath,
attributeName( identifierMapping )
),
entityTableGroup,
null,
creationState
@ -161,10 +141,7 @@ public abstract class AbstractEntityResultGraphNode extends AbstractFetchParent
}
else {
attributeMapping.createDomainResult(
new EntityIdentifierNavigablePath(
navigablePath,
attributeName( identifierMapping )
),
entityTableGroup,
null,
creationState
@ -173,6 +150,15 @@ public abstract class AbstractEntityResultGraphNode extends AbstractFetchParent
}
);
}
else {
identifierMapping.createDomainResult(
navigablePath,
entityTableGroup,
null,
creationState
);
}
}
protected EntityDiscriminatorMapping getDiscriminatorMapping(
EntityMappingType entityDescriptor,