!--a11y-->
Opening a Configuration in Read or Write
Mode 
You can open a configuration in one of the following modes:
· Read mode – in this mode you can only read configuration data without modifying or deleting it. Note that you cannot access data that is being modified and is not yet committed to the database.
· Write mode – you can modify or delete configuration data. The access to a configuration in write mode is strictly transactional, which implies the following:
¡ Once opened in write mode, data is locked against other attempts to open it in write mode until the changes are committed and the configuration is explicitly closed.
¡ Changes are written to the database only at commit time.

When you open a configuration in write mode, the entire sub-tree is also locked and cannot be accessed for modifications by other threads.
You must have connected to the Configuration Manager.
...
1. When connecting to the Configuraiton Manager, you obtain an ApplicationConfigurationHandler instance. To open a configuration in read mode, you must call the openSubConfiguration() method of this instance with the appropriate parameter – that is, ConfigurationHandler.READ_ACCESS:

Object attribute_A, attribute_B;
boolean successfullyRead = false; while (!successfullyRead) {
//open configuration with pathname "data" in read-mode: Configuration data = cfgHandler.openSubConfiguration( "data", ConfigurationHandler.READ_ACCESS); ... |
2. You can now read particular configuration entries. You should enclose the operation in a try-catch block, closing the configuration in the finally clause.

try { //read desired configuration entries attribute_A = data.getConfigEntry("attribute_A"); attribute_B = data.getConfigEntry("attribute_B");
//all data has been consistently read. successfullyRead = true;
} catch (InconsistentReadException e) { //the configuration "data" has been modified since it was read //above. //data that has already been read is inconsistent => close //configuration and read it again. data.close(); } finally { data.close(); } |
The InconsistentReadException in the above example may occur in one of the following cases:
¡ The configuration, which you try to open, has been deleted.
¡ The configuration entries have been changed.
¡ Sub-configurations have been added or deleted.
In these cases you must close the configuration and then re-open it to get consistent data.
To open a configuration in write mode, invoke the openSubConfiguration() method of the ApplicationConfigurationHandler with parameter ConfigurationHandler.WRITE_ACCESS:

boolean configObtained = false; Configuration data = null;
while (!configObtained) { try { //open configuration with pathname "data" in write-mode: data = cfgHandler.openSubConfiguration( "data", ConfigurationHandler.WRITE_ACCESS ); //configuration has been successfully obtained; it is now //locked for further write access. configObtained = true; } catch (ConfigurationLockedException e) { //the configuration is already locked for write access. //send the current thread to sleep for a second and retry. try { Thread.sleep(1000); } catch (InterruptedException f) { } } } |
The ConfigurationLockedException in the above example signifies that the configuration is already open in write mode. The solution is to invoke sleep() on the application thread that attempts to access the configuration, and retry to open it after a specified timeout (1000 milliseconds in the example.)
After you have opened the configuration in write mode, you can create its sub-configurations or modify the configuration data.
See also:
For more information about the operations that you can perform on the open configuration, see the documentation of com.sap.engine.frame.core.configuration.Configuration interface in the SAP NetWeaver Developer Studio documentation.
