Extend the samskivert provided default repository implementation now and

use the samskivert version of JORA.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@40 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-02-13 05:48:29 +00:00
parent c2db44dd77
commit 826a3f1749
@@ -1,5 +1,5 @@
//
// $Id: Repository.java,v 1.1 2000/11/08 06:42:57 mdb Exp $
// $Id: Repository.java,v 1.2 2001/02/13 05:48:29 mdb Exp $
package robodj.repository;
@@ -7,8 +7,9 @@ import java.sql.*;
import java.util.List;
import java.util.Properties;
import com.samskivert.jdbc.MySQLRepository;
import com.samskivert.jdbc.jora.*;
import com.samskivert.util.*;
import jora.*;
/**
* The repository class provides access to the music information
@@ -19,7 +20,7 @@ import jora.*;
* <p> Entries are stored in the repository according to genre. An entry
* may be associated with multiple genres.
*/
public class Repository
public class Repository extends MySQLRepository
{
/**
* Creates the repository and opens the music database. A properties
@@ -38,23 +39,12 @@ public class Repository
public Repository (Properties props)
throws SQLException
{
// create our JORA session
String dclass =
requireProp(props, "driver", "No driver class specified.");
_session = new Session(dclass);
// connect the session to the database
String url =
requireProp(props, "url", "No driver url specified.");
String username =
requireProp(props, "username", "No driver username specified.");
String password =
requireProp(props, "password", "No driver password specified.");
_session.open(url, username, password);
// set auto-commit to false
_session.connection.setAutoCommit(false);
super(props);
}
protected void createTables ()
throws SQLException
{
// create our table objects
_etable = new Table(Entry.class.getName(), "entries", _session,
"entryid");
@@ -66,28 +56,6 @@ public class Repository
_session, new String[] {"categoryid", "entryid"});
}
protected static String requireProp (Properties props,
String name, String errmsg)
throws SQLException
{
String value = props.getProperty(name);
if (StringUtil.blank(value)) {
throw new SQLException(errmsg);
}
return value;
}
/**
* A repository should be shutdown before the calling code disposes of
* it. This allows the repository to cleanly terminate the underlying
* database services.
*/
public void shutdown ()
throws SQLException
{
_session.close();
}
/**
* @return the entry with the specified entry id or null if no entry
* with that id exists.
@@ -158,19 +126,6 @@ public class Repository
}
}
protected int lastInsertedId ()
throws SQLException
{
// we have to do this by hand. alas all is not roses.
Statement stmt = _session.connection.createStatement();
ResultSet rs = stmt.executeQuery("select LAST_INSERT_ID()");
if (rs.next()) {
return rs.getInt(1);
} else {
return -1;
}
}
/**
* Updates an entry that was previously fetched from the database. The
* number of songs in the songs array <em>must not</em> have changed
@@ -386,7 +341,6 @@ public class Repository
}
}
protected Session _session;
protected Table _etable;
protected Table _stable;
protected Table _ctable;