/** Constructor. */
  public DatabaseEventQueue() {
    if (Debug.isLevelEnabled(Debug.OBJECT_LIFECYCLE))
      Debug.log(
          Debug.OBJECT_LIFECYCLE,
          "QUEUE OPERATION: Creating event queue of type ["
              + StringUtils.getClassName(this)
              + "] ...");

    queue = Collections.synchronizedList(new LinkedList());
  }
  /**
   * Initialize the event queue.
   *
   * @param props A container of configuration properties.
   * @exception FrameworkException Thrown if configuration is invalid.
   */
  public void initialize(Map props) throws FrameworkException {
    String temp = (String) props.get(LOAD_EVENT_BATCH_SIZE_PROP);

    if (StringUtils.hasValue(temp)) {
      maxDatabaseEventLoadSize = StringUtils.getInteger(temp);

      if (Debug.isLevelEnabled(Debug.SYSTEM_CONFIG))
        Debug.log(
            Debug.SYSTEM_CONFIG,
            "QUEUE OPERATION: Initializing: Maximum-database-event-batch-load-size is ["
                + maxDatabaseEventLoadSize
                + "] rows.");
    }
  }
  /**
   * Get the next queued item. Must be called after hasNext().
   *
   * @return The next item in the queue to process.
   * @exception FrameworkException Thrown on errors.
   */
  public Event next() throws FrameworkException {
    if (queue.size() == 0) {
      throw new FrameworkException("ERROR: Attempt was made to retrieve event from empty queue.");
    }

    Event event = (Event) queue.get(0);

    if (Debug.isLevelEnabled(Debug.MSG_STATUS))
      Debug.log(
          Debug.MSG_STATUS,
          "QUEUE OPERATION: Retrieving the following event from the database queue:\n"
              + event.describe());

    return event;
  }
Beispiel #4
0
  /**
   * Set the maximum number of rows
   *
   * @param max the new max rows limit; zero means unlimited
   * @exception java.sql.SQLException if a database access error occurs
   * @see getMaxRows
   */
  public void setMaxRows(int max) throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = {new Integer(max)};
      Debug.methodCall(this, "setMaxRows", Args);
    }

    if (max > MysqlDefs.MAX_ROWS) {
      throw new java.sql.SQLException(
          "setMaxRows() out of range. " + max + " > " + MysqlDefs.MAX_ROWS + ".", "S1009");
    }

    if (max == 0) {
      max = -1;
    }

    _max_rows = max;

    // Most people don't use setMaxRows()
    // so don't penalize them
    // with the extra query it takes
    // to do it efficiently unless we need
    // to.

    _Conn.maxRowsChanged();
  }
  /**
   * Returns 'true' if the queue has more items to process.
   *
   * @param criteria An event containing the event-selection criteria.
   * @return 'true' if queue has more items to process, otherwise 'false'.
   * @exception FrameworkException Thrown on errors.
   */
  public boolean hasNext(Event criteria) throws FrameworkException {
    boolean available = (queue.size() > 0);

    // If no events are available in memory, attempt to get more from the database.
    if (!available) {
      loadFromDatabase(criteria);

      available = (queue.size() > 0);
    }

    if (Debug.isLevelEnabled(Debug.MSG_STATUS))
      Debug.log(
          Debug.MSG_STATUS,
          "QUEUE OPERATION: Events available in database queue? [" + available + "].");

    return available;
  }
Beispiel #6
0
  /**
   * setCursorName defines the SQL cursor name that will be used by subsequent execute methods. This
   * name can then be used in SQL positioned update/delete statements to identify the current row in
   * the ResultSet generated by this statement. If a database doesn't support positioned
   * update/delete, this method is a no-op.
   *
   * <p><b>Note:</b> This MySQL driver does not support cursors.
   *
   * @param name the new cursor name
   * @exception java.sql.SQLException if a database access error occurs
   */
  public void setCursorName(String Name) throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = {Name};
      Debug.methodCall(this, "setCursorName", Args);
    }

    // No-op
  }
