Class ModelAccessorGenerator

java.lang.Object
org.adempiere.util.ModelAccessorGenerator

public class ModelAccessorGenerator extends Object
Generate an accessor class for the columns of a table selected by the column entity type filter: typed getters and setters over any PO of that table, with the behaviour of the generated X_ accessors.

Example: C_Order_XYZ.of(order).getXYZ_Carrier_ID(). The class needs no model factory and works on any object of the table, also one that core created with new MOrder(...). In a callout, C_Order_XYZ.of(mTab) reads and writes the fields of the tab. With the interface generated in the same run, the class implements it (I_C_Order_XYZ).

  • int getter: 0 when empty; boolean getter: Boolean, "Y" true, otherwise false; BigDecimal getter: zero when empty
  • _ID setter: null below 1 (below 0 for the columns where 0 is valid, as in ModelClassGenerator)
  • a column that is not updateable is written with set_ValueNoCheck; a virtual column cannot be set
  • set_Value reports a column the table does not have, so a renamed column fails at the first write
  • list columns get the value constants of the X_ class, for example SHIPPINGRULE_Force
  • on a GridTab: values go through GridTab.setValue, so dependent callouts run and the field's read-only rules apply, also for a column that is not updateable (there is no NoCheck on a tab); an error of setValue or a column the tab does not have is reported with an exception
  • an encrypted column is refused (checkColumns(int, java.lang.String)): the accessor reads and writes through the public PO methods, which do not encrypt
  • Constructor Details

    • ModelAccessorGenerator

      public ModelAccessorGenerator(int AD_Table_ID, String directory, String packageName, String entityTypeFilter, String suffix, boolean implementInterface)
      Parameters:
      AD_Table_ID - table
      directory - output directory, package path included
      packageName - package of the generated class
      entityTypeFilter - column filter, as for the interface generator, or null for all columns
      suffix - owner of the columns, class name <Table>_<suffix>; required
      implementInterface - true when the interface of the same run (I_<Table>[_<suffix>]) is implemented
  • Method Details

    • checkNotDictionaryColumns

      public static void checkNotDictionaryColumns(int AD_Table_ID, String columnNames)
      Refuse columns of the dictionary entity type D that are named one by one (--columns=): the accessor only gets and sets values, so it would skip the logic of the model classes.
      Parameters:
      AD_Table_ID - table
      columnNames - comma separated column names
      Throws:
      IllegalArgumentException - for a column of entity type D (rule S7)
    • checkColumns

      public static void checkColumns(int AD_Table_ID, String entityTypeFilter)
      Refuse a table whose selected columns cannot get an accessor with the behaviour of the X_ class.
      Parameters:
      AD_Table_ID - table
      entityTypeFilter - column filter, as for the constructor, or null for all columns
      Throws:
      IllegalArgumentException - for an encrypted column: X_ uses set_ValueE / get_ValueE, which PO does not offer to other classes, so the accessor would store the value in plain text
    • className

      public static String className(String tableName, String suffix)
      Returns:
      class name <Table>_<suffix>; the interface of the same owner is I_<Table>_<suffix>