/** * Create the {@link ChangeParameterMetaData} "example" value. Uses the value on the * DatabaseChangeProperty annotation or returns null as a default. Returns map with key=database * short name, value=example. Use short-name "all" as the fallback. */ @SuppressWarnings("UnusedParameters") protected Map<String, Object> createExampleValueMetaData( String parameterName, DatabaseChangeProperty changePropertyAnnotation) { if (changePropertyAnnotation == null) { return null; } Map<String, Object> examples = new HashMap<String, Object>(); examples.put("all", StringUtils.trimToNull(changePropertyAnnotation.exampleValue())); return examples; }
/** * Generate the ChangeMetaData for this class. Default implementation reads from the @{@link * DatabaseChange } annotation and calls out to {@link #createChangeParameterMetadata(String)} for * each property. * * @throws UnexpectedLiquibaseException if no @DatabaseChange annotation on this Change class */ @Override public ChangeMetaData createChangeMetaData() { try { DatabaseChange databaseChange = this.getClass().getAnnotation(DatabaseChange.class); if (databaseChange == null) { throw new UnexpectedLiquibaseException( "No @DatabaseChange annotation for " + getClass().getName()); } Set<ChangeParameterMetaData> params = new HashSet<ChangeParameterMetaData>(); for (PropertyDescriptor property : Introspector.getBeanInfo(this.getClass()).getPropertyDescriptors()) { if (isInvalidProperty(property)) { continue; } Method readMethod = property.getReadMethod(); Method writeMethod = property.getWriteMethod(); if (readMethod == null) { try { readMethod = this.getClass().getMethod("is" + StringUtils.upperCaseFirst(property.getName())); } catch (Exception ignore) { // it was worth a try } } if (readMethod != null && writeMethod != null) { DatabaseChangeProperty annotation = readMethod.getAnnotation(DatabaseChangeProperty.class); if (annotation == null || annotation.isChangeProperty()) { params.add(createChangeParameterMetadata(property.getDisplayName())); } } } Map<String, String> notes = new HashMap<String, String>(); for (DatabaseChangeNote note : databaseChange.databaseNotes()) { notes.put(note.database(), note.notes()); } return new ChangeMetaData( databaseChange.name(), databaseChange.description(), databaseChange.priority(), databaseChange.appliesTo(), notes, params); } catch (Throwable e) { throw new UnexpectedLiquibaseException(e); } }