Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* 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.generator;

public interface CompositeBeforeExecutionGenerator extends BeforeExecutionGenerator, CompositeGenerator {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
/*
* 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.generator;

public interface CompositeGenerator {
Generator getGenerator(String propertyName);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
/*
* 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.generator.internal;

import java.util.EnumSet;
import java.util.Map;

import org.hibernate.dialect.Dialect;
import org.hibernate.generator.CompositeGenerator;
import org.hibernate.generator.EventType;
import org.hibernate.generator.Generator;
import org.hibernate.generator.OnExecutionGenerator;

public class OnExecutionCompositeGenerator implements OnExecutionGenerator, CompositeGenerator {

final Map<String, Generator> generators;
final EnumSet<EventType> eventTypes;
final boolean writePropertyValue;
final boolean referenceColumnsInSql;
final String[] referencedColumnValues;

public OnExecutionCompositeGenerator(
Map<String, Generator> generators,
EnumSet<EventType> eventTypes,
boolean writePropertyValue,
boolean referenceColumnsInSql, String[] referencedColumnValues) {
this.generators = generators;
this.eventTypes = eventTypes;
this.writePropertyValue = writePropertyValue;
this.referenceColumnsInSql = referenceColumnsInSql;
this.referencedColumnValues = referencedColumnValues;
}

@Override
public EnumSet<EventType> getEventTypes() {
return eventTypes;
}

@Override
public boolean referenceColumnsInSql(Dialect dialect) {
return referenceColumnsInSql;
}

@Override
public boolean writePropertyValue() {
return writePropertyValue;
}

@Override
public String[] getReferencedColumnValues(Dialect dialect) {
return referencedColumnValues;
}

@Override
public boolean generatedOnExecution() {
return true;
}

@Override
public Generator getGenerator(String propertyName) {
return generators.get( propertyName );
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@
import org.hibernate.spi.EntityIdentifierNavigablePath;
import org.hibernate.spi.NavigablePath;
import org.hibernate.sql.ast.SqlAstJoinType;
import org.hibernate.sql.ast.internal.TableGroupJoinHelper;
import org.hibernate.sql.ast.spi.AliasCollector;
import org.hibernate.sql.ast.spi.FromClauseAccess;
import org.hibernate.sql.ast.spi.SimpleFromClauseAccessImpl;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import org.hibernate.engine.jdbc.spi.JdbcServices;
import org.hibernate.engine.spi.CascadeStyle;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.Generator;
import org.hibernate.internal.util.IndexedConsumer;
import org.hibernate.internal.util.collections.CollectionHelper;
import org.hibernate.mapping.Any;
Expand Down Expand Up @@ -268,6 +269,7 @@ protected boolean finishInitialization(
ConcreteTableResolver concreteTableResolver,
Consumer<AttributeMapping> attributeConsumer,
SuccessfulCompletionCallback completionCallback,
Generator generator,
MappingModelCreationProcess creationProcess) {
final TypeConfiguration typeConfiguration = creationProcess.getCreationContext().getTypeConfiguration();
final JdbcServices jdbcServices = creationProcess.getCreationContext().getJdbcServices();
Expand All @@ -278,7 +280,6 @@ protected boolean finishInitialization(

int attributeIndex = 0;
int columnPosition = 0;

for ( Property bootPropertyDescriptor : bootDescriptor.getProperties() ) {
final Type subtype = subtypes[ attributeIndex ];

Expand Down Expand Up @@ -373,6 +374,7 @@ protected boolean finishInitialization(
value.isColumnUpdateable( 0 ),
propertyAccess,
compositeType.getCascadeStyle( attributeIndex ),
generator,
creationProcess
);

Expand Down Expand Up @@ -440,6 +442,7 @@ else if ( subtype instanceof CompositeType ) {
subRootTableKeyColumnNames,
propertyAccess,
compositeType.getCascadeStyle( attributeIndex ),
generator,
creationProcess
);

Expand Down Expand Up @@ -473,6 +476,7 @@ else if ( subtype instanceof EntityType ) {
(EntityType) subtype,
representationStrategy.resolvePropertyAccess( bootPropertyDescriptor ),
compositeType.getCascadeStyle( attributeIndex ),
generator,
creationProcess
);
columnPosition += bootPropertyDescriptor.getColumnSpan();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ public abstract class AbstractSingularAttributeMapping
implements SingularAttributeMapping {

private final PropertyAccess propertyAccess;
private final Generator generator;

public AbstractSingularAttributeMapping(
String name,
Expand All @@ -31,9 +32,11 @@ public AbstractSingularAttributeMapping(
AttributeMetadata attributeMetadata,
FetchOptions mappedFetchOptions,
ManagedMappingType declaringType,
Generator generator,
PropertyAccess propertyAccess) {
super( name, attributeMetadata, mappedFetchOptions, stateArrayPosition, fetchableIndex, declaringType );
this.propertyAccess = propertyAccess;
this.generator = generator;
}

public AbstractSingularAttributeMapping(
Expand All @@ -44,9 +47,11 @@ public AbstractSingularAttributeMapping(
FetchTiming fetchTiming,
FetchStyle fetchStyle,
ManagedMappingType declaringType,
Generator generator,
PropertyAccess propertyAccess) {
super( name, attributeMetadata, fetchTiming, fetchStyle, stateArrayPosition, fetchableIndex, declaringType );
this.propertyAccess = propertyAccess;
this.generator = generator;
}

/**
Expand All @@ -55,6 +60,7 @@ public AbstractSingularAttributeMapping(
protected AbstractSingularAttributeMapping( AbstractSingularAttributeMapping original ) {
super( original );
this.propertyAccess = original.propertyAccess;
this.generator = original.getGenerator();
}

@Override
Expand All @@ -64,7 +70,7 @@ public PropertyAccess getPropertyAccess() {

@Override
public Generator getGenerator() {
return findContainingEntityMapping().getEntityPersister().getEntityMetamodel().getGenerators()[getStateArrayPosition()];
return generator;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import org.hibernate.engine.FetchStyle;
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.Generator;
import org.hibernate.internal.util.IndexedConsumer;
import org.hibernate.metamodel.mapping.AttributeMetadata;
import org.hibernate.metamodel.mapping.BasicValuedModelPart;
Expand Down Expand Up @@ -43,7 +44,7 @@
@SuppressWarnings("rawtypes")
public class BasicAttributeMapping
extends AbstractSingularAttributeMapping
implements SingularAttributeMapping, BasicValuedModelPart {
implements BasicValuedModelPart {
private final NavigableRole navigableRole;

private final String tableExpression;
Expand Down Expand Up @@ -95,6 +96,65 @@ public BasicAttributeMapping(
JdbcMapping jdbcMapping,
ManagedMappingType declaringType,
PropertyAccess propertyAccess) {
this(
attributeName,
navigableRole,
stateArrayPosition,
fetchableIndex,
attributeMetadata,
mappedFetchTiming,
mappedFetchStyle,
tableExpression,
mappedColumnExpression,
selectablePath,
isFormula,
customReadExpression,
customWriteExpression,
columnDefinition,
length,
precision,
scale,
temporalPrecision,
isLob,
nullable,
insertable,
updateable,
partitioned,
jdbcMapping,
declaringType,
null,
propertyAccess
);
}

public BasicAttributeMapping(
String attributeName,
NavigableRole navigableRole,
int stateArrayPosition,
int fetchableIndex,
AttributeMetadata attributeMetadata,
FetchTiming mappedFetchTiming,
FetchStyle mappedFetchStyle,
String tableExpression,
String mappedColumnExpression,
SelectablePath selectablePath,
boolean isFormula,
String customReadExpression,
String customWriteExpression,
String columnDefinition,
Long length,
Integer precision,
Integer scale,
Integer temporalPrecision,
boolean isLob,
boolean nullable,
boolean insertable,
boolean updateable,
boolean partitioned,
JdbcMapping jdbcMapping,
ManagedMappingType declaringType,
Generator generator,
PropertyAccess propertyAccess) {
super(
attributeName,
stateArrayPosition,
Expand All @@ -103,6 +163,7 @@ public BasicAttributeMapping(
mappedFetchTiming,
mappedFetchStyle,
declaringType,
generator,
propertyAccess
);
this.navigableRole = navigableRole;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.hibernate.engine.FetchTiming;
import org.hibernate.engine.spi.SessionFactoryImplementor;
import org.hibernate.engine.spi.SharedSessionContractImplementor;
import org.hibernate.generator.Generator;
import org.hibernate.internal.util.IndexedConsumer;
import org.hibernate.mapping.Any;
import org.hibernate.mapping.Property;
Expand Down Expand Up @@ -79,6 +80,40 @@ public DiscriminatedAssociationAttributeMapping(
AnyType anyType,
Any bootValueMapping,
MappingModelCreationProcess creationProcess) {
this(
attributeRole,
baseAssociationJtd,
declaringType,
stateArrayPosition,
fetchableIndex,
attributeMetadata,
fetchTiming,
propertyAccess,
bootProperty,
anyType,
bootValueMapping,
declaringType.findContainingEntityMapping()
.getEntityPersister()
.getEntityMetamodel()
.getGenerators()[stateArrayPosition],
creationProcess
);
}

public DiscriminatedAssociationAttributeMapping(
NavigableRole attributeRole,
JavaType<?> baseAssociationJtd,
ManagedMappingType declaringType,
int stateArrayPosition,
int fetchableIndex,
AttributeMetadata attributeMetadata,
FetchTiming fetchTiming,
PropertyAccess propertyAccess,
Property bootProperty,
AnyType anyType,
Any bootValueMapping,
Generator generator,
MappingModelCreationProcess creationProcess) {
super(
bootProperty.getName(),
stateArrayPosition,
Expand All @@ -87,6 +122,7 @@ public DiscriminatedAssociationAttributeMapping(
fetchTiming,
FetchStyle.SELECT,
declaringType,
generator,
propertyAccess
);
this.navigableRole = attributeRole;
Expand Down
Loading