|
com.im.commons.db 5.9.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectcom.im.commons.db.dml.SQLUpdateStatement
public class SQLUpdateStatement
Defines a SQL update statement that allows data in a table to be selectively updated
Typical usage:
SQLWriter sqlWriter = new SQLWriterRegistry() ;
SQLUpdateStatement update = new SQLUpdateStatement(sqlWriter);
update.setTable("foo");
SQLWhereClauseElement where = new SQLFilterElement(sqlWriter, "foo", new String[]{"baz"}, new int[]{Types.VARCHAR}, Operators.EQUALS, new Object[]{"mars"});
update.setWhereClause(where);
update.addValue("txtcol", TypesProvider.ColumnType.VARCHAR, "hello world");
update.addValue("intcol", TypesProvider.ColumnType.INTEGER, new Integer(99));
String sql = instance.generateSql();
// now execute the SQL
Will generate SQL like this:
UPDATE foo
SET txtcol = 'hello world', intcol = 99
WHERE foo.baz = 'mars'
TODO: add the ability to use a join as part of the where statement - currently
this implementation is limited to columns within the table being updated
| Field Summary | |
|---|---|
static String |
BIND_CHARACTER
|
| Constructor Summary | |
|---|---|
SQLUpdateStatement(SQLWriter sqlWriter)
Creates a new instance of SQLUpdateStatement |
|
| Method Summary | |
|---|---|
void |
addValue(String colName,
DBDatabaseInfo.ColumnSQLType colType,
Object value)
Add a value that will be updated. |
SQLUpdateStatement |
addWhereClause(SQLWhereClauseElement where,
SQLWhereClauseCompositeElement.Type type)
|
void |
bindVariable(String colName)
Bind a value that will be updated. |
String |
createSelectSql()
Creates a SELECT statement, which will list all IDs and values from columns scheduled for the update. |
String |
generateSql()
Generates the SQL that performs the update. |
String |
getIdColumnName()
|
SQLWhereClauseElement |
getWhereClause()
|
void |
setIdColumnName(String idColumnName)
|
void |
setTable(SchemaQualifiedName sqn)
Set the table to be updated |
void |
setUpdateAllRows()
Specifies that all rows are to be updated. |
protected void |
setWhereClause(SQLWhereClauseElement where)
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
public static final String BIND_CHARACTER
| Constructor Detail |
|---|
public SQLUpdateStatement(SQLWriter sqlWriter)
sqlWriter - How to write values to SQL| Method Detail |
|---|
public String getIdColumnName()
public void setIdColumnName(String idColumnName)
public void setTable(SchemaQualifiedName sqn)
sqn - The schema qualified namepublic void setUpdateAllRows()
public void addValue(String colName,
DBDatabaseInfo.ColumnSQLType colType,
Object value)
colName - The column namecolType - The type of the column. Affects how the value is writen to SQL.value - The value for the columnpublic SQLWhereClauseElement getWhereClause()
public SQLUpdateStatement addWhereClause(SQLWhereClauseElement where,
SQLWhereClauseCompositeElement.Type type)
protected void setWhereClause(SQLWhereClauseElement where)
public String createSelectSql()
public void bindVariable(String colName)
colName - The column namepublic String generateSql()
|
com.im.commons.db 5.9.2 | ||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||