HHH-4881: Keep track of the actual value used for the discriminator

This commit is contained in:
James Gilbertson 2011-10-07 20:08:09 -06:00 committed by Strong Liu
parent 81ad5c0eff
commit 11ef3e0765
4 changed files with 23 additions and 4 deletions

View File

@ -109,6 +109,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
private final String[] constraintOrderedTableNames;
private final String[][] constraintOrderedKeyColumnNames;
private final Object discriminatorValue;
private final String discriminatorSQLString;
// Span of the tables directly mapped by this entity and super-classes, if any
@ -128,7 +129,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
// DISCRIMINATOR
final Object discriminatorValue;
if ( persistentClass.isPolymorphic() ) {
try {
discriminatorValue = new Integer( persistentClass.getSubclassId() );
@ -537,6 +537,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
notNullColumnTableNumbers = null;
constraintOrderedTableNames = null;
constraintOrderedKeyColumnNames = null;
discriminatorValue = null;
discriminatorSQLString = null;
coreTableSpan = -1;
isNullableTable = null;
@ -567,11 +568,14 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
return StandardBasicTypes.INTEGER;
}
public Object getDiscriminatorValue() {
return discriminatorValue;
}
public String getDiscriminatorSQLValue() {
return discriminatorSQLString;
}
public String getSubclassForDiscriminatorValue(Object value) {
return (String) subclassesByDiscriminatorValue.get( value );
}

View File

@ -51,6 +51,11 @@ public interface Loadable extends EntityPersister {
*/
public Type getDiscriminatorType();
/**
* Get the discriminator value
*/
public Object getDiscriminatorValue();
/**
* Get the concrete subclass corresponding to the given discriminator
* value

View File

@ -114,6 +114,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
private final String discriminatorFormulaTemplate;
private final String discriminatorAlias;
private final Type discriminatorType;
private final Object discriminatorValue;
private final String discriminatorSQLValue;
private final boolean discriminatorInsertable;
@ -292,7 +293,6 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
// DISCRIMINATOR
final Object discriminatorValue;
if ( persistentClass.isPolymorphic() ) {
Value discrimValue = persistentClass.getDiscriminator();
if (discrimValue==null) {
@ -536,7 +536,6 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
// DISCRIMINATOR
final Object discriminatorValue;
if ( entityBinding.isPolymorphic() ) {
SimpleValue discriminatorRelationalValue = entityBinding.getHierarchyDetails().getEntityDiscriminator().getBoundValue();
if ( discriminatorRelationalValue == null ) {
@ -758,6 +757,10 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
return discriminatorType;
}
public Object getDiscriminatorValue() {
return discriminatorValue;
}
public String getDiscriminatorSQLValue() {
return discriminatorSQLValue;
}

View File

@ -70,6 +70,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
private final String[] subclassClosure;
private final String[] spaces;
private final String[] subclassSpaces;
private final Object discriminatorValue;
private final String discriminatorSQLValue;
private final Map subclassByDiscriminatorValue = new HashMap();
@ -144,6 +145,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
deleteCallable = new boolean[] { callable };
deleteResultCheckStyles = new ExecuteUpdateResultCheckStyle[] { checkStyle };
discriminatorValue = new Integer( persistentClass.getSubclassId() );
discriminatorSQLValue = String.valueOf( persistentClass.getSubclassId() );
// PROPERTIES
@ -248,6 +250,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
subclassClosure = null;
spaces = null;
subclassSpaces = null;
discriminatorValue = null;
discriminatorSQLValue = null;
constraintOrderedTableNames = null;
constraintOrderedKeyColumnNames = null;
@ -265,6 +268,10 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
return StandardBasicTypes.INTEGER;
}
public Object getDiscriminatorValue() {
return discriminatorValue;
}
public String getDiscriminatorSQLValue() {
return discriminatorSQLValue;
}