Annotation Interface Store


@Documented @Retention(RUNTIME) @Target(METHOD) @Around public @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

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    The optional name qualifier of the StorageManager to use.
    parameters which should be stored in the associated StorageManager.
    boolean
    Whether to store the method result.
    boolean
    Whether to ignore parameters() and result() and store the whole entity class root.
    The Storing strategy.
  • Element Details

    • name

      @AliasFor(member="value") String 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[] parameters
      parameters which should be stored in the associated StorageManager.
      Returns:
      parameters name which should be stored in the associated StorageManager.
      Default:
      {}
    • result

      boolean result
      Whether to store the method result.
      Returns:
      Whether to store the method result.
      Default:
      false
    • strategy

      StoringStrategy strategy
      The Storing strategy. Defaults to Lazy.
      Returns:
      Storing Strategy;
      Default:
      LAZY
    • root

      boolean root
      Whether to ignore parameters() and result() and store the whole entity class root. Defaults to false.
      Returns:
      Whether to ignore parameters() and result() and store the whole entity class root.
      Default:
      false