/**
  * Returns the enterprise objects fetched with decoded <code>formValues</code> from <code>
  * entityName</code>.
  *
  * @param ec the editing context to fetch the objects from
  * @param entityName the entity to fetch the objects from
  * @param formValues dictionary where the values are an encoded representation of the primary key
  *     values in either cleartext or encrypted format.
  * @return the enterprise objects
  */
 public static NSArray enterpriseObjectsForEntityNamedFromFormValues(
     EOEditingContext ec, String entityName, NSDictionary formValues) {
   NSArray formValueObjects = decodeEnterpriseObjectsFromFormValues(ec, formValues);
   NSDictionary groups = ERXArrayUtilities.arrayGroupedByKeyPath(formValueObjects, "entityName");
   EOEntity entity = ERXEOAccessUtilities.entityNamed(ec, entityName);
   NSMutableArray entityGroup = new NSMutableArray();
   if (entity != null && entity.isAbstractEntity()) {
     for (Enumeration e = ERXUtilities.allSubEntitiesForEntity(entity, false).objectEnumerator();
         e.hasMoreElements(); ) {
       EOEntity subEntity = (EOEntity) e.nextElement();
       NSArray aGroup = (NSArray) groups.objectForKey(subEntity.name());
       if (aGroup != null) entityGroup.addObjectsFromArray(aGroup);
     }
   } else {
     entityGroup.addObjectsFromArray((NSArray) groups.objectForKey(entityName));
   }
   return entityGroup != null ? entityGroup : NSArray.EmptyArray;
 }
Esempio n. 2
0
  public WOComponent executeQuery() {
    EOModel m = EOModelGroup.defaultGroup().models().objectAtIndex(0);
    con = ERXJDBCConnectionBroker.connectionBrokerForModel(m).getConnection();
    try {
      con.setAutoCommit(false);
      Statement s = con.createStatement();
      ResultSet rs = s.executeQuery(sql);
      con.commit();
      StringBuffer buf = new StringBuffer();

      // append header
      buf.append("<table border=\"1\"><tr>");
      ResultSetMetaData rsmd = rs.getMetaData();
      int colcount = rsmd.getColumnCount();
      for (int i = 1; i <= colcount; i++) {
        buf.append("<td>");
        buf.append(rsmd.getColumnName(i));
        buf.append("</td>");
      }
      buf.append("</tr>");

      while (rs.next()) {
        buf.append("<tr>");
        for (int i = 1; i <= colcount; i++) {
          buf.append("<td>");
          Object o = rs.getObject(i);
          buf.append(o == null ? "" : o.toString());
          buf.append("</td>");
        }
        buf.append("</tr>");
      }
      buf.append("</table>");
      response = buf.toString();
    } catch (SQLException e) {
      response = ERXUtilities.stackTrace(e);
    } finally {
      ERXJDBCConnectionBroker.connectionBrokerForModel(m).freeConnection(con);
    }
    return context().page();
  }