Package util

Examples of util.SQLHelper


   * @return Whether the session could be authenticated.
   * @throws Exception
   */
  protected boolean checkCredentials(String session_id, Credential[] credentials) throws Exception
  {
    SQLHelper sql = null;
    Object[] params = {
      credentials[USERNAME].getValue(),
      credentials[PASSWORD].getValue(),
      credentials[PROJECT].getValue(),
    };

    try {
      sql = new SQLHelper();
      sql.openDB();
      return sql.retrieve(CHECK_CRED_QUERY, params).next();

    } finally {
      sql.closeDB();
    }
  }
View Full Code Here


  public boolean authenticate(String session_id, Credential[] credentials) throws Exception
  {
    if (!checkCredentials(session_id, credentials))
      return false;

    SQLHelper sql = null;
    Object[] params = { session_id };

    try {
      sql = new SQLHelper();
      sql.openDB();
      return sql.update(AUTH_QUERY, params) == 1;

    } finally {
      sql.closeDB();
    }
  }
View Full Code Here

   * @throws Exception
   */
  public SimpleTable getMoteData(String session_id) throws Exception
  {
    String query,select;
    SQLHelper sql = null;
    ResultSet rs = null;
    SimpleTable result = null;
    Object[] param = { session_id };

    try {
      sql = new SQLHelper();
      sql.openDB();
      query = "select m.id mote_id, m.site_id site_id,s.sitename site, " +
        "case when m.curr_session_id=? then 'controlled' " +
              "when isnull(m.curr_session_id) then 'available' else 'occupied' end mote_usage ";

      select = "select id, name from moteattrtype order by sortseq";
      rs = sql.retrieve(select);
      while (rs.next()) {
        query+=getMoteAttrSubquery(rs.getString("name"),rs.getString("id"));
      }
      select = "select id, name from siteattrtype order by sortseq";
      rs = sql.retrieve(select);
      while (rs.next()) {
        query+=getSiteAttrSubquery(rs.getString("name"),rs.getString("id"));
      }
      query+=" from mote m, site s " +
             " where s.id=m.site_id";
      rs = sql.retrieve(query, param);
      rs.last();
      int rows = rs.getRow();
      int cols = rs.getMetaData().getColumnCount();
      result = new SimpleTable(rows,cols);
      rs.beforeFirst();

      for (int i=0;i<cols;i++){
        String title = rs.getMetaData().getColumnLabel(i+1);
        String name = rs.getMetaData().getColumnName(i+1);
        String classname = rs.getMetaData().getColumnClassName(i+1);
        result.getColumnHeaders()[i] = new ColumnHeader(title,name,true,classname);
      }

      int i = 0;
      while (rs.next()) {
        for (int j=0;j<cols;j++)
        {
          result.getData()[i][j] = rs.getObject(j+1);
        }
        i++;
      }

      return result;

    } finally {
      sql.closeDB();
    }
  }
View Full Code Here

   * @throws Exception
   */
  protected boolean getMoteControlPrivilege(long mote_id, String session_id) throws Exception
  {
    boolean access = false;
    SQLHelper sql = null;
    Object[] priv_params = { new Long(mote_id) };

    /* TODO: The queries in here are executed multiple
     * times. Since we use PreparedStatements this could be
     * optimized by moving the query initialization out of
     * the loop. This would require that SQLHelper exposes
     * more of its internal state such as allowing
     * PreparedStatement to be returned. */
    try {
      sql = new SQLHelper();
      sql.openDB();

      /* Check for current privileged session. */
      ResultSet sqlres = sql.retrieve(PRIV_QUERY, priv_params);
      if (sqlres.next()) {
        String privsess = sqlres.getString("priv_session_id");

        access = checkMoteAccess(session_id, privsess, mote_id);
      }

      if (access) {
        /* Grant privileges to current session. */
        Object[] access_params = { session_id, new Long(mote_id) };
        sql.execute(ACCESS_QUERY, access_params);
      }
      return access;

    } finally {
      sql.closeDB();
    }
  }
View Full Code Here

TOP

Related Classes of util.SQLHelper

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.