Skip to content

Commit 5966a8e

Browse files
committed
Upate to latest search api
1 parent ecedfd7 commit 5966a8e

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
<dependency>
4040
<groupId>net.sf.ehcache</groupId>
4141
<artifactId>ehcache-core</artifactId>
42-
<version>2.3.1-SNAPSHOT</version>
42+
<version>2.4.0-SNAPSHOT</version>
4343
</dependency>
4444
<dependency>
4545
<groupId>org.slf4j</groupId>

src/main/java/org/sharrissf/sample/EhcacheSearchPlaying.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@
1313
import net.sf.ehcache.search.Query;
1414
import net.sf.ehcache.search.Result;
1515
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;
1817
import net.sf.ehcache.search.attribute.AttributeExtractor;
1918
import net.sf.ehcache.search.expression.And;
2019

@@ -92,7 +91,6 @@ public void runTests() throws IOException {
9291

9392
Query query = cache.createQuery();
9493
query.includeKeys();
95-
query.includeValues();
9694
query.add(new And(name.like("Ari*"), gender.eq(Gender.MALE))).addOrder(age, Direction.ASCENDING).maxResults(10);
9795

9896
long t = System.currentTimeMillis();
@@ -102,8 +100,8 @@ public void runTests() throws IOException {
102100
System.out.println("Took: " + (System.currentTimeMillis() - t) + " Size: " + results.size());
103101
System.out.println("----Results-----");
104102
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() + "]");
107105
}
108106

109107
read();
@@ -122,25 +120,25 @@ public void runTests() throws IOException {
122120
System.out.println("Find the average age of all the entries in the cache");
123121

124122
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());
127125

128126
read();
129127

130128
System.out.println("Find the average age of all people between 30 and 40");
131129

132130
Query agesBetween = cache.createQuery();
133131
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());
136134

137135
read();
138136

139137
System.out.println("Find the count of people from NJ");
140138

141139
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());
144142
}
145143

146144
private void loadCache() {

0 commit comments

Comments
 (0)