You must create implementations for your skeletal getter methods created above. Each getter method is responsible for retrieving one or more fields from an underlying Dtls struct and returning a value (either primitive or object) to calling code.
The implementation of your entity has at its heart an instance of a RowManager. The RowManager instance contains a generated Dtls struct and manages the manipulation of this struct.
Getter methods must use the RowManager. getDtls method to get at the Dtls struct. For implementations extending SingleTableEntityImpl (which the example does via SingleTableLogicallyDeleteableEntityImpl), there is a convenience getDtls method which can be used directly as a shorthand.
In general the JavaDoc for your getter implementations can simply inherit from your entity API JavaDoc.
The getter for name is a straight-forward mapping of the name held in the Dlts struct:
/** * {@inheritDoc} */ public String getName() { return getDtls().name; }
The getter for your entity's date range must use the startDate and endDate held on the generated Dtls struct and construct a new DateRange object:
/** * {@inheritDoc} */ public DateRange getDateRange() { return new DateRange(getDtls().startDate, getDtls().endDate); }
The getter for your entity's type must retrieve the relevant MYNEWENTITYTYPEEntry value based on the codetable code String value held in the typeCode field on the Dtls struct:
/** * {@inheritDoc} */ public MYNEWENTITYTYPEEntry getType() { return MYNEWENTITYTYPEEntry.get(getDtls().typeCode); }
The getter for a single record must retrieve that related record and return it. However, the getter must check whether the key is currently zero (which is used throughout the server application to signify that a unique ID value has not been set), and if so instead return null.
Create a class member variable for the related record's DAO:
@Inject private MyParentEntityDAO myParentEntityDAO;
In the getter, conditionally call the DAO, depending on whether the value of myParentEntityID is zero:
/** * {@inheritDoc} */ public MyParentEntity getMyParentEntity() { final long myParentEntityID = getDtls().myParentEntityID; if (myParentEntityID == 0) { return null; } else { return myParentEntityDAO.get(myParentEntityID); } }
The getter for a set of related records must call a DAO method to perform a search.
Create a class member variable for the related records' DAO:
@Inject private MyChildEntityDAO myChildEntityDAO;
In the getter, call the DAO passing in this object:
/** * {@inheritDoc} */ public Set<MyChildEntity> getMyChildren() { return myChildEntityDAO.searchByParent(this); }
You must add the searchByParent method to the DAO:
/** * Data access for {@linkplain MyChildEntity}. */ public interface MyChildEntityDAO extends StandardDAO<MyChildEntity> { /** * Searches all the instances belonging to the specified parent. * * @param myNewEntity * the parent to search for * @return all the instances belonging to the specified parent, or * an empty set if none found. */ public Set<MyChildEntity> searchByParent( final MyNewEntity myNewEntity);
/** ********** VERY VERY BAD - DO NOT DO THIS! ********** */ /** * Searches all the instances belonging to the specified parent. * * @param impl * the parent to search for * @return all the instances belonging to the specified parent, or * an empty set if none found. */ public Set<MyChildEntity> searchByParent(MyNewEntityImpl impl); /** ********** VERY VERY BAD - DO NOT DO THIS! ********** */
(The underlying principle here is that entity and DAO interfaces are allowed to be dependent on other entity and DAO interfaces, but are not allowed to be dependent on implementations.)
If an implementation exists for MyChildEntityDAO, then you must implement the new method, and model a new search operation (a readmulti) to retrieve the required records.