Re: ERXQuery Preview

2017-03-19 Thread Ricardo Parada
All done.  I created feature branches as suggested and used them to create the 
pull requests.

Thanks for the help.

Ricardo


> On Mar 19, 2017, at 3:21 AM, Ricardo Parada <rpar...@mac.com> wrote:
> 
> That sounds like what is going on. I'll give that a shot tomorrow. Thanks 
> Chuck. 
> 
> Sent from my iPhone
> 
> On Mar 19, 2017, at 2:59 AM, Chuck Hill <ch...@gevityinc.com 
> <mailto:ch...@gevityinc.com>> wrote:
> 
>> Hi Ricardo,
>>  
>> You need to create a branch (push from your local) in your GitHub fork of 
>> Wonder for each set of changes in GitHub (aka a Feature Branch), then make a 
>> pull request from that branch to Wonder.  Otherwise all of your changes get 
>> inter-mixed.
>>  
>> Chuck
>>  
>>  
>> From: Ricardo Parada <rpar...@mac.com <mailto:rpar...@mac.com>>
>> Date: Saturday, March 18, 2017 at 11:22 PM
>> To: "webobjects-dev@lists.apple.com <mailto:webobjects-dev@lists.apple.com>" 
>> <webobjects-dev@lists.apple.com <mailto:webobjects-dev@lists.apple.com>>
>> Cc: Markus Ruggiero <mailingli...@kataputt.com 
>> <mailto:mailingli...@kataputt.com>>, Paul Hoadley <pa...@logicsquad.net 
>> <mailto:pa...@logicsquad.net>>, "koa...@icloud.com 
>> <mailto:koa...@icloud.com>" <koa...@icloud.com <mailto:koa...@icloud.com>>, 
>> "g...@knuckleheads.net <mailto:g...@knuckleheads.net>" 
>> <g...@knuckleheads.net <mailto:g...@knuckleheads.net>>, Chuck Hill 
>> <ch...@gevityinc.com <mailto:ch...@gevityinc.com>>, "aa...@chatnbike.com 
>> <mailto:aa...@chatnbike.com>" <aa...@chatnbike.com 
>> <mailto:aa...@chatnbike.com>>
>> Subject: Re: ERXQuery Preview
>>  
>> Hi all, 
>>  
>> As promised, I have committed ERXQuery to my Wonder clone on GitHub, i.e. 
>> rparada/wonder.  I just need help creating the pull request.  :-)
>>  
>> It turns out that I created first a pull request for ERXExtensions.java 
>> unrelated to ERXQuery.  Now when I tried to create the pull request for 
>> ERXQuery it just seems to show the previous pull request.  So I’m not sure 
>> what is going on.  I don’t have much experience with GitHub.
>>  
>> Anyways, the ERXQuery is an additive change to Wonder and consists of only 
>> three files: ERXQuery.java, ERXQueryAttributes and ERXQueryEOAttribute.  
>> It’s the last two commits in rparada/wonder.
>>  
>> I took the time to polish the API a bit more.  I think the API came out 
>> nicer than what I had the first time around.  Specially the single variadic 
>> select() method that allows you to specify EOAttributes, Strings, ERXKeys, 
>> or any Iterable containing these. Same for groupBy().  And the a similar 
>> technique with the orderBy() which can take EOSortOrderings or any Iterable 
>> (ERXSortOrderings, NSArray, List, Collection).
>>  
>> The documentation is more extensive now.  I have included here a copy of the 
>> ERXQuery class from the javadoc tab in my Eclipse.  
>>  
>> I have tested with ORACLE which is the easiest for me to test.  It would be 
>> great to hear others using this with other databases (h2, derby, mssql, 
>> mysql, frontbase, etc.)
>>  
>>  
>> ERXQuery.java
>> Overview
>> This class has a fluent API that mimics a select statement:
>> 
>>   NSArray<NSDictionary<String,Object>> records =
>>   ERXQuery.create()
>>   .select (keys)
>>   .from (entity)
>>   .where (qualifier)
>>   .groupBy (groupings)
>>   .having (havingQualifier)
>>   .orderBy (sortings)
>>   .fetch();
>>   
>> It allows you to use EOF/Wonder higher-level constructs (qualifiers, 
>> attributes, orderings, key paths, ERXKeys, etc.) to create a query that 
>> looks like this:
>> 
>>   SELECT ...
>>   FROM ...
>>   WHERE ...
>>   GROUP BY ...
>>   HAVING ...
>>   ORDER BY ...
>>   
>>  
>> Specifying the Attributes to Fetch
>> The select() method is very flexible and powerful. It accepts a variable 
>> number of objects of different types that specify the attributes to fetch. 
>> These objects can be EOAttributes, ERXKeys, Strings. You may also specify 
>> NSArray or List objects containing any combination of these (EOAttributes, 
>> ERXKeys, Strings).
>> 
>> The ERXKeys and String objects correspond to keys and key paths to the 
>> attributes to fetch, i.e. "customer.name". The key

