예제 #1
0
  public void appendToResponse(WOResponse aResponse, WOContext aContext) {
    try {
      Number b = (Number) valueForBinding("firstNameDisplay");
      if (b != null) firstNameDisplay = b.intValue();
      else firstNameDisplay = 2;

      b = (Number) valueForBinding("secondNameDisplay");
      if (b != null) secondNameDisplay = b.intValue();
      else secondNameDisplay = 2;

    } catch (ClassCastException cex) {
      throw new IllegalArgumentException("NameDisplay bindings should be integer");
    }
    String request = (String) valueForBinding("searchRequest");
    if (request != null) {
      performSearchRequest(request);
    } else {
      selection =
          (PersonLink)
              EOUtilities.localInstanceOfObject(
                  ec, (EOEnterpriseObject) valueForBinding("selection"));
      //			syncSelection();
    }
    if (selection == null && Various.boolForObject(valueForBinding("showPopup"))) {
      selection = defaultSelectionValue();
      setValueForBinding(selection, "selection");
    }
    super.appendToResponse(aResponse, aContext);
    found = null;
    //		searchMessage = null;
  }
예제 #2
0
  /**
   * Overrides the parent implementation to provide a more efficient mechanism for generating
   * primary keys, while generating the primary key support on the fly.
   *
   * @param count the batch size
   * @param entity the entity requesting primary keys
   * @param channel open JDBCChannel
   * @return NSArray of NSDictionary where each dictionary corresponds to a unique primary key value
   */
  public NSArray newPrimaryKeys(int count, EOEntity entity, JDBCChannel channel) {
    if (isPrimaryKeyGenerationNotSupported(entity)) {
      return null;
    }

    EOAttribute attribute = (EOAttribute) entity.primaryKeyAttributes().lastObject();
    String attrName = attribute.name();
    boolean isIntType = "i".equals(attribute.valueType());

    NSMutableArray results = new NSMutableArray(count);
    String sequenceName = sequenceNameForEntity(entity);
    DB2Expression expression = new DB2Expression(entity);

    boolean succeeded = false;
    for (int tries = 0; !succeeded && tries < 2; tries++) {
      while (results.count() < count) {
        try {
          StringBuffer sql = new StringBuffer();
          sql.append("SELECT ");
          sql.append("next value for " + sequenceName + " AS KEY");
          sql.append(" from sysibm.sysdummy1");
          expression.setStatement(sql.toString());
          channel.evaluateExpression(expression);
          try {
            NSDictionary row;
            while ((row = channel.fetchRow()) != null) {
              Enumeration pksEnum = row.allValues().objectEnumerator();
              while (pksEnum.hasMoreElements()) {
                Number pkObj = (Number) pksEnum.nextElement();
                Number pk;
                if (isIntType) {
                  pk = Integer.valueOf(pkObj.intValue());
                } else {
                  pk = Long.valueOf(pkObj.longValue());
                }
                results.addObject(new NSDictionary(pk, attrName));
              }
            }
          } finally {
            channel.cancelFetch();
          }
          succeeded = true;
        } catch (JDBCAdaptorException ex) {
          throw ex;
        }
      }
    }

    if (results.count() != count) {
      throw new IllegalStateException(
          "Unable to generate primary keys from the sequence for " + entity + ".");
    }

    return results;
  }