@Test public void diff() { SwiftMetaData meta1 = new SwiftMetaDataEntity("A", Arrays.<SwiftMetaDataColumn>asList( new MetaDataColumnEntity("a1", Types.INTEGER), new MetaDataColumnEntity("a2", Types.FLOAT), new MetaDataColumnEntity("a3", Types.TIMESTAMP))); SwiftMetaData meta2 = new SwiftMetaDataEntity("A", Arrays.<SwiftMetaDataColumn>asList( new MetaDataColumnEntity("a1", Types.INTEGER), new MetaDataColumnEntity("a3", Types.TIMESTAMP), new MetaDataColumnEntity("a4", Types.BIT))); MetadataDiffer differ = new MetadataDiffer(meta1, meta2); List<SwiftMetaDataColumn> added = differ.getAdded(); Assert.assertEquals(1, added.size()); DatabaseTest.assertEquals(new MetaDataColumnEntity("a4", Types.BIT), added.get(0)); List<SwiftMetaDataColumn> dropped = differ.getDropped(); Assert.assertEquals(1, dropped.size()); DatabaseTest.assertEquals(new MetaDataColumnEntity("a2", Types.FLOAT), dropped.get(0)); }
private static void diff(SwiftMetaData oldMeta, SwiftMetaData newMeta, Consumer<SwiftMetaDataColumn> columnMetaHandler) throws SwiftMetaDataException { for (int i = 0; i < newMeta.getColumnCount(); i++) { SwiftMetaDataColumn newColumnMeta = newMeta.getColumn(i + 1); Optional<SwiftMetaDataColumn> columnMeta = getColumn(oldMeta, newColumnMeta.getName()); if (!columnMeta.isPresent()) { columnMetaHandler.accept(newColumnMeta); continue; } SwiftMetaDataColumn oldColumnMeta = columnMeta.get(); if (!hasSameType(oldColumnMeta, newColumnMeta)) { SwiftLoggers.getLogger().warn("modify column type from {} to {} is not supported", oldColumnMeta, newColumnMeta); } } }
MetadataDiffer { private static void diff(SwiftMetaData oldMeta, SwiftMetaData newMeta, Consumer<SwiftMetaDataColumn> columnMetaHandler) throws SwiftMetaDataException { for (int i = 0; i < newMeta.getColumnCount(); i++) { SwiftMetaDataColumn newColumnMeta = newMeta.getColumn(i + 1); Optional<SwiftMetaDataColumn> columnMeta = getColumn(oldMeta, newColumnMeta.getName()); if (!columnMeta.isPresent()) { columnMetaHandler.accept(newColumnMeta); continue; } SwiftMetaDataColumn oldColumnMeta = columnMeta.get(); if (!hasSameType(oldColumnMeta, newColumnMeta)) { SwiftLoggers.getLogger().warn("modify column type from {} to {} is not supported", oldColumnMeta, newColumnMeta); } } } }
MetadataDiffer { private static void diff(SwiftMetaData oldMeta, SwiftMetaData newMeta, Consumer<SwiftMetaDataColumn> columnMetaHandler) throws SwiftMetaDataException { for (int i = 0; i < newMeta.getColumnCount(); i++) { SwiftMetaDataColumn newColumnMeta = newMeta.getColumn(i + 1); Optional<SwiftMetaDataColumn> columnMeta = getColumn(oldMeta, newColumnMeta.getName()); if (!columnMeta.isPresent()) { columnMetaHandler.accept(newColumnMeta); continue; } SwiftMetaDataColumn oldColumnMeta = columnMeta.get(); if (!hasSameType(oldColumnMeta, newColumnMeta)) { SwiftLoggers.getLogger().warn("modify column type from {} to {} is not supported", oldColumnMeta, newColumnMeta); } } } MetadataDiffer(SwiftMetaData oldMeta, SwiftMetaData newMeta); }
MetadataDiffer { private static void diff(SwiftMetaData oldMeta, SwiftMetaData newMeta, Consumer<SwiftMetaDataColumn> columnMetaHandler) throws SwiftMetaDataException { for (int i = 0; i < newMeta.getColumnCount(); i++) { SwiftMetaDataColumn newColumnMeta = newMeta.getColumn(i + 1); Optional<SwiftMetaDataColumn> columnMeta = getColumn(oldMeta, newColumnMeta.getName()); if (!columnMeta.isPresent()) { columnMetaHandler.accept(newColumnMeta); continue; } SwiftMetaDataColumn oldColumnMeta = columnMeta.get(); if (!hasSameType(oldColumnMeta, newColumnMeta)) { SwiftLoggers.getLogger().warn("modify column type from {} to {} is not supported", oldColumnMeta, newColumnMeta); } } } MetadataDiffer(SwiftMetaData oldMeta, SwiftMetaData newMeta); boolean hasDiff(); List<SwiftMetaDataColumn> getAdded(); List<SwiftMetaDataColumn> getDropped(); }
MetadataDiffer { private static void diff(SwiftMetaData oldMeta, SwiftMetaData newMeta, Consumer<SwiftMetaDataColumn> columnMetaHandler) throws SwiftMetaDataException { for (int i = 0; i < newMeta.getColumnCount(); i++) { SwiftMetaDataColumn newColumnMeta = newMeta.getColumn(i + 1); Optional<SwiftMetaDataColumn> columnMeta = getColumn(oldMeta, newColumnMeta.getName()); if (!columnMeta.isPresent()) { columnMetaHandler.accept(newColumnMeta); continue; } SwiftMetaDataColumn oldColumnMeta = columnMeta.get(); if (!hasSameType(oldColumnMeta, newColumnMeta)) { SwiftLoggers.getLogger().warn("modify column type from {} to {} is not supported", oldColumnMeta, newColumnMeta); } } } MetadataDiffer(SwiftMetaData oldMeta, SwiftMetaData newMeta); boolean hasDiff(); List<SwiftMetaDataColumn> getAdded(); List<SwiftMetaDataColumn> getDropped();  }