Hi,
This email describes a change in the way the admin mode can be set in
the OBContext instance. Please read this as it is very relevant for
developers using the DAL.
Sometimes it is necessary to read information from the database for
which the current user does not have enough privileges, for this the
admin mode concept is used.
Currently the way to set admin mode is through this structure:
final boolean prevMode = OBContext.getOBContext().setInAdministratorMode(true);
try {
// do administrative things here
} finally {
OBContext.getOBContext().setInAdministratorMode(prevMode);
}
This structure has risks and results in unpredictable
results/difficult-to-solve-errors when used in a nested manner (so within the
try block a method is called which again sets the admin mode).
A new api has been introduced which handles nested 'adminmode' calls
automatically. The new structure is as follows:
try {
OBContext.setAdminMode();
// do administrative things here
} finally {
OBContext.restorePreviousMode();
}
The 'old' approach was used in many places in openbravo/src and
openbravo/src-test. I have changed all the calls to use the new api. The diff
has been double checked and tested by Stefan. I pushed the changes to pi.
The old api has @deprecated annotations so when you compile you can possibly
see compile warnings with a message to use the new api. When you encounter
these compile warnings in your modules you should change to use the new api.
The old api will still work fine.
Developers guide entries (note links maybe line-broken by your email client):
http://wiki.openbravo.com/wiki/ERP/2.50/Developers_Guide/Concepts/Data_Access_Layer#Administrator_Mode
http://wiki.openbravo.com/wiki/ERP/2.50/Developers_Guide/Common_Issues,_Tips_and_Tricks#Getting_warning:_Unbalanced_calls_to_enableAsAdminContext_and_resetAsAdminContext
--
With Regards, Martin Taal
Openbravo
M: +31 6 288 48 943
@: [email protected]
Skype: martintaal
Openbravo Headquarters:
P: +34 93 27 25 947
F: +34 93 27 25 905
Address: Edificio Slan, Planta 2a, Landaben, Calle J, 31012 Pamplona, Navarra,
Spain
Mailing address: PO Box 5117, 31010 Pamplona, Navarra, Spain
------------------------------------------------------------------------------
_______________________________________________
Openbravo-development mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/openbravo-development