OrderBy is now a list of OrderByItem, instead of String, and support
upper and lower functions. git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@892142 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you 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.ofbiz.sql;
|
||||
|
||||
public final class OrderByItem extends Atom {
|
||||
enum Order { DEFAULT, ASCENDING, DESCENDING };
|
||||
|
||||
private final Order order;
|
||||
private final String functionName;
|
||||
private final String fieldName;
|
||||
|
||||
public OrderByItem(Order order, String functionName, String fieldName) {
|
||||
this.order = order;
|
||||
this.functionName = functionName;
|
||||
this.fieldName = fieldName;
|
||||
}
|
||||
|
||||
public final Order getOrder() {
|
||||
return order;
|
||||
}
|
||||
|
||||
public final String getFunctionName() {
|
||||
return functionName;
|
||||
}
|
||||
|
||||
public final String getFieldName() {
|
||||
return fieldName;
|
||||
}
|
||||
|
||||
public StringBuilder appendTo(StringBuilder sb) {
|
||||
if (functionName != null) sb.append(functionName).append('(');
|
||||
sb.append(fieldName);
|
||||
if (functionName != null) sb.append(')');
|
||||
switch (order) {
|
||||
case ASCENDING:
|
||||
sb.append(" ASC");
|
||||
break;
|
||||
case DESCENDING:
|
||||
sb.append(" DESC");
|
||||
break;
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
@@ -107,6 +107,8 @@ TOKEN: {
|
||||
| <INSERT: "INSERT">
|
||||
| <RELATION: "RELATION">
|
||||
| <EXCLUDE: "EXCLUDE">
|
||||
| <UPPER: "UPPER">
|
||||
| <LOWER: "LOWER">
|
||||
| <TYPE: "TYPE">
|
||||
| <TITLE: "TITLE">
|
||||
| <SET: "SET">
|
||||
@@ -114,6 +116,8 @@ TOKEN: {
|
||||
| <SEMI: ";">
|
||||
| <STAR: "*">
|
||||
| <COMMA: ",">
|
||||
| <PLUS: "+">
|
||||
| <MINUS: "-">
|
||||
| <DESC: "DESC">
|
||||
| <ASC: "ASC">
|
||||
| <EQUALS: "=">
|
||||
@@ -269,7 +273,8 @@ private SQLView View():
|
||||
private SQLSelect Select():
|
||||
{
|
||||
Integer i;
|
||||
List<String> orderBy = null, groupBy = null;
|
||||
List<OrderByItem> orderBy = null;
|
||||
List<String> groupBy = null;
|
||||
Map<String, FieldDef> fieldDefs = FastMap.newInstance();
|
||||
List<FieldAll> fieldAlls = FastList.newInstance();
|
||||
Table table;
|
||||
@@ -644,10 +649,10 @@ private FieldValue FieldValue(String fieldName):
|
||||
}
|
||||
}
|
||||
|
||||
private List<String> OrderByList():
|
||||
private List<OrderByItem> OrderByList():
|
||||
{
|
||||
List<String> orderBy = FastList.newInstance();
|
||||
String obi;
|
||||
List<OrderByItem> orderBy = FastList.newInstance();
|
||||
OrderByItem obi;
|
||||
}
|
||||
{
|
||||
obi=OrderByItem() { orderBy.add(obi); }
|
||||
@@ -655,18 +660,27 @@ private List<String> OrderByList():
|
||||
{ return orderBy; }
|
||||
}
|
||||
|
||||
private String OrderByItem():
|
||||
private OrderByItem OrderByItem():
|
||||
{
|
||||
StringBuilder sb = new StringBuilder();
|
||||
String n;
|
||||
String functionName = null, fieldName = null;
|
||||
boolean descending = false, orderingSet = false;
|
||||
OrderByItem.Order ordering = OrderByItem.Order.DEFAULT;
|
||||
}
|
||||
{
|
||||
n=NamePart() { sb.append(n); }
|
||||
(
|
||||
<DESC> { sb.append(" DESC"); }
|
||||
| <ASC> { sb.append(" ASC"); }
|
||||
<PLUS> { ordering = OrderByItem.Order.ASCENDING; }
|
||||
| <MINUS> { ordering = OrderByItem.Order.DESCENDING; }
|
||||
)?
|
||||
{ return sb.toString(); }
|
||||
(
|
||||
( <UPPER> | <LOWER> ) { functionName = getToken(0).image; }
|
||||
<OPEN_PAREN> fieldName=NamePart() <CLOSE_PAREN>
|
||||
| fieldName=NamePart()
|
||||
)
|
||||
LOOKAHEAD({!orderingSet}) (
|
||||
<DESC> { ordering = OrderByItem.Order.DESCENDING; }
|
||||
| <ASC> { ordering = OrderByItem.Order.ASCENDING; }
|
||||
)?
|
||||
{ return new OrderByItem(ordering, functionName, fieldName); }
|
||||
}
|
||||
|
||||
private Integer Integer():
|
||||
|
||||
@@ -35,10 +35,10 @@ public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSo
|
||||
private final Condition havingCondition;
|
||||
private final int offset;
|
||||
private final int limit;
|
||||
private final List<String> orderBy;
|
||||
private final List<OrderByItem> orderBy;
|
||||
private final List<String> groupBy;
|
||||
|
||||
public SQLSelect(List<FieldAll> fieldAlls, Map<String, FieldDef> fieldDefs, Table table, List<Relation> relations, Condition whereCondition, Condition havingCondition, List<String> groupBy, List<String> orderBy, int offset, int limit) {
|
||||
public SQLSelect(List<FieldAll> fieldAlls, Map<String, FieldDef> fieldDefs, Table table, List<Relation> relations, Condition whereCondition, Condition havingCondition, List<String> groupBy, List<OrderByItem> orderBy, int offset, int limit) {
|
||||
this.fieldAlls = fieldAlls;
|
||||
this.fieldDefs = fieldDefs;
|
||||
this.table = table;
|
||||
@@ -79,7 +79,7 @@ public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSo
|
||||
return groupBy;
|
||||
}
|
||||
|
||||
public List<String> getOrderBy() {
|
||||
public List<OrderByItem> getOrderBy() {
|
||||
return orderBy;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user