Exemplo n.º 1
0
 /**
  * Returns index of the object a <code>List</code> object of <code>PersistentObject</code>s that
  * contains an encoded key (<code>getEncodedKey()</code>).
  *
  * @param list <code>List</code> of objects to search.
  * @param encodedKey key obtained via <code>getEncodedKey()</code>.
  * @return index of object on list or <code>-1</code> if not found.
  * @see net.sf.jrf.domain.PersistentObject#getEncodedKey()
  * @see #findByKey(List,String)
  */
 public static int findIndexByKey(List list, String encodedKey) {
   for (int i = 0; i < list.size(); i++) {
     PersistentObject p = (PersistentObject) list.get(i);
     if (p.getEncodedKey().equals(encodedKey)) {
       return i;
     }
   }
   return -1;
 }
Exemplo n.º 2
0
 /**
  * Scans a list of <code>PersistentObject</code>s and return the object that matches the key or
  * <code>null</code> if not found.
  *
  * @param list list of <code>PersistentObject</code>s to scan.
  * @param encodedKey key to locate correct record on the list.
  * @return key-matching record of <code>null</code> if not found.
  */
 public static PersistentObject getPoInList(List list, String encodedKey) {
   Iterator iter = list.iterator();
   while (iter.hasNext()) {
     PersistentObject p = (PersistentObject) iter.next();
     if (p.getEncodedKey().equals(encodedKey)) {
       return p;
     }
   }
   return null;
 }
 /**
  * Using the list of <code>ColumnSpec</code> instances, set the prepared statement values from
  * parameter.
  *
  * @param obj is assumed to be a <code>List</code> of objects.
  * @throws SQLException if a JDBC set parameter method fails.
  */
 public void setPreparedValues(Object obj) throws SQLException {
   List params = (List) obj;
   if (params.size() != columnSpecs.size()) {
     throw new IllegalArgumentException(
         "Illegal list of parameters. There are "
             + columnSpecs.size()
             + " parameters to fill but argument supplied has "
             + params.size()
             + ".");
   }
   Iterator columnSpecIterator = columnSpecs.iterator();
   Iterator objIterator = params.iterator();
   int idx = 1;
   while (columnSpecIterator.hasNext()) {
     ColumnSpec aColumnSpec = (ColumnSpec) columnSpecIterator.next();
     setPreparedColumnValue(aColumnSpec, objIterator.next(), idx);
     idx++;
   }
 }
Exemplo n.º 4
0
 /**
  * Updates a <code>List</code> of objects obtained through a call to <code>findAllByList()</code>.
  * Each modified row in the list will be updated.
  *
  * @param list list of <code>PersistentObject</code>s.
  * @exception ObjectHasChangedException Description of the Exception
  * @exception MissingAttributeException Description of the Exception
  * @throws ObjectHasChangeException when another user has already updated the record (i.e. an
  *     optimistic lock error.
  * @throws MissingAtributeException if the column specification for some fields are marked as
  *     required and these fields are <code>null</code> in the <code>PersistentObject</code>
  *     parameter.
  * @throws DuplicateRowException if an insert operation fails or would fail because of key
  *     duplication.
  * @throws InvalidValueException if a value in a column is invalid (e.g. out of range).
  * @see #findByKey(Object)
  * @see #getAllAsList()
  */
 public void update(List list)
     throws ObjectHasChangedException, MissingAttributeException, DuplicateRowException,
         InvalidValueException {
   update(list.iterator());
 }