2Pack/Reference

From ADempiere
Jump to: navigation, search
This Wiki is read-only for reference purposes to avoid broken links.

Background

  • The AD is a series of table to sub-table relationships.
  • These relationships are denoted by the existence of Foreigh Key ID (FK) references within respective tables.
  • However during PackIn process, such FKs may not be known as the sub-tables are not created yet. So PackInHandler uses a Defer Method to wait until that sub-table is created.
  • For example a Menu may point to a Window but does not know of its Window_ID yet as that window was not created at that moment. Likewise a Window may have few tabs but do not know each Tab_ID until the Tabs are created first.

Reference Examples

  • In our PackOut.xml[1] example, the first Menu tag is a summary menu where there is a sub-menu called IS_Booking.
  • In that sub-menu tag there is a Parent_ID reference to the summary menu.
  <Parent_ID reference="table" reference-key="AD_Menu.Name">Afrikiya</Parent_ID>
  • There is also a reference that points to another sub-tag which holds a Window called also IS_Booking.
  <AD_Window_ID reference="table" reference-key="AD_Window.Name">IS_Booking</AD_Window_ID>

Parent ID debugging

  • Parent ID is used when there is backward referencing without the referenced item holding such reference. This is often the case for summary items such as in Orgs and Menus.
  • During debugging of the above example, i noted and confirmed that the Defer method was triggered on the sub-menu IS_Booking because there is a sub-menu Window reference that does not exist.
  • Since the Defer Method is quite complex, i focused on the more obvious Parent_ID.
  • Firstly i have to check if the Parent ID reference handling was called in the MenuElementHandler:
Element parentElement = element.properties.get("Parent_ID");
int parentId = 0;
if (parentElement != null) {
	if (ReferenceUtils.isIDLookup(parentElement) || ReferenceUtils.isUUIDLookup(parentElement)) {
		parentId = ReferenceUtils.resolveReference(ctx, parentElement);
	} else {
		String parent = getStringValue(element, "Parent_ID");
		parentId = findIdByName(ctx, "AD_Menu", parent);
	}
}
  • So what i did was to comment off its Defer Method so it won't get deferred but execute the above.
  • Luckily it did get executed with the Parent_ID Afrikiya retrieved nicely.
  • That means i will now focus on the Defer Method to be the possible culprit.

See Also