remove a bunch of unused junk from the persisters

this is a potential performance gain!
This commit is contained in:
Gavin King 2022-01-29 15:14:32 +01:00
parent 929cbd1139
commit 56232a0159
4 changed files with 185 additions and 403 deletions

View File

@ -45,7 +45,6 @@ import org.hibernate.QueryException;
import org.hibernate.Session;
import org.hibernate.StaleObjectStateException;
import org.hibernate.StaleStateException;
import org.hibernate.boot.spi.MetadataImplementor;
import org.hibernate.boot.spi.SessionFactoryOptions;
import org.hibernate.bytecode.enhance.spi.LazyPropertyInitializer;
import org.hibernate.bytecode.enhance.spi.interceptor.BytecodeLazyAttributeInterceptor;
@ -325,15 +324,15 @@ public abstract class AbstractEntityPersister
//including inherited properties
//(only really needed for updatable/insertable properties)
private final int[] propertyColumnSpans;
private final String[] propertySubclassNames;
// private final String[] propertySubclassNames;
private final String[][] propertyColumnAliases;
private final String[][] propertyColumnNames;
private final String[][] propertyColumnFormulaTemplates;
private final String[][] propertyColumnReaderTemplates;
// private final String[][] propertyColumnReaderTemplates;
private final String[][] propertyColumnWriters;
private final boolean[][] propertyColumnUpdateable;
private final boolean[][] propertyColumnInsertable;
private final boolean[] propertyUniqueness;
// private final boolean[] propertyUniqueness;
private final boolean[] propertySelectable;
private final List<Integer> lobProperties;
@ -346,7 +345,7 @@ public abstract class AbstractEntityPersister
//information about all properties in class hierarchy
private final String[] subclassPropertyNameClosure;
private final String[] subclassPropertySubclassNameClosure;
// private final String[] subclassPropertySubclassNameClosure;
private final Type[] subclassPropertyTypeClosure;
private final String[][] subclassPropertyFormulaTemplateClosure;
private final String[][] subclassPropertyColumnNameClosure;
@ -355,20 +354,20 @@ public abstract class AbstractEntityPersister
private final FetchMode[] subclassPropertyFetchModeClosure;
private final boolean[] subclassPropertyNullabilityClosure;
private final boolean[] propertyDefinedOnSubclass;
private final int[][] subclassPropertyColumnNumberClosure;
private final int[][] subclassPropertyFormulaNumberClosure;
// private final int[][] subclassPropertyColumnNumberClosure;
// private final int[][] subclassPropertyFormulaNumberClosure;
private final CascadeStyle[] subclassPropertyCascadeStyleClosure;
//information about all columns/formulas in class hierarchy
private final String[] subclassColumnClosure;
private final boolean[] subclassColumnLazyClosure;
private final String[] subclassColumnClosure; //only used by JoinedSubclassEntityPersister! TODO: MOVE IT DOWN!
// private final boolean[] subclassColumnLazyClosure;
private final String[] subclassColumnAliasClosure;
private final boolean[] subclassColumnSelectableClosure;
private final String[] subclassColumnReaderTemplateClosure;
private final String[] subclassFormulaClosure;
private final String[] subclassFormulaTemplateClosure;
// private final String[] subclassColumnReaderTemplateClosure;
// private final String[] subclassFormulaClosure;
// private final String[] subclassFormulaTemplateClosure;
private final String[] subclassFormulaAliasClosure;
private final boolean[] subclassFormulaLazyClosure;
// private final boolean[] subclassFormulaLazyClosure;
// dynamic filters attached to the class-level
private final FilterHelper filterHelper;
@ -426,10 +425,6 @@ public abstract class AbstractEntityPersister
protected void addDiscriminatorToInsert(Insert insert) {
}
protected abstract int[] getSubclassColumnTableNumberClosure();
protected abstract int[] getSubclassFormulaTableNumberClosure();
@Override
public abstract String getSubclassTableName(int j);
@ -469,8 +464,6 @@ public abstract class AbstractEntityPersister
public abstract boolean isPropertyOfTable(int property, int j);
protected abstract int[] getPropertyTableNumbersInSelect();
protected abstract int[] getPropertyTableNumbers();
protected abstract int getSubclassPropertyTableNumber(int i);
@ -524,7 +517,7 @@ public abstract class AbstractEntityPersister
return entityMetamodel.getSubclassEntityNames().contains( entityName );
}
private boolean[] getTableHasColumns() {
protected boolean[] getTableHasColumns() {
return tableHasColumns;
}
@ -553,12 +546,7 @@ public abstract class AbstractEntityPersister
return result;
}
public String getSQLLazySelectString(String fetchGroup) {
final SingleIdArrayLoadPlan singleIdLoadPlan = sqlLazySelectStringsByFetchGroup.get( fetchGroup );
return singleIdLoadPlan == null ? null : singleIdLoadPlan.getJdbcSelect().getSql();
}
public SingleIdArrayLoadPlan getSQLLazySelectLoadPlan(String fetchGroup) {
SingleIdArrayLoadPlan getSQLLazySelectLoadPlan(String fetchGroup) {
return sqlLazySelectStringsByFetchGroup.get( fetchGroup );
}
@ -578,15 +566,15 @@ public abstract class AbstractEntityPersister
return sqlLazyUpdateStrings;
}
public ExecuteUpdateResultCheckStyle[] getInsertResultCheckStyles() {
protected ExecuteUpdateResultCheckStyle[] getInsertResultCheckStyles() {
return insertResultCheckStyles;
}
public ExecuteUpdateResultCheckStyle[] getUpdateResultCheckStyles() {
protected ExecuteUpdateResultCheckStyle[] getUpdateResultCheckStyles() {
return updateResultCheckStyles;
}
public ExecuteUpdateResultCheckStyle[] getDeleteResultCheckStyles() {
protected ExecuteUpdateResultCheckStyle[] getDeleteResultCheckStyles() {
return deleteResultCheckStyles;
}
@ -665,18 +653,18 @@ public abstract class AbstractEntityPersister
return rowIdName != null;
}
//used by Hibernate Reactive
@SuppressWarnings("unused")
public boolean[][] getPropertyColumnUpdateable() {
return propertyColumnUpdateable;
}
//used by Hibernate Reactive
@SuppressWarnings("unused")
public boolean[][] getPropertyColumnInsertable() {
return propertyColumnInsertable;
}
public boolean[] getPropertySelectable() {
return propertySelectable;
}
public String[] getTableNames() {
String[] tableNames = new String[getTableSpan()];
for ( int i = 0; i < tableNames.length; i++ ) {
@ -685,7 +673,6 @@ public abstract class AbstractEntityPersister
return tableNames;
}
@SuppressWarnings("UnnecessaryBoxing")
public AbstractEntityPersister(
final PersistentClass bootDescriptor,
final EntityDataAccess cacheAccessStrategy,
@ -823,13 +810,13 @@ public abstract class AbstractEntityPersister
int hydrateSpan = entityMetamodel.getPropertySpan();
propertyColumnSpans = new int[hydrateSpan];
propertySubclassNames = new String[hydrateSpan];
// propertySubclassNames = new String[hydrateSpan];
propertyColumnAliases = new String[hydrateSpan][];
propertyColumnNames = new String[hydrateSpan][];
propertyColumnFormulaTemplates = new String[hydrateSpan][];
propertyColumnReaderTemplates = new String[hydrateSpan][];
// propertyColumnReaderTemplates = new String[hydrateSpan][];
propertyColumnWriters = new String[hydrateSpan][];
propertyUniqueness = new boolean[hydrateSpan];
// propertyUniqueness = new boolean[hydrateSpan];
propertySelectable = new boolean[hydrateSpan];
propertyColumnUpdateable = new boolean[hydrateSpan][];
propertyColumnInsertable = new boolean[hydrateSpan][];
@ -848,10 +835,10 @@ public abstract class AbstractEntityPersister
int span = prop.getColumnSpan();
propertyColumnSpans[i] = span;
propertySubclassNames[i] = prop.getPersistentClass().getEntityName();
// propertySubclassNames[i] = prop.getPersistentClass().getEntityName();
String[] colNames = new String[span];
String[] colAliases = new String[span];
String[] colReaderTemplates = new String[span];
// String[] colReaderTemplates = new String[span];
String[] colWriters = new String[span];
String[] formulaTemplates = new String[span];
int k = 0;
@ -865,23 +852,23 @@ public abstract class AbstractEntityPersister
else {
Column col = (Column) selectable;
colNames[k] = col.getQuotedName( dialect );
colReaderTemplates[k] = col.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
// colReaderTemplates[k] = col.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
colWriters[k] = col.getWriteExpr();
}
k++;
}
propertyColumnNames[i] = colNames;
propertyColumnFormulaTemplates[i] = formulaTemplates;
propertyColumnReaderTemplates[i] = colReaderTemplates;
// propertyColumnReaderTemplates[i] = colReaderTemplates;
propertyColumnWriters[i] = colWriters;
propertyColumnAliases[i] = colAliases;
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
prop,
entityMetamodel.isInstrumented(),
(entityName) -> {
final MetadataImplementor metadata = creationContext.getMetadata();
final PersistentClass entityBinding = metadata.getEntityBinding( entityName );
entityName -> {
final PersistentClass entityBinding =
creationContext.getMetadata().getEntityBinding( entityName );
assert entityBinding != null;
return entityBinding.hasSubclasses();
},
@ -900,7 +887,7 @@ public abstract class AbstractEntityPersister
propertySelectable[i] = prop.isSelectable();
propertyUniqueness[i] = prop.getValue().isAlternateUniqueKey();
// propertyUniqueness[i] = prop.getValue().isAlternateUniqueKey();
if ( prop.isLob() && dialect.forceLobAsLastValue() ) {
lobPropertiesLocalCollector.add( i );
@ -919,16 +906,16 @@ public abstract class AbstractEntityPersister
// SUBCLASS PROPERTY CLOSURE
ArrayList<String> columns = new ArrayList<>();
ArrayList<Boolean> columnsLazy = new ArrayList<>();
ArrayList<String> columnReaderTemplates = new ArrayList<>();
// ArrayList<Boolean> columnsLazy = new ArrayList<>();
// ArrayList<String> columnReaderTemplates = new ArrayList<>();
ArrayList<String> aliases = new ArrayList<>();
ArrayList<String> formulas = new ArrayList<>();
// ArrayList<String> formulas = new ArrayList<>();
ArrayList<String> formulaAliases = new ArrayList<>();
ArrayList<String> formulaTemplates = new ArrayList<>();
ArrayList<Boolean> formulasLazy = new ArrayList<>();
// ArrayList<String> formulaTemplates = new ArrayList<>();
// ArrayList<Boolean> formulasLazy = new ArrayList<>();
ArrayList<Type> types = new ArrayList<>();
ArrayList<String> names = new ArrayList<>();
ArrayList<String> classes = new ArrayList<>();
// ArrayList<String> classes = new ArrayList<>();
ArrayList<String[]> templates = new ArrayList<>();
ArrayList<String[]> propColumns = new ArrayList<>();
ArrayList<String[]> propColumnReaders = new ArrayList<>();
@ -936,65 +923,65 @@ public abstract class AbstractEntityPersister
ArrayList<FetchMode> joinedFetchesList = new ArrayList<>();
ArrayList<CascadeStyle> cascades = new ArrayList<>();
ArrayList<Boolean> definedBySubclass = new ArrayList<>();
ArrayList<int[]> propColumnNumbers = new ArrayList<>();
ArrayList<int[]> propFormulaNumbers = new ArrayList<>();
// ArrayList<int[]> propColumnNumbers = new ArrayList<>();
// ArrayList<int[]> propFormulaNumbers = new ArrayList<>();
ArrayList<Boolean> columnSelectables = new ArrayList<>();
ArrayList<Boolean> propNullables = new ArrayList<>();
for ( Property prop : bootDescriptor.getSubclassPropertyClosure() ) {
names.add( prop.getName() );
classes.add( prop.getPersistentClass().getEntityName() );
// classes.add( prop.getPersistentClass().getEntityName() );
types.add( prop.getType() );
final boolean isDefinedBySubclass = !thisClassProperties.contains( prop );
definedBySubclass.add( Boolean.valueOf( isDefinedBySubclass ) );
propNullables.add( Boolean.valueOf( prop.isOptional() || isDefinedBySubclass ) ); //TODO: is this completely correct?
definedBySubclass.add( isDefinedBySubclass );
propNullables.add( prop.isOptional() || isDefinedBySubclass ); //TODO: is this completely correct?
String[] cols = new String[ prop.getColumnSpan() ];
String[] readers = new String[ prop.getColumnSpan() ];
String[] readerTemplates = new String[ prop.getColumnSpan() ];
String[] forms = new String[ prop.getColumnSpan() ];
int[] colnos = new int[ prop.getColumnSpan() ];
int[] formnos = new int[ prop.getColumnSpan() ];
// int[] colnos = new int[ prop.getColumnSpan() ];
// int[] formnos = new int[ prop.getColumnSpan() ];
int l = 0;
final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
prop,
entityMetamodel.isInstrumented(),
entityName -> {
final MetadataImplementor metadata = creationContext.getMetadata();
final PersistentClass entityBinding = metadata.getEntityBinding( entityName );
assert entityBinding != null;
return entityBinding.hasSubclasses();
},
sessionFactoryOptions.isCollectionsInDefaultFetchGroupEnabled()
);
// final boolean lazy = ! EnhancementHelper.includeInBaseFetchGroup(
// prop,
// entityMetamodel.isInstrumented(),
// entityName -> {
// final MetadataImplementor metadata = creationContext.getMetadata();
// final PersistentClass entityBinding = metadata.getEntityBinding( entityName );
// assert entityBinding != null;
// return entityBinding.hasSubclasses();
// },
// sessionFactoryOptions.isCollectionsInDefaultFetchGroupEnabled()
// );
for ( Selectable selectable : prop.getSelectables() ) {
if ( selectable.isFormula() ) {
String template = selectable.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
formnos[l] = formulaTemplates.size();
colnos[l] = -1;
formulaTemplates.add( template );
// formnos[l] = formulaTemplates.size();
// colnos[l] = -1;
// formulaTemplates.add( template );
forms[l] = template;
formulas.add( selectable.getText( dialect ) );
// formulas.add( selectable.getText( dialect ) );
formulaAliases.add( selectable.getAlias( dialect ) );
formulasLazy.add( lazy );
// formulasLazy.add( lazy );
}
else {
Column col = (Column) selectable;
String colName = col.getQuotedName( dialect );
colnos[l] = columns.size(); //before add :-)
formnos[l] = -1;
// colnos[l] = columns.size(); //before add :-)
// formnos[l] = -1;
columns.add( colName );
cols[l] = colName;
aliases.add( selectable.getAlias( dialect, prop.getValue().getTable() ) );
columnsLazy.add( lazy );
columnSelectables.add( Boolean.valueOf( prop.isSelectable() ) );
// columnsLazy.add( lazy );
columnSelectables.add( prop.isSelectable() );
readers[l] = col.getReadExpr( dialect );
String readerTemplate = col.getTemplate( dialect, factory.getQueryEngine().getSqmFunctionRegistry() );
readerTemplates[l] = readerTemplate;
columnReaderTemplates.add( readerTemplate );
// columnReaderTemplates.add( readerTemplate );
}
l++;
}
@ -1002,33 +989,33 @@ public abstract class AbstractEntityPersister
propColumnReaders.add( readers );
propColumnReaderTemplates.add( readerTemplates );
templates.add( forms );
propColumnNumbers.add( colnos );
propFormulaNumbers.add( formnos );
// propColumnNumbers.add( colnos );
// propFormulaNumbers.add( formnos );
joinedFetchesList.add( prop.getValue().getFetchMode() );
cascades.add( prop.getCascadeStyle() );
}
subclassColumnClosure = ArrayHelper.toStringArray( columns );
subclassColumnAliasClosure = ArrayHelper.toStringArray( aliases );
subclassColumnLazyClosure = ArrayHelper.toBooleanArray( columnsLazy );
// subclassColumnLazyClosure = ArrayHelper.toBooleanArray( columnsLazy );
subclassColumnSelectableClosure = ArrayHelper.toBooleanArray( columnSelectables );
subclassColumnReaderTemplateClosure = ArrayHelper.toStringArray( columnReaderTemplates );
// subclassColumnReaderTemplateClosure = ArrayHelper.toStringArray( columnReaderTemplates );
subclassFormulaClosure = ArrayHelper.toStringArray( formulas );
subclassFormulaTemplateClosure = ArrayHelper.toStringArray( formulaTemplates );
// subclassFormulaClosure = ArrayHelper.toStringArray( formulas );
// subclassFormulaTemplateClosure = ArrayHelper.toStringArray( formulaTemplates );
subclassFormulaAliasClosure = ArrayHelper.toStringArray( formulaAliases );
subclassFormulaLazyClosure = ArrayHelper.toBooleanArray( formulasLazy );
// subclassFormulaLazyClosure = ArrayHelper.toBooleanArray( formulasLazy );
subclassPropertyNameClosure = ArrayHelper.toStringArray( names );
subclassPropertySubclassNameClosure = ArrayHelper.toStringArray( classes );
// subclassPropertySubclassNameClosure = ArrayHelper.toStringArray( classes );
subclassPropertyTypeClosure = ArrayHelper.toTypeArray( types );
subclassPropertyNullabilityClosure = ArrayHelper.toBooleanArray( propNullables );
subclassPropertyFormulaTemplateClosure = ArrayHelper.to2DStringArray( templates );
subclassPropertyColumnNameClosure = ArrayHelper.to2DStringArray( propColumns );
subclassPropertyColumnReaderClosure = ArrayHelper.to2DStringArray( propColumnReaders );
subclassPropertyColumnReaderTemplateClosure = ArrayHelper.to2DStringArray( propColumnReaderTemplates );
subclassPropertyColumnNumberClosure = ArrayHelper.to2DIntArray( propColumnNumbers );
subclassPropertyFormulaNumberClosure = ArrayHelper.to2DIntArray( propFormulaNumbers );
// subclassPropertyColumnNumberClosure = ArrayHelper.to2DIntArray( propColumnNumbers );
// subclassPropertyFormulaNumberClosure = ArrayHelper.to2DIntArray( propFormulaNumbers );
subclassPropertyCascadeStyleClosure = new CascadeStyle[cascades.size()];
int j = 0;
@ -1044,23 +1031,17 @@ public abstract class AbstractEntityPersister
propertyDefinedOnSubclass = ArrayHelper.toBooleanArray( definedBySubclass );
// Handle any filters applied to the class level
if ( CollectionHelper.isNotEmpty( bootDescriptor.getFilters() ) ) {
filterHelper = new FilterHelper( bootDescriptor.getFilters(), factory );
}
else {
filterHelper = null;
}
filterHelper = CollectionHelper.isNotEmpty( bootDescriptor.getFilters() )
? new FilterHelper(bootDescriptor.getFilters(), factory)
: null;
useReferenceCacheEntries = useReferenceCacheEntries();
cacheEntryHelper = buildCacheEntryHelper();
if ( sessionFactoryOptions.isSecondLevelCacheEnabled() ) {
this.invalidateCache = canWriteToCache && shouldInvalidateCache( bootDescriptor, creationContext );
}
else {
this.invalidateCache = false;
}
invalidateCache = sessionFactoryOptions.isSecondLevelCacheEnabled()
&& canWriteToCache
&& shouldInvalidateCache(bootDescriptor, creationContext);
}
@ -1188,12 +1169,6 @@ public abstract class AbstractEntityPersister
return useReferenceCacheEntries;
}
protected static String getTemplateFromString(String string, SessionFactoryImplementor factory) {
return string == null ?
null :
Template.renderWhereStringTemplate( string, factory.getJdbcServices().getDialect(), factory.getQueryEngine().getSqmFunctionRegistry() );
}
protected Map<String, SingleIdArrayLoadPlan> generateLazySelectStringsByFetchGroup() {
final BytecodeEnhancementMetadata enhancementMetadata = entityMetamodel.getBytecodeEnhancementMetadata();
if ( !enhancementMetadata.isEnhancedForLazyLoading()
@ -1346,7 +1321,7 @@ public abstract class AbstractEntityPersister
creationContext
);
final StandardTableGroup tableGroup = new StandardTableGroup(
return new StandardTableGroup(
canUseInnerJoins,
navigablePath,
this,
@ -1359,19 +1334,15 @@ public abstract class AbstractEntityPersister
final String[] subclassTableNames = getSubclassTableNames();
for ( int i = 0; i < subclassTableNames.length; i++ ) {
if ( tableExpression.equals( subclassTableNames[ i ] ) ) {
final boolean isNullableTable = isNullableSubclassTable( i );
final NamedTableReference joinedTableReference = new NamedTableReference(
tableExpression,
sqlAliasBase.generateNewAlias(),
isNullableTable,
isNullableSubclassTable( i ),
getFactory()
);
return new TableReferenceJoin(
shouldInnerJoinSubclassTable(
i,
Collections.emptySet()
),
shouldInnerJoinSubclassTable( i, Collections.emptySet() ),
joinedTableReference,
additionalPredicateCollectorAccess == null
? null
@ -1389,8 +1360,6 @@ public abstract class AbstractEntityPersister
},
getFactory()
);
return tableGroup;
}
@Override
@ -1703,7 +1672,6 @@ public abstract class AbstractEntityPersister
final boolean set = initializeLazyProperty(
fieldName,
entity,
session,
entry,
fetchGroupAttributeDescriptor.getLazyIndex(),
selectedValue
@ -1755,7 +1723,7 @@ public abstract class AbstractEntityPersister
session,
entity
);
if ( initializeLazyProperty( fieldName, entity, session, entry, j, propValue ) ) {
if ( initializeLazyProperty( fieldName, entity, entry, j, propValue ) ) {
result = propValue;
}
}
@ -1766,23 +1734,23 @@ public abstract class AbstractEntityPersister
return result;
}
// called by Hibernate Reactive
protected boolean initializeLazyProperty(
final String fieldName,
final Object entity,
final SharedSessionContractImplementor session,
final EntityEntry entry,
final int j,
final int index,
final Object propValue) {
setPropertyValue( entity, lazyPropertyNumbers[j], propValue );
setPropertyValue( entity, lazyPropertyNumbers[index], propValue );
if ( entry.getLoadedState() != null ) {
// object have been loaded with setReadOnly(true); HHH-2236
entry.getLoadedState()[lazyPropertyNumbers[j]] = lazyPropertyTypes[j].deepCopy( propValue, factory );
entry.getLoadedState()[lazyPropertyNumbers[index]] = lazyPropertyTypes[index].deepCopy( propValue, factory );
}
// If the entity has deleted state, then update that as well
if ( entry.getDeletedState() != null ) {
entry.getDeletedState()[lazyPropertyNumbers[j]] = lazyPropertyTypes[j].deepCopy( propValue, factory );
entry.getDeletedState()[lazyPropertyNumbers[index]] = lazyPropertyTypes[index].deepCopy( propValue, factory );
}
return fieldName.equals( lazyPropertyNames[j] );
return fieldName.equals( lazyPropertyNames[index] );
}
public boolean isBatchable() {
@ -1836,14 +1804,6 @@ public abstract class AbstractEntityPersister
return getTableName( 0 );
}
protected boolean[] getSubclassColumnLazyiness() {
return subclassColumnLazyClosure;
}
protected boolean[] getSubclassFormulaLazyiness() {
return subclassFormulaLazyClosure;
}
/**
* We can't immediately add to the cache if we have formulas
* which must be evaluated, or if we have the possibility of
@ -2101,10 +2061,6 @@ public abstract class AbstractEntityPersister
return select.addCondition( rootTableKeyColumnNames, "=?" ).toStatementString();
}
public boolean[] getPropertyUniqueness() {
return propertyUniqueness;
}
private GeneratedValuesProcessor createGeneratedValuesProcessor(GenerationTiming timing) {
return new GeneratedValuesProcessor( this, timing, getFactory() );
}
@ -2339,10 +2295,7 @@ public abstract class AbstractEntityPersister
return getSubclassColumnTableNumberClosure()[idx];
}
}*/
int index = ArrayHelper.indexOf(
getSubclassPropertyNameClosure(),
rootPropertyName
); //TODO: optimize this better!
int index = ArrayHelper.indexOf( getSubclassPropertyNameClosure(), rootPropertyName ); //TODO: optimize this better!
return index == -1 ? 0 : getSubclassPropertyTableNumber( index );
}
@ -2406,10 +2359,6 @@ public abstract class AbstractEntityPersister
return ArrayHelper.indexOf( subclassPropertyNameClosure, propertyName );
}
protected String[] getPropertySubclassNames() {
return propertySubclassNames;
}
@Override
public String[] getPropertyColumnNames(int i) {
return propertyColumnNames[i];
@ -2560,10 +2509,7 @@ public abstract class AbstractEntityPersister
return ArrayHelper.toIntArray( fields );
}
protected String[] getSubclassPropertySubclassNameClosure() {
return subclassPropertySubclassNameClosure;
}
@Deprecated //TODO: REMOVE THIS
protected String[] getSubclassColumnClosure() {
return subclassColumnClosure;
}
@ -2572,18 +2518,6 @@ public abstract class AbstractEntityPersister
return subclassColumnAliasClosure;
}
public String[] getSubclassColumnReaderTemplateClosure() {
return subclassColumnReaderTemplateClosure;
}
protected String[] getSubclassFormulaClosure() {
return subclassFormulaClosure;
}
protected String[] getSubclassFormulaTemplateClosure() {
return subclassFormulaTemplateClosure;
}
protected String[] getSubclassFormulaAliasClosure() {
return subclassFormulaAliasClosure;
}
@ -2702,18 +2636,8 @@ public abstract class AbstractEntityPersister
}
protected int[] getLazyPropertyNumbers() {
return lazyPropertyNumbers;
}
protected String[] getLazyPropertyNames() {
return lazyPropertyNames;
}
protected Type[] getLazyPropertyTypes() {
return lazyPropertyTypes;
}
// used by Hibernate Reactive
@SuppressWarnings("unused")
protected String[][] getLazyPropertyColumnAliases() {
return lazyPropertyColumnAliases;
}
@ -3238,11 +3162,6 @@ public abstract class AbstractEntityPersister
return 0;
}
public boolean useInsertSelectIdentity() {
return !useGetGeneratedKeys()
&& getFactory().getJdbcServices().getDialect().getIdentityColumnSupport().supportsInsertSelectIdentity();
}
public boolean useGetGeneratedKeys() {
return getFactory().getSessionFactoryOptions().isGetGeneratedKeysEnabled();
}
@ -4095,20 +4014,11 @@ public abstract class AbstractEntityPersister
protected abstract String filterFragment(String alias, Set<String> treatAsDeclarations);
public String generateWhereConditionAlias(String alias) {
return alias;
}
@Override
public String generateFilterConditionAlias(String rootAlias) {
return rootAlias;
}
protected boolean isSubclassTableLazy(int j) {
return false;
}
protected boolean shouldInnerJoinSubclassTable(
int subclassTableNumber,
Set<String> treatAsDeclarations) {
@ -6679,15 +6589,6 @@ public abstract class AbstractEntityPersister
return attributeDefinitions;
}
/**
* If true, persister can omit superclass tables during joining if they are not needed in the query.
*
* @return true if the persister can do it
*/
public boolean canOmitSuperclassTableJoin() {
return false;
}
private void prepareEntityIdentifierDefinition() {
if ( entityIdentifierDefinition != null ) {
return;

View File

@ -11,7 +11,6 @@ import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
@ -97,13 +96,11 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
private final String[][] tableKeyColumnReaders;
private final String[][] tableKeyColumnReaderTemplates;
private final String[][] naturalOrderTableKeyColumns;
private final String[][] naturalOrderTableKeyColumnReaders;
private final String[][] naturalOrderTableKeyColumnReaderTemplates;
private final boolean[] naturalOrderCascadeDeleteEnabled;
private final String[] spaces;
private final String[] subclassClosure;
// private final String[] subclassClosure;
private final String[] subclassTableNameClosure;
private final String[][] subclassTableKeyColumnClosure;
@ -120,10 +117,10 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
// the closure of all columns used by the entire hierarchy including
// subclasses and superclasses of this class
private final int[] subclassColumnTableNumberClosure;
private final int[] subclassFormulaTableNumberClosure;
// private final int[] subclassFormulaTableNumberClosure;
private final boolean[] subclassTableSequentialSelect;
private final boolean[] subclassTableIsLazyClosure;
// private final boolean[] subclassTableIsLazyClosure;
private final boolean[] isInverseSubclassTable;
private final boolean[] isNullableSubclassTable;
@ -315,14 +312,14 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
naturalOrderTableNames = ArrayHelper.toStringArray( tableNames );
naturalOrderTableKeyColumns = ArrayHelper.to2DStringArray( keyColumns );
naturalOrderTableKeyColumnReaders = ArrayHelper.to2DStringArray( keyColumnReaders );
naturalOrderTableKeyColumnReaderTemplates = ArrayHelper.to2DStringArray( keyColumnReaderTemplates );
String[][] naturalOrderTableKeyColumnReaders = ArrayHelper.to2DStringArray(keyColumnReaders);
String[][] naturalOrderTableKeyColumnReaderTemplates = ArrayHelper.to2DStringArray(keyColumnReaderTemplates);
naturalOrderCascadeDeleteEnabled = ArrayHelper.toBooleanArray( cascadeDeletes );
ArrayList<String> subclassTableNames = new ArrayList<>();
ArrayList<Boolean> isConcretes = new ArrayList<>();
ArrayList<Boolean> isDeferreds = new ArrayList<>();
ArrayList<Boolean> isLazies = new ArrayList<>();
// ArrayList<Boolean> isLazies = new ArrayList<>();
ArrayList<Boolean> isInverses = new ArrayList<>();
ArrayList<Boolean> isNullables = new ArrayList<>();
@ -330,7 +327,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
for ( Table table : persistentClass.getSubclassTableClosure() ) {
isConcretes.add( persistentClass.isClassOrSuperclassTable( table ) );
isDeferreds.add( Boolean.FALSE );
isLazies.add( Boolean.FALSE );
// isLazies.add( Boolean.FALSE );
isInverses.add( Boolean.FALSE );
isNullables.add( Boolean.FALSE );
final String tableName = determineTableName( table );
@ -351,7 +348,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
isDeferreds.add( join.isSequentialSelect() );
isInverses.add( join.isInverse() );
isNullables.add( join.isOptional() );
isLazies.add( join.isLazy() );
// isLazies.add( join.isLazy() );
String joinTableName = determineTableName( joinTable );
subclassTableNames.add( joinTableName );
@ -367,7 +364,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
String[][] naturalOrderSubclassTableKeyColumnClosure = ArrayHelper.to2DStringArray( keyColumns );
isClassOrSuperclassTable = ArrayHelper.toBooleanArray( isConcretes );
subclassTableSequentialSelect = ArrayHelper.toBooleanArray( isDeferreds );
subclassTableIsLazyClosure = ArrayHelper.toBooleanArray( isLazies );
// subclassTableIsLazyClosure = ArrayHelper.toBooleanArray( isLazies );
isInverseSubclassTable = ArrayHelper.toBooleanArray( isInverses );
isNullableSubclassTable = ArrayHelper.toBooleanArray( isNullables );
@ -471,11 +468,11 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
propertyTableNumbers = new int[hydrateSpan];
int i = 0;
for ( Property property : persistentClass.getPropertyClosure() ) {
String tabname = property.getValue().getTable().getQualifiedName(
String tableName = property.getValue().getTable().getQualifiedName(
factory.getSqlStringGenerationContext()
);
propertyTableNumbers[i] = getTableId( tabname, this.tableNames );
naturalOrderPropertyTableNumbers[i] = getTableId( tabname, naturalOrderTableNames );
propertyTableNumbers[i] = getTableId( tableName, this.tableNames );
naturalOrderPropertyTableNumbers[i] = getTableId( tableName, naturalOrderTableNames );
i++;
}
@ -484,23 +481,23 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
//TODO: code duplication with SingleTableEntityPersister
ArrayList<Integer> columnTableNumbers = new ArrayList<>();
ArrayList<Integer> formulaTableNumbers = new ArrayList<>();
// ArrayList<Integer> formulaTableNumbers = new ArrayList<>();
ArrayList<Integer> propTableNumbers = new ArrayList<>();
for ( Property property : persistentClass.getSubclassPropertyClosure() ) {
Table tab = property.getValue().getTable();
String tabname = tab.getQualifiedName(
Table table = property.getValue().getTable();
String tableName = table.getQualifiedName(
factory.getSqlStringGenerationContext()
);
Integer tabnum = getTableId( tabname, subclassTableNameClosure );
propTableNumbers.add( tabnum );
Integer tableNumber = getTableId( tableName, subclassTableNameClosure );
propTableNumbers.add( tableNumber );
for ( Selectable selectable : property.getSelectables() ) {
if ( selectable.isFormula() ) {
formulaTableNumbers.add( tabnum );
// formulaTableNumbers.add( tableNumber );
}
else {
columnTableNumbers.add( tabnum );
columnTableNumbers.add( tableNumber );
}
}
@ -508,14 +505,14 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
subclassColumnTableNumberClosure = ArrayHelper.toIntArray( columnTableNumbers );
subclassPropertyTableNumberClosure = ArrayHelper.toIntArray( propTableNumbers );
subclassFormulaTableNumberClosure = ArrayHelper.toIntArray( formulaTableNumbers );
// subclassFormulaTableNumberClosure = ArrayHelper.toIntArray( formulaTableNumbers );
// SUBCLASSES
int subclassSpan = persistentClass.getSubclassSpan() + 1;
subclassClosure = new String[subclassSpan];
// subclassClosure = new String[subclassSpan];
int subclassSpanMinusOne = subclassSpan - 1;
subclassClosure[subclassSpanMinusOne] = getEntityName();
// subclassClosure[subclassSpanMinusOne] = getEntityName();
if ( persistentClass.isPolymorphic() ) {
subclassesByDiscriminatorValue.put( discriminatorValue, getEntityName() );
@ -564,7 +561,7 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
int k = 0;
for ( Subclass subclass : persistentClass.getSubclasses() ) {
subclassClosure[k] = subclass.getEntityName();
// subclassClosure[k] = subclass.getEntityName();
final Table table = subclass.getTable();
subclassNameByTableName.put( table.getName(), subclass.getEntityName() );
try {
@ -948,16 +945,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
return tableNames[0];
}
private int getRootHierarchyClassTableIndex() {
final String rootHierarchyClassTableName = naturalOrderTableNames[0];
for ( int i = 0; i < subclassTableNameClosure.length; i++ ) {
if ( subclassTableNameClosure[i].equals( rootHierarchyClassTableName ) ) {
return i;
}
}
return 0;
}
@Override
protected String filterFragment(String alias) {
return hasWhere() ? getSQLWhereString( generateFilterConditionAlias( alias ) ) : "";
@ -973,11 +960,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
return generateTableAlias( rootAlias, tableSpan - 1 );
}
@Override
public String generateWhereConditionAlias(String rootAlias) {
return generateTableAlias( rootAlias, tableSpan - 1 );
}
@Override
public String[] getIdentifierColumnNames() {
return tableKeyColumns[0];
@ -998,11 +980,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
return tableKeyColumnReaders[0];
}
@Override
protected int[] getPropertyTableNumbersInSelect() {
return propertyTableNumbers;
}
@Override
protected int getSubclassPropertyTableNumber(int i) {
return subclassPropertyTableNumberClosure[i];
@ -1013,21 +990,11 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
return tableSpan;
}
@Override
@Override @Deprecated
public boolean isMultiTable() {
return true;
}
@Override
protected int[] getSubclassColumnTableNumberClosure() {
return subclassColumnTableNumberClosure;
}
@Override
protected int[] getSubclassFormulaTableNumberClosure() {
return subclassFormulaTableNumberClosure;
}
@Override
protected int[] getPropertyTableNumbers() {
return naturalOrderPropertyTableNumbers;
@ -1053,11 +1020,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
return subclassTableNameClosure.length;
}
@Override
protected boolean isSubclassTableLazy(int j) {
return subclassTableIsLazyClosure[j];
}
@Override
protected boolean shouldProcessSuperMapping() {
return false;
@ -1152,12 +1114,12 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
&& subclassColumnNameClosure[i].endsWith( "\"" );
if ( quoted ) {
if ( subclassColumnNameClosure[i].equals( columnName ) ) {
return getSubclassColumnTableNumberClosure()[i];
return subclassColumnTableNumberClosure[i];
}
}
else {
if ( subclassColumnNameClosure[i].equalsIgnoreCase( columnName ) ) {
return getSubclassColumnTableNumberClosure()[i];
return subclassColumnTableNumberClosure[i];
}
}
}
@ -1295,11 +1257,6 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
return new DynamicFilterAliasGenerator(subclassTableNameClosure, rootAlias);
}
@Override
public boolean canOmitSuperclassTableJoin() {
return true;
}
@Override
public <T> DomainResult<T> createDomainResult(
NavigablePath navigablePath,
@ -1351,8 +1308,8 @@ public class JoinedSubclassEntityPersister extends AbstractEntityPersister {
// Add the table references for all table names of the treated entities as we have to retain these table references.
// Table references not appearing in this set can later be pruned away
// todo (6.0): no need to resolve all table references, only the ones needed for cardinality
for ( int i = 0; i < subclassTableNames.length; i++ ) {
retainedTableReferences.add( tableGroup.resolveTableReference( null, subclassTableNames[i], false ) );
for ( String subclassTableName : subclassTableNames ) {
retainedTableReferences.add(tableGroup.resolveTableReference(null, subclassTableName, false));
}
}
final List<TableReferenceJoin> tableReferenceJoins = tableGroup.getTableReferenceJoins();

View File

@ -40,6 +40,7 @@ import org.hibernate.mapping.Value;
import org.hibernate.persister.spi.PersisterCreationContext;
import org.hibernate.query.sqm.ComparisonOperator;
import org.hibernate.query.spi.NavigablePath;
import org.hibernate.query.sqm.function.SqmFunctionRegistry;
import org.hibernate.sql.InFragment;
import org.hibernate.sql.Insert;
import org.hibernate.sql.ast.spi.FromClauseAccess;
@ -58,7 +59,6 @@ import org.hibernate.sql.ast.tree.predicate.Junction;
import org.hibernate.sql.ast.tree.predicate.NegatedPredicate;
import org.hibernate.sql.ast.tree.predicate.NullnessPredicate;
import org.hibernate.sql.ast.tree.predicate.Predicate;
import org.hibernate.type.AssociationType;
import org.hibernate.type.BasicType;
import org.hibernate.type.Type;
import org.hibernate.type.descriptor.jdbc.JdbcLiteralFormatter;
@ -89,7 +89,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
private final String[] subclassClosure;
private final String[] subclassTableNameClosure;
private final boolean[] subclassTableIsLazyClosure;
// private final boolean[] subclassTableIsLazyClosure;
private final boolean[] isInverseSubclassTable;
private final boolean[] isNullableSubclassTable;
private final boolean[] subclassTableSequentialSelect;
@ -104,8 +104,8 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
// subclasses and superclasses of this class
private final int[] subclassPropertyTableNumberClosure;
private final int[] subclassColumnTableNumberClosure;
private final int[] subclassFormulaTableNumberClosure;
// private final int[] subclassColumnTableNumberClosure;
// private final int[] subclassFormulaTableNumberClosure;
// discriminator column
private final Map<Object, String> subclassesByDiscriminatorValue;
@ -113,7 +113,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
private final String discriminatorColumnName;
private final String discriminatorColumnReaders;
private final String discriminatorColumnReaderTemplate;
private final String discriminatorFormula;
// private final String discriminatorFormula;
private final String discriminatorFormulaTemplate;
private final String discriminatorAlias;
private final BasicType<?> discriminatorType;
@ -125,7 +125,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
private final String[][] constraintOrderedKeyColumnNames;
//private final Map propertyTableNumbersByName = new HashMap();
private final Map<String, Integer> propertyTableNumbersByNameAndSubclass;
// private final Map<String, Integer> propertyTableNumbersByNameAndSubclass;
private static final Object NULL_DISCRIMINATOR = new MarkerObject( "<null discriminator>" );
private static final Object NOT_NULL_DISCRIMINATOR = new MarkerObject( "<not null discriminator>" );
@ -192,8 +192,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
qualifiedTableNames[j] = determineTableName( join.getTable() );
isInverseTable[j] = join.isInverse();
isNullableTable[j] = join.isOptional();
cascadeDeleteEnabled[j] = join.getKey().isCascadeDeleteEnabled() &&
dialect.supportsCascadeDelete();
cascadeDeleteEnabled[j] = join.getKey().isCascadeDeleteEnabled() && dialect.supportsCascadeDelete();
customSQLInsert[j] = join.getCustomSQLInsert();
insertCallable[j] = customSQLInsert[j] != null && join.isCustomInsertCallable();
@ -232,7 +231,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
ArrayHelper.toStringArray( persistentClass.getSynchronizedTables() )
);
final boolean lazyAvailable = isInstrumented();
// final boolean lazyAvailable = isInstrumented();
ArrayList<String> subclassTables = new ArrayList<>();
ArrayList<String[]> joinKeyColumns = new ArrayList<>();
@ -241,7 +240,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
ArrayList<Boolean> isDeferreds = new ArrayList<>();
ArrayList<Boolean> isInverses = new ArrayList<>();
ArrayList<Boolean> isNullables = new ArrayList<>();
ArrayList<Boolean> isLazies = new ArrayList<>();
// ArrayList<Boolean> isLazies = new ArrayList<>();
subclassTables.add( qualifiedTableNames[0] );
joinKeyColumns.add( getIdentifierColumnNames() );
isConcretes.add( Boolean.TRUE );
@ -249,13 +248,13 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
isDeferreds.add( Boolean.FALSE );
isInverses.add( Boolean.FALSE );
isNullables.add( Boolean.FALSE );
isLazies.add( Boolean.FALSE );
// isLazies.add( Boolean.FALSE );
for ( Join join : persistentClass.getSubclassJoinClosure() ) {
isConcretes.add( persistentClass.isClassOrSuperclassTable( join.getTable() ) );
isClassOrSuperclassJoins.add( persistentClass.isClassOrSuperclassJoin( join ) );
isInverses.add( join.isInverse() );
isNullables.add( join.isOptional() );
isLazies.add( lazyAvailable && join.isLazy() );
// isLazies.add( lazyAvailable && join.isLazy() );
boolean isDeferred = join.isSequentialSelect() && !persistentClass.isClassOrSuperclassJoin( join ) ;
isDeferreds.add( isDeferred );
@ -273,7 +272,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
subclassTableSequentialSelect = ArrayHelper.toBooleanArray( isDeferreds );
subclassTableNameClosure = ArrayHelper.toStringArray( subclassTables );
subclassTableIsLazyClosure = ArrayHelper.toBooleanArray( isLazies );
// subclassTableIsLazyClosure = ArrayHelper.toBooleanArray( isLazies );
subclassTableKeyColumnClosure = ArrayHelper.to2DStringArray( joinKeyColumns );
isClassOrSuperclassTable = ArrayHelper.toBooleanArray( isConcretes );
isClassOrSuperclassJoin = ArrayHelper.toBooleanArray( isClassOrSuperclassJoins );
@ -289,13 +288,11 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
}
forceDiscriminator = persistentClass.isForceDiscriminator();
Selectable selectable = discrimValue.getSelectables().get(0);
SqmFunctionRegistry functionRegistry = factory.getQueryEngine().getSqmFunctionRegistry();
if ( discrimValue.hasFormula() ) {
Formula formula = (Formula) selectable;
discriminatorFormula = formula.getFormula();
discriminatorFormulaTemplate = formula.getTemplate(
dialect,
factory.getQueryEngine().getSqmFunctionRegistry()
);
// discriminatorFormula = formula.getFormula();
discriminatorFormulaTemplate = formula.getTemplate( dialect, functionRegistry );
discriminatorColumnName = null;
discriminatorColumnReaders = null;
discriminatorColumnReaderTemplate = null;
@ -305,12 +302,9 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
Column column = (Column) selectable;
discriminatorColumnName = column.getQuotedName( dialect );
discriminatorColumnReaders = column.getReadExpr( dialect );
discriminatorColumnReaderTemplate = column.getTemplate(
dialect,
factory.getQueryEngine().getSqmFunctionRegistry()
);
discriminatorColumnReaderTemplate = column.getTemplate( dialect, functionRegistry );
discriminatorAlias = column.getAlias( dialect, persistentClass.getRootTable() );
discriminatorFormula = null;
// discriminatorFormula = null;
discriminatorFormulaTemplate = null;
}
discriminatorType = (BasicType<?>) persistentClass.getDiscriminator().getType();
@ -355,7 +349,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
discriminatorType = null;
discriminatorValue = null;
discriminatorSQLValue = null;
discriminatorFormula = null;
// discriminatorFormula = null;
discriminatorFormulaTemplate = null;
}
@ -369,11 +363,11 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
//TODO: code duplication with JoinedSubclassEntityPersister
ArrayList<Integer> columnJoinNumbers = new ArrayList<>();
ArrayList<Integer> formulaJoinedNumbers = new ArrayList<>();
// ArrayList<Integer> columnJoinNumbers = new ArrayList<>();
// ArrayList<Integer> formulaJoinedNumbers = new ArrayList<>();
ArrayList<Integer> propertyJoinNumbers = new ArrayList<>();
final HashMap<String, Integer> propertyTableNumbersByNameAndSubclassLocal = new HashMap<>();
// final HashMap<String, Integer> propertyTableNumbersByNameAndSubclassLocal = new HashMap<>();
final Map<Object, String> subclassesByDiscriminatorValueLocal = new HashMap<>();
for ( Property property : persistentClass.getSubclassPropertyClosure() ) {
@ -381,32 +375,36 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
propertyJoinNumbers.add( join );
//propertyTableNumbersByName.put( prop.getName(), join );
propertyTableNumbersByNameAndSubclassLocal.put(
property.getPersistentClass().getEntityName() + '.' + property.getName(),
join
);
// propertyTableNumbersByNameAndSubclassLocal.put(
// property.getPersistentClass().getEntityName() + '.' + property.getName(),
// join
// );
for ( Selectable selectable : property.getSelectables() ) {
if ( selectable.isFormula() ) {
formulaJoinedNumbers.add( join );
}
else {
columnJoinNumbers.add( join );
}
}
// for ( Selectable selectable : property.getSelectables() ) {
// if ( selectable.isFormula() ) {
// formulaJoinedNumbers.add( join );
// }
// else {
// columnJoinNumbers.add( join );
// }
// }
}
propertyTableNumbersByNameAndSubclass = CollectionHelper.toSmallMap( propertyTableNumbersByNameAndSubclassLocal );
// propertyTableNumbersByNameAndSubclass = CollectionHelper.toSmallMap( propertyTableNumbersByNameAndSubclassLocal );
subclassColumnTableNumberClosure = ArrayHelper.toIntArray( columnJoinNumbers );
subclassFormulaTableNumberClosure = ArrayHelper.toIntArray( formulaJoinedNumbers );
// subclassColumnTableNumberClosure = ArrayHelper.toIntArray( columnJoinNumbers );
// subclassFormulaTableNumberClosure = ArrayHelper.toIntArray( formulaJoinedNumbers );
subclassPropertyTableNumberClosure = ArrayHelper.toIntArray( propertyJoinNumbers );
int subclassSpan = persistentClass.getSubclassSpan() + 1;
subclassClosure = new String[subclassSpan];
subclassClosure[0] = getEntityName();
if ( persistentClass.isPolymorphic() ) {
addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, discriminatorValue, getEntityName() );
addSubclassByDiscriminatorValue(
subclassesByDiscriminatorValueLocal,
discriminatorValue,
getEntityName()
);
}
// SUBCLASSES
@ -415,16 +413,25 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
for ( Subclass subclass : persistentClass.getSubclasses() ) {
subclassClosure[k++] = subclass.getEntityName();
if ( subclass.isDiscriminatorValueNull() ) {
addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NULL_DISCRIMINATOR, subclass.getEntityName() );
addSubclassByDiscriminatorValue(
subclassesByDiscriminatorValueLocal,
NULL_DISCRIMINATOR,
subclass.getEntityName()
);
}
else if ( subclass.isDiscriminatorValueNotNull() ) {
addSubclassByDiscriminatorValue( subclassesByDiscriminatorValueLocal, NOT_NULL_DISCRIMINATOR, subclass.getEntityName() );
addSubclassByDiscriminatorValue(
subclassesByDiscriminatorValueLocal,
NOT_NULL_DISCRIMINATOR,
subclass.getEntityName()
);
}
else {
try {
addSubclassByDiscriminatorValue(
subclassesByDiscriminatorValueLocal,
discriminatorType.getJavaTypeDescriptor().fromString( subclass.getDiscriminatorValue() ),
discriminatorType.getJavaTypeDescriptor()
.fromString( subclass.getDiscriminatorValue() ),
subclass.getEntityName()
);
}
@ -439,7 +446,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
}
// Don't hold a reference to an empty HashMap:
this.subclassesByDiscriminatorValue = CollectionHelper.toSmallMap( subclassesByDiscriminatorValueLocal );
subclassesByDiscriminatorValue = CollectionHelper.toSmallMap( subclassesByDiscriminatorValueLocal );
initSubclassPropertyAliasesMap( persistentClass );
@ -535,16 +542,10 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
return spaces;
}
//Access cached SQL
protected boolean isDiscriminatorFormula() {
private boolean isDiscriminatorFormula() {
return discriminatorColumnName == null;
}
protected String getDiscriminatorFormula() {
return discriminatorFormula;
}
@Override
public String getTableName(int j) {
return qualifiedTableNames[j];
@ -713,11 +714,6 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
return subclassTableNameClosure[subclassPropertyTableNumberClosure[i]];
}
@Override
protected int[] getPropertyTableNumbersInSelect() {
return propertyTableNumbers;
}
@Override
protected int getSubclassPropertyTableNumber(int i) {
return subclassPropertyTableNumberClosure[i];
@ -737,44 +733,11 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
}
@Override
protected int[] getSubclassColumnTableNumberClosure() {
return subclassColumnTableNumberClosure;
}
@Override
protected int[] getSubclassFormulaTableNumberClosure() {
return subclassFormulaTableNumberClosure;
}
@Override
protected int[] getPropertyTableNumbers() {
return propertyTableNumbers;
}
private int getSubclassPropertyTableNumber(String propertyName, String entityName) {
// When there are duplicated property names in the subclasses
// then propertyMapping.toType( propertyName ) may return an
// incorrect Type. To ensure correct results, lookup the property type
// using the concrete EntityPersister with the specified entityName
// (since the concrete EntityPersister cannot have duplicated property names).
final EntityPersister concreteEntityPersister;
if ( getEntityName().equals( entityName ) ) {
concreteEntityPersister = this;
}
else {
concreteEntityPersister = getFactory().getRuntimeMetamodels()
.getMappingMetamodel()
.getEntityDescriptor( entityName );
}
Type type = concreteEntityPersister.getPropertyType( propertyName );
if ( type.isAssociationType() && ( (AssociationType) type ).useLHSPrimaryKey() ) {
return 0;
}
final Integer tabnum = propertyTableNumbersByNameAndSubclass.get( entityName + '.' + propertyName );
return tabnum == null ? 0 : tabnum;
}
@Override
protected String[] getSubclassTableKeyColumns(int j) {
return subclassTableKeyColumnClosure[j];
@ -805,11 +768,6 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
return isClassOrSuperclassJoin[j];
}
@Override
protected boolean isSubclassTableLazy(int j) {
return subclassTableIsLazyClosure[j];
}
@Override
public boolean isNullableTable(int j) {
return isNullableTable[j];
@ -823,18 +781,10 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
@Override
public String getPropertyTableName(String propertyName) {
Integer index = getEntityMetamodel().getPropertyIndexOrNull( propertyName );
if ( index == null ) {
return null;
}
return qualifiedTableNames[propertyTableNumbers[index]];
return index == null ? null : qualifiedTableNames[propertyTableNumbers[index]];
}
@Override
public boolean canOmitSuperclassTableJoin() {
return true;
}
@Override
@Override @Deprecated
public boolean isMultiTable() {
return getTableSpan() > 1;
}
@ -879,8 +829,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
final Predicate discriminatorPredicate = createDiscriminatorPredicate(
tableGroup.getPrimaryTableReference().getIdentificationVariable(),
tableGroup,
expressionResolver,
creationContext
expressionResolver
);
additionalPredicateCollectorAccess.get().accept( discriminatorPredicate );
}
@ -899,8 +848,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
createDiscriminatorPredicate(
alias,
tableGroup,
creationState.getSqlExpressionResolver(),
creationState.getCreationContext()
creationState.getSqlExpressionResolver()
)
);
}
@ -910,8 +858,7 @@ public class SingleTableEntityPersister extends AbstractEntityPersister {
private Predicate createDiscriminatorPredicate(
String alias,
TableGroup tableGroup,
SqlExpressionResolver sqlExpressionResolver,
SqlAstCreationContext creationContext) {
SqlExpressionResolver sqlExpressionResolver) {
final String columnReferenceKey;
final String discriminatorExpression;
if ( isDiscriminatorFormula() ) {

View File

@ -306,19 +306,11 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
return spaces;
}
protected boolean isDiscriminatorFormula() {
return false;
}
@Override
protected boolean shouldProcessSuperMapping() {
return false;
}
protected String getDiscriminatorFormula() {
return null;
}
@Override
public String getTableName(int j) {
return tableName;
@ -361,11 +353,6 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
return getTableName();//ie. the subquery! yuck!
}
@Override
protected int[] getPropertyTableNumbersInSelect() {
return new int[getPropertySpan()];
}
@Override
protected int getSubclassPropertyTableNumber(int i) {
return 0;
@ -376,7 +363,7 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
return 0;
}
@Override
@Override @Deprecated
public boolean isMultiTable() {
// This could also just be true all the time...
return isAbstract() || hasSubclasses();
@ -422,16 +409,6 @@ public class UnionSubclassEntityPersister extends AbstractEntityPersister {
return 1;
}
@Override
protected int[] getSubclassColumnTableNumberClosure() {
return new int[getSubclassColumnClosure().length];
}
@Override
protected int[] getSubclassFormulaTableNumberClosure() {
return new int[getSubclassFormulaClosure().length];
}
protected boolean[] getTableHasColumns() {
return ArrayHelper.TRUE;
}