The Web Graph Database

wiki:Examples/FirstStepWithMySQL

Examples: FirstStepWithMySQL

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

  1. Download FirstStepWithMySQL from the downloads page, and uncompress (instructions)
  2. Run ant to compile and run, e.g. ant build run
  3. 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();

we are creating a MeshBase using the Store abstraction:

    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...

Easy? Take the 1-minute survey. Feel free to ask questions on the MailingLists ...

Last modified 5 years ago Last modified on 02/17/10 06:25:26