incubator-lokahi-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From tob...@apache.org
Subject svn commit: r392982 [12/25] - in /incubator/lokahi/lokahi/trunk: ./ conf/ database/ docs/ lib/ src/ src/java/ src/java/lokahi/ src/java/lokahi/core/ src/java/lokahi/core/agent/ src/java/lokahi/core/agent/callable/ src/java/lokahi/core/agent/callable/co...
Date Mon, 10 Apr 2006 16:20:11 GMT
Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/BrokerFactory.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/BrokerFactory.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/BrokerFactory.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/BrokerFactory.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,88 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.database;
+
+import lokahi.core.common.interfaces.Dao;
+import lokahi.core.common.interfaces.ReadOnlyBroker;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.interfaces.XMLDao;
+import org.apache.log4j.Logger;
+import org.jdom.JDOMException;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: BrokerFactory.java,v 1.3 2006/03/07 20:18:52 drtobes Exp $
+ */
+public class BrokerFactory<ItemType extends Dao> {
+  static final Logger logger = Logger.getLogger(BrokerFactory.class);
+
+  public BrokerFactory() {
+  }
+
+  public TMCBroker<ItemType> getBroker() {
+    return new CachingBroker<ItemType>();
+  }
+
+  public <T extends XMLDao> ReadOnlyBroker<T> getBroker(InputStream in, Class<T> aClass) {
+    ReadOnlyBroker<T> ret = null;
+    if (in == null) {
+      if (logger.isDebugEnabled()) {
+        logger.debug("in=" + in);
+      }
+    }
+    try {
+      ret = new XMLBroker<T>(in, aClass);
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (JDOMException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+        logger.info("Exception: " + aClass.getName());
+      }
+    }
+    if (ret == null) {
+      ret = new CachingBroker<T>();
+    }
+    return ret;
+  }
+
+  public <T extends XMLDao> ReadOnlyBroker<T> getBroker(File f, Class<T> aClass) {
+    ReadOnlyBroker<T> ret = null;
+    try {
+      ret = new XMLBroker<T>(f, aClass);
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (JDOMException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    if (ret == null) {
+      ret = new CachingBroker<T>();
+    }
+    return ret;
+  }
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/CachingBroker.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/CachingBroker.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/CachingBroker.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/CachingBroker.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,69 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.database;
+
+import lokahi.core.common.interfaces.Dao;
+import lokahi.core.common.interfaces.TMCBroker;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: CachingBroker.java,v 1.3 2006/03/07 20:18:52 drtobes Exp $
+ */
+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>();
+
+  public int save(String statement, Object... objects) throws SQLException {
+    return masterBroker.save(statement, objects);
+  }
+
+  public boolean delete(String statement, Object... objects) throws SQLException {
+    return masterBroker.delete(statement, objects);
+  }
+
+  public void update(String statement, Object... objects) throws SQLException {
+    masterBroker.update(statement, objects);
+  }
+
+  public void modifyRelationship(String statement, Object... objects) throws SQLException {
+    masterBroker.modifyRelationship(statement, objects);
+  }
+
+  public T getObject(Class<T> c, String statement, boolean cache, Object... objects) throws SQLException {
+    return masterBroker.getObject(c, statement, cache, objects);
+  }
+
+  public Collection<T> getObjects(Class<T> c, boolean cache, String statement, Object... objects) throws SQLException {
+    return masterBroker.getObjects(c, cache, statement, objects);
+  }
+
+  public void useSQL(String statement, Object... objects) throws SQLException {
+    masterBroker.useSQL(statement, objects);
+  }
+
+  public void blobHack(String lockStatement, String statement, int id, byte[] blobData) throws SQLException {
+    masterBroker.blobHack(lockStatement, statement, id, blobData);
+  }
+
+  public String connectionReport() {
+    return masterBroker.connectionReport() + cacheBroker.connectionReport();
+  }
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/ConnBean.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/ConnBean.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/ConnBean.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/ConnBean.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,209 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.database;
+
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.log4j.Logger;
+
+import java.sql.Connection;
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ConnBean.java,v 1.1 2006/03/02 19:19:49 drtobes Exp $
+ */
+public class ConnBean {
+  static final Logger logger = Logger.getLogger(ConnBean.class);
+
+  private static BasicDataSource connPool = new BasicDataSource();
+
+  public static void initializePool(String uri, String user, String password, String driver) {
+    connPool.setDriverClassName(driver);
+    connPool.setUsername(user);
+    connPool.setPassword(password);
+    connPool.setUrl(uri);
+    connPool.setAccessToUnderlyingConnectionAllowed(false);
+    connPool.setDefaultAutoCommit(true);
+    connPool.setPoolPreparedStatements(false);
+    connPool.setDefaultReadOnly(false);
+    try {
+      initFromDatabase();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+  }
+
+  private static void initFromDatabase() throws SQLException {
+    connPool.setInitialSize(4);
+    connPool.setMaxActive(30);
+    connPool.setMaxIdle(10);
+    connPool.setMaxOpenPreparedStatements(3);
+    connPool.setMaxWait(100);
+    connPool.setMinIdle(2);
+    connPool.setNumTestsPerEvictionRun(2);
+    connPool.setTestOnBorrow(true);
+    connPool.setTestOnReturn(true);
+    connPool.setTestWhileIdle(true);
+    connPool.setTimeBetweenEvictionRunsMillis(30000);
+    connPool.setValidationQuery("SELECT SYSDATE FROM DUAL");
+    //then close and then get connection again...
+  }
+
+  public Connection getConn() throws SQLException {
+    Connection conn = connPool.getConnection();
+    if (logger.isInfoEnabled()) {
+      logger.info("On get of connection: " + connectionUsageReport() + " conn.hashCode()=" + conn.hashCode());
+    }
+
+    return conn;
+  }
+
+  public void returnConn(Connection conn) {
+    try {
+      if (conn != null) {
+        if (logger.isDebugEnabled()) {
+          logger.debug("On return of connection: conn.hashCode()=" + conn.hashCode());
+          logger.debug("conn.class" + conn.getClass());
+        }
+        conn.close();  //doesn't actually close it because of the way apache connections work.
+        if (logger.isInfoEnabled()) {
+          logger.info("On return of connection: " + connectionUsageReport());
+        }
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+  }
+
+  public static void connectionReporting() {
+    if (logger.isInfoEnabled()) {
+      logger.info(connectionUsageReport());
+    }
+  }
+
+  public static String connectionUsageReport() {
+    StringBuffer ret = new StringBuffer();
+    if (connPool == null) {
+      ret.append("Unable to report on a null Pool.");
+    } else {
+      ret.append("Used / Idle  = ");
+      ret.append(connPool.getNumActive());
+      ret.append('/');
+      ret.append(connPool.getNumIdle());
+//      ret.append('\n');
+//      int total = connPool.getNumIdle() + connPool.getNumActive();
+//      ret.append("Used / Total = ");
+//      ret.append(connPool.getNumActive());
+//      ret.append(" / ");
+//      ret.append(total);
+    }
+    return ret.toString();
+  }
+
+  public static void destroyPool() throws SQLException {
+    connectionReporting();
+    //Close all connections in the connection pool
+    connPool.close();
+    connPool = null;
+    if (logger.isInfoEnabled()) {
+      logger.info("Connection pool closed.");
+    }
+  } // end destroyPool
+
+  public String poolInfo() {
+    StringBuffer ret = new StringBuffer();
+    ret.append("getDefaultAutoCommit()=");
+    ret.append(connPool.getDefaultAutoCommit());
+    ret.append('\n');
+    ret.append("getDefaultReadOnly()=");
+    ret.append(connPool.getDefaultReadOnly());
+    ret.append('\n');
+    ret.append("getDefaultTransactionIsolation()=");
+    ret.append(connPool.getDefaultTransactionIsolation());
+    ret.append('\n');
+    ret.append("getDefaultCatalog()=");
+    ret.append(connPool.getDefaultCatalog());
+    ret.append('\n');
+    ret.append("getDriverClassName()=");
+    ret.append(connPool.getDriverClassName());
+    ret.append('\n');
+    ret.append("getMaxActive()=");
+    ret.append(connPool.getMaxActive());
+    ret.append('\n');
+    ret.append("getMaxIdle()=");
+    ret.append(connPool.getMaxIdle());
+    ret.append('\n');
+    ret.append("getMinIdle()=");
+    ret.append(connPool.getMinIdle());
+    ret.append('\n');
+    ret.append("getInitialSize()=");
+    ret.append(connPool.getInitialSize());
+    ret.append('\n');
+    ret.append("getMaxWait()=");
+    ret.append(connPool.getMaxWait());
+    ret.append('\n');
+    ret.append("isPoolPreparedStatements()=");
+    ret.append(connPool.isPoolPreparedStatements());
+    ret.append('\n');
+    ret.append("getMaxOpenPreparedStatements()=");
+    ret.append(connPool.getMaxOpenPreparedStatements());
+    ret.append('\n');
+    ret.append("getTestOnBorrow()=");
+    ret.append(connPool.getTestOnBorrow());
+    ret.append('\n');
+    ret.append("getTestOnReturn()=");
+    ret.append(connPool.getTestOnReturn());
+    ret.append('\n');
+    ret.append("getTimeBetweenEvictionRunsMillis()=");
+    ret.append(connPool.getTimeBetweenEvictionRunsMillis());
+    ret.append('\n');
+    ret.append("getNumTestsPerEvictionRun()=");
+    ret.append(connPool.getNumTestsPerEvictionRun());
+    ret.append('\n');
+    ret.append("getMinEvictableIdleTimeMillis()=");
+    ret.append(connPool.getMinEvictableIdleTimeMillis());
+    ret.append('\n');
+    ret.append("getTestWhileIdle()=");
+    ret.append(connPool.getTestWhileIdle());
+    ret.append('\n');
+    ret.append("getPassword()=");
+    ret.append(connPool.getPassword());
+    ret.append('\n');
+    ret.append("getUrl()=");
+    ret.append(connPool.getUrl());
+    ret.append('\n');
+    ret.append("getUsername()=");
+    ret.append(connPool.getUsername());
+    ret.append('\n');
+    ret.append("getValidationQuery()=");
+    ret.append(connPool.getValidationQuery());
+    ret.append('\n');
+    ret.append("isAccessToUnderlyingConnectionAllowed()=");
+    ret.append(connPool.isAccessToUnderlyingConnectionAllowed());
+    ret.append('\n');
+    return ret.toString();
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/DerbyBroker.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/DerbyBroker.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/DerbyBroker.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/DerbyBroker.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,495 @@
+package lokahi.core.common.database;
+
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.core.common.interfaces.Dao;
+import lokahi.core.common.interfaces.GenericDatabaseBroker;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.util.PropertiesFile;
+import org.apache.commons.dbcp.BasicDataSource;
+import org.apache.log4j.Logger;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.sql.Connection;
+import java.sql.DriverManager;
+import java.sql.PreparedStatement;
+import java.sql.SQLException;
+import java.sql.Statement;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: DerbyBroker.java,v 1.3 2006/03/07 20:18:52 drtobes Exp $
+ */
+public class DerbyBroker<T extends Dao> extends GenericDatabaseBroker<T> implements TMCBroker<T> {
+  static final DerbyConnBean connBean = new DerbyConnBean();
+  static final Logger logger = Logger.getLogger(DerbyBroker.class);
+  private static final String STATEMENT_PREFACE = "derby.";
+
+  public static void initalize() {
+    DerbyConnBean.initializePool();
+  }
+
+  public static void shutDown() throws SQLException {
+    DerbyConnBean.destroyPool();
+  }
+
+  private static void createTable(Connection conn, String table, Field... fields) throws SQLException {
+    Statement stmt = conn.createStatement();
+    StringBuffer query = new StringBuffer("Create Table ");
+    query.append(table);
+    query.append('(');
+    for (final Field newVar : fields) {
+      query.append(newVar.getStringBuffer());
+      query.append(',');
+    }
+    query = query.deleteCharAt(query.lastIndexOf(","));
+    query.append(')');
+    if (logger.isDebugEnabled()) {
+      logger.debug("query=" + query);
+    }
+    stmt.execute(query.toString());
+    stmt.close();
+  }
+
+  public Document testFile(String file, boolean b) {
+    URL u = null;
+    File f = new File(file);
+    Document d = null;
+    try {
+      u = f.toURL();
+      SAXBuilder builder = new SAXBuilder();
+      if (b) {
+        builder.setValidation(true);
+      }
+      d = builder.build(u.openStream());
+    } catch (JDOMException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (MalformedURLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    } catch (IOException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+    return d;
+  }
+
+  public String getModule(Document d) {
+    String result = "";
+    Element e = d.getRootElement();
+    result = getAttributeValue("name", e);
+    return result;
+  }
+
+  private String getAttributeValue(String attrName, Element e) {
+    String att = null;
+    if (e != null)
+      att = e.getAttributeValue(attrName);
+    if (att != null)
+      return att;
+    return "";
+  } // end getAttributeValue
+//************************************************************************************************
+
+  public Field[] getFields(Document d) {
+    int cnt = 0;
+    String temp = "";
+    Iterator<Element> i = d.getRootElement().getChildren("field").iterator();
+    int size = d.getRootElement().getChildren("field").size();
+    if (logger.isDebugEnabled()) {
+      logger.debug("size=" + size);
+    }
+    Field[] f = new Field[size];
+    while (i.hasNext()) {
+      Element userElement = i.next();
+      System.out.println(getAttributeValue("name", userElement) + " " + getAttributeValue("type", userElement) + " " + getAttributeValue("pk", userElement) + " " + getAttributeValue("size", userElement));
+      f[cnt] = new Field(getAttributeValue("name", userElement), getAttributeValue("type", userElement), getAttributeValue("pk", userElement), getAttributeValue("size", userElement));
+      System.out.println("To String representation of: " + f[cnt]);
+      cnt++;
+    }
+    return f;
+  }
+
+//  private static void buildCache(String[] classNames) throws IllegalAccessException, InstantiationException, SQLException, ClassNotFoundException {
+//    for (final String className : classNames) {
+//      Class c = Class.forName(className);
+//      if (logger.isDebugEnabled()) {
+//        logger.debug("c.getName()=" + c.getName());
+//        logger.debug("Cacheable.class.isAssignableFrom(c)=" + Cacheable.class.isAssignableFrom(c));
+//      }
+//      if (c != null && Cacheable.class.isAssignableFrom(c)) {
+//        Collection<Cacheable> col = ((Cacheable) c.newInstance()).getAll();
+//        DerbyBroker b = new DerbyBroker();
+//        for (final Cacheable obj : col) {
+//          obj.save(b);
+//        }
+//      }
+//    }
+//
+//  }
+
+  public void useSQL(String statement, Object... params) throws SQLException {
+    statement = PropertiesFile.getConstantValue(STATEMENT_PREFACE + statement);
+    if (!"".equals(statement)) {
+      Connection conn = null;
+      PreparedStatement stmt;
+      try {
+        conn = connBean.getConn();
+        stmt = conn.prepareCall(statement);
+        stmt = this.buildParams(stmt, params);
+        stmt.execute();
+        conn.commit();
+        stmt.close();
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+        throw e;
+      } finally {
+        connBean.returnConn(conn);
+      }
+    }
+  }
+
+  protected PreparedStatement buildParams(PreparedStatement psmt, 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) {
+        psmt.setInt(statemenLocation, (Integer) o);
+        if (logger.isDebugEnabled()) {
+          logger.debug("psmt.setInt(" + statemenLocation + ", " + o + ");");
+        }
+      } else if (o instanceof String) {
+        if (logger.isDebugEnabled()) {
+          logger.debug("psmt.setString(" + statemenLocation + ", " + o + ");");
+        }
+        psmt.setString(statemenLocation, (String) o);
+      } else if (o instanceof byte[]) {
+        if (logger.isDebugEnabled()) {
+          logger.debug("psmt.setBytes(" + statemenLocation + ", BYTEDATA);");
+        }
+        psmt.setBytes(statemenLocation, (byte[]) o);
+      }
+    }
+//	    if (returns) {
+//	      psmt.registerOutParameter(1, returnType);
+//	    }
+    return psmt;
+  }
+
+  public int save(String statement, Object... objects) throws SQLException {
+    Connection conn = null;
+    int ret = 0;
+    PreparedStatement stmt;
+    try {
+      conn = connBean.getConn();
+      stmt = getStatement(conn, statement, objects);
+      ret = stmt.executeUpdate();
+      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;
+  }
+
+  //Check: Statement should be in form similiar to:  insert into Modules(name, file) values (?, ?)
+  protected PreparedStatement getStatement(Connection conn, String statement, Object... objects) throws TMCIllegalArgumentException, SQLException {
+    PreparedStatement ps = null;
+    statement = PropertiesFile.getConstantValue(STATEMENT_PREFACE + statement);
+    if ("".equals(statement) || statement == null)
+      throw new TMCIllegalArgumentException("Proper sql statement not found!");
+    //StringBuilder stateStr = new StringBuilder(statement);
+    //insert into Modules(name, file) values (?, ?)
+    ps = conn.prepareStatement(statement);
+    ps = buildParams(ps, objects);
+
+    return ps;
+  }
+
+  public boolean delete(String statement, Object... objects) throws SQLException {
+    Connection conn = null;
+    boolean ret = false;
+    PreparedStatement stmt;
+    try {
+      conn = connBean.getConn();
+      stmt = getStatement(conn, statement, objects);
+      stmt.execute();
+      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... objects) throws SQLException {
+    Connection conn = null;
+    //int ret = 0;
+    PreparedStatement stmt;
+    try {
+      conn = connBean.getConn();
+      stmt = getStatement(conn, statement, objects);
+      stmt.executeUpdate();
+      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... objects) throws SQLException {
+    update(statement, objects);
+
+  }
+
+  public T getObject(Class<T> c, String statement, boolean cache, Object... objects) throws SQLException {
+    return null;
+  }
+
+  public Collection<T> getObjects(Class<T> c, boolean cache, String statement, Object... objects) throws SQLException {
+    return null;
+  }
+
+  public void blobHack(String lockStatement, String statement, int id, byte[] blobData) throws SQLException {
+
+  }
+
+  public String connectionReport() {
+    return DerbyConnBean.connectionUsageReport();
+  }
+}
+
+class DerbyConnBean {
+  static final Logger logger = Logger.getLogger(DerbyConnBean.class);
+
+  private static BasicDataSource connPool = new BasicDataSource();
+
+  public static void initializePool() {
+    //java.io.tmpdir
+    initializePool(System.getProperty("java.io.tmpdir") + "/TMCdb", null, null, "org.apache.derby.jdbc.EmbeddedDriver");
+  }
+
+  public static void initializePool(String uri, String user, String password, String driver) {
+    connPool.setDriverClassName(driver);
+    connPool.setUsername(user);
+    connPool.setPassword(password);
+    connPool.setUrl(uri);
+    connPool.setAccessToUnderlyingConnectionAllowed(false);
+    connPool.setDefaultAutoCommit(true);
+    connPool.setPoolPreparedStatements(false);
+    connPool.setDefaultReadOnly(false);
+    try {
+      initFromDatabase();
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+  }
+
+  private static void initFromDatabase() throws SQLException {
+    connPool.setInitialSize(4);
+    connPool.setMaxActive(30);
+    connPool.setMaxIdle(2);
+    connPool.setMaxOpenPreparedStatements(3);
+    connPool.setMaxWait(100);
+    connPool.setMinIdle(2);
+    connPool.setNumTestsPerEvictionRun(2);
+    connPool.setTestOnBorrow(true);
+    connPool.setTestOnReturn(true);
+    connPool.setTestWhileIdle(true);
+    connPool.setTimeBetweenEvictionRunsMillis(30000);
+    connPool.setValidationQuery("select count(*) from SYS.SYSTABLES;");
+    //then close and then get connection again...
+  }
+
+  public Connection getConn() throws SQLException {
+    Connection conn = connPool.getConnection();
+    if (logger.isInfoEnabled()) {
+      logger.info("On get of connection: " + connectionUsageReport() + " conn.hashCode()=" + conn.hashCode());
+    }
+
+    return conn;
+  }
+
+  public void returnConn(Connection conn) {
+    try {
+      if (conn != null) {
+        if (logger.isDebugEnabled()) {
+          logger.debug("On return of connection: conn.hashCode()=" + conn.hashCode());
+        }
+        conn.close();  //doesn't actually close it because of the way apache connections work.
+
+        if (logger.isInfoEnabled()) {
+          logger.info("On return of connection: " + connectionUsageReport());
+        }
+      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("Exception: " + e.getMessage());
+      }
+    }
+  }
+
+  public static void connectionReporting() {
+    if (logger.isInfoEnabled()) {
+      logger.info(connectionUsageReport());
+    }
+  }
+
+  public static String connectionUsageReport() {
+    StringBuffer ret = new StringBuffer();
+    if (connPool == null) {
+      ret.append("Unable to report on a null Pool.");
+    } else {
+      ret.append("Used / Idle  = ");
+      ret.append(connPool.getNumActive());
+      ret.append('/');
+      ret.append(connPool.getNumIdle());
+    }
+    return ret.toString();
+  }
+
+  public static void destroyPool() throws SQLException {
+    connectionReporting();
+    //Close all connections in the connection pool
+    connPool.close();
+    try {
+      DriverManager.getConnection("jdbc:derby;shutdown=true");
+    } catch (SQLException se) {
+      if ("XJ015".equals(se.getSQLState())) {
+        //Shutdown success
+      } else {
+        throw se;
+      }
+    }
+    connPool = null;
+    if (logger.isInfoEnabled()) {
+      logger.info("Connection pool closed.");
+    }
+  } // end destroyPool
+
+  public String poolInfo() {
+    StringBuffer ret = new StringBuffer();
+    ret.append("getDefaultAutoCommit()=");
+    ret.append(connPool.getDefaultAutoCommit());
+    ret.append('\n');
+    ret.append("getDefaultReadOnly()=");
+    ret.append(connPool.getDefaultReadOnly());
+    ret.append('\n');
+    ret.append("getDefaultTransactionIsolation()=");
+    ret.append(connPool.getDefaultTransactionIsolation());
+    ret.append('\n');
+    ret.append("getDefaultCatalog()=");
+    ret.append(connPool.getDefaultCatalog());
+    ret.append('\n');
+    ret.append("getDriverClassName()=");
+    ret.append(connPool.getDriverClassName());
+    ret.append('\n');
+    ret.append("getMaxActive()=");
+    ret.append(connPool.getMaxActive());
+    ret.append('\n');
+    ret.append("getMaxIdle()=");
+    ret.append(connPool.getMaxIdle());
+    ret.append('\n');
+    ret.append("getMinIdle()=");
+    ret.append(connPool.getMinIdle());
+    ret.append('\n');
+    ret.append("getInitialSize()=");
+    ret.append(connPool.getInitialSize());
+    ret.append('\n');
+    ret.append("getMaxWait()=");
+    ret.append(connPool.getMaxWait());
+    ret.append('\n');
+    ret.append("isPoolPreparedStatements()=");
+    ret.append(connPool.isPoolPreparedStatements());
+    ret.append('\n');
+    ret.append("getMaxOpenPreparedStatements()=");
+    ret.append(connPool.getMaxOpenPreparedStatements());
+    ret.append('\n');
+    ret.append("getTestOnBorrow()=");
+    ret.append(connPool.getTestOnBorrow());
+    ret.append('\n');
+    ret.append("getTestOnReturn()=");
+    ret.append(connPool.getTestOnReturn());
+    ret.append('\n');
+    ret.append("getTimeBetweenEvictionRunsMillis()=");
+    ret.append(connPool.getTimeBetweenEvictionRunsMillis());
+    ret.append('\n');
+    ret.append("getNumTestsPerEvictionRun()=");
+    ret.append(connPool.getNumTestsPerEvictionRun());
+    ret.append('\n');
+    ret.append("getMinEvictableIdleTimeMillis()=");
+    ret.append(connPool.getMinEvictableIdleTimeMillis());
+    ret.append('\n');
+    ret.append("getTestWhileIdle()=");
+    ret.append(connPool.getTestWhileIdle());
+    ret.append('\n');
+    ret.append("getPassword()=");
+    ret.append(connPool.getPassword());
+    ret.append('\n');
+    ret.append("getUrl()=");
+    ret.append(connPool.getUrl());
+    ret.append('\n');
+    ret.append("getUsername()=");
+    ret.append(connPool.getUsername());
+    ret.append('\n');
+    ret.append("getValidationQuery()=");
+    ret.append(connPool.getValidationQuery());
+    ret.append('\n');
+    ret.append("isAccessToUnderlyingConnectionAllowed()=");
+    ret.append(connPool.isAccessToUnderlyingConnectionAllowed());
+    ret.append('\n');
+    return ret.toString();
+  }
+
+}
\ No newline at end of file

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/Field.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/Field.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/Field.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/Field.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,130 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.database;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Field.java,v 1.1 2006/03/02 19:19:46 drtobes Exp $
+ */
+public class Field {
+  private String name;
+  private String type;
+  private int size;
+
+  private boolean isPk;
+  private boolean isNullable = true;
+
+  public Field() {
+  }
+
+  public Field(String name, String type, String pk) {
+    this.setName(name);
+    this.setIsPk(pk);
+    this.setType(type);
+  }
+
+  public Field(String name, String type, String pk, String size) {
+    this.setName(name);
+    this.setIsPk(pk);
+    this.setType(type);
+    this.setSize(size);
+  }
+
+  public Field(String name, String type, String pk, String size, String nullable) {
+    this.setName(name);
+    this.setIsPk(pk);
+    this.setType(type);
+    this.setSize(size);
+    this.setIsNullable(nullable);
+  }
+
+  public Field(String name, String type, int size, boolean pk, boolean nullable) {
+    this.name = name;
+    this.type = type;
+    this.size = size;
+    isPk = pk;
+    isNullable = nullable;
+  }
+
+  public String toString() {
+    return this.getStringBuffer().toString();
+  }
+
+  public StringBuffer getStringBuffer() {
+    StringBuffer ret = new StringBuffer();
+    ret.append(getName());
+    ret.append(' ');
+    ret.append(getType());
+    ret.append(' ');
+    if (!isNullable()) ret.append("NOT NULL ");
+    if (isPk()) ret.append("PRIMARY KEY ");
+    return ret;
+  }
+
+  public String getName() {
+    return name;
+  }
+
+  public void setName(String name) {
+    this.name = name;
+  }
+
+  public void setIsPk(String pk) {
+    if ("true".equalsIgnoreCase(pk)) this.isPk = true;
+  }
+
+  public int getSize() {
+    return size;
+  }
+
+  public void setSize(String size) {
+    if (!"".equals(size) && size != null)
+      this.size = Integer.parseInt(size);
+  }
+
+  public void setIsNullable(String val) {
+    if ("true".equalsIgnoreCase(val)) this.isNullable = true;
+  }
+
+  public boolean isNullable() {
+    boolean ret;
+    if (isPk()) {
+      ret = false;
+    } else {
+      ret = isNullable;
+    }
+    return ret;
+  }
+
+  public boolean isPk() {
+    return isPk;
+  }
+
+  public String getType() {
+    String res = type;
+    if ("string".equalsIgnoreCase(res) || "varchar".equalsIgnoreCase(res)) {
+      res = "varchar(" + size + ')';
+    }
+    return res;
+  }
+
+  public void setType(String type) {
+    this.type = type;
+  }
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/OracleBroker.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/OracleBroker.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/OracleBroker.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/OracleBroker.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,351 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.database;
+
+import lokahi.core.common.collection.TMCSet;
+import lokahi.core.common.exception.TMCIllegalArgumentException;
+import lokahi.core.common.interfaces.Dao;
+import lokahi.core.common.interfaces.GenericDatabaseBroker;
+import lokahi.core.common.interfaces.TMCBroker;
+import lokahi.core.common.util.PropertiesFile;
+import oracle.jdbc.driver.OracleTypes;
+import oracle.sql.BLOB;
+import org.apache.log4j.Logger;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.OutputStream;
+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;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: OracleBroker.java,v 1.4 2006/03/07 20:18:52 drtobes Exp $
+ */
+public class OracleBroker<T extends Dao> extends GenericDatabaseBroker<T> implements TMCBroker<T> {
+  static final Logger logger = Logger.getLogger(OracleBroker.class);
+  public static final ConnBean connBean = new ConnBean();
+  private static final String STATEMENT_PREFACE = "oracle.";
+
+  OracleBroker() {
+  }
+
+  protected CallableStatement getStatement(Connection conn, String statement, Object[] params, boolean isFunction) throws SQLException, TMCIllegalArgumentException {
+    return this.getStatement(conn, statement, params, isFunction, true, OracleTypes.CURSOR);
+  }
+
+  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;
+  }
+
+  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);
+      stmt.execute();
+      ret = stmt.getInt(1);
+      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 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);
+      stmt.execute();
+      if (stmt.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);
+      stmt.execute();
+      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();
+        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) {
+            OutputStream os = dbBlob.getBinaryOutputStream();
+            os.write(blobData);
+            os.close();
+            //update blob
+            ps = conn.prepareStatement(statement);
+            dbBlob.putBytes(1, blobData);
+            ps.setBlob(1, dbBlob);
+            ps.setInt(2, id);
+            rs.close();
+            ps.close();
+            conn.commit();
+          }
+        }
+      } catch (SQLException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+        throw e;
+      } catch (IOException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("Exception: " + e.getMessage());
+        }
+      } 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 {
+    T o = null;
+    ResultSet r;
+    Connection conn = null;
+    CallableStatement stmt;
+    try {
+      conn = connBean.getConn();
+      stmt = getStatement(conn, statement, params, true);
+      stmt.execute();
+      r = (ResultSet) stmt.getObject(1);
+      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;
+    CallableStatement stmt;
+    try {
+      conn = connBean.getConn();
+      stmt = getStatement(conn, statement, params, true);
+      stmt.execute();
+      r = (ResultSet) stmt.getObject(1);
+      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 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[]) {
+        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 + ");");
+        }
+      }
+    }
+    if (returns) {
+      csmt.registerOutParameter(1, returnType);
+    }
+    return csmt;
+  }
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/XMLBroker.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/XMLBroker.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/XMLBroker.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/database/XMLBroker.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,111 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.database;
+
+import lokahi.core.common.collection.TMCCache;
+import lokahi.core.common.interfaces.ReadOnlyBroker;
+import lokahi.core.common.interfaces.XMLDao;
+import org.apache.log4j.Logger;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.JDOMException;
+import org.jdom.input.SAXBuilder;
+
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.Iterator;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: XMLBroker.java,v 1.4 2006/03/07 22:05:24 drtobes Exp $
+ */
+public class XMLBroker<T extends XMLDao> implements ReadOnlyBroker<T> {
+  static final Logger logger = Logger.getLogger(XMLBroker.class);
+
+  private TMCCache<T> cache = new TMCCache<T>();
+
+  public XMLBroker(String filename, Class<T> aClass) throws IOException, JDOMException {
+    init(new File(filename), aClass);
+  }
+
+  public XMLBroker(File f, Class<T> aClass) throws IOException, JDOMException {
+    init(f, aClass);
+  }
+
+  public XMLBroker(InputStream in, Class<T> aClass) throws IOException, JDOMException {
+    SAXBuilder builder = new SAXBuilder();
+    Document d = builder.build(in);
+    build(d, aClass);
+  }
+
+  private void init(File f, Class<T> aClass) throws IOException, JDOMException {
+    SAXBuilder builder = new SAXBuilder();
+    Document d = builder.build(f);
+    build(d, aClass);
+  }
+
+  private void build(Document d, Class<T> aClass) {
+    Iterator i = d.getRootElement().getChildren().iterator();
+    while (i.hasNext()) {
+      Element next = (Element) i.next();
+      cache.add(fillObject(aClass, next));
+    }
+  }
+
+  public T getObject(Class<T> aClass, String statement, boolean cache, Object... objects) throws SQLException {
+    T ret = null;
+    if (objects != null && objects.length >= 1) {
+      if (objects[0] instanceof String) {
+        ret = this.cache.get((String) objects[0]);
+      }
+      if (objects[0] instanceof Integer) {
+        ret = this.cache.get((Integer) objects[0]);
+      }
+    }
+    return ret;
+  }
+
+  public Collection<T> getObjects(Class<T> aClass, boolean cache, String statement, Object... objects) throws SQLException {
+    return this.cache.values();
+  }
+
+  protected T fillObject(Class<T> c, Element r) {
+    T dao = null;
+    try {
+      dao = c.newInstance();
+      dao = (T) dao.fillObject(r);
+    } catch (SecurityException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("SecurityException: " + e.getMessage());
+      }
+    } catch (InstantiationException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("InstantiationException: " + e.getMessage());
+      }
+    } catch (IllegalAccessException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("IllegalAccessException: " + e.getMessage());
+      }
+    }
+    return dao;
+  }
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AlreadyExistException.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AlreadyExistException.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AlreadyExistException.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AlreadyExistException.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,36 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.exception;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AlreadyExistException.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public class AlreadyExistException extends TMCException {
+  public AlreadyExistException() {
+    super();
+  }
+
+  public AlreadyExistException(String err) {
+    super(err);
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AuthenticationException.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AuthenticationException.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AuthenticationException.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AuthenticationException.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,39 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.exception;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AuthenticationException.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public class AuthenticationException extends Exception {
+
+  public AuthenticationException() {
+    super();
+  }
+
+  public AuthenticationException(String err) {
+    super(err);
+  }
+
+}
+
+
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AuthorizationException.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AuthorizationException.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AuthorizationException.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/AuthorizationException.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,35 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.exception;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: AuthorizationException.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public class AuthorizationException extends TMCException {
+  public AuthorizationException() {
+    super();
+  }
+
+  public AuthorizationException(String err) {
+    super(err);
+  }
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/TMCException.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/TMCException.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/TMCException.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/TMCException.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,54 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.exception;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCException.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public class TMCException extends Exception {
+
+  /**
+   *
+   */
+  public TMCException() {
+    super();
+  }
+
+  /** @param message  */
+  public TMCException(String message) {
+    super(message);
+  }
+
+  /** @param cause  */
+  public TMCException(Throwable cause) {
+    super(cause);
+  }
+
+  /**
+   * @param message
+   * @param cause
+   */
+  public TMCException(String message, Throwable cause) {
+    super(message, cause);
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/TMCIllegalArgumentException.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/TMCIllegalArgumentException.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/TMCIllegalArgumentException.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/TMCIllegalArgumentException.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,36 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.exception;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCIllegalArgumentException.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public class TMCIllegalArgumentException extends TMCException {
+  public TMCIllegalArgumentException() {
+    super();
+  }
+
+  public TMCIllegalArgumentException(String err) {
+    super(err);
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/UnsupportedParameterException.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/UnsupportedParameterException.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/UnsupportedParameterException.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/exception/UnsupportedParameterException.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,36 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.exception;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: UnsupportedParameterException.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public class UnsupportedParameterException extends TMCException {
+  public UnsupportedParameterException() {
+    super();
+  }
+
+  public UnsupportedParameterException(String err) {
+    super(err);
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Application.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Application.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Application.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Application.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,36 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Application.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public abstract class Application<T extends Application> extends TMCDao<T> {
+  public abstract void setSysUser(String user);
+
+  public abstract void setSysGroup(String group);
+
+  public abstract String getSysUser();
+
+  public abstract String getSysGroup();
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Cacheable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Cacheable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Cacheable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Cacheable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,29 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Cacheable.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public interface Cacheable extends Dao {
+  <T extends Cacheable> Collection<T> getAll() throws SQLException;
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Collectable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Collectable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Collectable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Collectable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,29 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Collectable.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public interface Collectable {
+  int getPk();
+
+  String getName();
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Dao.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Dao.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Dao.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Dao.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,29 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Dao.java,v 1.2 2006/03/07 22:05:23 drtobes Exp $
+ */
+public interface Dao<T extends Dao> {
+  T fillObject(ResultSet r) throws SQLException;
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Datable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Datable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Datable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Datable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,31 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+import java.util.Date;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Datable.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public interface Datable {
+  Date getSortOnDate();
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Entity.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Entity.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Entity.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Entity.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,28 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Entity.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public interface Entity {
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/FunctionableEntity.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/FunctionableEntity.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/FunctionableEntity.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/FunctionableEntity.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,31 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: FunctionableEntity.java,v 1.2 2006/03/07 22:05:24 drtobes Exp $
+ */
+public abstract class FunctionableEntity<T extends FunctionableEntity> extends TMCDao<T> implements Entity {
+  public abstract int getObjectId();
+
+  public abstract <T extends FunctionableEntity> T getParent();
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/GenericDatabaseBroker.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/GenericDatabaseBroker.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/GenericDatabaseBroker.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/GenericDatabaseBroker.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,97 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+import org.apache.log4j.Logger;
+
+import java.sql.CallableStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: GenericDatabaseBroker.java,v 1.4 2006/03/07 22:05:24 drtobes Exp $
+ */
+public abstract class GenericDatabaseBroker<T extends Dao> {
+  static final Logger logger = Logger.getLogger(GenericDatabaseBroker.class);
+
+  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;
+  }
+
+  protected T fillObject(Class<T> c, ResultSet r) {
+    T dao = null;
+    try {
+      dao = c.newInstance();
+      dao = (T) dao.fillObject(r);
+//    } catch (NoSuchMethodException e) {
+//      if (logger.isInfoEnabled()) {
+//        logger.info("NoSuchMethodException: " + e.getMessage());
+//      }
+    } catch (SecurityException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("SecurityException: " + e.getMessage());
+      }
+    } catch (InstantiationException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("InstantiationException: " + e.getMessage());
+      }
+    } catch (IllegalAccessException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("IllegalAccessException: " + e.getMessage());
+      }
+//    } catch (InvocationTargetException e) {
+//      if (logger.isInfoEnabled()) {
+//        logger.info("InvocationTargetException: " + e.getMessage());
+//      }
+    } catch (SQLException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("SQLException: " + e.getMessage());
+      }
+    }
+    return dao;
+  }
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/LokahiModel.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/LokahiModel.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/LokahiModel.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/LokahiModel.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,136 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+import lokahi.core.api.function.Function;
+import lokahi.core.api.jobpool.JobPool;
+import lokahi.core.api.project.Project;
+import lokahi.core.api.state.State;
+import lokahi.core.api.user.User;
+import lokahi.core.common.exception.AlreadyExistException;
+import lokahi.core.common.exception.AuthorizationException;
+import lokahi.core.common.exception.TMCException;
+import lokahi.core.common.exception.UnsupportedParameterException;
+import org.apache.log4j.Logger;
+
+import java.lang.reflect.InvocationTargetException;
+import java.lang.reflect.Method;
+import java.sql.SQLException;
+import java.util.Collection;
+import java.util.concurrent.LinkedBlockingQueue;
+import java.util.concurrent.ThreadPoolExecutor;
+import java.util.concurrent.TimeUnit;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: LokahiModel.java,v 1.4 2006/03/07 20:18:54 drtobes Exp $
+ */
+public abstract class LokahiModel<T extends Restable> {
+  protected static final Logger logger = Logger.getLogger(LokahiModel.class);
+
+  protected static ThreadPoolExecutor tpe = new ThreadPoolExecutor(5, 20, 300, TimeUnit.SECONDS, new LinkedBlockingQueue<Runnable>(25));
+
+  public abstract Collection<T> getObjects() throws SQLException;
+
+  public abstract T getObject(int id) throws SQLException;
+
+  protected JobPool jp;
+
+  protected void jpInit(Function f, User u) throws IllegalArgumentException, SQLException {
+    this.jpInit(f, u, -1, "");
+  }
+
+  protected void jpInit(Function f, User u, String options) throws IllegalArgumentException, SQLException {
+    this.jpInit(f, u, -1, options);
+  }
+
+  protected void jpInit(Function f, User u, Project p, String options) throws IllegalArgumentException, SQLException {
+    int projectId = -1;
+    if (p != null)
+      projectId = p.getPk();
+    this.jpInit(f, u, projectId, options);
+  }
+
+  protected void jpInit(Function f, User u, int projectId, String options) throws IllegalArgumentException, SQLException {
+    if (logger.isDebugEnabled()) {
+      logger.debug("f=" + f);
+    }
+    if (f == null) {
+      throw new IllegalArgumentException("Function cannnot be null");
+    }
+    jp = new JobPool(u, State.FAILED, f);
+    jp.setProjectId(projectId);
+    jp.setOptions(options);
+    jp = JobPool.store(jp);
+  }
+
+  public void perform(Function f, Class[] methodParams, Object[] params) throws NoSuchMethodException, TMCException, SQLException {
+    String action = f.getCommand().substring(0, 1).toLowerCase() + f.getCommand().substring(1, f.getCommand().length());
+    Method method = null;
+    try {
+      method = this.getClass().getMethod(action, methodParams);
+    } catch (NoSuchMethodException e) {
+      if (logger.isInfoEnabled()) {
+        logger.info("NoSuchMethodException: " + e.getMessage());
+      }
+      throw e;
+    }
+    if (method != null) {
+      try {
+        method.invoke(this, params);
+      } catch (IllegalAccessException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("IllegalAccessException: " + e.getMessage());
+        }
+      } catch (InvocationTargetException e) {
+        if (logger.isInfoEnabled()) {
+          logger.info("InvocationTargetException: " + e.getMessage());
+        }
+        Throwable ex = e.getCause();
+        if (ex != null) {
+          logger.info("TMCMessage: " + ex.getMessage());
+          logger.info("Class: " + ex.getClass());
+          if (ex instanceof UnsupportedParameterException) {
+            throw new UnsupportedParameterException(ex.getMessage());
+          }
+          if (ex instanceof lokahi.core.common.exception.TMCIllegalArgumentException) {
+            throw new IllegalArgumentException(ex.getMessage());
+          }
+          if (ex instanceof AuthorizationException) {
+            throw new AuthorizationException(ex.getMessage());
+          }
+          if (ex instanceof AlreadyExistException) {
+            throw new AlreadyExistException(ex.getMessage());
+          }
+          if (ex instanceof TMCException) {
+            throw new TMCException(ex.getMessage());
+          }
+          if (ex instanceof SQLException) {
+            throw new SQLException(ex.getMessage());
+          }
+        }
+      }
+    } else {
+      throw new NoSuchMethodException("Method not found");
+    }
+  }
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Pool.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Pool.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Pool.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Pool.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,28 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Pool.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public interface Pool {
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/ReadOnlyBroker.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/ReadOnlyBroker.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/ReadOnlyBroker.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/ReadOnlyBroker.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,33 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+import java.sql.SQLException;
+import java.util.Collection;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: ReadOnlyBroker.java,v 1.3 2006/03/07 20:18:52 drtobes Exp $
+ */
+public interface ReadOnlyBroker<T extends Dao> {
+
+  T getObject(Class<T> c, String statement, boolean cache, Object... params) throws SQLException;
+
+  Collection<T> getObjects(Class<T> c, boolean cache, String statement, Object... params) throws SQLException;
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/RestObject.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/RestObject.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/RestObject.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/RestObject.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,54 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+import java.util.Map;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: RestObject.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public abstract class RestObject implements Restable {
+  protected static StringBuilder elementBuilder(String name, Map<String, String> a) {
+    StringBuilder ret = new StringBuilder();
+    ret.append('<');
+    ret.append(name);
+    ret.append(' ');
+    for (final String s : a.keySet()) {
+      ret.append(s);
+      ret.append("=\"");
+      ret.append(a.get(s));
+      ret.append("\" ");
+    }
+    ret.append("/>\n");
+    return ret;
+  }
+
+  protected static StringBuilder elementBuilder(String name, String value) {
+    StringBuilder ret = new StringBuilder();
+    ret.append('<');
+    ret.append(name);
+    ret.append('>');
+    ret.append(value);
+    ret.append("</");
+    ret.append(name);
+    ret.append(">\n");
+    return ret;
+  }
+
+}
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Restable.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Restable.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Restable.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Restable.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,27 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Restable.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public interface Restable extends Collectable {
+  StringBuilder buildXMLRepresention();
+
+  StringBuilder buildShortXMLRepresentation();
+
+}
\ No newline at end of file

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Server.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Server.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Server.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/Server.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,29 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: Server.java,v 1.1 2006/03/07 20:18:51 drtobes Exp $
+ */
+public interface Server {
+
+}
+
+
+
+
+

Added: incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCBroker.java
URL: http://svn.apache.org/viewcvs/incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCBroker.java?rev=392982&view=auto
==============================================================================
--- incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCBroker.java (added)
+++ incubator/lokahi/lokahi/trunk/src/java/lokahi/core/common/interfaces/TMCBroker.java Mon Apr 10 09:19:33 2006
@@ -0,0 +1,42 @@
+/*
+* Copyright 2006  The Apache Software Foundation
+*
+* Licensed 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 lokahi.core.common.interfaces;
+
+import java.sql.SQLException;
+
+/**
+ * @author Stephen Toback
+ * @version $Id: TMCBroker.java,v 1.3 2006/03/07 20:18:52 drtobes Exp $
+ */
+public interface TMCBroker<T extends Dao> extends ReadOnlyBroker<T> {
+
+  void useSQL(String statement, Object... params) throws SQLException;
+
+  int save(String statement, Object... params) throws SQLException;
+
+  boolean delete(String statement, Object... params) throws SQLException;
+
+  void update(String statement, Object... params) throws SQLException;
+
+  void modifyRelationship(String statement, Object... params) throws SQLException;
+
+  void blobHack(String lockStatement, String statement, int id, byte[] blobData) throws SQLException;
+
+  String connectionReport();
+
+}
+
+



Mime
View raw message