Create an implementation for your entity interface

You must create an implementation class for your entity interface. In this scenario you will only create the skeleton of your implementation class - it will be fleshed-out in later scenarios.

Create a class in the same package as your entity interface, and name the class after your entity, suffixed with Impl:

Figure 1. Creating an entity implementation file
package curam.mypackage;

/**
 * Standard implementation of {@linkplain MyNewEntity}.
 */
public class MyNewEntityImpl
}

Your entity implementation must implement the entity interface:

Figure 2. Implementing the entity API
public class MyNewEntityImpl implements MyNewEntity {

There are a number of common development patterns in the Cúram server layer, and the Persistence Infrastructure comes with a number of helper implementations that implement these patterns.

A common pattern is that an entity:

These patterns are implemented by the SingleTableLogicallyDeleteableEntityImpl helper class, so let's base your entity implementation on it:

Figure 3. Entity implementing extending SingleTableLogicallyDeleteableEntityImpl
package curam.mypackage;
import curam.mypackage.struct.MyNewEntityDtls;
import
  curam.util.persistence.helper.SingleTableLogicallyDeleteableEntityImpl;

/**
 * Standard implementation of {@linkplain MyNewEntity}.
 */
public class MyNewEntityImpl extends
    SingleTableLogicallyDeleteableEntityImpl<MyNewEntityDtls>
    implements MyNewEntity {
SingleTableLogicallyDeleteableEntityImpl provides a standard implementation of these methods:

Add a protected no-argument constructor:

Figure 4. Adding a protected constructor to the entity implementation
protected MyNewEntityImpl() {
    /* Protected no-arg constructor for use only by Guice */
  }

Use the "Add unimplemented methods" feature in Eclipse to add in the methods you must implement, and categorize them to aid readability:

Figure 5. Adding unimplemented methods to the entity implementation
package curam.mypackage;

import java.util.HashMap;
import java.util.Map;
import java.util.Set;

import com.google.inject.Inject;

import curam.message.impl.MYNEWENTITYExceptionCreator;
import curam.mypackage.codetable.impl.MYLIFECYCLEENTITYSTATEEntry;
import curam.mypackage.struct.MyNewEntityDtls;
import curam.util.persistence.ValidationHelper;
import curam.util.persistence.helper.CodetableState;
import
  curam.util.persistence.helper.SingleTableLogicallyDeleteableEntityImpl;
import curam.util.persistence.helper.State;
import curam.util.persistence.helper.Transition;
import curam.util.type.DateRange;
import curam.util.type.StringHelper;

/**
 * Standard implementation of {@linkplain MyNewEntity}.
 */
public class MyNewEntityImpl extends
    SingleTableLogicallyDeleteableEntityImpl<MyNewEntityDtls>
    implements MyNewEntity {

  protected MyNewEntityImpl() {
    /* Protected no-arg constructor for use only by Guice */
  }

  /*
   * Field getters
   */
  public String getName() {
    // TODO Auto-generated method stub
    return null;
  }

  public DateRange getDateRange() {
    // TODO Auto-generated method stub
    return null;
  }

  public State getLifecycleState() {
    // TODO Auto-generated method stub
    return null;
  }

  public MYNEWENTITYTYPEEntry getType() {
    // TODO Auto-generated method stub
    return null;
  }

  /*
   * Related-entity getters
   */
  public Set<MyChildEntity> getMyChildren() {
    // TODO Auto-generated method stub
    return null;
  }

  public MyParentEntity getMyParentEntity() {
    // TODO Auto-generated method stub
    return null;
  }

  /*
   * Setters
   */
  public void setMyParentEntity(MyParentEntity value) {
    // TODO Auto-generated method stub

  }

  public void setName(String value) {
    // TODO Auto-generated method stub

  }

  public void setType(final MYNEWENTITYTYPEEntry value) {
    // TODO Auto-generated method stub
  }

  /*
   * Validation
   */
  public void mandatoryFieldValidation() {
    // TODO Auto-generated method stub

  }

  public void crossFieldValidation() {
    // TODO Auto-generated method stub

  }

  public void crossEntityValidation() {
    // TODO Auto-generated method stub

  }

}

Your implementation of the skeletal entity interface is now complete. However, there is a final important step, which is to specify your entity implementation as the default implementation of the entity interface.

Open the entity interface and add an annotation prescribing the default implementation:

Figure 6. Specifying the entity implementation as the default implementation of the entity API
/**
 * Description of my wonderful new entity.
 */
@ImplementedBy(MyNewEntityImpl.class)
public interface MyNewEntity extends StandardEntity, DateRanged,
    Insertable, OptimisticLockModifiable, LogicallyDeleteable {

If you fail to do this step, then when your application runs you will likely see exceptions when Guice callers of your API attempt to read or create instances of your entity:

Figure 7. Exceptions will occur if no default entity implementation is specified on the entity API
/*
     * These attempts to construct instances of the entity interface
     * will fail if you don't specify the default implementation of
     * MyNewEntity properly...
     */
    final long someID = 123;
    final MyNewEntity tryingToRead = myNewEntityDAO.get(someID);

    final MyNewEntity tyringToCreate = myNewEntityDAO.newInstance();