Record Class ColumnModel

java.lang.Object
java.lang.Record
com.onec.schema.ColumnModel
Record Components:
name - column name (already through the naming strategy)
sqlType - declared SQL type, e.g. VARCHAR(100) or DECIMAL(15,2)
primaryKey - rendered as an inline PRIMARY KEY
notNull - rendered as NOT NULL; on existing tables the upgrader backfills before enforcing (see DdlRenderer.addColumn(java.lang.String, com.onec.schema.ColumnModel))
defaultExpr - SQL default expression (e.g. FALSE, 0, 'NEW'), or null
references - inline FK target like document_invoices(_id), or null
previousNames - former column names, in priority order, for rename detection

public record ColumnModel(String name, String sqlType, boolean primaryKey, boolean notNull, String defaultExpr, String references, List<String> previousNames) extends Record
Desired state of a single column, derived from metadata. This is what the SchemaGenerator renders into CREATE TABLE statements and what the SchemaDiffEngine compares against the live database.
  • Constructor Details

    • ColumnModel

      public ColumnModel(String name, String sqlType, boolean primaryKey, boolean notNull, String defaultExpr, String references, List<String> previousNames)
      Creates an instance of a ColumnModel record class.
      Parameters:
      name - the value for the name record component
      sqlType - the value for the sqlType record component
      primaryKey - the value for the primaryKey record component
      notNull - the value for the notNull record component
      defaultExpr - the value for the defaultExpr record component
      references - the value for the references record component
      previousNames - the value for the previousNames record component
  • Method Details

    • of

      public static ColumnModel of(String name, String sqlType)
    • primaryKey

      public static ColumnModel primaryKey(String name, String sqlType)
    • withDefault

      public static ColumnModel withDefault(String name, String sqlType, String defaultExpr)
    • asNotNull

      public ColumnModel asNotNull()
    • toString

      public final String toString()
      Returns a string representation of this record class. The representation contains the name of the class, followed by the name and value of each of the record components.
      Specified by:
      toString in class Record
      Returns:
      a string representation of this object
    • hashCode

      public final int hashCode()
      Returns a hash code value for this object. The value is derived from the hash code of each of the record components.
      Specified by:
      hashCode in class Record
      Returns:
      a hash code value for this object
    • equals

      public final boolean equals(Object o)
      Indicates whether some other object is "equal to" this one. The objects are equal if the other object is of the same class and if all the record components are equal. Reference components are compared with Objects::equals(Object,Object); primitive components are compared with '=='.
      Specified by:
      equals in class Record
      Parameters:
      o - the object with which to compare
      Returns:
      true if this object is the same as the o argument; false otherwise.
    • name

      public String name()
      Returns the value of the name record component.
      Returns:
      the value of the name record component
    • sqlType

      public String sqlType()
      Returns the value of the sqlType record component.
      Returns:
      the value of the sqlType record component
    • primaryKey

      public boolean primaryKey()
      Returns the value of the primaryKey record component.
      Returns:
      the value of the primaryKey record component
    • notNull

      public boolean notNull()
      Returns the value of the notNull record component.
      Returns:
      the value of the notNull record component
    • defaultExpr

      public String defaultExpr()
      Returns the value of the defaultExpr record component.
      Returns:
      the value of the defaultExpr record component
    • references

      public String references()
      Returns the value of the references record component.
      Returns:
      the value of the references record component
    • previousNames

      public List<String> previousNames()
      Returns the value of the previousNames record component.
      Returns:
      the value of the previousNames record component