Use the following steps to run a Java client to interact with
the data grid. The catalog server, container server, and client all run on a
single server in this example.
Before you begin
(Optional) Edit the wxs_install_root/ObjectGrid/gettingstarted/env.bat|sh file. This file is invoked by the
client automatically. The file contains the following information:
SET CATALOGSERVER_HOST=localhost
SET CATALOGSERVER_PORT=2809
SET GRID_NAME=Grid
SET MAP_NAME=Map1
You must update the CATALOGSERVER_HOST and
CATALOGSERVER_PORT values if your catalog server is not running on the same
host as your client application.
Procedure
-
Run the client in interactive mode.
-
Start a transaction.
You can use a one-phase commit or a two-phase commit operation for your transaction. With a
one-phase commit, the transaction must write to a single partition. If you insert several keys
during your transaction that are placed in different partitions, the transaction fails when you
commit. You can use a two-phase commit to write to multiple partitions in a single transaction.
- Begin a one-phase commit transaction.
begin
- Begin a two-phase commit transaction.
begin2pc
-
Insert a value.
> i key1 helloWorld
SUCCESS: Inserted TestValue [value=helloWorld] with key TestKey [key=key1], part
itionId=6
-
Retrieve a value that you inserted.
> g key1
Value is TestValue [value=helloWorld], partitionId=6
-
Update a value.
> u key1 goodbyeWorld
SUCCESS: Updated key TestKey [key=key1] with value TestValue [value=goodbyeWorld
], partitionId=6
-
Rollback the transaction.
When you roll back the transaction, all operations that are associated with this transaction
are canceled.
> rollback
-
To test the rollback operation, try getting the key again.
Because you rolled back the transaction, the key does not exist:
> g key1
-
Insert a value.
> i key1 helloWorld
SUCCESS: Inserted TestValue [value=helloWorld] with key TestKey [key=key1], part
itionId=6
-
Delete a value that you inserted.
> d key1
SUCCESS: Deleted value with key TestKey [key=key1], partitionId=6
-
Insert a number of test entries.
For example, to insert 1000 keys and values that are numbered from 0 to 999, use the
following command:
> n 1000
-
Run the client in command-line mode.
Using command-line mode can be useful if you want to write a script to run the client
application. You can run the same commands that you run in interactive mode. An example of the
syntax for command-line mode follows: