public final class JdbcBuilder extends Object implements Serializable
| Modifier and Type | Field and Description |
|---|---|
protected List<Object> |
arguments
Seznam argumentů
|
protected int |
columnCounter
Column counter
|
protected int |
conditionCounter
Condition counter
|
protected boolean |
emptySql
The SQL buffer has assigned an character
|
protected boolean |
insertMode
An insert sign for different rendering
|
protected static char |
ITEM_SEPARATOR
Separator of database columns
|
protected static char |
SPACE
A value marker for SQL
|
protected StringBuilder |
sql
Opening SQL string
|
protected static char |
VALUE_MARKER
A value marker for SQL
|
| Constructor and Description |
|---|
JdbcBuilder()
Default constructor
|
JdbcBuilder(StringBuilder sql)
StringBuilder construcor
|
| Modifier and Type | Method and Description |
|---|---|
JdbcBuilder |
andCondition(CharSequence sqlCondition,
Object value)
Add an condition for a valid argument joined by AND operator
|
JdbcBuilder |
andCondition(CharSequence sqlCondition,
String operator,
Object value)
Add an equals condition for a valid argument joined by AND operator
|
JdbcBuilder |
column(CharSequence column)
Add new column
|
JdbcBuilder |
columnInsert(CharSequence column,
Object value)
Set new value to column by template {@code name = ?
|
JdbcBuilder |
columnUpdate(CharSequence column,
Object value)
Set new value to column by template {@code name = ?
|
JdbcBuilder |
concat(JdbcBuilder builder)
Concatenates the specified statement to the end of this statement.
|
JdbcBuilder |
condition(CharSequence sqlCondition,
Object value,
Boolean andOperator)
Add an condition for an argument with length
|
JdbcBuilder |
condition(CharSequence sqlCondition,
String operator,
Object value,
Boolean andOperator)
Add an condition for an argument with length
|
int |
executeUpdate(Connection connection)
Create statement and call
PreparedStatement.executeUpdate() . |
Object[] |
getArguments()
Array of JDBC argumets
|
String |
getSql()
Returns a SQL text
|
JdbcBuilder |
orCondition(CharSequence sqlCondition,
Object value)
Add an condition for a valid argument joined by OR operator
|
JdbcBuilder |
orCondition(CharSequence sqlCondition,
String operator,
Object value)
Add an equals condition for a valid argument joined by OR operator
|
PreparedStatement |
prepareStatement(Connection connection)
Build the PreparedStatement with arguments
|
JdbcBuilder |
rawArguments(Object... values)
Add raw arguments for special use
|
JdbcBuilder |
rawWrite(CharSequence sqlFragment)
Write argument with no space
|
String |
toString()
Returns a SQL including values
|
<T> T |
uniqueValue(Class<T> resultType,
Connection connection)
Return the first column value of a unique resultset, else returns
null value |
JdbcBuilder |
value(Object param)
Add new value
|
JdbcBuilder |
write(CharSequence sqlFragment)
If buffer is an empty, than the space is introduced
|
protected static final char ITEM_SEPARATOR
protected static final char VALUE_MARKER
protected static final char SPACE
@Nonnull protected final StringBuilder sql
protected boolean emptySql
protected int columnCounter
protected int conditionCounter
protected boolean insertMode
public JdbcBuilder()
public JdbcBuilder(@Nonnull StringBuilder sql)
@Nonnull public JdbcBuilder concat(@Nonnull JdbcBuilder builder)
@Nonnull public JdbcBuilder write(@Nonnull CharSequence sqlFragment)
@Nonnull public JdbcBuilder rawWrite(@Nonnull CharSequence sqlFragment)
@Nonnull public JdbcBuilder column(@Nonnull CharSequence column)
@Nonnull public JdbcBuilder columnUpdate(@Nonnull CharSequence column, @Nonnull Object value)
@Nonnull public JdbcBuilder columnInsert(@Nonnull CharSequence column, @Nonnull Object value)
@Nonnull public JdbcBuilder value(@Nonnull Object param)
@Nonnull public JdbcBuilder andCondition(@Nonnull CharSequence sqlCondition, @Nullable Object value)
sqlCondition - A condition in the SQL format like the next: "table.id = ?"value - The value od the condition (a replacement for the question character)@Nonnull public JdbcBuilder andCondition(@Nonnull CharSequence sqlCondition, @Nullable String operator, @Nullable Object value)
sqlCondition - A condition in the SQL format like the next: "table.id = ?"operator - An optional operator is followed by the VALUE_MARKER automaticallyvalue - The value od the condition (a replacement for the question character)@Nonnull public JdbcBuilder orCondition(@Nonnull CharSequence sqlCondition, @Nullable Object value)
sqlCondition - A condition in the SQL format like the next: "table.id = ?"value - The value od the condition (a replacement for the question character)@Nonnull public JdbcBuilder orCondition(@Nonnull CharSequence sqlCondition, @Nullable String operator, @Nullable Object value)
sqlCondition - A condition in the SQL format like the next: "table.id = ?"operator - An optional operator is followed by the VALUE_MARKER automaticallyvalue - The value od the condition (a replacement for the question character)@Nonnull public JdbcBuilder condition(@Nonnull CharSequence sqlCondition, @Nullable Object value, @Nullable Boolean andOperator)
sqlCondition - A condition in the SQL format like the next: "table.id = ?"value - The value od the condition (a replacement for the question character)@Nonnull public JdbcBuilder condition(@Nonnull CharSequence sqlCondition, @Nullable String operator, @Nullable Object value, @Nullable Boolean andOperator)
sqlCondition - A condition in the SQL format like the next: "table.id = ?"operator - An optional operator is followed by the VALUE_MARKER automaticallyvalue - The value od the condition (a replacement for the question character)@Nonnull public Object[] getArguments()
@Nonnull public JdbcBuilder rawArguments(@Nonnull Object... values)
rawWrite(java.lang.CharSequence)@Nonnull public PreparedStatement prepareStatement(@Nonnull Connection connection) throws SQLException
SQLExceptionpublic int executeUpdate(@Nonnull Connection connection) throws IllegalStateException
PreparedStatement.executeUpdate() .
Supported SQL statements are: INSERT, UPDATE, DELETE .IllegalStateExceptionpublic <T> T uniqueValue(@Nonnull Class<T> resultType, @Nonnull Connection connection) throws IllegalStateException
null valueIllegalStateExceptionCopyright 2015, Pavel Ponec