incubator-lokahi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tob...@apache.org
Subject svn commit: r451335 - in /incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core: common/database/CachingBroker.java common/database/ConnBean.java common/database/MySqlBroker.java controller/AdminBean.java gui/www/TMCStartupServlet.java
Date Fri, 29 Sep 2006 16:16:39 GMT
Author: toback
Date: Fri Sep 29 09:16:38 2006
New Revision: 451335

URL: http://svn.apache.org/viewvc?view=rev&rev=451335
Log:
Re:

http://mail-archives.apache.org/mod_mbox/incubator-lokahi-dev/200609.mbox/%3c451AF45C.5030904@free.fr%3e

Added:
    incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/MySqlBroker.java
  (with props)
Modified:
    incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/CachingBroker.java
    incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/ConnBean.java
    incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/controller/AdminBean.java
    incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/gui/www/TMCStartupServlet.java

Modified: incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/CachingBroker.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/CachingBroker.java?view=diff&rev=451335&r1=451334&r2=451335
==============================================================================
--- incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/CachingBroker.java
(original)
+++ incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/CachingBroker.java
Fri Sep 29 09:16:38 2006
@@ -18,6 +18,7 @@
 */
 package org.apache.lokahi.core.common.database;
 
+import org.apache.log4j.Logger;
 import org.apache.lokahi.core.common.interfaces.Dao;
 import org.apache.lokahi.core.common.interfaces.TMCBroker;
 
@@ -29,9 +30,31 @@
  * @version $Id$
  */
 public class CachingBroker<T extends Dao> implements TMCBroker<T> {
-  private final TMCBroker<T> masterBroker = new OracleBroker<T>();
-  private final TMCBroker<T> cacheBroker = new DerbyBroker<T>();
-
+  static final Logger logger = Logger.getLogger(CachingBroker.class);
+    
+  public final static String DEFAULT_BROKER_IMPLEMENTATION = "org.apache.lokahi.core.common.database.OracleBroker";
+    
+  private static String masterBrokerClassName = DEFAULT_BROKER_IMPLEMENTATION;
+    
+  private TMCBroker<T> masterBroker;
+
+  private TMCBroker<T> cacheBroker = new DerbyBroker<T>();
+
+  public CachingBroker() {
+    super();
+    if (logger.isDebugEnabled())
+      logger.debug("Instantiate a '"+masterBrokerClassName+"' broker.");    
+    try {
+      masterBroker = (TMCBroker<T>) Class.forName(masterBrokerClassName).newInstance();
+    } catch (InstantiationException e) {
+        e.printStackTrace();
+    } catch (IllegalAccessException e) {
+        e.printStackTrace();
+    } catch (ClassNotFoundException e) {
+        e.printStackTrace();
+    }
+  }
+    
   public int save(String statement, Object... objects) throws SQLException {
     return masterBroker.save(statement, objects);
   }
@@ -66,5 +89,13 @@
 
   public String connectionReport() {
     return masterBroker.connectionReport() + cacheBroker.connectionReport();
+  }
+
+  public static String getMasterBrokerClassName() {
+    return masterBrokerClassName;
+  }
+
+  public static void setMasterBrokerClassName(String masterBrokerClassName) {
+    CachingBroker.masterBrokerClassName = masterBrokerClassName;
   }
 }

Modified: incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/ConnBean.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/ConnBean.java?view=diff&rev=451335&r1=451334&r2=451335
==============================================================================
--- incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/ConnBean.java
(original)
+++ incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/ConnBean.java
Fri Sep 29 09:16:38 2006
@@ -63,7 +63,7 @@
     connPool.setTestOnReturn(true);
     connPool.setTestWhileIdle(true);
     connPool.setTimeBetweenEvictionRunsMillis(30000);
-    connPool.setValidationQuery("SELECT SYSDATE FROM DUAL");
+    connPool.setValidationQuery("SELECT COUNT(*) FROM TMC_PROJECT");
     //then close and then get connection again...
   }
 

