001: // THIS SOFTWARE IS PROVIDED BY SOFTARIS PTY.LTD. AND OTHER METABOSS
002: // CONTRIBUTORS ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES, INCLUDING,
003: // BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
004: // FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL SOFTARIS PTY.LTD.
005: // OR OTHER METABOSS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
006: // INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
007: // LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
008: // OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
009: // LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
010: // NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE,
011: // EVEN IF SOFTARIS PTY.LTD. OR OTHER METABOSS CONTRIBUTORS ARE ADVISED OF THE
012: // POSSIBILITY OF SUCH DAMAGE.
013: //
014: // Copyright 2000-2005 © Softaris Pty.Ltd. All Rights Reserved.
015: package com.metaboss.enterprise.spi.inprocessimpl;
016:
017: import org.apache.commons.logging.Log;
018: import org.apache.commons.logging.LogFactory;
019:
020: /** Makes sure that domain is inialisd by whoever wants to get TransactionDomain first */
021: public class TyrexUtil {
022: private static final Log sLogger = LogFactory
023: .getLog(TyrexUtil.class);
024:
025: private static String sDomainName;
026: static {
027: try {
028: tyrex.tm.TransactionDomain lDomain = tyrex.tm.TransactionDomain
029: .createDomain("domainconfig.xml");
030: sDomainName = lDomain.getDomainName();
031: // Initialise all datasources
032: /* This code was commented out, because tyrex works from XML file out of the box
033: tyrex.resource.Resources lDomainResources = lDomain.getResources();
034: java.util.Iterator lIterator = lDomainResources.listConfigurations();
035: for( int i = 0; lIterator.hasNext(); i++)
036: {
037: // Initialise factories
038: tyrex.resource.ResourceConfig lConfig = (tyrex.resource.ResourceConfig)lIterator.next();
039: Object lFactory = lConfig.createFactory();
040: //-------------------------------------------------------------------------------------------------
041: // General tyrex problem is that config is not passed to factory correctly (or at least we could not see it
042: // for now we will use simple, but dirty solution
043: // we will try to load additional properties file with the datatsource name and
044: // set all the properties is it
045: {
046: String lPropertiesFileName = lConfig.getName() + ".properties";
047: java.io.File lFile = new java.io.File(lPropertiesFileName);
048: if (lFile.exists() && lFile.isFile() && lFile.canRead())
049: {
050: try
051: {
052: java.util.Properties lExtraProps = new java.util.Properties();
053: lExtraProps.load(new java.io.FileInputStream(lFile));
054: java.util.Enumeration lPropertyNames = lExtraProps.propertyNames();
055: Class lFactoryClass = lFactory.getClass();
056: while(lPropertyNames.hasMoreElements())
057: {
058: String lPropertyName = (String)lPropertyNames.nextElement();
059: java.lang.reflect.Method lSetMethod = lFactoryClass.getMethod("set" + lPropertyName, new Class[] { String.class });
060: if (lSetMethod != null)
061: {
062: lSetMethod.invoke(lFactory, new Object[] {lExtraProps.getProperty(lPropertyName)});
063: }
064: }
065: }
066: catch(Exception e)
067: {
068: // Ignore - just means that thre are no extra properties to set
069: sLogger.error("Exception caught while configurring " + lConfig.getName() + " datasource from file " + lPropertiesFileName, e);
070: }
071: }
072: else
073: sLogger.warn("File " + lPropertiesFileName + " not found. " + lConfig.getName() + " data source is likely to be not configurred properly.");
074: }
075: // Cloudscape only problem. Think about it latter
076: // if (lFactory instanceof com.ibm.db2j.jdbc.DB2jXADataSource)
077: // {
078: // if (lConfig.getName().equals("DataSources_HatMaker_Core"))
079: // ((com.ibm.db2j.jdbc.DB2jXADataSource)lFactory).setDatabaseName("C:/Cloudscape_5.1/demo/databases/HatMaker_Core");
080: // else
081: // if (lConfig.getName().equals("DataSources_HatMaker_Main"))
082: // ((com.ibm.db2j.jdbc.DB2jXADataSource)lFactory).setDatabaseName("C:/Cloudscape_5.1/demo/databases/HatMaker_Main");
083: // }
084: // Oracle only problem. Think about it latter
085: lConfig.setFactory(lFactory);
086: }
087: */
088: // Now that we are fully setup - do recovery
089: lDomain.recover();
090:
091: } catch (tyrex.tm.DomainConfigurationException e) {
092: sLogger
093: .error(
094: "Error loading Tyrex domain details. Transaction and resource management facilities are not initialised properly and will not work as expected.",
095: e);
096: } catch (tyrex.tm.RecoveryException e) {
097: for (int i = 1; e != null; i++) {
098: sLogger
099: .error(
100: "Error ("
101: + i
102: + ") recovering outstanding Tyrex domain transactions. Manual intervention may be required.",
103: e);
104: e = e.getNextException();
105: }
106: }
107: }
108:
109: /** Method used to obtain JTA's user transaction */
110: public static tyrex.tm.TransactionDomain getTransactionDomain() {
111: return tyrex.tm.TransactionDomain.getDomain(sDomainName);
112: }
113: }
|