public class MigrationReportImpl extends Object implements MigrationReport
Constructor and Description |
---|
MigrationReportImpl(MigrationOperation operation,
Optional<Consumer<MigrationMessage>> consumer)
Creates a new migration report.
|
Modifier and Type | Method and Description |
---|---|
MigrationReport |
doAfterCompletion(Consumer<MigrationReport> code)
Registers code to be invoked at the completion of the migration operation.
|
Optional<Instant> |
getEndTime()
Gets the time the corresponding migration operation ended.
|
MigrationOperation |
getOperation()
Gets the type of migration operation this report is associated with.
|
Instant |
getStartTime()
Gets the time the corresponding migration operation started.
|
boolean |
hasErrors()
Checks if the operation that generated this migration recorded any errors.
|
boolean |
hasInfos()
Checks if the operation that generated this migration recorded any information messages.
|
boolean |
hasWarnings()
Checks if the operation that generated this migration recorded any warnings.
|
Stream<MigrationMessage> |
messages()
Retrieves all messages recorded by the operation that generated this migration report.
|
MigrationReportImpl |
record(MigrationMessage msg)
Records a message that occurred during the migration report.
|
void |
verifyCompletion()
Verifies if the operation that generated this migration report completed successfully.
|
boolean |
wasIOSuccessful(ThrowingRunnable<IOException> code)
Runs the specified code and report whether or not it was successful.
|
boolean |
wasSuccessful()
Checks if the operation that generated this migration report was successful or not.
|
boolean |
wasSuccessful(Runnable code)
Runs the specified code and report whether or not it was successful.
|
public MigrationReportImpl(MigrationOperation operation, Optional<Consumer<MigrationMessage>> consumer)
operation
- the type of migration operation for this reportconsumer
- an optional consumer to call whenever a new migration message is recorded
during the operationIllegalArgumentException
- if operation
is null
public MigrationOperation getOperation()
MigrationReport
getOperation
in interface MigrationReport
public Instant getStartTime()
MigrationReport
getStartTime
in interface MigrationReport
public Optional<Instant> getEndTime()
MigrationReport
getEndTime
in interface MigrationReport
public MigrationReportImpl record(MigrationMessage msg)
MigrationReport
Recorded errors (i.e. MigrationException} will be thrown back when MigrationReport.verifyCompletion()
is called at the end of the operation.
record
in interface MigrationReport
msg
- the message to recordpublic MigrationReport doAfterCompletion(Consumer<MigrationReport> code)
MigrationReport
doAfterCompletion
in interface MigrationReport
code
- the code to execute which will receive this report in parameter where additional
errors and/or warnings can be registeredpublic Stream<MigrationMessage> messages()
MigrationReport
messages
in interface MigrationReport
public boolean wasSuccessful()
MigrationReport
Note: A successful operation might still report warnings.
wasSuccessful
in interface MigrationReport
true
if the operation was successfull; false
if notpublic boolean wasSuccessful(Runnable code)
MigrationReport
Note: This method will only account for errors generated from the point where the provided code is called to the moment it terminates.
wasSuccessful
in interface MigrationReport
code
- the code to runtrue
if no new errors were recorded while running the provided code;
false
if at least one error was recordedpublic boolean wasIOSuccessful(ThrowingRunnable<IOException> code) throws IOException
MigrationReport
Note: This method will only account for errors generated from the point where the provided code is called to the moment it terminates.
wasIOSuccessful
in interface MigrationReport
code
- the code to runtrue
if no new errors were recorded while running the provided code;
false
if at least one error was recordedIOException
- if the code executed throws itpublic boolean hasInfos()
MigrationReport
hasInfos
in interface MigrationReport
true
if the operation recorded at least one informational message;
false
if notpublic boolean hasWarnings()
MigrationReport
hasWarnings
in interface MigrationReport
true
if the operation recorded at least one warning; false
if
notpublic boolean hasErrors()
MigrationReport
hasErrors
in interface MigrationReport
true
if the operation recorded at least one error; false
if
notpublic void verifyCompletion()
MigrationReport
Note: The first exception recorded will always be thrown out and all additional
exceptions recorded will be added to it as suppressed exceptions (see Throwable.getSuppressed()
).
verifyCompletion
in interface MigrationReport
This work is licensed under a Creative Commons Attribution 4.0 International License.