|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--waba.io.Stream | +--waba.io.Catalog
Catalog is a collection of records commonly referred to as a database on small devices.
Here is an example showing data being read from records in a catalog:
Catalog c = new Catalog("MyCatalog", Catalog.READ_ONLY); if (!c.isOpen()) return; DataStream ds = new DataStream(c); int count = c.getRecordCount(); for (int i = 0; i < count; i++) if (c.setRecordPos(i)) { String name = ds.readString(); int age = ds.readShort(); double salary = ds.readDouble(); ... } c.close();
Note: a Catalog cannot be opened twice. You must close one instance before opening the other or share the same instance.
In Windows CE, you can specify the path of the pdb file, either absolute ("\\My Documents\\Test") or relative ("..\\..\\Test").
Field Summary | |
static int |
CREATE
Create open mode. |
static int |
DB_ATTR_APPINFODIRTY
Set if Application Info block is dirty. |
static int |
DB_ATTR_BACKUP
Set if database should be backed up to PC if no app-specific synchronization conduit has been supplied. |
static int |
DB_ATTR_COPY_PREVENTION
This database should not be copied to |
static int |
DB_ATTR_OK_TO_INSTALL_NEWER
This tells the backup conduit that it's OK for it to install a newer version of this database with a different name if the current database is open. |
static int |
DB_ATTR_READ_ONLY
Read Only database |
static int |
DB_ATTR_RESET_AFTER_INSTALL
Device requires a reset after this database is installed. |
static int |
DB_ATTR_STREAM
This database is used for file stream implementation. |
static int |
READ_ONLY
Read-only open mode. |
static int |
READ_WRITE
Read-write open mode. |
static byte |
REC_ATTR_DELETE
Record atribute: Deleted. |
static byte |
REC_ATTR_DIRTY
Record atribute: Dirty (has been modified since last sync) |
static byte |
REC_ATTR_SECRET
Record atribute: Private |
static int |
WRITE_ONLY
Write-only open mode. |
Constructor Summary | |
Catalog()
this constructor was created to let users use the toPdb and fromPdb methods if running in the desktop. |
|
Catalog(String name,
int mode)
Opens a catalog with the given name and mode. |
Method Summary | |
int |
addRecord(int size)
Adds a record to the end of the catalog. |
int |
addRecord(int size,
int pos)
Adds a record to the |
boolean |
close()
Closes the catalog. |
boolean |
delete()
Deletes the catalog. |
boolean |
deleteRecord()
Deletes the current record and sets the current record position to -1. |
int |
getAttributes()
Retrieves this catalog's attributes. |
byte |
getRecordAttributes()
Deprecated. use getRecordAttributes(recordPos) instead. |
byte |
getRecordAttributes(int recordPos)
Retrieves the attributes of the current record. |
int |
getRecordCount()
Returns the number of records in the catalog or -1 if the catalog is not open. |
int |
getRecordOffset()
Returns the internal record offset. |
int |
getRecordPos()
Returns the current record position or -1 if there is no current record. |
int |
getRecordSize()
Returns the size of the current record in bytes or -1 if there is no current record. |
int |
inspectRecord(byte[] buf,
int recPosition)
Inspects a record. use this method with careful, none of the params are checked for validity. the cursor is not advanced, neither the current record position. this method must be used only for a fast way of viewing the contents of a record, like searching for a specific header or filling a grid of data. |
boolean |
isOpen()
Returns true if the catalog is open and false otherwise. |
static String[] |
listCatalogs()
Returns the complete list of existing catalogs. |
static String[] |
listCatalogs(int creatorId,
int type)
Returns the list of existing catalogs with the given creator id and/or type. |
int |
readBytes(byte[] buf,
int start,
int count)
Reads bytes from the current record into a byte array. |
boolean |
rename(String newName)
Renames the currently open catalog to the given name. |
boolean |
resizeRecord(int size)
Resizes a record. |
void |
setAttributes(int i)
Sets this catalog's attributes, defined by the DB_ATTR_xxx constants. |
void |
setRecordAttributes(byte attr)
Deprecated. use setRecordAttributes(recordPos, attr) instead. |
void |
setRecordAttributes(int recordPos,
byte attr)
Sets the attributes of the current record. |
boolean |
setRecordPos(int pos)
Sets the current record position and locks the given record. |
int |
skipBytes(int count)
Offsets the cursor in the current record a number of bytes. |
int |
writeBytes(byte[] buf,
int start,
int count)
Writes to the current record. |
Methods inherited from class java.lang.Object |
equals,
getClass,
hashCode,
notify,
toString,
wait,
wait |
Field Detail |
public static final int READ_ONLY
public static final int WRITE_ONLY
public static final int READ_WRITE
public static final int CREATE
public static final int DB_ATTR_READ_ONLY
public static final int DB_ATTR_APPINFODIRTY
public static final int DB_ATTR_BACKUP
public static final int DB_ATTR_OK_TO_INSTALL_NEWER
public static final int DB_ATTR_RESET_AFTER_INSTALL
public static final int DB_ATTR_COPY_PREVENTION
public static final int DB_ATTR_STREAM
public static final byte REC_ATTR_DELETE
public static final byte REC_ATTR_DIRTY
public static final byte REC_ATTR_SECRET
Constructor Detail |
public Catalog(String name, int mode)
For PalmOS: A PalmOS creator id and type can be specified by appending a 4 character creator id and 4 character type to the name seperated by periods. For example:
Catalog c = new Catalog("MyCatalog.CRTR.TYPE", Catalog.CREATE);Will create a PalmOS database with the name "MyCatalog", creator id of "CRTR" and type of "TYPE".
If no creator id and type is specified, the creator id will default to the creator id of current SuperWaba program and the type will default to "DATA". Note that in desktop the complete form is required.
Under PalmOS, the name of the catalog must be 31 characters or less, not including the creator id and type. Windows CE supports a 32 character catalog name but to maintain compatibility with PalmOS, you should use 31 characters maximum for the name of the catalog. Every time the database is modified the backup attribute is set.
name
- catalog name. Don't use accentuated characters in the catalog name.mode
- one of READ_ONLY, WRITE_ONLY, READ_WRITE or CREATEpublic Catalog()
Method Detail |
public boolean rename(String newName)
Here is an example of use:
Catalog c = new Catalog("guich.Crtr.Type",Catalog.READ_ONLY); if (c.isOpen()) c.rename("flor.CrTr.TyPe"); c.close();
public int addRecord(int size)
size
- the size in bytes of the record to addpublic int addRecord(int size, int pos)
size
- the size in bytes of the record to addpublic boolean resizeRecord(int size)
size
- the new size of the recordpublic boolean close()
public boolean delete()
After this, the catalog is closed (of course).
Note that this behavior is different between running on desktop and running on palm os, because in applets we cannot erase files at the server, in this case only records are all deleted, but file still exists, with palm-info-header. PS: since 3.0, the catalog may be deleted in applet too.
public static String[] listCatalogs()
public static String[] listCatalogs(int creatorId, int type)
public boolean deleteRecord()
public int getRecordCount()
public int getRecordSize()
public boolean isOpen()
public boolean setRecordPos(int pos)
public int readBytes(byte[] buf, int start, int count)
buf
- the byte array to read data intostart
- the start position in the arraycount
- the number of bytes to readpublic int skipBytes(int count)
count
- the number of bytes to skippublic int writeBytes(byte[] buf, int start, int count)
buf
- the byte array to write data fromstart
- the start position in the byte arraycount
- the number of bytes to writepublic int inspectRecord(byte[] buf, int recPosition)
public byte getRecordAttributes()
public void setRecordAttributes(byte attr)
public byte getRecordAttributes(int recordPos)
public void setRecordAttributes(int recordPos, byte attr)
public int getAttributes()
public void setAttributes(int i)
public int getRecordPos()
public int getRecordOffset()
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |