How to access data store configuration in Mx 2.5

We're migrating a project that contains the following legacy Java code: DataStoreConfiguration dbConfiguration = Configuration.getConnectionBusConfiguration().getDataStoreSuppliers().get(0).getDataStoreRegistrations().get(0).getDataStoreConfiguration(); String driverName = dbConfiguration.getField("driver"); String url = dbConfiguration.getField("url"); Properties props = dbConfiguration.getProperties(); String username = null; String password = null; for( Entry<Object, Object> obj : props.entrySet() ) { String key = (String)obj.getKey(); if( key.contains("user") ) username = (String) obj.getValue(); else if( key.contains("pass") ) password = (String) obj.getValue(); } However, the method getDataStoreSuppliers() is no longer available on the ConnectionBusConfiguration object. Is there another way to get to these database configuration properties? PS Please don't ask why we need to do this... its legacy code ;-) EDIT: As a (temporary?) workaround, I've created my own DataStoreConfiguration object. It's edited using a microflow from the navigation, which ensures there is always only 1 object instance. However, this means I have to duplicate the Mendix database configuration settings (and thus password) in the runtime database, which I'm not particularly happy with... Any ideas?? Has this functionality been completely removed? I suppose the correct way to refactor this code is to step away from SQL and move back to OQL generated in a Java action.
1 answers

I don't know any way to retrieve those settings either. I tried using Core.getConfiguration().getCustomConfigProperty(String), but this method (as its name implies) only seems to access custom properties. However, there is a method for retrieving the database name (but not the other settings): Core.getConfiguration().getDatabaseName().

As to your workaround, I would store the (duplicate) settings in project constants. This has the following advantages:

  • Easier to configure and no need for the system administrator to have runtime access to your application, since project constants are defined the same way as the other project settings (including the "real" database settings), namely in the model (when running from the modeler) or in the Mendix Service Console (Windows server deployment) or in application.conf (non-Windows server deployment).
  • Doesn't make it less secure, because the settings are not stored or visible in the runtime environment. Even if someone somehow has access to the project constant settings, this most likely doesn't provide him/her with any information that he/she couldn't already access.
  • No need to worry whether your configuration object exists and what to do when it doesn't (or when multiple configuration objects are found!), since project constants must be defined for the project to run.

I would then pass the values to the Java action using parameters. You could use Core.getConfiguration().getConstantValue(String), but I wouldn't advice it, as this makes it more error prone: you can't use "find all references" on the constants this way (very useful feature!) and every time you rename a constant your Java action will compile just fine, but probably cause runtime exceptions.