BrightSide Workbench Full Report + Source Code
org.turro.elephant.db.WhereClause Class Reference

Public Member Functions

 WhereClause ()
 
 WhereClause (String prefix)
 
Map< String, Object > getAttributes ()
 
void addClause (String clause)
 
void addClauseIfNotExists (String clause)
 
void addInRange (String operator, String startField, String endField, String attribute, Date date)
 
void addValue (Object value)
 
void addNamedValue (String name, Object value)
 
void addLikeFields (String[] fields, String value)
 
Map< String, Object > getNamedValues ()
 
List< Object > getNamedValues (String ... name)
 
int getValueCount ()
 
Object getValue (int index)
 
String getClause ()
 
void setClause (String clause)
 
void setOrderByClause (String orderByClause)
 
void setGroupByClause (String groupByClause)
 
boolean isUseNative ()
 
void setUseNative (boolean useNative)
 
Class getResultClass ()
 
void setResultClass (Class resultClass)
 
int getUniqueSuffix ()
 
Object[] getValues ()
 
void setParameters (Query q, int start)
 
void setNamedParameters (Query q)
 
String getFieldOcurrence ()
 
void setFieldOcurrence (String fieldOcurrence)
 
String getPrefix ()
 
void setPrefix (String prefix)
 
void addNotIn (String operator, String field, List values)
 
void addIn (String operator, String field, List values)
 
String getUniqueVariable (String prefix)
 

Static Public Member Functions

static WhereClause getFromClause (String clause)
 

Detailed Description

Author
Lluis TurrĂ³ Cutiller lluis.nosp@m.@tur.nosp@m.ro.or.nosp@m.g

Definition at line 32 of file WhereClause.java.

Constructor & Destructor Documentation

◆ WhereClause() [1/2]

org.turro.elephant.db.WhereClause.WhereClause ( )

Definition at line 45 of file WhereClause.java.

45  {
46  }
Here is the caller graph for this function:

◆ WhereClause() [2/2]

org.turro.elephant.db.WhereClause.WhereClause ( String  prefix)

Definition at line 48 of file WhereClause.java.

48  {
49  this.prefix = prefix;
50  }

Member Function Documentation

◆ addClause()

void org.turro.elephant.db.WhereClause.addClause ( String  clause)

Definition at line 56 of file WhereClause.java.

56  {
57  this.clause += " " + clause;
58  }

◆ addClauseIfNotExists()

void org.turro.elephant.db.WhereClause.addClauseIfNotExists ( String  clause)

Definition at line 60 of file WhereClause.java.

60  {
61  if(this.clause == null || !this.clause.contains(clause)) {
62  this.clause += " " + clause;
63  }
64  }

◆ addIn()

void org.turro.elephant.db.WhereClause.addIn ( String  operator,
String  field,
List  values 
)

Definition at line 204 of file WhereClause.java.

204  {
205  if(values == null || values.isEmpty()) {
206  addClause((operator != null ? operator + " 1=2" : "1=2"));
207  } else {
208  int listSize = values.size();
209  if(listSize <= IN_LIMIT) {
210  String var = getUniqueVariable("intids");
211  addClause((operator != null ? operator + " " : "") + field + " in (:"+ var + ")");
212  addNamedValue(var, values);
213  } else {
214  addClause((operator != null ? operator + " (" : "("));
215  String sep = "";
216  for (int i = 0; i < listSize; i += IN_LIMIT) {
217  String var = getUniqueVariable("intids");
218  List subList = (listSize > i + IN_LIMIT) ?
219  values.subList(i, (i + IN_LIMIT)) :
220  values.subList(i, listSize);
221  addClause(sep + field + " in (:" + var + ")");
222  addNamedValue(var, subList);
223  sep = "or ";
224  }
225  addClause(")");
226  }
227  }
228  }
String getUniqueVariable(String prefix)
void addNamedValue(String name, Object value)
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addInRange()

void org.turro.elephant.db.WhereClause.addInRange ( String  operator,
String  startField,
String  endField,
String  attribute,
Date  date 
)

Definition at line 66 of file WhereClause.java.

