Resolved issue with DependandValue resolution

This commit is contained in:
Andrea Boriero 2020-07-17 10:23:44 +01:00 committed by Steve Ebersole
parent cb2a2bbd58
commit 26339598a5
4 changed files with 50 additions and 6 deletions

View File

@ -50,7 +50,7 @@
* @author Steve Ebersole * @author Steve Ebersole
*/ */
@SuppressWarnings({"unchecked", "rawtypes"}) @SuppressWarnings({"unchecked", "rawtypes"})
public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicators { public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicators, Resolvable {
private static final CoreMessageLogger log = CoreLogging.messageLogger( BasicValue.class ); private static final CoreMessageLogger log = CoreLogging.messageLogger( BasicValue.class );
private final MetadataBuildingContext buildingContext; private final MetadataBuildingContext buildingContext;
@ -245,11 +245,13 @@ public Resolution<?> getResolution() {
return resolution; return resolution;
} }
@Override
public boolean resolve(MetadataBuildingContext buildingContext) { public boolean resolve(MetadataBuildingContext buildingContext) {
resolve(); resolve();
return true; return true;
} }
@Override
public Resolution<?> resolve() { public Resolution<?> resolve() {
if ( resolution != null ) { if ( resolution != null ) {
return resolution; return resolution;

View File

@ -17,7 +17,7 @@
* *
* @author Gavin King * @author Gavin King
*/ */
public class DependantValue extends SimpleValue { public class DependantValue extends SimpleValue implements Resolvable {
private KeyValue wrappedValue; private KeyValue wrappedValue;
private boolean nullable; private boolean nullable;
private boolean updateable; private boolean updateable;
@ -31,12 +31,15 @@ public Type getType() throws MappingException {
return wrappedValue.getType(); return wrappedValue.getType();
} }
@Override
public void setTypeUsingReflection(String className, String propertyName) {} public void setTypeUsingReflection(String className, String propertyName) {}
@Override
public Object accept(ValueVisitor visitor) { public Object accept(ValueVisitor visitor) {
return visitor.accept(this); return visitor.accept(this);
} }
@Override
public boolean isNullable() { public boolean isNullable() {
return nullable; return nullable;
@ -45,7 +48,8 @@ public boolean isNullable() {
public void setNullable(boolean nullable) { public void setNullable(boolean nullable) {
this.nullable = nullable; this.nullable = nullable;
} }
@Override
public boolean isUpdateable() { public boolean isUpdateable() {
return updateable; return updateable;
} }
@ -64,4 +68,19 @@ public boolean isSame(DependantValue other) {
&& isSame( wrappedValue, other.wrappedValue ); && isSame( wrappedValue, other.wrappedValue );
} }
@Override
public boolean resolve(MetadataBuildingContext buildingContext) {
resolve();
return true;
}
@Override
public BasicValue.Resolution<?> resolve() {
if ( wrappedValue instanceof BasicValue ) {
return ( (BasicValue) wrappedValue ).resolve();
}
// not sure it is ever possible
throw new UnsupportedOperationException("Trying to resolve the wrapped value but it is non a BasicValue");
}
} }

View File

@ -0,0 +1,20 @@
/*
* Hibernate, Relational Persistence for Idiomatic Java
*
* License: GNU Lesser General Public License (LGPL), version 2.1 or later.
* See the lgpl.txt file in the root directory or <http://www.gnu.org/licenses/lgpl-2.1.html>.
*/
package org.hibernate.mapping;
import org.hibernate.boot.spi.MetadataBuildingContext;
/**
* @author Andrea Boriero
*/
public interface Resolvable {
boolean resolve(MetadataBuildingContext buildingContext);
BasicValue.Resolution<?> resolve();
}

View File

@ -36,12 +36,14 @@
import org.hibernate.mapping.BasicValue; import org.hibernate.mapping.BasicValue;
import org.hibernate.mapping.Collection; import org.hibernate.mapping.Collection;
import org.hibernate.mapping.Component; import org.hibernate.mapping.Component;
import org.hibernate.mapping.DependantValue;
import org.hibernate.mapping.IndexedCollection; import org.hibernate.mapping.IndexedCollection;
import org.hibernate.mapping.KeyValue; import org.hibernate.mapping.KeyValue;
import org.hibernate.mapping.OneToMany; import org.hibernate.mapping.OneToMany;
import org.hibernate.mapping.OneToOne; import org.hibernate.mapping.OneToOne;
import org.hibernate.mapping.PersistentClass; import org.hibernate.mapping.PersistentClass;
import org.hibernate.mapping.Property; import org.hibernate.mapping.Property;
import org.hibernate.mapping.Resolvable;
import org.hibernate.mapping.Selectable; import org.hibernate.mapping.Selectable;
import org.hibernate.mapping.Table; import org.hibernate.mapping.Table;
import org.hibernate.mapping.ToOne; import org.hibernate.mapping.ToOne;
@ -277,13 +279,14 @@ public static BasicValuedSingularAttributeMapping buildBasicAttributeMapping(
PropertyAccess propertyAccess, PropertyAccess propertyAccess,
CascadeStyle cascadeStyle, CascadeStyle cascadeStyle,
MappingModelCreationProcess creationProcess) { MappingModelCreationProcess creationProcess) {
final BasicValue.Resolution<?> resolution = ( (BasicValue) bootProperty.getValue() ).resolve(); final Value value = bootProperty.getValue();
final BasicValue.Resolution<?> resolution = ( (Resolvable) value ).resolve();
final BasicValueConverter valueConverter = resolution.getValueConverter(); final BasicValueConverter valueConverter = resolution.getValueConverter();
final StateArrayContributorMetadataAccess attributeMetadataAccess = entityMappingType -> new StateArrayContributorMetadata() { final StateArrayContributorMetadataAccess attributeMetadataAccess = entityMappingType -> new StateArrayContributorMetadata() {
private final MutabilityPlan mutabilityPlan = resolution.getMutabilityPlan(); private final MutabilityPlan mutabilityPlan = resolution.getMutabilityPlan();
private final boolean nullable = bootProperty.getValue().isNullable(); private final boolean nullable = value.isNullable();
private final boolean insertable = bootProperty.isInsertable(); private final boolean insertable = bootProperty.isInsertable();
private final boolean updateable = bootProperty.isUpdateable(); private final boolean updateable = bootProperty.isUpdateable();
private final boolean includeInOptimisticLocking = bootProperty.isOptimisticLocked(); private final boolean includeInOptimisticLocking = bootProperty.isOptimisticLocked();