|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectcom.github.drinkjava2.jdbpro.template.BasicSqlTemplate
public class BasicSqlTemplate
BasicSqlTemplate is a simple implementation of SqlTemplateEngine. It allow use #{xxxx} format parameters in template, and replace ${xxxx} pieces directly. This is a thread safe class.
| Nested Class Summary | |
|---|---|
static class |
BasicSqlTemplate.BasicSqlTemplateException
|
| Field Summary | |
|---|---|
protected Boolean |
allowColonAsDelimiter
If set true, ${placeHolder} can write as :placeHolder Default is true |
protected Boolean |
dollarKeyForDollarPlaceHolder
If set true, for ${placeHolder} in template, should use put("$placeHolder",value) instead of use put("placeHolder",value) Default is false |
| Constructor Summary | |
|---|---|
BasicSqlTemplate()
Build a BasicSqlTemplate instance, default use #{} as delimiter, dollarKeyForDollarPlaceHolder is false, allow |
|
BasicSqlTemplate(String startDelimiter,
String endDelimiter,
Boolean allowColonAsDelimiter,
Boolean dollarKeyForDollarPlaceHolder)
|
|
| Method Summary | |
|---|---|
static BasicSqlTemplate |
instance()
|
static boolean |
isEmpty(CharSequence cs)
Checks if a CharSequence is empty ("") or null. |
PreparedSQL |
render(String sqlTemplate,
Map<String,Object> paramMap,
Object[] unbindParams)
Render a SQL Template String and a Map PreparedSQL instance |
static String |
substringAfter(String str,
String separator)
Gets the substring after the first occurrence of a separator. |
static String |
substringBefore(String str,
String separator)
Gets the substring before the first occurrence of a separator. |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected Boolean dollarKeyForDollarPlaceHolder
protected Boolean allowColonAsDelimiter
| Constructor Detail |
|---|
public BasicSqlTemplate()
public BasicSqlTemplate(String startDelimiter,
String endDelimiter,
Boolean allowColonAsDelimiter,
Boolean dollarKeyForDollarPlaceHolder)
startDelimiter - The start delimiterendDelimiter - The end delimiterallowColonAsDelimiter - If set true, write :placeHolder is equal to #{placeHolder}dollarKeyForDollarPlaceHolder - If set true, ${placeHolder} should use put("$placeHolder",value)
instead of use put("placeHolder",value)| Method Detail |
|---|
public static BasicSqlTemplate instance()
public PreparedSQL render(String sqlTemplate,
Map<String,Object> paramMap,
Object[] unbindParams)
SqlTemplateEnginePreparedSQL instance
render in interface SqlTemplateEnginesqlTemplate - A SQL Template String, or a SqlId used to locate the real SQL
template StringparamMap - A Map instance, key is String type, value is Object typeunbindParams - Optional, some time un-binded parameter can make template SQL
executed like normal SQL, i.e., use normal params to replace
placeholder according apperance order
For example:
Template "delete from #{tb}", use put("tb","users") method, will get "delete from ?"
Template "delete from ${tb}", use replace("tb","users") method, will get "delete from users"
Template "delete from #{tb}", use replace("tb","users") method, will cause an Exception
Template "delete from ${tb}", use put("tb","users") method, will cause an Exception
This design is to avoid typing mistake cause a SQL injection
security leak, when programmer use replace() or replace0() method,
he will aware this is a String direct replace method, not a SQL
parameter, SQL parameter always use "put" method.
public static boolean isEmpty(CharSequence cs)
Checks if a CharSequence is empty ("") or null.
StringUtils.isEmpty(null) = true
StringUtils.isEmpty("") = true
StringUtils.isEmpty(" ") = false
StringUtils.isEmpty("bob") = false
StringUtils.isEmpty(" bob ") = false
NOTE: This method changed in Lang version 2.0. It no longer trims the CharSequence. That functionality is available in isBlank().
cs - the CharSequence to check, may be null
true if the CharSequence is empty or null
public static String substringBefore(String str,
String separator)
Gets the substring before the first occurrence of a separator. The separator is not returned.
A null string input will return null. An empty ("") string
input will return the empty string. A null separator will return the
input string.
If nothing is found, the string input is returned.
StringUtils.substringBefore(null, *) = null
StringUtils.substringBefore("", *) = ""
StringUtils.substringBefore("abc", "a") = ""
StringUtils.substringBefore("abcba", "b") = "a"
StringUtils.substringBefore("abc", "c") = "ab"
StringUtils.substringBefore("abc", "d") = "abc"
StringUtils.substringBefore("abc", "") = ""
StringUtils.substringBefore("abc", null) = "abc"
str - the String to get a substring from, may be nullseparator - the String to search for, may be null
null if null String input
public static String substringAfter(String str,
String separator)
Gets the substring after the first occurrence of a separator. The separator is not returned.
A null string input will return null. An empty ("") string
input will return the empty string. A null separator will return the
empty string if the input string is not null.
If nothing is found, the empty string is returned.
StringUtils.substringAfter(null, *) = null
StringUtils.substringAfter("", *) = ""
StringUtils.substringAfter(*, null) = ""
StringUtils.substringAfter("abc", "a") = "bc"
StringUtils.substringAfter("abcba", "b") = "cba"
StringUtils.substringAfter("abc", "c") = ""
StringUtils.substringAfter("abc", "d") = ""
StringUtils.substringAfter("abc", "") = "abc"
str - the String to get a substring from, may be nullseparator - the String to search for, may be null
null if null String input
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||