diff options
Diffstat (limited to 'src/main/java/com/amazon/carbonado/qe')
3 files changed, 74 insertions, 4 deletions
diff --git a/src/main/java/com/amazon/carbonado/qe/AbstractQuery.java b/src/main/java/com/amazon/carbonado/qe/AbstractQuery.java index bd27d9a..21c7e3f 100644 --- a/src/main/java/com/amazon/carbonado/qe/AbstractQuery.java +++ b/src/main/java/com/amazon/carbonado/qe/AbstractQuery.java @@ -45,18 +45,22 @@ public abstract class AbstractQuery<S extends Storable> implements Query<S>, App protected AbstractQuery() {
}
+ @Override
public Query<S> and(String filter) throws FetchException {
return and(Filter.filterFor(getStorableType(), filter));
}
+ @Override
public Query<S> or(String filter) throws FetchException {
return or(Filter.filterFor(getStorableType(), filter));
}
- public Cursor<S> fetchAfter(S start) throws FetchException {
+ @Override
+ public <T extends S> Cursor<S> fetchAfter(T start) throws FetchException {
return after(start).fetch();
}
+ @Override
public S loadOne() throws FetchException {
S obj = tryLoadOne();
if (obj == null) {
@@ -65,6 +69,7 @@ public abstract class AbstractQuery<S extends Storable> implements Query<S>, App return obj;
}
+ @Override
public S tryLoadOne() throws FetchException {
Cursor<S> cursor = fetch();
try {
@@ -82,12 +87,14 @@ public abstract class AbstractQuery<S extends Storable> implements Query<S>, App }
}
+ @Override
public void deleteOne() throws PersistException {
if (!tryDeleteOne()) {
throw new PersistNoneException(toString());
}
}
+ @Override
public boolean printNative() {
try {
return printNative(System.out);
@@ -97,10 +104,12 @@ public abstract class AbstractQuery<S extends Storable> implements Query<S>, App }
}
+ @Override
public boolean printNative(Appendable app) throws IOException {
return printNative(app, 0);
}
+ @Override
public boolean printPlan() {
try {
return printPlan(System.out);
@@ -110,6 +119,7 @@ public abstract class AbstractQuery<S extends Storable> implements Query<S>, App }
}
+ @Override
public boolean printPlan(Appendable app) throws IOException {
return printPlan(app, 0);
}
diff --git a/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java b/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java index e9431f3..873b8a7 100644 --- a/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java +++ b/src/main/java/com/amazon/carbonado/qe/EmptyQuery.java @@ -81,6 +81,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { mOrdering = OrderingList.emptyList();
}
+ @Override
public Class<S> getStorableType() {
return mFactory.getStorableType();
}
@@ -88,6 +89,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always returns a {@link com.amazon.carbonado.filter.ClosedFilter ClosedFilter}.
*/
+ @Override
public Filter<S> getFilter() {
return Filter.getClosedFilter(getStorableType());
}
@@ -95,6 +97,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always returns null.
*/
+ @Override
public FilterValues<S> getFilterValues() {
return null;
}
@@ -102,6 +105,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always returns zero.
*/
+ @Override
public int getBlankParameterCount() {
return 0;
}
@@ -109,6 +113,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always throws an IllegalStateException.
*/
+ @Override
public Query<S> with(int value) {
throw error();
}
@@ -116,6 +121,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always throws an IllegalStateException.
*/
+ @Override
public Query<S> with(long value) {
throw error();
}
@@ -123,6 +129,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always throws an IllegalStateException.
*/
+ @Override
public Query<S> with(float value) {
throw error();
}
@@ -130,6 +137,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always throws an IllegalStateException.
*/
+ @Override
public Query<S> with(double value) {
throw error();
}
@@ -137,6 +145,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always throws an IllegalStateException.
*/
+ @Override
public Query<S> with(boolean value) {
throw error();
}
@@ -144,6 +153,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always throws an IllegalStateException.
*/
+ @Override
public Query<S> with(char value) {
throw error();
}
@@ -151,6 +161,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always throws an IllegalStateException.
*/
+ @Override
public Query<S> with(byte value) {
throw error();
}
@@ -158,6 +169,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always throws an IllegalStateException.
*/
+ @Override
public Query<S> with(short value) {
throw error();
}
@@ -165,6 +177,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always throws an IllegalStateException.
*/
+ @Override
public Query<S> with(Object value) {
throw error();
}
@@ -172,6 +185,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Throws an IllegalStateException unless no values passed in.
*/
+ @Override
public Query<S> withValues(Object... values) {
if (values == null || values.length == 0) {
return this;
@@ -182,10 +196,12 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always throws an IllegalStateException.
*/
+ @Override
public Query<S> and(Filter<S> filter) {
throw new IllegalStateException("Query is already guaranteed to fetch nothing");
}
+ @Override
public Query<S> or(Filter<S> filter) throws FetchException {
return mFactory.query(filter, null, mOrdering, null);
}
@@ -193,25 +209,30 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Returns a query that fetches everything, possibly in a specified order.
*/
+ @Override
public Query<S> not() throws FetchException {
return mFactory.query(null, null, mOrdering, null);
}
+ @Override
public Query<S> orderBy(String property) throws FetchException {
return new EmptyQuery<S>(mFactory, property);
}
+ @Override
public Query<S> orderBy(String... properties) throws FetchException {
return new EmptyQuery<S>(mFactory, properties);
}
- public Query<S> after(S start) {
+ @Override
+ public <T extends S> Query<S> after(T start) {
return this;
}
/**
* Always returns an {@link EmptyCursor}.
*/
+ @Override
public Cursor<S> fetch() {
return EmptyCursor.the();
}
@@ -219,6 +240,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always returns an {@link EmptyCursor}.
*/
+ @Override
public Cursor<S> fetchSlice(long from, Long to) {
checkSliceArguments(from, to);
return EmptyCursor.the();
@@ -235,6 +257,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always returns false.
*/
+ @Override
public boolean tryDeleteOne() {
return false;
}
@@ -242,12 +265,14 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Does nothing.
*/
+ @Override
public void deleteAll() {
}
/**
* Always returns zero.
*/
+ @Override
public long count() {
return 0;
}
@@ -255,10 +280,12 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always returns false.
*/
+ @Override
public boolean exists() {
return false;
}
+ @Override
public void appendTo(Appendable app) throws IOException {
app.append("Query {type=");
app.append(getStorableType().getName());
@@ -282,6 +309,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always returns false.
*/
+ @Override
public boolean printNative(Appendable app, int indentLevel) {
return false;
}
@@ -289,6 +317,7 @@ public final class EmptyQuery<S extends Storable> extends AbstractQuery<S> { /**
* Always returns false.
*/
+ @Override
public boolean printPlan(Appendable app, int indentLevel) {
return false;
}
diff --git a/src/main/java/com/amazon/carbonado/qe/StandardQuery.java b/src/main/java/com/amazon/carbonado/qe/StandardQuery.java index 736f31f..08cd27a 100644 --- a/src/main/java/com/amazon/carbonado/qe/StandardQuery.java +++ b/src/main/java/com/amazon/carbonado/qe/StandardQuery.java @@ -90,10 +90,12 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> mHints = hints;
}
+ @Override
public Class<S> getStorableType() {
return queryFactory().getStorableType();
}
+ @Override
public Filter<S> getFilter() {
Filter<S> filter = mFilter;
if (filter == null) {
@@ -102,50 +104,62 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> return filter;
}
+ @Override
public FilterValues<S> getFilterValues() {
return mValues;
}
+ @Override
public int getBlankParameterCount() {
return mValues == null ? 0 : mValues.getBlankParameterCount();
}
+ @Override
public Query<S> with(int value) {
return newInstance(requireValues().with(value));
}
+ @Override
public Query<S> with(long value) {
return newInstance(requireValues().with(value));
}
+ @Override
public Query<S> with(float value) {
return newInstance(requireValues().with(value));
}
+ @Override
public Query<S> with(double value) {
return newInstance(requireValues().with(value));
}
+ @Override
public Query<S> with(boolean value) {
return newInstance(requireValues().with(value));
}
+ @Override
public Query<S> with(char value) {
return newInstance(requireValues().with(value));
}
+ @Override
public Query<S> with(byte value) {
return newInstance(requireValues().with(value));
}
+ @Override
public Query<S> with(short value) {
return newInstance(requireValues().with(value));
}
+ @Override
public Query<S> with(Object value) {
return newInstance(requireValues().with(value));
}
+ @Override
public Query<S> withValues(Object... values) {
if (values == null || values.length == 0) {
return this;
@@ -153,6 +167,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> return newInstance(requireValues().withValues(values));
}
+ @Override
public Query<S> and(Filter<S> filter) throws FetchException {
Filter<S> newFilter;
FilterValues<S> newValues;
@@ -172,6 +187,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> return createQuery(newFilter, newValues, mOrdering, mHints);
}
+ @Override
public Query<S> or(Filter<S> filter) throws FetchException {
if (mFilter == null) {
throw new IllegalStateException("Query is already guaranteed to fetch everything");
@@ -187,6 +203,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> return createQuery(newFilter, newValues, mOrdering, mHints);
}
+ @Override
public Query<S> not() throws FetchException {
if (mFilter == null) {
return new EmptyQuery<S>(queryFactory(), mOrdering);
@@ -199,17 +216,20 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> return createQuery(newFilter, newValues, mOrdering, mHints);
}
+ @Override
public Query<S> orderBy(String property) throws FetchException {
return createQuery(mFilter, mValues,
OrderingList.get(getStorableType(), property), mHints);
}
+ @Override
public Query<S> orderBy(String... properties) throws FetchException {
return createQuery(mFilter, mValues,
OrderingList.get(getStorableType(), properties), mHints);
}
- public Query<S> after(S start) throws FetchException {
+ @Override
+ public <T extends S> Query<S> after(T start) throws FetchException {
OrderingList<S> orderings;
if (start == null || (orderings = mOrdering).size() == 0) {
return this;
@@ -217,7 +237,9 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> return buildAfter(start, orderings);
}
- private Query<S> buildAfter(S start, OrderingList<S> orderings) throws FetchException {
+ private <T extends S> Query<S> buildAfter(T start, OrderingList<S> orderings)
+ throws FetchException
+ {
Class<S> storableType = getStorableType();
Filter<S> orderFilter = Filter.getClosedFilter(storableType);
Filter<S> openFilter = Filter.getOpenFilter(storableType);
@@ -256,6 +278,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> return query;
}
+ @Override
public Cursor<S> fetch() throws FetchException {
try {
return executor().fetch(mValues);
@@ -264,6 +287,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> }
}
+ @Override
public Cursor<S> fetchSlice(long from, Long to) throws FetchException {
if (!checkSliceArguments(from, to)) {
return fetch();
@@ -277,6 +301,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> }
}
+ @Override
public boolean tryDeleteOne() throws PersistException {
Transaction txn = enterTransaction(IsolationLevel.READ_COMMITTED);
try {
@@ -308,6 +333,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> }
}
+ @Override
public void deleteAll() throws PersistException {
Transaction txn = enterTransaction(IsolationLevel.READ_COMMITTED);
try {
@@ -331,6 +357,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> }
}
+ @Override
public long count() throws FetchException {
try {
return executor().count(mValues);
@@ -339,6 +366,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> }
}
+ @Override
public boolean exists() throws FetchException {
Cursor<S> cursor = fetchSlice(0L, 1L);
try {
@@ -348,6 +376,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> }
}
+ @Override
public boolean printNative(Appendable app, int indentLevel) throws IOException {
try {
return executor().printNative(app, indentLevel, mValues);
@@ -356,6 +385,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> }
}
+ @Override
public boolean printPlan(Appendable app, int indentLevel) throws IOException {
try {
return executor().printPlan(app, indentLevel, mValues);
@@ -394,6 +424,7 @@ public abstract class StandardQuery<S extends Storable> extends AbstractQuery<S> return false;
}
+ @Override
public void appendTo(Appendable app) throws IOException {
app.append("Query {type=");
app.append(getStorableType().getName());
|