HHH-6485 Add support for @DiscriminatorFormula
This commit is contained in:
parent
236ba1d247
commit
ec89e8674d
|
@ -0,0 +1,24 @@
|
|||
package org.hibernate.metamodel.source.annotations.attribute;
|
||||
|
||||
import org.hibernate.metamodel.source.binder.DerivedValueSource;
|
||||
|
||||
/**
|
||||
* @author Strong Liu
|
||||
*/
|
||||
public class DerivedValueSourceImpl implements DerivedValueSource {
|
||||
private final FormulaValue formulaValue;
|
||||
|
||||
DerivedValueSourceImpl(FormulaValue formulaValue) {
|
||||
this.formulaValue = formulaValue;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpression() {
|
||||
return formulaValue.getExpression();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContainingTableName() {
|
||||
return formulaValue.getContainingTableName();
|
||||
}
|
||||
}
|
|
@ -49,9 +49,9 @@ public class DiscriminatorSourceImpl implements DiscriminatorSource {
|
|||
|
||||
@Override
|
||||
public RelationalValueSource getDiscriminatorRelationalValueSource() {
|
||||
return entityClass.getDiscriminatorFormula() != null ? entityClass.getDiscriminatorFormula() : new ColumnValuesSourceImpl(
|
||||
entityClass.getDiscriminatorColumnValues()
|
||||
);
|
||||
return entityClass.getDiscriminatorFormula() != null ?
|
||||
new DerivedValueSourceImpl( entityClass.getDiscriminatorFormula() )
|
||||
: new ColumnValuesSourceImpl( entityClass.getDiscriminatorColumnValues() );
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -0,0 +1,22 @@
|
|||
package org.hibernate.metamodel.source.annotations.attribute;
|
||||
|
||||
/**
|
||||
* @author Strong Liu
|
||||
*/
|
||||
public class FormulaValue {
|
||||
private String tableName;
|
||||
private final String expression;
|
||||
|
||||
public FormulaValue(String tableName, String expression) {
|
||||
this.tableName = tableName;
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
public String getContainingTableName() {
|
||||
return tableName;
|
||||
}
|
||||
}
|
|
@ -49,12 +49,13 @@ import org.hibernate.internal.util.StringHelper;
|
|||
import org.hibernate.metamodel.binding.Caching;
|
||||
import org.hibernate.metamodel.binding.CustomSQL;
|
||||
import org.hibernate.metamodel.binding.InheritanceType;
|
||||
import org.hibernate.metamodel.relational.Identifier;
|
||||
import org.hibernate.metamodel.source.annotations.AnnotationBindingContext;
|
||||
import org.hibernate.metamodel.source.annotations.HibernateDotNames;
|
||||
import org.hibernate.metamodel.source.annotations.JPADotNames;
|
||||
import org.hibernate.metamodel.source.annotations.JandexHelper;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.ColumnValues;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.DerivedValueSourceImpl;
|
||||
import org.hibernate.metamodel.source.annotations.attribute.FormulaValue;
|
||||
import org.hibernate.metamodel.source.binder.ConstraintSource;
|
||||
import org.hibernate.metamodel.source.binder.DerivedValueSource;
|
||||
import org.hibernate.metamodel.source.binder.TableSource;
|
||||
|
@ -97,7 +98,7 @@ public class EntityClass extends ConfiguredClass {
|
|||
private String proxy;
|
||||
|
||||
private ColumnValues discriminatorColumnValues;
|
||||
private DerivedValueSource discriminatorFormula;
|
||||
private FormulaValue discriminatorFormula;
|
||||
private Class<?> discriminatorType;
|
||||
private String discriminatorMatchValue;
|
||||
private boolean isDiscriminatorForced = true;
|
||||
|
@ -146,7 +147,7 @@ public class EntityClass extends ConfiguredClass {
|
|||
return discriminatorColumnValues;
|
||||
}
|
||||
|
||||
public DerivedValueSource getDiscriminatorFormula() {
|
||||
public FormulaValue getDiscriminatorFormula() {
|
||||
return discriminatorFormula;
|
||||
}
|
||||
|
||||
|
@ -355,7 +356,7 @@ public class EntityClass extends ConfiguredClass {
|
|||
Class<?> type = String.class; // string is the discriminator default
|
||||
if ( discriminatorFormulaAnnotation != null ) {
|
||||
String expression = JandexHelper.getValue( discriminatorFormulaAnnotation, "value", String.class );
|
||||
discriminatorFormula = new FormulaImpl( getPrimaryTableSource().getExplicitTableName(), expression );
|
||||
discriminatorFormula = new FormulaValue( getPrimaryTableSource().getExplicitTableName(), expression );
|
||||
}
|
||||
discriminatorColumnValues = new ColumnValues( null ); //(stliu) give null here, will populate values below
|
||||
discriminatorColumnValues.setNullable( false ); // discriminator column cannot be null
|
||||
|
|
|
@ -1,26 +0,0 @@
|
|||
package org.hibernate.metamodel.source.annotations.entity;
|
||||
|
||||
import org.hibernate.metamodel.source.binder.DerivedValueSource;
|
||||
|
||||
/**
|
||||
* @author Strong Liu
|
||||
*/
|
||||
public class FormulaImpl implements DerivedValueSource{
|
||||
private String tableName;
|
||||
private final String expression;
|
||||
|
||||
FormulaImpl(String tableName, String expression) {
|
||||
this.tableName = tableName;
|
||||
this.expression = expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getExpression() {
|
||||
return expression;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getContainingTableName() {
|
||||
return tableName;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue