dataweb.datastore.Table calss is main one for table access management. It manage permissions, concurrence and data transaction.
This class permit to define table structure and manage data content, and work on table like a cursor.
Method are:

first()
move on first table record

previous()

move on previous record

next()
move on next record.

last()

move on last table record

moveTo(<UID>)
move on record with UID = <UID>.

seek(<IndexName>,<Values>)
move on record with values set to <Values>. Values are select via unique index <IndexName>.

seek(<transaction>,<IndexName>,<Values>)
as previous method but add the transaction object.

beforeFirst()
move before first record

afterLast()
move after last record

As soon move on a record we can read values via those method:

getValue(<ColName>)
Return <ColName> column value. This method also permit to got to a value  into a relate table via this syntax:

table.getValue(<ColRel>.<ColTabRel>);

where <ColRel> is a relate column name and <ColTabRel> is a name of relate column.

getValue(<IdxCol>)

Return value of <IdxCol> column.

getValues()

Return an array of value that are the column of current record.

getData(<startRow>, <size>)

Return a data matrix where initial row is <startRow> and <size> the number of desidereed row . Valid for subtable


In order to edit or add data into the table we can use those method:

edit()

open an edit on current record

addNew()

open an add a new record

setValue(<ColName>, <Value>)
set the value <Value> for column <ColName> for current edit.

setValue(<IdxCol>, <Value>)
set the value <Value> for the column with index <IdxCol> for current record.

update()
confirm the edit on record or the add new record. It can be used just after edit or addNew

update(<transaction>)

as previous method, but manage transaction too.

cancelUpdate()
undo the edit on record or the add new record.It can be used just after edit or addNew

remove()
remove current record


Next method return record information:

getState()
return record state:

STATE_NONE : record in view mode.
STATE_EDIT : record in edit mode
STATE_ADDNEW: new record

getUID()
return unique Id for current record.

isBeforeFirst()
return if is positioned before first record.

isAfterLast()
return if is positioned after last record.


Additional method:

getSchema()
return an object with info on table definition.

getExtended()
Return object that is code manager built into the table. It permit use of public method of the table.

In case of the table definition include sub-table, each time we are on a table record, the subtable got the relate information. For each record in main table can be present from 0 to N record into subtable. All edit on set of records of table and subtables are stored only after  update() method is used on main table.
Method for subtable management:

getSubTableCount()

number of subtable relate to main table.

getSubTable(<SubTabName>)
return the subtable <SubTabName>. Methos return another instance of table class where we can work with previouses method. Please note a subtable also can be relate to subtable and so on.

getSubTable(<IdxSubTab>)
return subtable with index <IdxSubTab>.

isRootTable()

true If table is on main table

getValue(<Row>, <ColName>)
return column  <ColName> value for record on row <Row>.
Valid for subtable only (isRootTable() = false).

getValue(<Row>, <IdxCol>)
Return calue of coolumn with index <IdxCol> for record of row <Row>.
Valid for subtable only (isRootTable() = false).

getRow()
return position of current row
Valid for subtable only (isRootTable() = false).

getRowCount()
return row number for subtable
This method can be used for main table too, but in this case it return number of record calculate on-fly.

absolute(<Row>)
it move on row <Row>.
Valid for subtable only (isRootTable() = false).


In order to create a class Table instance is mandatory to got dbSession object in order to create, edit, open a table, method are:

dbSession.newTable(<TableName>)
dbSession.editTable(<TableName>)
dbSession.openTable(<TableName>)

newTable and editTable method return a table instance relate to table structure. openTable return a table instance relate to table content.
If for example we want to create a table, the code to use is:

Table tbl = dbSession.newTable("<Package>.<Table>");
tbl.setValue("<PropertyName>", <Value>);
.....
Table tblcols = tbl.getSubTable("Columns");
tblcols.addNew();
tblcols.setValue("Name", <ColumnName 1>);
tblcols.setValue("DataType", <DataType 1>);
tblcols.setValue("<PropertyName>", <Value>);
.....
tblcols.update();
tblcols.addNew();
tblcols.setValue("Name", <ColumnName 2>);
tblcols.setValue("DataType", <DataType 2>);
tblcols.setValue("<OtherPropertyName>", <Value>);
.....
Table tblav = tblcols.getSubTable("AllowValues");
tblav.addNew();
tblav.setValue("Value", <Value 1>);
tblav.setValue("Label", <Label 1>);
tblav.update();
tblcols.update();
....
Table tblidx = tbl.getSubTable("Index");
tblidx.addNew();
tblidx.setValue("Name", <IndexName>);
tblidx.setValue("<PropertyName>", <Value>);
.....
tblidx.update();
....
Table tblsubt = tbl.getSubTable("SubTables");
tblsubt.addNew();
tblsubt.setValue("Name", <SubTableName>);
tblsubt.setValue("<PropertyName>", <Value>);
.....
tblsubt.update();
tbl.update();
tbl.close();


When we create or edit a table, class table of root table do not permit to use method for positioning like first, previous, next, last, seek, ecc....
If we want to manipulate table data, for example to edit a record value, and add row to a subtable, we can use this code:

Table tbl = dbSession.openTable("<Package>.<Table>");
if (tbl.seek("<IndexUnique>","<IndexValues">)){
tbl.edit();
tbl.setValue("<ColumnName>", <NewValue>);
Table subt = tbl.getSubTable("<SubTableName>");
subt.addNew();
subt.setValue("<ColumnName>", <NewValue>);
.....
subt.update();
subt.addNew();
subt.setValue("<ColumnName>", <NewValue>);
.....
subt.update();
.....
tbl.update();
}
tbl.close();

Last updatedFriday, 19 November 2010 23:22