push the middle-tier changes to the database without actually committing.
Scenario # You have a Master and detail tables and there is no foregin key relation ship, You may have to get the Master Primary key and set to child Entity, DBTransaction.commit() should first save the master record into Database then upon successful saving master recrod it should save the child recrod. So that dbTransaction.commit() shound't throw any 'Key Not found' related exceptions while saving both master and detail data in a single trascation.
Solution : postChange() override this method in EntityImpl class, what this will do is Push the middle-tier database related changes to database without actually performing commit, so that when child record gets inserted into database without any errors.
Refer below for more information http://docs.oracle.com/cd/B14099_19/web.1012/b14022/oracle/jbo/server/EntityImpl.html#postChanges_oracle_jbo_server_TransactionEvent_ Override below two methods in both master and child EOImpl classes
MasterEOImpl.java
public void postChanges(TransactionEvent TransactionEvent) {
if (getPostState() == STATUS_NEW) {
mNewServiceProviderCostsBeforePost = (RowSet) getServiceProviderCostEO();
}
super.postChanges(TransactionEvent);
}
ChildEOImpl.java
public void postChanges(TransactionEvent e)
{
if (getPostState() == STATUS_NEW getPostState() == STATUS_MODIFIED) {
MasterEOImpl masterEO= getMasterEO();
if (masterEO!= null) {
if (masterEO.getPostState() == STATUS_NEW) {
masterEO.postChanges(e);
}
}
}
super.postChanges(e);
}
and also override below methods in MasterEOImpl.java
refreshFKInNewContainees() - Iterate the child RowSet and set the primary key then close the rowSetIterator.
handlePostChangesError() - Override this method , If any error happens this will get invoked and close row set iterator.
No comments:
Post a Comment