Added: incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/MySqlBroker.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/MySqlBroker.java?view=auto&rev=451335
==============================================================================
--- incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/MySqlBroker.java
(added)
+++ incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/MySqlBroker.java
Fri Sep 29 09:16:38 2006
@@ -0,0 +1,408 @@
+/*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements.  See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership.  The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License.  You may obtain a copy of the License at
+*
+*   http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied.  See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*/
+package org.apache.lokahi.core.common.database;
+
+import java.io.ByteArrayInputStream;
+import java.sql.CallableStatement;
+import java.sql.Connection;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.sql.Types;
+import java.util.Collection;
+
+import org.apache.commons.dbcp.DelegatingCallableStatement;
+import org.apache.commons.dbcp.DelegatingPreparedStatement;
+import org.apache.log4j.Logger;
+import org.apache.lokahi.core.common.collection.TMCSet;
+import org.apache.lokahi.core.common.exception.TMCIllegalArgumentException;
+import org.apache.lokahi.core.common.interfaces.Dao;
+import org.apache.lokahi.core.common.interfaces.GenericDatabaseBroker;
+import org.apache.lokahi.core.common.interfaces.TMCBroker;
+import org.apache.lokahi.core.common.util.PropertiesFile;
+
+import com.mysql.jdbc.Blob;
+
+/**
+ *
+ * @version $Id$
+ */
+public class MySqlBroker<T extends Dao> extends GenericDatabaseBroker<T> implements
TMCBroker<T> {
+  static final Logger logger = Logger.getLogger(MySqlBroker.class);
+  public static final ConnBean connBean = new ConnBean();
+  private static final String STATEMENT_PREFACE = "mysql.";
+
+  MySqlBroker() {
+      if (logger.isDebugEnabled())
+          logger.debug("Using MySql Broker");
+  }
+
+  protected PreparedStatement getPreparedStatement(Connection conn, String statement, Object[]
params, boolean isFunction) throws SQLException, TMCIllegalArgumentException {
+    return this.getPreparedStatement(conn, statement, params, isFunction, false, -1);
+  }
+
+  protected PreparedStatement getPreparedStatement(Connection conn, String statement, Object[]
params, boolean isFunction, boolean returns, int type) throws SQLException, TMCIllegalArgumentException
{
+    statement = PropertiesFile.getConstantValue(STATEMENT_PREFACE + statement);
+    if ("".equals(statement) || statement == null)
+      throw new TMCIllegalArgumentException("Proper sql statement not found!");
+    StringBuffer stateStr = new StringBuffer(statement);
+    int numqMarks = params.length;
+    if (logger.isDebugEnabled()) {
+      logger.debug("numqMarks=" + numqMarks);
+      logger.debug("isFunction=" + isFunction);
+      logger.debug("returns=" + returns);
+      logger.debug("params.length=" + params.length);
+      logger.debug("Setting statementStr to " + stateStr);
+    }
+    PreparedStatement csmt = conn.prepareStatement(stateStr.toString());
+    csmt = this.buildPreparedStatementParams(csmt, returns, type, params);
+    return csmt;
+  }
+
+  // Store procs
+
+  public int save(String statement, Object... params) throws SQLException {
+    Connection conn = null;
+    int ret = 0;
+    CallableStatement stmt;
+    try {
+      conn = connBean.getConn();
+      stmt = getStatement(conn, statement, params, false, true, Types.INTEGER);
+      ResultSet res = stmt.executeQuery();
+      ret = stmt.getInt(1);
+      stmt.close();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    } catch (TMCIllegalArgumentException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } finally {
+      connBean.returnConn(conn);
+    }
+    return ret;
+  }
+
+  public boolean delete(String statement, Object... params) throws SQLException {
+    Connection conn = null;
+    boolean ret = false;
+    CallableStatement stmt;
+    try {
+      conn = connBean.getConn();
+      stmt = getStatement(conn, statement, params, false, true, Types.INTEGER);
+      if (stmt instanceof DelegatingCallableStatement) {
+          logger.info("Stmt: "+((DelegatingCallableStatement)stmt).getInnermostDelegate());
+      }
+      if (stmt.executeQuery().getInt(1) != 1) {
+        ret = true;
+      }
+      conn.commit();
+      stmt.close();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    } catch (TMCIllegalArgumentException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } finally {
+      connBean.returnConn(conn);
+    }
+    return ret;
+  }
+
+  public void update(String statement, Object... params) throws SQLException {
+    Connection conn = null;
+    CallableStatement stmt;
+    try {
+      conn = connBean.getConn();
+      stmt = getStatement(conn, statement, params, false, false, 0);
+      if (logger.isDebugEnabled() && stmt instanceof DelegatingCallableStatement)
{
+          logger.debug("Stmt: "+((DelegatingCallableStatement)stmt).getInnermostDelegate());
+      }
+      stmt.executeQuery();
+      if (!"true".equals(PropertiesFile.getConstantValue("lokahi.broker.autocommit")))
+          conn.commit();
+      stmt.close();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    } catch (TMCIllegalArgumentException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } finally {
+      connBean.returnConn(conn);
+    }
+  }
+
+  public void modifyRelationship(String statement, Object... params) throws SQLException
{
+    update(statement, params);
+  }
+
+  public void useSQL(String statement, Object... params) throws SQLException {
+    statement = PropertiesFile.getConstantValue(STATEMENT_PREFACE + statement);
+    if (!"".equals(statement)) {
+      Connection conn = null;
+      CallableStatement stmt;
+      try {
+        conn = connBean.getConn();
+        stmt = conn.prepareCall(statement);
+        stmt = this.buildParams(stmt, false, 0, params);
+        stmt.execute();
+        if (!"true".equals(PropertiesFile.getConstantValue("lokahi.broker.autocommit")))
+            conn.commit();
+        stmt.close();
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+        throw e;
+      } finally {
+        connBean.returnConn(conn);
+      }
+    }
+  }
+
+  public void blobHack(String lockStatement, String statement, int id, byte[] blobData) throws
SQLException {
+    statement = PropertiesFile.getConstantValue(STATEMENT_PREFACE + statement);
+    lockStatement = PropertiesFile.getConstantValue(STATEMENT_PREFACE + lockStatement);
+    if (!"".equals(statement) && !"".equals(lockStatement)) {
+      Connection conn = null;
+      try {
+        conn = connBean.getConn();
+        conn.setAutoCommit(false);
+        PreparedStatement ps = conn.prepareStatement(lockStatement);
+        ps.setInt(1, id);
+        ResultSet rs = ps.executeQuery();
+        if (logger.isDebugEnabled()) {
+          logger.debug("blobBytes.length=" + blobData.length);
+        }
+        if (rs.next()) {
+          Blob dbBlob = (Blob) rs.getBlob(1);
+          if (dbBlob != null) {
+            //update blob
+            ps = conn.prepareStatement(statement);
+            dbBlob.setBytes(1, blobData);
+            ps.setBlob(1, dbBlob);
+            ps.setInt(2, id);
+            rs.close();
+            ps.close();
+            if (!"true".equals(PropertiesFile.getConstantValue("lokahi.broker.autocommit")))
+                conn.commit();
+          }
+        }
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+        throw e;
+      } finally {
+        if (conn != null)
+          conn.setAutoCommit(true);
+        connBean.returnConn(conn);
+      }
+    }
+  }
+
+  public String connectionReport() {
+    return ConnBean.connectionUsageReport();
+  }
+
+  public T getObject(Class<T> c, String statement, boolean cache, Object... params)
throws SQLException {
+    if (logger.isDebugEnabled())
+      logger.debug("Returning object "+c.getName()+":"+params[0]+" using statment "+statement);
+    T o = null;
+    ResultSet r;
+    Connection conn = null;
+    PreparedStatement stmt;
+    try {
+      conn = connBean.getConn();
+      stmt = getPreparedStatement(conn, statement, params, false);
+      if (logger.isDebugEnabled() && stmt instanceof DelegatingPreparedStatement)
{
+          logger.debug("Stmt: "+((DelegatingPreparedStatement)stmt).getInnermostDelegate());
+      }
+     r = (ResultSet) stmt.executeQuery();
+      if (r != null && r.next()) {
+        o = fillObject(c, r);
+        r.close();
+      } else {
+        if (logger.isDebugEnabled()) {
+          logger.debug("R is null! ");
+        }
+      }
+      stmt.close();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    } catch (TMCIllegalArgumentException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } finally {
+      connBean.returnConn(conn);
+    }
+    return o;
+  }
+
+  public Collection<T> getObjects(Class<T> clazz, boolean cache, String statement,
Object... params) throws SQLException {
+    Collection<T> c = new TMCSet<T>();
+    Connection conn = null;
+    ResultSet r;
+    PreparedStatement stmt;
+    try {
+      conn = connBean.getConn();
+      stmt = getPreparedStatement(conn, statement, params, true);
+      if (logger.isDebugEnabled() && stmt instanceof DelegatingPreparedStatement)
{
+          logger.debug("Stmt: "+((DelegatingPreparedStatement)stmt).getInnermostDelegate());
+      }
+      r = (ResultSet) stmt.executeQuery();
+      if (r != null) {
+        while (r.next()) {
+          T o = fillObject(clazz, r);
+          if (o != null) c.add(o);
+        }
+        r.close();
+      } else {
+        if (logger.isDebugEnabled()) {
+          logger.debug("RESULTSET IS NULL");
+        }
+      }
+      stmt.close();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      throw e;
+    } catch (TMCIllegalArgumentException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } finally {
+      connBean.returnConn(conn);
+    }
+    return c;
+  }
+
+  protected PreparedStatement buildPreparedStatementParams(PreparedStatement csmt, boolean
returns, int returnType, Object... params) throws SQLException {
+    int modifier = 1;
+    for (int i = 0; i < params.length; i++) {
+      int statemenLocation = i + modifier;
+      Object o = params[i];
+      if (o instanceof Integer) {
+        csmt.setInt(statemenLocation, (Integer) o);
+        if (logger.isDebugEnabled()) {
+          logger.debug("csmt.setInt(" + statemenLocation + ", " + o + ");");
+        }
+      } else if (o instanceof String) {
+        if (logger.isDebugEnabled()) {
+          logger.debug("csmt.setString(" + statemenLocation + ", " + o + ");");
+        }
+        csmt.setString(statemenLocation, (String) o);
+      } else if (o instanceof byte[]) {
+        ByteArrayInputStream bais = new ByteArrayInputStream((byte[]) o);
+        csmt.setBinaryStream(statemenLocation, bais, ((byte[]) o).length);
+        if (logger.isDebugEnabled()) {
+          logger.debug("csmt.setBinaryStream(" + statemenLocation + ", BYTEDATA, " + ((byte[])
o).length + ");");
+        }
+      }
+    }
+    return csmt;
+  }
+
+  protected CallableStatement getStatement(Connection conn, String statement, Object[] params,
boolean isFunction) throws SQLException, TMCIllegalArgumentException {
+      return this.getStatement(conn, statement, params, isFunction, true, Types.INTEGER);
+    }
+
+    protected CallableStatement getStatement(Connection conn, String statement, Object[]
params, boolean isFunction, boolean returns, int type) throws SQLException, TMCIllegalArgumentException
{
+      statement = PropertiesFile.getConstantValue(STATEMENT_PREFACE + statement);
+      if ("".equals(statement) || statement == null)
+        throw new TMCIllegalArgumentException("Proper sql statement not found!");
+      StringBuffer stateStr = new StringBuffer(statement);
+      stateStr.append('(');
+      int numqMarks = params.length;
+      if (returns && !isFunction) {
+        numqMarks++;
+      }
+      if (logger.isDebugEnabled()) {
+        logger.debug("numqMarks=" + numqMarks);
+        logger.debug("isFunction=" + isFunction);
+        logger.debug("returns=" + returns);
+        logger.debug("params.length=" + params.length);
+      }
+      for (int i = 1; i < numqMarks; i++) {
+        stateStr.append("?,");
+      }
+      if (numqMarks > 0) {
+        stateStr.append('?');
+      }
+      stateStr.append(")}");
+      if (isFunction) {
+        stateStr.insert(0, "{? = call ");
+      } else {
+        stateStr.insert(0, "{call ");
+      }
+      if (logger.isDebugEnabled()) {
+        logger.debug("Setting statementStr to " + stateStr);
+      }
+      CallableStatement csmt = conn.prepareCall(stateStr.toString());
+      csmt = this.buildParams(csmt, returns, type, params);
+      return csmt;
+    }
+
+    protected CallableStatement buildParams(CallableStatement csmt, boolean returns, int
returnType, Object... params) throws SQLException {
+        int modifier = 1;
+        if (returns) {
+          modifier++;
+        }
+        for (int i = 0; i < params.length; i++) {
+          int statemenLocation = i + modifier;
+          Object o = params[i];
+          if (o instanceof Integer) {
+            csmt.setInt(statemenLocation, (Integer) o);
+            if (logger.isDebugEnabled()) {
+              logger.debug("csmt.setInt(" + statemenLocation + ", " + o + ");");
+            }
+          } else if (o instanceof String) {
+            if (logger.isDebugEnabled()) {
+              logger.debug("csmt.setString(" + statemenLocation + ", " + o + ");");
+            }
+            csmt.setString(statemenLocation, (String) o);
+          } else if (o instanceof byte[]) {
+            if (logger.isDebugEnabled()) {
+              logger.debug("csmt.setBytes(" + statemenLocation + ", BYTEDATA);");
+            }
+            csmt.setBytes(statemenLocation, (byte[]) o);
+          }
+        }
+        if (returns) {
+          csmt.registerOutParameter(1, returnType);
+        }
+        return csmt;
+      }
+}

