T
- The type which has an ID and version.public interface Versioned<T> extends Identifiable<T>
Typically this is a parameter of the an update or delete command.
So for example you have
ProductUpdateCommand of(final Versioned<Product> versioned, final UpdateAction<Product> updateAction)
then you should NOT do:
final Product product = getProduct();
//NOT GOOD
final ProductUpdateCommand cmd = ProductUpdateCommand.of(Versioned.of(product.getId(), product.getVersion()), Publish.of());
The resources already implement Versioned
so you can use them directly:
final Product product = getProduct();
//Product implements Versioned<Product>
final ProductUpdateCommand cmd = ProductUpdateCommand.of(product, Publish.of());
But there occasions where you submit ID and version in a form and want to update a resource without fetching it before:
final String id = "c7b25e66-465f-4b77-8c8b-10f0958a1436";
final long version = 5;
final ProductUpdateCommand cmd = ProductUpdateCommand.of(Versioned.of(id, version), Publish.of());
Modifier and Type | Method and Description |
---|---|
String |
getId()
The unique ID of this object.
|
Long |
getVersion() |
static <T> Versioned<T> |
of(String id,
long version) |
static <T> Versioned<T> |
of(Versioned<T> versioned)
Creates a versioned that only contains the id and the version.
|
String getId()
Identifiable
getId
in interface Identifiable<T>
Long getVersion()
static <T> Versioned<T> of(Versioned<T> versioned)
T
- The type which has an ID and version.versioned
- the template object to use its ID and version