Search in sources :

Example 21 with UnexpectedLiquibaseException

use of liquibase.exception.UnexpectedLiquibaseException in project liquibase by liquibase.

the class StandardDiffGenerator method compare.

@Override
public DiffResult compare(DatabaseSnapshot referenceSnapshot, DatabaseSnapshot comparisonSnapshot, CompareControl compareControl) throws DatabaseException {
    if (comparisonSnapshot == null) {
        try {
            //, compareControl.toSnapshotControl(CompareControl.DatabaseRole.REFERENCE));
            comparisonSnapshot = new EmptyDatabaseSnapshot(referenceSnapshot.getDatabase());
        } catch (InvalidExampleException e) {
            throw new UnexpectedLiquibaseException(e);
        }
    }
    DiffResult diffResult = new DiffResult(referenceSnapshot, comparisonSnapshot, compareControl);
    checkVersionInfo(referenceSnapshot, comparisonSnapshot, diffResult);
    Set<Class<? extends DatabaseObject>> typesToCompare = compareControl.getComparedTypes();
    typesToCompare.retainAll(referenceSnapshot.getSnapshotControl().getTypesToInclude());
    typesToCompare.retainAll(comparisonSnapshot.getSnapshotControl().getTypesToInclude());
    for (Class<? extends DatabaseObject> typeToCompare : typesToCompare) {
        compareObjectType(typeToCompare, referenceSnapshot, comparisonSnapshot, diffResult);
    }
    return diffResult;
}
Also used : InvalidExampleException(liquibase.snapshot.InvalidExampleException) EmptyDatabaseSnapshot(liquibase.snapshot.EmptyDatabaseSnapshot) DatabaseObject(liquibase.structure.DatabaseObject) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 22 with UnexpectedLiquibaseException

use of liquibase.exception.UnexpectedLiquibaseException in project liquibase by liquibase.

the class OracleDatabase method setConnection.

@Override
public void setConnection(DatabaseConnection conn) {
    //more reserved words not returned by driver
    reservedWords.addAll(Arrays.asList("GROUP", "USER", "SESSION", "PASSWORD", "RESOURCE", "START", "SIZE", "UID", "DESC", "ORDER"));
    Connection sqlConn = null;
    if (!(conn instanceof OfflineConnection)) {
        try {
            /**
                 * Don't try to call getWrappedConnection if the conn instance is
                 * is not a JdbcConnection. This happens for OfflineConnection.
                 * @see <a href="https://liquibase.jira.com/browse/CORE-2192">CORE-2192</a>
                 **/
            if (conn instanceof JdbcConnection) {
                Method wrappedConn = conn.getClass().getMethod("getWrappedConnection");
                wrappedConn.setAccessible(true);
                sqlConn = (Connection) wrappedConn.invoke(conn);
            }
        } catch (Exception e) {
            throw new UnexpectedLiquibaseException(e);
        }
        if (sqlConn != null) {
            try {
                reservedWords.addAll(Arrays.asList(sqlConn.getMetaData().getSQLKeywords().toUpperCase().split(",\\s*")));
            } catch (SQLException e) {
                LogFactory.getLogger().info("Could get sql keywords on OracleDatabase: " + e.getMessage());
            //can not get keywords. Continue on
            }
            try {
                Method method = sqlConn.getClass().getMethod("setRemarksReporting", Boolean.TYPE);
                method.setAccessible(true);
                method.invoke(sqlConn, true);
            } catch (Exception e) {
                LogFactory.getLogger().info("Could not set remarks reporting on OracleDatabase: " + e.getMessage());
                //cannot set it. That is OK
                ;
            }
            Statement statement = null;
            ResultSet resultSet = null;
            try {
                statement = sqlConn.createStatement();
                resultSet = statement.executeQuery("SELECT value FROM v$parameter WHERE name = 'compatible'");
                String compatibleVersion = null;
                if (resultSet.next()) {
                    compatibleVersion = resultSet.getString("value");
                }
                if (compatibleVersion != null) {
                    Matcher majorVersionMatcher = Pattern.compile("(\\d+)\\..*").matcher(compatibleVersion);
                    if (majorVersionMatcher.matches()) {
                        this.databaseMajorVersion = Integer.valueOf(majorVersionMatcher.group(1));
                    }
                }
            } catch (SQLException e) {
                String message = "Cannot read from v$parameter: " + e.getMessage();
                LogFactory.getLogger().info("Could not set check compatibility mode on OracleDatabase, assuming not running in any sort of compatibility mode: " + message);
            } finally {
                JdbcUtils.close(resultSet, statement);
            }
        }
    }
    super.setConnection(conn);
}
Also used : SQLException(java.sql.SQLException) Matcher(java.util.regex.Matcher) RawCallStatement(liquibase.statement.core.RawCallStatement) RawSqlStatement(liquibase.statement.core.RawSqlStatement) Statement(java.sql.Statement) Connection(java.sql.Connection) DatabaseConnection(liquibase.database.DatabaseConnection) OfflineConnection(liquibase.database.OfflineConnection) JdbcConnection(liquibase.database.jvm.JdbcConnection) ResultSet(java.sql.ResultSet) JdbcConnection(liquibase.database.jvm.JdbcConnection) OfflineConnection(liquibase.database.OfflineConnection) Method(java.lang.reflect.Method) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) SQLException(java.sql.SQLException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) DatabaseException(liquibase.exception.DatabaseException)

