|
BEA Systems, Inc. | ||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--weblogic.db.jdbc.DataSet | +--weblogic.db.jdbc.TableDataSet
A TableDataSet holds the results of an SQL query on a single table. The results are available as a collection of Records accessible by an integer index. Each record has all the attributes of the specified table, unless a subset of attributes is specified. The API allows you to specify the WHERE and ORDER BY clauses as well.
You can update values in the Records, add new Records, and mark Records for deletion. After making such changes, you can save the changes to a database. You can execute TableDataSet.save() to save all the changes made to a TableDataset, or you can execute Record.save() to save changes to a single record.
If you intend to save updates or deletes to a database, you must provide a KeyDef object in the TableDataSet constructor. The KeyDef object is used to specify a unique key that is the basis for forming the WHERE clause automatically generated in the UPDATE and DELETE statements. A KeyDef object is not necessary if only inserts take place, since they are performed without a WHERE clause.
Each TableDataSet also has a default SelectStmt object that can be used to take advantage of QBE functionality.
If you do not want to save changes to a database, or if you want to execute an arbitrary SQL query involving more than one table, use a QueryDataSet instead.
The following example shows how to create a TableDataSet, add 10 records to it, and insert the records into the database. Note that the TableDataSet must be closed when work with it is completed.
TableDataSet tds = new TableDataSet(conn, "emp"); for (int i = 0; i < 10; i++) { Record rec = tds.addRecord(); rec.setValue("recnum", i) .setValue("firstname", "joe") .setValue("lastname", "smith"); tds.save(); tds.close(); // This must be called
For more implementation and usage see the Developers Guide.
KeyDef
,
DataSet
,
QueryDataSet
,
SelectStmt
, Serialized FormField Summary | |
protected KeyDef |
keydefval
|
Fields inherited from class weblogic.db.jdbc.DataSet |
cached,
resetable,
resultval,
stmt |
Constructor Summary | |
TableDataSet()
Private - used for serialization |
|
TableDataSet(java.sql.Connection conn,
Schema schema,
KeyDef key)
Constructs a TableDataSet from the specified Schema and KeyDef. |
|
TableDataSet(java.sql.Connection conn,
java.lang.String tablename)
Constructs a TableDataSet from the specified table. |
|
TableDataSet(java.sql.Connection conn,
java.lang.String tablename,
KeyDef key)
Constructs a TableDataSet from the specified table, and sets its KeyDef, which is used to specify a unique key for updates and deletes. |
|
TableDataSet(java.sql.Connection conn,
java.lang.String tablename,
java.lang.String attributes)
Constructs a TableDataSet from the specified table, limited to the specified set of attributes (columns). |
|
TableDataSet(java.sql.Connection conn,
java.lang.String tablename,
java.lang.String attributes,
KeyDef key)
Constructs a TableDataSet from the specified table, limited to the specified set of attributes (columns). |
Method Summary | |
java.lang.String |
attributes()
Returns the set of attributes with which a TableDataSet was constructed. |
java.lang.String |
debugInfo()
Returns information about a TableDataSet object for debugging purposes. |
DataSet |
fetchRecords(int start,
int maxrecs)
Fetches at most the specified number of records starting at the specified record. |
java.lang.String |
getSelectString()
Returns the SQL SELECT string of the query that was used to populate a TableDataSet. |
KeyDef |
keydef()
Returns the KeyDef for a TableDataSet. |
java.lang.String |
optimisticLockingCol()
|
TableDataSet |
order(java.lang.String str)
Sets the ORDER BY clause for a TableDataSet. |
protected java.lang.String |
orderstr()
|
TableDataSet |
other(java.lang.String str)
Sets additional SQL clause for a TableDataSet. |
void |
refresh(java.sql.Connection conn)
Refreshes all of the records in the TableDataSet from the DBMS. |
boolean |
refreshOnSave()
Returns the current setting of setRefreshOnSave(), which is False by default. |
void |
removeDeletedRecords()
Removes deleted records from the TableDataSet. |
java.sql.ResultSet |
resultSet()
Returns the JDBC ResultSet associated with a TableDataSet. |
int |
save()
Saves changes made in a TableDataSet to a database using the default Connection. |
int |
save(boolean intransaction)
Saves changes made in a TableDataSet to a database using the default Connection. |
int |
save(java.sql.Connection conn,
boolean intransaction)
Saves changes made in a TableDataSet to a database using the specified Connection. |
int |
saveWithoutStatusUpdate(java.sql.Connection conn)
|
Schema |
schema()
Returns the Schema of a TableDataSet. |
SelectStmt |
selectStmt()
Returns the SelectStmt object associated with a TableDataSet. |
void |
setOptimisticLockingColumn(java.lang.String colName)
Identifies the table column used for optimistic locking. |
void |
setRefreshOnSave(boolean yesOrNo)
Sets TableDataSet so that every record inserted or updated during a save is immediately refreshed from the DBMS contents. |
java.lang.String |
tableName()
Returns the database table name with which a TableDataSet was created. |
TableDataSet |
tableQualifier(java.lang.String str)
Sets additional SQL for the table name clause. |
void |
updateStatus()
Updates the save status of the rows in the TableDataSet. |
TableDataSet |
where(java.lang.String str)
Sets the WHERE clause for a TableDataSet. |
Methods inherited from class weblogic.db.jdbc.DataSet |
addRecord,
allRecordsRetrieved,
clearRecords,
close,
connection,
containsRecord,
destroy,
fetchRecords,
fetchRecords,
getRecord,
getResultSet,
initialize,
lastFetchSize,
maxColumnWidths,
readExternal,
releaseRecords,
removeRecord,
reset,
size,
toString,
writeExternal |
Methods inherited from class java.lang.Object |
clone,
equals,
finalize,
getClass,
hashCode,
notify,
notifyAll,
wait,
wait,
wait |
Field Detail |
protected KeyDef keydefval
Constructor Detail |
public TableDataSet(java.sql.Connection conn, java.lang.String tablename) throws java.sql.SQLException, DataSetException
conn
- Connection objecttablename
- Table name in the databasepublic TableDataSet(java.sql.Connection conn, java.lang.String tablename, java.lang.String attributes) throws java.sql.SQLException, DataSetException
conn
- Connection objecttablename
- Table name in the databaseattributes
- Attributes of the table to usepublic TableDataSet(java.sql.Connection conn, java.lang.String tablename, KeyDef key) throws DataSetException, java.sql.SQLException
conn
- Connection objecttablename
- Table name in the databasekey
- KeyDef objectpublic TableDataSet(java.sql.Connection conn, java.lang.String tablename, java.lang.String attributes, KeyDef key) throws DataSetException, java.sql.SQLException
conn
- Connection objecttablename
- Table name in the databaseattributes
- Attributes of the table to usekey
- KeyDef objectpublic TableDataSet(java.sql.Connection conn, Schema schema, KeyDef key) throws DataSetException, java.sql.SQLException
conn
- Connection objectschema
- Schema from previous TDSkey
- KeyDef objectpublic TableDataSet()
Method Detail |
public DataSet fetchRecords(int start, int maxrecs) throws java.sql.SQLException, DataSetException
start
- Position of first record to fetchmaxrecs
- Maximum number of records to fetchpublic void setRefreshOnSave(boolean yesOrNo)
yesOrNo
- True to enable refresh on savepublic boolean refreshOnSave()
public void updateStatus() throws java.sql.SQLException, DataSetException
public void refresh(java.sql.Connection conn) throws java.sql.SQLException, DataSetException
conn
- Connection objectpublic KeyDef keydef()
public java.lang.String tableName()
public java.lang.String attributes()
public Schema schema()
public int save() throws java.sql.SQLException, DataSetException
public int save(boolean intransaction) throws java.sql.SQLException, DataSetException
intransaction
- True if in a transactionpublic int save(java.sql.Connection conn, boolean intransaction) throws java.sql.SQLException, DataSetException
Set intransaction to False (the default) if you call this method without starting a transaction. In this case, the method updates a row in the database, then updates the status of the corresponding row in the TableDataSet so that the database status matches the TableDataSet status.
conn
- Connection objectintransaction
- True if in a transactionpublic int saveWithoutStatusUpdate(java.sql.Connection conn) throws java.sql.SQLException, DataSetException
public void removeDeletedRecords() throws DataSetException
public java.lang.String getSelectString()
public TableDataSet where(java.lang.String str)
str
- Specifies the WHERE clausepublic TableDataSet order(java.lang.String str)
str
- Specifies the ORDER BY clauseprotected java.lang.String orderstr()
public TableDataSet other(java.lang.String str)
str
- Specifies the ORDER BY clausepublic TableDataSet tableQualifier(java.lang.String str)
str
- Specifies the table clause qualifierpublic java.lang.String debugInfo()
public SelectStmt selectStmt()
SelectStmt
public java.sql.ResultSet resultSet() throws java.sql.SQLException, DataSetException
public void setOptimisticLockingColumn(java.lang.String colName) throws DataSetException
colName
- The column name that is used for optimistic locking.public java.lang.String optimisticLockingCol()
|
Documentation is available at http://download.oracle.com/docs/cd/E13222_01/wls/docs61 |
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |