HHH-16372 Fix NPEs in some Bindable implementations that operate on values
This commit is contained in:
parent
7f7e4b5f6a
commit
71541679e8
|
@ -88,11 +88,6 @@ public abstract class AbstractCompositeIdentifierMapping
|
||||||
return getPartMappingType();
|
return getPartMappingType();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public JavaType<?> getJavaType() {
|
|
||||||
return getPartMappingType().getMappedJavaType();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getContainingTableExpression() {
|
public String getContainingTableExpression() {
|
||||||
return tableExpression;
|
return tableExpression;
|
||||||
|
@ -188,28 +183,36 @@ public abstract class AbstractCompositeIdentifierMapping
|
||||||
int span = 0;
|
int span = 0;
|
||||||
final EmbeddableMappingType embeddableTypeDescriptor = getEmbeddableTypeDescriptor();
|
final EmbeddableMappingType embeddableTypeDescriptor = getEmbeddableTypeDescriptor();
|
||||||
final int size = embeddableTypeDescriptor.getNumberOfAttributeMappings();
|
final int size = embeddableTypeDescriptor.getNumberOfAttributeMappings();
|
||||||
for ( int i = 0; i < size; i++ ) {
|
if ( value == null ) {
|
||||||
final AttributeMapping attributeMapping = embeddableTypeDescriptor.getAttributeMapping( i );
|
for ( int i = 0; i < size; i++ ) {
|
||||||
final Object o = attributeMapping.getPropertyAccess().getGetter().get( value );
|
final AttributeMapping attributeMapping = embeddableTypeDescriptor.getAttributeMapping( i );
|
||||||
if ( attributeMapping instanceof ToOneAttributeMapping ) {
|
span += attributeMapping.forEachJdbcValue( null, span + offset, x, y, valuesConsumer, session );
|
||||||
final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attributeMapping;
|
|
||||||
final ForeignKeyDescriptor fkDescriptor = toOneAttributeMapping.getForeignKeyDescriptor();
|
|
||||||
final Object identifier = fkDescriptor.getAssociationKeyFromSide(
|
|
||||||
o,
|
|
||||||
toOneAttributeMapping.getSideNature().inverse(),
|
|
||||||
session
|
|
||||||
);
|
|
||||||
span += fkDescriptor.forEachJdbcValue(
|
|
||||||
identifier,
|
|
||||||
span + offset,
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
valuesConsumer,
|
|
||||||
session
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
else {
|
}
|
||||||
span += attributeMapping.forEachJdbcValue( o, span + offset, x, y, valuesConsumer, session );
|
else {
|
||||||
|
for ( int i = 0; i < size; i++ ) {
|
||||||
|
final AttributeMapping attributeMapping = embeddableTypeDescriptor.getAttributeMapping( i );
|
||||||
|
final Object o = attributeMapping.getPropertyAccess().getGetter().get( value );
|
||||||
|
if ( attributeMapping instanceof ToOneAttributeMapping ) {
|
||||||
|
final ToOneAttributeMapping toOneAttributeMapping = (ToOneAttributeMapping) attributeMapping;
|
||||||
|
final ForeignKeyDescriptor fkDescriptor = toOneAttributeMapping.getForeignKeyDescriptor();
|
||||||
|
final Object identifier = fkDescriptor.getAssociationKeyFromSide(
|
||||||
|
o,
|
||||||
|
toOneAttributeMapping.getSideNature().inverse(),
|
||||||
|
session
|
||||||
|
);
|
||||||
|
span += fkDescriptor.forEachJdbcValue(
|
||||||
|
identifier,
|
||||||
|
span + offset,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
valuesConsumer,
|
||||||
|
session
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
span += attributeMapping.forEachJdbcValue( o, span + offset, x, y, valuesConsumer, session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
|
|
|
@ -21,6 +21,7 @@ import org.hibernate.sql.ast.tree.from.TableGroup;
|
||||||
import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer;
|
import org.hibernate.sql.ast.tree.from.TableGroupJoinProducer;
|
||||||
import org.hibernate.sql.results.graph.Fetchable;
|
import org.hibernate.sql.results.graph.Fetchable;
|
||||||
import org.hibernate.sql.results.graph.FetchableContainer;
|
import org.hibernate.sql.results.graph.FetchableContainer;
|
||||||
|
import org.hibernate.type.descriptor.java.JavaType;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Describes the mapping of an embeddable (composite).
|
* Describes the mapping of an embeddable (composite).
|
||||||
|
@ -37,6 +38,11 @@ public interface EmbeddableValuedModelPart extends ValuedModelPart, Fetchable, F
|
||||||
return getEmbeddableTypeDescriptor();
|
return getEmbeddableTypeDescriptor();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default JavaType<?> getJavaType() {
|
||||||
|
return getEmbeddableTypeDescriptor().getJavaType();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default ModelPart findSubPart(String name, EntityMappingType treatTargetType) {
|
default ModelPart findSubPart(String name, EntityMappingType treatTargetType) {
|
||||||
return getEmbeddableTypeDescriptor().findSubPart( name, treatTargetType );
|
return getEmbeddableTypeDescriptor().findSubPart( name, treatTargetType );
|
||||||
|
@ -83,6 +89,43 @@ public interface EmbeddableValuedModelPart extends ValuedModelPart, Fetchable, F
|
||||||
return getEmbeddableTypeDescriptor().forEachJdbcValue( value, offset, x, y, valuesConsumer, session );
|
return getEmbeddableTypeDescriptor().forEachJdbcValue( value, offset, x, y, valuesConsumer, session );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default <X, Y> int breakDownJdbcValues(
|
||||||
|
Object domainValue,
|
||||||
|
int offset,
|
||||||
|
X x,
|
||||||
|
Y y,
|
||||||
|
JdbcValueBiConsumer<X, Y> valueConsumer,
|
||||||
|
SharedSessionContractImplementor session) {
|
||||||
|
return getEmbeddableTypeDescriptor().breakDownJdbcValues( domainValue, offset, x, y, valueConsumer, session );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default <X, Y> int decompose(
|
||||||
|
Object domainValue,
|
||||||
|
int offset,
|
||||||
|
X x,
|
||||||
|
Y y,
|
||||||
|
JdbcValueBiConsumer<X, Y> valueConsumer,
|
||||||
|
SharedSessionContractImplementor session) {
|
||||||
|
return getEmbeddableTypeDescriptor().decompose( domainValue, offset, x, y, valueConsumer, session );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default int getNumberOfFetchables() {
|
||||||
|
return getEmbeddableTypeDescriptor().getNumberOfAttributeMappings();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default Fetchable getFetchable(int position) {
|
||||||
|
return getEmbeddableTypeDescriptor().getFetchable( position );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default int getSelectableIndex(String selectableName) {
|
||||||
|
return getEmbeddableTypeDescriptor().getSelectableIndex( selectableName );
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default SelectableMapping getSelectable(int columnIndex) {
|
default SelectableMapping getSelectable(int columnIndex) {
|
||||||
return getEmbeddableTypeDescriptor().getSelectable( columnIndex );
|
return getEmbeddableTypeDescriptor().getSelectable( columnIndex );
|
||||||
|
@ -93,6 +136,21 @@ public interface EmbeddableValuedModelPart extends ValuedModelPart, Fetchable, F
|
||||||
return getEmbeddableTypeDescriptor().forEachSelectable( offset, consumer );
|
return getEmbeddableTypeDescriptor().forEachSelectable( offset, consumer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void forEachInsertable(SelectableConsumer consumer) {
|
||||||
|
getEmbeddableTypeDescriptor().forEachInsertable( 0, consumer );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default void forEachUpdatable(SelectableConsumer consumer) {
|
||||||
|
getEmbeddableTypeDescriptor().forEachUpdatable( 0, consumer );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
default boolean hasPartitionedSelectionMapping() {
|
||||||
|
return getEmbeddableTypeDescriptor().hasPartitionedSelectionMapping();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
default <X, Y> int forEachDisassembledJdbcValue(
|
default <X, Y> int forEachDisassembledJdbcValue(
|
||||||
Object value,
|
Object value,
|
||||||
|
|
|
@ -574,8 +574,35 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
|
||||||
forEachAttributeMapping( consumer );
|
forEachAttributeMapping( consumer );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <X, Y> int breakDownJdbcValues(
|
||||||
|
Object domainValue,
|
||||||
|
int offset,
|
||||||
|
X x,
|
||||||
|
Y y,
|
||||||
|
JdbcValueBiConsumer<X, Y> valueConsumer, SharedSessionContractImplementor session) {
|
||||||
|
int span = 0;
|
||||||
|
if ( domainValue == null ) {
|
||||||
|
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
||||||
|
final AttributeMapping attribute = attributeMappings.get( i );
|
||||||
|
span += attribute.breakDownJdbcValues( null, offset + span, x, y, valueConsumer, session );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
||||||
|
final AttributeMapping attribute = attributeMappings.get( i );
|
||||||
|
final Object attributeValue = attribute.getValue( domainValue );
|
||||||
|
span += attribute.breakDownJdbcValues( attributeValue, offset + span, x, y, valueConsumer, session );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return span;
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object disassemble(Object value, SharedSessionContractImplementor session) {
|
public Object disassemble(Object value, SharedSessionContractImplementor session) {
|
||||||
|
if ( value == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
final int size = attributeMappings.size();
|
final int size = attributeMappings.size();
|
||||||
final Object[] result = new Object[ size ];
|
final Object[] result = new Object[ size ];
|
||||||
for ( int i = 0; i < size; i++ ) {
|
for ( int i = 0; i < size; i++ ) {
|
||||||
|
@ -590,9 +617,16 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
|
||||||
@Override
|
@Override
|
||||||
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
||||||
final int size = attributeMappings.size();
|
final int size = attributeMappings.size();
|
||||||
for ( int i = 0; i < size; i++ ) {
|
if ( value == null ) {
|
||||||
final AttributeMapping attributeMapping = attributeMappings.get( i );
|
for ( int i = 0; i < size; i++ ) {
|
||||||
attributeMapping.addToCacheKey( cacheKey, attributeMapping.getValue( value ), session );
|
attributeMappings.get( i ).addToCacheKey( cacheKey, null, session );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for ( int i = 0; i < size; i++ ) {
|
||||||
|
final AttributeMapping attributeMapping = attributeMappings.get( i );
|
||||||
|
attributeMapping.addToCacheKey( cacheKey, attributeMapping.getValue( value ), session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -604,11 +638,19 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
|
||||||
Y y,
|
Y y,
|
||||||
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
final Object[] values = (Object[]) value;
|
|
||||||
int span = 0;
|
int span = 0;
|
||||||
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
if ( value == null ) {
|
||||||
final AttributeMapping mapping = attributeMappings.get( i );
|
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
||||||
span += mapping.forEachDisassembledJdbcValue( values[i], span + offset, x, y, valuesConsumer, session );
|
final AttributeMapping mapping = attributeMappings.get( i );
|
||||||
|
span += mapping.forEachDisassembledJdbcValue( null, span + offset, x, y, valuesConsumer, session );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final Object[] values = (Object[]) value;
|
||||||
|
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
||||||
|
final AttributeMapping mapping = attributeMappings.get( i );
|
||||||
|
span += mapping.forEachDisassembledJdbcValue( values[i], span + offset, x, y, valuesConsumer, session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
@ -622,14 +664,24 @@ public abstract class AbstractEmbeddableMapping implements EmbeddableMappingType
|
||||||
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
int span = 0;
|
int span = 0;
|
||||||
|
if ( value == null ) {
|
||||||
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
||||||
final AttributeMapping attributeMapping = attributeMappings.get( i );
|
final AttributeMapping attributeMapping = attributeMappings.get( i );
|
||||||
if ( attributeMapping instanceof PluralAttributeMapping ) {
|
if ( attributeMapping instanceof PluralAttributeMapping ) {
|
||||||
continue;
|
continue;
|
||||||
|
}
|
||||||
|
span += attributeMapping.forEachJdbcValue( null, span + offset, x, y, valuesConsumer, session );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
||||||
|
final AttributeMapping attributeMapping = attributeMappings.get( i );
|
||||||
|
if ( attributeMapping instanceof PluralAttributeMapping ) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
final Object o = attributeMapping.getPropertyAccess().getGetter().get( value );
|
||||||
|
span += attributeMapping.forEachJdbcValue( o, span + offset, x, y, valuesConsumer, session );
|
||||||
}
|
}
|
||||||
final Object o = attributeMapping.getPropertyAccess().getGetter().get( value );
|
|
||||||
span += attributeMapping.forEachJdbcValue( o, span + offset, x, y, valuesConsumer, session );
|
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
|
@ -326,16 +326,23 @@ public class CompoundNaturalIdMapping extends AbstractNaturalIdMapping implement
|
||||||
for ( int i = 0; i < attributes.size(); i++ ) {
|
for ( int i = 0; i < attributes.size(); i++ ) {
|
||||||
span += attributes.get( i ).breakDownJdbcValues( null, offset + span, x, y, valueConsumer, session );
|
span += attributes.get( i ).breakDownJdbcValues( null, offset + span, x, y, valueConsumer, session );
|
||||||
}
|
}
|
||||||
return span;
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
assert domainValue instanceof Object[];
|
||||||
|
|
||||||
assert domainValue instanceof Object[];
|
final Object[] values = (Object[]) domainValue;
|
||||||
|
assert values.length == attributes.size();
|
||||||
|
|
||||||
final Object[] values = (Object[]) domainValue;
|
for ( int i = 0; i < attributes.size(); i++ ) {
|
||||||
assert values.length == attributes.size();
|
span += attributes.get( i ).breakDownJdbcValues(
|
||||||
|
values[i],
|
||||||
for ( int i = 0; i < attributes.size(); i++ ) {
|
offset + span,
|
||||||
span += attributes.get( i ).breakDownJdbcValues( values[ i ], offset + span, x, y, valueConsumer, session );
|
x,
|
||||||
|
y,
|
||||||
|
valueConsumer,
|
||||||
|
session
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
@ -379,6 +386,9 @@ public class CompoundNaturalIdMapping extends AbstractNaturalIdMapping implement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object disassemble(Object value, SharedSessionContractImplementor session) {
|
public Object disassemble(Object value, SharedSessionContractImplementor session) {
|
||||||
|
if ( value == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
assert value instanceof Object[];
|
assert value instanceof Object[];
|
||||||
|
|
||||||
final Object[] incoming = (Object[]) value;
|
final Object[] incoming = (Object[]) value;
|
||||||
|
@ -396,13 +406,20 @@ public class CompoundNaturalIdMapping extends AbstractNaturalIdMapping implement
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
||||||
assert value instanceof Object[];
|
if ( value == null ) {
|
||||||
|
for ( int i = 0; i < attributes.size(); i++ ) {
|
||||||
|
attributes.get( i ).addToCacheKey( cacheKey, null, session );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert value instanceof Object[];
|
||||||
|
|
||||||
final Object[] values = (Object[]) value;
|
final Object[] values = (Object[]) value;
|
||||||
assert values.length == attributes.size();
|
assert values.length == attributes.size();
|
||||||
|
|
||||||
for ( int i = 0; i < attributes.size(); i++ ) {
|
for ( int i = 0; i < attributes.size(); i++ ) {
|
||||||
attributes.get( i ).addToCacheKey( cacheKey, values[i], session );
|
attributes.get( i ).addToCacheKey( cacheKey, values[i], session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -414,14 +431,36 @@ public class CompoundNaturalIdMapping extends AbstractNaturalIdMapping implement
|
||||||
Y y,
|
Y y,
|
||||||
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
assert value instanceof Object[];
|
|
||||||
|
|
||||||
final Object[] incoming = (Object[]) value;
|
|
||||||
assert incoming.length == attributes.size();
|
|
||||||
int span = 0;
|
int span = 0;
|
||||||
for ( int i = 0; i < attributes.size(); i++ ) {
|
if ( value == null ) {
|
||||||
final SingularAttributeMapping attribute = attributes.get( i );
|
for ( int i = 0; i < attributes.size(); i++ ) {
|
||||||
span += attribute.forEachDisassembledJdbcValue( incoming[ i ], span + offset, x, y, valuesConsumer, session );
|
final SingularAttributeMapping attribute = attributes.get( i );
|
||||||
|
span += attribute.forEachDisassembledJdbcValue(
|
||||||
|
null,
|
||||||
|
span + offset,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
valuesConsumer,
|
||||||
|
session
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert value instanceof Object[];
|
||||||
|
|
||||||
|
final Object[] incoming = (Object[]) value;
|
||||||
|
assert incoming.length == attributes.size();
|
||||||
|
for ( int i = 0; i < attributes.size(); i++ ) {
|
||||||
|
final SingularAttributeMapping attribute = attributes.get( i );
|
||||||
|
span += attribute.forEachDisassembledJdbcValue(
|
||||||
|
incoming[i],
|
||||||
|
span + offset,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
valuesConsumer,
|
||||||
|
session
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
@ -434,15 +473,23 @@ public class CompoundNaturalIdMapping extends AbstractNaturalIdMapping implement
|
||||||
Y y,
|
Y y,
|
||||||
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
assert value instanceof Object[];
|
|
||||||
|
|
||||||
final Object[] incoming = (Object[]) value;
|
|
||||||
assert incoming.length == attributes.size();
|
|
||||||
|
|
||||||
int span = 0;
|
int span = 0;
|
||||||
for ( int i = 0; i < attributes.size(); i++ ) {
|
if ( value == null ) {
|
||||||
final SingularAttributeMapping attribute = attributes.get( i );
|
for ( int i = 0; i < attributes.size(); i++ ) {
|
||||||
span += attribute.forEachJdbcValue( incoming[ i ], span + offset, x, y, valuesConsumer, session );
|
final SingularAttributeMapping attribute = attributes.get( i );
|
||||||
|
span += attribute.forEachJdbcValue( null, span + offset, x, y, valuesConsumer, session );
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
assert value instanceof Object[];
|
||||||
|
|
||||||
|
final Object[] incoming = (Object[]) value;
|
||||||
|
assert incoming.length == attributes.size();
|
||||||
|
|
||||||
|
for ( int i = 0; i < attributes.size(); i++ ) {
|
||||||
|
final SingularAttributeMapping attribute = attributes.get( i );
|
||||||
|
span += attribute.forEachJdbcValue( incoming[i], span + offset, x, y, valuesConsumer, session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
|
@ -240,18 +240,20 @@ public class DiscriminatedAssociationAttributeMapping
|
||||||
@Override
|
@Override
|
||||||
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
||||||
if ( value == null ) {
|
if ( value == null ) {
|
||||||
return ;
|
cacheKey.addValue( null );
|
||||||
|
cacheKey.addHashCode( 0 );
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
final EntityMappingType concreteMappingType = determineConcreteType( value, session );
|
||||||
|
|
||||||
final EntityMappingType concreteMappingType = determineConcreteType( value, session );
|
final Object discriminator = discriminatorMapping
|
||||||
|
.getModelPart()
|
||||||
|
.resolveDiscriminatorForEntityType( concreteMappingType );
|
||||||
|
discriminatorMapping.getDiscriminatorPart().addToCacheKey( cacheKey, discriminator, session );
|
||||||
|
|
||||||
final Object discriminator = discriminatorMapping
|
final EntityIdentifierMapping identifierMapping = concreteMappingType.getIdentifierMapping();
|
||||||
.getModelPart()
|
identifierMapping.addToCacheKey( cacheKey, identifierMapping.getIdentifier( value ), session );
|
||||||
.resolveDiscriminatorForEntityType( concreteMappingType );
|
}
|
||||||
discriminatorMapping.getDiscriminatorPart().addToCacheKey( cacheKey, discriminator, session );
|
|
||||||
|
|
||||||
final EntityIdentifierMapping identifierMapping = concreteMappingType.getIdentifierMapping();
|
|
||||||
identifierMapping.addToCacheKey( cacheKey, identifierMapping.getIdentifier( value ), session );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private EntityMappingType determineConcreteType(Object entity, SharedSessionContractImplementor session) {
|
private EntityMappingType determineConcreteType(Object entity, SharedSessionContractImplementor session) {
|
||||||
|
@ -290,7 +292,23 @@ public class DiscriminatedAssociationAttributeMapping
|
||||||
Y y,
|
Y y,
|
||||||
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
if ( value != null ) {
|
if ( value == null ) {
|
||||||
|
valuesConsumer.consume(
|
||||||
|
offset,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
null,
|
||||||
|
discriminatorMapping.getDiscriminatorPart().getJdbcMapping()
|
||||||
|
);
|
||||||
|
valuesConsumer.consume(
|
||||||
|
offset + 1,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
null,
|
||||||
|
discriminatorMapping.getKeyPart().getJdbcMapping()
|
||||||
|
);
|
||||||
|
}
|
||||||
|
else {
|
||||||
if ( value.getClass().isArray() ) {
|
if ( value.getClass().isArray() ) {
|
||||||
final Object[] values = (Object[]) value;
|
final Object[] values = (Object[]) value;
|
||||||
valuesConsumer.consume(
|
valuesConsumer.consume(
|
||||||
|
|
|
@ -184,53 +184,6 @@ public class EmbeddedAttributeMapping
|
||||||
return parentInjectionAttributePropertyAccess;
|
return parentInjectionAttributePropertyAccess;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int compare(Object value1, Object value2) {
|
|
||||||
return super.compare( value1, value2 );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int forEachSelectable(int offset, SelectableConsumer consumer) {
|
|
||||||
return getEmbeddableTypeDescriptor().forEachSelectable( offset, consumer );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void forEachInsertable(SelectableConsumer consumer) {
|
|
||||||
getEmbeddableTypeDescriptor().forEachInsertable( 0, consumer );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void forEachUpdatable(SelectableConsumer consumer) {
|
|
||||||
getEmbeddableTypeDescriptor().forEachUpdatable( 0, consumer );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <X, Y> int breakDownJdbcValues(
|
|
||||||
Object domainValue,
|
|
||||||
int offset,
|
|
||||||
X x,
|
|
||||||
Y y,
|
|
||||||
JdbcValueBiConsumer<X, Y> valueConsumer,
|
|
||||||
SharedSessionContractImplementor session) {
|
|
||||||
return getEmbeddableTypeDescriptor().breakDownJdbcValues( domainValue, offset, x, y, valueConsumer, session );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <X, Y> int decompose(
|
|
||||||
Object domainValue,
|
|
||||||
int offset,
|
|
||||||
X x,
|
|
||||||
Y y,
|
|
||||||
JdbcValueBiConsumer<X, Y> valueConsumer,
|
|
||||||
SharedSessionContractImplementor session) {
|
|
||||||
return getEmbeddableTypeDescriptor().decompose( domainValue, offset, x, y, valueConsumer, session );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPartitionedSelectionMapping() {
|
|
||||||
return getEmbeddableTypeDescriptor().hasPartitionedSelectionMapping();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <T> DomainResult<T> createDomainResult(
|
public <T> DomainResult<T> createDomainResult(
|
||||||
NavigablePath navigablePath,
|
NavigablePath navigablePath,
|
||||||
|
@ -343,20 +296,6 @@ public class EmbeddedAttributeMapping
|
||||||
return new SqlTuple( columnReferences, this );
|
return new SqlTuple( columnReferences, this );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public ModelPart findSubPart(
|
|
||||||
String name,
|
|
||||||
EntityMappingType treatTargetType) {
|
|
||||||
return getMappedType().findSubPart( name, treatTargetType );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void visitSubParts(
|
|
||||||
Consumer<ModelPart> consumer,
|
|
||||||
EntityMappingType treatTargetType) {
|
|
||||||
getMappedType().visitSubParts( consumer, treatTargetType );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public TableGroupJoin createTableGroupJoin(
|
public TableGroupJoin createTableGroupJoin(
|
||||||
NavigablePath navigablePath,
|
NavigablePath navigablePath,
|
||||||
|
@ -400,21 +339,6 @@ public class EmbeddedAttributeMapping
|
||||||
return getAttributeName();
|
return getAttributeName();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNumberOfFetchables() {
|
|
||||||
return getEmbeddableTypeDescriptor().getNumberOfAttributeMappings();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Fetchable getFetchable(int position) {
|
|
||||||
return getEmbeddableTypeDescriptor().getFetchable( position );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getSelectableIndex(String selectableName) {
|
|
||||||
return getEmbeddableTypeDescriptor().getSelectableIndex( selectableName );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "EmbeddedAttributeMapping(" + navigableRole + ")@" + System.identityHashCode( this );
|
return "EmbeddedAttributeMapping(" + navigableRole + ")@" + System.identityHashCode( this );
|
||||||
|
|
|
@ -297,11 +297,6 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
|
||||||
embeddableMappingType.applySqlSelections( navigablePath, tableGroup, creationState, selectionConsumer );
|
embeddableMappingType.applySqlSelections( navigablePath, tableGroup, creationState, selectionConsumer );
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public JavaType<?> getJavaType() {
|
|
||||||
return getEmbeddableTypeDescriptor().getJavaType();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public JavaType<?> getExpressibleJavaType() {
|
public JavaType<?> getExpressibleJavaType() {
|
||||||
return getJavaType();
|
return getJavaType();
|
||||||
|
@ -317,32 +312,6 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
|
||||||
return collectionDescriptor.getAttributeMapping().findContainingEntityMapping();
|
return collectionDescriptor.getAttributeMapping().findContainingEntityMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNumberOfFetchables() {
|
|
||||||
return getEmbeddableTypeDescriptor().getNumberOfAttributeMappings();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Fetchable getFetchable(int position) {
|
|
||||||
return getEmbeddableTypeDescriptor().getFetchable( position );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int forEachSelectable(int offset, SelectableConsumer consumer) {
|
|
||||||
return getEmbeddableTypeDescriptor().forEachSelectable( offset, consumer );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <X, Y> int breakDownJdbcValues(
|
|
||||||
Object domainValue,
|
|
||||||
int offset,
|
|
||||||
X x,
|
|
||||||
Y y,
|
|
||||||
JdbcValueBiConsumer<X, Y> valueConsumer,
|
|
||||||
SharedSessionContractImplementor session) {
|
|
||||||
return getEmbeddableTypeDescriptor().breakDownJdbcValues( domainValue, offset, x, y, valueConsumer, session );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public FetchStyle getStyle() {
|
public FetchStyle getStyle() {
|
||||||
return FetchStyle.JOIN;
|
return FetchStyle.JOIN;
|
||||||
|
@ -353,9 +322,4 @@ public class EmbeddedCollectionPart implements CollectionPart, EmbeddableValuedF
|
||||||
return FetchTiming.IMMEDIATE;
|
return FetchTiming.IMMEDIATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public boolean hasPartitionedSelectionMapping() {
|
|
||||||
return getEmbeddableTypeDescriptor().hasPartitionedSelectionMapping();
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,7 +6,6 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.mapping.internal;
|
package org.hibernate.metamodel.mapping.internal;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.function.BiConsumer;
|
import java.util.function.BiConsumer;
|
||||||
|
|
||||||
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
import org.hibernate.engine.spi.SharedSessionContractImplementor;
|
||||||
|
@ -110,17 +109,6 @@ public class EmbeddedIdentifierMappingImpl
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public int getNumberOfFetchables() {
|
|
||||||
return getEmbeddableTypeDescriptor().getNumberOfAttributeMappings();
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Fetchable getFetchable(int position) {
|
|
||||||
return getEmbeddableTypeDescriptor().getFetchable( position );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public PropertyAccess getPropertyAccess() {
|
public PropertyAccess getPropertyAccess() {
|
||||||
return propertyAccess;
|
return propertyAccess;
|
||||||
|
@ -131,32 +119,4 @@ public class EmbeddedIdentifierMappingImpl
|
||||||
return name;
|
return name;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <X, Y> int breakDownJdbcValues(
|
|
||||||
Object domainValue,
|
|
||||||
int offset,
|
|
||||||
X x,
|
|
||||||
Y y,
|
|
||||||
JdbcValueBiConsumer<X, Y> valueConsumer,
|
|
||||||
SharedSessionContractImplementor session) {
|
|
||||||
return getEmbeddableTypeDescriptor().breakDownJdbcValues( domainValue, offset, x, y, valueConsumer, session );
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public <X, Y> int forEachDisassembledJdbcValue(
|
|
||||||
Object value,
|
|
||||||
int offset,
|
|
||||||
X x,
|
|
||||||
Y y,
|
|
||||||
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
|
||||||
SharedSessionContractImplementor session) {
|
|
||||||
return getEmbeddableTypeDescriptor().forEachDisassembledJdbcValue(
|
|
||||||
value,
|
|
||||||
offset,
|
|
||||||
x,
|
|
||||||
y,
|
|
||||||
valuesConsumer,
|
|
||||||
session
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -6,10 +6,8 @@
|
||||||
*/
|
*/
|
||||||
package org.hibernate.metamodel.mapping.internal;
|
package org.hibernate.metamodel.mapping.internal;
|
||||||
|
|
||||||
import java.io.Serializable;
|
|
||||||
import java.util.function.Consumer;
|
import java.util.function.Consumer;
|
||||||
|
|
||||||
import org.hibernate.cache.MutableCacheKeyBuilder;
|
|
||||||
import org.hibernate.engine.FetchStyle;
|
import org.hibernate.engine.FetchStyle;
|
||||||
import org.hibernate.engine.FetchTiming;
|
import org.hibernate.engine.FetchTiming;
|
||||||
import org.hibernate.engine.spi.EntityKey;
|
import org.hibernate.engine.spi.EntityKey;
|
||||||
|
@ -288,49 +286,6 @@ public class IdClassEmbeddable extends AbstractEmbeddableMapping implements Iden
|
||||||
return idMapping.findContainingEntityMapping();
|
return idMapping.findContainingEntityMapping();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <X, Y> int breakDownJdbcValues(
|
|
||||||
Object domainValue,
|
|
||||||
int offset,
|
|
||||||
X x,
|
|
||||||
Y y,
|
|
||||||
JdbcValueBiConsumer<X, Y> valueConsumer,
|
|
||||||
SharedSessionContractImplementor session) {
|
|
||||||
int span = 0;
|
|
||||||
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
|
||||||
final AttributeMapping attribute = attributeMappings.get( i );
|
|
||||||
final Object attributeValue = attribute.getValue( domainValue );
|
|
||||||
span += attribute.breakDownJdbcValues( attributeValue, offset + span, x, y, valueConsumer, session );
|
|
||||||
}
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public Object disassemble(Object value, SharedSessionContractImplementor session) {
|
|
||||||
// todo (6.0) : reduce to-one values to id here?
|
|
||||||
final Object[] result = new Object[ getNumberOfAttributeMappings() ];
|
|
||||||
for ( int i = 0; i < result.length; i++ ) {
|
|
||||||
final AttributeMapping attributeMapping = getAttributeMapping( i );
|
|
||||||
Object o = attributeMapping.getPropertyAccess().getGetter().get( value );
|
|
||||||
result[i] = attributeMapping.disassemble( o, session );
|
|
||||||
}
|
|
||||||
|
|
||||||
return result;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
|
||||||
if ( value == null ) {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final Serializable[] result = new Serializable[ getNumberOfAttributeMappings() ];
|
|
||||||
for ( int i = 0; i < result.length; i++ ) {
|
|
||||||
final AttributeMapping attributeMapping = getAttributeMapping( i );
|
|
||||||
final Object o = attributeMapping.getPropertyAccess().getGetter().get( value );
|
|
||||||
attributeMapping.addToCacheKey( cacheKey, o, session );
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <X, Y> int forEachDisassembledJdbcValue(
|
public <X, Y> int forEachDisassembledJdbcValue(
|
||||||
Object value,
|
Object value,
|
||||||
|
|
|
@ -158,22 +158,6 @@ public class VirtualIdEmbeddable extends AbstractEmbeddableMapping implements Id
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
public <X, Y> int breakDownJdbcValues(
|
|
||||||
Object domainValue,
|
|
||||||
int offset,
|
|
||||||
X x,
|
|
||||||
Y y,
|
|
||||||
JdbcValueBiConsumer<X, Y> valueConsumer, SharedSessionContractImplementor session) {
|
|
||||||
int span = 0;
|
|
||||||
for ( int i = 0; i < attributeMappings.size(); i++ ) {
|
|
||||||
final AttributeMapping attribute = attributeMappings.get( i );
|
|
||||||
final Object attributeValue = attribute.getValue( domainValue );
|
|
||||||
span += attribute.breakDownJdbcValues( attributeValue, offset + span, x, y, valueConsumer, session );
|
|
||||||
}
|
|
||||||
return span;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public <X, Y> int decompose(
|
public <X, Y> int decompose(
|
||||||
Object domainValue,
|
Object domainValue,
|
||||||
|
|
|
@ -34,6 +34,9 @@ public class TupleMappingModelExpressible implements MappingModelExpressible {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object disassemble(Object value, SharedSessionContractImplementor session) {
|
public Object disassemble(Object value, SharedSessionContractImplementor session) {
|
||||||
|
if ( value == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
final Object[] disassembled = new Object[components.length];
|
final Object[] disassembled = new Object[components.length];
|
||||||
final Object[] array = (Object[]) value;
|
final Object[] array = (Object[]) value;
|
||||||
for ( int i = 0; i < components.length; i++ ) {
|
for ( int i = 0; i < components.length; i++ ) {
|
||||||
|
@ -45,10 +48,15 @@ public class TupleMappingModelExpressible implements MappingModelExpressible {
|
||||||
@Override
|
@Override
|
||||||
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
||||||
if ( value == null ) {
|
if ( value == null ) {
|
||||||
return;
|
for ( int i = 0; i < components.length; i++ ) {
|
||||||
|
components[i].addToCacheKey( cacheKey, null, session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
for ( int i = 0; i < components.length; i++ ) {
|
else {
|
||||||
components[i].addToCacheKey( cacheKey, value, session );
|
final Object[] array = (Object[]) value;
|
||||||
|
for ( int i = 0; i < components.length; i++ ) {
|
||||||
|
components[i].addToCacheKey( cacheKey, array[i], session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -60,10 +68,31 @@ public class TupleMappingModelExpressible implements MappingModelExpressible {
|
||||||
Y y,
|
Y y,
|
||||||
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
final Object[] values = (Object[]) value;
|
|
||||||
int span = 0;
|
int span = 0;
|
||||||
for ( int i = 0; i < components.length; i++ ) {
|
if ( value == null ) {
|
||||||
span += components[i].forEachDisassembledJdbcValue( values[i], span + offset, x, y, valuesConsumer, session );
|
for ( int i = 0; i < components.length; i++ ) {
|
||||||
|
span += components[i].forEachDisassembledJdbcValue(
|
||||||
|
null,
|
||||||
|
span + offset,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
valuesConsumer,
|
||||||
|
session
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final Object[] values = (Object[]) value;
|
||||||
|
for ( int i = 0; i < components.length; i++ ) {
|
||||||
|
span += components[i].forEachDisassembledJdbcValue(
|
||||||
|
values[i],
|
||||||
|
span + offset,
|
||||||
|
x,
|
||||||
|
y,
|
||||||
|
valuesConsumer,
|
||||||
|
session
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
@ -76,15 +105,27 @@ public class TupleMappingModelExpressible implements MappingModelExpressible {
|
||||||
Y y,
|
Y y,
|
||||||
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
final Object[] values = (Object[]) value;
|
|
||||||
int span = 0;
|
int span = 0;
|
||||||
for ( int i = 0; i < components.length; i++ ) {
|
if ( value == null ) {
|
||||||
span += components[i].forEachDisassembledJdbcValue(
|
for ( int i = 0; i < components.length; i++ ) {
|
||||||
components[i].disassemble( values[i], session ),
|
span += components[i].forEachDisassembledJdbcValue(
|
||||||
span + offset,
|
components[i].disassemble( null, session ),
|
||||||
x, y, valuesConsumer,
|
span + offset,
|
||||||
session
|
x, y, valuesConsumer,
|
||||||
);
|
session
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final Object[] values = (Object[]) value;
|
||||||
|
for ( int i = 0; i < components.length; i++ ) {
|
||||||
|
span += components[i].forEachDisassembledJdbcValue(
|
||||||
|
components[i].disassemble( values[i], session ),
|
||||||
|
span + offset,
|
||||||
|
x, y, valuesConsumer,
|
||||||
|
session
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
|
@ -56,6 +56,7 @@ import org.hibernate.sql.results.graph.DomainResultCreationState;
|
||||||
import org.hibernate.sql.results.graph.Fetch;
|
import org.hibernate.sql.results.graph.Fetch;
|
||||||
import org.hibernate.sql.results.graph.FetchOptions;
|
import org.hibernate.sql.results.graph.FetchOptions;
|
||||||
import org.hibernate.sql.results.graph.FetchParent;
|
import org.hibernate.sql.results.graph.FetchParent;
|
||||||
|
import org.hibernate.sql.results.graph.Fetchable;
|
||||||
import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableResultImpl;
|
import org.hibernate.sql.results.graph.embeddable.internal.EmbeddableResultImpl;
|
||||||
import org.hibernate.type.descriptor.java.JavaType;
|
import org.hibernate.type.descriptor.java.JavaType;
|
||||||
|
|
||||||
|
@ -67,19 +68,21 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
|
|
||||||
private static final FetchOptions FETCH_OPTIONS = FetchOptions.valueOf( FetchTiming.IMMEDIATE, FetchStyle.JOIN );
|
private static final FetchOptions FETCH_OPTIONS = FetchOptions.valueOf( FetchTiming.IMMEDIATE, FetchStyle.JOIN );
|
||||||
|
|
||||||
private final Map<String, ModelPart> modelParts;
|
private final Map<String, ModelPart> modelPartMap;
|
||||||
|
private final ModelPart[] modelParts;
|
||||||
private final DomainType<?> domainType;
|
private final DomainType<?> domainType;
|
||||||
private final String componentName;
|
private final String componentName;
|
||||||
private final EmbeddableValuedModelPart existingModelPartContainer;
|
private final EmbeddableValuedModelPart existingModelPartContainer;
|
||||||
private final int fetchableIndex;
|
private final int fetchableIndex;
|
||||||
|
|
||||||
public AnonymousTupleEmbeddableValuedModelPart(
|
public AnonymousTupleEmbeddableValuedModelPart(
|
||||||
Map<String, ModelPart> modelParts,
|
Map<String, ModelPart> modelPartMap,
|
||||||
DomainType<?> domainType,
|
DomainType<?> domainType,
|
||||||
String componentName,
|
String componentName,
|
||||||
EmbeddableValuedModelPart existingModelPartContainer,
|
EmbeddableValuedModelPart existingModelPartContainer,
|
||||||
int fetchableIndex) {
|
int fetchableIndex) {
|
||||||
this.modelParts = modelParts;
|
this.modelPartMap = modelPartMap;
|
||||||
|
this.modelParts = modelPartMap.values().toArray( new ModelPart[0] );
|
||||||
this.domainType = domainType;
|
this.domainType = domainType;
|
||||||
this.componentName = componentName;
|
this.componentName = componentName;
|
||||||
this.existingModelPartContainer = existingModelPartContainer;
|
this.existingModelPartContainer = existingModelPartContainer;
|
||||||
|
@ -88,12 +91,21 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ModelPart findSubPart(String name, EntityMappingType treatTargetType) {
|
public ModelPart findSubPart(String name, EntityMappingType treatTargetType) {
|
||||||
return modelParts.get( name );
|
return modelPartMap.get( name );
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachSubPart(IndexedConsumer<ModelPart> consumer, EntityMappingType treatTarget) {
|
||||||
|
for ( int i = 0; i < modelParts.length; i++ ) {
|
||||||
|
consumer.accept( i, modelParts[i] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void visitSubParts(Consumer<ModelPart> consumer, EntityMappingType treatTargetType) {
|
public void visitSubParts(Consumer<ModelPart> consumer, EntityMappingType treatTargetType) {
|
||||||
modelParts.values().forEach( consumer );
|
for ( int i = 0; i < modelParts.length; i++ ) {
|
||||||
|
consumer.accept( modelParts[i] );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -148,7 +160,7 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNumberOfAttributeMappings() {
|
public int getNumberOfAttributeMappings() {
|
||||||
return modelParts.size();
|
return modelParts.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -166,6 +178,17 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
throw new UnsupportedOperationException();
|
throw new UnsupportedOperationException();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public <X, Y> int decompose(
|
||||||
|
Object domainValue,
|
||||||
|
int offset,
|
||||||
|
X x,
|
||||||
|
Y y,
|
||||||
|
JdbcValueBiConsumer<X, Y> valueConsumer,
|
||||||
|
SharedSessionContractImplementor session) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object[] getValues(Object instance) {
|
public Object[] getValues(Object instance) {
|
||||||
return existingModelPartContainer.getEmbeddableTypeDescriptor()
|
return existingModelPartContainer.getEmbeddableTypeDescriptor()
|
||||||
|
@ -192,6 +215,11 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
.setValue( instance, value );
|
.setValue( instance, value );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getSelectableIndex(String selectableName) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SelectableMapping getSelectable(int columnIndex) {
|
public SelectableMapping getSelectable(int columnIndex) {
|
||||||
final List<SelectableMapping> results = new ArrayList<>();
|
final List<SelectableMapping> results = new ArrayList<>();
|
||||||
|
@ -199,6 +227,16 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
return results.get( columnIndex );
|
return results.get( columnIndex );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Fetchable getFetchable(int position) {
|
||||||
|
return (Fetchable) modelParts[position];
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public JdbcMapping getJdbcMapping(int index) {
|
||||||
|
return getSelectable( index ).getJdbcMapping();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public List<JdbcMapping> getJdbcMappings() {
|
public List<JdbcMapping> getJdbcMappings() {
|
||||||
final List<JdbcMapping> results = new ArrayList<>();
|
final List<JdbcMapping> results = new ArrayList<>();
|
||||||
|
@ -214,12 +252,22 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
@Override
|
@Override
|
||||||
public int forEachSelectable(int offset, SelectableConsumer consumer) {
|
public int forEachSelectable(int offset, SelectableConsumer consumer) {
|
||||||
int span = 0;
|
int span = 0;
|
||||||
for ( ModelPart mapping : modelParts.values() ) {
|
for ( ModelPart mapping : modelParts ) {
|
||||||
span += mapping.forEachSelectable( offset + span, consumer );
|
span += mapping.forEachSelectable( offset + span, consumer );
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachInsertable(int offset, SelectableConsumer consumer) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void forEachUpdatable(int offset, SelectableConsumer consumer) {
|
||||||
|
throw new UnsupportedOperationException();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getContainingTableExpression() {
|
public String getContainingTableExpression() {
|
||||||
return "";
|
return "";
|
||||||
|
@ -234,7 +282,7 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
final List<ColumnReference> columnReferences = CollectionHelper.arrayList( getJdbcTypeCount() );
|
final List<ColumnReference> columnReferences = CollectionHelper.arrayList( getJdbcTypeCount() );
|
||||||
final NavigablePath navigablePath = tableGroup.getNavigablePath().append( componentName );
|
final NavigablePath navigablePath = tableGroup.getNavigablePath().append( componentName );
|
||||||
final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, getContainingTableExpression() );
|
final TableReference tableReference = tableGroup.resolveTableReference( navigablePath, getContainingTableExpression() );
|
||||||
for ( ModelPart modelPart : modelParts.values() ) {
|
for ( ModelPart modelPart : modelParts ) {
|
||||||
modelPart.forEachSelectable(
|
modelPart.forEachSelectable(
|
||||||
(columnIndex, selection) -> {
|
(columnIndex, selection) -> {
|
||||||
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver()
|
final Expression columnReference = sqlAstCreationState.getSqlExpressionResolver()
|
||||||
|
@ -339,7 +387,7 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int getNumberOfFetchables() {
|
public int getNumberOfFetchables() {
|
||||||
return modelParts.size();
|
return modelParts.length;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -376,7 +424,7 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
NavigablePath navigablePath,
|
NavigablePath navigablePath,
|
||||||
TableGroup tableGroup,
|
TableGroup tableGroup,
|
||||||
DomainResultCreationState creationState) {
|
DomainResultCreationState creationState) {
|
||||||
for ( ModelPart mapping : modelParts.values() ) {
|
for ( ModelPart mapping : modelParts ) {
|
||||||
mapping.applySqlSelections( navigablePath, tableGroup, creationState );
|
mapping.applySqlSelections( navigablePath, tableGroup, creationState );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -387,7 +435,7 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
TableGroup tableGroup,
|
TableGroup tableGroup,
|
||||||
DomainResultCreationState creationState,
|
DomainResultCreationState creationState,
|
||||||
BiConsumer<SqlSelection, JdbcMapping> selectionConsumer) {
|
BiConsumer<SqlSelection, JdbcMapping> selectionConsumer) {
|
||||||
for ( ModelPart mapping : modelParts.values() ) {
|
for ( ModelPart mapping : modelParts ) {
|
||||||
mapping.applySqlSelections( navigablePath, tableGroup, creationState, selectionConsumer );
|
mapping.applySqlSelections( navigablePath, tableGroup, creationState, selectionConsumer );
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -400,27 +448,33 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
Y y,
|
Y y,
|
||||||
JdbcValueBiConsumer<X, Y> valueConsumer,
|
JdbcValueBiConsumer<X, Y> valueConsumer,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
final Object[] values = (Object[]) domainValue;
|
|
||||||
assert values.length == modelParts.size();
|
|
||||||
int span = 0;
|
int span = 0;
|
||||||
int i = 0;
|
if ( domainValue == null ) {
|
||||||
for ( ModelPart mapping : modelParts.values() ) {
|
for ( ModelPart mapping : modelParts ) {
|
||||||
final Object attributeValue = values[ i ];
|
span += mapping.breakDownJdbcValues( null, offset + span, x, y, valueConsumer, session );
|
||||||
span += mapping.breakDownJdbcValues( attributeValue, offset + span, x, y, valueConsumer, session );
|
}
|
||||||
i++;
|
}
|
||||||
|
else {
|
||||||
|
final Object[] values = (Object[]) domainValue;
|
||||||
|
assert values.length == modelParts.length;
|
||||||
|
for ( int i = 0; i < modelParts.length; i++ ) {
|
||||||
|
final Object attributeValue = values[i];
|
||||||
|
span += modelParts[i].breakDownJdbcValues( attributeValue, offset + span, x, y, valueConsumer, session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Object disassemble(Object value, SharedSessionContractImplementor session) {
|
public Object disassemble(Object value, SharedSessionContractImplementor session) {
|
||||||
|
if ( value == null ) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
final Object[] values = (Object[]) value;
|
final Object[] values = (Object[]) value;
|
||||||
final Object[] result = new Object[ modelParts.size() ];
|
final Object[] result = new Object[ modelParts.length ];
|
||||||
int i = 0;
|
for ( int i = 0; i < modelParts.length; i++ ) {
|
||||||
for ( ModelPart mapping : modelParts.values() ) {
|
|
||||||
Object o = values[i];
|
Object o = values[i];
|
||||||
result[i] = mapping.disassemble( o, session );
|
result[i] = modelParts[i].disassemble( o, session );
|
||||||
i++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
@ -428,11 +482,18 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
public void addToCacheKey(MutableCacheKeyBuilder cacheKey, Object value, SharedSessionContractImplementor session) {
|
||||||
final Object[] values = (Object[]) value;
|
if ( value == null ) {
|
||||||
int i = 0;
|
for ( ModelPart mapping : modelParts ) {
|
||||||
for ( ModelPart mapping : modelParts.values() ) {
|
mapping.addToCacheKey( cacheKey, null, session );
|
||||||
mapping.addToCacheKey( cacheKey, values[i], session );
|
}
|
||||||
i++;
|
}
|
||||||
|
else {
|
||||||
|
final Object[] values = (Object[]) value;
|
||||||
|
int i = 0;
|
||||||
|
for ( ModelPart mapping : modelParts ) {
|
||||||
|
mapping.addToCacheKey( cacheKey, values[i], session );
|
||||||
|
i++;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -444,12 +505,17 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
Y y,
|
Y y,
|
||||||
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
JdbcValuesBiConsumer<X, Y> valuesConsumer,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
final Object[] values = (Object[]) value;
|
|
||||||
int span = 0;
|
int span = 0;
|
||||||
int i = 0;
|
if ( value == null ) {
|
||||||
for ( ModelPart mapping : modelParts.values() ) {
|
for ( ModelPart mapping : modelParts ) {
|
||||||
span += mapping.forEachDisassembledJdbcValue( values[i], span + offset, x, y, valuesConsumer, session );
|
span += mapping.forEachDisassembledJdbcValue( null, span + offset, x, y, valuesConsumer, session );
|
||||||
i++;
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
final Object[] values = (Object[]) value;
|
||||||
|
for ( int i = 0; i < modelParts.length; i++ ) {
|
||||||
|
span += modelParts[i].forEachDisassembledJdbcValue( values[i], span + offset, x, y, valuesConsumer, session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
@ -462,13 +528,18 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
Y y,
|
Y y,
|
||||||
JdbcValuesBiConsumer<X, Y> consumer,
|
JdbcValuesBiConsumer<X, Y> consumer,
|
||||||
SharedSessionContractImplementor session) {
|
SharedSessionContractImplementor session) {
|
||||||
final Object[] values = (Object[]) value;
|
|
||||||
int span = 0;
|
int span = 0;
|
||||||
int i = 0;
|
if ( value == null ) {
|
||||||
for ( ModelPart attributeMapping : modelParts.values() ) {
|
for ( ModelPart mapping : modelParts ) {
|
||||||
final Object o = values[i];
|
span += mapping.forEachJdbcValue( null, span + offset, x, y, consumer, session );
|
||||||
span += attributeMapping.forEachJdbcValue( o, span + offset, x, y, consumer, session );
|
}
|
||||||
i++;
|
}
|
||||||
|
else {
|
||||||
|
final Object[] values = (Object[]) value;
|
||||||
|
for ( int i = 0; i < modelParts.length; i++ ) {
|
||||||
|
final Object o = values[i];
|
||||||
|
span += modelParts[i].forEachJdbcValue( o, span + offset, x, y, consumer, session );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
}
|
}
|
||||||
|
@ -476,7 +547,7 @@ public class AnonymousTupleEmbeddableValuedModelPart implements EmbeddableValued
|
||||||
@Override
|
@Override
|
||||||
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
|
public int forEachJdbcType(int offset, IndexedConsumer<JdbcMapping> action) {
|
||||||
int span = 0;
|
int span = 0;
|
||||||
for ( ModelPart attributeMapping : modelParts.values() ) {
|
for ( ModelPart attributeMapping : modelParts ) {
|
||||||
span += attributeMapping.forEachJdbcType( span + offset, action );
|
span += attributeMapping.forEachJdbcType( span + offset, action );
|
||||||
}
|
}
|
||||||
return span;
|
return span;
|
||||||
|
|
Loading…
Reference in New Issue