SelectModifier.java

biz/hammurapi/sql/syntax/SelectModifier.java

Violations

Inspector Message Severity Location
Java Inspector 048 Copyrights information should be present in each file. 1
Java Inspector 070-B Cyclomatic complexity is too high: 28, maximum allowed is 20 1 107:9
Java Inspector 086 Use equals() instead of == or != to compare objects. 1 112:32
Java Inspector 015 Do not change parameter value. For comprehensibility, formal parameters should be final 2 84:25
Java Inspector 015 Do not change parameter value. For comprehensibility, formal parameters should be final 2 87:25
Java Inspector 015 Do not change parameter value. For comprehensibility, formal parameters should be final 2 90:25
Java Inspector 070-A Cyclomatic complexity is too high: 28, maximum allowed is 12 2 107:9
Java Inspector 073 [java.lang.StringBuffer] In Java 5 use StringBuilder instead of StringBuffer if access is single-threaded, e.g. StringBuffer is used as a local variable . 2 47:17
Java Inspector 082 Parenthesis are redundant. 2 98:44
Java Inspector 082 Parenthesis are redundant. 2 99:44
Java Inspector 082 Parenthesis are redundant. 2 100:44
Java Inspector 082 Parenthesis are redundant. 2 101:44
Java Inspector 082 Parenthesis are redundant. 2 102:44
Java Inspector 082 Parenthesis are redundant. 2 103:44
Java Inspector 089 Undocumented top level type 2 9:1
Java Inspector 089 Undocumented method 2 18:9
Java Inspector 089 Undocumented method 2 22:9
Java Inspector 089 Undocumented method 2 26:9
Java Inspector 089 Undocumented method 2 30:9
Java Inspector 089 Undocumented method 2 34:9
Java Inspector 089 Undocumented method 2 38:9
Java Inspector 089 Undocumented method 2 42:9
Java Inspector 089 Undocumented method 2 46:9
Java Inspector 089 Undocumented method 2 82:9
Java Inspector 089 Undocumented method 2 95:9
Java Inspector 089 Undocumented method 2 107:9
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 109:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 111:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 113:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 117:33
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 119:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 122:33
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 124:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 127:33
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 129:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 132:33
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 134:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 137:33
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 139:25
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 142:33
Java Inspector 003 do, while, if, and for statements need a brace enclosed block 3 144:25
Java Inspector 025 Avoid hardwired numeric literals. Allowed literals: [1, -1, 0] 3 96:35
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 27:45
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 49:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 53:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 57:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 61:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 66:52
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 71:36
Java Inspector 026 Avoid hardwired string literals. Allowed literals: [] 3 74:44

Source code

1package biz.hammurapi.sql.syntax;
2
3import java.sql.PreparedStatement;
4import java.sql.SQLException;
5import java.util.ArrayList;
6import java.util.Iterator;
7import java.util.List;
8
9public class SelectModifier implements StatementFragment {
10
11 private StatementFragment where;
12 private StatementFragment groupBy;
13 private List orderBy = new ArrayList();
14 private StatementFragment having;
15 private Integer limit;
16 private Integer offset;
17
18 public void setWhere(StatementFragment where) {
19 this.where = where;
20 }
21
22 public void setGroupBy(StatementFragment groupBy) {
23 this.groupBy = groupBy;
24 }
25
26 public void addOrderBy(String column, boolean desc) {
27 orderBy.add(desc ? column + " DESC" : column);
28 }
29
30 public void addOrderBy(String column) {
31 orderBy.add(column);
32 }
33
34 public void setHaving(StatementFragment having) {
35 this.having = having;
36 }
37
38 public void setLimit(int limit) {
39 this.limit = new Integer(limit);
40 }
41
42 public void setOffset(int offset) {
43 this.offset = new Integer(offset);
44 }
45
46 public String toSqlString() {
47 StringBuffer ret = new StringBuffer();
48 if (where!=null) {
49 ret.append(" WHERE ");
50 ret.append(where.toSqlString());
51 }
52 if (groupBy!=null) {
53 ret.append(" GROUP BY ");
54 ret.append(groupBy.toSqlString());
55 }
56 if (having!=null) {
57 ret.append(" HAVING ");
58 ret.append(having.toSqlString());
59 }
60 if (!orderBy.isEmpty()) {
61 ret.append(" ORDER BY ");
62 Iterator it = orderBy.iterator();
63 while (it.hasNext()) {
64 ret.append(it.next());
65 if (it.hasNext()) {
66 ret.append(", ");
67 }
68 }
69 }
70 if (limit!=null) {
71 ret.append(" LIMIT ");
72 ret.append(limit);
73 if (offset!=null) {
74 ret.append(" OFFSET ");
75 ret.append(offset);
76 }
77 }
78
79 return ret.toString();
80 }
81
82 public int parameterize(PreparedStatement ps, int idx) throws SQLException {
83 if (where!=null) {
84 idx = where.parameterize(ps, idx);
85 }
86 if (groupBy!=null) {
87 idx = groupBy.parameterize(ps, idx);
88 }
89 if (having!=null) {
90 idx = having.parameterize(ps, idx);
91 }
92 return idx;
93 }
94
95 public int hashCode() {
96 final int prime = 31;
97 int result = 1;
98 result = prime * result + ((groupBy == null) ? 0 : groupBy.hashCode());
99 result = prime * result + ((having == null) ? 0 : having.hashCode());
100 result = prime * result + ((limit == null) ? 0 : limit.hashCode());
101 result = prime * result + ((offset == null) ? 0 : offset.hashCode());
102 result = prime * result + ((orderBy == null) ? 0 : orderBy.hashCode());
103 result = prime * result + ((where == null) ? 0 : where.hashCode());
104 return result;
105 }
106
107 public boolean equals(Object obj) {
108 if (this == obj)
109 return true;
110 if (obj == null)
111 return false;
112 if (getClass() != obj.getClass())
113 return false;
114 final SelectModifier other = (SelectModifier) obj;
115 if (groupBy == null) {
116 if (other.groupBy != null)
117 return false;
118 } else if (!groupBy.equals(other.groupBy))
119 return false;
120 if (having == null) {
121 if (other.having != null)
122 return false;
123 } else if (!having.equals(other.having))
124 return false;
125 if (limit == null) {
126 if (other.limit != null)
127 return false;
128 } else if (!limit.equals(other.limit))
129 return false;
130 if (offset == null) {
131 if (other.offset != null)
132 return false;
133 } else if (!offset.equals(other.offset))
134 return false;
135 if (orderBy == null) {
136 if (other.orderBy != null)
137 return false;
138 } else if (!orderBy.equals(other.orderBy))
139 return false;
140 if (where == null) {
141 if (other.where != null)
142 return false;
143 } else if (!where.equals(other.where))
144 return false;
145 return true;
146 }
147
148}
149