Clean up BasicValue

This commit is contained in:
Andrea Boriero 2021-03-08 11:54:42 +01:00
parent b225beb3cc
commit 47f7ca7ff5
2 changed files with 34 additions and 52 deletions

View File

@ -53,7 +53,6 @@ import org.hibernate.type.spi.TypeConfiguration;
public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicators, Resolvable {
private static final CoreMessageLogger log = CoreLogging.messageLogger( BasicValue.class );
private final MetadataBuildingContext buildingContext;
private final TypeConfiguration typeConfiguration;
private final int preferredJdbcTypeCodeForBoolean;
@ -68,20 +67,14 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
private Function<TypeConfiguration,MutabilityPlan> explicitMutabilityPlanAccess;
private Function<TypeConfiguration,Class> implicitJavaTypeAccess;
private boolean isNationalized;
private boolean isLob;
private EnumType enumerationStyle;
private TemporalType temporalPrecision;
private ConverterDescriptor attributeConverterDescriptor;
private Class resolvedJavaClass;
private String ownerName;
private String propertyName;
private Selectable column;
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Resolved state - available after `#resolve`
private Resolution<?> resolution;
@ -94,23 +87,12 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
public BasicValue(MetadataBuildingContext buildingContext, Table table) {
super( buildingContext, table );
this.buildingContext = buildingContext;
this.typeConfiguration = buildingContext.getBootstrapContext().getTypeConfiguration();
this.preferredJdbcTypeCodeForBoolean = buildingContext.getPreferredSqlTypeCodeForBoolean();
buildingContext.getMetadataCollector().registerValueMappingResolver( this::resolve );
}
public MetadataBuildingContext getBuildingContext() {
return buildingContext;
}
@Override
public ServiceRegistry getServiceRegistry() {
return buildingContext.getBootstrapContext().getServiceRegistry();
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
// Setters - in preparation of resolution
@ -136,12 +118,9 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
return enumerationStyle;
}
public ConverterDescriptor getJpaAttributeConverterDescriptor() {
return attributeConverterDescriptor;
}
public void setJpaAttributeConverterDescriptor(ConverterDescriptor descriptor) {
this.attributeConverterDescriptor = descriptor;
setAttributeConverterDescriptor( descriptor );
super.setJpaAttributeConverterDescriptor( descriptor );
}
@ -164,7 +143,10 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
}
public Selectable getColumn() {
return column;
if ( getColumnSpan() == 0 ) {
return null;
}
return getColumn( 0 );
}
public Class getResolvedJavaClass() {
@ -173,6 +155,7 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
@Override
public long getColumnLength() {
final Selectable column = getColumn();
if ( column != null && column instanceof Column ) {
final Long length = ( (Column) column ).getLength();
return length == null ? NO_COLUMN_LENGTH : length;
@ -186,7 +169,7 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
public void addColumn(Column incomingColumn) {
super.addColumn( incomingColumn );
applySelectable( incomingColumn );
checkSelectable( incomingColumn );
}
@Override
@ -199,39 +182,38 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
}
}
private void applySelectable(Selectable incomingColumn) {
private void checkSelectable(Selectable incomingColumn) {
if ( incomingColumn == null ) {
throw new IllegalArgumentException( "Incoming column was null" );
}
if ( this.column == incomingColumn ) {
final Selectable column = getColumn();
if ( column == incomingColumn ) {
log.debugf( "Skipping column re-registration: %s.%s", getTable().getName(), column.getText() );
return;
}
if ( this.column != null ) {
if ( column != null ) {
throw new IllegalStateException(
"BasicValue [" + ownerName + "." + propertyName +
"] already had column associated: `" + this.column.getText() +
"] already had column associated: `" + column.getText() +
"` -> `" + incomingColumn.getText() + "`"
);
}
this.column = incomingColumn;
}
@Override
public void addColumn(Column incomingColumn, boolean isInsertable, boolean isUpdatable) {
super.addColumn( incomingColumn, isInsertable, isUpdatable );
applySelectable( incomingColumn );
checkSelectable( incomingColumn );
}
@Override
public void addFormula(Formula formula) {
super.addFormula( formula );
applySelectable( formula );
checkSelectable( formula );
}
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
@ -267,6 +249,7 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
throw new IllegalStateException( "Unable to resolve BasicValue : " + this );
}
final Selectable column = getColumn();
if ( column instanceof Column && resolution.getValueConverter() == null ) {
final Column physicalColumn = (Column) column;
if ( physicalColumn.getSqlTypeCode() == null ) {
@ -299,7 +282,7 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
explicitJavaTypeAccess,
explicitSqlTypeAccess,
explicitMutabilityPlanAccess,
attributeConverterDescriptor,
getAttributeConverterDescriptor(),
explicitLocalTypeParams,
this,
typeConfiguration,
@ -319,6 +302,7 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
}
final ConverterDescriptor attributeConverterDescriptor = getAttributeConverterDescriptor();
if ( attributeConverterDescriptor != null ) {
final ManagedBeanRegistry managedBeanRegistry = getBuildingContext().getBootstrapContext()
.getServiceRegistry()
@ -410,7 +394,7 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
this::determineReflectedJavaTypeDescriptor,
this,
getTable(),
column,
getColumn(),
ownerName,
propertyName,
typeConfiguration
@ -582,13 +566,6 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
return getEnumerationStyle();
}
public boolean isNationalized() {
return isNationalized;
}
public boolean isLob() {
return isLob;
}
@Override
public int getPreferredSqlTypeCodeForBoolean() {
@ -620,11 +597,11 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
try {
//noinspection rawtypes
final Class<AttributeConverter> converterClass = cls.classForName( converterClassName );
attributeConverterDescriptor = new ClassBasedConverterDescriptor(
setAttributeConverterDescriptor( new ClassBasedConverterDescriptor(
converterClass,
false,
getBuildingContext().getBootstrapContext().getClassmateContext()
);
) );
return;
}
catch (Exception e) {
@ -648,14 +625,6 @@ public class BasicValue extends SimpleValue implements SqlTypeDescriptorIndicato
return temporalPrecision;
}
public void makeLob() {
this.isLob = true;
}
public void makeNationalized() {
this.isNationalized = true;
}
/**
* Resolved form of {@link BasicValue} as part of interpreting the
* boot-time model into the run-time model

View File

@ -179,6 +179,10 @@ public abstract class SimpleValue implements KeyValue {
return columns.size();
}
protected Selectable getColumn(int position){
return columns.get( position );
}
@Override
public Iterator<Selectable> getColumnIterator() {
return columns.iterator();
@ -223,6 +227,7 @@ public abstract class SimpleValue implements KeyValue {
public boolean isVersion() {
return isVersion;
}
public void makeNationalized() {
this.isNationalized = true;
}
@ -465,7 +470,15 @@ public abstract class SimpleValue implements KeyValue {
return getColumnSpan() == getType().getColumnSpan( mapping );
}
// public Type getType() throws MappingException {
protected void setAttributeConverterDescriptor(ConverterDescriptor descriptor) {
this.attributeConverterDescriptor = descriptor;
}
protected ConverterDescriptor getAttributeConverterDescriptor() {
return attributeConverterDescriptor;
}
// public Type getType() throws MappingException {
// if ( type != null ) {
// return type;
// }