Module io.ebean.api

Class DbPlatformType

java.lang.Object
io.ebean.config.dbplatform.DbPlatformType
All Implemented Interfaces:
ExtraDbTypes

public class DbPlatformType extends Object implements ExtraDbTypes
Represents a DB type with name, length, precision, and scale.

The length is for VARCHAR types and precision/scale for DECIMAL types.

  • Constructor Details

    • DbPlatformType

      public DbPlatformType(String name)
      Construct with no length or scale.
    • DbPlatformType

      public DbPlatformType(String name, int defaultLength)
      Construct with a given length.
    • DbPlatformType

      public DbPlatformType(String name, int defaultPrecision, int defaultScale)
      Construct for Decimal with precision and scale.
    • DbPlatformType

      public DbPlatformType(String name, boolean canHaveLength)
      Use with canHaveLength=false for types that should never have a length.
      Parameters:
      name - the type name
      canHaveLength - set this to false for type that should never have a length
  • Method Details

    • parse

      public static DbPlatformType parse(String columnDefinition)
      Parse a type definition into a DbPlatformType.

      e.g. "decimal(18,6)" e.g. "text"

    • getName

      public String getName()
      Return the type name.
    • getDefaultLength

      public int getDefaultLength()
      Return the default length/precision.
    • getDefaultScale

      public int getDefaultScale()
      Return the default scale.
    • renderType

      public String renderType(int deployLength, int deployScale)
      Return the type for a specific property that incorporates the name, length, precision and scale.

      The deployLength and deployScale are for the property we are rendering the DB type for.

      Parameters:
      deployLength - the length or precision defined by deployment on a specific property.
      deployScale - the scale defined by deployment on a specific property.
    • renderType

      public String renderType(int deployLength, int deployScale, boolean strict)
      Render the type defining strict mode.

      If strict mode if OFF then this will render with a scale value even if that is not strictly supported. The reason for supporting this is to enable use to use types like jsonb(200) as a "logical" type that maps to JSONB for Postgres and VARCHAR(200) for other databases.

    • renderLengthScale

      protected void renderLengthScale(int deployLength, int deployScale, StringBuilder sb)
      Render the length and scale part of the column definition.
    • withLength

      public DbPlatformType withLength(int defaultLength)
      Create a copy of the type with a new default length.