-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
261 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
39 changes: 39 additions & 0 deletions
39
src/main/java/com/jmethods/catatumbo/DefaultQueryResponseMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
/* | ||
* Copyright 2019 Sai Pullabhotla. | ||
* | ||
* 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 com.jmethods.catatumbo; | ||
|
||
/** | ||
* Default implementation of {@link QueryResponseMetadata} interface. | ||
* | ||
* @author Matthew Tso | ||
*/ | ||
public class DefaultQueryResponseMetadata implements QueryResponseMetadata { | ||
|
||
/** | ||
* The query state metadata value. | ||
*/ | ||
private QueryResponseMetadata.QueryState queryState; | ||
|
||
public DefaultQueryResponseMetadata(QueryResponseMetadata.QueryState queryState) { | ||
this.queryState = queryState; | ||
} | ||
|
||
public QueryResponseMetadata.QueryState getQueryState() { | ||
return queryState; | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
99 changes: 99 additions & 0 deletions
99
src/main/java/com/jmethods/catatumbo/QueryResponseMetadata.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2019 Sai Pullabhotla. | ||
* | ||
* 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 com.jmethods.catatumbo; | ||
|
||
import com.google.datastore.v1.QueryResultBatch; | ||
|
||
/** | ||
* Contains metadata on the query execution result within the context of a {@link QueryResponse}. | ||
* | ||
* @author Matthew Tso | ||
*/ | ||
public interface QueryResponseMetadata { | ||
|
||
/** | ||
* Returns the query execution's query state. | ||
* | ||
* @return query state | ||
*/ | ||
QueryState getQueryState(); | ||
|
||
/** | ||
* The result state value returned in a query execution. | ||
* | ||
* @author Matthew Tso | ||
*/ | ||
enum QueryState { | ||
/** | ||
* Possibly unspecified enum value. | ||
*/ | ||
MORE_RESULTS_TYPE_UNSPECIFIED, | ||
|
||
/** | ||
* Query execution is not finished. | ||
*/ | ||
NOT_FINISHED, | ||
|
||
/** | ||
* There *may* be more results after the specified limit (possibly a false positive). | ||
*/ | ||
MORE_RESULTS_AFTER_LIMIT, | ||
|
||
/** | ||
* There *may* be more results after the specified end cursor (possibly a false positive). | ||
*/ | ||
MORE_RESULTS_AFTER_CURSOR, | ||
|
||
/** | ||
* There are no more results left to query for. | ||
*/ | ||
NO_MORE_RESULTS, | ||
|
||
/** | ||
* Unrecognized state. | ||
*/ | ||
UNRECOGNIZED; | ||
|
||
/** | ||
* Initialize a QueryState from a Datastore QueryResultBatch.MoreResultsType enum value. | ||
* | ||
* @param moreResultsType original enum value. | ||
* @return query state enum | ||
*/ | ||
public static QueryState forMoreResultsType(QueryResultBatch.MoreResultsType moreResultsType) { | ||
if (null == moreResultsType) { | ||
return null; | ||
} | ||
switch (moreResultsType) { | ||
case MORE_RESULTS_TYPE_UNSPECIFIED: | ||
return MORE_RESULTS_TYPE_UNSPECIFIED; | ||
case NOT_FINISHED: | ||
return NOT_FINISHED; | ||
case MORE_RESULTS_AFTER_LIMIT: | ||
return MORE_RESULTS_AFTER_LIMIT; | ||
case MORE_RESULTS_AFTER_CURSOR: | ||
return MORE_RESULTS_AFTER_CURSOR; | ||
case NO_MORE_RESULTS: | ||
return NO_MORE_RESULTS; | ||
case UNRECOGNIZED: | ||
return UNRECOGNIZED; | ||
default: | ||
throw new IllegalStateException("null value should have been caught earlier."); | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
81 changes: 81 additions & 0 deletions
81
src/test/java/com/jmethods/catatumbo/QueryResponseMetadataTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
/* | ||
* Copyright 2019 Sai Pullabhotla, Matthew Tso. | ||
* | ||
* 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 com.jmethods.catatumbo; | ||
|
||
import java.util.Arrays; | ||
|
||
import com.google.datastore.v1.QueryResultBatch; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.junit.runners.Parameterized; | ||
|
||
import static junit.framework.TestCase.assertEquals; | ||
|
||
/** | ||
* @author Matthew Tso | ||
*/ | ||
@RunWith(Parameterized.class) | ||
public class QueryResponseMetadataTest { | ||
private final QueryResultBatch.MoreResultsType input; | ||
private final QueryResponseMetadata.QueryState expected; | ||
|
||
public QueryResponseMetadataTest(QueryResultBatch.MoreResultsType input, | ||
QueryResponseMetadata.QueryState expected) { | ||
this.input = input; | ||
this.expected = expected; | ||
} | ||
|
||
@Parameterized.Parameters | ||
public static Iterable<Object[]> testCases() { | ||
return Arrays.asList(new Object[][] { | ||
{ | ||
QueryResultBatch.MoreResultsType.MORE_RESULTS_TYPE_UNSPECIFIED, | ||
QueryResponseMetadata.QueryState.MORE_RESULTS_TYPE_UNSPECIFIED | ||
}, | ||
{ | ||
QueryResultBatch.MoreResultsType.NOT_FINISHED, | ||
QueryResponseMetadata.QueryState.NOT_FINISHED, | ||
}, | ||
{ | ||
QueryResultBatch.MoreResultsType.MORE_RESULTS_AFTER_LIMIT, | ||
QueryResponseMetadata.QueryState.MORE_RESULTS_AFTER_LIMIT, | ||
}, | ||
{ | ||
QueryResultBatch.MoreResultsType.MORE_RESULTS_AFTER_CURSOR, | ||
QueryResponseMetadata.QueryState.MORE_RESULTS_AFTER_CURSOR, | ||
}, | ||
{ | ||
QueryResultBatch.MoreResultsType.NO_MORE_RESULTS, | ||
QueryResponseMetadata.QueryState.NO_MORE_RESULTS, | ||
}, | ||
{ | ||
QueryResultBatch.MoreResultsType.UNRECOGNIZED, | ||
QueryResponseMetadata.QueryState.UNRECOGNIZED, | ||
}, | ||
{ | ||
null, | ||
null, | ||
}, | ||
}); | ||
} | ||
|
||
@Test | ||
public void testQueryStateMapping() { | ||
QueryResponseMetadata.QueryState actual = QueryResponseMetadata.QueryState.forMoreResultsType(input); | ||
assertEquals(expected, actual); | ||
} | ||
} |