MySQL Attribute Persistence

Overview

org.moock.unity.opt.sqlap.SQLAttributePersistence is an AttributePersistence Object for MySQL database. It is a simple but effective implementation and can be used as a guide for more complex implementations. Tables are created automatically by the Server when the server starts up if they don't already exist. Only String Attributes can be persisted. All Attributes set via UPCRoom are String so this is only a concern for Attributes set by other Rooms which may store different Objects. Client persistence is done by a clientID and clientPassword combination.

Deploying to the Server

Creating and Logging In

Server and Room persistence is handled automatically. Client persistence must be initiated by a Room using the ClientManagementServices Object.
All arguments passed in args for are Strings.

createPersistentClient(String clientID, ArrayList args)

args 0 identifies the Client across sessions (eg. username).
args 1 the password for the Client which must be matched for loginClient

removePersistentClient(String clientID, ArrayList args)

args 0 identifies the Client across sessions (eg. username).

loginClient(String clientID, ArrayList args)

args 0 identifies the Client across sessions (eg. username).
args 1 the password GIVEN which must match the existing password to login successfully

So to create a new client in the database for the client with clientID 45 (obtained via ClientServices getClientID()) you would use something like the following code:

ArrayList args = new ArrayList();
args.add("james");
args.add("7hth3n3");
Services.getClientManagementServices().createPersistentClient("45", args);

Of course generally you will not hardcode the username and password but will instead retrieve it from Messages sent by the Client. See the code in UPCRoom for a demonstration of how UPCRoom uses this AttributePersistence.