Class DbDefaultValue

java.lang.Object
io.ebean.config.dbplatform.DbDefaultValue

public class DbDefaultValue extends Object
DB Column default values mapping to database platform specific literals.
  • Field Summary

    Fields
    Modifier and Type
    Field
    Description
    static final String
    The key for FALSE.
    static final String
    The key for the NOW / current timestamp.
    static final String
    The 'null' literal.
    static final String
    The key for TRUE.
  • Constructor Summary

    Constructors
    Constructor
    Description
     
  • Method Summary

    Modifier and Type
    Method
    Description
    convert(String dbDefaultLiteral)
    Convert the DB default literal to platform specific type or function.
    void
    put(String dbLiteral, String dbTranslated)
    Add an translation entry.
    void
    setFalse(String dbFalseLiteral)
    Set the DB false literal.
    void
    setNow(String dbFunction)
    Set the DB now function.
    void
    setTrue(String dbTrueLiteral)
    Set the DB true literal.
    static String
    toSqlLiteral(String defaultValue, Class<?> propertyType, int sqlType)
    This method checks and converts the DbDefault.value() to a valid SQL literal.

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Field Details

  • Constructor Details

  • Method Details

    • setNow

      public void setNow(String dbFunction)
      Set the DB now function.
    • setFalse

      public void setFalse(String dbFalseLiteral)
      Set the DB false literal.
    • setTrue

      public void setTrue(String dbTrueLiteral)
      Set the DB true literal.
    • put

      public void put(String dbLiteral, String dbTranslated)
      Add an translation entry.
    • convert

      public String convert(String dbDefaultLiteral)
      Convert the DB default literal to platform specific type or function.

      This is intended for the DB column default clause in DDL.

    • toSqlLiteral

      public static String toSqlLiteral(String defaultValue, Class<?> propertyType, int sqlType)
      This method checks and converts the DbDefault.value() to a valid SQL literal. This is mainly to quote string literals and verify integer/dates for correctness.

      Note: There are some special cases:

      • Normal Quoting: @DbDefault("User's default") on a String propery returns: default 'User''s default'
        (the same on an integer property will throw a NumberFormatException)
      • Special case null: @DbDefault("null") will return this: default null
        If you need really the String "null", you have to specify @DbDefault("'null'") which gives you the default 'null' statement.
      • Any statement, that begins and ends with single quote will not be checked or get quoted again.
      • A statement that begins with "$RAW:", e.g @DbDefault("$RAW:N'SANDNES'") will lead to a default N'SANDNES' in DDL. Note that this is platform specific!