Example #1
0
  /**
   * Create a new object of type cls from a resultset row starting from a specified offset. This is
   * done so that you can select other rows than just those needed for this object. You may for
   * example want to create two objects from the same row.
   *
   * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
   *     TorqueException.
   */
  public static User row2Object(Record row, int offset, Class cls) throws TorqueException {
    try {
      User obj = (User) cls.newInstance();
      UserPeer.populateObject(row, offset, obj);
      obj.setModified(false);
      obj.setNew(false);

      return obj;
    } catch (InstantiationException e) {
      throw new TorqueException(e);
    } catch (IllegalAccessException e) {
      throw new TorqueException(e);
    }
  }
Example #2
0
 /** Build a Criteria object from the data object for this peer */
 public static Criteria buildCriteria(User obj) {
   Criteria criteria = new Criteria(DATABASE_NAME);
   if (!obj.isNew()) criteria.add(ID, obj.getId());
   criteria.add(NAME, obj.getName());
   criteria.add(PASSWORD, obj.getPassword());
   criteria.add(TRUE_NAME, obj.getTrueName());
   criteria.add(TEAM, obj.getTeam());
   criteria.add(SEX, obj.getSex());
   criteria.add(BIRTH, obj.getBirth());
   criteria.add(LASTLOGINDATE, obj.getLastlogindate());
   return criteria;
 }
Example #3
0
 /**
  * Populates an object from a resultset row starting from a specified offset. This is done so that
  * you can select other rows than just those needed for this object. You may for example want to
  * create two objects from the same row.
  *
  * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
  *     TorqueException.
  */
 public static void populateObject(Record row, int offset, User obj) throws TorqueException {
   try {
     obj.setId(row.getValue(offset + 0).asInt());
     obj.setName(row.getValue(offset + 1).asString());
     obj.setPassword(row.getValue(offset + 2).asString());
     obj.setTrueName(row.getValue(offset + 3).asString());
     obj.setTeam(row.getValue(offset + 4).asString());
     obj.setSex(row.getValue(offset + 5).asInt());
     obj.setBirth(row.getValue(offset + 6).asString());
     obj.setLastlogindate(row.getValue(offset + 7).asUtilDate());
   } catch (DataSetException e) {
     throw new TorqueException(e);
   }
 }
Example #4
0
 /**
  * Method to do update. This method is to be used during a transaction, otherwise use the
  * doUpdate(User) method. It will take care of the connection details internally.
  *
  * @param obj the data object to update in the database.
  * @param con the connection to use
  * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
  *     TorqueException.
  */
 public static void doUpdate(User obj, Connection con) throws TorqueException {
   doUpdate(buildCriteria(obj), con);
   obj.setModified(false);
 }
Example #5
0
 /**
  * Method to do inserts. This method is to be used during a transaction, otherwise use the
  * doInsert(User) method. It will take care of the connection details internally.
  *
  * @param obj the data object to insert into the database.
  * @param con the connection to use
  * @throws TorqueException Any exceptions caught during processing will be rethrown wrapped into a
  *     TorqueException.
  */
 public static void doInsert(User obj, Connection con) throws TorqueException {
   obj.setPrimaryKey(doInsert(buildCriteria(obj), con));
   obj.setNew(false);
   obj.setModified(false);
 }