Simulates a very simple URL tagging application a la delicious.com, which allows users to tag any URL on the internet with one or more tags/labels. See also FirstStep, which does the same thing in memory.
Obtain, compile and run
- Download FirstStepWithMySQL from the downloads page, and uncompress (instructions)
- Run ant to compile and run, e.g. ant build run
- Two apps will run:
- The first app instantiates some objects representing bookmarks and tags in a graph, which is persisted in MySQL, using it as a key-value store.
- The second app reads the graph from the database and traverses the graph to print out the data in different ways
Annotated source code
Compare with FirstStep, which keeps the object graph in memory only. The key difference are the following lines:
Instead of creating a MeshBase in memory:
MeshBase mb = MMeshBase.create();
MeshBase mb = StoreMeshBase.create( store );
where Store could be any kind of store supporting Store abstraction. In this example, we use MySQL because many developers are familiar with it and InfoGrid contains a MySQL-based implementation of Store called MySqlStore. We instantiate it as follows:
MysqlDataSource ds = new MysqlDataSource(); ds.setDatabaseName( "test" ); // name of the database MysqlStore store = MysqlStore.create( ds, "test" ); // name of the single table used in this example app store.initializeIfNecessary(); // will create table if not there, but does not touch data
To run the same example using PostgreSQL? Simply instantiate PostgresqlStore instead. Or FilesystemStore or HadoopStore...