net.sourceforge.mayfly.JdbcDriver Class Reference

List of all members.

Detailed Description

JDBC Driver for Mayfly.

In many cases, it will be more convenient to instantiate a net.sourceforge.mayfly.Database object, and then call net.sourceforge.mayfly.Database#openConnection() on it (from there on out, you don't need to do anything mayfly-specific).

However, if you want to create a JDBC connection via non-mayfly-specific means (for example, via a database mapping layer like Hibernate or SqlMaps), you may need to access mayfly via a JDBC URL. This creates a bit of work in terms of getting your tests to run independently of each other (one line summary: call shutdown from your tearDown method).

One connects via standard JDBC mechanisms, using a JDBC URL of one of the following two forms:

  1. The URL jdbc:mayfly: means to open the default database. The default database will be created if it doesn't exist (without tables or data). The default database is destroyed by calling shutdown.

  2. If you want to start a database with some tables or data, you can call create(DataStore), which will return a new URL to you. This database lives until the next call to shutdown.

If you specify a username or a password via JDBC, Mayfly ignores them.

Example:

 Class.forName("net.sourceforge.mayfly.JdbcDriver");
 Connection connection = DriverManager.getConnection("jdbc:mayfly:");
 


Static Public Member Functions

static String create (DataStore dataStore)
 Create a database which you want to access via a JDBC URL.
static void shutdown ()
 Destroy databases managed by JdbcDriver.


Member Function Documentation

static String net.sourceforge.mayfly.JdbcDriver.create DataStore  dataStore  )  [static]
 

Create a database which you want to access via a JDBC URL.

For many purposes, it will be more convenient to instantiate a Database object, but if you need a JDBC URL (for example, to pass to a database mapping layer like Hibernate or SqlMaps), call this method instead.

Example:

    static final DataStore standardSetup = makeData();

    private static DataStore makeData() {
        try {
            Database original = new Database();
            original.execute("create table foo (a integer)");
            original.execute("insert into foo(a) values(6)");
            return original.dataStore();
        } catch (SQLException e) {
            throw new RuntimeException(e);
        }
    }

    String jdbcUrl;
    public void setUp() {
        jdbcUrl = JdbcDriver.create(standardSetup);
    }

    public void tearDown() {
        JdbcDriver.shutdown();
    }
    
Parameters:
dataStore The initial contents of the database.

static void net.sourceforge.mayfly.JdbcDriver.shutdown  )  [static]
 

Destroy databases managed by JdbcDriver.

That is, destroy all databases which have been created with create(DataStore), plus the default database (the one with url jdbc:mayfly:).

Databases created by calling constructors of Database directly are instead garbage collected like any other object.


The documentation for this class was generated from the following file:
For more information on Mayfly see mayfly.sourceforge.net.