001: /*
002: * Enhydra Java Application Server Project
003: *
004: * The contents of this file are subject to the Enhydra Public License
005: * Version 1.1 (the "License"); you may not use this file except in
006: * compliance with the License. You may obtain a copy of the License on
007: * the Enhydra web site ( http://www.enhydra.org/ ).
008: *
009: * Software distributed under the License is distributed on an "AS IS"
010: * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See
011: * the License for the specific terms governing rights and limitations
012: * under the License.
013: *
014: * The Initial Developer of the Enhydra Application Server is Lutris
015: * Technologies, Inc. The Enhydra Application Server and portions created
016: * by Lutris Technologies, Inc. are Copyright Lutris Technologies, Inc.
017: * All Rights Reserved.
018: *
019: * Contributor(s):
020: *
021: * $Id: JtaDiscRack.java,v 1.2 2007-05-22 10:19:28 sinisa Exp $
022: */
023:
024: package jtaDiscRack;
025:
026: import javax.naming.InitialContext;
027: import javax.transaction.UserTransaction;
028:
029: import com.lutris.appserver.server.*;
030:
031: import com.lutris.appserver.server.httpPresentation.*;
032: import com.lutris.util.*;
033:
034: import jtaDiscRack.spec.UserTransactionJNDI;
035:
036: /**
037: * The application object.
038: *
039: * Application-wide data would go here.
040: */
041: public class JtaDiscRack extends StandardApplication {
042:
043: /*
044: * A few methods you might want to add to.
045: * See StandardApplication for more details.
046: */
047: public void startup(Config appConfig) throws ApplicationException {
048:
049: // Get the UserTransaction JNDI path from configuration (used for transaction lookup)
050: String db = null;
051: try {
052: db = appConfig
053: .getString("NameDatabaseManager/DefaultDatabase");
054: } catch (ConfigException e1) {
055: db = "sid1";
056: }
057: String propertyName = "DatabaseManager.DB." + db
058: + ".XaUserTransactionLookupName";
059: try {
060: jtaDiscRack.spec.UserTransactionJNDI.jNDIName = appConfig
061: .getString(propertyName);
062: } catch (ConfigException ex) {
063: try {
064: propertyName = "DatabaseManager.DB." + db
065: + ".XATransactionManagerLookupName";
066: UserTransactionJNDI.jNDIName = appConfig.getString(
067: propertyName, "java:comp/env/UserTransaction");
068: } catch (ConfigException exc) {
069: UserTransactionJNDI.jNDIName = "java:comp/env/UserTransaction";
070: }
071: }
072:
073: try {
074: // Get UserTransaction (sync cache load)
075: UserTransaction ut = (UserTransaction) new InitialContext()
076: .lookup(UserTransactionJNDI.jNDIName);
077: // Set timeout for UserTransaction (sync cache load)
078: ut.setTransactionTimeout(60 * 30);
079: // Begin UserTransaction (enabling sync cache load)
080: ut.begin();
081: // StandardApplication startup (initalizes sync cache load)
082: super .startup(appConfig);
083: // No need for UserTransaction commit - only read (sync cache load)
084: ut.rollback();
085: } catch (Exception e) {
086: throw new ApplicationException(e);
087: }
088:
089: }
090:
091: public boolean requestPreprocessor(HttpPresentationComms comms)
092: throws Exception {
093: return super .requestPreprocessor(comms);
094: }
095:
096: /**
097: * This is an optional function, used only by the Multiserver's graphical
098: * administration. This bit of HTML appears in the status page for this
099: * application. You could add extra status info, for example
100: * a list of currently logged in users.
101: *
102: * @return HTML that is displayed in the status page of the Multiserver.
103: */
104: public String toHtml() {
105: return "This is <I>JtaDiscRack</I>";
106: }
107: }
|