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