@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); } }
@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()); } }