Skip to content

Commit 9fce4e6

Browse files
committed
change Identifier.quote() to an instance method
1 parent f01bcc0 commit 9fce4e6

File tree

6 files changed

+23
-14
lines changed

6 files changed

+23
-14
lines changed

hibernate-community-dialects/src/main/java/org/hibernate/community/dialect/HANALegacyDialect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ public Identifier normalizeQuoting(Identifier identifier) {
965965

966966
// need to quote names containing special characters like ':'
967967
if ( !normalizedIdentifier.isQuoted() && !normalizedIdentifier.getText().matches( "\\w+" ) ) {
968-
normalizedIdentifier = Identifier.quote( normalizedIdentifier );
968+
normalizedIdentifier = normalizedIdentifier.quoted();
969969
}
970970

971971
return normalizedIdentifier;

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -488,15 +488,15 @@ private static Identifier quoteIfNecessary(
488488
boolean isRefColumnQuoted, Identifier logicalTableName, Identifier columnIdentifier) {
489489
return !columnIdentifier.isQuoted()
490490
&& ( isRefColumnQuoted || logicalTableName.isQuoted() )
491-
? Identifier.quote( columnIdentifier )
491+
? columnIdentifier.quoted()
492492
: columnIdentifier;
493493
}
494494

495495
private static Identifier quoteIfNecessary(
496496
boolean isRefColumnQuoted, String logicalTableName, Identifier columnIdentifier) {
497497
//one element was quoted so we quote
498498
return isRefColumnQuoted || isQuoted( logicalTableName )
499-
? Identifier.quote( columnIdentifier )
499+
? columnIdentifier.quoted()
500500
: columnIdentifier;
501501
}
502502

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -263,7 +263,7 @@ public MetadataBuildingContext getBuildingContext() {
263263
}
264264

265265
if ( ownerEntityTableQuoted || associatedEntityTableQuoted ) {
266-
name = Identifier.quote( name );
266+
name = name.quoted();
267267
}
268268

269269
return name;

hibernate-core/src/main/java/org/hibernate/boot/model/naming/Identifier.java

Lines changed: 17 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,13 @@ public boolean isQuoted() {
222222
return isQuoted;
223223
}
224224

225+
/**
226+
* A quoted form of this identifier.
227+
*/
228+
public Identifier quoted() {
229+
return isQuoted ? this : toIdentifier( text, true );
230+
}
231+
225232
/**
226233
* If this is a quoted identifier, then return the identifier name
227234
* enclosed in dialect-specific open- and end-quotes; otherwise,
@@ -272,18 +279,20 @@ public int hashCode() {
272279
: text.toLowerCase( Locale.ENGLISH ).hashCode();
273280
}
274281

282+
@Override
283+
public int compareTo(Identifier identifier) {
284+
return getCanonicalName().compareTo( identifier.getCanonicalName() );
285+
}
286+
275287
public static boolean areEqual(Identifier id1, Identifier id2) {
276288
return Objects.equals( id1, id2 );
277289
}
278290

291+
/**
292+
* @deprecated Use {@link #quoted()}.
293+
*/
294+
@Deprecated(since = "7.1", forRemoval = true)
279295
public static Identifier quote(Identifier identifier) {
280-
return identifier.isQuoted()
281-
? identifier
282-
: Identifier.toIdentifier( identifier.getText(), true );
283-
}
284-
285-
@Override
286-
public int compareTo(Identifier identifier) {
287-
return getCanonicalName().compareTo( identifier.getCanonicalName() );
296+
return identifier.quoted();
288297
}
289298
}

hibernate-core/src/main/java/org/hibernate/boot/model/naming/ImplicitNamingStrategyLegacyJpaImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ public Identifier determineCollectionTableName(ImplicitCollectionTableNameSource
3131
+ "_" + transformAttributePath( source.getOwningAttributePath() ),
3232
source.getBuildingContext()
3333
);
34-
return owningPhysicalTableName.isQuoted() ? Identifier.quote( identifier ) : identifier;
34+
return owningPhysicalTableName.isQuoted() ? identifier.quoted() : identifier;
3535
}
3636

3737
@Override

hibernate-core/src/main/java/org/hibernate/dialect/HANADialect.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -976,7 +976,7 @@ public Identifier normalizeQuoting(Identifier identifier) {
976976

977977
// need to quote names containing special characters like ':'
978978
if ( !normalizedIdentifier.isQuoted() && !normalizedIdentifier.getText().matches( "\\w+" ) ) {
979-
normalizedIdentifier = Identifier.quote( normalizedIdentifier );
979+
normalizedIdentifier = normalizedIdentifier.quoted();
980980
}
981981

982982
return normalizedIdentifier;

0 commit comments

Comments
 (0)