Remove FieldDefFieldValue, and merge FieldDefValue into FieldDef.
git-svn-id: https://svn.apache.org/repos/asf/ofbiz/trunk@949603 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
@@ -18,14 +18,26 @@
|
||||
*/
|
||||
package org.ofbiz.sql;
|
||||
|
||||
public abstract class FieldDef extends Atom {
|
||||
protected final String alias;
|
||||
public final class FieldDef extends Atom {
|
||||
private final String alias;
|
||||
private final StaticValue value;
|
||||
|
||||
protected FieldDef(String alias) {
|
||||
this.alias = alias;
|
||||
public FieldDef(StaticValue value, String alias) {
|
||||
this.alias = alias == null ? value.getDefaultName() : alias;
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public final String getAlias() {
|
||||
return alias;
|
||||
}
|
||||
|
||||
public StaticValue getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public StringBuilder appendTo(StringBuilder sb) {
|
||||
value.appendTo(sb);
|
||||
sb.append(" AS ").append(alias);
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,40 +0,0 @@
|
||||
/*
|
||||
* 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 FieldDefFieldValue extends FieldDef {
|
||||
private final FieldValue value;
|
||||
|
||||
public FieldDefFieldValue(FieldValue value, String alias) {
|
||||
super(alias == null ? value.getFieldName() : alias);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public FieldValue getFieldValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public StringBuilder appendTo(StringBuilder sb) {
|
||||
value.appendTo(sb);
|
||||
if (!value.getFieldName().equals(alias)) {
|
||||
sb.append(" AS ").append(alias);
|
||||
}
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
/*
|
||||
* 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 FieldDefValue extends FieldDef {
|
||||
private final StaticValue value;
|
||||
|
||||
public FieldDefValue(StaticValue value, String alias) {
|
||||
super(alias == null ? value.getDefaultName() : alias);
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public StaticValue getValue() {
|
||||
return value;
|
||||
}
|
||||
|
||||
public StringBuilder appendTo(StringBuilder sb) {
|
||||
value.appendTo(sb);
|
||||
sb.append(" AS ").append(alias);
|
||||
return sb;
|
||||
}
|
||||
}
|
||||
@@ -554,13 +554,13 @@ private void FieldDef(Map<String, FieldDef> fieldDefs, List<FieldAll> fieldAlls,
|
||||
<CLOSE_PAREN>
|
||||
)?
|
||||
{ fieldAlls.add(new FieldAll(n, excludeList)); return; }
|
||||
| fieldName=NamePart() ( <AS> fieldAlias=NamePart() )? { def = new FieldDefFieldValue(new FieldValue(n, fieldName), fieldAlias); }
|
||||
| fieldName=NamePart() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(new FieldValue(n, fieldName), fieldAlias); }
|
||||
)
|
||||
| v=FunctionCallRest(n) ( <AS> fieldAlias=NamePart() )? { def = new FieldDefValue(v, fieldAlias); }
|
||||
| ( <AS> fieldAlias=NamePart() )? { def = new FieldDefFieldValue(new FieldValue(null, n), fieldAlias); }
|
||||
| v=FunctionCallRest(n) ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
|
||||
| ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(new FieldValue(null, n), fieldAlias); }
|
||||
)
|
||||
| v=MathValue() ( <AS> fieldAlias=NamePart() )? { def = new FieldDefValue(v, fieldAlias); }
|
||||
| v=Count() ( <AS> fieldAlias=NamePart() )? { def = new FieldDefValue(v, fieldAlias); }
|
||||
| v=MathValue() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
|
||||
| v=Count() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(v, fieldAlias); }
|
||||
) {
|
||||
if (fieldDefs.containsKey(def.getAlias())) throw new ParseException("duplicate alias(" + def.getAlias() + ")");
|
||||
fieldDefs.put(def.getAlias(), def);
|
||||
|
||||
@@ -32,8 +32,6 @@ import junit.framework.TestCase;
|
||||
import org.ofbiz.sql.Condition;
|
||||
import org.ofbiz.sql.FieldAll;
|
||||
import org.ofbiz.sql.FieldDef;
|
||||
import org.ofbiz.sql.FieldDefFieldValue;
|
||||
import org.ofbiz.sql.FieldDefValue;
|
||||
import org.ofbiz.sql.FieldValue;
|
||||
import org.ofbiz.sql.FunctionCall;
|
||||
import org.ofbiz.sql.MathValue;
|
||||
@@ -84,28 +82,32 @@ public class SQLTest extends GenericTestCaseBase {
|
||||
assertTrue("has first field def", fieldDefIt.hasNext());
|
||||
FieldDef fieldDef = fieldDefIt.next();
|
||||
assertEquals("first fieldDef.alias", "roleTypeId", fieldDef.getAlias());
|
||||
assertTrue("first is FieldDefFieldValue", fieldDef instanceof FieldDefFieldValue);
|
||||
FieldDefFieldValue fdfv = (FieldDefFieldValue) fieldDef;
|
||||
assertEquals("first fieldDef.tableName", "d", fdfv.getFieldValue().getTableName());
|
||||
assertEquals("first fieldDef.fieldName", "roleTypeId", fdfv.getFieldValue().getFieldName());
|
||||
assertEquals("first fieldDef.defaultName", "roleTypeId", fdfv.getFieldValue().getDefaultName());
|
||||
assertTrue("first is FieldDef", fieldDef instanceof FieldDef);
|
||||
FieldDef fdfv = (FieldDef) fieldDef;
|
||||
assertTrue("first has FieldValue", fdfv.getValue() instanceof FieldValue);
|
||||
FieldValue fv = (FieldValue) fdfv.getValue();
|
||||
assertEquals("first fieldDef.tableName", "d", fv.getTableName());
|
||||
assertEquals("first fieldDef.fieldName", "roleTypeId", fv.getFieldName());
|
||||
assertEquals("first fieldDef.defaultName", "roleTypeId", fv.getDefaultName());
|
||||
|
||||
assertTrue("has second field def", fieldDefIt.hasNext());
|
||||
fieldDef = fieldDefIt.next();
|
||||
assertEquals("second fieldDef.alias", "roleDescription", fieldDef.getAlias());
|
||||
assertTrue("second is FieldDefFieldValue", fieldDef instanceof FieldDefFieldValue);
|
||||
fdfv = (FieldDefFieldValue) fieldDef;
|
||||
assertEquals("second fieldDef.tableName", "d", fdfv.getFieldValue().getTableName());
|
||||
assertEquals("second fieldDef.fieldName", "description", fdfv.getFieldValue().getFieldName());
|
||||
assertEquals("second fieldDef.defaultName", "description", fdfv.getFieldValue().getDefaultName());
|
||||
assertTrue("second is FieldDef", fieldDef instanceof FieldDef);
|
||||
fdfv = (FieldDef) fieldDef;
|
||||
assertTrue("second has FieldValue", fdfv.getValue() instanceof FieldValue);
|
||||
fv = (FieldValue) fdfv.getValue();
|
||||
assertEquals("second fieldDef.tableName", "d", fv.getTableName());
|
||||
assertEquals("second fieldDef.fieldName", "description", fv.getFieldName());
|
||||
assertEquals("second fieldDef.defaultName", "description", fv.getDefaultName());
|
||||
|
||||
assertTrue("has third field def", fieldDefIt.hasNext());
|
||||
fieldDef = fieldDefIt.next();
|
||||
assertEquals("third fieldDef.alias", "SUM", fieldDef.getAlias());
|
||||
assertTrue("third is FieldDefValue", fieldDef instanceof FieldDefValue);
|
||||
FieldDefValue fdv = (FieldDefValue) fieldDef;
|
||||
assertTrue("third fieldDefValue.staticValue is FunctionCall", fdv.getValue() instanceof FunctionCall);
|
||||
FunctionCall fc = (FunctionCall) fdv.getValue();
|
||||
assertTrue("third is FieldDef", fieldDef instanceof FieldDef);
|
||||
FieldDef fd = (FieldDef) fieldDef;
|
||||
assertTrue("third fieldDefValue.staticValue is FunctionCall", fd.getValue() instanceof FunctionCall);
|
||||
FunctionCall fc = (FunctionCall) fd.getValue();
|
||||
assertEquals("third arg count", 1, fc.getArgCount());
|
||||
Iterator<Value> valueIt = fc.iterator();
|
||||
assertTrue("third args hasNext", valueIt.hasNext());
|
||||
@@ -119,32 +121,32 @@ public class SQLTest extends GenericTestCaseBase {
|
||||
assertTrue("has fourth field def", fieldDefIt.hasNext());
|
||||
fieldDef = fieldDefIt.next();
|
||||
assertEquals("fourth fieldDef.alias", "baz", fieldDef.getAlias());
|
||||
assertTrue("fourth is FieldDefValue", fieldDef instanceof FieldDefValue);
|
||||
fdv = (FieldDefValue) fieldDef;
|
||||
assertTrue("fourth is FieldDef", fieldDef instanceof FieldDef);
|
||||
fd = (FieldDef) fieldDef;
|
||||
|
||||
assertTrue("has fifth field def", fieldDefIt.hasNext());
|
||||
fieldDef = fieldDefIt.next();
|
||||
assertEquals("fifth fieldDef.alias", "one", fieldDef.getAlias());
|
||||
assertTrue("fifth is FieldDefValue", fieldDef instanceof FieldDefValue);
|
||||
fdv = (FieldDefValue) fieldDef;
|
||||
assertTrue("fifth is FieldDef", fieldDef instanceof FieldDef);
|
||||
fd = (FieldDef) fieldDef;
|
||||
|
||||
assertTrue("has sixth field def", fieldDefIt.hasNext());
|
||||
fieldDef = fieldDefIt.next();
|
||||
assertEquals("sixth fieldDef.alias", "cnt1", fieldDef.getAlias());
|
||||
assertTrue("sixth is FieldDefValue", fieldDef instanceof FieldDefValue);
|
||||
fdv = (FieldDefValue) fieldDef;
|
||||
assertTrue("sixth is FieldDef", fieldDef instanceof FieldDef);
|
||||
fd = (FieldDef) fieldDef;
|
||||
|
||||
assertTrue("has seventh field def", fieldDefIt.hasNext());
|
||||
fieldDef = fieldDefIt.next();
|
||||
assertEquals("seventh fieldDef.alias", "cnt2", fieldDef.getAlias());
|
||||
assertTrue("seventh is FieldDefValue", fieldDef instanceof FieldDefValue);
|
||||
fdv = (FieldDefValue) fieldDef;
|
||||
assertTrue("seventh is FieldDef", fieldDef instanceof FieldDef);
|
||||
fd = (FieldDef) fieldDef;
|
||||
|
||||
assertTrue("has eighth field def", fieldDefIt.hasNext());
|
||||
fieldDef = fieldDefIt.next();
|
||||
assertEquals("eighth fieldDef.alias", "cnt3", fieldDef.getAlias());
|
||||
assertTrue("eighth is FieldDefValue", fieldDef instanceof FieldDefValue);
|
||||
fdv = (FieldDefValue) fieldDef;
|
||||
assertTrue("eighth is FieldDef", fieldDef instanceof FieldDef);
|
||||
fd = (FieldDef) fieldDef;
|
||||
|
||||
assertFalse("has no more field def", fieldDefIt.hasNext());
|
||||
|
||||
|
||||
Reference in New Issue
Block a user