Skip to content

Commit 7299365

Browse files
committed
correct sequence restart syntax for Oracle
1 parent ecc3334 commit 7299365

File tree

5 files changed

+27
-11
lines changed

5 files changed

+27
-11
lines changed

hibernate-core/src/main/java/org/hibernate/dialect/sequence/OracleSequenceSupport.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,4 +51,9 @@ public boolean sometimesNeedsStartingValue() {
5151
public String getDropSequenceString(String sequenceName) throws MappingException {
5252
return "drop sequence " + (supportsIfExists ? "if exists " : "") + sequenceName;
5353
}
54+
55+
@Override
56+
public String getRestartSequenceString(String sequenceName, long startWith) {
57+
return "alter sequence " + sequenceName + " restart start with " + startWith;
58+
}
5459
}

hibernate-core/src/main/java/org/hibernate/dialect/sequence/SequenceSupport.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ default String[] getCreateSequenceStrings(String sequenceName, int initialValue,
145145
}
146146

147147
/**
148-
* Typically dialects which support sequences can create a sequence with
148+
* Typically, dialects which support sequences can create a sequence with
149149
* a single command. This method is a convenience making it easier to
150150
* implement {@link #getCreateSequenceStrings(String,int,int)} for these
151151
* dialects.
@@ -169,7 +169,7 @@ default String getCreateSequenceString(String sequenceName) throws MappingExcept
169169
}
170170

171171
/**
172-
* Typically dialects which support sequences can create a sequence with
172+
* Typically, dialects which support sequences can create a sequence with
173173
* a single command. This method is a convenience making it easier to
174174
* implement {@link #getCreateSequenceStrings(String,int,int)} for these
175175
* dialects.
@@ -212,9 +212,9 @@ default String[] getDropSequenceStrings(String sequenceName) throws MappingExcep
212212
}
213213

214214
/**
215-
* Typically dialects which support sequences can drop a sequence
216-
* with a single command. This is convenience form of
217-
* {@link #getDropSequenceStrings} to help facilitate that.
215+
* Typically, dialects which support sequences can drop a sequence
216+
* with a single command. This is a convenience form of
217+
* {@link #getDropSequenceStrings} which facilitates that.
218218
* <p>
219219
* Dialects which support sequences and can drop a sequence in a
220220
* single command need *only* override this method. Dialects
@@ -229,6 +229,17 @@ default String getDropSequenceString(String sequenceName) throws MappingExceptio
229229
return "drop sequence " + sequenceName;
230230
}
231231

232+
/**
233+
* A DDL statement to restart a sequence with a given value.
234+
*
235+
* @param sequenceName The name of the sequence
236+
* @param startWith The value to restart at
237+
* @return The {@code alter sequence ... restart} command
238+
*/
239+
default String getRestartSequenceString(String sequenceName, long startWith) {
240+
return "alter sequence " + sequenceName + " restart with " + startWith;
241+
}
242+
232243
/**
233244
* Do we need to explicitly specify {@code minvalue} or
234245
* {@code maxvalue} when the initial value doesn't have

hibernate-core/src/main/java/org/hibernate/id/enhanced/DatabaseStructure.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,8 @@
1212
import org.hibernate.mapping.Table;
1313

1414
/**
15-
* Encapsulates definition of the underlying data structure backing a
16-
* sequence-style generator.
15+
* Encapsulates definition of the underlying data structure backing
16+
* a {@linkplain SequenceStyleGenerator sequence-style} generator.
1717
*
1818
* @author Steve Ebersole
1919
*/

hibernate-core/src/main/java/org/hibernate/id/enhanced/ExportableColumnHelper.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
class ExportableColumnHelper {
2525

2626
static Column column(Database database, Table table, String segmentColumnName, BasicType<?> type, String typeName) {
27-
final Column column = new Column( segmentColumnName );
27+
final var column = new Column( segmentColumnName );
2828
column.setSqlType( typeName );
2929
column.setValue( new Value() {
3030
@Override

hibernate-core/src/main/java/org/hibernate/id/enhanced/SequenceStructure.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,9 @@ public void registerExtraExportables(Table table, Optimizer optimizer) {
177177
final int adjustment = optimizer.getAdjustment();
178178
final long max = getMaxPrimaryKey( connection, primaryKeyColumnName, tableName );
179179
final long current = getNextSequenceValue( connection, sequenceName, context.getDialect() );
180-
final long newValue = Math.max( max + adjustment, current );
181-
final String restart = "alter sequence " + sequenceName + " restart with " + newValue;
182-
return new InitCommand( restart );
180+
final long startWith = Math.max( max + adjustment, current );
181+
return new InitCommand( context.getDialect().getSequenceSupport()
182+
.getRestartSequenceString( sequenceName, startWith ) );
183183
} );
184184
}
185185

0 commit comments

Comments
 (0)