HHH-14665 Use semi-colon as the default statement delimiter for scripts

This commit is contained in:
Christian Beikov 2021-06-08 17:08:59 +02:00
parent 6155f95cf7
commit 10cba26bda
10 changed files with 21 additions and 17 deletions

View File

@ -929,6 +929,7 @@ Valid options are defined by the `strategy` value of the https://docs.jboss.org/
`*hibernate.hbm2ddl.delimiter*` (e.g. `;`):: `*hibernate.hbm2ddl.delimiter*` (e.g. `;`)::
Identifies the delimiter to use to separate schema management statements in script outputs. Identifies the delimiter to use to separate schema management statements in script outputs.
The default value is `;`.
`*hibernate.schema_management_tool*` (e.g. A schema name):: `*hibernate.schema_management_tool*` (e.g. A schema name)::
Used to specify the `SchemaManagementTool` to use for performing schema management. The default is to use `HibernateSchemaManagementTool`. Used to specify the `SchemaManagementTool` to use for performing schema management. The default is to use `HibernateSchemaManagementTool`.

View File

@ -1859,7 +1859,8 @@ public interface AvailableSettings extends org.hibernate.jpa.AvailableSettings {
String HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY = "hibernate.hbm2ddl.jdbc_metadata_extraction_strategy"; String HBM2DDL_JDBC_METADATA_EXTRACTOR_STRATEGY = "hibernate.hbm2ddl.jdbc_metadata_extraction_strategy";
/** /**
* Identifies the delimiter to use to separate schema management statements in script outputs * Identifies the delimiter to use to separate schema management statements in script outputs.
* The default value is <code>;</code>.
*/ */
String HBM2DDL_DELIMITER = "hibernate.hbm2ddl.delimiter"; String HBM2DDL_DELIMITER = "hibernate.hbm2ddl.delimiter";

View File

@ -123,7 +123,7 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
JdbcContext jdbcContext, JdbcContext jdbcContext,
Map options, Map options,
boolean needsAutoCommit) { boolean needsAutoCommit) {
final String scriptDelimiter = ConfigurationHelper.getString( HBM2DDL_DELIMITER, options ); final String scriptDelimiter = ConfigurationHelper.getString( HBM2DDL_DELIMITER, options, ";" );
final GenerationTarget[] targets = new GenerationTarget[ targetDescriptor.getTargetTypes().size() ]; final GenerationTarget[] targets = new GenerationTarget[ targetDescriptor.getTargetTypes().size() ];
@ -156,7 +156,7 @@ public class HibernateSchemaManagementTool implements SchemaManagementTool, Serv
TargetDescriptor targetDescriptor, TargetDescriptor targetDescriptor,
DdlTransactionIsolator ddlTransactionIsolator, DdlTransactionIsolator ddlTransactionIsolator,
Map options) { Map options) {
final String scriptDelimiter = ConfigurationHelper.getString( HBM2DDL_DELIMITER, options ); final String scriptDelimiter = ConfigurationHelper.getString( HBM2DDL_DELIMITER, options, ";" );
final GenerationTarget[] targets = new GenerationTarget[ targetDescriptor.getTargetTypes().size() ]; final GenerationTarget[] targets = new GenerationTarget[ targetDescriptor.getTargetTypes().size() ];

View File

@ -85,7 +85,7 @@ public class PostgreSQLMultipleSchemaSequenceTest extends BaseUnitTestCase {
); );
try(Statement statement = ddlTransactionIsolator1.getIsolatedConnection().createStatement()) { try(Statement statement = ddlTransactionIsolator1.getIsolatedConnection().createStatement()) {
statement.execute( String.format( "DROP SCHEMA IF EXISTS %s CASCADE", extraSchemaName ) ); statement.execute( String.format( "DROP SCHEMA IF EXISTS %s CASCADE", extraSchemaName ) );
statement.execute( String.format( "CREATE SCHEMA %s", extraSchemaName ) ); statement.execute( String.format( "CREATE SCHEMA %s;", extraSchemaName ) );
try(ResultSet resultSet = statement.executeQuery( "SELECT NEXTVAL('SEQ_TEST')" )) { try(ResultSet resultSet = statement.executeQuery( "SELECT NEXTVAL('SEQ_TEST')" )) {
while ( resultSet.next() ) { while ( resultSet.next() ) {
@ -156,7 +156,7 @@ public class PostgreSQLMultipleSchemaSequenceTest extends BaseUnitTestCase {
assertEquals( 2 , assertEquals( 2 ,
sqlLines sqlLines
.stream() .stream()
.filter( s -> s.equalsIgnoreCase( "create sequence SEQ_TEST start 1 increment 1" ) ) .filter( s -> s.equalsIgnoreCase( "create sequence SEQ_TEST start 1 increment 1;" ) )
.count() .count()
); );
} }

View File

@ -68,12 +68,12 @@ public class SequenceGenerationTest extends BaseUnitTestCase {
List<String> commands = Files.readAllLines( output.toPath() ); List<String> commands = Files.readAllLines( output.toPath() );
assertThat( assertThat(
isCommandGenerated( commands, "create table test_entity \\(id .*, primary key \\(id\\)\\)" ), isCommandGenerated( commands, "create table test_entity \\(id .*, primary key \\(id\\)\\);" ),
is( true ) is( true )
); );
assertThat( assertThat(
isCommandGenerated( commands, "create sequence sequence_generator start with 5 increment by 3" ), isCommandGenerated( commands, "create sequence sequence_generator start with 5 increment by 3;" ),
is( true ) is( true )
); );
} }

View File

@ -70,12 +70,12 @@ public class SequenceGeneratorsTest extends BaseUnitTestCase {
List<String> commands = Files.readAllLines( output.toPath() ); List<String> commands = Files.readAllLines( output.toPath() );
assertThat( assertThat(
isCommandGenerated( commands, "CREATE TABLE TEST_ENTITY \\(ID .*, PRIMARY KEY \\(ID\\)\\)" ), isCommandGenerated( commands, "CREATE TABLE TEST_ENTITY \\(ID .*, PRIMARY KEY \\(ID\\)\\);" ),
is( true ) is( true )
); );
assertThat( assertThat(
isCommandGenerated( commands, "CREATE SEQUENCE SEQUENCE_GENERATOR START WITH 5 INCREMENT BY 3" ), isCommandGenerated( commands, "CREATE SEQUENCE SEQUENCE_GENERATOR START WITH 5 INCREMENT BY 3;" ),
is( true ) is( true )
); );
} }

View File

@ -71,13 +71,13 @@ public class TableGeneratorTest extends BaseUnitTestCase {
final List<String> commands = Files.readAllLines( output.toPath() ); final List<String> commands = Files.readAllLines( output.toPath() );
final String expectedTestEntityTableCreationCommand = "CREATE TABLE TEST_ENTITY \\(ID .*, PRIMARY KEY \\(ID\\)\\)"; final String expectedTestEntityTableCreationCommand = "CREATE TABLE TEST_ENTITY \\(ID .*, PRIMARY KEY \\(ID\\)\\);";
assertTrue( assertTrue(
"The command '" + expectedTestEntityTableCreationCommand + "' has not been correctly generated", "The command '" + expectedTestEntityTableCreationCommand + "' has not been correctly generated",
isCommandGenerated( commands, expectedTestEntityTableCreationCommand ) isCommandGenerated( commands, expectedTestEntityTableCreationCommand )
); );
final String expectedIdTableGeneratorCreationCommand = "CREATE TABLE ID_TABLE_GENERATOR \\(PK .*, VALUE .*, PRIMARY KEY \\(PK\\)\\)"; final String expectedIdTableGeneratorCreationCommand = "CREATE TABLE ID_TABLE_GENERATOR \\(PK .*, VALUE .*, PRIMARY KEY \\(PK\\)\\);";
assertTrue( assertTrue(
"The command '" + expectedIdTableGeneratorCreationCommand + "' has not been correctly generated", "The command '" + expectedIdTableGeneratorCreationCommand + "' has not been correctly generated",
@ -88,7 +88,7 @@ public class TableGeneratorTest extends BaseUnitTestCase {
) )
); );
final String expectedInsertIntoTableGeneratorCommand = "INSERT INTO ID_TABLE_GENERATOR\\(PK, VALUE\\) VALUES \\('TEST_ENTITY_ID'," + EXPECTED_DB_INSERTED_VALUE + "\\)"; final String expectedInsertIntoTableGeneratorCommand = "INSERT INTO ID_TABLE_GENERATOR\\(PK, VALUE\\) VALUES \\('TEST_ENTITY_ID'," + EXPECTED_DB_INSERTED_VALUE + "\\);";
assertTrue( assertTrue(
"The command '" + expectedInsertIntoTableGeneratorCommand + "' has not been correctly generated", "The command '" + expectedInsertIntoTableGeneratorCommand + "' has not been correctly generated",

View File

@ -72,13 +72,13 @@ public class TableGeneratorsTest extends BaseUnitTestCase {
final List<String> commands = Files.readAllLines( output.toPath() ); final List<String> commands = Files.readAllLines( output.toPath() );
final String expectedTestEntityTableCreationCommand = "CREATE TABLE TEST_ENTITY \\(ID .*, PRIMARY KEY \\(ID\\)\\)"; final String expectedTestEntityTableCreationCommand = "CREATE TABLE TEST_ENTITY \\(ID .*, PRIMARY KEY \\(ID\\)\\);";
assertTrue( assertTrue(
"The command '" + expectedTestEntityTableCreationCommand + "' has not been correctly generated", "The command '" + expectedTestEntityTableCreationCommand + "' has not been correctly generated",
isCommandGenerated( commands, expectedTestEntityTableCreationCommand ) isCommandGenerated( commands, expectedTestEntityTableCreationCommand )
); );
final String expectedIdTableGeneratorCreationCommand = "CREATE TABLE ID_TABLE_GENERATOR \\(PK .*, VALUE .*, PRIMARY KEY \\(PK\\)\\)"; final String expectedIdTableGeneratorCreationCommand = "CREATE TABLE ID_TABLE_GENERATOR \\(PK .*, VALUE .*, PRIMARY KEY \\(PK\\)\\);";
assertTrue( assertTrue(
"The command '" + expectedIdTableGeneratorCreationCommand + "' has not been correctly generated", "The command '" + expectedIdTableGeneratorCreationCommand + "' has not been correctly generated",
@ -89,7 +89,7 @@ public class TableGeneratorsTest extends BaseUnitTestCase {
) )
); );
final String expectedInsertIntoTableGeneratorCommand = "INSERT INTO ID_TABLE_GENERATOR\\(PK, VALUE\\) VALUES \\('TEST_ENTITY_ID'," + EXPECTED_DB_INSERTED_VALUE + "\\)"; final String expectedInsertIntoTableGeneratorCommand = "INSERT INTO ID_TABLE_GENERATOR\\(PK, VALUE\\) VALUES \\('TEST_ENTITY_ID'," + EXPECTED_DB_INSERTED_VALUE + "\\);";
assertTrue( assertTrue(
"The command '" + expectedInsertIntoTableGeneratorCommand + "' has not been correctly generated", "The command '" + expectedInsertIntoTableGeneratorCommand + "' has not been correctly generated",

View File

@ -93,7 +93,7 @@ public class UniqueConstraintGenerationTest {
private boolean isUniqueConstraintGenerated(String tableName, String columnName) throws IOException { private boolean isUniqueConstraintGenerated(String tableName, String columnName) throws IOException {
boolean matches = false; boolean matches = false;
final String regex = getDialect().getAlterTableString( tableName ) + " add constraint uk_(.)* unique \\(" + columnName + "\\)"; final String regex = getDialect().getAlterTableString( tableName ) + " add constraint uk_(.)* unique \\(" + columnName + "\\);";
final String fileContent = new String( Files.readAllBytes( output.toPath() ) ).toLowerCase(); final String fileContent = new String( Files.readAllBytes( output.toPath() ) ).toLowerCase();
final String[] split = fileContent.split( System.lineSeparator() ); final String[] split = fileContent.split( System.lineSeparator() );
@ -109,7 +109,7 @@ public class UniqueConstraintGenerationTest {
private boolean isCreateUniqueIndexGenerated(String tableName, String columnName) throws IOException { private boolean isCreateUniqueIndexGenerated(String tableName, String columnName) throws IOException {
boolean matches = false; boolean matches = false;
String regex = "create unique index uk_(.)* on " + tableName + " \\(" + columnName + "\\)"; String regex = "create unique index uk_(.)* on " + tableName + " \\(" + columnName + "\\);";
final String fileContent = new String( Files.readAllBytes( output.toPath() ) ).toLowerCase(); final String fileContent = new String( Files.readAllBytes( output.toPath() ) ).toLowerCase();
final String[] split = fileContent.split( System.lineSeparator() ); final String[] split = fileContent.split( System.lineSeparator() );

View File

@ -11,6 +11,7 @@ import java.lang.reflect.Executable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.hibernate.internal.build.AllowSysOut;
import org.hibernate.internal.util.ReflectHelper; import org.hibernate.internal.util.ReflectHelper;
import com.oracle.svm.core.annotate.AutomaticFeature; import com.oracle.svm.core.annotate.AutomaticFeature;
@ -50,6 +51,7 @@ public final class QueryParsingSupport implements Feature {
access.registerReachabilityHandler(this::enableHQLSupport, parserClazz); access.registerReachabilityHandler(this::enableHQLSupport, parserClazz);
} }
@AllowSysOut
private void enableHQLSupport(DuringAnalysisAccess duringAnalysisAccess) { private void enableHQLSupport(DuringAnalysisAccess duringAnalysisAccess) {
final boolean needsEnablingYet = triggered.compareAndSet( false, true ); final boolean needsEnablingYet = triggered.compareAndSet( false, true );
if ( needsEnablingYet ) { if ( needsEnablingYet ) {