Propchange: incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/common/database/MySqlBroker.java
------------------------------------------------------------------------------
    svn:keywords = Id

Modified: incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/controller/AdminBean.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/controller/AdminBean.java?view=diff&rev=451335&r1=451334&r2=451335
==============================================================================
--- incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/controller/AdminBean.java
(original)
+++ incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/controller/AdminBean.java
Fri Sep 29 09:16:38 2006
@@ -23,22 +23,24 @@
 
 package org.apache.lokahi.core.controller;
 
-import oracle.jdbc.driver.OracleTypes;
-import oracle.sql.ARRAY;
-import oracle.sql.STRUCT;
-import org.apache.log4j.Logger;
-import org.apache.lokahi.core.api.instance.Instance;
-import org.apache.lokahi.core.common.database.ConnBean;
-import org.apache.lokahi.core.common.util.PropertiesFile;
-
 import java.sql.CallableStatement;
 import java.sql.Connection;
+import java.sql.PreparedStatement;
 import java.sql.ResultSet;
 import java.sql.SQLException;
 import java.util.Hashtable;
 import java.util.StringTokenizer;
 import java.util.Vector;
 
+import oracle.jdbc.driver.OracleTypes;
+import oracle.sql.ARRAY;
+import oracle.sql.STRUCT;
+
+import org.apache.log4j.Logger;
+import org.apache.lokahi.core.api.instance.Instance;
+import org.apache.lokahi.core.common.database.ConnBean;
+import org.apache.lokahi.core.common.util.PropertiesFile;
+
 public class AdminBean {  //todo scrap this entire thing
   static final Logger logger = Logger.getLogger(AdminBean.class);
 
@@ -98,8 +100,24 @@
     }
 
     Hashtable contHash = new Hashtable();
