summaryrefslogtreecommitdiff
path: root/src/main/java/com/amazon/carbonado/repo/jdbc
diff options
context:
space:
mode:
authorBrian S. O'Neill <bronee@gmail.com>2007-10-14 05:44:35 +0000
committerBrian S. O'Neill <bronee@gmail.com>2007-10-14 05:44:35 +0000
commit1e81bfc705cafe88b804a8a6b1b8616c8773d280 (patch)
tree01266dc8995a350f6681997173205c59857f6abb /src/main/java/com/amazon/carbonado/repo/jdbc
parenta2b87f48775ca6687de0eb4af4b846bd1f0cdebf (diff)
Support ordering by derived properties.
Diffstat (limited to 'src/main/java/com/amazon/carbonado/repo/jdbc')
-rw-r--r--src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java62
1 files changed, 45 insertions, 17 deletions
diff --git a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
index c0f23a2..a841d3a 100644
--- a/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
+++ b/src/main/java/com/amazon/carbonado/repo/jdbc/JDBCStorage.java
@@ -63,6 +63,7 @@ import com.amazon.carbonado.qe.QueryExecutor;
import com.amazon.carbonado.qe.QueryExecutorCache;
import com.amazon.carbonado.qe.QueryExecutorFactory;
import com.amazon.carbonado.qe.QueryFactory;
+import com.amazon.carbonado.qe.SortedQueryExecutor;
import com.amazon.carbonado.qe.StandardQuery;
import com.amazon.carbonado.qe.StandardQueryFactory;
import com.amazon.carbonado.sequence.SequenceValueProducer;
@@ -395,29 +396,54 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S>
}
}
- // Append order-by clause.
- if (ordering != null && ordering.size() != 0) {
- selectBuilder.append(" ORDER BY ");
+ // Append order-by clause. Remainder ordering is required if a derived
+ // property is used.
+
+ OrderingList<S> sqlOrdering = ordering;
+ OrderingList<S> remainderOrdering = null;
+
+ if (ordering != null && ordering.size() > 0) {
ordinal = 0;
for (OrderedProperty<S> orderedProperty : ordering) {
- if (ordinal > 0) {
- selectBuilder.append(',');
- }
- selectBuilder.appendColumn(alias == null ? null : jn,
- orderedProperty.getChainedProperty());
- if (orderedProperty.getDirection() == Direction.DESCENDING) {
- selectBuilder.append(" DESC");
+ if (orderedProperty.getChainedProperty().isDerived()) {
+ sqlOrdering = ordering.subList(0, ordinal);
+ remainderOrdering = ordering.subList(ordinal, ordering.size());
+ break;
}
ordinal++;
}
+
+ if (sqlOrdering != null && sqlOrdering.size() > 0) {
+ selectBuilder.append(" ORDER BY ");
+ ordinal = 0;
+ for (OrderedProperty<S> orderedProperty : sqlOrdering) {
+ if (ordinal > 0) {
+ selectBuilder.append(',');
+ }
+ selectBuilder.appendColumn(alias == null ? null : jn,
+ orderedProperty.getChainedProperty());
+ if (orderedProperty.getDirection() == Direction.DESCENDING) {
+ selectBuilder.append(" DESC");
+ }
+ ordinal++;
+ }
+ }
+ }
+
+ QueryExecutor<S> executor = new Executor(filter,
+ sqlOrdering,
+ selectBuilder.build(),
+ fromWhereBuilder.build(),
+ propertyFilters,
+ propertyFilterNullable);
+
+ if (remainderOrdering != null && remainderOrdering.size() > 0) {
+ // FIXME: use MergeSortBuffer
+ executor = new SortedQueryExecutor<S>
+ (null, executor, sqlOrdering, remainderOrdering);
}
- return new Executor(filter,
- ordering,
- selectBuilder.build(),
- fromWhereBuilder.build(),
- propertyFilters,
- propertyFilterNullable);
+ return executor;
}
}
@@ -940,7 +966,9 @@ class JDBCStorage<S extends Storable> extends StandardQueryFactory<S>
if (ordering != null) {
for (OrderedProperty<?> orderedProperty : ordering) {
ChainedProperty<?> chained = orderedProperty.getChainedProperty();
- mRootJoinNode.addJoin(mRepository, chained, mAliasGenerator);
+ if (!chained.isDerived()) {
+ mRootJoinNode.addJoin(mRepository, chained, mAliasGenerator);
+ }
}
}
} catch (RepositoryException e) {