@Documented
@Retention(value=RUNTIME)
@Target(value=METHOD)
@Around
public @interface Store
This annotation will wrap the decorated method to ensure thread isolation.
You can store method parameters or a Method return statement.
A method such as this:
@Store(parameters = "customers") protected Customer addCustomer(Map<String, Customer> customers, CustomerSave customerSave) { String id = UUID.randomUUID().toString(); Customer customer = new Customer(id, customerSave.getFirstName(), customerSave.getLastName()); customers.put(id, customer); return customer; }
Becomes
protected Customer addCustomer(Map<String, Customer> customers, CustomerSave customerSave) { return XThreads.executeSynchronized(() -> { String id = UUID.randomUUID().toString(); Customer customer = new Customer(id, customerSave.getFirstName(), customerSave.getLastName()); customers.put(id, customer); embeddedStorageManager.store(customers); return customer; }); }
You can store a method's result.
A method such as this:
@Store(result = true) protected Customer updateCustomer(String id, CustomerSave customerSave) { Customer c = data().getCustomers().get(id); if (c != null) { c.setFirstName(customerSave.getFirstName()); c.setLastName(customerSave.getLastName()); return c; } return null; }
Becomes
protected Customer updateCustomer(String id, CustomerSave customerSave) { XThreads.executeSynchronized(() -> { Customer c = data().getCustomers().get(id); if (c != null) { c.setFirstName(customerSave.getFirstName()); c.setLastName(customerSave.getLastName()); embeddedStorageManager.store(c); return c; } return null; } }
Modifier and Type | Optional Element and Description |
---|---|
java.lang.String |
name
The optional name qualifier of the StorageManager to use.
|
java.lang.String[] |
parameters
parameters which should be stored in the associated StorageManager.
|
boolean |
result
Whether to store the method result.
|
boolean |
root
Whether to ignore
parameters() and result() and store the whole entity class root. |
StoringStrategy |
strategy
The Storing strategy.
|
@AliasFor(member="value") public abstract java.lang.String name
public abstract java.lang.String[] parameters
public abstract boolean result
public abstract StoringStrategy strategy
public abstract boolean root
parameters()
and result()
and store the whole entity class root. Defaults to false.parameters()
and result()
and store the whole entity class root.