@Test public void testDeletedMiddle() throws ConnectionException { logger.info( "ChangeLogGeneratorImpl test" ); final Id entityId = new SimpleId( "test" ); Entity e1 = new Entity( entityId ); e1.setField( new StringField( "name", "name1" ) ); e1.setField( new IntegerField( "count", 1 ) ); e1.setField( new BooleanField( "single", true ) ); final MvccEntity mvccEntity1 = new MvccEntityImpl( entityId, UUIDGenerator.newTimeUUID(), MvccEntity.Status.COMPLETE, e1 ); Entity e2 = new Entity( entityId ); e2.setField( new StringField( "name", "name2" ) ); e2.setField( new IntegerField( "count", 2 ) ); e2.setField( new StringField( "nickname", "buddy" ) ); e2.setField( new BooleanField( "cool", false ) ); final MvccEntity mvccEntity2 = new MvccEntityImpl( entityId, UUIDGenerator.newTimeUUID(), MvccEntity.Status.DELETED, e2 ); Entity e3 = new Entity( entityId ); e3.setField( new StringField( "name", "name3" ) ); e3.setField( new IntegerField( "count", 2 ) ); e3.setField( new BooleanField( "single", true ) ); final MvccEntity mvccEntity3 = new MvccEntityImpl( entityId, UUIDGenerator.newTimeUUID(), MvccEntity.Status.PARTIAL, e3 ); ChangeLogGeneratorImpl instance = new ChangeLogGeneratorImpl(); ChangeLog result = instance.getChangeLog( Arrays.asList( mvccEntity1, mvccEntity2, mvccEntity3 ) ); assertEquals( "All changes present", 0, result.getSize() ); Collection<Field> changes = result.getWrites(); assertEquals( 0, changes.size() ); Set<String> deletes = result.getDeletes(); assertEquals( 0, deletes.size() ); }
@Override public ChangeLog getChangeLog( Collection<MvccEntity> mvccEntities ) { Preconditions.checkArgument( mvccEntities.size() > 0, "You must specify at least 1 entities for a change log" ); final ChangeLogImpl changeLog = new ChangeLogImpl( 50 ); Iterator<MvccEntity> iterator = mvccEntities.iterator(); Set<String> previousFieldNames = getFieldNames( iterator.next().getEntity() ); Set<String> currentFieldNames = null; while ( iterator.hasNext() ) { final MvccEntity mvccEntity = iterator.next(); currentFieldNames = getFieldNames( mvccEntity.getEntity() ); if(mvccEntity.getStatus() == MvccEntity.Status.DELETED){ changeLog.clear(); continue; } final Entity currentEntity = mvccEntity.getEntity().orNull(); final Set<String> deletedFields = Sets.difference( previousFieldNames, currentFieldNames ); changeLog.addDeletes( deletedFields ); for ( String addedField : currentFieldNames ) { changeLog.addWrite( currentEntity.getField( addedField ) ); } previousFieldNames = currentFieldNames; } if(currentFieldNames != null) { changeLog.clear( currentFieldNames ); } return changeLog; }
ChangeLogGeneratorImpl implements ChangeLogGenerator { @Override public ChangeLog getChangeLog( Collection<MvccEntity> mvccEntities ) { Preconditions.checkArgument( mvccEntities.size() > 0, "You must specify at least 1 entities for a change log" ); final ChangeLogImpl changeLog = new ChangeLogImpl( 50 ); Iterator<MvccEntity> iterator = mvccEntities.iterator(); Set<String> previousFieldNames = getFieldNames( iterator.next().getEntity() ); Set<String> currentFieldNames = null; while ( iterator.hasNext() ) { final MvccEntity mvccEntity = iterator.next(); currentFieldNames = getFieldNames( mvccEntity.getEntity() ); if(mvccEntity.getStatus() == MvccEntity.Status.DELETED){ changeLog.clear(); continue; } final Entity currentEntity = mvccEntity.getEntity().orNull(); final Set<String> deletedFields = Sets.difference( previousFieldNames, currentFieldNames ); changeLog.addDeletes( deletedFields ); for ( String addedField : currentFieldNames ) { changeLog.addWrite( currentEntity.getField( addedField ) ); } previousFieldNames = currentFieldNames; } if(currentFieldNames != null) { changeLog.clear( currentFieldNames ); } return changeLog; } }
ChangeLogGeneratorImpl implements ChangeLogGenerator { @Override public ChangeLog getChangeLog( Collection<MvccEntity> mvccEntities ) { Preconditions.checkArgument( mvccEntities.size() > 0, "You must specify at least 1 entities for a change log" ); final ChangeLogImpl changeLog = new ChangeLogImpl( 50 ); Iterator<MvccEntity> iterator = mvccEntities.iterator(); Set<String> previousFieldNames = getFieldNames( iterator.next().getEntity() ); Set<String> currentFieldNames = null; while ( iterator.hasNext() ) { final MvccEntity mvccEntity = iterator.next(); currentFieldNames = getFieldNames( mvccEntity.getEntity() ); if(mvccEntity.getStatus() == MvccEntity.Status.DELETED){ changeLog.clear(); continue; } final Entity currentEntity = mvccEntity.getEntity().orNull(); final Set<String> deletedFields = Sets.difference( previousFieldNames, currentFieldNames ); changeLog.addDeletes( deletedFields ); for ( String addedField : currentFieldNames ) { changeLog.addWrite( currentEntity.getField( addedField ) ); } previousFieldNames = currentFieldNames; } if(currentFieldNames != null) { changeLog.clear( currentFieldNames ); } return changeLog; }  }
ChangeLogGeneratorImpl implements ChangeLogGenerator { @Override public ChangeLog getChangeLog( Collection<MvccEntity> mvccEntities ) { Preconditions.checkArgument( mvccEntities.size() > 0, "You must specify at least 1 entities for a change log" ); final ChangeLogImpl changeLog = new ChangeLogImpl( 50 ); Iterator<MvccEntity> iterator = mvccEntities.iterator(); Set<String> previousFieldNames = getFieldNames( iterator.next().getEntity() ); Set<String> currentFieldNames = null; while ( iterator.hasNext() ) { final MvccEntity mvccEntity = iterator.next(); currentFieldNames = getFieldNames( mvccEntity.getEntity() ); if(mvccEntity.getStatus() == MvccEntity.Status.DELETED){ changeLog.clear(); continue; } final Entity currentEntity = mvccEntity.getEntity().orNull(); final Set<String> deletedFields = Sets.difference( previousFieldNames, currentFieldNames ); changeLog.addDeletes( deletedFields ); for ( String addedField : currentFieldNames ) { changeLog.addWrite( currentEntity.getField( addedField ) ); } previousFieldNames = currentFieldNames; } if(currentFieldNames != null) { changeLog.clear( currentFieldNames ); } return changeLog; }  @Override ChangeLog getChangeLog( Collection<MvccEntity> mvccEntities ); }
ChangeLogGeneratorImpl implements ChangeLogGenerator { @Override public ChangeLog getChangeLog( Collection<MvccEntity> mvccEntities ) { Preconditions.checkArgument( mvccEntities.size() > 0, "You must specify at least 1 entities for a change log" ); final ChangeLogImpl changeLog = new ChangeLogImpl( 50 ); Iterator<MvccEntity> iterator = mvccEntities.iterator(); Set<String> previousFieldNames = getFieldNames( iterator.next().getEntity() ); Set<String> currentFieldNames = null; while ( iterator.hasNext() ) { final MvccEntity mvccEntity = iterator.next(); currentFieldNames = getFieldNames( mvccEntity.getEntity() ); if(mvccEntity.getStatus() == MvccEntity.Status.DELETED){ changeLog.clear(); continue; } final Entity currentEntity = mvccEntity.getEntity().orNull(); final Set<String> deletedFields = Sets.difference( previousFieldNames, currentFieldNames ); changeLog.addDeletes( deletedFields ); for ( String addedField : currentFieldNames ) { changeLog.addWrite( currentEntity.getField( addedField ) ); } previousFieldNames = currentFieldNames; } if(currentFieldNames != null) { changeLog.clear( currentFieldNames ); } return changeLog; }  @Override ChangeLog getChangeLog( Collection<MvccEntity> mvccEntities );  }