Skip to content

Commit 4b06bf6

Browse files
committed
HHH-18337 Account for physical naming strategy when querying db sequence
Introduced new signature for `Configurable#configure` which accepts a `GeneratorCreationContext`.
1 parent 7402e1a commit 4b06bf6

20 files changed

+272
-108
lines changed

hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorBinder.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -560,23 +560,22 @@ private static void checkVersionGenerationAlways(MemberDetails property, Generat
560560

561561
/**
562562
* If the given {@link Generator} also implements {@link Configurable},
563-
* call its {@link Configurable#configure(Type, Properties, ServiceRegistry)
563+
* call its {@link Configurable#configure(GeneratorCreationContext, Properties)
564564
* configure()} method.
565565
*/
566566
private static void callConfigure(
567567
GeneratorCreationContext creationContext,
568568
Generator generator,
569569
Map<String, Object> configuration,
570570
SimpleValue identifierValue) {
571-
if ( generator instanceof Configurable ) {
572-
final Configurable configurable = (Configurable) generator;
571+
if ( generator instanceof final Configurable configurable ) {
573572
final Properties parameters = collectParameters(
574573
identifierValue,
575574
creationContext.getDatabase().getDialect(),
576575
creationContext.getRootClass(),
577576
configuration
578577
);
579-
configurable.configure( identifierValue.getType(), parameters, creationContext.getServiceRegistry() );
578+
configurable.configure( creationContext, parameters );
580579
}
581580
}
582581

hibernate-core/src/main/java/org/hibernate/boot/model/internal/GeneratorParameters.java

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
import org.hibernate.dialect.Dialect;
1616
import org.hibernate.engine.config.spi.ConfigurationService;
1717
import org.hibernate.engine.config.spi.StandardConverters;
18+
import org.hibernate.generator.GeneratorCreationContext;
1819
import org.hibernate.id.Configurable;
1920
import org.hibernate.id.IdentifierGenerator;
2021
import org.hibernate.id.OptimizableGenerator;
@@ -38,7 +39,7 @@
3839

3940
/**
4041
* Responsible for setting up the parameters which are passed to
41-
* {@link Configurable#configure(Type, Properties, ServiceRegistry)}
42+
* {@link Configurable#configure(GeneratorCreationContext, Properties)}
4243
* when a {@link Configurable} generator is instantiated.
4344
*
4445
* @since 7.0
@@ -51,7 +52,7 @@ public class GeneratorParameters {
5152

5253
/**
5354
* Collect the parameters which should be passed to
54-
* {@link Configurable#configure(Type, Properties, ServiceRegistry)}.
55+
* {@link Configurable#configure(GeneratorCreationContext, Properties)}.
5556
*/
5657
public static Properties collectParameters(
5758
SimpleValue identifierValue,

hibernate-core/src/main/java/org/hibernate/generator/GeneratorCreationContext.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
import org.hibernate.mapping.Property;
1313
import org.hibernate.mapping.RootClass;
1414
import org.hibernate.service.ServiceRegistry;
15+
import org.hibernate.type.Type;
1516

1617
/**
1718
* An object passed as a parameter to the constructor or
@@ -34,4 +35,7 @@ public interface GeneratorCreationContext {
3435
RootClass getRootClass();
3536

3637
Property getProperty();
38+
default Type getType() {
39+
return getProperty().getType();
40+
}
3741
}

hibernate-core/src/main/java/org/hibernate/id/Configurable.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import org.hibernate.MappingException;
1212
import org.hibernate.boot.model.relational.Database;
1313
import org.hibernate.boot.model.relational.SqlStringGenerationContext;
14+
import org.hibernate.generator.GeneratorCreationContext;
1415
import org.hibernate.service.ServiceRegistry;
1516
import org.hibernate.type.Type;
1617

@@ -21,6 +22,13 @@
2122
* @author Steve Ebersole
2223
*/
2324
public interface Configurable {
25+
/**
26+
* @deprecated Use {@link #configure(GeneratorCreationContext, Properties)} instead
27+
*/
28+
@Deprecated( since = "7.0", forRemoval = true )
29+
default void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) throws MappingException {
30+
}
31+
2432
/**
2533
* Configure this instance, given the value of parameters
2634
* specified by the user as XML {@code <param>} elements and
@@ -32,13 +40,14 @@ public interface Configurable {
3240
* then this method is always called before
3341
* {@link org.hibernate.boot.model.relational.ExportableProducer#registerExportables(Database)},
3442
*
35-
* @param type The id property type descriptor
43+
* @param creationContext Access to the generator creation context
3644
* @param parameters param values, keyed by parameter name
37-
* @param serviceRegistry Access to service that may be needed.
3845
*
3946
* @throws MappingException when there's something wrong with the given parameters
4047
*/
41-
void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) throws MappingException;
48+
default void configure(GeneratorCreationContext creationContext, Properties parameters) throws MappingException {
49+
configure( creationContext.getType(), parameters, creationContext.getServiceRegistry() );
50+
};
4251

4352
/**
4453
* Initializes this instance, pre-generating SQL if necessary.

hibernate-core/src/main/java/org/hibernate/id/ForeignGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010

1111
import org.hibernate.MappingException;
1212
import org.hibernate.engine.spi.SharedSessionContractImplementor;
13+
import org.hibernate.generator.GeneratorCreationContext;
1314
import org.hibernate.service.ServiceRegistry;
1415
import org.hibernate.type.Type;
1516

@@ -68,7 +69,7 @@ public String getRole() {
6869

6970

7071
@Override
71-
public void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) throws MappingException {
72+
public void configure(GeneratorCreationContext creationContext, Properties parameters) throws MappingException {
7273
propertyName = parameters.getProperty( PROPERTY );
7374
entityName = parameters.getProperty( ENTITY_NAME );
7475
if ( propertyName==null ) {

hibernate-core/src/main/java/org/hibernate/id/IdentifierGenerator.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
import org.hibernate.engine.spi.SharedSessionContractImplementor;
1818
import org.hibernate.generator.EventType;
1919
import org.hibernate.generator.EventTypeSets;
20+
import org.hibernate.generator.Generator;
21+
import org.hibernate.generator.GeneratorCreationContext;
2022
import org.hibernate.service.ServiceRegistry;
2123
import org.hibernate.generator.BeforeExecutionGenerator;
2224
import org.hibernate.type.Type;
@@ -39,7 +41,7 @@
3941
* {@code ExportableProducer}, in case the implementation needs to export
4042
* objects to the database as part of the process of schema export.
4143
* <p>
42-
* The {@link #configure(Type, Properties, ServiceRegistry)} method accepts
44+
* The {@link #configure(GeneratorCreationContext, Properties)} method accepts
4345
* a properties object containing named values. These include:
4446
* <ul>
4547
* <li>several "standard" parameters with keys defined as static members of
@@ -104,7 +106,7 @@ default void configure(Type type, Properties parameters, ServiceRegistry service
104106
* for example, a sequence or tables.
105107
* <p>
106108
* This method is called just once, after
107-
* {@link #configure(Type, Properties, ServiceRegistry)}.
109+
* {@link #configure(GeneratorCreationContext, Properties)}.
108110
*
109111
* @param database The database instance
110112
*/

hibernate-core/src/main/java/org/hibernate/id/IncrementGenerator.java

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import org.hibernate.engine.jdbc.env.spi.IdentifierHelper;
2323
import org.hibernate.engine.jdbc.env.spi.JdbcEnvironment;
2424
import org.hibernate.engine.spi.SharedSessionContractImplementor;
25+
import org.hibernate.generator.GeneratorCreationContext;
2526
import org.hibernate.internal.CoreLogging;
2627
import org.hibernate.internal.CoreMessageLogger;
2728
import org.hibernate.service.ServiceRegistry;
@@ -85,10 +86,10 @@ public synchronized Object generate(SharedSessionContractImplementor session, Ob
8586
}
8687

8788
@Override
88-
public void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) throws MappingException {
89-
returnClass = type.getReturnedClass();
89+
public void configure(GeneratorCreationContext creationContext, Properties parameters) throws MappingException {
90+
returnClass = creationContext.getType().getReturnedClass();
9091

91-
final JdbcEnvironment jdbcEnvironment = serviceRegistry.requireService( JdbcEnvironment.class );
92+
final JdbcEnvironment jdbcEnvironment = creationContext.getServiceRegistry().requireService( JdbcEnvironment.class );
9293
final IdentifierHelper identifierHelper = jdbcEnvironment.getIdentifierHelper();
9394

9495
column = parameters.getProperty( COLUMN );

hibernate-core/src/main/java/org/hibernate/id/PersistentIdentifierGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,15 @@
88

99
import java.util.Properties;
1010

11+
import org.hibernate.generator.GeneratorCreationContext;
1112
import org.hibernate.service.ServiceRegistry;
1213
import org.hibernate.type.Type;
1314

1415
/**
1516
* An {@link IdentifierGenerator} that requires creation of database objects.
1617
* <p>
1718
* All instances have access to a special mapping parameter in their
18-
* {@link #configure(Type, Properties, ServiceRegistry)} method: schema
19+
* {@link #configure(GeneratorCreationContext, Properties)} method: schema
1920
*
2021
* @author Gavin King
2122
* @author Steve Ebersole

hibernate-core/src/main/java/org/hibernate/id/PostInsertIdentifierGenerator.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,9 @@
88

99
import org.hibernate.generator.EventType;
1010
import org.hibernate.generator.EventTypeSets;
11-
import org.hibernate.service.ServiceRegistry;
11+
import org.hibernate.generator.GeneratorCreationContext;
1212
import org.hibernate.generator.OnExecutionGenerator;
13+
import org.hibernate.service.ServiceRegistry;
1314
import org.hibernate.type.Type;
1415

1516
import java.util.EnumSet;

hibernate-core/src/main/java/org/hibernate/id/SelectGenerator.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
import java.util.Properties;
1010

1111
import org.hibernate.dialect.Dialect;
12+
import org.hibernate.generator.GeneratorCreationContext;
1213
import org.hibernate.generator.OnExecutionGenerator;
1314
import org.hibernate.persister.entity.EntityPersister;
14-
import org.hibernate.service.ServiceRegistry;
1515
import org.hibernate.type.Type;
1616

1717
import static org.hibernate.generator.internal.NaturalIdHelper.getNaturalIdPropertyNames;
@@ -87,7 +87,7 @@ public class SelectGenerator
8787
private String uniqueKeyPropertyName;
8888

8989
@Override
90-
public void configure(Type type, Properties parameters, ServiceRegistry serviceRegistry) {
90+
public void configure(GeneratorCreationContext creationContext, Properties parameters) {
9191
uniqueKeyPropertyName = parameters.getProperty( KEY );
9292
}
9393

0 commit comments

Comments
 (0)