public class TimeType extends LiquibaseDataType {
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof InformixDatabase) {
return new DatabaseDataType("INTERVAL HOUR TO FRACTION", 5);
}
if (database instanceof MSSQLDatabase) {
try {
if (database.getDatabaseMajorVersion() <= 9) {
return new DatabaseDataType("DATETIME");
}
} catch (DatabaseException e) {
//assume greater than sql 2008 and TIME will work
}
}
if (database instanceof MySQLDatabase) {
boolean supportsParameters = true;
try {
supportsParameters = database.getDatabaseMajorVersion() >= 5
&& database.getDatabaseMinorVersion() >= 6
&& ((MySQLDatabase) database).getDatabasePatchVersion() >= 4;
} catch (Exception ignore) {
//assume supports parameters
}
if (supportsParameters && getParameters().length > 0 && Integer.valueOf(getParameters()[0].toString()) <= 6) {
return new DatabaseDataType(getName(), getParameters());
} else {
return new DatabaseDataType(getName());
}
}
if (database instanceof OracleDatabase) {
return new DatabaseDataType("DATE");
}
if (database instanceof PostgresDatabase) {
String rawDefinition = getRawDefinition().toLowerCase();
if (rawDefinition.contains("tz") || rawDefinition.contains("with time zone")) {
return new DatabaseDataType("TIME WITH TIME ZONE");
} else {
return new DatabaseDataType("TIME WITHOUT TIME ZONE");
}
}
return new DatabaseDataType(getName());
}