Skip to content

Commit 29e6c4e

Browse files
committed
Fix new @Nullable annotations
This might fix #96 but needs more testing
1 parent 5398361 commit 29e6c4e

File tree

9 files changed

+95
-21
lines changed

9 files changed

+95
-21
lines changed
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
/**
2+
* Copyright © 2018 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.socialsignin.spring.data.dynamodb.query;
17+
18+
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
19+
20+
public abstract class AbstractDynamicQuery<T> extends AbstractQuery<T> {
21+
22+
protected final DynamoDBOperations dynamoDBOperations;
23+
protected final Class<T> clazz;
24+
25+
public AbstractDynamicQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
26+
this.dynamoDBOperations = dynamoDBOperations;
27+
this.clazz = clazz;
28+
}
29+
}

src/main/java/org/socialsignin/spring/data/dynamodb/query/AbstractMultipleEntityQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
* @author Michael Lavelle
2626
* @author Sebastian Just
2727
*/
28-
public abstract class AbstractMultipleEntityQuery<T> extends AbstractQuery<T> implements Query<T> {
28+
public abstract class AbstractMultipleEntityQuery<T> extends AbstractDynamicQuery<T> implements Query<T> {
2929

3030
public AbstractMultipleEntityQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
3131
super(dynamoDBOperations, clazz);

src/main/java/org/socialsignin/spring/data/dynamodb/query/AbstractQuery.java

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,6 @@
1515
*/
1616
package org.socialsignin.spring.data.dynamodb.query;
1717

18-
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
19-
2018
/**
2119
* {@link org.socialsignin.spring.data.dynamodb.mapping.DynamoDBPersistentProperty}
2220
* implementation
@@ -26,11 +24,10 @@
2624
*/
2725
public abstract class AbstractQuery<T> implements Query<T> {
2826

29-
protected final DynamoDBOperations dynamoDBOperations;
30-
protected final Class<T> clazz;
3127
protected boolean scanEnabled = false;
3228
protected boolean scanCountEnabled = false;
3329

30+
@Override
3431
public boolean isScanCountEnabled() {
3532
return scanCountEnabled;
3633
}
@@ -45,13 +42,9 @@ public void setScanEnabled(boolean scanEnabled) {
4542
this.scanEnabled = scanEnabled;
4643
}
4744

45+
@Override
4846
public boolean isScanEnabled() {
4947
return scanEnabled;
5048
}
5149

52-
public AbstractQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
53-
this.dynamoDBOperations = dynamoDBOperations;
54-
this.clazz = clazz;
55-
}
56-
5750
}

src/main/java/org/socialsignin/spring/data/dynamodb/query/AbstractSingleEntityQuery.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
import java.util.Arrays;
2121
import java.util.List;
2222

23-
public abstract class AbstractSingleEntityQuery<T> extends AbstractQuery<T> implements Query<T> {
23+
public abstract class AbstractSingleEntityQuery<T> extends AbstractDynamicQuery<T> implements Query<T> {
2424

2525
public AbstractSingleEntityQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
2626
super(dynamoDBOperations, clazz);

src/main/java/org/socialsignin/spring/data/dynamodb/query/Query.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,5 +38,7 @@ public interface Query<T> {
3838

3939
void setScanEnabled(boolean scanEnabled);
4040
void setScanCountEnabled(boolean scanCountEnabled);
41+
boolean isScanCountEnabled();
42+
boolean isScanEnabled();
4143

4244
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/**
2+
* Copyright © 2018 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.socialsignin.spring.data.dynamodb.query;
17+
18+
import java.util.Collections;
19+
import java.util.List;
20+
21+
public class StaticQuery<T> extends AbstractQuery<T> {
22+
23+
private final T result;
24+
private final List<T> resultList;
25+
26+
public StaticQuery(T result) {
27+
this.result = result;
28+
this.resultList = Collections.singletonList(result);
29+
}
30+
31+
@Override
32+
public List<T> getResultList() {
33+
return resultList;
34+
}
35+
36+
@Override
37+
public T getSingleResult() {
38+
return result;
39+
}
40+
}

src/main/java/org/socialsignin/spring/data/dynamodb/repository/query/DynamoDBCountQueryCreator.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
1919
import org.socialsignin.spring.data.dynamodb.query.Query;
20+
import org.socialsignin.spring.data.dynamodb.query.StaticQuery;
2021
import org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBEntityInformation;
2122
import org.springframework.data.domain.Sort;
2223
import org.springframework.data.repository.query.ParameterAccessor;
2324
import org.springframework.data.repository.query.parser.PartTree;
25+
import org.springframework.lang.Nullable;
2426

2527
import java.util.Optional;
2628

@@ -42,10 +44,12 @@ public DynamoDBCountQueryCreator(PartTree tree, ParameterAccessor parameterAcces
4244
}
4345

4446
@Override
45-
protected Query<Long> complete(DynamoDBQueryCriteria<T, ID> criteria, Sort sort) {
46-
47-
return criteria.buildCountQuery(dynamoDBOperations, pageQuery);
48-
47+
protected Query<Long> complete(@Nullable DynamoDBQueryCriteria<T, ID> criteria, Sort sort) {
48+
if (criteria == null) {
49+
return new StaticQuery<>(1L);
50+
} else {
51+
return criteria.buildCountQuery(dynamoDBOperations, pageQuery);
52+
}
4953
}
5054

5155
}

src/main/java/org/socialsignin/spring/data/dynamodb/repository/query/DynamoDBQueryCreator.java

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,12 @@
1717

1818
import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
1919
import org.socialsignin.spring.data.dynamodb.query.Query;
20+
import org.socialsignin.spring.data.dynamodb.query.StaticQuery;
2021
import org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBEntityInformation;
2122
import org.springframework.data.domain.Sort;
2223
import org.springframework.data.repository.query.ParameterAccessor;
2324
import org.springframework.data.repository.query.parser.PartTree;
25+
import org.springframework.lang.Nullable;
2426

2527
import java.util.Optional;
2628

@@ -33,11 +35,15 @@ public DynamoDBQueryCreator(PartTree tree, ParameterAccessor parameterAccessor,
3335
}
3436

3537
@Override
36-
protected Query<T> complete(DynamoDBQueryCriteria<T, ID> criteria, Sort sort) {
37-
criteria.withSort(sort);
38-
criteria.withProjection(projection);
38+
protected Query<T> complete(@Nullable DynamoDBQueryCriteria<T, ID> criteria, Sort sort) {
39+
if (criteria == null) {
40+
return new StaticQuery<T>(null);
41+
} else {
42+
criteria.withSort(sort);
43+
criteria.withProjection(projection);
3944

40-
return criteria.buildQuery(dynamoDBOperations);
45+
return criteria.buildQuery(dynamoDBOperations);
46+
}
4147
}
4248

4349
}

src/test/java/org/socialsignin/spring/data/dynamodb/query/AbstractQueryTest.java renamed to src/test/java/org/socialsignin/spring/data/dynamodb/query/AbstractDynamicQueryTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
import static org.junit.Assert.assertTrue;
3030

3131
@RunWith(MockitoJUnitRunner.class)
32-
public class AbstractQueryTest {
32+
public class AbstractDynamicQueryTest {
3333

34-
private static class QueryTest<T> extends AbstractQuery<T> {
34+
private static class QueryTest<T> extends AbstractDynamicQuery<T> {
3535
public QueryTest(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
3636
super(dynamoDBOperations, clazz);
3737
}

0 commit comments

Comments
 (0)