Пример #1
0
    /**
     * Convenience method for selecting records. Ideally this should not be use, instead a custom
     * query for this table should be used.
     *
     * @param where sql where statement.
     * @param orderBy sql order by statement
     */
    public ResultSet select(String where, String orderBy) {
      ResultSet rs = null;
      java.sql.Statement stmnt = null;

      try {
        stmnt = GenOrmDataSource.createStatement();
        StringBuilder sb = new StringBuilder();
        sb.append(SELECT);
        sb.append(FROM);
        if (where != null) {
          sb.append(WHERE);
          sb.append(where);
        }

        if (orderBy != null) {
          sb.append(" ");
          sb.append(orderBy);
        }

        String query = sb.toString();
        rs = new SQLResultSet(stmnt.executeQuery(query), query, stmnt);
      } catch (java.sql.SQLException sqle) {
        try {
          if (stmnt != null) stmnt.close();
        } catch (java.sql.SQLException sqle2) {
        }

        throw new GenOrmException(sqle);
      }

      return (rs);
    }
Пример #2
0
    /**
     * This resets the key generator from the values in the database Usefull if the generated key
     * has been modified via some other means Connection must be open before calling this
     */
    public synchronized void reset() {
      m_nextKey = 0;
      java.sql.Statement stmnt = null;
      java.sql.ResultSet rs = null;
      try {
        stmnt = GenOrmDataSource.createStatement();
        rs = stmnt.executeQuery(MAX_QUERY);

        if (rs.next()) m_nextKey = rs.getInt(1);
      } catch (java.sql.SQLException sqle) {
        // The exception may occur if the table does not yet exist
        if (WARNINGS) System.out.println(sqle);
      } finally {
        try {
          if (rs != null) rs.close();

          if (stmnt != null) stmnt.close();
        } catch (java.sql.SQLException sqle2) {
          throw new GenOrmException(sqle2);
        }
      }
    }