Example #1
0
  public Row getRow(Table table, int action, OpenJPAStateManager sm, boolean create) {
    if (sm == null) return null;

    // check if request matches cached version
    if (_key != null
        && _key.table == table
        && _key.sm == sm
        && _row != null
        && _row.getAction() == action) return _row;

    Map<Key, PrimaryRow> map;
    if (action == Row.ACTION_DELETE) {
      if (_deletes == null && create) _deletes = new LinkedHashMap<Key, PrimaryRow>();
      map = _deletes;
    } else if (action == Row.ACTION_INSERT) {
      if (_inserts == null && create) _inserts = new LinkedHashMap<Key, PrimaryRow>();
      map = _inserts;
    } else {
      if (_updates == null && create) _updates = new LinkedHashMap<Key, PrimaryRow>();
      map = _updates;
    }
    if (map == null) return null;

    _key = new Key(table, sm);
    _row = map.get(_key);

    if (_row == null && create) {
      _row = new PrimaryRow(table, action, sm);
      map.put(_key, _row);
      if (_primaryOrder != null) {
        _row.setIndex(_primaryOrder.size());
        _primaryOrder.add(_row);
      }

      if (!_auto && action == Row.ACTION_INSERT) _auto = table.getAutoAssignedColumns().length > 0;
    }

    if (_row != null) _row.setFailedObject(sm.getManagedInstance());
    return _row;
  }
Example #2
0
 public int hashCode() {
   return ((table == null) ? 0 : table.hashCode())
       + ((sm == null) ? 0 : sm.hashCode()) % Integer.MAX_VALUE;
 }