Module io.ebean.api

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 Details

  • Constructor Details

    • DbDefaultValue

      public DbDefaultValue()
  • 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!