Beispiel #7
0
  /**
   * getResultSet returns the current result as a ResultSet. It should only be called once per
   * result.
   *
   * @return the current result set; null if there are no more
   * @exception java.sql.SQLException if a database access error occurs (why?)
   */
  public java.sql.ResultSet getResultSet() throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = new Object[0];
      Debug.methodCall(this, "getResultSet", Args);
    }

    return _Results;
  }
Beispiel #8
0
  /**
   * getLastInsertID returns the value of the auto_incremented key after an executeQuery() or
   * excute() call.
   *
   * <p>This gets around the un-threadsafe behavior of "select LAST_INSERT_ID()" which is tied to
   * the Connection that created this Statement, and therefore could have had many INSERTS performed
   * before one gets a chance to call "select LAST_INSERT_ID()".
   *
   * @return the last update ID.
   */
  public long getLastInsertID() {
    if (Driver.trace) {
      Object[] Args = new Object[0];
      Debug.methodCall(this, "getLastInsertID", Args);
    }

    return _last_insert_id;
  }
  // Release the given database resources, if non-null.
  private static void releaseDatabaseResources(Connection dbConn, PreparedStatement ps) {
    if (ps != null) {
      try {
        ps.close();
      } catch (Exception e) {
        Debug.warning("Failed to close the prepared statement:\n" + e.toString());
      }
    }

    if (dbConn != null) {
      try {
        DBConnectionPool.getInstance().releaseConnection(dbConn);
      } catch (Exception e) {
        Debug.warning("Failed to release database connection back to the pool:\n" + e.toString());
      }
    }
  }
Beispiel #10
0
  /**
   * Sets the queryTimeout limit
   *
   * @param seconds - the new query timeout limit in seconds
   * @exception java.sql.SQLException if a database access error occurs
   */
  public void setQueryTimeout(int seconds) throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = {new Integer(seconds)};
      Debug.methodCall(this, "setQueryTimeout", Args);
    }

    _timeout = seconds;
  }
Beispiel #11
0
  /**
   * The queryTimeout limit is the number of seconds the driver will wait for a Statement to
   * execute. If the limit is exceeded, a java.sql.SQLException is thrown.
   *
   * @return the current query timeout limit in seconds; 0 = unlimited
   * @exception java.sql.SQLException if a database access error occurs
   */
  public int getQueryTimeout() throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = new Object[0];
      Debug.methodCall(this, "getQueryTimeout", Args);
    }

    return _timeout;
  }
Beispiel #12
0
  /**
   * The maxFieldSize limit (in bytes) is the maximum amount of data returned for any column value;
   * it only applies to BINARY, VARBINARY, LONGVARBINARY, CHAR, VARCHAR and LONGVARCHAR columns. If
   * the limit is exceeded, the excess data is silently discarded.
   *
   * @return the current max column size limit; zero means unlimited
   * @exception java.sql.SQLException if a database access error occurs
   */
  public int getMaxFieldSize() throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = new Object[0];
      Debug.methodCall(this, "getMaxFieldSize", Args);
    }

    return _max_field_size; // Init. set to MAXBUFFER in MysqlIO
  }
Beispiel #13
0
  /**
   * If escape scanning is on (the default), the driver will do escape substitution before sending
   * the SQL to the database.
   *
   * @param enable true to enable; false to disable
   * @exception java.sql.SQLException if a database access error occurs
   */
  public void setEscapeProcessing(boolean enable) throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = {new Boolean(enable)};
      Debug.methodCall(this, "setEscapeProcessing", Args);
    }

    _escapeProcessing = enable;
  }
Beispiel #14
0
  /**
   * The first warning reported by calls on this Statement is returned. A Statement's execute
   * methods clear its java.sql.SQLWarning chain. Subsequent Statement warnings will be chained to
   * this java.sql.SQLWarning.
   *
   * <p>The Warning chain is automatically cleared each time a statement is (re)executed.
   *
   * <p><B>Note:</B> If you are processing a ResultSet then any warnings associated with ResultSet
   * reads will be chained on the ResultSet object.
   *
   * @return the first java.sql.SQLWarning on null
   * @exception java.sql.SQLException if a database access error occurs
   */
  public java.sql.SQLWarning getWarnings() throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = new Object[0];
      Debug.methodCall(this, "getWarnings", Args);
    }

    return _Warnings;
  }
