Annotation Interface Store
An around annotation for methods which simplifies storing objects in an associated Storage Manager.
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; } }
- Since:
- 1.0.0
- Author:
- Tim Yates, Sergio del Amo
- See Also:
-
Optional Element Summary
Modifier and TypeOptional ElementDescriptionThe optional name qualifier of the StorageManager to use.String[]
parameters which should be stored in the associated StorageManager.boolean
Whether to store the method result.boolean
Whether to ignoreparameters()
andresult()
and store the whole entity class root.The Storing strategy.
-
Element Details
-
name
The optional name qualifier of the StorageManager to use. If your application only have a EclipseStore instance, this is not required- Returns:
- The name qualifier of the StorageManager to use.
- Default:
- ""
-
parameters
String[] parametersparameters which should be stored in the associated StorageManager.- Returns:
- parameters name which should be stored in the associated StorageManager.
- Default:
- {}
-
result
boolean resultWhether to store the method result.- Returns:
- Whether to store the method result.
- Default:
- false
-
strategy
StoringStrategy strategyThe Storing strategy. Defaults to Lazy.- Returns:
- Storing Strategy;
- Default:
- LAZY
-
root
boolean rootWhether to ignoreparameters()
andresult()
and store the whole entity class root. Defaults to false.- Returns:
- Whether to ignore
parameters()
andresult()
and store the whole entity class root.
- Default:
- false
-