use of liquibase.datatype.DatabaseDataType in project liquibase by liquibase.
the class MediumIntType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof MSSQLDatabase) {
return new DatabaseDataType(database.escapeDataTypeName("int"));
}
if (database instanceof MySQLDatabase) {
DatabaseDataType type = new DatabaseDataType("MEDIUMINT");
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
if (database instanceof DB2Database || database instanceof DerbyDatabase || database instanceof FirebirdDatabase) {
//always smallint regardless of parameters passed
return new DatabaseDataType("MEDIUMINT");
}
return super.toDatabaseDataType(database);
}
use of liquibase.datatype.DatabaseDataType in project liquibase by liquibase.
the class NCharType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof HsqlDatabase) {
return new DatabaseDataType("CHAR", getParameters());
}
if (database instanceof OracleDatabase) {
return new DatabaseDataType("NCHAR", getParameters());
}
if (database instanceof MSSQLDatabase) {
Object[] parameters = getParameters();
if (parameters.length > 0) {
String param1 = parameters[0].toString();
if (!param1.matches("\\d+") || new BigInteger(param1).compareTo(BigInteger.valueOf(4000)) > 0) {
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("nchar"), 4000);
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
}
if (parameters.length == 0) {
parameters = new Object[] { 1 };
} else if (parameters.length > 1) {
parameters = Arrays.copyOfRange(parameters, 0, 1);
}
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("nchar"), parameters);
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
return super.toDatabaseDataType(database);
}
use of liquibase.datatype.DatabaseDataType in project liquibase by liquibase.
the class CharType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof MSSQLDatabase) {
Object[] parameters = getParameters();
if (parameters.length > 0) {
String param1 = parameters[0].toString();
if (!param1.matches("\\d+") || new BigInteger(param1).compareTo(BigInteger.valueOf(8000)) > 0) {
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("char"), 8000);
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
}
if (parameters.length == 0) {
parameters = new Object[] { 1 };
} else if (parameters.length > 1) {
parameters = Arrays.copyOfRange(parameters, 0, 1);
}
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("char"), parameters);
type.addAdditionalInformation(getAdditionalInformation());
return type;
} else if (database instanceof PostgresDatabase) {
if (getParameters() != null && getParameters().length == 1 && getParameters()[0].toString().equals("2147483647")) {
DatabaseDataType type = new DatabaseDataType("CHARACTER");
type.addAdditionalInformation("VARYING");
return type;
}
return super.toDatabaseDataType(database);
}
return super.toDatabaseDataType(database);
}
use of liquibase.datatype.DatabaseDataType in project liquibase by liquibase.
the class ClobType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
String originalDefinition = StringUtils.trimToEmpty(getRawDefinition());
if (database instanceof MSSQLDatabase) {
if (!LiquibaseConfiguration.getInstance().getProperty(GlobalConfiguration.class, GlobalConfiguration.CONVERT_DATA_TYPES).getValue(Boolean.class) && originalDefinition.toLowerCase().startsWith("text")) {
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("text"));
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
}
if (database instanceof FirebirdDatabase) {
return new DatabaseDataType("BLOB SUB_TYPE TEXT");
} else if (database instanceof SybaseASADatabase) {
return new DatabaseDataType("LONG VARCHAR");
} else if (database instanceof MSSQLDatabase) {
if (originalDefinition.equalsIgnoreCase("text") || originalDefinition.equals("[text]") || originalDefinition.matches("(?i)text .+") || originalDefinition.matches("\\[text\\] .+")) {
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("text"));
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
if (originalDefinition.toLowerCase().startsWith("ntext") || originalDefinition.toLowerCase().startsWith("[ntext]")) {
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("ntext"));
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
if (originalDefinition.equalsIgnoreCase("nclob")) {
try {
if (database.getDatabaseMajorVersion() <= 8) {
//2000 or earlier
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("ntext"));
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
} catch (DatabaseException ignore) {
}
return new DatabaseDataType(database.escapeDataTypeName("nvarchar"), "MAX");
}
try {
if (database.getDatabaseMajorVersion() <= 8) {
//2000 or earlier
DatabaseDataType type = new DatabaseDataType(database.escapeDataTypeName("text"));
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
} catch (DatabaseException ignore) {
}
return new DatabaseDataType(database.escapeDataTypeName("varchar"), "MAX");
} else if (database instanceof MySQLDatabase) {
if (originalDefinition.toLowerCase().startsWith("text")) {
return new DatabaseDataType("TEXT");
} else if (originalDefinition.toLowerCase().startsWith("tinytext")) {
return new DatabaseDataType("TINYTEXT");
} else if (originalDefinition.toLowerCase().startsWith("mediumtext")) {
return new DatabaseDataType("MEDIUMTEXT");
} else if (originalDefinition.toLowerCase().startsWith("nclob")) {
DatabaseDataType type = new DatabaseDataType("LONGTEXT");
type.addAdditionalInformation("CHARACTER SET utf8");
return type;
} else {
return new DatabaseDataType("LONGTEXT");
}
} else if (database instanceof H2Database || database instanceof HsqlDatabase) {
if (originalDefinition.toLowerCase().startsWith("longvarchar") || originalDefinition.startsWith("java.sql.Types.LONGVARCHAR")) {
return new DatabaseDataType("LONGVARCHAR");
} else {
return new DatabaseDataType("CLOB");
}
} else if (database instanceof PostgresDatabase || database instanceof SQLiteDatabase || database instanceof SybaseDatabase) {
return new DatabaseDataType("TEXT");
} else if (database instanceof OracleDatabase) {
if (originalDefinition.equalsIgnoreCase("nclob")) {
return new DatabaseDataType("NCLOB");
}
return new DatabaseDataType("CLOB");
} else if (database instanceof InformixDatabase) {
if (originalDefinition.toLowerCase().startsWith("text")) {
return new DatabaseDataType("TEXT");
}
}
return super.toDatabaseDataType(database);
}
use of liquibase.datatype.DatabaseDataType in project liquibase by liquibase.
the class IntType method toDatabaseDataType.
@Override
public DatabaseDataType toDatabaseDataType(Database database) {
if (database instanceof InformixDatabase && isAutoIncrement()) {
return new DatabaseDataType("SERIAL");
}
if (database instanceof DB2Database || database instanceof DerbyDatabase || database instanceof OracleDatabase) {
return new DatabaseDataType("INTEGER");
}
if (database instanceof PostgresDatabase) {
if (autoIncrement) {
return new DatabaseDataType("SERIAL");
}
}
if (database instanceof MSSQLDatabase) {
return new DatabaseDataType(database.escapeDataTypeName("int"));
}
if (database instanceof MySQLDatabase) {
DatabaseDataType type = new DatabaseDataType("INT");
type.addAdditionalInformation(getAdditionalInformation());
return type;
}
if (database instanceof HsqlDatabase || database instanceof FirebirdDatabase || database instanceof InformixDatabase) {
return new DatabaseDataType("INT");
}
if (database instanceof SQLiteDatabase) {
return new DatabaseDataType("INTEGER");
}
return super.toDatabaseDataType(database);
//sqllite
// if (columnTypeString.equals("INTEGER") ||
// columnTypeString.toLowerCase(Locale.ENGLISH).contains("int") ||
// columnTypeString.toLowerCase(Locale.ENGLISH).contains("bit")) {
// type = new IntType("INTEGER");
}
Aggregations