Skip to content

Latest commit

 

History

History
110 lines (83 loc) · 5.09 KB

eo_create.md

File metadata and controls

110 lines (83 loc) · 5.09 KB

Callback methods in EO instance creation phase

Related methods

API Doc

initialize()

initDefaults() Initialize Entity row's default values. It walks through all entity definitions and initializes the attribute with the static default value (from the definition).

create(AttributeList nameValuePair) This method should be subclassed to supply programmatic default values to various attributes of a new Entity Object. Instances of subclasses should call super.create() before performing any operations.

initDefaultExpressionAttributes(AttributeList nameValuePair) Used to initialize this entity with values from evaluated expressions on the attributedefs. No events are generated and evaluated values replace any existing values in the relevant attributes unless it was overridden via nameValuePair.


If you have ADF source code, you can read, debug directly. Otherwise, we can override these methods in EO to detect the sequence.
I use regions table in HR schema. The RegionEO is quite simple:

In RegionEOImpl.java, I just override them and add log output.

@Override
protected void create(AttributeList attributeList) {        
    _logger.info("--Start RegionEOImpl::create()");
    super.create(attributeList);
    _logger.info("--End RegionEOImpl::create()");
}

@Override
protected void initialize() {
    _logger.info("--Start RegionEOImpl::initialize()");
    super.initialize();
    _logger.info("--End RegionEOImpl::initialize()");
}

@Override
protected void initDefaults() {
    _logger.info("--Start RegionEOImpl::initDefaults()");
    super.initDefaults();        
    _logger.info("--End RegionEOImpl::initDefaults()");
}

@Override
protected void initDefaultExpressionAttributes(AttributeList nameValuePair) {
    _logger.info("--Start RegionEOImpl::initDefaultExpressionAttributes()");
    super.initDefaultExpressionAttributes(nameValuePair);
    _logger.info("--End RegionEOImpl::initDefaultExpressionAttributes()");
}

In TestAppModuleImpl.java, I add two methods.

public void createRegionEntity() {
    EntityDefImpl regionEODef = RegionEOImpl.getDefinitionObject();
    RegionEOImpl row = (RegionEOImpl)regionEODef.createInstance2(this.getDBTransaction(),null);
    System.out.println("~~~~~ Regin Name " + row.getRegionName());
}

//for test
public static void main(String[] args) {
    String amDef = "com.adfnotes.model.am.TestAppModule";
    String config = "TestAppModuleLocal";
    TestAppModuleImpl am = (TestAppModuleImpl)Configuration.createRootApplicationModule(amDef, config);
    am.createRegionEntity();
    Configuration.releaseRootApplicationModule(am, true);
}

Note: We should NOT create entity instance directly, here just for debug purpose.

Add -Djbo.debugoutput=console in Java options of run configuration. Then, just debug TestAppModuleImpl.java, you can see following outupt in console.

2012-10-28 8:30:06 com.adfnotes.model.entity.RegionEOImpl initialize
信息: --Start RegionEOImpl::initialize()
2012-10-28 8:30:06 com.adfnotes.model.entity.RegionEOImpl initialize
信息: --End RegionEOImpl::initialize()
2012-10-28 8:30:06 com.adfnotes.model.entity.RegionEOImpl initDefaults
信息: --Start RegionEOImpl::initDefaults()
2012-10-28 8:30:06 com.adfnotes.model.entity.RegionEOImpl initDefaults
信息: --End RegionEOImpl::initDefaults()
2012-10-28 8:30:06 com.adfnotes.model.entity.RegionEOImpl create
信息: --Start RegionEOImpl::create()
2012-10-28 8:30:06 com.adfnotes.model.entity.RegionEOImpl initDefaultExpressionAttributes
信息: --Start RegionEOImpl::initDefaultExpressionAttributes()
2012-10-28 8:30:06 com.adfnotes.model.entity.RegionEOImpl initDefaultExpressionAttributes
信息: --End RegionEOImpl::initDefaultExpressionAttributes()
2012-10-28 8:30:06 com.adfnotes.model.entity.RegionEOImpl create
信息: --End RegionEOImpl::create()
~~~~~ Regin Name null

The sequence is straightforward:

Note: initDefaultExpressionAttributes() is called in create().

You can override these methods to supply default value to attribute for newly created row, I think create() is the first option, initDefaults() and initDefaultExpressionAttributes() are also invoked in refresh phase. A typical case is initialize primary key with database sequence:

@Override
 public void create(AttributeList attributeList) {
     super.create(attributeList);
     SequenceImpl seq = new SequenceImpl
     ("XXX_SEQ", getDBTransaction());
     Integer seqNextval = seq.getSequenceNumber().intValue();
     setXXXId(seqNextval);
}

You can change Default Vaule settings of attribute to watch behaviors of initDefaults() (static value) and initDefaultExpressionAttributes() (groovy expression).

Reference: Oracel ADF Real World Developer's Guide, Chapter 5