Example 23 with UnexpectedLiquibaseException

use of liquibase.exception.UnexpectedLiquibaseException in project liquibase by liquibase.

the class ReflectionSerializer method getDataTypeClassParameters.

public Type[] getDataTypeClassParameters(Object object, String field) {
    try {
        Field foundField = findField(object, field);
        Type dataType = foundField.getGenericType();
        if (dataType instanceof ParameterizedType) {
            return ((ParameterizedType) dataType).getActualTypeArguments();
        }
        return new Type[0];
    } catch (Exception e) {
        throw new UnexpectedLiquibaseException(e);
    }
}
Also used : UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 24 with UnexpectedLiquibaseException

use of liquibase.exception.UnexpectedLiquibaseException in project liquibase by liquibase.

the class StringSnapshotSerializer method serializeObject.

private String serializeObject(LiquibaseSerializable objectToSerialize, int indent) {
    try {
        StringBuffer buffer = new StringBuffer();
        buffer.append("[");
        SortedSet<String> values = new TreeSet<String>();
        for (String field : objectToSerialize.getSerializableFields()) {
            Object value = objectToSerialize.getSerializableFieldValue(field);
            if (value instanceof LiquibaseSerializable) {
                values.add(indent(indent) + serializeObject((LiquibaseSerializable) value, indent + 1));
            } else {
                if (value != null) {
                    if (value instanceof Map) {
                        values.add(indent(indent) + field + "=" + serializeObject((Map) value, indent + 1));
                    } else if (value instanceof Collection) {
                        values.add(indent(indent) + field + "=" + serializeObject((Collection) value, indent + 1));
                    } else if (value instanceof Object[]) {
                        values.add(indent(indent) + field + "=" + serializeObject((Object[]) value, indent + 1));
                    } else {
                        String valueString = value.toString();
                        if (value instanceof Double || value instanceof Float) {
                            //java 6 adds additional zeros to the end of doubles and floats
                            if (valueString.contains(".")) {
                                valueString = valueString.replaceFirst("0*$", "");
                            }
                        }
                        values.add(indent(indent) + field + "=\"" + valueString + "\"");
                    }
                }
            }
        }
        if (values.size() > 0) {
            buffer.append("\n");
            buffer.append(StringUtils.join(values, "\n"));
            buffer.append("\n");
        }
        buffer.append(indent(indent - 1)).append("]");
        //standardize all newline chars
        return buffer.toString().replace("\r\n", "\n").replace("\r", "\n");
    } catch (Exception e) {
        throw new UnexpectedLiquibaseException(e);
    }
}
Also used : LiquibaseSerializable(liquibase.serializer.LiquibaseSerializable) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Example 25 with UnexpectedLiquibaseException

use of liquibase.exception.UnexpectedLiquibaseException in project liquibase by liquibase.

the class AbstractLiquibaseSerializable method serialize.

@Override
public ParsedNode serialize() throws ParsedNodeException {
    ParsedNode node = new ParsedNode(null, getSerializedObjectName());
    for (String field : getSerializableFields()) {
        Object fieldValue = getSerializableFieldValue(field);
        fieldValue = serializeValue(fieldValue);
        if (fieldValue == null) {
            continue;
        }
        SerializationType type = getSerializableFieldType(field);
        if (type == SerializationType.DIRECT_VALUE) {
            node.setValue(fieldValue);
        } else if (type == SerializationType.NAMED_FIELD || type == SerializationType.NESTED_OBJECT) {
            if (fieldValue instanceof ParsedNode) {
                node.addChild((ParsedNode) fieldValue);
            } else {
                node.addChild(new ParsedNode(null, field).setValue(fieldValue));
            }
        } else {
            throw new UnexpectedLiquibaseException("Unknown type: " + type);
        }
    }
    return node;
}
Also used : ParsedNode(liquibase.parser.core.ParsedNode) UnexpectedLiquibaseException(liquibase.exception.UnexpectedLiquibaseException)

Aggregations

UnexpectedLiquibaseException (liquibase.exception.UnexpectedLiquibaseException)75 DatabaseException (liquibase.exception.DatabaseException)12 IOException (java.io.IOException)10 Database (liquibase.database.Database)10 DatabaseObject (liquibase.structure.DatabaseObject)10 LiquibaseException (liquibase.exception.LiquibaseException)9 InvalidExampleException (liquibase.snapshot.InvalidExampleException)9 CatalogAndSchema (liquibase.CatalogAndSchema)8 InputStream (java.io.InputStream)7 ParsedNodeException (liquibase.parser.core.ParsedNodeException)7 SQLException (java.sql.SQLException)6 DatabaseFunction (liquibase.statement.DatabaseFunction)6 SqlStatement (liquibase.statement.SqlStatement)6 ArrayList (java.util.ArrayList)5 Matcher (java.util.regex.Matcher)5 Change (liquibase.change.Change)5 ColumnConfig (liquibase.change.ColumnConfig)5 Executor (liquibase.executor.Executor)5 Sql (liquibase.sql.Sql)5 InvocationTargetException (java.lang.reflect.InvocationTargetException)4