32.5. The InsertEvent

This diagram shows the interaction between the Controller object, the InsertEvent object and all the other actors that are used to process this database event.

Note: InsertEvent works similar to UpdateEvent and DeleteEvent, so the diagram above should explain the sequence of class messages for all those events. For further details, see the

  public void processEvent(Connection con)
      throws SQLException, MultipleValidationException
       

method of the selected DatabaseEvent class.

32.5.1. Event initialization

This database event is initialized by the following parameters and example values:

Table 32.3. initialization parameters and their meaning

action stringthe input action string generated by the parent jsp page
event typethe string identifying the event type
table idthe dbforms' table identifier (used to build the query string)
key idthe dbforms' key identifier related to the current table
insert button countbutton count used to identify individual insert buttons

Table 32.4. insert event parameters generated by a main form

action stringac_insert_0_root_5
event typeac_insert
table id0
key idroot
button count5

Table 32.5. insert event parameters generated by a subform

actionac_insert_1_0@root_17
event typeac_insert
table id1
key id0@root
button count17

32.5.2. Event steps

  • The Controller servlet calls the InsertEvent's processEvent method.

  • The InsertEvent object checks if the current user has got the INSERT privilege.

  • The InsertEvent object builds a FieldValues object representing the set of FieldValue objects to process. Then it copy the FieldValues data into a new fieldValueHashTable object that will be used as interceptor's input parameter.

  • The InsertEvent object checks if there is any interceptor object binded to the current main table. If yes, executes its PRE_INSERT hook method.

    Then the InsertEvent object synchronizes data from the fieldValueHashTable structure used as interceptor's input parameter (the hash table could contains values modified by the interceptor code) to the original FieldValues object (that will be used by the database insert operation).

  • The InsertEvent object builds a FieldValues object representing the set of FieldValue objects to process. Then it copy the FieldValues data into a new fieldValueHashTable object that will be used as interceptor's input parameter.

  • The InsertEvent object calls the checkSufficentValues method to check a list of conditions on the the input FieldValues object:

    • it must contains the same number of fields as the current main Table

    • any autoInc field must NOT have a related FieldValue object (generated by a request parameter) because that field value must be calculated by the underlying RDBMS

    if all the conditions above are true, the system continues the execution of the event flow, else it generates a SQLException that stops the event procession.

  • The InsertEvent object retrieve the DataSourceFactory and executes its doInsert method to store the data contained into the FieldValues object (the new record to insert) into the underlying database.

  • The InsertEvent object checks (again) if there is any interceptor object binded to the current main table. If yes, executes its POST_INSERT hook method.