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