Re: ERXQuery Preview

2017-03-12 Thread Paul Hoadley
On 12 Mar 2017, at 9:11 am, Ricardo Parada  wrote:

> Please let me know if you guys think this would be a useful contribution.


Looks great Ricardo. Nice work.


-- 
Paul Hoadley
http://logicsquad.net/
https://www.linkedin.com/company/logic-squad/



 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com


Re: ERXQuery Preview

2017-03-12 Thread George Domurot
For sure!

Sent from my iPhone

> On Mar 11, 2017, at 8:27 PM, Chuck Hill  wrote:
> 
> That looks like a very cool, useful contribution!
>  
> Chuck
>  
> From:  on behalf 
> of Ricardo Parada 
> Date: Saturday, March 11, 2017 at 2:41 PM
> To: "webobjects-dev@lists.apple.com WebObjects" 
> 
> Subject: ERXQuery Preview
>  
> Hi all,
>  
> Over the years, I’ve worked on an class for doing ad hoc queries.  This class 
> has gotten better and better.  At first, the API of this class and some 
> implementation details were not  ready for public consumption in my opinion.  
>  
> However, recently I took the time to polish the code as much as possible and 
> if I can get my employer's approval I would like to contribute this code to 
> project Wonder which has given us so much in return during the years.  
>  
> Here is a preview of its functionality.  Please let me know if you guys think 
> this would be a useful contribution.
> ERXQuery.java
> This class has a fluent API that mimics a select statement:
> NSArray> records =
>ERXQuery.create()
>   .select (keys)
>   .from (entity)
>   .where (qualifier)
>   .groupBy (groupings)
>   .having (havingQualifier)
>   .orderBy (sortings)
>   .fetch();
> Overview
> ERXQuery allows you to use EOF constructs (EOQualifiers, EOAttributes, 
> EOSortOrdering, EOAttribute names, relationships, etc.) to create queries of 
> the form:
> SELECT ...
> FROM ...
> WHERE ...
> GROUP BY ...
> HAVING ...
> ORDER BY ...
> Using Ad Hoc Attributes
> You may use the ERXAdHocAttributes class to easily create ad hoc attributes 
> to use with your query. For example, the code below creates two ad hoc 
> EOAttributes. An ad hoc attribute is an EOAttribute that is not physically 
> attached to an entity and that has a definition. They are useful for 
> aggregating other attributes. The definition of the attribute can reference 
> relationships and attributes as shown below.
> // Using a single query against the order entity, count the number of
> // orders and line items that match the qualifier.
> ERXAdHocAttributes attributes = ERXAdHocAttributes.create(orderEntity)
>.add("itemCount", "COUNT(DISTINCT lineItems.lineItemID)", "intNumber")
>.add("orderCount", "COUNT(DISTINCT orderID)", "intNumber");
> NSDictionary row =
>ERXQuery.create()
>   .select (attributes)
>   .from (orderEntity)
>   .where (qualifier)
>   .fetch()
>   .lastObject();
> int orderCount = ((Number) row.objectForKey("orderCount")).intValue();
> int itemCount = ((Number) row.objectForKey("itemCount")).intValue();
> Fetching into a Custom Record Class
> You can also fetch using a custom class of your choice, i.e. Foo, as shown 
> below:
> // Using java >= 8 is easy with a lambda expression
> NSArray objs = query.fetch(editingContext, (ec, row) -> new Foo(ec, 
> row));
>
> // Using java < 8 you must provide a RecordConstructor 
> ERXQuery.RecordConstructor recordConstructor =
>new ERXQuery.RecordConstructor {
>@Override
>public Foo constructRecord(EOEditingContext ec, NSMutableDictionary 
> row) {
>   return new Foo(ec, row);
>}
>};
> NSArray objs = query.fetch(editingContext, recordConstructor);
> Author: Ricardo J. Parada
> ___
> Do not post admin requests to the list. They will be ignored.
> Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
> Help/Unsubscribe/Update your Subscription:
> https://lists.apple.com/mailman/options/webobjects-dev/g%40knuckleheads.net
> 
> This email sent to g...@knuckleheads.net
 ___
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list  (Webobjects-dev@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/webobjects-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com