Package st.orm

Enum Class GenerationStrategy

All Implemented Interfaces:
Serializable, Comparable<GenerationStrategy>, Constable

public enum GenerationStrategy extends Enum<GenerationStrategy>
Defines the strategy to use when generating values for primary keys.

The generation strategy is specified via the PK.generation() attribute.

Java:


 record User(@PK(generation = IDENTITY) Integer id,
             String name
 ) implements Entity<Integer> {}
 

Kotlin:


 data class User(@PK(generation = IDENTITY) val id: Int?,
                 val name: String
 ) : Entity<Int>
 
Since:
1.6
See Also:
  • Enum Constant Details

    • NONE

      public static final GenerationStrategy NONE
      No primary key generation is applied. The caller must provide the key value when inserting.

      Use this strategy when:

      • The key is a natural key (e.g., country codes, UUIDs)
      • The key comes from an external source
      • The primary key is also a foreign key (dependent one-to-one relationship)

      Example with natural key (Java):

      
       record Country(@PK(generation = NONE) String code,
                      String name
       ) implements Entity<String> {}
       

      Example with natural key (Kotlin):

      
       data class Country(@PK(generation = NONE) val code: String,
                          val name: String
       ) : Entity<String>
       

      Example with primary key as foreign key (Java):

      
       record UserProfile(@PK(generation = NONE) @FK User user,
                          String bio
       ) implements Entity<User> {}
       

      Example with primary key as foreign key (Kotlin):

      
       data class UserProfile(@PK(generation = NONE) @FK val user: User,
                              val bio: String
       ) : Entity<User>
       
    • IDENTITY

      public static final GenerationStrategy IDENTITY
      The primary key is generated by the database using an identity or auto-increment column.

      This is the default strategy. When inserting, Storm omits the primary key column from the INSERT statement and retrieves the generated value after the insert completes.

      Java:

      
       record User(@PK Integer id,  // generation = IDENTITY is the default
                   String name
       ) implements Entity<Integer> {}
       

      Kotlin:

      
       data class User(@PK val id: Int?,  // generation = IDENTITY is the default
                       val name: String
       ) : Entity<Int>
       
    • SEQUENCE

      public static final GenerationStrategy SEQUENCE
      The primary key is generated using a database sequence.

      When inserting, Storm fetches the next value from the sequence before executing the INSERT statement. The sequence name must be specified via PK.sequence().

      Java:

      
       record Order(@PK(generation = SEQUENCE, sequence = "order_seq") Long id,
                    BigDecimal total
       ) implements Entity<Long> {}
       

      Kotlin:

      
       data class Order(@PK(generation = SEQUENCE, sequence = "order_seq") val id: Long?,
                        val total: BigDecimal
       ) : Entity<Long>
       
  • Method Details

    • values

      public static GenerationStrategy[] values()
      Returns an array containing the constants of this enum class, in the order they are declared.
      Returns:
      an array containing the constants of this enum class, in the order they are declared
    • valueOf

      public static GenerationStrategy valueOf(String name)
      Returns the enum constant of this class with the specified name. The string must match exactly an identifier used to declare an enum constant in this class. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum class has no constant with the specified name
      NullPointerException - if the argument is null