EMMA Coverage Report (generated Mon Apr 21 23:56:41 GMT 2008)
[all classes][org.sqlorm.querybuilder]

COVERAGE SUMMARY FOR SOURCE FILE [AndOrList.java]

nameclass, %method, %block, %line, %
AndOrList.java100% (1/1)90%  (9/10)88%  (148/168)92%  (33,2/36)

COVERAGE BREAKDOWN BY CLASS AND METHOD

nameclass, %method, %block, %line, %
     
class AndOrList100% (1/1)90%  (9/10)88%  (148/168)92%  (33,2/36)
AndOrList (): void 100% (1/1)100% (11/11)100% (3/3)
and (IPositionAndOr): ItfAndOrList 100% (1/1)100% (10/10)100% (2/2)
and (String): ItfAndOrList 100% (1/1)100% (16/16)100% (2/2)
and (String, Object []): ItfAndOrList 100% (1/1)100% (15/15)100% (2/2)
internal_setIsOutermostList (): void 100% (1/1)100% (4/4)100% (2/2)
internal_size (): int 100% (1/1)100% (4/4)100% (1/1)
or (IPositionAndOr): ItfAndOrList 100% (1/1)100% (10/10)100% (2/2)
or (String): ItfAndOrList 100% (1/1)100% (16/16)100% (2/2)
or (String, Object []): ItfAndOrList 0%   (0/1)0%   (0/15)0%   (0/2)
toSql (StringBuilder, String): void 100% (1/1)93%  (62/67)95%  (17,2/18)

1package org.sqlorm.querybuilder;
2 
3import java.util.ArrayList;
4import java.util.List;
5 
6/**
7 * Internal helper class for query generation. Implements <tt>IPositionAndOr</tt> as you can say
8 * <tt>.and( new AndOrList().and(boo).and(bar)</tt>
9 * 
10 * @author kasper graversen
11 */
12public class AndOrList implements ItfAndOrList {
13private final List<IPositionAndOr> andOrs = new ArrayList<IPositionAndOr>();
14 
15/**
16 * if true, do not add "()" around the entries of the list
17 */
18private boolean isOutermostList = false;
19 
20public ItfAndOrList and(final IPositionAndOr andOr) {
21        this.andOrs.add(new AndExpr(andOr));
22        return this;
23}
24 
25public ItfAndOrList and(final String sqlString) {
26        this.andOrs.add(new AndExpr(new ExprString(QueryBuilderHelper.format(sqlString, new Object[0]))));
27        return this;
28}
29 
30public ItfAndOrList and(final String fmtString, final Object... args) {
31        this.andOrs.add(new AndExpr(new ExprString(QueryBuilderHelper.format(fmtString, args))));
32        return this;
33}
34 
35public ItfAndOrList or(final IPositionAndOr andOr) {
36        this.andOrs.add(new OrExpr(andOr));
37        return this;
38}
39 
40public ItfAndOrList or(final String sqlString) {
41        this.andOrs.add(new OrExpr(new ExprString(QueryBuilderHelper.format(sqlString, new Object[0]))));
42        return this;
43}
44 
45public ItfAndOrList or(final String fmtString, final Object... args) {
46        this.andOrs.add(new OrExpr(new ExprString(QueryBuilderHelper.format(fmtString, args))));
47        return this;
48}
49 
50/**
51 * internal method! Use this method when creating InnerJoin expressions or other elements that contains lists, where
52 * that list may be nested in other lists. But where the outermost list must be formatted differently than the nested
53 * lists.
54 */
55public void internal_setIsOutermostList() {
56        this.isOutermostList = true;
57}
58 
59/**
60 * internal method!
61 */
62public int internal_size() {
63        return andOrs.size();
64}
65 
66public void toSql(final StringBuilder sb, final String indent) {
67        if(isOutermostList == false) {
68                sb.append("(");
69        }
70 
71        boolean first = true;
72        for(final IPositionAndOr ao : andOrs) {
73                if(first) {
74                        first = false;
75                        ao.toSql(sb, indent); // add with no 'and' or 'or' prepended
76                        continue;
77                }
78 
79                if(ao instanceof AndExpr) {
80                        sb.append(" AND ");
81                        ao.toSql(sb, indent);
82                }
83                else if(ao instanceof OrExpr) {
84                        sb.append(" OR ");
85                        ao.toSql(sb, indent);
86                }
87                else {
88                        throw new IllegalStateException("can never reach here");
89                }
90        }
91 
92        if(isOutermostList == false) {
93                sb.append(")");
94        }
95 
96}
97}

[all classes][org.sqlorm.querybuilder]
EMMA 2.0.5312 (C) Vladimir Roubtsov