|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--com.ibm.mobileservices.isync.midp.TableMetaData
This class holds table information within an ISyncSubscriptionSet, consisting of the name of the table, the number of columns in the table, the type of each column, if it is nullable, and if it is a primary key.
The application (MIDLET) designer is responsible for reading and writing the raw data in the byte arrays read from and written to FastRecordStore and Index .
This format is described below.
Every row has an extra byte at its beginning to indicate if the application modified the row, this byte is intially zero. The application designer is required to update this byte if they DELETE, UPDATE or INSERT a row into RMS. This indicates that on a future SYNCHRONIZE request the rows should be sent to DB2 Everyplace to be included in the source database.
If the sync is successful, we clear the dirty bytes in those rows.
Failure to set this byte to ISync.ROW_ADDED, ISync.ROW_CHANGED, ISync.ROW_DELETED will cause your changes to never be replicated.
Within each row, for each column, if it is nullable, call DataInputStream.readBoolean to get the null indicator. If null, no data for the column follows.
If not null (indicator is false) or if the column is not nullable, the following table indicates which DataInputStream/DataOutputStream method to call.
SQL Data Type on Data Source | java.sql.Types on MIDP Client | Java Data Type on MIDP Client |
datalink | // unsupported | N/A |
time | INTEGER | int |
date | INTEGER | int |
timestamp | LONG | long |
blob | LONGVARCHAR | String, or byte[] |
char | CHAR | String |
varchar | VARCHAR | String |
clob | LONGVARBINARY | String, or byte[] |
graphic | // unsupported | N/A |
vargraphic | // unsupported | N/A |
dbclob | // unsupported | N/A |
real | REAL | String |
double precision | DOUBLE | String |
bit | VARCHAR | String |
//unsupported | TINYINT | N/A |
smallint | SMALLINT | short |
int | INTEGER | int |
bigint, int8 | BIGINT | long |
numeric | VARCHAR | String |
SQL Type | JAVA Type | DataOut/InputStream method |
INT8, BIGINT | long | writeLong, readLong |
CHAR | String | writeUTF, readUTF |
VARCHAR | String | writeUTF, readUTF |
DATE, TIME | int (see below) | writeInt, readInt |
TIMESTAMP | long (see below) | writeLong, readLong |
DECIMAL, NUMERIC | String | writeUTF, readUTF |
INTEGER | int | writeInt, readInt |
SMALLINT | short | writeShort, readShort |
TINYINT | byte | writeByte, readByte |
BLOB/CLOB | String | writeUTF, readUTF |
DATE stored in an integer is represented as follows:
All values are 1 based, e.g. Jan == 1.int dt = din.readInt(); int year = dt >> 16; int mon = (dt >> 8) & 0xFF; int day = dt & 0xFF;
TIME is represented as:
int tm = din.readInt(); int hour = tm >> 16; int min = (tm >> 8) & 0xFF; sec = tm & 0xFF;TIMESTAMP stores the DATE in the upper 4 bytes of the Long and TIME in the lower:
long ts = dinr.readLong(); int dt = (int) (ts >> 32);int year = dt >> 16; int mon = (dt >> 8) & 0xFF; int day = dt & 0xFF;
int tm = (int) (ts & 0xFFFF);
int hour = tm >> 16; int min = (tm >> 8) & 0xFF; int sec = tm & 0xFF;
create table isyncUSync (a int, b int not null, c varchar(20), id bigint not null primary key)the rowdata would be interpreted as follows:insert into isyncUSync values (null, 10, 'some text', 99);
DataOutputStream dout = new DataOutputStream(byteArrayOutStrm);dout.writeByte(ISync.ROW_ADDED); // dirty byte, flags byte at start of row
dout.writeBoolean(true); // 'a' is null, no data follows
dout.writeInt(10); // 'b', not nullable, no null ind
dout.writeBoolean(false); // c is nullable, but not null
dout.writeUTF("some text");
dout.writeLong(99); // 'id' not nullable
TableMetaData rs = ((MIDPISync)isync).getTableMetaDataByName(storeName); int numCols = rs.getNumCols(); FastRecordStore rms = FastRecordStore.openRecordStore(storeName, false); Index index = new Index(rms, rs); FastRecordEnumeration enum = rms.enumerateRecords(null, null, false); while (enum.hasNextElement()) {int id = enum.nextRecordId(); int recSize = rms.getRecordSize(id); byte data = new byte[recSize]; recSize = rms.getRecord(id, data, 0); // found record to delete from source database, during next sync cycle if (id == rowToDelete) {}// mark row dirty data[0] = ISync.ROW_DELETED; index.updateRecord(id, data, recSize); continue; // to next row} ByteArrayInputStream bin = new ByteArrayInputStream(data); DataInputStream din = new DataInputStream(bin);din.readByte(); // dirty byte, flags byte at start of row
for (int c = 0; c < numCols; c++) {
int type = rs.getType(c); boolean isNullable = rs.isNullable(c); boolean ind = false; if (isNullable)}ind = din.readBoolean(); // null indicatorif (ind)continue;switch (type) {case CHAR: case VARCHAR: strval = din.readUTF(); break;}case INTEGER: case DATE: case TIME: intval = din.readInt(); break; // etc
Field Summary | |
java.lang.String |
operation
|
Constructor Summary | |
TableMetaData(java.lang.String name,
byte[] schema,
int schemaLen,
boolean readOnlyTable)
Called from JavaCommonISync after reading schema from SS |
Method Summary | |
java.lang.String |
getColumnName(int colnum)
Return column name, if present |
int |
getNumCols()
Get the number of columns in this table |
int |
getNumPrimaryKeys()
Return the number of primary keys |
java.lang.String |
getTableName()
Return the name of the table represented by this TableMetaData |
short |
getType(int colnum)
Return the com.ibm.mobileservices.isync.sql.Types java type, colnum is 0 based. |
boolean |
isNullable(int colnum)
Return if this column is nullable, colnum is 0 based. |
boolean |
isPrimaryKey(int colnum)
Return if this column is the primary key, colnum is 0 based. |
boolean |
isReadOnlyTable()
|
java.lang.String |
toString()
|
Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
public java.lang.String operation
Constructor Detail |
public TableMetaData(java.lang.String name, byte[] schema, int schemaLen, boolean readOnlyTable) throws java.io.IOException
Method Detail |
public int getNumPrimaryKeys()
public short getType(int colnum) throws java.lang.Exception
java.lang.Exception
Types
public boolean isNullable(int colnum) throws java.lang.Exception
java.lang.Exception
public boolean isPrimaryKey(int colnum) throws java.lang.Exception
java.lang.Exception
public java.lang.String getColumnName(int colnum) throws java.lang.Exception
java.lang.Exception
public java.lang.String getTableName()
public int getNumCols()
public boolean isReadOnlyTable()
public java.lang.String toString()
toString
in class java.lang.Object
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |