Skip to content

Commit 6ab9567

Browse files
committed
feature: implemented Streams-based query builder w/ generated metamodel
1 parent eddd868 commit 6ab9567

File tree

152 files changed

+19442
-57
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

152 files changed

+19442
-57
lines changed

demos/roms-documents/pom.xml

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
<maven.compiler.target>11</maven.compiler.target>
2424
<maven.test.source>11</maven.test.source>
2525
<maven.test.target>11</maven.test.target>
26+
<testcontainers.redis.version>1.5.2</testcontainers.redis.version>
27+
<testcontainers.redis.junit.version>1.4.6</testcontainers.redis.junit.version>
2628
</properties>
2729

2830
<dependencies>
@@ -51,6 +53,46 @@
5153
<artifactId>spring-boot-starter-test</artifactId>
5254
<scope>test</scope>
5355
</dependency>
56+
<!-- test dependencies -->
57+
<dependency>
58+
<groupId>org.junit.jupiter</groupId>
59+
<artifactId>junit-jupiter</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.assertj</groupId>
64+
<artifactId>assertj-core</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
<dependency>
68+
<groupId>org.springframework</groupId>
69+
<artifactId>spring-test</artifactId>
70+
<scope>test</scope>
71+
</dependency>
72+
<!-- <dependency>
73+
<groupId>org.springframework.boot</groupId>
74+
<artifactId>spring-boot-starter-test</artifactId>
75+
<version>${spring.version}</version>
76+
<scope>test</scope>
77+
<exclusions>
78+
<exclusion>
79+
<groupId>com.vaadin.external.google</groupId>
80+
<artifactId>android-json</artifactId>
81+
</exclusion>
82+
</exclusions>
83+
</dependency> -->
84+
<dependency>
85+
<groupId>com.redis.testcontainers</groupId>
86+
<artifactId>testcontainers-redis</artifactId>
87+
<version>${testcontainers.redis.version}</version>
88+
<scope>test</scope>
89+
</dependency>
90+
<dependency>
91+
<groupId>com.redis.testcontainers</groupId>
92+
<artifactId>testcontainers-redis-junit-jupiter</artifactId>
93+
<version>${testcontainers.redis.junit.version}</version>
94+
<scope>test</scope>
95+
</dependency>
5496
</dependencies>
5597

5698
<build>

demos/roms-documents/src/test/java/com/redis/om/documents/RomsDocumentsApplicationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.redis.om.documents;
22

33
import org.junit.jupiter.api.Test;
4-
import org.springframework.boot.test.context.SpringBootTest;
54

6-
@SpringBootTest
5+
//@SpringBootTest
76
class RomsDocumentsApplicationTests {
87

98
@Test

demos/roms-hashes/src/test/java/com/redis/om/hashes/RomsHashesApplicationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.redis.om.hashes;
22

33
import org.junit.jupiter.api.Test;
4-
import org.springframework.boot.test.context.SpringBootTest;
54

6-
@SpringBootTest
5+
//@SpringBootTest
76
class RomsHashesApplicationTests {
87

98
@Test

demos/roms-permits/src/test/java/com/redis/om/permits/PermitsApplicationTests.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
package com.redis.om.permits;
22

33
import org.junit.jupiter.api.Test;
4-
import org.springframework.boot.test.context.SpringBootTest;
54

6-
@SpringBootTest
5+
//@SpringBootTest
76
class PermitsApplicationTests {
87

98
@Test

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<modelVersion>4.0.0</modelVersion>
66
<groupId>com.redis.om</groupId>
77
<artifactId>redis-om-spring-parent</artifactId>
8-
<version>0.2.0-SNAPSHOT</version>
8+
<version>0.3.0-SNAPSHOT</version>
99
<name>redis-om-spring-parent</name>
1010
<packaging>pom</packaging>
1111

redis-om-spring/pom.xml

Lines changed: 28 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

3-
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
3+
<project xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
5+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
46
<modelVersion>4.0.0</modelVersion>
57

68
<groupId>com.redis.om</groupId>
79
<artifactId>redis-om-spring</artifactId>
8-
<version>0.2.0-SNAPSHOT</version>
10+
<version>0.3.0-SNAPSHOT</version>
911
<packaging>jar</packaging>
1012

1113
<name>redis-om-spring</name>
@@ -61,6 +63,7 @@
6163
<jredisearch.version>2.2.0</jredisearch.version>
6264
<jredisbloom.version>2.2.0</jredisbloom.version>
6365
<cdi>1.0</cdi>
66+
<auto-service.version>1.0.1</auto-service.version>
6467
<testcontainers.redis.version>1.5.2</testcontainers.redis.version>
6568
<testcontainers.redis.junit.version>1.4.6</testcontainers.redis.junit.version>
6669
</properties>
@@ -154,6 +157,18 @@
154157
<scope>provided</scope>
155158
<optional>true</optional>
156159
</dependency>
160+
<dependency>
161+
<groupId>com.google.auto.service</groupId>
162+
<artifactId>auto-service</artifactId>
163+
<version>${auto-service.version}</version>
164+
<scope>provided</scope>
165+
</dependency>
166+
<dependency>
167+
<groupId>com.squareup</groupId>
168+
<artifactId>javapoet</artifactId>
169+
<version>1.13.0</version>
170+
</dependency>
171+
157172
<!-- test dependencies -->
158173
<dependency>
159174
<groupId>org.junit.jupiter</groupId>
@@ -244,21 +259,21 @@
244259
<artifactId>maven-surefire-plugin</artifactId>
245260
<version>3.0.0-M5</version>
246261
<configuration>
247-
<argLine>
248-
--illegal-access=permit
249-
</argLine>
262+
<argLine>
263+
--illegal-access=permit
264+
</argLine>
250265
</configuration>
251-
</plugin>
252-
<plugin>
266+
</plugin>
267+
<plugin>
253268
<groupId>org.apache.maven.plugins</groupId>
254269
<artifactId>maven-failsafe-plugin</artifactId>
255270
<version>3.0.0-M5</version>
256271
<configuration>
257-
<argLine>
258-
--illegal-access=permit
259-
</argLine>
272+
<argLine>
273+
--illegal-access=permit
274+
</argLine>
260275
</configuration>
261-
</plugin>
276+
</plugin>
262277
</plugins>
263278
</build>
264279
<profiles>
@@ -294,7 +309,8 @@
294309
</executions>
295310
</plugin>
296311

297-
<!--Sign the components - this is required by maven central for releases -->
312+
<!--Sign the components - this is required by maven central for
313+
releases -->
298314
<plugin>
299315
<groupId>org.apache.maven.plugins</groupId>
300316
<artifactId>maven-gpg-plugin</artifactId>

redis-om-spring/src/main/java/com/redis/om/spring/RedisModulesConfiguration.java

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,8 @@
5050
import com.redis.om.spring.ops.json.JSONOperations;
5151
import com.redis.om.spring.ops.pds.BloomOperations;
5252
import com.redis.om.spring.ops.search.SearchOperations;
53+
import com.redis.om.spring.search.stream.EntityStream;
54+
import com.redis.om.spring.search.stream.EntityStreamImpl;
5355

5456
import io.redisearch.FieldName;
5557
import io.redisearch.Schema;
@@ -65,6 +67,7 @@
6567
@EnableConfigurationProperties(RedisProperties.class)
6668
@EnableAspectJAutoProxy
6769
@ComponentScan("com.redis.om.spring.bloom")
70+
@ComponentScan("com.redis.om.spring.metamodel")
6871
public class RedisModulesConfiguration extends CachingConfigurerSupport {
6972

7073
private static final Log logger = LogFactory.getLog(RedisModulesConfiguration.class);
@@ -117,6 +120,11 @@ public CustomRedisKeyValueTemplate getKeyValueTemplate(RedisOperations<?, ?> red
117120
RedisMappingContext mappingContext = new RedisMappingContext();
118121
return new CustomRedisKeyValueTemplate(new RedisEnhancedKeyValueAdapter(redisOps), mappingContext);
119122
}
123+
124+
@Bean(name = "streamingQueryBuilder")
125+
EntityStream streamingQueryBuilder(RedisModulesOperations<?, ?> redisModulesOperations) {
126+
return new EntityStreamImpl(redisModulesOperations);
127+
}
120128

121129
@EventListener(ContextRefreshedEvent.class)
122130
public void ensureIndexesAreCreated(ContextRefreshedEvent cre) {
@@ -170,8 +178,8 @@ private void createIndicesFor(Class<?> cls, ApplicationContext ac) {
170178
String scoreField = null;
171179
try {
172180
Class<?> cl = Class.forName(beanDef.getBeanClassName());
173-
indexName = cl.getSimpleName() + "Idx";
174-
logger.info(String.format("Found @%s annotated class: %s", cls.getSimpleName(), cl.getSimpleName()));
181+
indexName = cl.getName() + "Idx";
182+
logger.info(String.format("Found @%s annotated class: %s", cls.getSimpleName(), cl.getName()));
175183

176184
List<Field> fields = new ArrayList<Field>();
177185

@@ -227,7 +235,7 @@ private List<Field> findIndexFields(java.lang.reflect.Field field, String prefix
227235
List<Field> fields = new ArrayList<Field>();
228236

229237
if (field.isAnnotationPresent(Indexed.class)) {
230-
logger.debug(String.format("FOUND @Indexed annotation on field of type: %s", field.getType()));
238+
logger.info(String.format("FOUND @Indexed annotation on field of type: %s", field.getType()));
231239

232240
Indexed indexed = (Indexed) field.getAnnotation(Indexed.class);
233241

@@ -267,6 +275,7 @@ else if (field.getType() == Point.class) {
267275

268276
// Searchable - behaves like Text indexed
269277
else if (field.isAnnotationPresent(Searchable.class)) {
278+
logger.info(String.format("FOUND @Searchable annotation on field of type: %s", field.getType()));
270279
Searchable searchable = field.getAnnotation(Searchable.class);
271280
fields.add(indexAsTextFieldFor(field, isDocument, prefix, searchable));
272281
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
package com.redis.om.spring.metamodel;
2+
3+
import java.lang.reflect.Field;
4+
5+
import com.redis.om.spring.search.stream.predicates.BetweenPredicate;
6+
import com.redis.om.spring.search.stream.predicates.GreaterThanOrEqualPredicate;
7+
import com.redis.om.spring.search.stream.predicates.GreaterThanPredicate;
8+
import com.redis.om.spring.search.stream.predicates.LessThanOrEqualPredicate;
9+
import com.redis.om.spring.search.stream.predicates.LessThanPredicate;
10+
11+
public class DateFieldOperationInterceptor<E, T> extends FieldOperationInterceptor<E, T> {
12+
13+
public DateFieldOperationInterceptor(Field field, boolean indexed) {
14+
super(field, indexed);
15+
}
16+
17+
public GreaterThanPredicate<? super E,T> after(T value) {
18+
return new GreaterThanPredicate<E,T>(field,value);
19+
}
20+
21+
public GreaterThanOrEqualPredicate<? super E,T> onOrAfter(T value) {
22+
return new GreaterThanOrEqualPredicate<E,T>(field,value);
23+
}
24+
25+
public LessThanPredicate<? super E,T> before(T value) {
26+
return new LessThanPredicate<E,T>(field,value);
27+
}
28+
29+
public LessThanOrEqualPredicate<? super E,T> onOrBefore(T value) {
30+
return new LessThanOrEqualPredicate<E,T>(field,value);
31+
}
32+
33+
public BetweenPredicate<? super E,T> between(T min, T max) {
34+
return new BetweenPredicate<E,T>(field,min,max);
35+
}
36+
37+
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.redis.om.spring.metamodel;
2+
3+
import java.lang.reflect.Field;
4+
import java.util.Comparator;
5+
import java.util.function.Function;
6+
7+
import com.redis.om.spring.search.stream.predicates.EqualPredicate;
8+
import com.redis.om.spring.search.stream.predicates.NotEqualPredicate;
9+
10+
public class FieldOperationInterceptor<E, T> implements Comparator<E>, Function<E,T> {
11+
12+
protected final Field field;
13+
protected final boolean indexed;
14+
15+
public FieldOperationInterceptor(Field field, boolean indexed) {
16+
this.field = field;
17+
this.indexed = indexed;
18+
}
19+
20+
public Field getField() {
21+
return field;
22+
}
23+
24+
public EqualPredicate<? super E,T> eq(T value) {
25+
return new EqualPredicate<E,T>(field,value);
26+
}
27+
28+
public NotEqualPredicate<? super E,T> notEq(T value) {
29+
return new NotEqualPredicate<E,T>(field,value);
30+
}
31+
32+
@Override
33+
public int compare(E o1, E o2) {
34+
// TODO Auto-generated method stub
35+
return 0;
36+
}
37+
38+
@Override
39+
public T apply(E t) {
40+
// TODO Auto-generated method stub
41+
return null;
42+
}
43+
44+
public boolean isIndexed() {
45+
return indexed;
46+
}
47+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
package com.redis.om.spring.metamodel;
2+
3+
import java.lang.reflect.Field;
4+
5+
import org.springframework.data.geo.Distance;
6+
import org.springframework.data.geo.Point;
7+
8+
import com.redis.om.spring.search.stream.predicates.NearPredicate;
9+
10+
public class GeoFieldOperationInterceptor<E, T> extends FieldOperationInterceptor<E, T> {
11+
12+
public GeoFieldOperationInterceptor(Field field, boolean indexed) {
13+
super(field, indexed);
14+
}
15+
16+
public NearPredicate<? super E,T> near(Point point, Distance distance) {
17+
return new NearPredicate<E,T>(field,point,distance);
18+
}
19+
20+
}

0 commit comments

Comments
 (0)