Struts DataSource Manager |
|
ConfigurationBase configuration1) First of all you load the plug-in through the struts-config.xml. Just put this XML piece:
Obviously you must set the "value" attribute of the "set-property" element accordingly to your configuration file path. 2) Now you must configure the DataSource you need. Here is an example:
As you can see, it is a normal DataSource configuration, just as you did inside the "struts-config.xml" file. For this reason, if you have a DataSource configured in "struts-config.xml", you have only to cut and paste the "data-sources" piece inside the new XML file. For documentation about basic DataSource configuration, see the docs in Struts ;-) Advanced configurationNow the good news. How many times did you ask yourself "Why do I have to get a DataSource inside an Action? Action is Controller and DataSource is Model, it is an overlapping of competence, right?" It's time to change. Now you can configure a DataSource so that it will be used inside business delegates. OK, probably there is space for improvement, but now this is all I need in my projects. 1) Create a business delegate that implements the "net.sourceforge.sdsmanager.business.DataSourceUser" interface. There are two methods in this interface:
For setting the default DataSource. In fact it will be never called, but it can be useful, so I put it :-P
For setting a keyed DataSource. The key is the same specified in the XML file or (if not specified) it's the default key used in Struts, i.e.:
2) Be sure that your delegate is a singleton, with a method:
that returns the only instance of the delegate itself. 3) Configure the delegate in the "sdsmanager-config.xml" file this way:
This way you assign the DataSource keyed with "mykey" to the singleton "TestDelegate". Notice that for now only the pattern "singleton" is supported. You can also avoid to specify the "key" attribute if you use an unkeyed DataSource. In this case, the unkeyed DataSource will be passed to the delegate. Reloading the configurationSuppose that you modify the DataSource configuration (either base or advanced, or both), for example by using some administration tool, or simply a bunch of Actions and JSP pages that can modify the "sdsmanager-config.xml". You can reload the configuration without reloading the entire application in this ways: 1) By calling the "net.sourceforge.sdsmanager.action.ReloadAllAction". Obviously you have to configure this action, for example this way:
Remember to configure the local forwards "success" and "failure"! 2) By calling the "reloadAll"
method of " (You have to call "getInstance()" to get the single instance). 3) You can reload only a specific
SDSManager. An instance of SDSManager will be created for each
module. You can get the SDSManager instances bound to a
configuration file (e.g. sdsmanager-config.xml) by calling the
method " |