Package liquibase.datatype
Class LiquibaseDataType
- java.lang.Object
-
- liquibase.datatype.LiquibaseDataType
-
- All Implemented Interfaces:
PrioritizedService
- Direct Known Subclasses:
BigIntType
,BinaryTypeSnowflake
,BlobType
,BooleanType
,CharType
,ClobType
,ClobTypeSnowflake
,CurrencyType
,DatabaseFunctionType
,DataTypeWrapper
,DateTimeType
,DateType
,DecimalType
,DoubleType
,FloatType
,IntType
,MediumIntType
,NumberType
,SmallIntType
,TextDataTypeSnowflake
,TimestampNTZTypeSnowflake
,TimeType
,TinyIntType
,UnknownType
,UUIDType
,XMLType
public abstract class LiquibaseDataType extends Object implements PrioritizedService
Object representing a data type, instead of a plain string. It will be returned by the getXXXType in the Database interface.
-
-
Field Summary
-
Fields inherited from interface liquibase.servicelocator.PrioritizedService
COMPARATOR, PRIORITY_DATABASE, PRIORITY_DEFAULT
-
-
Constructor Summary
Constructors Modifier Constructor Description LiquibaseDataType()
protected
LiquibaseDataType(String name, int minParameters, int maxParameters)
protected
LiquibaseDataType(LiquibaseDataType originalType)
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addParameter(Object value)
Adds an object to the list of this data type's parameters.boolean
equals(Object o)
void
finishInitialization(String originalDefinition)
protected String
formatNumber(String value)
Removes any trailing ".0[...]0" from the end of a numberprotected String
functionToSql(DatabaseFunction function, Database database)
String
getAdditionalInformation()
Returns additional information that was stored duringDataTypeFactory.fromDescription(String, Database)
or other parsers.String[]
getAliases()
abstract LoadDataChange.LOAD_DATA_TYPE
getLoadTypeName()
Returns one of the four basic data types for use in LoadData: BOOLEAN, NUMERIC, DATE or STRINGint
getMaxParameters(Database database)
int
getMinParameters(Database database)
String
getName()
Object[]
getParameters()
Returns an array with the parameters to the data type, e.g.int
getPriority()
String
getRawDefinition()
Obtains the "raw" data type definition if one was used to create this object as a result of parsingint
hashCode()
boolean
isAutoIncrement()
protected boolean
isCurrentDateTimeFunction(String string, Database database)
Determines if the given function name refers to the function that returns the current time and date for a specific DBMS.protected String
numberToSql(Number number, Database database)
String
objectToSql(Object value, Database database)
Returns the value object in a format to include in SQL.protected String
otherToSql(Object value, Database database)
void
setAdditionalInformation(String additionalInformation)
Object
sqlToObject(String value, Database database)
boolean
supports(Database database)
DatabaseDataType
toDatabaseDataType(Database database)
Transforms this data type into the native data type of the target DBMS.String
toString()
boolean
validate(Database database)
Validates the correct state of this data type against a given database.
-
-
-
Constructor Detail
-
LiquibaseDataType
protected LiquibaseDataType(LiquibaseDataType originalType)
-
LiquibaseDataType
public LiquibaseDataType()
-
LiquibaseDataType
protected LiquibaseDataType(String name, int minParameters, int maxParameters)
-
-
Method Detail
-
getName
public String getName()
-
getAliases
public String[] getAliases()
-
getPriority
public int getPriority()
- Specified by:
getPriority
in interfacePrioritizedService
-
supports
public boolean supports(Database database)
-
getMinParameters
public int getMinParameters(Database database)
-
getMaxParameters
public int getMaxParameters(Database database)
-
getParameters
public Object[] getParameters()
Returns an array with the parameters to the data type, e.g. NUMBER(10, 2) would return an array with the items 10 and 2.- Returns:
- An array with the parameters. May contain 0 items.
-
addParameter
public void addParameter(Object value)
Adds an object to the list of this data type's parameters. Note that it is possible to temporarily exceed the allowed number of allowed parameters untilvalidate(Database)
is called, because the number of allowed parameters might differ between DBMS.- Parameters:
value
- the new value to add as parameter.
-
getAdditionalInformation
public String getAdditionalInformation()
Returns additional information that was stored duringDataTypeFactory.fromDescription(String, Database)
or other parsers.- Returns:
- the additional information. Might be null.
-
setAdditionalInformation
public void setAdditionalInformation(String additionalInformation)
-
getRawDefinition
public String getRawDefinition()
Obtains the "raw" data type definition if one was used to create this object as a result of parsing- Returns:
- the raw definition, or null.
-
validate
public boolean validate(Database database)
Validates the correct state of this data type against a given database.- Parameters:
database
- the database to validate against- Returns:
- true if the current settings for this data type can be implemented on the given database, false otherwise
-
toDatabaseDataType
public DatabaseDataType toDatabaseDataType(Database database)
Transforms this data type into the native data type of the target DBMS.- Parameters:
database
- theDatabase
for which the native data type is to be constructed- Returns:
- the new, native data type
-
objectToSql
public String objectToSql(Object value, Database database)
Returns the value object in a format to include in SQL. Quote if necessary.
-
functionToSql
protected String functionToSql(DatabaseFunction function, Database database)
-
isCurrentDateTimeFunction
protected boolean isCurrentDateTimeFunction(String string, Database database)
Determines if the given function name refers to the function that returns the current time and date for a specific DBMS. Also returns true if the name returns the Liquibase wildcard CURRENT_DATE_TIME_PLACE_HOLDER, which will later be translated into the appropriate function.- Parameters:
string
- The database function name to testdatabase
- A database object to test against- Returns:
- see above
-
finishInitialization
public void finishInitialization(String originalDefinition)
-
formatNumber
protected String formatNumber(String value)
Removes any trailing ".0[...]0" from the end of a number- Parameters:
value
- the number (in String form) to format- Returns:
- the formatted number
-
getLoadTypeName
public abstract LoadDataChange.LOAD_DATA_TYPE getLoadTypeName()
Returns one of the four basic data types for use in LoadData: BOOLEAN, NUMERIC, DATE or STRING- Returns:
- one of the above Strings
-
isAutoIncrement
public boolean isAutoIncrement()
-
-