Skip to content

PartitionKey jdoc and fix to DDL formatting #10519

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 12, 2025
Merged
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
Expand Up @@ -12,12 +12,50 @@
import static java.lang.annotation.RetentionPolicy.RUNTIME;

/**
* Identifies a field of an entity that holds the partition key of a table.
* Identifies a field of an entity that holds the
* partition key of a table mapped by the entity
* class.
* <p>
* If the partition key forms part of the unique
* {@linkplain jakarta.persistence.Id identifier}
* of the entity, this annotation is optional but
* may still be applied for documentation purposes.
* <p>
* On the other hand, if the partition key is not
* part of the identifier, use of this annotation
* may improve the performance of SQL {@code update}
* and {@code delete} statements.
* <p>
* <pre>
* &#064;Entity
* &#064;Table(name = "partitioned_table",
* options =
* """
* partition by range (pid) (
* partition p1 values less than (1000),
* partition p2 values less than (2000)
* )
* """)
* class Partitioned {
* &#064;Id &#064;GeneratedValue Long id;
* &#064;PartitionKey Long pid;
* String text;
* }
* </pre>
* Many databases are not able to maintain a unique
* key constraint across multiple partitions unless
* the unique key contains the partition key column.
* On these databases, the column mapped by a field
* annotated {@code @PartitionKey} is automatically
* added to the generated primary key constraint.
* In this case, the database is not able to enforce
* uniqueness of the identifier value, and care must
* be taken to ensure that the identifier is unique
* across entity instances.
*
* @since 6.2
*/
@Target({METHOD, FIELD})
@Retention(RUNTIME)
public @interface PartitionKey {

}
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,9 @@ else if ( lowerCaseSql.startsWith( "comment on" ) ) {

private String formatCommentOn(String sql) {
final StringBuilder result = new StringBuilder( 60 ).append( INITIAL_LINE );
final StringTokenizer tokens = new StringTokenizer( sql, " '[]\"", true );
final StringTokenizer tokens =
new StringTokenizer( sql.replace('\n',' '),
" '[]\"", true );

boolean quoted = false;
while ( tokens.hasMoreTokens() ) {
Expand All @@ -79,7 +81,9 @@ else if ( !quoted ) {

private String formatAlterTable(String sql) {
final StringBuilder result = new StringBuilder( 60 ).append( INITIAL_LINE );
final StringTokenizer tokens = new StringTokenizer( sql, " (,)'[]\"", true );
final StringTokenizer tokens =
new StringTokenizer( sql.replace('\n',' '),
" (,)'[]\"", true );

boolean first = true;
boolean quoted = false;
Expand All @@ -102,7 +106,9 @@ else if ( !quoted ) {

private String formatCreateTable(String sql) {
final StringBuilder result = new StringBuilder( 60 ).append( INITIAL_LINE );
final StringTokenizer tokens = new StringTokenizer( sql, "(,)'[]\"", true );
final StringTokenizer tokens =
new StringTokenizer( sql.replace('\n',' '),
"(,)'[]\"", true );

int depth = 0;
boolean quoted = false;
Expand Down