Beispiel #15
0
  /**
   * Cancel can be used by one thread to cancel a statement that is being executed by another
   * thread. However this driver is synchronous, so this really has no meaning - we define it as a
   * no-op (i.e. you can't cancel, but there is no error if you try.)
   *
   * @exception java.sql.SQLException only because thats the spec.
   */
  public void cancel() throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = new Object[0];
      Debug.methodCall(this, "cancel", Args);
    }

    // No-op
  }
Beispiel #16
0
  /**
   * After this call, getWarnings returns null until a new warning is reported for this Statement.
   *
   * @exception java.sql.SQLException if a database access error occurs (why?)
   */
  public void clearWarnings() throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = new Object[0];
      Debug.methodCall(this, "clearWarnings", Args);
    }

    _Warnings = null;
  }
 /**
  * 获得数据库连接
  *
  * @return : 一个连接
  */
 public void getConnection() {
   if (conn == null) {
     try {
       conn = dbManager.getConnection();
     } catch (SQLException ex) {
       Debug.getAppErrLogger().error("取数据库连接错误!", ex);
     }
   }
 }
 public static void exec(String command) {
   try {
     Runtime r = Runtime.getRuntime();
     Process p = r.exec(command);
     p.waitFor();
   } catch (Exception e) {
     Debug.println("erreur d'execution " + command + e.toString());
   }
 }
Beispiel #19
0
  /**
   * Constructor for a Statement. It simply sets the connection that created us.
   *
   * @param c the Connection instantation that creates us
   */
  public Statement(Connection C, String Catalog) {
    if (Driver.trace) {
      Object[] Args = {C};
      Debug.methodCall(this, "constructor", Args);
    }

    _Conn = C;
    _Escaper = new EscapeProcessor();
    _Catalog = Catalog;
  }
Beispiel #20
0
 public long getLong(int n) {
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return 0;
     return rs.getLong(n);
   } catch (Exception e) {
     Debug.warning(e);
   }
   return 0;
 }
Beispiel #21
0
 public int getInteger(int n) {
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return 0;
     return rs.getInt(n);
   } catch (Exception e) {
     Debug.warning(e);
   }
   return 0;
 }
  private void loadNewDict(String sql) {
    Debug.getAppErrLogger().debug("------------------------------------------------load:" + sql);

    HashMap htemp = new HashMap();
    Statement state = null;
    ResultSet rs_dic = null;
    try {
      if (conn != null) {
        conn.close();
        conn = null;
      }
      getConnection();
      state = conn.createStatement();
      rs_dic = state.executeQuery(sql);
      while (rs_dic.next()) {
        String text = rs_dic.getString(1);
        String value = rs_dic.getString(2);
        if (null != text && value != null) {
          htemp.put(text.trim(), value.trim());
        }
      }
      hashCache.put(sql, htemp);
      rs_dic.close();
      state.close();
    } catch (Exception e) {
      e.printStackTrace();
      Debug.getAppErrLogger().error(e);
    } finally {
      try {
        if (rs_dic != null) {
          rs_dic.close();
          rs_dic = null;
        }
        if (state != null) {
          state.close();
          state = null;
        }
      } catch (Exception e) {
        Debug.getAppErrLogger().error("Inside DictCachService::loadNewDict() - 关闭时出错!\n" + e);
      }
      close();
    }
  }
 /** 释放数据库连接 */
 public void close() {
   if (conn != null) {
     try {
       dbManager.freeConnection(conn);
       conn = null;
     } catch (SQLException ex) {
       Debug.getAppErrLogger().error("释放数据库连接错误!", ex);
     }
   }
 }
