|
ZCache ZCacheBean Documentation
For detailed JavaDoc documentation about the APIs in this bean, click
here.
We often refer to ZCacheBean as the ZCacheClient, or just the "client", since ZCacheClient is the
name of the class that must be instantiated in order to make calls to its public methods.
The code snippets included here are by no means definitive, but they will give the developer a good starting
point on how to implement this bean. Obviously, a ZCache server must be running and properly configured in order
for these snippets to work. As with any database program the tables and fields must exist.......
These samples are just a guideline.
Examples
In the documentation for the APIs (Methods) you'll see that the data returned is in a String[] form. This is
the case with all the methods.
IMPORTANT!
If you are NOT using the ZCacheBean.jar, remember that when doing a read operation, the return data will include
a cache object number. There is a significant improvement in read times if you use this object number as a part
of the read. ( i.e. R:433 ) The performance boost comes into play because the same search object can be reused
with significantly less processing than when the object identifier is not included. The ZCacheBean jar uses object
numbers automatically, improving performance and simplifying development.
While it is true that an existing object will be located and used whenever possible, performance is degraded.
Use the object number whenever possible.
Client Initialization
Before you can make any of the ZCacheBean.ZCacheClient calls to the methods listed below, you must first initialize
the client.
You do so by making the following calls once for each instantiation of the client:
Instantiation of the client:
private ZCacheBean.ZCacheClient zdc = new ZCacheBean.ZCacheClient();
Set the IP address of ZCache in the client. This tells the client where ZCache is running:
zdc.setIPAddress(IPAddress);
Set the port ZCache is listening on in the client. This tells the client which port to use to communicate with
ZCache:
zdc.setPort(port);
Set the security prefix for ZCache in the client. This tells the client the security prefix to use to communicate
with ZCache. This must match exactly the security prefix found in the configuration of ZCache:
zdc.setSecurityString(securityString);
Set the secure mode flag in the client. This must match the secure mode setting found in the configuration of
ZCache.
If you are not using secure mode, set it to false:
zdc.setSecureMode(false);
Using SecureMode
There are four steps to configuring SecureMode.
- zdc.setUsername("Harry");
- zdc.setPassword("myPwd");
- zdc.setContext("TestProgram1");
- zdc.setSecureMode(true);
After secure mode has been set up all operations are the same. Performance slows somewhat, due to increased
encryption/decryption processing, but in most cases this is not noticeable and is always a price you have to pay
for secure data transfers.
When compared to other encryption systems SecureMode is very fast. Unlike other systems (i.e. SSL), protocol
negotiations are not needed and the result is much faster response to a query.
Insert
String[] req3 =
{
"T:DBUSER",
"I:ID:11",
"F:DBUSERSTATUS_ID:20",
"F:LOGON_NAME:empl",
"F:EMPLOYEE_NUM:110",
"F:FULL_NAME:Employee 1",
"F:PASSWORD:Emp1"
};
result = zdc.putRecord( req3 );
Delete
String[] req2 =
{
"T:DBUSER",
"I:ID:11",
};
result = zdc.delRecord( req2 );
Update
String[] req =
{
"T:DBUSER",
"I:ID:11",
"F:EMPLOYEE_NUM:666"
};
result = zdc.putUpdate( req );
Read
Using ZCache is greatly simplified by using the ZCacheBean. The following are two code snippets that illustrate
the simplicity of using ZCache with this bean.
While understanding the low level protocol is an advantage, with this bean access is really simple.
The following gets a file. zds is an instantiated ZCacheBean.ZCacheClient object.
void getFileBtn_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
zdc.getFile("hosts");
}
void getDataBtn_ActionPerformed_Interaction1(java.awt.event.ActionEvent event)
{
String[] saray =
{
R:",
U:BeanUser",
T:DRIVERS",
I:DRIVER_TYPE_KEY:2",
F:DRIVER_TYPE_KEY",
F:DRIVER_NAME",
F:DRIVER_SIZE",
O:0",
N:1000"
};
results = zds.getData(saray);
}
Return Data Structure
The data returned always returns in the form of a String[]
putRecord():
ZCacheClient returns the text "Inserted OK" in the first element of the returned String array if the
operation was successful. The second element contains the number of the record that was inserted. The application
then knows the record number that was inserted in case it needs to use that record number as an ID in other records
that may be inserted.
delRecord():
ZCacheClient returns the text "Deleted OK" in the first element of the returned String array if the operation
was successful.
putUpdate():
ZCacheClient returns the text "Updated OK" in the first element of the returned String array if the operation
was successful.
getData():
ZCacheClient just returns the information generated by the ZCache request. Each element of the returned String
array represents one record from the database. If no data was found or an error occured, null is returned.
This documentation reflects the latest information available. We intend to expand and improve this document
over time, so you may want to mark this page and return often if you are a developer using ZCache.
|