Package liquibase.datatype

Examples of liquibase.datatype.DatabaseDataType


    @Test
    public void varchar2ForHsqldbInOracleSyntaxMode() {
        VarcharType type = new VarcharType();
        HsqlDatabase hsqlDatabase = mock(HsqlDatabase.class);
        when(hsqlDatabase.isUsingOracleSyntax()).thenReturn(true);
        DatabaseDataType databaseDataType = type.toDatabaseDataType(hsqlDatabase);
        assertEquals("VARCHAR2", databaseDataType.getType().toUpperCase());
    }
View Full Code Here


    @Test
    public void varcharForHsqldbNotInOracleSyntaxMode() {
        VarcharType type = new VarcharType();
        HsqlDatabase hsqlDatabase = mock(HsqlDatabase.class);
        when(hsqlDatabase.isUsingOracleSyntax()).thenReturn(false);
        DatabaseDataType databaseDataType = type.toDatabaseDataType(hsqlDatabase);
        assertEquals("VARCHAR", databaseDataType.getType().toUpperCase());
    }
View Full Code Here

                || database instanceof HsqlDatabase
                || database instanceof DerbyDatabase
                || database instanceof FirebirdDatabase
                || database instanceof SybaseASADatabase
                || database instanceof SybaseDatabase) {
            return new DatabaseDataType("numeric", getParameters());
        } else if (database instanceof OracleDatabase) {
            if (getParameters().length > 1 && getParameters()[0].equals("0") && getParameters()[1].equals("-127")) {
                return new DatabaseDataType("NUMBER");
            } else {
                return new DatabaseDataType("NUMBER", getParameters());
            }
        } else if (database instanceof PostgresDatabase) {
            if (getParameters().length > 0 && Integer.valueOf(getParameters()[0].toString()) > 1000) {
                return new DatabaseDataType("numeric");
            }
            return new DatabaseDataType("numeric", getParameters());
        }
        return super.toDatabaseDataType(database);
    }
View Full Code Here

public class NCharType extends CharType {

    @Override
    public DatabaseDataType toDatabaseDataType(Database database) {
        if (database instanceof HsqlDatabase) {
            return new DatabaseDataType("CHAR", getParameters());
        }
        if (database instanceof OracleDatabase) {
            return new DatabaseDataType("NCHAR", getParameters());
        }
        return super.toDatabaseDataType(database);
    }
View Full Code Here

public class NVarcharType extends CharType {

    @Override
    public DatabaseDataType toDatabaseDataType(Database database) {
        if (database instanceof HsqlDatabase || database instanceof PostgresDatabase|| database instanceof DerbyDatabase) {
            return new DatabaseDataType("VARCHAR", getParameters());
        }
        if (database instanceof OracleDatabase) {
            return new DatabaseDataType("NVARCHAR2", getParameters());
        }
        if (database instanceof MSSQLDatabase) {
            if (getParameters() != null && getParameters().length > 0) {
                Object param1 = getParameters()[0];
                if (param1.toString().matches("\\d+")) {
                    if (Long.valueOf(param1.toString()) > 8000) {
                        return new DatabaseDataType("NVARCHAR", "MAX");
                    }
                }
            }
            return new DatabaseDataType("NVARCHAR", getParameters());
        }
        return super.toDatabaseDataType(database);
    }
View Full Code Here

      if(getParameters() != null && getParameters().length == 2) {

        // Don't use 255 as a scale because it is invalid,
        // use only 1 argument in this special case
        if("255".equals(String.valueOf(getParameters()[1]))) {
          return new DatabaseDataType(getName(), getParameters()[0]);
        }
      }
    }

    return super.toDatabaseDataType(database);
View Full Code Here

    public DatabaseDataType toDatabaseDataType(Database database) {
        String originalDefinition = StringUtils.trimToEmpty(getRawDefinition());

        if (database instanceof H2Database || database instanceof HsqlDatabase) {
            if (originalDefinition.toLowerCase().startsWith("longvarbinary") || originalDefinition.startsWith("java.sql.Types.LONGVARBINARY")) {
                return new DatabaseDataType("LONGVARBINARY");
            } else {
                return new DatabaseDataType("BLOB");
            }
        }

        if (database instanceof MSSQLDatabase) {
            String param = "MAX";
            if (this.getParameters().length > 0) {
                param = this.getParameters()[0].toString();
            }
            if (param.equals("2147483647")) {
                param = "MAX";
            }
            return new DatabaseDataType("VARBINARY", param);
        }
        if (database instanceof MySQLDatabase) {
            if (originalDefinition.toLowerCase().startsWith("blob") || originalDefinition.equals("java.sql.Types.BLOB")) {
                return new DatabaseDataType("BLOB");
            } else if (originalDefinition.toLowerCase().startsWith("varbinary") || originalDefinition.equals("java.sql.Types.VARBINARY")) {
                return new DatabaseDataType("VARBINARY", getParameters());
            } else {
                return new DatabaseDataType("LONGBLOB");
            }
        }
        if (database instanceof PostgresDatabase) {
            return new DatabaseDataType("BYTEA");
        }
        if (database instanceof SybaseASADatabase) {
            return new DatabaseDataType("LONG BINARY");
        }
        if (database instanceof SybaseDatabase) {
            return new DatabaseDataType("IMAGE");
        }
        if (database instanceof OracleDatabase) {
            return new DatabaseDataType("BLOB");
        }

        if (database instanceof FirebirdDatabase) {
            return new DatabaseDataType("BLOB");
        }
        return super.toDatabaseDataType(database);
    }
View Full Code Here