Re: ERXQuery Preview

2017-03-19 Thread Ricardo Parada
That sounds like what is going on. I'll give that a shot tomorrow. Thanks 
Chuck. 

Sent from my iPhone

> On Mar 19, 2017, at 2:59 AM, Chuck Hill <ch...@gevityinc.com> wrote:
> 
> Hi Ricardo,
>  
> You need to create a branch (push from your local) in your GitHub fork of 
> Wonder for each set of changes in GitHub (aka a Feature Branch), then make a 
> pull request from that branch to Wonder.  Otherwise all of your changes get 
> inter-mixed.
>  
> Chuck
>  
>  
> From: Ricardo Parada <rpar...@mac.com>
> Date: Saturday, March 18, 2017 at 11:22 PM
> To: "webobjects-dev@lists.apple.com" <webobjects-dev@lists.apple.com>
> Cc: Markus Ruggiero <mailingli...@kataputt.com>, Paul Hoadley 
> <pa...@logicsquad.net>, "koa...@icloud.com" <koa...@icloud.com>, 
> "g...@knuckleheads.net" <g...@knuckleheads.net>, Chuck Hill 
> <ch...@gevityinc.com>, "aa...@chatnbike.com" <aa...@chatnbike.com>
> Subject: Re: ERXQuery Preview
>  
> Hi all,
>  
> As promised, I have committed ERXQuery to my Wonder clone on GitHub, i.e. 
> rparada/wonder.  I just need help creating the pull request.  :-)
>  
> It turns out that I created first a pull request for ERXExtensions.java 
> unrelated to ERXQuery.  Now when I tried to create the pull request for 
> ERXQuery it just seems to show the previous pull request.  So I’m not sure 
> what is going on.  I don’t have much experience with GitHub.
>  
> Anyways, the ERXQuery is an additive change to Wonder and consists of only 
> three files: ERXQuery.java, ERXQueryAttributes and ERXQueryEOAttribute.  It’s 
> the last two commits in rparada/wonder.
>  
> I took the time to polish the API a bit more.  I think the API came out nicer 
> than what I had the first time around.  Specially the single variadic 
> select() method that allows you to specify EOAttributes, Strings, ERXKeys, or 
> any Iterable containing these. Same for groupBy().  And the a similar 
> technique with the orderBy() which can take EOSortOrderings or any Iterable 
> (ERXSortOrderings, NSArray, List, Collection).
>  
> The documentation is more extensive now.  I have included here a copy of the 
> ERXQuery class from the javadoc tab in my Eclipse.  
>  
> I have tested with ORACLE which is the easiest for me to test.  It would be 
> great to hear others using this with other databases (h2, derby, mssql, 
> mysql, frontbase, etc.)
>  
>  
> ERXQuery.java
> Overview
> This class has a fluent API that mimics a select statement:
> 
>   NSArray<NSDictionary<String,Object>> records =
>   ERXQuery.create()
>   .select (keys)
>   .from (entity)
>   .where (qualifier)
>   .groupBy (groupings)
>   .having (havingQualifier)
>   .orderBy (sortings)
>   .fetch();
>   
> It allows you to use EOF/Wonder higher-level constructs (qualifiers, 
> attributes, orderings, key paths, ERXKeys, etc.) to create a query that looks 
> like this:
> 
>   SELECT ...
>   FROM ...
>   WHERE ...
>   GROUP BY ...
>   HAVING ...
>   ORDER BY ...
>   
>  
> Specifying the Attributes to Fetch
> The select() method is very flexible and powerful. It accepts a variable 
> number of objects of different types that specify the attributes to fetch. 
> These objects can be EOAttributes, ERXKeys, Strings. You may also specify 
> NSArray or List objects containing any combination of these (EOAttributes, 
> ERXKeys, Strings).
> 
> The ERXKeys and String objects correspond to keys and key paths to the 
> attributes to fetch, i.e. "customer.name". The keys and key paths can also be 
> relationships to objects, i.e. "customer" which translate into a fetch of 
> foreign keys used to build object faults and return them in the results.
> 
> You may call the select() method multiple times to keep adding to the list of 
> attributes to fetch.
> 
> Using Ad Hoc Attributes
> It is very common to aggregate attributes in these queries. For this purpose, 
> you may want to create what ERXQuery refers to as ad hoc attributes. These 
> attributes have a definition but are not physically attached to the entity. 
> You can use the ERXQueryAttributes class to easily create multiple ad hoc 
> attributes. The definition of the attribute can reference relationships and 
> attributes as shown below. If you just want to create a single ad hoc 
> attribute you may use the ERXQueryEOAttribute class.
> 
>   // Using a single query against the order entity to count the number of
>   // orders and line items that match an order qualifier.
>   
>   ERXQueryAttributes attributes = ERXQueryAttributes.create(orderEn

Re: ERXQuery Preview

2017-03-19 Thread Chuck Hill
Hi Ricardo,

You need to create a branch (push from your local) in your GitHub fork of 
Wonder for each set of changes in GitHub (aka a Feature Branch), then make a 
pull request from that branch to Wonder.  Otherwise all of your changes get 
inter-mixed.

Chuck


From: Ricardo Parada <rpar...@mac.com>
Date: Saturday, March 18, 2017 at 11:22 PM
To: "webobjects-dev@lists.apple.com" <webobjects-dev@lists.apple.com>
Cc: Markus Ruggiero <mailingli...@kataputt.com>, Paul Hoadley 
<pa...@logicsquad.net>, "koa...@icloud.com" <koa...@icloud.com>, 
"g...@knuckleheads.net" <g...@knuckleheads.net>, Chuck Hill 
<ch...@gevityinc.com>, "aa...@chatnbike.com" <aa...@chatnbike.com>
Subject: Re: ERXQuery Preview

Hi all,

As promised, I have committed ERXQuery to my Wonder clone on GitHub, i.e. 
rparada/wonder.  I just need help creating the pull request.  :-)

