public class InsertBuilder
extends java.lang.Object
This is not thread safe.
InsertBuilder builder = InsertBuilder.newInstance(config);
builder.sql("insert into Emp");
builder.sql("(name, salary)");
builder.sql("values (");
builder.param(String.class, "SMITH").sql(", ");
builder.param(BigDecimal.class, new BigDecimal(1000)).sql(")");
builder.execute();
insert into Emp
(name, salary)
values('SMITH', 1000)
| Modifier and Type | Method and Description |
|---|---|
void |
callerClassName(java.lang.String className)
Sets the caller class name.
|
void |
callerMethodName(java.lang.String methodName)
Sets the caller method name.
|
int |
execute()
Executes an SQL INSERT statement.
|
Sql<?> |
getSql()
Returns the built SQL.
|
<P> InsertBuilder |
literal(java.lang.Class<P> paramClass,
P param)
Appends a parameter as literal.
|
<E> InsertBuilder |
literals(java.lang.Class<E> elementClass,
java.util.List<E> params)
Appends a parameter list as literal.
|
static InsertBuilder |
newInstance(Config config)
Creates a new instance.
|
<P> InsertBuilder |
param(java.lang.Class<P> paramClass,
P param)
Appends a parameter.
|
<E> InsertBuilder |
params(java.lang.Class<E> elementClass,
java.util.List<E> params)
Appends a parameter list.
|
void |
queryTimeout(int queryTimeout)
Sets the query timeout limit in seconds.
|
InsertBuilder |
removeLast()
Removes the last SQL fragment or parameter.
|
InsertBuilder |
sql(java.lang.String sql)
Appends an SQL fragment.
|
void |
sqlLogType(SqlLogType sqlLogType)
Sets the SQL log format.
|
public static InsertBuilder newInstance(Config config)
config - the configurationDomaNullPointerException - if config is nullpublic InsertBuilder sql(java.lang.String sql)
sql - the SQL fragmentDomaNullPointerException - if sql is nullpublic InsertBuilder removeLast()
public <P> InsertBuilder param(java.lang.Class<P> paramClass, P param)
The parameter type must be one of basic types or holder types.
P - the parameter typeparamClass - the parameter classparam - the parameterDomaNullPointerException - if paramClass is nullpublic <E> InsertBuilder params(java.lang.Class<E> elementClass, java.util.List<E> params)
The element type of the list must be one of basic types or holder types.
E - the element type of the listelementClass - the element class of the listparams - the parameter listDomaNullPointerException - if elementClass or params is nullpublic <P> InsertBuilder literal(java.lang.Class<P> paramClass, P param)
The parameter type must be one of basic types or holder types.
P - the parameter typeparamClass - the parameter classparam - the parameterDomaNullPointerException - if paramClass is nullpublic <E> InsertBuilder literals(java.lang.Class<E> elementClass, java.util.List<E> params)
The element type of the list must be one of basic types or holder types.
E - the element type of the listelementClass - the element class of the listparams - the parameter listDomaNullPointerException - if elementClass or params is nullpublic int execute()
UniqueConstraintException - if an unique constraint violation occursJdbcException - if a JDBC related error occurspublic void queryTimeout(int queryTimeout)
If not specified, the value of Config.getQueryTimeout() is used.
queryTimeout - the query timeout limit in secondsStatement.setQueryTimeout(int)public void sqlLogType(SqlLogType sqlLogType)
sqlLogType - the SQL log format typepublic void callerClassName(java.lang.String className)
If not specified, the class name of this instance is used.
className - the caller class nameDomaNullPointerException - if className is nullpublic void callerMethodName(java.lang.String methodName)
if not specified, execute is used.
methodName - the caller method nameDomaNullPointerException - if methodName is nullpublic Sql<?> getSql()