Skip to content

Commit

Permalink
Fix new @Nullable annotations
Browse files Browse the repository at this point in the history
This might fix #96 but needs more testing
  • Loading branch information
derjust committed Aug 11, 2018
1 parent 5398361 commit 29e6c4e
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 21 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/**
* Copyright © 2018 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.socialsignin.spring.data.dynamodb.query;

import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;

public abstract class AbstractDynamicQuery<T> extends AbstractQuery<T> {

protected final DynamoDBOperations dynamoDBOperations;
protected final Class<T> clazz;

public AbstractDynamicQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
this.dynamoDBOperations = dynamoDBOperations;
this.clazz = clazz;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
* @author Michael Lavelle
* @author Sebastian Just
*/
public abstract class AbstractMultipleEntityQuery<T> extends AbstractQuery<T> implements Query<T> {
public abstract class AbstractMultipleEntityQuery<T> extends AbstractDynamicQuery<T> implements Query<T> {

public AbstractMultipleEntityQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
super(dynamoDBOperations, clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,6 @@
*/
package org.socialsignin.spring.data.dynamodb.query;

import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;

/**
* {@link org.socialsignin.spring.data.dynamodb.mapping.DynamoDBPersistentProperty}
* implementation
Expand All @@ -26,11 +24,10 @@
*/
public abstract class AbstractQuery<T> implements Query<T> {

protected final DynamoDBOperations dynamoDBOperations;
protected final Class<T> clazz;
protected boolean scanEnabled = false;
protected boolean scanCountEnabled = false;

@Override
public boolean isScanCountEnabled() {
return scanCountEnabled;
}
Expand All @@ -45,13 +42,9 @@ public void setScanEnabled(boolean scanEnabled) {
this.scanEnabled = scanEnabled;
}

@Override
public boolean isScanEnabled() {
return scanEnabled;
}

public AbstractQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
this.dynamoDBOperations = dynamoDBOperations;
this.clazz = clazz;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
import java.util.Arrays;
import java.util.List;

public abstract class AbstractSingleEntityQuery<T> extends AbstractQuery<T> implements Query<T> {
public abstract class AbstractSingleEntityQuery<T> extends AbstractDynamicQuery<T> implements Query<T> {

public AbstractSingleEntityQuery(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
super(dynamoDBOperations, clazz);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,5 +38,7 @@ public interface Query<T> {

void setScanEnabled(boolean scanEnabled);
void setScanCountEnabled(boolean scanCountEnabled);
boolean isScanCountEnabled();
boolean isScanEnabled();

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/**
* Copyright © 2018 spring-data-dynamodb (https://github.com/derjust/spring-data-dynamodb)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.socialsignin.spring.data.dynamodb.query;

import java.util.Collections;
import java.util.List;

public class StaticQuery<T> extends AbstractQuery<T> {

private final T result;
private final List<T> resultList;

public StaticQuery(T result) {
this.result = result;
this.resultList = Collections.singletonList(result);
}

@Override
public List<T> getResultList() {
return resultList;
}

@Override
public T getSingleResult() {
return result;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
import org.socialsignin.spring.data.dynamodb.query.Query;
import org.socialsignin.spring.data.dynamodb.query.StaticQuery;
import org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBEntityInformation;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.parser.PartTree;
import org.springframework.lang.Nullable;

import java.util.Optional;

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

@Override
protected Query<Long> complete(DynamoDBQueryCriteria<T, ID> criteria, Sort sort) {

return criteria.buildCountQuery(dynamoDBOperations, pageQuery);

protected Query<Long> complete(@Nullable DynamoDBQueryCriteria<T, ID> criteria, Sort sort) {
if (criteria == null) {
return new StaticQuery<>(1L);
} else {
return criteria.buildCountQuery(dynamoDBOperations, pageQuery);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@

import org.socialsignin.spring.data.dynamodb.core.DynamoDBOperations;
import org.socialsignin.spring.data.dynamodb.query.Query;
import org.socialsignin.spring.data.dynamodb.query.StaticQuery;
import org.socialsignin.spring.data.dynamodb.repository.support.DynamoDBEntityInformation;
import org.springframework.data.domain.Sort;
import org.springframework.data.repository.query.ParameterAccessor;
import org.springframework.data.repository.query.parser.PartTree;
import org.springframework.lang.Nullable;

import java.util.Optional;

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

@Override
protected Query<T> complete(DynamoDBQueryCriteria<T, ID> criteria, Sort sort) {
criteria.withSort(sort);
criteria.withProjection(projection);
protected Query<T> complete(@Nullable DynamoDBQueryCriteria<T, ID> criteria, Sort sort) {
if (criteria == null) {
return new StaticQuery<T>(null);
} else {
criteria.withSort(sort);
criteria.withProjection(projection);

return criteria.buildQuery(dynamoDBOperations);
return criteria.buildQuery(dynamoDBOperations);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,9 @@
import static org.junit.Assert.assertTrue;

@RunWith(MockitoJUnitRunner.class)
public class AbstractQueryTest {
public class AbstractDynamicQueryTest {

private static class QueryTest<T> extends AbstractQuery<T> {
private static class QueryTest<T> extends AbstractDynamicQuery<T> {
public QueryTest(DynamoDBOperations dynamoDBOperations, Class<T> clazz) {
super(dynamoDBOperations, clazz);
}
Expand Down

0 comments on commit 29e6c4e

Please sign in to comment.