|
Modified: ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Parser.jj
URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Parser.jj?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Parser.jj (original) +++ ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Parser.jj Wed Aug 11 13:22:40 2010 @@ -17,11 +17,11 @@ * under the License. */ options { - JAVA_UNICODE_ESCAPE = false; - ERROR_REPORTING = true; - STATIC = false; + JAVA_UNICODE_ESCAPE = false; + ERROR_REPORTING = true; + STATIC = false; // MULTI = true; - JDK_VERSION = "1.5"; + JDK_VERSION = "1.5"; // VISITOR = true; // BUILD_NODE_FILES = true; // NODE_FACTORY = false; @@ -31,15 +31,16 @@ options { // DEBUG_PARSER = true; // DEBUG_LOOKAHEAD = true; // DEBUG_TOKEN_MANAGER = true; - LOOKAHEAD = 1; + LOOKAHEAD = 1; // CHOICE_AMBIGUITY_CHECK = 3; // OTHER_AMBIGUITY_CHECK = 3; - IGNORE_CASE = true; + IGNORE_CASE = true; } PARSER_BEGIN(Parser) package org.ofbiz.sql; +import java.util.EnumSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -85,66 +86,77 @@ TOKEN_MGR_DECLS: { } TOKEN: { - <OPEN_PAREN: "("> -| <CLOSE_PAREN: ")"> -| <AND: "AND"> -| <OR: "OR"> -| <PERIOD: "."> -| <JOIN: "JOIN"> -| <LEFT: "LEFT"> -| <AS: "AS"> -| <COUNT: "COUNT"> -| <DISTINCT: "DISTINCT"> -| <WHERE: "WHERE"> -| <HAVING: "HAVING"> -| <GROUP: "GROUP"> -| <ORDER: "ORDER"> -//| <UNION: "UNION"> -| <BY: "BY"> -| <ON: "ON"> -| <USING: "USING"> -| <LIMIT: "LIMIT"> -| <OFFSET: "OFFSET"> -| <SELECT: "SELECT"> -| <DELETE: "DELETE"> -| <UPDATE: "UPDATE"> -| <INSERT: "INSERT"> -| <RELATION: "RELATION"> -| <EXCLUDE: "EXCLUDE"> -| <UPPER: "UPPER"> -| <LOWER: "LOWER"> -| <TYPE: "TYPE"> -| <TITLE: "TITLE"> -| <SET: "SET"> -| <FROM: "FROM"> -| <SEMI: ";"> -| <STAR: "*"> -| <COMMA: ","> -| <PLUS: "+"> -| <MINUS: "-"> -| <DESC: "DESC"> -| <ASC: "ASC"> -| <EQUALS: "="> -| <BETWEEN: "BETWEEN"> -| <INTO: "INTO"> -| <VALUES: "VALUES"> -| <CREATE: "CREATE"> -| <VIEW: "VIEW"> -| <IS: "IS"> -| <NOT: "NOT"> -| <NULL: "NULL"> -| <START_DQUOTE: "\""> { pushState(IN_DQUOTE); } -| <START_SQUOTE: "'"> { pushState(IN_SQUOTE); } -| <INTEGER: - "0" ( - "x" (["0"-"9","a"-"b"])+ - | (["0"-"7"])+ - ) - | ["1"-"9"] (["0"-"9"])* + <OPEN_PAREN: "("> + | <CLOSE_PAREN: ")"> + | <AND: "AND"> + | <OR: "OR"> + | <PERIOD: "."> + | <JOIN: "JOIN"> + | <LEFT: "LEFT"> + | <AS: "AS"> + | <COUNT: "COUNT"> + | <MAX: "MAX"> + | <MIN: "MIN"> + | <SUM: "SUM"> + | <AVG: "AVG"> + | <DISTINCT: "DISTINCT"> + | <WHERE: "WHERE"> + | <HAVING: "HAVING"> + | <GROUP: "GROUP"> + | <ORDER: "ORDER"> + | <INTERSECT: "INTERSECT"> + | <EXCEPT: "EXCEPT"> + | <UNION: "UNION"> + | <ALL: "ALL"> + | <BY: "BY"> + | <ON: "ON"> + | <USING: "USING"> + | <LIMIT: "LIMIT"> + | <OFFSET: "OFFSET"> + | <SELECT: "SELECT"> + | <DELETE: "DELETE"> + | <UPDATE: "UPDATE"> + | <INSERT: "INSERT"> + | <INDEX: "INDEX"> + | <UNIQUE: "UNIQUE"> + | <RELATION: "RELATION"> + | <EXCLUDE: "EXCLUDE"> + | <TYPE: "TYPE"> + | <TITLE: "TITLE"> + | <SET: "SET"> + | <FROM: "FROM"> + | <SEMI: ";"> + | <STAR: "*"> + | <COMMA: ","> + | <PLUS: "+"> + | <MINUS: "-"> + | <DESC: "DESC"> + | <ASC: "ASC"> + | <EQUALS: "="> + | <BETWEEN: "BETWEEN"> + | <INTO: "INTO"> + | <VALUES: "VALUES"> + | <CREATE: "CREATE"> + | <VIEW: "VIEW"> + | <IS: "IS"> + | <NOT: "NOT"> + | <NULL: "NULL"> + | <MAP: "MAP"> + | <NULLS: "NULLS"> + | <FIRST: "FIRST"> + | <LAST: "LAST"> + | <START_DQUOTE: "\""> { pushState(IN_DQUOTE); } + | <START_SQUOTE: "'"> { pushState(IN_SQUOTE); } + | <INTEGER: + "0" ( + "x" (["0"-"9","a"-"b"])+ + | (["0"-"7"])+ + ) + | ["1"-"9"] (["0"-"9"])* > -| <NAME: ["a"-"z"] (["a"-"z","0"-"9","_","-"])*> -| <PARAMETER: "?" (["a"-"z"])+> -//| <WORD: (~["'", "\"", "/", " ", "\f", "\n", "\r", "\t", "*"])+> + | <NAME: ["a"-"z"] (["a"-"z","0"-"9","_","-"])*> + | <PARAMETER: "?" (["a"-"z"])+> +// | <WORD: (~["'", "\"", "/", " ", "\f", "\n", "\r", "\t", "*"])+> } <DEFAULT> @@ -159,8 +171,8 @@ MORE: { <IN_COMMENT> MORE: { - <(~[])> -| <COMMENT_END: "*/"> { popState(); } + <(~[])> + | <COMMENT_END: "*/"> { popState(); } } <IN_DQUOTE,IN_SQUOTE> @@ -175,8 +187,8 @@ TOKEN: { <IN_SQUOTE> TOKEN: { - <ESCAPE_SQUOTE: "''"> -| <END_SQUOTE: "'"> { popState(); } + <ESCAPE_SQUOTE: "''"> + | <END_SQUOTE: "'"> { popState(); } } <DEFAULT,IN_DQUOTE,IN_SQUOTE> @@ -186,98 +198,155 @@ TOKEN: { // ------------------- -public List<SQLStatement<?>> SQLFile(): -{ +public List<SQLStatement<?>> SQLFile(): { List<SQLStatement<?>> list = FastList.newInstance(); SQLStatement<?> statement; -} -{ - ( statement=Statement() ( <SEMI> )? { list.add(statement); } )* +} { + ( + statement=Statement() ( <SEMI> )? + { list.add(statement); } + )* <EOF> { return list; } } -public SQLStatement StandaloneStatement(): -{ +public SQLStatement StandaloneStatement(): { SQLStatement statement; -} -{ - statement=Statement() ( <SEMI> )? <EOF> { return statement; } +} { + statement=Statement() ( <SEMI> )? <EOF> + { return statement; } } -public SQLView ViewStatement(): -{ +public SQLView ViewStatement(): { SQLView sqlView; -} -{ - sqlView=View() ( <SEMI> )? <EOF> { return sqlView; } +} { + <CREATE> <VIEW> sqlView=View() ( <SEMI> )? <EOF> + { return sqlView; } } -public SQLSelect SelectStatement(): -{ +public SQLSelect SelectStatement(): { SQLSelect sqlSelect; -} -{ +} { sqlSelect=Select() ( <SEMI> )? <EOF> { return sqlSelect; } } -public SQLDelete DeleteStatement(): -{ +public SQLDelete DeleteStatement(): { SQLDelete sqlDelete; -} -{ +} { sqlDelete=Delete() ( <SEMI> )? <EOF> { return sqlDelete; } } -public SQLUpdate UpdateStatement(): -{ +public SQLUpdate UpdateStatement(): { SQLUpdate sqlUpdate; -} -{ +} { sqlUpdate=Update() ( <SEMI> )? <EOF> { return sqlUpdate; } } -public SQLInsert InsertStatement(): -{ +public SQLInsert InsertStatement(): { SQLInsert sqlInsert; -} -{ +} { sqlInsert=Insert() ( <SEMI> )? <EOF> { return sqlInsert; } } -public Condition Condition(): -{ Condition c; } -{ +public Condition Condition(): { + Condition c; +} { c=ConditionExpression() <EOF> { return c; } } -private SQLStatement Statement(): -{ - SQLStatement statement; +public FieldAll parse_FieldAll(): { + FieldAll fieldAll; +} { + fieldAll=FieldAll() <EOF> { return fieldAll; } +} + +public FieldDef parse_FieldDef(): { + FieldDef fieldDef; +} { + fieldDef=FieldDef() <EOF> { return fieldDef; } +} + +public OrderByItem parse_OrderByItem(): { + OrderByItem item; +} { + item=OrderByItem() <EOF> { return item; } } -{ + +private SQLStatement Statement(): { + SQLStatement statement; +} { ( - statement=Select() { return statement; } - | statement=Delete() { return statement; } - | statement=Update() { return statement; } - | statement=Insert() { return statement; } - | statement=View() { return statement; } + statement=Select() { return statement; } + | statement=Delete() { return statement; } + | statement=Update() { return statement; } + | statement=Insert() { return statement; } + | statement=Creates() { return statement; } + ) +} + +private SQLStatement Creates(): { + SQLStatement statement; + boolean isUnique = false; +} { + <CREATE> ( + <VIEW> statement=View() { return statement; } + | ( <UNIQUE> { isUnique = true; } )? + <INDEX> statement=Index(isUnique) { return statement; } ) } -private SQLView View(): -{ +private SQLView View(): { String name; SQLSelect sqlSelect; +} { + name=NamePart() <AS> sqlSelect=Select() { return new SQLView(name, sqlSelect); } } -{ - <CREATE> <VIEW> name=NamePart() <AS> sqlSelect=Select() - { return new SQLView(name, sqlSelect); } + +private SelectGroup SelectGroup(): { + boolean isDistinct = false; + List<String> groupBy = null; + Map<String, FieldDef> fieldDefs = FastMap.newInstance(); + List<FieldAll> fieldAlls = FastList.newInstance(); + Set<String> fieldAllAliases = FastSet.newInstance(); + Table table; + Condition whereCondition = null, havingCondition = null; +} { + <SELECT> (<DISTINCT> { isDistinct = true; })? ( + SelectField(fieldDefs, fieldAlls, fieldAllAliases) + ( <COMMA> SelectField(fieldDefs, fieldAlls, fieldAllAliases) )* + ) + <FROM> table=Table() + ( <WHERE> whereCondition=ConditionExpression() )? + ( <HAVING> havingCondition=ConditionExpression() )? + ( <GROUP> <BY> groupBy=FieldList() )? + { return new SelectGroup(isDistinct, fieldAlls, fieldDefs, table, whereCondition, havingCondition, groupBy); } } -private SQLSelect Select(): -{ - Integer i; +private Unioned.Operator UnionOperator(): { +} { + <UNION> + ( <ALL> { return Unioned.Operator.UNION_ALL; } )? + { return Unioned.Operator.UNION; } + | <INTERSECT> + ( <ALL> { return Unioned.Operator.INTERSECT_ALL; } )? + { return Unioned.Operator.INTERSECT; } + | <EXCEPT> + ( <ALL> { return Unioned.Operator.EXCEPT_ALL; } )? + { return Unioned.Operator.EXCEPT; } +} + +private Unioned Unioned(): { + Unioned.Operator operator; + SelectGroup selectGroup; + Unioned next = null; +} { + operator=UnionOperator() selectGroup=SelectGroup() ( next=Unioned() )? + { return new Unioned(operator, selectGroup, next); } +} + +private SQLSelect Select(): { + boolean hadEarlyRelations = false; + Unioned unioned = null; boolean isDistinct = false; List<OrderByItem> orderBy = null; List<String> groupBy = null; @@ -288,33 +357,36 @@ private SQLSelect Select(): Map<String, Relation> relations = FastMap.newInstance(); Condition whereCondition = null, havingCondition = null; int offset = -1, limit = -1; -} -{ +} { <SELECT> (<DISTINCT> { isDistinct = true; })? ( - FieldDef(fieldDefs, fieldAlls, fieldAllAliases) - ( <COMMA> FieldDef(fieldDefs, fieldAlls, fieldAllAliases) )* + SelectField(fieldDefs, fieldAlls, fieldAllAliases) + ( <COMMA> SelectField(fieldDefs, fieldAlls, fieldAllAliases) )* ) <FROM> table=Table() - ( <RELATION> Relation(relations) )* + ( LOOKAHEAD(1) <RELATION> Relation(relations) { hadEarlyRelations = true; } )* ( <WHERE> whereCondition=ConditionExpression() )? ( <HAVING> havingCondition=ConditionExpression() )? ( <GROUP> <BY> groupBy=FieldList() )? + ( unioned=Unioned() )? + ( LOOKAHEAD(1, {!hadEarlyRelations}) <RELATION> Relation(relations) )* ( <ORDER> <BY> orderBy=OrderByList() )? ( <OFFSET> offset=Integer() )? ( <LIMIT> limit=Integer() )? - { return new SQLSelect(isDistinct, fieldAlls, fieldDefs, table, relations, whereCondition, havingCondition, groupBy, orderBy, offset, limit); } + { return new SQLSelect(new SelectGroup(isDistinct, fieldAlls, fieldDefs, table, whereCondition, havingCondition, groupBy), unioned, relations, orderBy, offset, limit); } } -private void Relation(Map<String, Relation> relations): -{ +private void Relation(Map<String, Relation> relations): { String type = null, title = null, entityName; - List<KeyMap> keyMaps; -} -{ + KeyMap keyMap; + List<KeyMap> keyMaps = FastList.newInstance(); +} { ( <TYPE> type=NamePart() )? ( <TITLE> title=NamePart() )? <NAME> { entityName = getToken(0).image; } - keyMaps=KeyMaps("cur", "other") + <MAP> keyMap=PlainKeyMap() { keyMaps.add(keyMap); } ( + <COMMA> + keyMap=PlainKeyMap() { keyMaps.add(keyMap); } + )* { Relation relation = new Relation(type, title, entityName, keyMaps); if (relations.containsKey(relation.getName())) throw new ParseException("Duplicate relation: " + relation); @@ -322,17 +394,23 @@ private void Relation(Map<String, Relati } } +private KeyMap PlainKeyMap(): { + String left, right; +} { + left=NamePart() ( + <EQUALS> right=NamePart() { return new KeyMap(left, right); } + | { return new KeyMap(left, left); } + ) +} -private SQLUpdate Update(): -{ +private SQLUpdate Update(): { TableName tableName; List<Table> tableList = null; Condition whereCondition = null; List<SetField> allSetFields = FastList.newInstance(); List<SetField> setFields; Joined joined = null; -} -{ +} { <UPDATE> tableName=TableName() <SET> setFields=SetField() { allSetFields.addAll(setFields); } @@ -342,28 +420,38 @@ private SQLUpdate Update(): { return new SQLUpdate(new Table(tableName, joined), allSetFields, whereCondition); } } -private SQLDelete Delete(): -{ +private SQLDelete Delete(): { TableName tableName; List<Table> tableList = null; Condition whereCondition = null; Joined joined = null; -} -{ +} { <DELETE> <FROM> tableName=TableName() ( LOOKAHEAD(<USING>, {deleteSupportsUsing}) <USING> joined=JoinedRest(false, tableName) )? ( <WHERE> whereCondition=ConditionExpression() )? { return new SQLDelete(new Table(tableName, joined), whereCondition); } } -private SQLInsert Insert(): -{ +private SQLIndex Index(boolean isUnique): { + String name, table, using = null; + ConstantValue value; + List<ConstantValue> values = FastList.newInstance(); +} { + name=NamePart() <ON> table=NamePart() + ( <USING> using=NamePart() )? + <OPEN_PAREN> + value=ConstantValue() { values.add(value); } + ( <COMMA> value=ConstantValue() { values.add(value); } )* + <CLOSE_PAREN> + { return new SQLIndex(isUnique, name, table, using, values); } +} + +private SQLInsert Insert(): { TableName tableName; List<String> columns = FastList.newInstance(); String n; InsertSource source; -} -{ +} { <INSERT> <INTO> tableName=TableName() ( <OPEN_PAREN> n=NamePart() { columns.add(n); } @@ -374,24 +462,20 @@ private SQLInsert Insert(): { return new SQLInsert(tableName, source, columns); } } -private InsertValues InsertValues(): -{ +private InsertValues InsertValues(): { List<InsertRow> list = FastList.newInstance(); InsertRow row; -} -{ +} { <VALUES> row=InsertRow() { list.add(row); } ( <COMMA> row=InsertRow() { list.add(row); } )* { return new InsertValues(list); } } -private InsertRow InsertRow(): -{ +private InsertRow InsertRow(): { List<Value> list = FastList.newInstance(); Value v; -} -{ +} { <OPEN_PAREN> v=InsertValue() { list.add(v); } ( <COMMA> v=InsertValue() { list.add(v); } )* @@ -399,112 +483,96 @@ private InsertRow InsertRow(): { return new InsertRow(list); } } -private Value InsertValue(): -{ +private Value InsertValue(): { Value v; Integer i; String s; -} -{ - v=ParameterValue() { return v; } -| i=Integer() { return new NumberValue<Integer>(i); } -| s=SQuoted() { return new StringValue(s); } +} { + v=ParameterValue() { return v; } + | i=Integer() { return new NumberValue<Integer>(i); } + | s=SQuoted() { return new StringValue(s); } } -private List<SetField> SetField(): -{ +private List<SetField> SetField(): { List<SetField> setFields = FastList.newInstance(); String n; Value v; List<String> columnList = FastList.newInstance(); List<Value> valueList = FastList.newInstance(); -} -{ +} { ( - n=NamePart() <EQUALS> ( - v=Value() { setFields.add(new SetField(n, v)); } - | v=MathValue() { setFields.add(new SetField(n, v)); } - ) - | <OPEN_PAREN> - n=NamePart() { columnList.add(n); } - ( <COMMA> n=NamePart() { columnList.add(n); } )* - <CLOSE_PAREN> - <EQUALS> - <OPEN_PAREN> - (v=Value()|v=MathValue()) { valueList.add(v); } - ( <COMMA> (v=Value()|v=MathValue()) { valueList.add(v); } )* - <CLOSE_PAREN> { + n=NamePart() <EQUALS> ( + v=Value() { setFields.add(new SetField(n, v)); } + | v=MathValue() { setFields.add(new SetField(n, v)); } + ) + | <OPEN_PAREN> + n=NamePart() { columnList.add(n); } + ( <COMMA> n=NamePart() { columnList.add(n); } )* + <CLOSE_PAREN> + <EQUALS> + <OPEN_PAREN> + ( v=Value() | v=MathValue() ) { valueList.add(v); } + ( <COMMA> (v=Value()|v=MathValue()) { valueList.add(v); } )* + <CLOSE_PAREN> { if (columnList.size() != valueList.size()) throw new ParseException(); for (int i = 0; i < columnList.size(); i++) { setFields.add(new SetField(columnList.get(i), valueList.get(i))); } - } + } ) { return setFields; } } -private Table Table(): -{ +private Table Table(): { TableName tableName; Joined joined = null; -} -{ +} { tableName=TableName() ( joined=Joined(tableName) )? { return new Table(tableName, joined); } } -private Joined Joined(TableName leftTableName): -{ +private Joined Joined(TableName leftTableName): { Boolean isOptional; Joined joined = null; -} -{ +} { isOptional=Joiner() joined=JoinedRest(isOptional, leftTableName) { return joined; } } -private Joined JoinedRest(boolean isOptional, TableName leftTableName): -{ +private Joined JoinedRest(boolean isOptional, TableName leftTableName): { TableName rightTableName; List<KeyMap> keyMaps; Joined joined = null; -} -{ +} { rightTableName=TableName() keyMaps=KeyMaps(leftTableName.getAlias(), rightTableName.getAlias()) ( joined=Joined(rightTableName) )? { return new Joined(isOptional, rightTableName, keyMaps, joined); } } -private List<KeyMap> KeyMaps(String leftAlias, String rightAlias): -{ +private List<KeyMap> KeyMaps(String leftAlias, String rightAlias): { List<KeyMap> keyMaps = FastList.newInstance(); String n; -} -{ +} { ( - <ON> - KeyMap(keyMaps, leftAlias, rightAlias) - ( <AND> KeyMap(keyMaps, leftAlias, rightAlias) )* - | - <USING> - n=NamePart() { keyMaps.add(new KeyMap(n, n)); } - ( <COMMA> n=NamePart() { keyMaps.add(new KeyMap(n, n)); } )* + <ON> + KeyMap(keyMaps, leftAlias, rightAlias) + ( <AND> KeyMap(keyMaps, leftAlias, rightAlias) )* + | <USING> + n=NamePart() { keyMaps.add(new KeyMap(n, n)); } + ( <COMMA> n=NamePart() { keyMaps.add(new KeyMap(n, n)); } )* ) { return keyMaps; } } -private void KeyMap(List<KeyMap> keyMaps, String leftAlias, String rightAlias): -{ +private void KeyMap(List<KeyMap> keyMaps, String leftAlias, String rightAlias): { String alias1, field1; String alias2, field2; -} -{ +} { alias1=NamePart() <PERIOD> field1=NamePart() <EQUALS> - alias2=NamePart() <PERIOD> field2=NamePart() - { + alias2=NamePart() <PERIOD> field2=NamePart() { if (alias1.equals(leftAlias)) { if (!alias2.equals(rightAlias)) throw new ParseException("invalid right alias(" + alias2 + "), expected(" + rightAlias + ")"); keyMaps.add(new KeyMap(field1, field2)); @@ -517,341 +585,344 @@ private void KeyMap(List<KeyMap> keyMaps } } -private TableName TableName(): -{ +private TableName TableName(): { String tableName, alias = null; -} -{ +} { tableName=NamePart() - ( (<AS>)? alias=NamePart() )? + ( ( <AS> )? alias=NamePart() )? { return new TableName(tableName, alias); } } -private Boolean Joiner(): -{} -{ - <LEFT> <JOIN> { return Boolean.TRUE; } -| <JOIN> { return Boolean.FALSE; } +private Boolean Joiner(): { +} { + <LEFT> <JOIN> { return Boolean.TRUE; } + | <JOIN> { return Boolean.FALSE; } +} + +private void SelectField(Map<String, FieldDef> fieldDefs, List<FieldAll> fieldAlls, Set<String> fieldAllAliases): { + FieldAll fieldAll; + FieldDef fieldDef; +} { + LOOKAHEAD(3) fieldAll=FieldAll() { + if (fieldAllAliases.contains(fieldAll.getAlias())) throw new ParseException("Duplicate aliasAll(" + fieldAll.getAlias() + ")"); + fieldAlls.add(fieldAll); return; + } + | fieldDef=FieldDef() { + if (fieldDefs.containsKey(fieldDef.getDefaultName())) throw new ParseException("duplicate alias(" + fieldDef.getDefaultName() + ")"); + fieldDefs.put(fieldDef.getDefaultName(), fieldDef); + } } -private void FieldDef(Map<String, FieldDef> fieldDefs, List<FieldAll> fieldAlls, Set<String> fieldAllAliases): -{ - StaticValue v; - String n, fieldAlias = null, fieldName, exc; - FieldDef def; +private FieldAll FieldAll(): { + String n, exc; Set<String> excludeList = FastSet.newInstance(); +} { + n=NamePart() <PERIOD> <STAR> ( + <EXCLUDE> <OPEN_PAREN> + exc=NamePart() { excludeList.add(exc); } + ( <COMMA> exc=NamePart() { excludeList.add(exc); } )* + <CLOSE_PAREN> + )? + { return new FieldAll(n, excludeList); } } -{ + +private StaticValue StaticValue(): { + StaticValue v; + String n, fieldName; +} { ( - n=NamePart() ( - <PERIOD> ( - <STAR> - ( - { if (fieldAllAliases.contains(n)) throw new ParseException("Duplicate aliasAll(" + n + ")"); } - <EXCLUDE> <OPEN_PAREN> - exc=NamePart() { excludeList.add(exc); } - ( <COMMA> exc=NamePart() { excludeList.add(exc); } )* - <CLOSE_PAREN> - )? - { fieldAlls.add(new FieldAll(n, excludeList)); return; } - | fieldName=NamePart() ( <AS> fieldAlias=NamePart() )? { def = new FieldDef(new FieldValue(n, fieldName), 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 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); - } + n=NamePart() ( + <PERIOD> fieldName=NamePart() { v = new FieldValue(n, fieldName); } + | v=FunctionCallRest(n) + | { v = new FieldValue(null, n); } + ) + | v=MathValue() + | LOOKAHEAD(5) v=CountAll() + | v=AggregateFunction() + ) { return v; } } -private StaticValue Count(): -{ - String n, fieldName; +private FieldDef FieldDef(): { + StaticValue v; + String fieldAlias = null; +} { + v=StaticValue() ( <AS> fieldAlias=NamePart() )? { + return new FieldDef(v, fieldAlias); + } } -{ - <COUNT> <OPEN_PAREN> - ( - n=NamePart() ( - <PERIOD> ( - <STAR> <CLOSE_PAREN> { return new CountAllFunction(); } - | fieldName=NamePart() <CLOSE_PAREN> { return new CountFunction(false, new FieldValue(n, fieldName)); } - ) - | <CLOSE_PAREN> { return new CountFunction(false, new FieldValue(null, n)); } - ) - | <DISTINCT> n=NamePart() ( - <PERIOD> fieldName=NamePart() <CLOSE_PAREN> { return new CountFunction(true, new FieldValue(n, fieldName)); } - | <CLOSE_PAREN> { return new CountFunction(true, new FieldValue(null, n)); } - ) - ) + +private CountAllFunction CountAll(): { + String n; +} { + <COUNT> <OPEN_PAREN> ( + n=NamePart() + | { n = null; } + ) <PERIOD> <STAR> <CLOSE_PAREN> + { return new CountAllFunction(n); } } -private StaticValue MathValue(): -{ +private StaticValue MathValue(): { ConstantValue v; List<ConstantValue> values = FastList.newInstance(); String operator = null, newOperator; -} -{ - <OPEN_PAREN> - v=ConstantValue() { values.add(v); } - ( - newOperator=MathOperator() - v=ConstantValue() { - if (operator == null) { - operator = newOperator; - } else if (!newOperator.equals(operator)) { - throw new ParseException("Different operators in complex alias(" + operator + ":" + newOperator + ")"); - } - values.add(v); +} { + <OPEN_PAREN> v=ConstantValue() { values.add(v); } ( + newOperator=MathOperator() v=ConstantValue() { + if (operator == null) { + operator = newOperator; + } else if (!newOperator.equals(operator)) { + throw new ParseException("Different operators in complex alias(" + operator + ":" + newOperator + ")"); } - )* - <CLOSE_PAREN> - { + values.add(v); + } + )* + <CLOSE_PAREN> { if (values.size() == 1 && values.get(0) instanceof StaticValue) return (StaticValue) values.get(0); return new MathValue(operator, values); } } -private FunctionCall FunctionCallRest(String name): -{ +private AggregateFunction AggregateFunction(): { + StaticValue v; + String name, n, fieldName; + boolean isDistinct = false; +} { + name=AggregateName() <OPEN_PAREN> + ( <DISTINCT> { isDistinct = true; } )? ( + n=NamePart() ( + <PERIOD> fieldName=NamePart() { v = new FieldValue(n, fieldName); } + | v=FunctionCallRest(n) + | { v = new FieldValue(null, n); } + ) + | v=MathValue() + ) <CLOSE_PAREN> + { return new AggregateFunction(name, isDistinct, v); } +} + +private FunctionCall FunctionCallRest(String name): { Value arg; List<Value> args = FastList.newInstance(); -} -{ - <OPEN_PAREN> - ( +} { + <OPEN_PAREN> ( arg=Value() { args.add(arg); } ( <COMMA> arg=Value() { args.add(arg); } )* - ) ? + )? <CLOSE_PAREN> { return new FunctionCall(name, args); } } -private ConstantValue ConstantValue(): -{ +private ConstantValue ConstantValue(): { String n; ConstantValue v; int i; String s; +} { + n=NamePart() ( + v=FunctionCallRest(n) { return v; } + | v=FieldValue(n) { return v; } + ) + | i=Integer() { return new NumberValue<Integer>(i); } + | s=SQuoted() { return new StringValue(s); } + | v=MathValue() { return v; } +} + +private String NamePart(): { +} { + <NAME> { return getToken(0).image; } + | <TYPE> { return getToken(0).image; } } -{ - n=NamePart() ( - v=FunctionCallRest(n) { return v; } - | v=FieldValue(n) { return v; } - ) -| i=Integer() { return new NumberValue<Integer>(i); } -| s=SQuoted() { return new StringValue(s); } -| v=MathValue() { return v; } -} - -private String NamePart(): -{} -{ - <NAME> { return getToken(0).image; } -| <TYPE> { return getToken(0).image; } -} - -private String DQuoted(): -{ StringBuilder sb = new StringBuilder(); } -{ - <START_DQUOTE> (<TEXT> { sb.append(getToken(0).image); } | <ESCAPED> { sb.append(getToken(0).image); })* <END_DQUOTE> + +private String DQuoted(): { + StringBuilder sb = new StringBuilder(); +} { + <START_DQUOTE> ( + <TEXT> { sb.append(getToken(0).image); } + | <ESCAPED> { sb.append(getToken(0).image); } + )* <END_DQUOTE> { return sb.toString(); } } -private String SQuoted(): -{ StringBuilder sb = new StringBuilder(); } -{ +private String SQuoted(): { + StringBuilder sb = new StringBuilder(); +} { <START_SQUOTE> ( - <TEXT> { sb.append(getToken(0).image); } - | <ESCAPED> { sb.append(getToken(0).image); } - | <ESCAPE_SQUOTE> { sb.append("'"); } + <TEXT> { sb.append(getToken(0).image); } + | <ESCAPED> { sb.append(getToken(0).image); } + | <ESCAPE_SQUOTE> { sb.append("'"); } )* <END_SQUOTE> { return sb.toString(); } } -private String Text(): -{ +private String Text(): { StringBuilder sb = new StringBuilder(); -} -{ +} { ( <TEXT> { sb.append(getToken(0).image); } )+ { return sb.toString(); } } -private List<String> FieldList(): -{ + +private List<String> FieldList(): { List<String> list = FastList.newInstance(); String n; -} -{ +} { n=NamePart() { list.add(n); } ( <COMMA> n=NamePart() { list.add(n); } )* { return list; } } -private FieldValue FieldValue(String fieldName): -{ +private FieldValue FieldValue(String fieldName): { String s; -} -{ +} { ( <PERIOD> s=NamePart() { return new FieldValue(fieldName, s); } )? - { - return new FieldValue(fieldName); - } + { return new FieldValue(fieldName); } } -private List<OrderByItem> OrderByList(): -{ +private List<OrderByItem> OrderByList(): { List<OrderByItem> orderBy = FastList.newInstance(); OrderByItem obi; -} -{ +} { obi=OrderByItem() { orderBy.add(obi); } ( <COMMA> obi=OrderByItem() { orderBy.add(obi); } )* { return orderBy; } } -private OrderByItem OrderByItem(): -{ - String functionName = null, fieldName = null; - boolean descending = false, orderingSet = false; +public OrderByItem OrderByItem(): { + ConstantValue value; OrderByItem.Order ordering = OrderByItem.Order.DEFAULT; -} -{ - ( - <PLUS> { ordering = OrderByItem.Order.ASCENDING; } - | <MINUS> { ordering = OrderByItem.Order.DESCENDING; } - )? + OrderByItem.Nulls nulls = OrderByItem.Nulls.DEFAULT; +} { ( - ( <UPPER> | <LOWER> ) { functionName = getToken(0).image; } - <OPEN_PAREN> fieldName=NamePart() <CLOSE_PAREN> - | fieldName=NamePart() + ( + ( + <PLUS> { ordering = OrderByItem.Order.ASCENDING; } + | <MINUS> { ordering = OrderByItem.Order.DESCENDING; } + ) + value=ConstantValue() + ) + | value=ConstantValue() ( + <DESC> { ordering = OrderByItem.Order.DESCENDING; } + | <ASC> { ordering = OrderByItem.Order.ASCENDING; } + )? ) - LOOKAHEAD({!orderingSet}) ( - <DESC> { ordering = OrderByItem.Order.DESCENDING; } - | <ASC> { ordering = OrderByItem.Order.ASCENDING; } + ( + <NULLS> ( + <FIRST> { nulls = OrderByItem.Nulls.FIRST; } + | <LAST> { nulls = OrderByItem.Nulls.LAST; } + ) )? - { return new OrderByItem(ordering, functionName, fieldName); } + { return new OrderByItem(ordering, nulls, value); } } -private Integer Integer(): -{} -{ +private Integer Integer(): { +} { <INTEGER> { return Integer.decode(getToken(0).image); } } -private Value Value(): -{ +private Value Value(): { String n; Value v; int i; String s; -} -{ - n=NamePart() ( - v=FunctionCallRest(n) { return v; } - | v=FieldValue(n) { return v; } - ) -| i=Integer() { return new NumberValue<Integer>(i); } -| s=SQuoted() { return new StringValue(s); } +} { + n=NamePart() ( + v=FunctionCallRest(n) { return v; } + | v=FieldValue(n) { return v; } + ) + | i=Integer() { return new NumberValue<Integer>(i); } + | s=SQuoted() { return new StringValue(s); } } -private Condition ConditionExpression(): -{ Condition c; } -{ +private Condition ConditionExpression(): { + Condition c; +} { c=OrExpression() { return c; } } -private Condition AndExpression(): -{ +private Condition AndExpression(): { List<Condition> list = FastList.newInstance(); Condition c; -} -{ +} { c=BooleanExpression() { list.add(c); } - ( <AND> c=BooleanExpression() { list.add(c); } )* + ( <AND> c=BooleanExpression() { list.add(c); } )* { return reduce(list, Joiner.AND); } } -private Condition OrExpression(): -{ +private Condition OrExpression(): { List<Condition> list = FastList.newInstance(); Condition c; -} -{ +} { c=AndExpression() { list.add(c); } - ( <OR> c=AndExpression() { list.add(c); } )* + ( <OR> c=AndExpression() { list.add(c); } )* { return reduce(list, Joiner.OR); } } -private Value RightValue(): -{ +private Value RightValue(): { Value v; -} -{ - v=Value() { return v; } -| v=ParameterValue() { return v; } +} { + v=Value() { return v; } + | v=ParameterValue() { return v; } } -private ParameterValue ParameterValue(): -{} -{ +private ParameterValue ParameterValue(): { +} { <PARAMETER> { return new ParameterValue(getToken(0).image.substring(1)); } } -private Condition BooleanExpression(): -{ +private Condition BooleanExpression(): { Value v1, v2, v, r1, r2; String op; Condition c; List<Value> list = FastList.newInstance(); -} -{ +} { v1=Value() ( - <BETWEEN> - r1=RightValue() - <AND> - r2=RightValue() - { return new BetweenCondition(v1, r1, r2); } - | <IS> ( - <NULL> { op = "="; v2 = Value.NULL; } - | <NOT> <NULL> { op = "!="; v2 = Value.NULL; } - ) - | op=ComparisonOperator() ( - v2=RightValue() - | <OPEN_PAREN> - v=RightValue() { list.add(v); } - ( <COMMA> v=RightValue() { list.add(v); } )* - <CLOSE_PAREN> - { return new ListCondition(v1, op, list); } + <BETWEEN> r1=RightValue() <AND> r2=RightValue() + { return new BetweenCondition(v1, r1, r2); } + | <IS> ( + <NULL> { op = "="; v2 = Value.NULL; } + | <NOT> <NULL> { op = "!="; v2 = Value.NULL; } ) - ) - { return new BooleanCondition(v1, op, v2); } -| <OPEN_PAREN> c=ConditionExpression() <CLOSE_PAREN> { return c; } + | op=ComparisonOperator() ( + v2=RightValue() + | <OPEN_PAREN> + v=RightValue() { list.add(v); } + ( + <COMMA> v=RightValue() { list.add(v); } + )* + <CLOSE_PAREN> + { return new ListCondition(v1, op, list); } + ) + ) + { return new BooleanCondition(v1, op, v2); } + | <OPEN_PAREN> c=ConditionExpression() <CLOSE_PAREN> { return c; } } -private String ComparisonOperator(): -{ +private String ComparisonOperator(): { StringBuilder sb = new StringBuilder(); String s; -} -{ - s=Text() { sb.append(s); } - ( +} { + s=Text() { sb.append(s); } + ( <EQUALS> { sb.append(getToken(0).image); } - (s=Text() { sb.append(s); })? - )* { return sb.toString(); } -| <NAME> { return getToken(0).image; } -| <EQUALS> { return getToken(0).image; } + ( s=Text() { sb.append(s); } )? + )* + { return sb.toString(); } + | <NAME> { return getToken(0).image; } + | <EQUALS> { return getToken(0).image; } } -private String MathOperator(): -{ +private String MathOperator(): { String s; +} { + s=Text() { return s; } + | <NAME> { return getToken(0).image; } } -{ - s=Text() { return s; } -| <NAME> { return getToken(0).image; } + +private String AggregateName(): { +} { + <COUNT> { return getToken(0).image; } + | <MAX> { return getToken(0).image; } + | <MIN> { return getToken(0).image; } + | <SUM> { return getToken(0).image; } + | <AVG> { return getToken(0).image; } + | <FIRST> { return getToken(0).image; } + | <LAST> { return getToken(0).image; } } Modified: ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Relation.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Relation.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Relation.java (original) +++ ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Relation.java Wed Aug 11 13:22:40 2010 @@ -74,10 +74,12 @@ public final class Relation extends Atom sb.append(" TITLE ").append(title); } sb.append(' ').append(entityName); - sb.append(" ON"); + sb.append(" MAP"); for (int i = 0; i < keyMaps.size(); i++) { - sb.append(' '); - keyMaps.get(i).appendTo("cur", "other", sb); + KeyMap keyMap = keyMaps.get(i); + if (i != 0) sb.append(" AND "); + sb.append(' ').append(keyMap.getLeftFieldName()); + sb.append(" = ").append(keyMap.getRightFieldName()); } return sb; } Modified: ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLInsert.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLInsert.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLInsert.java (original) +++ ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLInsert.java Wed Aug 11 13:22:40 2010 @@ -22,7 +22,6 @@ import java.util.Iterator; import java.util.List; import org.ofbiz.base.util.StringUtil; -import org.ofbiz.base.util.UtilGenerics; public final class SQLInsert extends SQLStatement<SQLInsert> { private final TableName tableName; Modified: ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLSelect.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLSelect.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLSelect.java (original) +++ ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLSelect.java Wed Aug 11 13:22:40 2010 @@ -19,35 +19,27 @@ package org.ofbiz.sql; import java.util.Collection; -import java.util.Iterator; import java.util.List; -import java.util.ListIterator; import java.util.Map; import org.ofbiz.base.util.StringUtil; public final class SQLSelect extends SQLStatement<SQLSelect> implements InsertSource { - private final boolean isDistinct; - private final List<FieldAll> fieldAlls; - private final Map<String, FieldDef> fieldDefs; - private final Table table; + private final SelectGroup selectGroup; + private final Unioned unioned; private final Map<String, Relation> relations; - private final Condition whereCondition; - private final Condition havingCondition; private final int offset; private final int limit; private final List<OrderByItem> orderBy; - private final List<String> groupBy; public SQLSelect(boolean isDistinct, List<FieldAll> fieldAlls, Map<String, FieldDef> fieldDefs, Table table, Map<String, Relation> relations, Condition whereCondition, Condition havingCondition, List<String> groupBy, List<OrderByItem> orderBy, int offset, int limit) { - this.isDistinct = isDistinct; - this.fieldAlls = checkEmpty(fieldAlls); - this.fieldDefs = checkEmpty(fieldDefs); - this.table = table; + this(new SelectGroup(isDistinct, fieldAlls, fieldDefs, table, whereCondition, havingCondition, groupBy), null, relations, orderBy, offset, limit); + } + + public SQLSelect(SelectGroup selectGroup, Unioned unioned, Map<String, Relation> relations, List<OrderByItem> orderBy, int offset, int limit) { + this.selectGroup = selectGroup; + this.unioned = unioned; this.relations = checkEmpty(relations); - this.whereCondition = whereCondition; - this.havingCondition = havingCondition; - this.groupBy = groupBy; this.orderBy = orderBy; this.offset = offset; this.limit = limit; @@ -57,38 +49,18 @@ public final class SQLSelect extends SQL visitor.visit(this); } - public boolean getIsDistinct() { - return isDistinct; - } - - public Collection<FieldAll> getFieldAlls() { - return fieldAlls; - } - - public Collection<FieldDef> getFieldDefs() { - return fieldDefs.values(); + public SelectGroup getSelectGroup() { + return selectGroup; } - public Table getTable() { - return table; + public Unioned getUnioned() { + return unioned; } public Map<String, Relation> getRelations() { return relations; } - public Condition getWhereCondition() { - return whereCondition; - } - - public Condition getHavingCondition() { - return havingCondition; - } - - public List<String> getGroupBy() { - return groupBy; - } - public List<OrderByItem> getOrderBy() { return orderBy; } @@ -107,46 +79,26 @@ public final class SQLSelect extends SQL } SQLSelect other = (SQLSelect) o; - return isDistinct == other.isDistinct - && equalsHelper(fieldAlls, other.fieldAlls) - && equalsHelper(fieldDefs, other.fieldDefs) - && table.equals(other.table) + return selectGroup.equals(other.selectGroup) + && equalsHelper(unioned, other.unioned) && equalsHelper(relations, other.relations) - && equalsHelper(whereCondition, other.whereCondition) - && equalsHelper(havingCondition, other.havingCondition) && offset == other.offset && limit == other.limit - && equalsHelper(groupBy, other.groupBy) && equalsHelper(orderBy, other.orderBy) ; } public StringBuilder appendTo(StringBuilder sb) { - sb.append("SELECT"); - if (isDistinct) { - sb.append(" DISTINCT"); + selectGroup.appendTo(sb); + if (unioned != null) { + unioned.appendTo(sb); } - if (fieldAlls != null) { - StringUtil.appendTo(sb, fieldAlls, " ", null, ","); - } - if (fieldAlls != null && fieldDefs != null) { - sb.append(','); - } - if (fieldDefs != null) { - StringUtil.appendTo(sb, fieldDefs.values(), " ", null, ","); - } - sb.append(" FROM "); - table.appendTo(sb); if (relations != null) { - StringUtil.appendTo(sb, relations.values(), " ", null, ","); + StringUtil.appendTo(sb, relations.values(), " ", null, null); } - if (whereCondition != null) { - sb.append(" WHERE "); - whereCondition.appendTo(sb); - } - if (havingCondition != null) { - sb.append(" HAVING "); - havingCondition.appendTo(sb); + if (orderBy != null) { + sb.append(" ORDER BY "); + StringUtil.append(sb, orderBy, null, null, ", "); } if (offset != -1) { sb.append(" OFFSET ").append(offset); @@ -154,14 +106,6 @@ public final class SQLSelect extends SQL if (limit != -1) { sb.append(" LIMIT ").append(limit); } - if (groupBy != null) { - sb.append(" GROUP BY "); - StringUtil.append(sb, groupBy, null, null, ", "); - } - if (orderBy != null) { - sb.append(" ORDER BY "); - StringUtil.append(sb, orderBy, null, null, ", "); - } sb.append(';'); return sb; } Modified: ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLStatement.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLStatement.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLStatement.java (original) +++ ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/SQLStatement.java Wed Aug 11 13:22:40 2010 @@ -21,11 +21,32 @@ package org.ofbiz.sql; public abstract class SQLStatement<S extends SQLStatement<S>> extends Atom { public interface Visitor { void visit(SQLDelete statement); + void visit(SQLIndex statement); void visit(SQLInsert statement); void visit(SQLSelect statement); void visit(SQLUpdate statement); void visit(SQLView statement); } + public static class BaseVisitor implements Visitor { + public void visit(SQLDelete statement) { + } + + public void visit(SQLIndex statement) { + } + + public void visit(SQLInsert statement) { + } + + public void visit(SQLSelect statement) { + } + + public void visit(SQLUpdate statement) { + } + + public void visit(SQLView statement) { + } + } + public abstract void accept(Visitor visitor); } Modified: ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/StringValue.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/StringValue.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/StringValue.java (original) +++ ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/StringValue.java Wed Aug 11 13:22:40 2010 @@ -18,6 +18,9 @@ */ package org.ofbiz.sql; +import org.ofbiz.base.lang.SourceMonitored; + +@SourceMonitored public final class StringValue extends ConstantValue { private final String str; Modified: ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Value.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Value.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Value.java (original) +++ ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/Value.java Wed Aug 11 13:22:40 2010 @@ -34,6 +34,7 @@ public abstract class Value extends Atom public static final Null NULL = new Null(); public interface Visitor { + void visit(AggregateFunction value); void visit(FieldValue value); void visit(FunctionCall value); void visit(MathValue value); @@ -41,9 +42,37 @@ public abstract class Value extends Atom void visit(NumberValue value); void visit(ParameterValue value); void visit(StringValue value); - void visit(CountFunction value); void visit(CountAllFunction value); } + public static class BaseVisitor implements Visitor { + public void visit(AggregateFunction value) { + } + + public void visit(FieldValue value) { + } + + public void visit(FunctionCall value) { + } + + public void visit(MathValue value) { + } + + public void visit(Null value) { + } + + public void visit(NumberValue value) { + } + + public void visit(ParameterValue value) { + } + + public void visit(StringValue value) { + } + + public void visit(CountAllFunction value) { + } + } + public abstract void accept(Visitor visitor); } Modified: ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/test/GoodParseAll.sql URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/test/GoodParseAll.sql?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/test/GoodParseAll.sql (original) +++ ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/test/GoodParseAll.sql Wed Aug 11 13:22:40 2010 @@ -33,10 +33,6 @@ FROM Party a LEFT JOIN Person b USING partyId LEFT JOIN PartyGroup c ON b.partyId = c.partyId JOIN PartyRole d ON c.partyId = d.partyId AND c.partyId = d.partyId -RELATION TYPE one TITLE MainA Person USING partyId -RELATION TITLE MainB Person USING partyId -RELATION TYPE one Person USING partyId -RELATION PartyGroup USING partyId WHERE a.partyTypeId = 'PERSON' AND @@ -52,8 +48,12 @@ WHERE HAVING b.firstName LIKE '%foo%' +RELATION TYPE one TITLE MainA Person MAP partyId +RELATION TITLE MainB Person MAP partyId +RELATION TYPE one Person MAP partyId +RELATION PartyGroup MAP partyId ORDER BY - LOWER(lastName), firstName, birthDate DESC + LOWER(lastName), firstName, -birthDate OFFSET 5 LIMIT 10 ; @@ -68,6 +68,7 @@ UPDATE Person SET lastName = ('auto-' || DELETE FROM Person WHERE partyId IN ('a', 'b'); DELETE FROM Party WHERE partyId IN ('a', 'b'); CREATE VIEW viewOne AS SELECT a.* FROM Party a; +CREATE INDEX testIndex ON Party USING btree (partyId); /* UPDATE Person SET firstName = partyId || '-auto' WHERE partyId IN ('a', 'b'); */ Modified: ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/test/SQLTest.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/test/SQLTest.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/test/SQLTest.java (original) +++ ofbiz/branches/jquery/framework/sql/src/org/ofbiz/sql/test/SQLTest.java Wed Aug 11 13:22:40 2010 @@ -18,28 +18,25 @@ */ package org.ofbiz.sql.test; +import java.io.StringReader; import java.net.URL; import java.util.Collections; import java.util.Iterator; import java.util.List; -import java.util.Map; - -import javolution.util.FastList; -import javolution.util.FastMap; - -import junit.framework.TestCase; +import org.ofbiz.base.test.GenericTestCaseBase; +import org.ofbiz.sql.AggregateFunction; import org.ofbiz.sql.BetweenCondition; import org.ofbiz.sql.BooleanCondition; import org.ofbiz.sql.Condition; import org.ofbiz.sql.ConditionList; -import org.ofbiz.sql.CountFunction; +import org.ofbiz.sql.ConstantValue; import org.ofbiz.sql.FieldAll; import org.ofbiz.sql.FieldDef; import org.ofbiz.sql.FieldValue; import org.ofbiz.sql.FunctionCall; -import org.ofbiz.sql.InsertValues; import org.ofbiz.sql.InsertRow; +import org.ofbiz.sql.InsertValues; import org.ofbiz.sql.Joined; import org.ofbiz.sql.Joiner; import org.ofbiz.sql.KeyMap; @@ -50,25 +47,28 @@ import org.ofbiz.sql.OrderByItem; import org.ofbiz.sql.ParameterValue; import org.ofbiz.sql.Parser; import org.ofbiz.sql.Relation; -import org.ofbiz.sql.SetField; import org.ofbiz.sql.SQLDelete; +import org.ofbiz.sql.SQLIndex; import org.ofbiz.sql.SQLInsert; import org.ofbiz.sql.SQLSelect; import org.ofbiz.sql.SQLStatement; import org.ofbiz.sql.SQLUpdate; import org.ofbiz.sql.SQLView; +import org.ofbiz.sql.SetField; import org.ofbiz.sql.StringValue; import org.ofbiz.sql.Table; import org.ofbiz.sql.TableName; import org.ofbiz.sql.Value; -import org.ofbiz.base.test.GenericTestCaseBase; - public class SQLTest extends GenericTestCaseBase { public SQLTest(String name) { super(name); } + private static Parser parser(SQLStatement s) throws Exception { + return new Parser(new StringReader(s.toString())); + } + public void testParse() throws Exception { List<SQLStatement<?>> statements = new Parser(getClass().getResourceAsStream("GoodParseAll.sql")).SQLFile(); for (SQLStatement<?> statement: statements) { @@ -88,12 +88,12 @@ public class SQLTest extends GenericTest GenericTestCaseBase.<String, FieldDef>map( "roleTypeId", new FieldDef(new FieldValue("d", "roleTypeId"), null), "roleDescription", new FieldDef(new FieldValue("d", "description"), "roleDescription"), - "SUM", new FieldDef(new FunctionCall("SUM", GenericTestCaseBase.<Value>list(new FieldValue("a", "partyId"))), null), + "SUM", new FieldDef(new AggregateFunction("SUM", false, new FieldValue("a", "partyId")), null), "baz", new FieldDef(new FunctionCall("FOO", GenericTestCaseBase.<Value>list(new FieldValue("a", "partyId"), new NumberValue<Integer>(Integer.valueOf(1)))), "baz"), "one", new FieldDef(new MathValue("||", list(new FieldValue("a", "partyId"), new StringValue("-"), new FieldValue("a", "partyTypeId"))), "one"), - "cnt1", new FieldDef(new CountFunction(false, new FieldValue("a", "partyId")), "cnt1"), - "cnt2", new FieldDef(new CountFunction(false, new FieldValue(null, "partyId")), "cnt2"), - "cnt3", new FieldDef(new CountFunction(true, new FieldValue("a", "partyId")), "cnt3") + "cnt1", new FieldDef(new AggregateFunction("COUNT", false, new FieldValue("a", "partyId")), "cnt1"), + "cnt2", new FieldDef(new AggregateFunction("COUNT", false, new FieldValue(null, "partyId")), "cnt2"), + "cnt3", new FieldDef(new AggregateFunction("COUNT", true, new FieldValue("a", "partyId")), "cnt3") ), new Table( new TableName("Party", "a"), @@ -137,15 +137,16 @@ public class SQLTest extends GenericTest new BooleanCondition(new FieldValue("b", "firstName"), "LIKE", new StringValue("%foo%")), null, list( - new OrderByItem(OrderByItem.Order.DEFAULT, "LOWER", "lastName"), - new OrderByItem(OrderByItem.Order.DEFAULT, null, "firstName"), - new OrderByItem(OrderByItem.Order.DESCENDING, null, "birthDate") + new OrderByItem(OrderByItem.Order.DEFAULT, OrderByItem.Nulls.DEFAULT, new FunctionCall("LOWER", GenericTestCaseBase.<Value>list(new FieldValue(null, "lastName")))), + new OrderByItem(OrderByItem.Order.DEFAULT, OrderByItem.Nulls.DEFAULT, new FieldValue(null, "firstName")), + new OrderByItem(OrderByItem.Order.DESCENDING, OrderByItem.Nulls.DEFAULT, new FieldValue(null, "birthDate")) ), 5, 10 ); SQLStatement stmt = stmtIt.next(); assertEquals("firstSelect", select, stmt); + assertEquals("firstSelect:parse", parser(select).SelectStatement(), parser(stmt).SelectStatement()); } { SQLInsert insert = new SQLInsert( @@ -160,6 +161,7 @@ public class SQLTest extends GenericTest ); SQLStatement stmt = stmtIt.next(); assertEquals("firstInsert", insert, stmt); + assertEquals("firstInsert:parse", parser(insert).InsertStatement(), parser(stmt).InsertStatement()); } { SQLInsert insert = new SQLInsert( @@ -184,6 +186,7 @@ public class SQLTest extends GenericTest ); SQLStatement stmt = stmtIt.next(); assertEquals("secondInsert", insert, stmt); + assertEquals("secondInsert:parse", parser(insert).InsertStatement(), parser(stmt).InsertStatement()); } { SQLUpdate update = new SQLUpdate( @@ -195,6 +198,7 @@ public class SQLTest extends GenericTest ); SQLStatement stmt = stmtIt.next(); assertEquals("firstUpdate", update, stmt); + assertEquals("firstUpdate:parse", parser(update).UpdateStatement(), parser(stmt).UpdateStatement()); } { SQLUpdate update = new SQLUpdate( @@ -208,6 +212,7 @@ public class SQLTest extends GenericTest ); SQLStatement stmt = stmtIt.next(); assertEquals("secondUpdate", update, stmt); + assertEquals("secondUpdate:parse", parser(update).UpdateStatement(), parser(stmt).UpdateStatement()); } { SQLUpdate update = new SQLUpdate( @@ -222,6 +227,7 @@ public class SQLTest extends GenericTest ); SQLStatement stmt = stmtIt.next(); assertEquals("thirdUpdate", update, stmt); + assertEquals("thirdUpdate:parse", parser(update).UpdateStatement(), parser(stmt).UpdateStatement()); } { SQLDelete delete = new SQLDelete( @@ -230,6 +236,7 @@ public class SQLTest extends GenericTest ); SQLStatement stmt = stmtIt.next(); assertEquals("firstDelete", delete, stmt); + assertEquals("firstDelete:parse", parser(delete).DeleteStatement(), parser(stmt).DeleteStatement()); } { SQLDelete delete = new SQLDelete( @@ -238,6 +245,7 @@ public class SQLTest extends GenericTest ); SQLStatement stmt = stmtIt.next(); assertEquals("secondDelete", delete, stmt); + assertEquals("secondDelete:parse", parser(delete).DeleteStatement(), parser(stmt).DeleteStatement()); } { SQLView view = new SQLView( @@ -258,7 +266,22 @@ public class SQLTest extends GenericTest ); SQLStatement stmt = stmtIt.next(); assertEquals("firstView", view, stmt); + assertEquals("firstView:parse", parser(view).ViewStatement(), parser(stmt).ViewStatement()); + } + { + SQLIndex index = new SQLIndex( + false, + "testIndex", + "Party", + "btree", + GenericTestCaseBase.<ConstantValue>list( + new FieldValue(null, "partyId") + ) + ); + SQLStatement stmt = stmtIt.next(); + assertEquals("firstIndex", index, stmt); } + assertFalse("has no more statements", stmtIt.hasNext()); } /* CREATE VIEW viewOne AS SELECT a.* FROM Party a; Modified: ofbiz/branches/jquery/framework/start/src/org/ofbiz/base/start/test.properties URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/start/src/org/ofbiz/base/start/test.properties?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/start/src/org/ofbiz/base/start/test.properties (original) +++ ofbiz/branches/jquery/framework/start/src/org/ofbiz/base/start/test.properties Wed Aug 11 13:22:40 2010 @@ -51,7 +51,7 @@ ofbiz.start.loader1=org.ofbiz.base.conta ofbiz.auto.shutdown=true ofbiz.instrumenterClassName=org.ofbiz.base.config.CoberturaInstrumenter -ofbiz.instrumenterFile=runtime/logs/cobertura.dat +ofbiz.instrumenterFile=runtime/logs/cobertura-base.dat # --- Default Derby system home directory #derby.system.home=runtime/data/derby Modified: ofbiz/branches/jquery/framework/testtools/config/seleniumXml.properties URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/testtools/config/seleniumXml.properties?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/testtools/config/seleniumXml.properties (original) +++ ofbiz/branches/jquery/framework/testtools/config/seleniumXml.properties Wed Aug 11 13:22:40 2010 @@ -22,4 +22,4 @@ proxyPort=4444 #browser=*firefox /usr/lib/iceweasel/firefox-bin browser=*firefox /usr/lib/firefox-3.0.8/firefox startUrl=http://localhost:8080/ -log4jFile=./config/log4j.properties \ No newline at end of file +log4jFile=./config/log4j.properties Modified: ofbiz/branches/jquery/framework/testtools/src/org/ofbiz/testtools/seleniumxml/DataLoop.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/testtools/src/org/ofbiz/testtools/seleniumxml/DataLoop.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/testtools/src/org/ofbiz/testtools/seleniumxml/DataLoop.java (original) +++ ofbiz/branches/jquery/framework/testtools/src/org/ofbiz/testtools/seleniumxml/DataLoop.java Wed Aug 11 13:22:40 2010 @@ -71,4 +71,4 @@ public class DataLoop { } currentTest.runCommands(this.children); } -} \ No newline at end of file +} Modified: ofbiz/branches/jquery/framework/testtools/widget/CommonScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/testtools/widget/CommonScreens.xml?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/testtools/widget/CommonScreens.xml (original) +++ ofbiz/branches/jquery/framework/testtools/widget/CommonScreens.xml Wed Aug 11 13:22:40 2010 @@ -97,4 +97,4 @@ </widgets> </section> </screen> -</screens> \ No newline at end of file +</screens> Modified: ofbiz/branches/jquery/framework/testtools/widget/RunSeleniumForms.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/testtools/widget/RunSeleniumForms.xml?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/testtools/widget/RunSeleniumForms.xml (original) +++ ofbiz/branches/jquery/framework/testtools/widget/RunSeleniumForms.xml Wed Aug 11 13:22:40 2010 @@ -57,4 +57,4 @@ </hyperlink> </field> </form> -</forms> \ No newline at end of file +</forms> Modified: ofbiz/branches/jquery/framework/webapp/config/fop.xconf URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webapp/config/fop.xconf?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webapp/config/fop.xconf (original) +++ ofbiz/branches/jquery/framework/webapp/config/fop.xconf Wed Aug 11 13:22:40 2010 @@ -42,6 +42,8 @@ the location of this file. value is specified as auto --> <default-page-settings height="11in" width="8.26in"/> + <prefer-renderer>true</prefer-renderer> + <!-- Information for specific renderers --> <!-- Uses renderer mime type for renderers --> <renderers> Modified: ofbiz/branches/jquery/framework/webapp/ofbiz-component.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webapp/ofbiz-component.xml?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webapp/ofbiz-component.xml (original) +++ ofbiz/branches/jquery/framework/webapp/ofbiz-component.xml Wed Aug 11 13:22:40 2010 @@ -31,5 +31,5 @@ under the License. <entity-resource type="model" reader-name="main" loader="main" location="entitydef/entitymodel.xml"/> - <test-suite loader="main" location="testdef/webapptests.xml"/> +<!--<test-suite loader="main" location="testdef/webapptests.xml"/>--> </ofbiz-component> Modified: ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java (original) +++ ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/control/ControlServlet.java Wed Aug 11 13:22:40 2010 @@ -18,6 +18,9 @@ *******************************************************************************/ package org.ofbiz.webapp.control; +import java.io.IOException; +import java.util.Enumeration; + import javax.servlet.RequestDispatcher; import javax.servlet.ServletConfig; import javax.servlet.ServletContext; @@ -26,11 +29,8 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; -import java.io.IOException; -import java.util.Enumeration; import org.apache.bsf.BSFManager; - import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilGenerics; @@ -45,10 +45,7 @@ import org.ofbiz.entity.GenericValue; import org.ofbiz.entity.transaction.GenericTransactionException; import org.ofbiz.entity.transaction.TransactionUtil; import org.ofbiz.security.Security; -import org.ofbiz.security.SecurityConfigurationException; -import org.ofbiz.security.SecurityFactory; import org.ofbiz.security.authz.Authorization; -import org.ofbiz.security.authz.AuthorizationFactory; import org.ofbiz.service.LocalDispatcher; import org.ofbiz.webapp.stats.ServerHitBin; import org.ofbiz.webapp.stats.VisitHandler; Modified: ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java (original) +++ ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/control/RequestHandler.java Wed Aug 11 13:22:40 2010 @@ -53,7 +53,6 @@ import org.ofbiz.webapp.event.EventFacto import org.ofbiz.webapp.event.EventHandler; import org.ofbiz.webapp.event.EventHandlerException; import org.ofbiz.webapp.stats.ServerHitBin; -import org.ofbiz.webapp.stats.VisitHandler; import org.ofbiz.webapp.view.ViewFactory; import org.ofbiz.webapp.view.ViewHandler; import org.ofbiz.webapp.view.ViewHandlerException; @@ -274,23 +273,20 @@ public class RequestHandler { } // If its the first visit run the first visit events. - if (this.trackVisit(request) && session.getAttribute("visit") == null) { + if (this.trackVisit(request) && session.getAttribute("_FIRST_VISIT_EVENTS_") == null) { if (Debug.infoOn()) Debug.logInfo("This is the first request in this visit." + " sessionId=" + UtilHttp.getSessionId(request), module); - // This isn't an event because it is required to run. We do not want to make it optional. - GenericValue visit = VisitHandler.getVisit(session); - if (visit != null) { - for (ConfigXMLReader.Event event: controllerConfig.getFirstVisitEventList().values()) { - try { - String returnString = this.runEvent(request, response, event, null, "firstvisit"); - if (returnString != null && !returnString.equalsIgnoreCase("success")) { - throw new EventHandlerException("First-Visit event did not return 'success'."); - } else if (returnString == null) { - interruptRequest = true; - } - } catch (EventHandlerException e) { - Debug.logError(e, module); + session.setAttribute("_FIRST_VISIT_EVENTS_", "complete"); + for (ConfigXMLReader.Event event: controllerConfig.getFirstVisitEventList().values()) { + try { + String returnString = this.runEvent(request, response, event, null, "firstvisit"); + if (returnString != null && !returnString.equalsIgnoreCase("success")) { + throw new EventHandlerException("First-Visit event did not return 'success'."); + } else if (returnString == null) { + interruptRequest = true; } + } catch (EventHandlerException e) { + Debug.logError(e, module); } } } Modified: ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java (original) +++ ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/event/ServiceMultiEventHandler.java Wed Aug 11 13:22:40 2010 @@ -261,6 +261,11 @@ public class ServiceMultiEventHandler im } } + // make any composite parameter data (e.g., from a set of parameters {name_c_date, name_c_hour, name_c_minutes}) + if (value == null) { + value = UtilHttp.makeParamValueFromComposite(request, paramName + curSuffix, locale); + } + if (value == null) { // still null, give up for this one continue; Modified: ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopWorker.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopWorker.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopWorker.java (original) +++ ofbiz/branches/jquery/framework/webapp/src/org/ofbiz/webapp/view/ApacheFopWorker.java Wed Aug 11 13:22:40 2010 @@ -82,11 +82,8 @@ public class ApacheFopWorker { String fopPath = UtilProperties.getPropertyValue("fop.properties", "fop.path", ofbizHome + "/framework/webapp/config"); File userConfigFile = FileUtil.getFile(fopPath + "/fop.xconf"); fopFactory.setUserConfig(userConfigFile); - String fopFontBaseUrl = fopFactory.getFontBaseURL(); - if (fopFontBaseUrl == null) { - fopFontBaseUrl = UtilProperties.getPropertyValue("fop.properties", "fop.font.base.url", "file:///" + ofbizHome + "/framework/webapp/config/"); - fopFactory.setFontBaseURL(fopFontBaseUrl); - } + String fopFontBaseUrl = UtilProperties.getPropertyValue("fop.properties", "fop.font.base.url", "file:///" + ofbizHome + "/framework/webapp/config/"); + fopFactory.getFontManager().setFontBaseURL(fopFontBaseUrl); Debug.logInfo("FOP-FontBaseURL: " + fopFontBaseUrl, module); } catch (Exception e) { Debug.logWarning("Error reading FOP configuration", module); Modified: ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java (original) +++ ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/WebToolsServices.java Wed Aug 11 13:22:40 2010 @@ -121,7 +121,6 @@ public class WebToolsServices { if (txTimeout == null) { txTimeout = Integer.valueOf(7200); } - InputSource ins = null; URL url = null; // ############################# @@ -130,8 +129,6 @@ public class WebToolsServices { if (UtilValidate.isNotEmpty(filename)) { try { url = isUrl?FlexibleLocation.resolveLocation(filename):UtilURL.fromFilename(filename); - InputStream is = url.openStream(); - ins = new InputSource(is); } catch (MalformedURLException mue) { return ServiceUtil.returnError("ERROR: invalid file name (" + filename + "): " + mue.getMessage()); } catch (IOException ioe) { @@ -142,18 +139,9 @@ public class WebToolsServices { } // ############################# - // The text to parse is prepared - // ############################# - if (UtilValidate.isNotEmpty(fulltext)) { - StringReader sr = new StringReader(fulltext); - ins = new InputSource(sr); - } - - // ############################# // FM Template // ############################# - String s = null; - if (UtilValidate.isNotEmpty(fmfilename) && ins != null) { + if (UtilValidate.isNotEmpty(fmfilename) && (UtilValidate.isNotEmpty(fulltext) || url != null)) { FileReader templateReader = null; try { templateReader = new FileReader(fmfilename); @@ -169,14 +157,25 @@ public class WebToolsServices { template = new Template("FMImportFilter", templateReader, conf); Map<String, Object> fmcontext = FastMap.newInstance(); - NodeModel nodeModel = NodeModel.parse(ins); + InputSource ins = url != null ? new InputSource(url.openStream()) : new InputSource(new StringReader(fulltext)); + NodeModel nodeModel; + try { + nodeModel = NodeModel.parse(ins); + } finally { + if (ins.getByteStream() != null) { + ins.getByteStream().close(); + } + if (ins.getCharacterStream() != null) { + ins.getCharacterStream().close(); + } + } fmcontext.put("doc", nodeModel); BeansWrapper wrapper = BeansWrapper.getDefaultInstance(); TemplateHashModel staticModels = wrapper.getStaticModels(); fmcontext.put("Static", staticModels); template.process(fmcontext, outWriter); - s = outWriter.toString(); + fulltext = outWriter.toString(); } catch (Exception ex) { return ServiceUtil.returnError("ERROR processing template file (" + fmfilename + "): " + ex.getMessage()); } @@ -185,7 +184,7 @@ public class WebToolsServices { // ############################# // The parsing takes place // ############################# - if (s != null || fulltext != null || url != null) { + if (fulltext != null || url != null) { try { Map<String, Object> inputMap = UtilMisc.toMap("mostlyInserts", mostlyInserts, "createDummyFks", createDummyFks, @@ -193,14 +192,10 @@ public class WebToolsServices { "maintainTimeStamps", maintainTimeStamps, "txTimeout", txTimeout, "userLogin", userLogin); - if (s != null) { - inputMap.put("xmltext", s); + if (fulltext != null) { + inputMap.put("xmltext", fulltext); } else { - if (fulltext != null) { - inputMap.put("xmltext", fulltext); - } else { - inputMap.put("url", url); - } + inputMap.put("url", url); } Map<String, Object> outputMap = dispatcher.runSync("parseEntityXmlFile", inputMap); if (ServiceUtil.isError(outputMap)) { Modified: ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java (original) +++ ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/artifactinfo/ArtifactInfoFactory.java Wed Aug 11 13:22:40 2010 @@ -23,7 +23,6 @@ import java.io.IOException; import java.net.MalformedURLException; import java.net.URL; import java.util.Collection; -import java.util.Iterator; import java.util.List; import java.util.Map; import java.util.Set; Modified: ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java (original) +++ ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/labelmanager/LabelManagerFactory.java Wed Aug 11 13:22:40 2010 @@ -165,7 +165,7 @@ public class LabelManagerFactory { } public Set<String> getLocalesFound() { - return localesFound; + return new TreeSet<String>(localesFound); } public static Collection<LabelFile> getFilesFound() { Modified: ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java (original) +++ ofbiz/branches/jquery/framework/webtools/src/org/ofbiz/webtools/labelmanager/SaveLabelsToXmlFile.java Wed Aug 11 13:22:40 2010 @@ -81,6 +81,9 @@ public class SaveLabelsToXmlFile { Map<String, LabelInfo> labels = factory.getLabels(); Set<String> labelsList = factory.getLabelsList(); Set<String> localesFound = factory.getLocalesFound(); + for (String localeName : localeNames) { + localesFound.add(localeName); + } // Remove a Label if (UtilValidate.isNotEmpty(removeLabel)) { labels.remove(key + LabelManagerFactory.keySeparator + fileName); Modified: ofbiz/branches/jquery/framework/webtools/webapp/webtools/WEB-INF/actions/service/AvailableServices.groovy URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webtools/webapp/webtools/WEB-INF/actions/service/AvailableServices.groovy?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webtools/webapp/webtools/WEB-INF/actions/service/AvailableServices.groovy (original) +++ ofbiz/branches/jquery/framework/webtools/webapp/webtools/WEB-INF/actions/service/AvailableServices.groovy Wed Aug 11 13:22:40 2010 @@ -421,6 +421,7 @@ if (selectedService) { curInParam.internal = curParam.internal ? uiLabelMap.CommonTrue : uiLabelMap.CommonFalse; curInParam.mode = curParam.mode; curInParam.name = curParam.name; + curInParam.description = curParam.description; curInParam.optional = curParam.optional ? uiLabelMap.CommonTrue : uiLabelMap.CommonFalse; curInParam.type = curParam.type; inParamsList.add(curInParam); @@ -440,6 +441,7 @@ if (selectedService) { curOutParam.internal = curParam.internal ? uiLabelMap.CommonTrue : uiLabelMap.CommonFalse; curOutParam.mode = curParam.mode; curOutParam.name = curParam.name; + curOutParam.description = curParam.description; curOutParam.optional = curParam.optional ? uiLabelMap.CommonTrue : uiLabelMap.CommonFalse; curOutParam.type = curParam.type; outParamsList.add(curOutParam); @@ -458,6 +460,7 @@ if (selectedService) { curOvrPrm.internal = curParam.internal ? uiLabelMap.CommonTrue : uiLabelMap.CommonFalse; curOvrPrm.mode = curParam.mode; curOvrPrm.name = curParam.name; + curOvrParam.description = curParam.description; curOvrPrm.optional = curParam.optional ? uiLabelMap.CommonTrue : uiLabelMap.CommonFalse; curOvrPrm.type = curParam.type; ovrPrmList.add(curOvrPrm); Modified: ofbiz/branches/jquery/framework/webtools/webapp/webtools/service/availableservices.ftl URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webtools/webapp/webtools/service/availableservices.ftl?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webtools/webapp/webtools/service/availableservices.ftl (original) +++ ofbiz/branches/jquery/framework/webtools/webapp/webtools/service/availableservices.ftl Wed Aug 11 13:22:40 2010 @@ -271,14 +271,21 @@ under the License. <#-- End if service has ECA's --> <#list selectedServiceMap.allParamsList?if_exists as paramList> + <style type="text/css"> + .param-table tr td { + width: 12.5%; + vertical-align: top; + } + </style> <div class="screenlet"> <div class="screenlet-title-bar"> <h3>${paramList.title}</h3> </div> <#if paramList.paramList?exists && paramList.paramList?has_content> - <table class="basic-table" cellspacing='0'> + <table class="basic-table param-table" cellspacing='0'> <tr class="header-row"> <td>${uiLabelMap.WebtoolsParameterName}</td> + <td>${uiLabelMap.CommonDescription}</td> <td>${uiLabelMap.WebtoolsOptional}</td> <td>${uiLabelMap.CommonType}</td> <#-- <td>Default Value</td> --> @@ -290,6 +297,7 @@ under the License. <#list paramList.paramList as modelParam> <tr> <td>${modelParam.name?if_exists}</td> + <td>${modelParam.description?if_exists}</td> <td>${modelParam.optional?if_exists}</td> <td>${modelParam.type?if_exists}</td> <#-- <td>[${modelParam.defaultValue?if_exists}]</td> --> Modified: ofbiz/branches/jquery/framework/webtools/widget/CacheScreens.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webtools/widget/CacheScreens.xml?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webtools/widget/CacheScreens.xml (original) +++ ofbiz/branches/jquery/framework/webtools/widget/CacheScreens.xml Wed Aug 11 13:22:40 2010 @@ -112,4 +112,4 @@ under the License. </widgets> </section> </screen> -</screens> \ No newline at end of file +</screens> Modified: ofbiz/branches/jquery/framework/webtools/widget/LogForms.xml URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/webtools/widget/LogForms.xml?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/webtools/widget/LogForms.xml (original) +++ ofbiz/branches/jquery/framework/webtools/widget/LogForms.xml Wed Aug 11 13:22:40 2010 @@ -71,4 +71,4 @@ under the License. </field> <field name="submit" title="${uiLabelMap.CommonUpdate}"><submit/></field> </form> -</forms> \ No newline at end of file +</forms> Modified: ofbiz/branches/jquery/framework/widget/dtd/widget-menu.xsd URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/widget/dtd/widget-menu.xsd?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/widget/dtd/widget-menu.xsd (original) +++ ofbiz/branches/jquery/framework/widget/dtd/widget-menu.xsd Wed Aug 11 13:22:40 2010 @@ -220,6 +220,7 @@ under the License. </xs:simpleType> </xs:attribute> <xs:attribute name="confirmation-message" type="xs:string"><xs:annotation><xs:documentation>The message displayed when request-confirm is set to true</xs:documentation></xs:annotation></xs:attribute> + <xs:attribute name="parameters-map" type="xs:string"/> </xs:attributeGroup> <xs:element name="parameter"> <xs:complexType> Modified: ofbiz/branches/jquery/framework/widget/src/org/ofbiz/widget/ModelWidget.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/widget/src/org/ofbiz/widget/ModelWidget.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/widget/src/org/ofbiz/widget/ModelWidget.java (original) +++ ofbiz/branches/jquery/framework/widget/src/org/ofbiz/widget/ModelWidget.java Wed Aug 11 13:22:40 2010 @@ -20,10 +20,10 @@ package org.ofbiz.widget; import java.io.Serializable; import java.util.Map; -import org.w3c.dom.Element; -import org.ofbiz.base.util.Debug; + import org.ofbiz.base.util.UtilGenerics; import org.ofbiz.base.util.UtilProperties; +import org.w3c.dom.Element; /** * Widget Library - Widget model class. ModelWidget is a base class that is Modified: ofbiz/branches/jquery/framework/widget/src/org/ofbiz/widget/WidgetWorker.java URL: http://svn.apache.org/viewvc/ofbiz/branches/jquery/framework/widget/src/org/ofbiz/widget/WidgetWorker.java?rev=984399&r1=984398&r2=984399&view=diff ============================================================================== --- ofbiz/branches/jquery/framework/widget/src/org/ofbiz/widget/WidgetWorker.java (original) +++ ofbiz/branches/jquery/framework/widget/src/org/ofbiz/widget/WidgetWorker.java Wed Aug 11 13:22:40 2010 @@ -29,6 +29,7 @@ import javax.servlet.ServletContext; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import org.ofbiz.base.util.Debug; import org.ofbiz.base.util.StringUtil; import org.ofbiz.base.util.UtilDateTime; import org.ofbiz.base.util.UtilGenerics; @@ -98,6 +99,26 @@ public class WidgetWorker { } for (Map.Entry<String, String> parameter: parameterMap.entrySet()) { + String parameterValue = null; + if (parameter.getValue() instanceof String) { + parameterValue = parameter.getValue(); + } else { + Object parameterObject = parameter.getValue(); + + // skip null values + if (parameterObject == null) continue; + + if (parameterObject instanceof String[]) { + // it's probably a String[], just get the first value + String[] parameterArray = (String[]) parameterObject; + parameterValue = parameterArray[0]; + Debug.logInfo("Found String array value for parameter [" + parameter.getKey() + "], using first value: " + parameterValue, module); + } else { + // not a String, and not a String[], just use toString + parameterValue = parameterObject.toString(); + } + } + if (needsAmp) { externalWriter.append("&"); } else { @@ -107,9 +128,9 @@ public class WidgetWorker { externalWriter.append('='); StringUtil.SimpleEncoder simpleEncoder = (StringUtil.SimpleEncoder) context.get("simpleEncoder"); if (simpleEncoder != null) { - externalWriter.append(simpleEncoder.encode(parameter.getValue())); + externalWriter.append(simpleEncoder.encode(parameterValue)); } else { - externalWriter.append(parameter.getValue()); + externalWriter.append(parameterValue); } } } else { |
| Free forum by Nabble | Edit this page |