It turns out that I created first a pull request for ERXExtensions.java 
unrelated to ERXQuery.  Now when I tried to create the pull request for 
ERXQuery it just seems to show the previous pull request.  So I’m not sure what 
is going on.  I don’t have much experience with GitHub.

Anyways, the ERXQuery is an additive change to Wonder and consists of only 
three files: ERXQuery.java, ERXQueryAttributes and ERXQueryEOAttribute.  It’s 
the last two commits in rparada/wonder.

I took the time to polish the API a bit more.  I think the API came out nicer 
than what I had the first time around.  Specially the single variadic select() 
method that allows you to specify EOAttributes, Strings, ERXKeys, or any 
Iterable containing these. Same for groupBy().  And the a similar technique 
with the orderBy() which can take EOSortOrderings or any Iterable 
(ERXSortOrderings, NSArray, List, Collection).

The documentation is more extensive now.  I have included here a copy of the 
ERXQuery class from the javadoc tab in my Eclipse.

I have tested with ORACLE which is the easiest for me to test.  It would be 
great to hear others using this with other databases (h2, derby, mssql, mysql, 
frontbase, etc.)


ERXQuery.java
Overview
This class has a fluent API that mimics a select statement:

  NSArray<NSDictionary<String,Object>> records =

  ERXQuery.create()

  .select (keys)

  .from (entity)

  .where (qualifier)

  .groupBy (groupings)

  .having (havingQualifier)

  .orderBy (sortings)

  .fetch();