    @Override
    public DatabaseDataType toDatabaseDataType(Database database) {
        if (database instanceof InformixDatabase && isAutoIncrement()) {
            return new DatabaseDataType("SERIAL");
        }
        if (database instanceof OracleDatabase) {
            return new DatabaseDataType("NUMBER", 10);
        }
        if (database instanceof DB2Database || database instanceof DerbyDatabase) {
            return new DatabaseDataType("INTEGER");
        }
        if (database instanceof PostgresDatabase) {
            if (autoIncrement) {
                return new DatabaseDataType("SERIAL");
            }
        }
        if (database instanceof MSSQLDatabase || database instanceof HsqlDatabase || database instanceof FirebirdDatabase || database instanceof InformixDatabase  || database instanceof MySQLDatabase) {
            return new DatabaseDataType("INT");
        }
        if (database instanceof SQLiteDatabase) {
          return new DatabaseDataType("INTEGER");
        }
        return super.toDatabaseDataType(database);

        //sqllite
        //        if (columnTypeString.equals("INTEGER") ||
View Full Code Here

                || database instanceof DerbyDatabase
                || database instanceof FirebirdDatabase
                || database instanceof H2Database
                || database instanceof HsqlDatabase
                || database instanceof OracleDatabase) {
            return new DatabaseDataType("TIMESTAMP");
        }

        if (database instanceof MSSQLDatabase) {
            if ((getParameters().length > 0 && "16".equals(getParameters()[0])) || "SMALLDATETIME".equalsIgnoreCase(getRawDefinition())) {
                   return new DatabaseDataType("SMALLDATETIME");
            }
        }
        if (database instanceof InformixDatabase) {

          // From database to changelog
          if (getAdditionalInformation() == null || getAdditionalInformation().length() == 0) {
            if (getParameters() != null && getParameters().length > 0) {

              String parameter = String.valueOf(getParameters()[0]);
             
              if("4365".equals(parameter)) {
                return new DatabaseDataType("DATETIME YEAR TO FRACTION(3)");
              }

              if("3594".equals(parameter)) {
                return new DatabaseDataType("DATETIME YEAR TO SECOND");
              }

              if("3080".equals(parameter)) {
                return new DatabaseDataType("DATETIME YEAR TO MINUTE");
              }

              if("2052".equals(parameter)) {
                return new DatabaseDataType("DATETIME YEAR TO DAY");
              }
            }
          }

          // From changelog to the database
          if (getAdditionalInformation() != null && getAdditionalInformation().length() > 0) {
            return new DatabaseDataType(getRawDefinition());
          }

          return new DatabaseDataType("DATETIME YEAR TO FRACTION", 5);
        }
        if (database instanceof PostgresDatabase) {
            String rawDefinition = getRawDefinition().toLowerCase();
            if (rawDefinition.contains("tz") || rawDefinition.contains("with time zone")) {
                return new DatabaseDataType("TIMESTAMP WITH TIME ZONE");
            } else {
                return new DatabaseDataType("TIMESTAMP WITHOUT TIME ZONE");
            }
        }
        if (database instanceof SQLiteDatabase) {
            return new DatabaseDataType("TEXT");
        }

        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());
            }        }

        return new DatabaseDataType(getName());
    }
View Full Code Here

    @Override
    public DatabaseDataType toDatabaseDataType(Database database) {
        if (database instanceof OracleDatabase
                || (database instanceof HsqlDatabase && ((HsqlDatabase) database).isUsingOracleSyntax())) {
            return new DatabaseDataType("VARCHAR2", getParameters());
        }

        if (database instanceof InformixDatabase && getSize() > 255) {
            return new DatabaseDataType("LVARCHAR", getParameters());
        }

        if (database instanceof MSSQLDatabase) {
            if (getParameters() != null && getParameters().length > 0) {
                Object param1 = getParameters()[0];
                if (param1.toString().matches("\\d+")) {
                    if (Long.valueOf(param1.toString()) > 8000) {
                        return new DatabaseDataType("VARCHAR", "MAX");
                    }
                }
            }
            return new DatabaseDataType("VARCHAR", getParameters());
        }

        return super.toDatabaseDataType(database);
    }
View Full Code Here

TOP

Related Classes of liquibase.datatype.DatabaseDataType

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.