01: /**
02: * Copyright 2006 Webmedia Group Ltd.
03: *
04: * Licensed under the Apache License, Version 2.0 (the "License");
05: * you may not use this file except in compliance with the License.
06: * You may obtain a copy of the License at
07: *
08: * http://www.apache.org/licenses/LICENSE-2.0
09: *
10: * Unless required by applicable law or agreed to in writing, software
11: * distributed under the License is distributed on an "AS IS" BASIS,
12: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13: * See the License for the specific language governing permissions and
14: * limitations under the License.
15: **/package org.araneaframework.backend.list.sqlexpr.compare;
16:
17: import java.util.ArrayList;
18: import java.util.Arrays;
19: import java.util.List;
20: import org.araneaframework.backend.list.SqlExpression;
21:
22: public abstract class SqlComparableExpression implements SqlExpression {
23: protected SqlExpression expr1;
24:
25: protected SqlExpression expr2;
26:
27: public SqlComparableExpression(SqlExpression expr1,
28: SqlExpression expr2) {
29: if (expr1 == null || expr2 == null) {
30: throw new RuntimeException(
31: "Both arguments must be provided");
32: }
33: this .expr1 = expr1;
34: this .expr2 = expr2;
35: }
36:
37: public String toSqlString() {
38: StringBuffer sb = new StringBuffer();
39: sb.append(this .expr1.toSqlString());
40: sb.append(" ");
41: sb.append(getOperator());
42: sb.append(" ");
43: sb.append(this .expr2.toSqlString());
44: return sb.toString();
45: }
46:
47: protected abstract String getOperator();
48:
49: public Object[] getValues() {
50: List values = new ArrayList();
51: Object[] childValues = this.expr1.getValues();
52: if (childValues != null) {
53: values.addAll(Arrays.asList(childValues));
54: }
55: childValues = this.expr2.getValues();
56: if (childValues != null) {
57: values.addAll(Arrays.asList(childValues));
58: }
59: return values.toArray();
60: }
61: }
|