Create a menu item¶
Creates a new menu item, illustrating the create pattern shared by every maintenance object in this library (clsMenuPage, clsMenuSecurity, clsMenuSecurityUser, clsMenuFavorite, clsApplicationCode, clsMenuCategoryCode), including the cascading save of the item's child security groups.
| Field | Value |
|---|---|
| Operation ID | OP-MENU-06 |
| Trigger | Administration code calls clsMenuItem.NewMenuItem(dpi) then Save() |
| Inputs | Item properties supplied by the caller; DataPortalInfo.UserID |
| Outputs | New MENU_ITEM row and a populated sequence number |
| Primary components | clsMenuItem (create + insert); the same pattern applies to every maintenance object in this library |
| Entry point | SAIF.Business.Menu/clsMenuItem.vb |
Steps¶
NewMenuItemcallsDataAccessLayer.CreateObject(New Criteria(dpi)).BeforeCreateissues aScalarrequest withCreateSQL=SELECT MENU_ITEM_SEQ.NEXTVAL FROM DUAL(SQL-002). (BR-MENU-014)AfterCreatestores the returned sequence into both the object and the criteria, stampsUpdateDate = NowandUpdateUserfromDataPortalInfo.UserID.Trim.ToUpper, thenMarkNew+MarkClean. (BR-MENU-015, BR-MENU-016)- The caller sets properties; each setter compares old and new values and calls
MarkDirtyonly on an actual change. (BR-MENU-017) Save→SaveMe: if the object itself is dirty, callMyBase.SaveChild()when it is a child, elseMyBase.Save(). (BR-MENU-018)- If not dirty: no database work occurs.
BeforeInsertissues aNonQuerywithInsertSQL(SQL-008) and parametersMenuItemSeqNum,MenuPageSeqNum,MenuCategoryCode(5),VisibleFlag(1, fromIsVisible.ToY_N_String),PageOrder,ToolTip(1000),UserId(30).UPDATE_DATEis set toSYSDATEin SQL, not passed. (BR-MENU-016, BR-MENU-019; table MENU_ITEM)AfterInsertrequires exactly one affected row; otherwise it adds error messageInsertError= "Insert Failed". On success it callsMarkOld. (BR-MENU-020)- On failure (rows affected ≠ 1): the object records the
InsertErrorerror message instead of throwing. - After the parent save succeeds, if
SecurityGroups.IsDirtythe childclsMenuSecurityCollectionis saved withSaveChildObject(SQL-010, table MENU_SECURITY). (BR-MENU-021)
Process flow¶
flowchart TD
Start([NewMenuItem]) --> Seq[BeforeCreate: fetch MENU_ITEM_SEQ.NEXTVAL]
Seq --> Stamp[AfterCreate: stamp UpdateDate/UpdateUser, MarkClean]
Stamp --> SetProps[Caller sets properties, MarkDirty on change]
SetProps --> Dirty{Object dirty?}
Dirty -->|No| Skip([Save is a no-op])
Dirty -->|Yes| Insert[BeforeInsert: INSERT MENU_ITEM row]
Insert --> RowCheck{Exactly one row affected?}
RowCheck -->|No| Fail([AfterInsert: add InsertError])
RowCheck -->|Yes| MarkOld[AfterInsert: MarkOld]
MarkOld --> SecDirty{SecurityGroups dirty?}
SecDirty -->|Yes| SaveChild([SaveChildObject: insert MENU_SECURITY rows])
SecDirty -->|No| Done([Create complete])
SaveChild --> Done
Failure and edge-case behavior¶
- Insert affects zero or more than one row:
AfterInsertaddsInsertError= "Insert Failed" instead of throwing. - Object is not dirty when
Saveis called: no database work occurs.
Related documentation¶
Sources¶
- SAIF.Business.Menu/clsMenuItem.vb
- SAIF.Business.Menu/clsMenuSecurityCollection.vb