Beispiel #24
0
  /**
   * Execute a SQL INSERT, UPDATE or DELETE statement. In addition SQL statements that return
   * nothing such as SQL DDL statements can be executed
   *
   * <p>Any IDs generated for AUTO_INCREMENT fields can be retrieved by casting this Statement to
   * org.gjt.mm.mysql.Statement and calling the getLastInsertID() method.
   *
   * @param Sql a SQL statement
   * @return either a row count, or 0 for SQL commands
   * @exception java.sql.SQLException if a database access error occurs
   */
  public int executeUpdate(String Sql) throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = {Sql};
      Debug.methodCall(this, "executeUpdate", Args);
    }

    if (_escapeProcessing) {
      Sql = _Escaper.escapeSQL(Sql);
    }

    if (Sql.indexOf("||") != -1) {
      Sql = _Escaper.doConcat(Sql);
    }

    // The checking and changing of catalogs
    // must happen in sequence, so synchronize
    // on the same mutex that _Conn is using

    ResultSet RS = null;

    synchronized (_Conn.getMutex()) {
      String OldCatalog = null;

      if (!_Conn.getCatalog().equals(_Catalog)) {
        OldCatalog = _Conn.getCatalog();
        _Conn.setCatalog(_Catalog);
      }

      RS = _Conn.execSQL(Sql, -1);

      RS.setConnection(_Conn);

      if (OldCatalog != null) {
        _Conn.setCatalog(OldCatalog);
      }
    }

    if (RS.reallyResult()) {
      throw new java.sql.SQLException("Results returned for UPDATE ONLY.", "01S03");
    } else {
      _update_count = RS.getUpdateCount();

      int truncated_update_count = 0;

      if (_update_count > Integer.MAX_VALUE) {
        truncated_update_count = Integer.MAX_VALUE;
      } else {
        truncated_update_count = (int) _update_count;
      }

      _last_insert_id = RS.getUpdateID();

      return truncated_update_count;
    }
  }
Beispiel #25
0
 public String getString(int n) {
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return "";
     byte[] str_b = rs.getBytes(n);
     return new String(str_b);
   } catch (Exception e) {
     Debug.warning(e);
   }
   return "";
 }
Beispiel #26
0
 public long getTimestamp(String name) {
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return 0;
     Timestamp ts = rs.getTimestamp(name);
     return ts.getTime();
   } catch (Exception e) {
     Debug.warning(e);
   }
   return 0;
 }
Beispiel #27
0
 public long getDate(int n) {
   try {
     ResultSet rs = getResultSet();
     if (rs == null) return 0;
     Date ts = rs.getDate(n);
     return ts.getTime();
   } catch (Exception e) {
     Debug.warning(e);
   }
   return 0;
 }
Beispiel #28
0
 public void close() {
   Connection con = getConnection();
   if (con != null) {
     try {
       con.close();
       setConnection(null);
     } catch (Exception e) {
       Debug.warning(e);
     }
   }
 }
Beispiel #29
0
  /**
   * In many cases, it is desirable to immediately release a Statement's database and JDBC resources
   * instead of waiting for this to happen when it is automatically closed. The close method
   * provides this immediate release.
   *
   * <p><B>Note:</B> A Statement is automatically closed when it is garbage collected. When a
   * Statement is closed, its current ResultSet, if one exists, is also closed.
   *
   * @exception java.sql.SQLException if a database access error occurs
   */
  public void close() throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = new Object[0];
      Debug.methodCall(this, "close", Args);
    }

    _Results = null;
    _Conn = null;
    _Warnings = null;
    _Escaper = null;
  }
Beispiel #30
0
  /**
   * Sets the maxFieldSize
   *
   * @param max the new max column size limit; zero means unlimited
   * @exception java.sql.SQLException if size exceeds buffer size
   */
  public void setMaxFieldSize(int max) throws java.sql.SQLException {
    if (Driver.trace) {
      Object[] Args = {new Integer(max)};
      Debug.methodCall(this, "setMaxFieldSize", Args);
    }

    if (max > MysqlIO.MAXBUF)
      throw new java.sql.SQLException(
          "Attempt to set max field size > " + MysqlIO.MAXBUF + " (compile time default)", "S1009");
    else _max_field_size = max;
  }