One of the benefits of ROP is that the client code is no different from the server code - it uses the same ObjectContext interface for access, same query and commit API. So the code below will be similar to the code presented in the first Cayenne tutorial, although with a few ROP-specific parts required to bootstrap the ObjectContext.
Let's start by creating an empty Main class with the standard main() method in the client project:
Now the part that is actually different from regular Cayenne - establishing the server connection and obtaining the ObjectContext:
Note that the "channel" can be used to create as many peer ObjectContexts as needed over the same connection, while ObjectContext is a kind of isolated "persistence session", similar to the server-side context. A few more notes. Since we are using HTTP(S) to communicate with ROP server, there's no need to explicitly close the connection (or channel, or context).
So now let's do the same persistent operaions that we did in the first tutorial "Main" class. Let's start by creating and saving some objects:
Now let's select them back:
This code is exactly the same as in the first tutorial. So now let's try running the client and see what happens. In Eclipse open main class and select "Run > Rus As > Java Application" from the menu (assuming the ROP server started in the previous step is still running). You will some output in both server and client process consoles. Client:
As you see client prints no SQL statmenets, just a bunch of query and flush messages sent to the server. The server side is more verbose, showing the actual client queries executed against the database:
You are done with the basic ROP client!