Package io.ebean.config.dbplatform
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.
-
-
Constructor Summary
Constructors Constructor Description DbDefaultValue()
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description String
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 theDbDefault.value()
to a valid SQL literal.
-
-
-
Field Detail
-
FALSE
public static final String FALSE
The key for FALSE.- See Also:
- Constant Field Values
-
TRUE
public static final String TRUE
The key for TRUE.- See Also:
- Constant Field Values
-
NOW
public static final String NOW
The key for the NOW / current timestamp.- See Also:
- Constant Field Values
-
NULL
public static final String NULL
The 'null' literal.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
DbDefaultValue
public DbDefaultValue()
-
-
Method Detail
-
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 theDbDefault.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 thedefault '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 adefault N'SANDNES'
in DDL. Note that this is platform specific!
- Normal Quoting:
-
-