예제 #1
1
파일: UserDao.java 프로젝트: dsonti/deal70
  @Override
  public long update() throws DataModelException, TMException, SQLException {
    UserData user = (UserData) datamodel;

    ResultSet rst = null;
    try {
      String sql = UPDATE_USER;
      Collection<SQLValue> bindVars = new ArrayList<SQLValue>();

      bindVars.add(SQLValue.String(user.getUserName()));
      bindVars.add(SQLValue.String(user.getFirstName()));
      bindVars.add(SQLValue.String(user.getMiddleName()));
      bindVars.add(SQLValue.String(user.getLastName()));
      bindVars.add(SQLValue.String(user.getMailId()));
      bindVars.add(SQLValue.String(user.getPassword()));
      bindVars.add(SQLValue.Blob((Blob) user.getImage()));
      bindVars.add(SQLValue.String(user.getDob()));
      bindVars.add(SQLValue.Long(user.getSex()));
      bindVars.add(SQLValue.Long(user.getAddressId()));
      bindVars.add(SQLValue.String(user.getMaritalStatus()));
      bindVars.add(SQLValue.String(user.getNationality()));
      bindVars.add(SQLValue.Boolean(user.isActive()));
      bindVars.add(SQLValue.String(user.getActivationKey()));
      bindVars.add(SQLValue.Long(user.getId()));

      logger.debug("QUERY - Loading Address :" + sql);
      return executeUpdate(sql, bindVars);
    } catch (SQLException sql) {
      logger.error("SQL-Exception", sql);
      throw new TMException("SQL-Exception", sql.getLocalizedMessage());
    } finally {
      close(null, rst);
    }
  }
예제 #2
0
파일: UserDao.java 프로젝트: dsonti/deal70
  @Override
  public DataModel read() throws DataModelException, TMException, SQLException {
    UserData user = (UserData) datamodel;

    ResultSet rst = null;
    try {
      String sql = READ_USER;
      Collection<SQLValue> bindVars = new ArrayList<SQLValue>();
      if (user.getId() > 0) {
        sql += AND + "`ID` = ? ";
        bindVars.add(SQLValue.Long(user.getId()));
      }
      if (user.getUserName() != null) {
        sql += AND + "`USER_NAME` = ? ";
        bindVars.add(SQLValue.String(user.getUserName()));
      }
      if (user.getPassword() != null) {
        sql += AND + "`PASSWORD` = ? ";
        bindVars.add(SQLValue.String(user.getPassword()));
      }
      logger.debug("QUERY - Loading Address :" + sql);
      rst = executeQuery(sql, bindVars);

      return loadUserVO(user, rst);
    } catch (SQLException sql) {
      logger.error("SQL-Exception", sql);
      throw new TMException("SQL-Exception", sql.getLocalizedMessage());
    } finally {
      close(null, rst);
    }
  }
예제 #3
0
파일: UserDao.java 프로젝트: dsonti/deal70
  @Override
  public long create() throws DataModelException, TMException, SQLException {
    UserData user = (UserData) datamodel;
    if (user == null) throw new TMException("INVALID_VO", "provided User instance is null");

    if (isEmptyOrNull(user.getUserName()))
      throw new TMException("INVALID_KEY", "required key not found");

    if (read() != null) throw new SQLException("USER_EXISTS", "User Name already in use");

    try {
      String sql = CREATE_USER;
      Collection<SQLValue> bindVars = new ArrayList<SQLValue>();

      bindVars.add(SQLValue.String(user.getUserName()));
      bindVars.add(SQLValue.String(user.getFirstName()));
      bindVars.add(SQLValue.String(user.getMiddleName()));
      bindVars.add(SQLValue.String(user.getLastName()));
      bindVars.add(SQLValue.String(user.getMailId()));
      bindVars.add(SQLValue.String(user.getPassword()));
      bindVars.add(SQLValue.Blob((Blob) user.getImage()));
      bindVars.add(SQLValue.String(user.getDob()));
      bindVars.add(SQLValue.Long(user.getSex()));
      bindVars.add(SQLValue.Long(user.getAddressId()));
      bindVars.add(SQLValue.String(user.getMaritalStatus()));
      bindVars.add(SQLValue.String(user.getNationality()));
      bindVars.add(SQLValue.Boolean(user.isActive()));
      bindVars.add(SQLValue.String(user.getActivationKey()));

      logger.debug("QUERY - Loading Address :" + sql);
      return executeUpdate(sql, bindVars);
    } catch (SQLException sql) {
      logger.error("SQL-Exception", sql);
      throw new TMException("SQL-Exception", sql.getLocalizedMessage());
    }
  }