diff options
author | Brian S. O'Neill <bronee@gmail.com> | 2009-07-25 18:09:50 +0000 |
---|---|---|
committer | Brian S. O'Neill <bronee@gmail.com> | 2009-07-25 18:09:50 +0000 |
commit | e85d59d3ec0839617a2c4b394301dc6c3c4e31b4 (patch) | |
tree | bf27c2c323cdcdc72421fcd1aa54f01281d38978 /src | |
parent | 4a25366df4303bebdbd771dcec202e8368fdb61f (diff) |
Query.after and Query.fetchAfter supports subclass parameter.
Diffstat (limited to 'src')
5 files changed, 116 insertions, 12 deletions
diff --git a/src/main/java/com/amazon/carbonado/Query.java b/src/main/java/com/amazon/carbonado/Query.java index 3c3e6e2..f987727 100644 --- a/src/main/java/com/amazon/carbonado/Query.java +++ b/src/main/java/com/amazon/carbonado/Query.java @@ -271,7 +271,7 @@ public interface Query<S extends Storable> { * @throws FetchException if storage layer throws an exception
* @since 1.2
*/
- Query<S> after(S start) throws FetchException;
+ <T extends S> Query<S> after(T start) throws FetchException;
/**
* Fetches results for this query. If any updates or deletes might be
@@ -323,7 +323,7 @@ public interface Query<S extends Storable> { * @see Repository#enterTransaction(IsolationLevel)
* @see #after
*/
- Cursor<S> fetchAfter(S start) throws FetchException;
+ <T extends S> Cursor<S> fetchAfter(T start) throws FetchException;
/**
* Attempts to load exactly one matching object. If the number of matching
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());
diff --git a/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java b/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java index c4c8414..eb18933 100644 --- a/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java +++ b/src/main/java/com/amazon/carbonado/repo/logging/LoggingQuery.java @@ -43,96 +43,119 @@ class LoggingQuery<S extends Storable> implements Query<S> { mQuery = query;
}
+ @Override
public Class<S> getStorableType() {
return mQuery.getStorableType();
}
+ @Override
public Filter<S> getFilter() {
return mQuery.getFilter();
}
+ @Override
public FilterValues<S> getFilterValues() {
return mQuery.getFilterValues();
}
+ @Override
public int getBlankParameterCount() {
return mQuery.getBlankParameterCount();
}
+ @Override
public Query<S> with(int value) {
return newInstance(mQuery.with(value));
}
+ @Override
public Query<S> with(long value) {
return newInstance(mQuery.with(value));
}
+ @Override
public Query<S> with(float value) {
return newInstance(mQuery.with(value));
}
+ @Override
public Query<S> with(double value) {
return newInstance(mQuery.with(value));
}
+ @Override
public Query<S> with(boolean value) {
return newInstance(mQuery.with(value));
}
+ @Override
public Query<S> with(char value) {
return newInstance(mQuery.with(value));
}
+ @Override
public Query<S> with(byte value) {
return newInstance(mQuery.with(value));
}
+ @Override
public Query<S> with(short value) {
return newInstance(mQuery.with(value));
}
+ @Override
public Query<S> with(Object value) {
return newInstance(mQuery.with(value));
}
+ @Override
public Query<S> withValues(Object... objects) {
return newInstance(mQuery.withValues(objects));
}
+ @Override
public Query<S> and(String filter) throws FetchException {
return newInstance(mQuery.and(filter));
}
+ @Override
public Query<S> and(Filter<S> filter) throws FetchException {
return newInstance(mQuery.and(filter));
}
+ @Override
public Query<S> or(String filter) throws FetchException {
return newInstance(mQuery.or(filter));
}
+ @Override
public Query<S> or(Filter<S> filter) throws FetchException {
return newInstance(mQuery.or(filter));
}
+ @Override
public Query<S> not() throws FetchException {
return newInstance(mQuery.not());
}
+ @Override
public Query<S> orderBy(String property) throws FetchException, UnsupportedOperationException {
return newInstance(mQuery.orderBy(property));
}
+ @Override
public Query<S> orderBy(String... strings)
throws FetchException, UnsupportedOperationException
{
return newInstance(mQuery.orderBy(strings));
}
- public Query<S> after(S start) throws FetchException {
+ @Override
+ public <T extends S> Query<S> after(T start) throws FetchException {
return newInstance(mQuery.after(start));
}
+ @Override
public Cursor<S> fetch() throws FetchException {
Log log = mStorage.mLog;
if (log.isEnabled()) {
@@ -141,6 +164,7 @@ class LoggingQuery<S extends Storable> implements Query<S> { return mQuery.fetch();
}
+ @Override
public Cursor<S> fetchSlice(long from, Long to) throws FetchException {
Log log = mStorage.mLog;
if (log.isEnabled()) {
@@ -150,7 +174,8 @@ class LoggingQuery<S extends Storable> implements Query<S> { return mQuery.fetchSlice(from, to);
}
- public Cursor<S> fetchAfter(S start) throws FetchException {
+ @Override
+ public <T extends S> Cursor<S> fetchAfter(T start) throws FetchException {
Log log = mStorage.mLog;
if (log.isEnabled()) {
log.write("Query.fetchAfter(start) on " + this + ", start: " + start);
@@ -158,6 +183,7 @@ class LoggingQuery<S extends Storable> implements Query<S> { return mQuery.fetchAfter(start);
}
+ @Override
public S loadOne() throws FetchException {
Log log = mStorage.mLog;
if (log.isEnabled()) {
@@ -166,6 +192,7 @@ class LoggingQuery<S extends Storable> implements Query<S> { return mQuery.loadOne();
}
+ @Override
public S tryLoadOne() throws FetchException {
Log log = mStorage.mLog;
if (log.isEnabled()) {
@@ -174,6 +201,7 @@ class LoggingQuery<S extends Storable> implements Query<S> { return mQuery.tryLoadOne();
}
+ @Override
public void deleteOne() throws PersistException {
Log log = mStorage.mLog;
if (log.isEnabled()) {
@@ -182,6 +210,7 @@ class LoggingQuery<S extends Storable> implements Query<S> { mQuery.deleteOne();
}
+ @Override
public boolean tryDeleteOne() throws PersistException {
Log log = mStorage.mLog;
if (log.isEnabled()) {
@@ -190,6 +219,7 @@ class LoggingQuery<S extends Storable> implements Query<S> { return mQuery.tryDeleteOne();
}
+ @Override
public void deleteAll() throws PersistException {
Log log = mStorage.mLog;
if (log.isEnabled()) {
@@ -198,6 +228,7 @@ class LoggingQuery<S extends Storable> implements Query<S> { mQuery.deleteAll();
}
+ @Override
public long count() throws FetchException {
Log log = mStorage.mLog;
if (log.isEnabled()) {
@@ -206,6 +237,7 @@ class LoggingQuery<S extends Storable> implements Query<S> { return mQuery.count();
}
+ @Override
public boolean exists() throws FetchException {
Log log = mStorage.mLog;
if (log.isEnabled()) {
@@ -214,34 +246,36 @@ class LoggingQuery<S extends Storable> implements Query<S> { return mQuery.exists();
}
+ @Override
public boolean printNative() {
return mQuery.printNative();
}
+ @Override
public boolean printNative(Appendable app) throws IOException {
return mQuery.printNative(app);
}
+ @Override
public boolean printNative(Appendable app, int indentLevel) throws IOException {
return mQuery.printNative(app, indentLevel);
}
+ @Override
public boolean printPlan() {
return mQuery.printPlan();
}
+ @Override
public boolean printPlan(Appendable app) throws IOException {
return mQuery.printPlan(app);
}
+ @Override
public boolean printPlan(Appendable app, int indentLevel) throws IOException {
return mQuery.printPlan(app, indentLevel);
}
- public void appendTo(Appendable appendable) throws IOException {
- appendable.append(mQuery.toString());
- }
-
@Override
public String toString() {
return mQuery.toString();
|