@Test public void createNode_ColumnConfig() throws Exception { ColumnConfig column = new ColumnConfig(); column.setName("id"); column.setType("varchar(255)"); column.setDefaultValue("test Value"); column.setValue("some value here"); ConstraintsConfig constraints = new ConstraintsConfig(); constraints.setDeferrable(Boolean.TRUE); constraints.setDeleteCascade(true); constraints.setForeignKeyName("FK_NAME"); constraints.setInitiallyDeferred(true); constraints.setNullable(false); constraints.setPrimaryKey(true); constraints.setReferences("state(id)"); constraints.setUnique(true); column.setConstraints(constraints); Element element = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(column); assertEquals("column", element.getTagName()); assertEquals("id", element.getAttribute("name")); assertEquals("varchar(255)", element.getAttribute("type")); assertEquals("test Value", element.getAttribute("defaultValue")); assertEquals("some value here", element.getAttribute("value")); Element constraintsElement = (Element) element.getChildNodes().item(0); assertEquals(8, constraintsElement.getAttributes().getLength()); assertEquals("true", constraintsElement.getAttribute("deferrable")); assertEquals("true", constraintsElement.getAttribute("deleteCascade")); assertEquals("FK_NAME", constraintsElement.getAttribute("foreignKeyName")); assertEquals("true", constraintsElement.getAttribute("initiallyDeferred")); assertEquals("false", constraintsElement.getAttribute("nullable")); assertEquals("true", constraintsElement.getAttribute("primaryKey")); assertEquals("state(id)", constraintsElement.getAttribute("references")); assertEquals("true", constraintsElement.getAttribute("unique")); }
public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected  XMLChangeLogSerializer(Document currentChangeLogFileDOM); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected  XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change); }
XMLChangeLogSerializer implements ChangeLogSerializer { public Element createNode(SqlVisitor visitor) { Element node = currentChangeLogFileDOM.createElementNS(XMLChangeLogSAXParser.getDatabaseChangeLogNameSpace(), visitor.getName()); try { List<Field> allFields = new ArrayList<Field>(); Class classToExtractFieldsFrom = visitor.getClass(); while (!classToExtractFieldsFrom.equals(Object.class)) { allFields.addAll(Arrays.asList(classToExtractFieldsFrom.getDeclaredFields())); classToExtractFieldsFrom = classToExtractFieldsFrom.getSuperclass(); } for (Field field : allFields) { field.setAccessible(true); ChangeProperty changePropertyAnnotation = field.getAnnotation(ChangeProperty.class); if (changePropertyAnnotation != null && !changePropertyAnnotation.includeInSerialization()) { continue; } if (field.getName().equals("serialVersionUID")) { continue; } if (field.getName().equals("$VRc")) { continue; } String propertyName = field.getName(); Object value = field.get(visitor); if (value != null) { node.setAttribute(propertyName, value.toString()); } } } catch (Exception e) { throw new UnexpectedLiquibaseException(e); } return node; } XMLChangeLogSerializer(); protected  XMLChangeLogSerializer(Document currentChangeLogFileDOM); void setCurrentChangeLogFileDOM(Document currentChangeLogFileDOM); String[] getValidFileExtensions(); String serialize(DatabaseChangeLog databaseChangeLog); String serialize(Change change); String serialize(SqlVisitor visitor); String serialize(ColumnConfig columnConfig); String serialize(ChangeSet changeSet); void write(List<ChangeSet> changeSets, OutputStream out); Element createNode(SqlVisitor visitor); Element createNode(Change change); Element createNode(String nodeName, String nodeContent); Element createNode(ColumnConfig columnConfig); Element createNode(ChangeSet changeSet); Element createNode(CustomChangeWrapper change);  }