66  {
67  addClause(operator + "(");
68  addClause("(" + startField + " is null or " + startField + " >= :" + attribute + ")");
69  addClause("and (" + endField + " is null or " + endField + " <= :" + attribute + ")");
70  addClause(")");
71  addNamedValue(attribute, date);
72  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addLikeFields()

void org.turro.elephant.db.WhereClause.addLikeFields ( String[]  fields,
String  value 
)

Definition at line 82 of file WhereClause.java.

82  {
83  if(value == null) return;
84  if(value.startsWith("=") || value.startsWith("?")) {
85  SQLHelper.getWhereClause(this, fields, value);
86  } else if(value.startsWith("\"") && value.endsWith("\"")) {
87  value = value.substring(1, value.length() - 1);
88  SQLHelper.getWhereClause(this, fields,
89  (value == null ? "" : value.replaceAll("\\*", "%").replaceAll("\\?", "_")), null);
90  } else {
91  SQLHelper.getWhereClause(this, fields,
92  (value == null ? "" : value.replaceAll("\\*", "%").replaceAll("\\?", "_")), " +");
93  }
94  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ addNamedValue()

void org.turro.elephant.db.WhereClause.addNamedValue ( String  name,
Object  value 
)

Definition at line 78 of file WhereClause.java.

78  {
79  namedValues.put(name, value);
80  }

◆ addNotIn()

void org.turro.elephant.db.WhereClause.addNotIn ( String  operator,
String  field,
List  values 
)

Definition at line 200 of file WhereClause.java.

200  {
201  addIn(operator, field + " not", values);
202  }
void addIn(String operator, String field, List values)
Here is the call graph for this function:

◆ addValue()

void org.turro.elephant.db.WhereClause.addValue ( Object  value)

Definition at line 74 of file WhereClause.java.

74  {
75  values.add(value);
76  }

◆ getAttributes()

Map<String, Object> org.turro.elephant.db.WhereClause.getAttributes ( )

Definition at line 52 of file WhereClause.java.

52  {
53  return attributes;
54  }
Here is the caller graph for this function:

◆ getClause()

String org.turro.elephant.db.WhereClause.getClause ( )

Definition at line 116 of file WhereClause.java.

116  {
117  if(!Strings.isBlank(clause)) {
118  if(!Strings.isBlank(groupByClause) && clause.toLowerCase().contains("group by")) {
119  clause += " " + groupByClause;
120  }
121  if(!Strings.isBlank(orderByClause) && clause.toLowerCase().contains("order by")) {
122  clause += " " + orderByClause;
123  }
124  }
125  if(clause.matches(".*\\{[^\\}]+\\}.*")) {
126  clause = clause.replaceAll("\\{([^\\}]+)\\}", useNative ? "*" : "$1");
127  }
128  return clause;
129  }
Here is the caller graph for this function:

◆ getFieldOcurrence()

String org.turro.elephant.db.WhereClause.getFieldOcurrence ( )

Definition at line 180 of file WhereClause.java.

180  {
181  return fieldOcurrence;
182  }

◆ getFromClause()

static WhereClause org.turro.elephant.db.WhereClause.getFromClause ( String  clause)
static

Definition at line 236 of file WhereClause.java.

236  {
237  WhereClause wc = new WhereClause();
238  wc.addClause(clause);
239  return wc;
240  }
Here is the call graph for this function:

◆ getNamedValues() [1/2]

Map<String, Object> org.turro.elephant.db.WhereClause.getNamedValues ( )

Definition at line 96 of file WhereClause.java.

96  {
97  return namedValues;
98  }

◆ getNamedValues() [2/2]

List<Object> org.turro.elephant.db.WhereClause.getNamedValues ( String ...  name)

Definition at line 100 of file WhereClause.java.

100  {
101  ArrayList<Object> list = new ArrayList<>();
102  for(String n : name) {
103  if(namedValues.containsKey(n)) list.add(namedValues.get(n));
104  }
105  return list;
106  }

◆ getPrefix()

String org.turro.elephant.db.WhereClause.getPrefix ( )

Definition at line 189 of file WhereClause.java.

189  {
190  return prefix;
191  }
Here is the caller graph for this function:

◆ getResultClass()

Class org.turro.elephant.db.WhereClause.getResultClass ( )

Definition at line 151 of file WhereClause.java.

151  {
152  return resultClass;
153  }
Here is the caller graph for this function:

◆ getUniqueSuffix()

int org.turro.elephant.db.WhereClause.getUniqueSuffix ( )

Definition at line 159 of file WhereClause.java.

159  {
160  return uniqueSuffix++;
161  }
Here is the caller graph for this function:

◆ getUniqueVariable()

String org.turro.elephant.db.WhereClause.getUniqueVariable ( String  prefix)

Definition at line 230 of file WhereClause.java.

230  {
231  return prefix + "wcvar" + getUniqueSuffix();
232  }
Here is the call graph for this function:
Here is the caller graph for this function:

◆ getValue()

Object org.turro.elephant.db.WhereClause.getValue ( int  index)

Definition at line 112 of file WhereClause.java.

112  {
113  return values.get(index);
114  }
Here is the caller graph for this function:

◆ getValueCount()

int org.turro.elephant.db.WhereClause.getValueCount ( )

Definition at line 108 of file WhereClause.java.

108  {
109  return values.size();
110  }
Here is the caller graph for this function:

◆ getValues()

Object [] org.turro.elephant.db.WhereClause.getValues ( )

Definition at line 163 of file WhereClause.java.

163  {
164  return values.toArray(new Object[0]);
165  }

◆ isUseNative()

boolean org.turro.elephant.db.WhereClause.isUseNative ( )

Definition at line 143 of file WhereClause.java.

143  {
144  return useNative;
145  }
Here is the caller graph for this function:

◆ setClause()

void org.turro.elephant.db.WhereClause.setClause ( String  clause)

Definition at line 131 of file WhereClause.java.

131  {
132  this.clause = clause;
133  }

◆ setFieldOcurrence()

void org.turro.elephant.db.WhereClause.setFieldOcurrence ( String  fieldOcurrence)

Definition at line 184 of file WhereClause.java.

184  {
185  if(fieldOcurrence == null) fieldOcurrence = "and";
186  this.fieldOcurrence = fieldOcurrence;
187  }

◆ setGroupByClause()

void org.turro.elephant.db.WhereClause.setGroupByClause ( String  groupByClause)

Definition at line 139 of file WhereClause.java.

139  {
140  this.groupByClause = groupByClause;
141  }

◆ setNamedParameters()

void org.turro.elephant.db.WhereClause.setNamedParameters ( Query  q)

Definition at line 174 of file WhereClause.java.

174  {
175  for (Map.Entry<String, Object> e : namedValues.entrySet()) {
176  q.setParameter(e.getKey(), e.getValue());
177  }
178  }
Here is the caller graph for this function:

◆ setOrderByClause()

void org.turro.elephant.db.WhereClause.setOrderByClause ( String  orderByClause)

Definition at line 135 of file WhereClause.java.

135  {
136  this.orderByClause = orderByClause;
137  }
Here is the caller graph for this function:

◆ setParameters()

void org.turro.elephant.db.WhereClause.setParameters ( Query  q,
int  start 
)

Definition at line 168 of file WhereClause.java.

168  {
169  for (int i = 0; i < getValueCount(); i++) {
170  q.setParameter(i + start, getValue(i));
171  }
172  }
Here is the call graph for this function:

◆ setPrefix()

void org.turro.elephant.db.WhereClause.setPrefix ( String  prefix)

Definition at line 193 of file WhereClause.java.

193  {
194  if(prefix == null) prefix = "and";
195  this.prefix = prefix;
196  }
Here is the caller graph for this function:

◆ setResultClass()

void org.turro.elephant.db.WhereClause.setResultClass ( Class  resultClass)

Definition at line 155 of file WhereClause.java.

155  {
156  this.resultClass = resultClass;
157  }
Here is the caller graph for this function:

◆ setUseNative()

void org.turro.elephant.db.WhereClause.setUseNative ( boolean  useNative)

Definition at line 147 of file WhereClause.java.

147  {
148  this.useNative = useNative;
149  }
Here is the caller graph for this function:

The documentation for this class was generated from the following file: