Exemple #1
0
  /**
   * Selects exactly one LOB (of the target type) from exactly one query row.
   *
   * @param pUCon
   * @return True if a valid row was selected, false otherwise.
   * @throws ExDBTimeout
   */
  protected boolean selectRow(UCon pUCon) throws ExDBTimeout {

    ExecutableQuery lSelectQuery = mWorkingStorageLocation.getExecutableSelectStatement();
    try {
      SingleRowResultDeliverer lDeliverer = new SingleRowResultDeliverer();
      lSelectQuery.executeAndDeliver(pUCon, lDeliverer);

      Map<String, Object> lColumnMap = lDeliverer.getColumnMap();
      LOBAccessor<T> lLOBAccessor = null;
      int lLOBsFound = 0;
      COL_LOOP:
      for (Map.Entry<String, Object> lColumn : lColumnMap.entrySet()) {
        Object lColObject = lColumn.getValue();

        // If we don't know what LOB type we're looking for, try and get an accessor for every
        // object, otherwise only
        // attempt to get an accessor for columns of the desired type.
        if (lColObject != null
            && (mLOBClass == AnyLOBType.class || mLOBClass.isInstance(lColObject))) {
          LOBAccessor<T> lLOBAccessorOrNull =
              LOBAccessor.getAccessorForLOBOrNull(lColObject, mLOBClass);
          if (lLOBAccessorOrNull != null) {
            lLOBsFound++;
            lLOBAccessor = lLOBAccessorOrNull;
          }
        }
      }

      // Looped all columns without finding exactly one compatible LOB - this is an error
      if (lLOBsFound != 1) {
        throw new ExInternal(
            "Select query for "
                + mWorkingStorageLocation.getStorageLocationName()
                + " failed to locate exactly one non-null "
                + mLOBClass.getSimpleName()
                + " column (got "
                + lLOBsFound
                + ")");
      } else {
        mLOBAccessor = lLOBAccessor;
      }

      return true;
    } catch (ExDBTooFew e) {
      return false;
    } catch (ExDBTooMany e) {
      throw new ExInternal(
          "Select query for "
              + mWorkingStorageLocation.getStorageLocationName()
              + " returned more than 1 row",
          e);
    } catch (ExDBTimeout e) {
      throw e;
    } catch (ExDB e) {
      throw new ExInternal(
          "Error running select query for " + mWorkingStorageLocation.getStorageLocationName(), e);
    }
  }
 /**
  * Constructs a new UConStatementResult from a ResultSet.
  *
  * @param pResultSet
  * @return New UConStatementResult.
  * @throws SQLException If ResultSet read fails.
  */
 static UConStatementResult fromResultSet(ResultSet pResultSet) throws SQLException {
   return new UConStatementResult(
       SingleRowResultDeliverer.createObjectMapFromResultSet(pResultSet));
 }