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

Static Public Member Functions

static String convertToLike (String value)
 
static String convertToPartialLike (String value)
 
static String convertToIn (Collection collection)
 
static String quoteTokensForIn (String inValue)
 
static WhereClause getWhereClause (String[] fields, String value)
 
static WhereClause getWhereClause (WhereClause wc, String[] fields, String value)
 
static WhereClause getWhereClause (String[] fields, String value, String regexp)
 
static WhereClause getWhereClause (WhereClause wc, String[] fields, String value, String regexp)
 
static WhereClause getWhereClause (String[] fields, String[] values)
 
static WhereClause getWhereClause (WhereClause wc, String[] fields, String[] values)
 
static WhereClause getWhereClause (String[] fields, String[] values, boolean namedValues)
 
static WhereClause getWhereClause (WhereClause wc, String[] fields, String[] values, boolean namedValues)
 

Detailed Description

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

Definition at line 27 of file SQLHelper.java.

Member Function Documentation

◆ convertToIn()

static String org.turro.elephant.db.SQLHelper.convertToIn ( Collection  collection)
static

Definition at line 43 of file SQLHelper.java.

43  {
44  String result = null;
45  for(Object o : collection) {
46  if(o instanceof String) {
47  result = (result == null) ? ("'" + o + "'") : (result + ",'" + o + "'");
48  } else {
49  result = (String) ((result == null) ? o + "" : (result + "," + o));
50  }
51  }
52  return result;
53  }

◆ convertToLike()

static String org.turro.elephant.db.SQLHelper.convertToLike ( String  value)
static

Definition at line 33 of file SQLHelper.java.

33  {
34  if(value == null) return null;
35  return value.replaceAll("\\*", "%").replaceAll("\\?", "_");
36  }
Here is the caller graph for this function:

◆ convertToPartialLike()

static String org.turro.elephant.db.SQLHelper.convertToPartialLike ( String  value)
static

Definition at line 38 of file SQLHelper.java.

38  {
39  if(value == null) return null;
40  return "%" + value.replaceAll("\\*", "%").replaceAll("\\?", "_") + "%";
41  }
Here is the caller graph for this function:

◆ getWhereClause() [1/8]

static WhereClause org.turro.elephant.db.SQLHelper.getWhereClause ( String[]  fields,
String  value 
)
static

Definition at line 64 of file SQLHelper.java.

64  {
65  return getWhereClause(null, fields, value);
66  }
static WhereClause getWhereClause(String[] fields, String value)
Definition: SQLHelper.java:64
Here is the caller graph for this function:

◆ getWhereClause() [2/8]

static WhereClause org.turro.elephant.db.SQLHelper.getWhereClause ( String[]  fields,
String  value,
String  regexp 
)
static

Definition at line 84 of file SQLHelper.java.

84  {
85  return getWhereClause(null, fields, value, regexp);
86  }
Here is the call graph for this function:

◆ getWhereClause() [3/8]

static WhereClause org.turro.elephant.db.SQLHelper.getWhereClause ( String[]  fields,
String[]  values 
)
static

Definition at line 99 of file SQLHelper.java.

99  {
100  return getWhereClause(fields, values, true);
101  }

◆ getWhereClause() [4/8]

static WhereClause org.turro.elephant.db.SQLHelper.getWhereClause ( String[]  fields,
String[]  values,
boolean  namedValues 
)
static

Definition at line 107 of file SQLHelper.java.

107  {
108  return getWhereClause(null, fields, values, namedValues);
109  }

◆ getWhereClause() [5/8]

static WhereClause org.turro.elephant.db.SQLHelper.getWhereClause ( WhereClause  wc,
String[]  fields,
String  value 
)
static

Definition at line 68 of file SQLHelper.java.

68  {
69  if(wc == null) wc = new WhereClause();
70  if(value != null) {
71  if(value.startsWith("=")) {
72  // value must be equal
73  value = value.substring(1);
74  return /*"%".equals(value) ? wc :*/ getWhereClause(wc, fields, value, null);
75  } else if(value.startsWith("?")) {
76  // where portion as is
77  wc.addClause(value.substring(1));
78  return wc;
79  }
80  }
81  return /*"%".equals(value) ? wc :*/ getWhereClause(wc, fields, value, " ");
82  }
Here is the call graph for this function:

◆ getWhereClause() [6/8]

static WhereClause org.turro.elephant.db.SQLHelper.getWhereClause ( WhereClause  wc,
String[]  fields,
String  value,
String  regexp 
)
static

Definition at line 88 of file SQLHelper.java.

88  {
89  if(value != null) {
90  if(regexp != null) {
91  return getWhereClause(wc, fields, value.split(regexp));
92  } else {
93  return getWhereClause(wc, fields, new String[] { value });
94  }
95  }
96  return new WhereClause();
97  }
Here is the call graph for this function:

◆ getWhereClause() [7/8]

static WhereClause org.turro.elephant.db.SQLHelper.getWhereClause ( WhereClause  wc,
String[]  fields,
String[]  values 
)
static

Definition at line 103 of file SQLHelper.java.

103  {
104  return getWhereClause(wc, fields, values, true);
105  }

◆ getWhereClause() [8/8]

static WhereClause org.turro.elephant.db.SQLHelper.getWhereClause ( WhereClause  wc,
String[]  fields,
String[]  values,
boolean  namedValues 
)
static

Definition at line 111 of file SQLHelper.java.

111  {
112  if(wc == null) wc = new WhereClause();
113 
114  String result = "", partial, param;
115 
116  for(int f = 0; f < fields.length; f++) {
117  partial = "";
118  for(int v = 0; v < values.length; v++) {
119  if(!Strings.isBlank(values[v])) {
120  if(partial.length() > 0) {
121  partial += " " + wc.getFieldOcurrence() + " ";
122  }
123  if(namedValues) {
124  param = fields[f].replaceAll("\\.", "_") + wc.getUniqueSuffix();
125  partial += "UCASE(" + fields[f] + ") like :" + param;
126  if("%".equals(values[v])) {
127  wc.addNamedValue(param, "%");
128  } else {
129  wc.addNamedValue(param, "%" + values[v].toUpperCase() + "%");
130  }
131  } else {
132  partial += "UCASE(" + fields[f] + ") like ?";
133  if("%".equals(values[v])) {
134  wc.addValue("%");
135  } else {
136  wc.addValue("%" + values[v].toUpperCase() + "%");
137  }
138  }
139  }
140  }
141 
142  if(partial.length() > 0) {
143  if(result.length() > 0) {
144  result += " or ";
145  }
146  result += "(" + partial + ")";
147  }
148  }
149 
150  if(result.length() > 0) {
151  result = wc.getPrefix() + " (" + result + ") ";
152  }
153 
154  wc.addClause(result);
155 
156  return wc;
157  }

◆ quoteTokensForIn()

static String org.turro.elephant.db.SQLHelper.quoteTokensForIn ( String  inValue)
static

Definition at line 55 of file SQLHelper.java.

55  {
56  String[] tokens = inValue.split(",");
57  String result = null;
58  for(String s : tokens) {
59  result = (result == null) ? ("'" + s + "'") : (result + ",'" + s + "'");
60  }
61  return result;
62  }
Here is the caller graph for this function:

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