Note that it is quite in order not to publish any persistence methods on your entity interface, and instead create your own specialized methods instead.
In practice, entities often combine a mixture of exposing some persistence methods (for what are known as "CRUD" operations) and other specialized methods for business operations such as controlling the change of an entity's state.
If your entity API contains setter methods, then typically calling code will require an insert method to store new instances of your entity on the database:
@Inject private MyInsertableEntityDAO myInsertableEntityDAO; public void someCallToAnInsert() throws InformationalException { final MyInsertableEntity myInsertableEntity = myInsertableEntityDAO.newInstance(); // set some field values on the new instance myInsertableEntity.setSomeField("some value"); myInsertableEntity.setSomeOtherField("some other value"); // ask the new entity instance to store itself on the database myInsertableEntity.insert(); }
If your entity API must publish an insert method, change the entity API declaration to extend the Insertable interface:
/** * This entity supports callers asking it to insert itself. */ public interface MyInsertableEntity extends StandardEntity, Insertable { }
Note that the.insert() method (inherited from Insertable) throws InformationalException, in the case that validation errors are detected.
If your entity API contains setter methods, then typically calling code will require a.modify method to store changes on the database any changes to field values.
e.g.:
/** * This entity supports callers asking it to modify itself. */ public interface MyModifiableEntity extends StandardEntity, OptimisticLockModifiable { }
Note that database tables which store historical data (e.g. a history of state changes or other events) typically should not support modify.
If your entity supports the concept of logical deletion, then typically calling code will require a.cancel method to logically delete an instance of your entity.
If cancel support is required, change the entity API declaration to extend LogicallyDeleteable:
/** * This entity supports callers asking it to cancel itself. */ public interface MyLogicallyDeleteableEntity extends StandardEntity, LogicallyDeleteable { }
Note that support for logical deletes requires support for optimistic locking.
If your entity supports the concept of physical deletion, then typically calling code will require a.remove method to physically delete an instance of your entity.
Business tables in Cúram rarely support physical deletion (favoring logical deletion instead). Technical tables (such as link tables) may support physical removal.
e.g.:
/** * This entity supports callers asking it to remove itself. */ public interface MyPhysicallyDeleteableEntity extends StandardEntity, OptimisticLockRemovable { }