@Test public void createNode_CreateTableChange() throws Exception { CreateTableChange change = new CreateTableChange(); change.setTableName("TABLE_NAME"); ColumnConfig column1 = new ColumnConfig(); column1.setName("id"); column1.setType("int"); ConstraintsConfig column1constraints = new ConstraintsConfig(); column1constraints.setPrimaryKey(true); column1constraints.setNullable(false); column1.setConstraints(column1constraints); change.addColumn(column1); ColumnConfig column2 = new ColumnConfig(); column2.setName("name"); column2.setType("varchar(255)"); change.addColumn(column2); ColumnConfig column3 = new ColumnConfig(); column3.setName("state_id"); ConstraintsConfig column3constraints = new ConstraintsConfig(); column3constraints.setNullable(false); column3constraints.setInitiallyDeferred(true); column3constraints.setDeferrable(true); column3constraints.setForeignKeyName("fk_tab_ref"); column3constraints.setReferences("state(id)"); column3.setConstraints(column3constraints); change.addColumn(column3); ColumnConfig column4 = new ColumnConfig(); column4.setName("phone"); column4.setType("varchar(255)"); column4.setDefaultValue("NOPHONE"); change.addColumn(column4); ColumnConfig column5 = new ColumnConfig(); column5.setName("phone2"); column5.setType("varchar(255)"); ConstraintsConfig column5constraints = new ConstraintsConfig(); column5constraints.setUnique(true); column5.setConstraints(column5constraints); change.addColumn(column5); Element element = new XMLChangeLogSerializer(DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument()).createNode(change); assertEquals("createTable", element.getTagName()); assertEquals(5, element.getChildNodes().getLength()); Element columnElement = ((Element) element.getChildNodes().item(0)); assertEquals("column", columnElement.getTagName()); assertEquals("id", columnElement.getAttribute("name")); assertEquals("int", columnElement.getAttribute("type")); Element constraintsElement = (Element) columnElement.getChildNodes().item(0); assertEquals("constraints", constraintsElement.getTagName()); assertEquals(2, constraintsElement.getAttributes().getLength()); assertEquals("true", constraintsElement.getAttribute("primaryKey")); assertEquals("false", constraintsElement.getAttribute("nullable")); columnElement = ((Element) element.getChildNodes().item(1)); assertEquals("column", columnElement.getTagName()); assertEquals("name", columnElement.getAttribute("name")); assertEquals("varchar(255)", columnElement.getAttribute("type")); columnElement = ((Element) element.getChildNodes().item(2)); assertEquals("column", columnElement.getTagName()); assertEquals("state_id", columnElement.getAttribute("name")); constraintsElement = (Element) columnElement.getChildNodes().item(0); assertEquals("constraints", constraintsElement.getTagName()); assertEquals(5, constraintsElement.getAttributes().getLength()); assertEquals("false", constraintsElement.getAttribute("nullable")); assertEquals("true", constraintsElement.getAttribute("deferrable")); assertEquals("true", constraintsElement.getAttribute("initiallyDeferred")); assertEquals("fk_tab_ref", constraintsElement.getAttribute("foreignKeyName")); assertEquals("state(id)", constraintsElement.getAttribute("references")); columnElement = ((Element) element.getChildNodes().item(3)); assertEquals("column", columnElement.getTagName()); assertEquals("phone", columnElement.getAttribute("name")); assertEquals("varchar(255)", columnElement.getAttribute("type")); columnElement = ((Element) element.getChildNodes().item(4)); assertEquals("column", columnElement.getTagName()); assertEquals("phone2", columnElement.getAttribute("name")); assertEquals("varchar(255)", columnElement.getAttribute("type")); constraintsElement = (Element) columnElement.getChildNodes().item(0); assertEquals("constraints", constraintsElement.getTagName()); assertEquals(1, constraintsElement.getAttributes().getLength()); 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);  }