T
- The class that the code will be operating on.ID
- The class of the ID column associated with the class. The T class does not require an ID field. The class
needs an ID parameter however so you can use Void or Object to satisfy the compiler.public class UpdateBuilder<T,ID> extends StatementBuilder<T,ID>
StatementBuilder.StatementInfo, StatementBuilder.StatementType, StatementBuilder.WhereOperation
addTableName, dao, databaseType, tableInfo, tableName, type, where
Constructor and Description |
---|
UpdateBuilder(DatabaseType databaseType,
TableInfo<T,ID> tableInfo,
Dao<T,ID> dao) |
Modifier and Type | Method and Description |
---|---|
protected void |
appendStatementEnd(StringBuilder sb,
List<ArgumentHolder> argList)
Append the end of our statement string to the StringBuilder.
|
protected void |
appendStatementStart(StringBuilder sb,
List<ArgumentHolder> argList)
Append the start of our statement string to the StringBuilder.
|
String |
escapeColumnName(String columnName)
Same as
escapeColumnName(StringBuilder, String) but it will return the escaped string. |
void |
escapeColumnName(StringBuilder sb,
String columnName)
When you are building the expression for
updateColumnExpression(String, String) , you may need to escape
column names since they may be reserved words to the database. |
String |
escapeValue(String value)
Same as
escapeValue(StringBuilder, String) but it will return the escaped string. |
void |
escapeValue(StringBuilder sb,
String value)
When you are building the expression for
updateColumnExpression(String, String) , you may need to escape
values since they may be reserved words to the database. |
UpdateBuilder<T,ID> |
limit(Long maxRows)
Limit the rows affected to maxRows maximum number of rows.
|
PreparedUpdate<T> |
prepare()
Build and return a prepared update that can be used by
Dao.update(PreparedUpdate) method. |
void |
reset()
Clear out all of the statement settings so we can reuse the builder.
|
int |
update()
A short cut to
Dao.update(PreparedUpdate) . |
UpdateBuilder<T,ID> |
updateColumnExpression(String columnName,
String expression)
Add a column to be set to a value for UPDATE statements.
|
UpdateBuilder<T,ID> |
updateColumnValue(String columnName,
Object value)
Add a column to be set to a value for UPDATE statements.
|
appendStatementString, appendWhereStatement, buildStatementString, getResultFieldTypes, getTableName, prepareStatement, prepareStatementInfo, prepareStatementString, setWhere, shouldPrependTableNameToColumns, verifyColumnName, where
public PreparedUpdate<T> prepare() throws SQLException
Dao.update(PreparedUpdate)
method. If you change
the where or make other calls you will need to re-call this method to re-prepare the statement for execution.SQLException
public UpdateBuilder<T,ID> updateColumnValue(String columnName, Object value) throws SQLException
SQLException
public UpdateBuilder<T,ID> updateColumnExpression(String columnName, String expression) throws SQLException
The expression should have any strings escaped using the escapeValue(String)
or
escapeValue(StringBuilder, String)
methods and should have any column names escaped using the
escapeColumnName(String)
or escapeColumnName(StringBuilder, String)
methods.
SQLException
public void escapeColumnName(StringBuilder sb, String columnName)
updateColumnExpression(String, String)
, you may need to escape
column names since they may be reserved words to the database. This will help you by adding escape characters
around the word.public String escapeColumnName(String columnName)
escapeColumnName(StringBuilder, String)
but it will return the escaped string. The StringBuilder
method is more efficient since this method creates a StringBuilder internally.public void escapeValue(StringBuilder sb, String value)
updateColumnExpression(String, String)
, you may need to escape
values since they may be reserved words to the database. Numbers should not be escaped. This will help you by
adding escape characters around the word.public String escapeValue(String value)
escapeValue(StringBuilder, String)
but it will return the escaped string. Numbers should not be
escaped. The StringBuilder method is more efficient since this method creates a StringBuilder internally.public int update() throws SQLException
Dao.update(PreparedUpdate)
.SQLException
public UpdateBuilder<T,ID> limit(Long maxRows)
public void reset()
StatementBuilder
reset
in class StatementBuilder<T,ID>
protected void appendStatementStart(StringBuilder sb, List<ArgumentHolder> argList) throws SQLException
StatementBuilder
appendStatementStart
in class StatementBuilder<T,ID>
SQLException
protected void appendStatementEnd(StringBuilder sb, List<ArgumentHolder> argList)
StatementBuilder
appendStatementEnd
in class StatementBuilder<T,ID>
This documentation is licensed by Gray Watson under the Creative Commons Attribution-Share Alike 3.0 License.