|
|||||||||
| Home >> All >> javatools >> [ db overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
javatools.db
Class DbUpdater

java.lang.Objectjavatools.db.DbUpdater
- Direct Known Subclasses:
- DbReferencedUpdater
- public class DbUpdater
- extends java.lang.Object
A class used to update records from SQL tables. The constructor is not public. To obtain a DbUpdater call DbTable.updater(); Example: To update all the people who are (younger than 18 or older than 80) and whose name is "Fred"... to have a favourite_team of "Raiders";
DbDatabase db = ...;
DbTable people = db.getTable("PEOPLE");
DbUpdater updater = people.deleter();
updater.addColumn(people.getColumn("FAVOURITE_TEAM"), "Raiders");
updater.setWhere(people.getColumn("AGE").lessThan(new Integer(18)).or(
people.getColumn("AGE").greaterThan(new Integer(80))).and(
people.getColumn("NAME").equal("FRED"));
int numberOfPeopleUpdated = updater.execute();
This is equivilent to... UPDATE PEOPLE SET FAVOURITE_TEAM='Raiders' WHERE (AGE < 18 OR AGE > 80 ) AND NAME='Fred'Note the use of equal(), NOT equals(). To get more fancy, to update the same group of people to have a favourite team the same as Bill's team, we use a sub-select...
DbDatabase db = ...;
DbTable people = db.getTable("PEOPLE");
DbSelector bills_team = db.selector();
bills_team.addColumn(people.getColumn("FAVOURITE_TEAM"));
bills_team.setWhere(people.getColumn("NAME").equal("BILL"));
DbUpdater updater = people.deleter();
updater.addColumn(people.getColumn("FAVOURITE_TEAM"), bills_team);
updater.setWhere(people.getColumn("AGE").lessThan(new Integer(18)).or(
people.getColumn("AGE").greaterThan(new Integer(80))).and(
people.getColumn("NAME").equal("FRED"));
int numberOfPeopleUpdated = updater.execute();
This is equivilent to... UPDATE PEOPLE SET FAVOURITE_TEAM=(SELECT FAVOURITE_TEAM FROM PEOPLE WHERE NAME='Bill') WHERE (AGE < 18 OR AGE > 80 ) AND NAME='Fred'
- Version:
- 0.2.0
| Field Summary | |
(package private) java.util.List |
fromList
The list of data to update. |
(package private) java.util.List |
intoList
The list of columns to update. |
(package private) DbAbstractTable |
table
The table to update. |
(package private) DbExpr |
where
The where condition, specifying which rows will be affected. |
| Constructor Summary | |
(package private) |
DbUpdater(DbAbstractTable table)
Creates a new DbUpdater. |
| Method Summary | |
void |
addColumn(DbColumn into,
java.lang.Object from)
Add a column specification to update. |
int |
execute()
Execute this command on the default connection. |
int |
execute(DbConnection dbcon)
Execute this delete command on a specific connection. |
(package private) java.lang.String |
getQueryString()
Returns the query string for this object. |
void |
setLists(java.util.List pIntoList,
java.util.List pFromList)
Sets in one time the column list and the value list. |
(package private) int |
setSqlValues(java.sql.PreparedStatement stmt,
int i)
Sets values for the statement. |
void |
setWhere(DbExpr where)
Set the where condition on which records to update. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
table
DbAbstractTable table
- The table to update.
intoList
java.util.List intoList
- The list of columns to update.
fromList
java.util.List fromList
- The list of data to update.
where
DbExpr where
- The where condition, specifying which rows will be affected.
| Constructor Detail |
DbUpdater
DbUpdater(DbAbstractTable table)
- Creates a new DbUpdater.
| Method Detail |
setWhere
public void setWhere(DbExpr where)
- Set the where condition on which records to update.
addColumn
public void addColumn(DbColumn into, java.lang.Object from)
- Add a column specification to update. The new value can either be a raw
value - Integer, String, java.sql.Date etc. Or it can be a DbSelector in
the case of a sub-select.
setLists
public void setLists(java.util.List pIntoList, java.util.List pFromList)
- Sets in one time the column list and the value list.
execute
public int execute(DbConnection dbcon) throws DbException
- Execute this delete command on a specific connection.
execute
public int execute()
throws DbException
- Execute this command on the default connection.
setSqlValues
int setSqlValues(java.sql.PreparedStatement stmt, int i) throws DbException, java.sql.SQLException
- Sets values for the statement.
getQueryString
java.lang.String getQueryString() throws DbException
- Returns the query string for this object.
|
|||||||||
| Home >> All >> javatools >> [ db overview ] | PREV CLASS NEXT CLASS | ||||||||
SUMMARY: JAVADOC | SOURCE | DOWNLOAD | NESTED | FIELD | CONSTR | METHOD |
DETAIL: FIELD | CONSTR | METHOD | ||||||||
JAVADOC
javatools.db.DbUpdater