-    CallableStatement csmt;
     try {
+        if ("oracle".equals(PropertiesFile.getConstantValue("lokahi.broker.type")))
+            contHash = getAllAdminInfoOracleImpl(conn, contHash);
+        else
+            contHash = getAllAdminInfoStdImpl(conn, contHash);
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+      contHash = null;
+    } finally {
+      if (fromDb) connBean.returnConn(conn);
+    }
+    return contHash;
+  } // end getAllAdminInfo
+
+  private Hashtable getAllAdminInfoOracleImpl(Connection conn, Hashtable contHash) throws
SQLException {
+      CallableStatement csmt;
       csmt = conn.prepareCall("{? = call  " + schema_owner + "." + stored_proc + "}");
 
       csmt.registerOutParameter(1, OracleTypes.ARRAY, "BI_LIST");
@@ -122,17 +140,35 @@
           contHash.put(val1, val2);
         }
       } // while rs.next
-      csmt.close();
-    } catch (SQLException e) {
-      if (logger.isInfoEnabled()) {
-        logger.info("Exception: " + e.getMessage());
-      }
-      contHash = null;
-    } finally {
-      if (fromDb) connBean.returnConn(conn);
-    }
-    return contHash;
-  } // end getAllAdminInfo
+      csmt.close();   
+      return contHash;
+  }
+
+  private Hashtable getAllAdminInfoStdImpl(Connection conn, Hashtable contHash) throws SQLException
{
+      PreparedStatement psmt;
+      psmt = conn.prepareStatement("select 'PRIMARY',primary_jvm,'BACKUP', backup_jvm, 'ALTERNATE',
alternate_jvm from TMC_ADMIN where INSTANCE_ID=?;");
+
+      psmt.setInt(1, this.getInstance().getPk());
+      psmt.execute();
+
+      // returns rows with 2 fields
+      // let us build a hashtable out of this, with first field as hashtable key and 2nd
as value for this key
+      // retrieve the array as an oracle array
+      ResultSet rs = psmt.getResultSet();
+      while (rs.next()) {
+          for (int i=0;i<rs.getMetaData().getColumnCount();i=i+2) {
+              Object attrs[] = { rs.getString(i), rs.getString(i+1)};
+              String val1 = (attrs[0] != null) ? (String) attrs[0] : null;
+              String val2 = (attrs[1] != null) ? (String) attrs[1] : "";
+              if (val1 != null) {
+                // overwrite the key if it already exists
+                contHash.put(val1, val2);
+              }              
+          }
+      } // while rs.next
+      psmt.close();   
+      return contHash;
+  }
 
   /**
    * This method changes the role of the machine:port supplied to primary/backup or alternate
@@ -200,14 +236,15 @@
       csmt.execute();
       csmt.close();
 
-      conn.commit();
+      if (!"true".equals(PropertiesFile.getConstantValue("lokahi.broker.autocommit")))
+      	conn.commit();
     } catch (SQLException e) {
       if (logger.isInfoEnabled()) {
         logger.info("Exception: " + e.getMessage());
       }
     } finally {
       if (fromDb) connBean.returnConn(conn);
-      return;
+          return;
     }
   } // end changeJvmAdminRole
 
@@ -232,7 +269,3 @@
   } // end split
 
 } // end AdminBean
-
-
-
-

Modified: incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/gui/www/TMCStartupServlet.java
URL: http://svn.apache.org/viewvc/incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/gui/www/TMCStartupServlet.java?view=diff&rev=451335&r1=451334&r2=451335
==============================================================================
--- incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/gui/www/TMCStartupServlet.java
(original)
+++ incubator/lokahi/lokahi/branches/mysql/src/java/org/apache/lokahi/core/gui/www/TMCStartupServlet.java
Fri Sep 29 09:16:38 2006
@@ -19,6 +19,7 @@
 package org.apache.lokahi.core.gui.www;
 
 import org.apache.log4j.xml.DOMConfigurator;
+import org.apache.lokahi.core.common.database.CachingBroker;
 import org.apache.lokahi.core.common.database.ConnBean;
 import org.apache.lokahi.core.common.database.DerbyBroker;
 import org.apache.lokahi.core.common.util.PropertiesFile;
@@ -53,6 +54,10 @@
     PropertiesFile.load(this.getClass().getClassLoader().getResourceAsStream(propsName));
     PropertiesFile.load(this.getClass().getClassLoader().getResourceAsStream("db.properties"));
 
+    if (PropertiesFile.getConstantValue("lokahi.broker.implementation")!=null) {
+        CachingBroker.setMasterBrokerClassName(PropertiesFile.getConstantValue("lokahi.broker.implementation"));
       
+    }
+    
     // check for some specific init values that need non-standard action
     ConnBean.initializePool(PropertiesFile.getConstantValue("tmc.database.uri"),
                             PropertiesFile.getConstantValue("tmc.database.user"),



Mime
View raw message