Using ASPersistence with a Database

You can use the ASPersistence example with a database for the data store. The default database supported in the code is PostgreSQL. The class MySQLConnection is also provided to show you how easy it is to build on the current ASPersistence example to support a different database.

Procedure

  1. Ensure your database server is running.
  2. Create a database for use with the ASPersistence example.
  3. Modify your CLASSPATH to include the JDBC driver jar file for your database
  4. Modify the file ASPersistence.java as follows:
    1. Uncomment the following import statement at the beginning of the file:
      //import persistence.ASPersister;
    2. Comment out the following import statement at the beginning of the file:
      import persistence.SimplePersister;
    3. Comment out the following lines in the ASPersistence constructor:
      persister = space.setPersister(new SimplePersister(spaceDef));
    4. Uncomment the following line in the ASPersistence constructor:
      //persister = space.setPersister(new ASPersister(metaspace));
  5. Modify the file ASPersister.java as follows:
    1. Ensure that the values for DB_NAME, DB_HOST, USER_NAME, and USER_PASS are set appropriately for your database.
    2. Ensure that JDBC_DRIVER and JDBC_URL are set appropriately for your database.
    3. In the onOpen method, ensure that the appropriate database connection class is being instantiated.
  6. Rebuild Examples.jar.
  7. Invoke the ASPersistence and ASOperations examples as described in Starting ASPersistence, and ensure that your CLASSPATH has been set appropriately as described in Step 3.