com.j256.ormlite.stmt
Class UpdateBuilder<T,ID>

java.lang.Object
  extended by com.j256.ormlite.stmt.StatementBuilder<T,ID>
      extended by com.j256.ormlite.stmt.UpdateBuilder<T,ID>

public class UpdateBuilder<T,ID>
extends StatementBuilder<T,ID>

Assists in building sql UPDATE statements for a particular table in a particular database.

Author:
graywatson

Nested Class Summary
 
Nested classes/interfaces inherited from class com.j256.ormlite.stmt.StatementBuilder
StatementBuilder.StatementType
 
Field Summary
 
Fields inherited from class com.j256.ormlite.stmt.StatementBuilder
databaseType, limit, tableInfo
 
Constructor Summary
UpdateBuilder(DatabaseType databaseType, TableInfo<T> tableInfo)
           
 
Method Summary
protected  void appendStatementEnd(StringBuilder sb)
          Append the end of our statement string to the StringBuilder.
protected  void appendStatementStart(StringBuilder sb, List<FieldType> resultFieldTypeList)
          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.
 PreparedUpdate<T> prepare()
          Build and return a prepared update that can be used by Dao.update(PreparedUpdate) method.
 StatementBuilder<T,ID> updateColumnExpression(String columnName, String expression)
          Add a column to be set to a value for UPDATE statements.
 StatementBuilder<T,ID> updateColumnValue(String columnName, Object value)
          Add a column to be set to a value for UPDATE statements.
 
Methods inherited from class com.j256.ormlite.stmt.StatementBuilder
buildStatementString, prepareStatement, prepareStatementString, setWhere, verifyColumnName, where
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

UpdateBuilder

public UpdateBuilder(DatabaseType databaseType,
                     TableInfo<T> tableInfo)
Method Detail

prepare

public PreparedUpdate<T> prepare()
                          throws SQLException
Build and return a prepared update that can be used by 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.

Throws:
SQLException

updateColumnValue

public StatementBuilder<T,ID> updateColumnValue(String columnName,
                                                Object value)
                                         throws SQLException
Add a column to be set to a value for UPDATE statements. This will generate something like columnName = 'value' with the value escaped if necessary.

Throws:
SQLException

updateColumnExpression

public StatementBuilder<T,ID> updateColumnExpression(String columnName,
                                                     String expression)
                                              throws SQLException
Add a column to be set to a value for UPDATE statements. This will generate something like 'columnName = expression' where the expression is built by the caller.

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.

Throws:
SQLException

escapeColumnName

public 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. This will help you by adding escape characters around the word.


escapeColumnName

public String escapeColumnName(String columnName)
Same as escapeColumnName(StringBuilder, String) but it will return the escaped string. The StringBuilder method is more efficient since this method creates a StatementBuilder internally.


escapeValue

public 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. Numbers should not be escaped. This will help you by adding escape characters around the word.


escapeValue

public String escapeValue(String value)
Same as 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 StatementBuilder internally.


appendStatementStart

protected void appendStatementStart(StringBuilder sb,
                                    List<FieldType> resultFieldTypeList)
                             throws SQLException
Description copied from class: StatementBuilder
Append the start of our statement string to the StringBuilder.

Specified by:
appendStatementStart in class StatementBuilder<T,ID>
Throws:
SQLException

appendStatementEnd

protected void appendStatementEnd(StringBuilder sb)
Description copied from class: StatementBuilder
Append the end of our statement string to the StringBuilder.

Specified by:
appendStatementEnd in class StatementBuilder<T,ID>


Copyright © 2011. All Rights Reserved.