It allows you to use EOF/Wonder higher-level constructs (qualifiers, 
attributes, orderings, key paths, ERXKeys, etc.) to create a query that looks 
like this:

  SELECT ...

  FROM ...

  WHERE ...

  GROUP BY ...

  HAVING ...

  ORDER BY ...



Specifying the Attributes to Fetch
The select() method is very flexible and powerful. It accepts a variable number 
of objects of different types that specify the attributes to fetch. These 
objects can be EOAttributes, ERXKeys, Strings. You may also specify NSArray or 
List objects containing any combination of these (EOAttributes, ERXKeys, 
Strings).
The ERXKeys and String objects correspond to keys and key paths to the 
attributes to fetch, i.e. "customer.name". The keys and key paths can also be 
relationships to objects, i.e. "customer" which translate into a fetch of 
foreign keys used to build object faults and return them in the results.
You may call the select() method multiple times to keep adding to the list of 
attributes to fetch.
Using Ad Hoc Attributes
It is very common to aggregate attributes in these queries. For this purpose, 
you may want to create what ERXQuery refers to as ad hoc attributes. These 
attributes have a definition but are not physically attached to the entity. You 
can use the ERXQueryAttributes class to easily create multiple ad hoc 
attributes. The definition of the attribute can reference relationships and 
attributes as shown below. If you just want to create a single ad hoc attribute 
you may use the ERXQueryEOAttribute class.

  // Using a single query against the order entity to count the number of

  // orders and line items that match an order qualifier.



  ERXQueryAttributes attributes = ERXQueryAttributes.create(orderEntity)

  .add("itemCount", "COUNT(DISTINCT lineItems.lineItemID)", "intNumber")

  .add("orderCount", "COUNT(DISTINCT orderID)", "intNumber");



  ERXQuery query =

  ERXQuery.create()

  .select (attributes)

  .from (orderEntity)

  .where (qualifier);



  // Fetch into a dictionary

  NSDictionary<String,Object> row = query.fetch().lastObject();



  int orderCount = ((Number) row.objectForKey("orderCount")).intValue();

  int itemCount = ((Number) row.objectForKey("itemCount")).intValue();



Fetching Results into a Custom Class
It is useful to fetch results into objects of 

Re: ERXQuery Preview

2017-03-14 Thread Markus Ruggiero
Great thing, looks very useful.

> On 11.03.2017, at 23:41, Ricardo Parada  wrote:
> 
> 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/mailinglists%40kataputt.com
> 
> This email sent to mailingli...@kataputt.com



Markus Ruggiero
mailingli...@kataputt.com
Check out the new book about Project Wonder and WebObjects on 
http://learningthewonders.com/







 ___
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 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 <ch...@gevityinc.com> wrote:
> 
> That looks like a very cool, useful contribution!
>  
> Chuck
>  
> From: <webobjects-dev-bounces+chill=gevityinc@lists.apple.com> on behalf 
> of Ricardo Parada <rpar...@mac.com>
> Date: Saturday, March 11, 2017 at 2:41 PM
> To: "webobjects-dev@lists.apple.com WebObjects" 
> <webobjects-dev@lists.apple.com>
> 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<NSDictionary<String,Object>> 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<String,Object> 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


Re: ERXQuery Preview

2017-03-11 Thread Chuck Hill
That looks like a very cool, useful contribution!

Chuck

From: <webobjects-dev-bounces+chill=gevityinc@lists.apple.com> on behalf of 
Ricardo Parada <rpar...@mac.com>
Date: Saturday, March 11, 2017 at 2:41 PM
To: "webobjects-dev@lists.apple.com WebObjects" <webobjects-dev@lists.apple.com>
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<NSDictionary<String,Object>> 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<String,Object> 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/archive%40mail-archive.com

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


ERXQuery Preview

2017-03-11 Thread Ricardo Parada
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/archive%40mail-archive.com

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