13
13
import net .sf .ehcache .search .Query ;
14
14
import net .sf .ehcache .search .Result ;
15
15
import net .sf .ehcache .search .Results ;
16
- import net .sf .ehcache .search .aggregator .Average ;
17
- import net .sf .ehcache .search .aggregator .Count ;
16
+ import net .sf .ehcache .search .aggregator .Aggregators ;
18
17
import net .sf .ehcache .search .attribute .AttributeExtractor ;
19
18
import net .sf .ehcache .search .expression .And ;
20
19
@@ -92,7 +91,6 @@ public void runTests() throws IOException {
92
91
93
92
Query query = cache .createQuery ();
94
93
query .includeKeys ();
95
- query .includeValues ();
96
94
query .add (new And (name .like ("Ari*" ), gender .eq (Gender .MALE ))).addOrder (age , Direction .ASCENDING ).maxResults (10 );
97
95
98
96
long t = System .currentTimeMillis ();
@@ -102,8 +100,8 @@ public void runTests() throws IOException {
102
100
System .out .println ("Took: " + (System .currentTimeMillis () - t ) + " Size: " + results .size ());
103
101
System .out .println ("----Results-----" );
104
102
for (Result result : results .all ()) {
105
- System .out .println ("Got: Key[" + result .getKey () + "] Value class [" + result .getValue (). getClass () + "] Value ["
106
- + result .getValue () + "]" );
103
+ System .out .println ("Got: Key[" + result .getKey () + "] Value class [" + cache . get ( result .getKey ()). getValue () + "] Value ["
104
+ + cache . get ( result . getKey ()) .getValue () + "]" );
107
105
}
108
106
109
107
read ();
@@ -122,25 +120,25 @@ public void runTests() throws IOException {
122
120
System .out .println ("Find the average age of all the entries in the cache" );
123
121
124
122
Query averageAgeQuery = cache .createQuery ();
125
- averageAgeQuery .includeAggregator (new Average (), age );
126
- System .out .println ("Average age: " + averageAgeQuery .execute ().aggregateResult ());
123
+ averageAgeQuery .includeAggregator (Aggregators . average ( age ) );
124
+ System .out .println ("Average age: " + averageAgeQuery .execute ().getAggregatorResults ());
127
125
128
126
read ();
129
127
130
128
System .out .println ("Find the average age of all people between 30 and 40" );
131
129
132
130
Query agesBetween = cache .createQuery ();
133
131
agesBetween .add (age .between (30 , 40 ));
134
- agesBetween .includeAggregator (new Average (), age );
135
- System .out .println ("Average age between 30 and 40: " + agesBetween .execute ().aggregateResult ());
132
+ agesBetween .includeAggregator (Aggregators . average ( age ) );
133
+ System .out .println ("Average age between 30 and 40: " + agesBetween .execute ().getAggregatorResults ());
136
134
137
135
read ();
138
136
139
137
System .out .println ("Find the count of people from NJ" );
140
138
141
139
Query newJerseyCountQuery = cache .createQuery ().add (state .eq ("NJ" ));
142
- newJerseyCountQuery .includeAggregator (new Count (), state );
143
- System .out .println ("Count of people from NJ: " + newJerseyCountQuery .execute ().aggregateResult ());
140
+ newJerseyCountQuery .includeAggregator (Aggregators . count () );
141
+ System .out .println ("Count of people from NJ: " + newJerseyCountQuery .execute ().getAggregatorResults ());
144
142
}
145
143
146
144
private void loadCache () {
0 commit comments