Modified code to use new repository services. Created proper configuration

files rather than hardcoding configuration in classes. Made startup error
reporting appear in a dialog rather than be written to stderr.


git-svn-id: https://samskivert.googlecode.com/svn/trunk@328 6335cc39-0255-0410-8fd6-9bcaacd3b74c
This commit is contained in:
mdb
2001-09-20 20:42:48 +00:00
parent baf5cade44
commit 4057710901
13 changed files with 247 additions and 157 deletions
+4 -1
View File
@@ -32,6 +32,9 @@
<fileset dir="${src.dir}" includes="**/*.gif"/> <fileset dir="${src.dir}" includes="**/*.gif"/>
<fileset dir="${src.dir}" includes="**/*.jpg"/> <fileset dir="${src.dir}" includes="**/*.jpg"/>
</copy> </copy>
<copy todir="${deploy.dir}/classes/conf">
<fileset dir="conf"/>
</copy>
</target> </target>
<!-- cleans out the installed application --> <!-- cleans out the installed application -->
@@ -67,7 +70,7 @@
<!-- builds our distribution files (war and jar) --> <!-- builds our distribution files (war and jar) -->
<target name="dist" depends="prepare,compile"> <target name="dist" depends="prepare,compile">
<jar jarfile="${deploy.dir}/${dist.jar}" <jar file="${deploy.dir}/${dist.jar}"
basedir="${deploy.dir}/classes"/> basedir="${deploy.dir}/classes"/>
</target> </target>
+6
View File
@@ -0,0 +1,6 @@
#
# $Id: chooser.properties,v 1.1 2001/09/20 20:42:48 mdb Exp $
#
# RoboDJ configuration properties
repository.basedir =/export/robodj/repository
+6
View File
@@ -0,0 +1,6 @@
#
# $Id: importer.properties,v 1.1 2001/09/20 20:42:48 mdb Exp $
#
# RoboDJ configuration properties
repository.basedir =/export/robodj/repository
@@ -0,0 +1,9 @@
#
# $Id: repository.properties.dist,v 1.1 2001/09/20 20:42:48 mdb Exp $
#
# RoboDJ music repository configuration
robodj.driver = org.gjt.mm.mysql.Driver
robodj.username = www
robodj.password = Il0ve2PL@Y
robodj.url = jdbc:mysql://depravity:3306/robodj
@@ -1,15 +1,20 @@
// //
// $Id: Chooser.java,v 1.5 2001/07/26 00:24:22 mdb Exp $ // $Id: Chooser.java,v 1.6 2001/09/20 20:42:48 mdb Exp $
package robodj.chooser; package robodj.chooser;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.io.IOException; import java.io.IOException;
import java.sql.SQLException;
import java.util.Properties; import java.util.Properties;
import javax.swing.JOptionPane;
import com.samskivert.jdbc.PersistenceException;
import com.samskivert.jdbc.StaticConnectionProvider;
import com.samskivert.swing.util.SwingUtil; import com.samskivert.swing.util.SwingUtil;
import com.samskivert.util.ConfigUtil;
import com.samskivert.util.PropertiesUtil; import com.samskivert.util.PropertiesUtil;
import robodj.Log; import robodj.Log;
@@ -33,25 +38,31 @@ public class Chooser
public static void main (String[] args) public static void main (String[] args)
{ {
// set up our configuration by hand for now // load our main configuration
config = new Properties(); String cpath = "conf/chooser.properties";
config.setProperty("repository.db.driver", "org.gjt.mm.mysql.Driver"); try {
config.setProperty("repository.db.username", "www"); config = ConfigUtil.loadProperties(cpath);
config.setProperty("repository.db.password", "Il0ve2PL@Y"); } catch (IOException ioe) {
config.setProperty("repository.db.url", String err = "Unable to load configuration " +
"jdbc:mysql://depravity:3306/robodj"); "[path=" + cpath + "]: " + ioe;
config.setProperty("repository.basedir", "/export/robodj/repository"); reportError(err);
System.exit(-1);
}
// create an interface to the database repository // create an interface to the database repository
try { try {
Properties dbprops = StaticConnectionProvider scp =
PropertiesUtil.getSubProperties(config, "repository.db"); new StaticConnectionProvider("conf/repository.properties");
repository = new Repository(dbprops); repository = new Repository(scp);
model = new Model(repository); model = new Model(repository);
} catch (SQLException sqe) { } catch (IOException ioe) {
Log.warning("Unable to establish communication with music " + reportError("Error loading repository config: " + ioe);
"database: " + sqe); System.exit(-1);
} catch (PersistenceException pe) {
reportError("Unable to establish communication " +
"with music database: " + pe);
System.exit(-1); System.exit(-1);
} }
@@ -81,4 +92,13 @@ public class Chooser
SwingUtil.centerWindow(frame); SwingUtil.centerWindow(frame);
frame.setVisible(true); frame.setVisible(true);
} }
protected static void reportError (String error)
{
Object[] options = { "OK" };
JOptionPane.showOptionDialog(null, error, "Error",
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, options, options[0]);
}
} }
@@ -1,5 +1,5 @@
// //
// $Id: EditDialog.java,v 1.1 2001/07/26 00:24:22 mdb Exp $ // $Id: EditDialog.java,v 1.2 2001/09/20 20:42:48 mdb Exp $
package robodj.chooser; package robodj.chooser;
@@ -8,8 +8,7 @@ import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import javax.swing.*; import javax.swing.*;
import java.sql.SQLException; import com.samskivert.jdbc.PersistenceException;
import com.samskivert.swing.*; import com.samskivert.swing.*;
import com.samskivert.swing.util.*; import com.samskivert.swing.util.*;
@@ -78,7 +77,7 @@ public class EditDialog
* Updates the entry in the repository. * Updates the entry in the repository.
*/ */
public void updateEntry () public void updateEntry ()
throws SQLException throws PersistenceException
{ {
Chooser.model.updateEntry(_entry); Chooser.model.updateEntry(_entry);
} }
@@ -1,16 +1,16 @@
// //
// $Id: EntryList.java,v 1.6 2001/08/06 23:26:42 mdb Exp $ // $Id: EntryList.java,v 1.7 2001/09/20 20:42:48 mdb Exp $
package robodj.chooser; package robodj.chooser;
import java.awt.Font; import java.awt.Font;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.*; import java.util.*;
import javax.swing.*; import javax.swing.*;
import javax.swing.event.*; import javax.swing.event.*;
import com.samskivert.jdbc.PersistenceException;
import com.samskivert.swing.*; import com.samskivert.swing.*;
import com.samskivert.swing.util.*; import com.samskivert.swing.util.*;
@@ -93,7 +93,7 @@ public class EntryList
* Reads the entries from the database. * Reads the entries from the database.
*/ */
public Entry[] readEntries () public Entry[] readEntries ()
throws SQLException throws PersistenceException
{ {
return Chooser.model.getEntries(_catid); return Chooser.model.getEntries(_catid);
} }
@@ -102,7 +102,7 @@ public class EntryList
* Reads the entries from the database. * Reads the entries from the database.
*/ */
public void readSongs () public void readSongs ()
throws SQLException throws PersistenceException
{ {
Chooser.repository.populateSongs(_entry); Chooser.repository.populateSongs(_entry);
} }
@@ -111,7 +111,7 @@ public class EntryList
* Reads the entries from the database and plays them all. * Reads the entries from the database and plays them all.
*/ */
public void readAndPlay () public void readAndPlay ()
throws SQLException throws PersistenceException
{ {
Chooser.repository.populateSongs(_entry); Chooser.repository.populateSongs(_entry);
} }
@@ -120,7 +120,7 @@ public class EntryList
* Updates the category for the displayed entry. * Updates the category for the displayed entry.
*/ */
public void recategorizeEntry () public void recategorizeEntry ()
throws SQLException throws PersistenceException
{ {
Chooser.model.recategorize(_entry, _newcatid); Chooser.model.recategorize(_entry, _newcatid);
} }
@@ -1,15 +1,15 @@
// //
// $Id: PlaylistPanel.java,v 1.6 2001/09/14 17:45:46 mdb Exp $ // $Id: PlaylistPanel.java,v 1.7 2001/09/20 20:42:48 mdb Exp $
package robodj.chooser; package robodj.chooser;
import java.awt.*; import java.awt.*;
import java.awt.event.ActionEvent; import java.awt.event.ActionEvent;
import java.awt.event.ActionListener; import java.awt.event.ActionListener;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import javax.swing.*; import javax.swing.*;
import com.samskivert.jdbc.PersistenceException;
import com.samskivert.swing.*; import com.samskivert.swing.*;
import com.samskivert.swing.util.*; import com.samskivert.swing.util.*;
import com.samskivert.util.StringUtil; import com.samskivert.util.StringUtil;
@@ -129,7 +129,7 @@ public class PlaylistPanel
} }
public void readPlaylist () public void readPlaylist ()
throws SQLException throws PersistenceException
{ {
// clear out any previous playlist // clear out any previous playlist
_plist.clear(); _plist.clear();
@@ -1,5 +1,5 @@
// //
// $Id: DetailTableModel.java,v 1.2 2001/06/05 17:41:00 mdb Exp $ // $Id: DetailTableModel.java,v 1.3 2001/09/20 20:42:48 mdb Exp $
package robodj.importer; package robodj.importer;
@@ -10,8 +10,8 @@ import javax.swing.table.AbstractTableModel;
import javax.swing.text.Document; import javax.swing.text.Document;
import javax.swing.text.BadLocationException; import javax.swing.text.BadLocationException;
import com.samskivert.util.Log;
import com.samskivert.net.cddb.CDDB; import com.samskivert.net.cddb.CDDB;
import robodj.Log;
public class DetailTableModel public class DetailTableModel
extends AbstractTableModel extends AbstractTableModel
@@ -99,8 +99,8 @@ public class DetailTableModel
} }
} catch (BadLocationException ble) { } catch (BadLocationException ble) {
Importer.log.warning("Can't extract text from text field?!"); Log.warning("Can't extract text from text field?!");
Importer.log.logStackTrace(Log.WARNING, ble); Log.logStackTrace(ble);
} }
} }
@@ -1,17 +1,23 @@
// //
// $Id: Importer.java,v 1.6 2001/07/26 00:24:22 mdb Exp $ // $Id: Importer.java,v 1.7 2001/09/20 20:42:48 mdb Exp $
package robodj.importer; package robodj.importer;
import java.awt.Dimension; import java.awt.Dimension;
import java.awt.Toolkit; import java.awt.Toolkit;
import java.sql.SQLException; import java.io.IOException;
import java.util.Properties; import java.util.Properties;
import javax.swing.JOptionPane;
import com.samskivert.jdbc.PersistenceException;
import com.samskivert.jdbc.StaticConnectionProvider;
import com.samskivert.swing.util.SwingUtil; import com.samskivert.swing.util.SwingUtil;
import com.samskivert.util.Log; import com.samskivert.util.ConfigUtil;
import com.samskivert.util.PropertiesUtil; import com.samskivert.util.PropertiesUtil;
import robodj.Log;
import robodj.repository.Repository; import robodj.repository.Repository;
/** /**
@@ -26,31 +32,36 @@ public class Importer
*/ */
public static final String ENTRY_SOURCE = "CD"; public static final String ENTRY_SOURCE = "CD";
public static Log log = new Log("importer");
public static Properties config; public static Properties config;
public static Repository repository; public static Repository repository;
public static void main (String[] args) public static void main (String[] args)
{ {
// set up our configuration by hand for now // load our main configuration
config = new Properties(); String cpath = "rsrc/importer.properties";
config.setProperty("repository.db.driver", "org.gjt.mm.mysql.Driver"); try {
config.setProperty("repository.db.username", "www"); config = ConfigUtil.loadProperties(cpath);
config.setProperty("repository.db.password", "Il0ve2PL@Y"); } catch (IOException ioe) {
config.setProperty("repository.db.url", String err = "Unable to load configuration " +
"jdbc:mysql://depravity:3306/robodj"); "[path=" + cpath + "]: " + ioe;
config.setProperty("repository.basedir", "/export/robodj/repository"); reportError(err);
System.exit(-1);
}
// create an interface to the database repository // create an interface to the database repository
try { try {
Properties dbprops = StaticConnectionProvider scp =
PropertiesUtil.getSubProperties(config, "repository.db"); new StaticConnectionProvider("rsrc/repository.properties");
repository = new Repository(dbprops); repository = new Repository(scp);
} catch (SQLException sqe) {
System.err.println("Unable to establish communication " + } catch (IOException ioe) {
"with music database: " + sqe); reportError("Error loading repository config: " + ioe);
System.exit(-1);
} catch (PersistenceException pe) {
reportError("Unable to establish communication " +
"with music database: " + pe);
System.exit(-1); System.exit(-1);
} }
@@ -64,4 +75,13 @@ public class Importer
SwingUtil.centerWindow(frame); SwingUtil.centerWindow(frame);
frame.setVisible(true); frame.setVisible(true);
} }
protected static void reportError (String error)
{
Object[] options = { "OK" };
JOptionPane.showOptionDialog(null, error, "Error",
JOptionPane.DEFAULT_OPTION,
JOptionPane.ERROR_MESSAGE,
null, options, options[0]);
}
} }
@@ -1,13 +1,13 @@
// //
// $Id: Model.java,v 1.3 2001/09/15 17:31:09 mdb Exp $ // $Id: Model.java,v 1.4 2001/09/20 20:42:48 mdb Exp $
package robodj.repository; package robodj.repository;
import java.sql.SQLException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Comparator; import java.util.Comparator;
import com.samskivert.jdbc.PersistenceException;
import com.samskivert.util.*; import com.samskivert.util.*;
/** /**
@@ -24,7 +24,7 @@ public class Model
* Constructs a new model instance from the supplied repository. * Constructs a new model instance from the supplied repository.
*/ */
public Model (Repository rep) public Model (Repository rep)
throws SQLException throws PersistenceException
{ {
_rep = rep; _rep = rep;
@@ -74,7 +74,7 @@ public class Model
* if database access takes place. * if database access takes place.
*/ */
public Entry getEntry (int entryid) public Entry getEntry (int entryid)
throws SQLException throws PersistenceException
{ {
Entry entry = (Entry)_entries.get(entryid); Entry entry = (Entry)_entries.get(entryid);
if (entry == null) { if (entry == null) {
@@ -91,7 +91,7 @@ public class Model
* category. This call blocks if database access takes place. * category. This call blocks if database access takes place.
*/ */
public Entry[] getEntries (int categoryid) public Entry[] getEntries (int categoryid)
throws SQLException throws PersistenceException
{ {
ArrayList catlist = getCatList(categoryid); ArrayList catlist = getCatList(categoryid);
Entry[] ents = new Entry[catlist.size()]; Entry[] ents = new Entry[catlist.size()];
@@ -105,7 +105,7 @@ public class Model
* artist, names) may have changed. * artist, names) may have changed.
*/ */
public void updateEntry (Entry entry) public void updateEntry (Entry entry)
throws SQLException throws PersistenceException
{ {
_rep.updateEntry(entry); _rep.updateEntry(entry);
} }
@@ -115,7 +115,7 @@ public class Model
* entry can be mapped into multiple categories. * entry can be mapped into multiple categories.
*/ */
public void associateEntry (Entry entry, int categoryid) public void associateEntry (Entry entry, int categoryid)
throws SQLException throws PersistenceException
{ {
// keep our category mapping up to date // keep our category mapping up to date
ArrayList catlist = getCatList(categoryid); ArrayList catlist = getCatList(categoryid);
@@ -133,7 +133,7 @@ public class Model
* Disassociates the specified entry from the specified category. * Disassociates the specified entry from the specified category.
*/ */
public void disassociateEntry (Entry entry, int categoryid) public void disassociateEntry (Entry entry, int categoryid)
throws SQLException throws PersistenceException
{ {
// keep our category mapping up to date // keep our category mapping up to date
ArrayList catlist = getCatList(categoryid); ArrayList catlist = getCatList(categoryid);
@@ -163,7 +163,7 @@ public class Model
* temporary until we fully implement multi-category support. * temporary until we fully implement multi-category support.
*/ */
public void recategorize (Entry entry, int categoryid) public void recategorize (Entry entry, int categoryid)
throws SQLException throws PersistenceException
{ {
// see if we need to change categories // see if we need to change categories
int curcatid = _entmap.get(entry.entryid); int curcatid = _entmap.get(entry.entryid);
@@ -178,13 +178,13 @@ public class Model
* if database access takes place. * if database access takes place.
*/ */
public void populateSongs (Entry entry) public void populateSongs (Entry entry)
throws SQLException throws PersistenceException
{ {
_rep.populateSongs(entry); _rep.populateSongs(entry);
} }
protected ArrayList getCatList (int categoryid) protected ArrayList getCatList (int categoryid)
throws SQLException throws PersistenceException
{ {
ArrayList catlist = (ArrayList)_catmap.get(categoryid); ArrayList catlist = (ArrayList)_catmap.get(categoryid);
@@ -1,5 +1,5 @@
// //
// $Id: Repository.java,v 1.6 2001/09/15 17:31:09 mdb Exp $ // $Id: Repository.java,v 1.7 2001/09/20 20:42:48 mdb Exp $
package robodj.repository; package robodj.repository;
@@ -8,8 +8,7 @@ import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.Properties; import java.util.Properties;
import com.samskivert.jdbc.MySQLRepository; import com.samskivert.jdbc.*;
import com.samskivert.jdbc.JDBCUtil;
import com.samskivert.jdbc.jora.*; import com.samskivert.jdbc.jora.*;
import com.samskivert.util.*; import com.samskivert.util.*;
@@ -22,70 +21,77 @@ import com.samskivert.util.*;
* <p> Entries are stored in the repository according to genre. An entry * <p> Entries are stored in the repository according to genre. An entry
* may be associated with multiple genres. * may be associated with multiple genres.
*/ */
public class Repository extends MySQLRepository public class Repository extends JORARepository
{ {
/** /**
* Creates the repository and opens the music database. A properties * The database identifier that the repository will use when fetching
* object should be supplied with the following fields: * a connection from the connection provider. The value is
* * <code>robodj</code> which you'll probably need to know to properly
* <pre> * configure your connection provider.
* driver=[jdbc driver class]
* url=[jdbc driver url]
* username=[jdbc username]
* password=[jdbc password]
* </pre>
*
* @param props a properties object containing the configuration
* parameters for the repository.
*/ */
public Repository (Properties props) public static final String REPOSITORY_DB_IDENT = "robodj";
throws SQLException
/**
* Creates the repository and opens the music database. A connection
* provider should be supplied that will be used to obtain the
* necessary database connection. The database identifier used to
* obtain our connection is documented by {@link
* #REPOSITORY_DB_IDENT}.
*
* @param provider a connection provider via which the repository will
* get its database connection.
*/
public Repository (ConnectionProvider provider)
throws PersistenceException
{ {
super(props); super(provider, REPOSITORY_DB_IDENT);
} }
protected void createTables () protected void createTables (Session session)
throws SQLException
{ {
// create our table objects // create our table objects
_etable = new Table(Entry.class.getName(), "entries", _session, _etable = new Table(Entry.class.getName(), "entries", session,
"entryid"); "entryid");
_stable = new Table(Song.class.getName(), "songs", _session, _stable = new Table(Song.class.getName(), "songs", session,
"songid"); "songid");
_ctable = new Table(Category.class.getName(), "category_names", _ctable = new Table(Category.class.getName(), "category_names",
_session, "categoryid"); session, "categoryid");
_cmtable = new Table(CategoryMapping.class.getName(), "category_map", _cmtable = new Table(CategoryMapping.class.getName(), "category_map",
_session, new String[] {"categoryid", "entryid"}); session, new String[] {"categoryid", "entryid"});
} }
/** /**
* @return the entry with the specified entry id or null if no entry * @return the entry with the specified entry id or null if no entry
* with that id exists. * with that id exists.
*/ */
public Entry getEntry (int entryid) public Entry getEntry (final int entryid)
throws SQLException throws PersistenceException
{ {
// make sure the connection is open return (Entry)execute(new Operation() {
ensureConnection(); public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{
// look up the entry
Cursor ec = _etable.select("where entryid = " + entryid);
// look up the entry // fetch the entry from the cursor
Cursor ec = _etable.select("where entryid = " + entryid); Entry entry = (Entry)ec.next();
// fetch the entry from the cursor if (entry != null) {
Entry entry = (Entry)ec.next(); // and call next() again to cause the cursor to close
// itself
ec.next();
if (entry != null) { // load up the songs for this entry
// and call next() again to cause the cursor to close itself Cursor sc = _stable.select("where entryid = " + entryid);
ec.next(); List slist = sc.toArrayList();
entry.songs = new Song[slist.size()];
slist.toArray(entry.songs);
}
// load up the songs for this entry return entry;
Cursor sc = _stable.select("where entryid = " + entryid); }
List slist = sc.toArrayList(); });
entry.songs = new Song[slist.size()];
slist.toArray(entry.songs);
}
return entry;
} }
/** /**
@@ -98,10 +104,11 @@ public class Repository extends MySQLRepository
* <code>populateSongs</code> on an entry by entry basis for that. * <code>populateSongs</code> on an entry by entry basis for that.
*/ */
public Entry[] getEntries (final String query) public Entry[] getEntries (final String query)
throws SQLException throws PersistenceException
{ {
return (Entry[])execute(new Operation() { return (Entry[])execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
// look up the entry // look up the entry
Cursor ec = _etable.select(query); Cursor ec = _etable.select(query);
@@ -122,22 +129,25 @@ public class Repository extends MySQLRepository
* function does nothing. * function does nothing.
*/ */
public void populateSongs (final Entry entry) public void populateSongs (final Entry entry)
throws SQLException throws PersistenceException
{ {
if (entry.songs == null) { if (entry.songs != null) {
execute(new Operation() { return;
public Object invoke () throws SQLException
{
// load up the songs for this entry
String query = "where entryid = " + entry.entryid;
Cursor sc = _stable.select(query);
List slist = sc.toArrayList();
entry.songs = new Song[slist.size()];
slist.toArray(entry.songs);
return null;
}
});
} }
execute(new Operation() {
public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{
// load up the songs for this entry
String query = "where entryid = " + entry.entryid;
Cursor sc = _stable.select(query);
List slist = sc.toArrayList();
entry.songs = new Song[slist.size()];
slist.toArray(entry.songs);
return null;
}
});
} }
/** /**
@@ -149,16 +159,17 @@ public class Repository extends MySQLRepository
* newly created entry. * newly created entry.
*/ */
public void insertEntry (final Entry entry) public void insertEntry (final Entry entry)
throws SQLException throws PersistenceException
{ {
execute(new Operation() { execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
// insert the entry into the entry table // insert the entry into the entry table
_etable.insert(entry); _etable.insert(entry);
// update the entryid now that it's known // update the entryid now that it's known
entry.entryid = lastInsertedId(); entry.entryid = liaison.lastInsertedId(conn);
// and insert all of it's songs into the songs table // and insert all of it's songs into the songs table
if (entry.songs != null) { if (entry.songs != null) {
@@ -167,7 +178,7 @@ public class Repository extends MySQLRepository
entry.songs[i].entryid = entry.entryid; entry.songs[i].entryid = entry.entryid;
_stable.insert(entry.songs[i]); _stable.insert(entry.songs[i]);
// find out what songid was assigned // find out what songid was assigned
entry.songs[i].songid = lastInsertedId(); entry.songs[i].songid = liaison.lastInsertedId(conn);
} }
} }
@@ -187,10 +198,11 @@ public class Repository extends MySQLRepository
* @see removeSongFromEntry * @see removeSongFromEntry
*/ */
public void updateEntry (final Entry entry) public void updateEntry (final Entry entry)
throws SQLException throws PersistenceException
{ {
execute(new Operation() { execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
// update the entry // update the entry
_etable.update(entry); _etable.update(entry);
@@ -211,10 +223,11 @@ public class Repository extends MySQLRepository
* Removes the entry (and all associated songs) from the database. * Removes the entry (and all associated songs) from the database.
*/ */
public void deleteEntry (final Entry entry) public void deleteEntry (final Entry entry)
throws SQLException throws PersistenceException
{ {
execute(new Operation() { execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
// remove the entry from the entry table and the foreign // remove the entry from the entry table and the foreign
// key constraints will automatically remove all of the // key constraints will automatically remove all of the
@@ -238,10 +251,11 @@ public class Repository extends MySQLRepository
* @see updateSong * @see updateSong
*/ */
public void addSongToEntry (final Entry entry, final Song song) public void addSongToEntry (final Entry entry, final Song song)
throws SQLException throws PersistenceException
{ {
execute(new Operation() { execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
// fill in the appropriate entry id value // fill in the appropriate entry id value
song.entryid = entry.entryid; song.entryid = entry.entryid;
@@ -249,7 +263,7 @@ public class Repository extends MySQLRepository
// and stick the song into the database // and stick the song into the database
_stable.insert(song); _stable.insert(song);
// communicate the songid back to the caller // communicate the songid back to the caller
song.songid = lastInsertedId(); song.songid = liaison.lastInsertedId(conn);
return null; return null;
} }
@@ -261,10 +275,11 @@ public class Repository extends MySQLRepository
* parameters should already be set to the appropriate values. * parameters should already be set to the appropriate values.
*/ */
public void updateSong (final Song song) public void updateSong (final Song song)
throws SQLException throws PersistenceException
{ {
execute(new Operation() { execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
_stable.update(song); _stable.update(song);
return null; return null;
@@ -277,19 +292,20 @@ public class Repository extends MySQLRepository
* that new category. * that new category.
*/ */
public int createCategory (final String name) public int createCategory (final String name)
throws SQLException throws PersistenceException
{ {
execute(new Operation() { Integer catid = (Integer)execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
Category cat = new Category(); Category cat = new Category();
cat.name = name; cat.name = name;
_ctable.insert(cat); _ctable.insert(cat);
return null; return new Integer(liaison.lastInsertedId(conn));
} }
}); });
return lastInsertedId(); return catid.intValue();
} }
/** /**
@@ -297,10 +313,11 @@ public class Repository extends MySQLRepository
* the category table. * the category table.
*/ */
public Category[] getCategories () public Category[] getCategories ()
throws SQLException throws PersistenceException
{ {
return (Category[])execute(new Operation() { return (Category[])execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
Cursor ccur = _ctable.select(""); Cursor ccur = _ctable.select("");
List clist = ccur.toArrayList(); List clist = ccur.toArrayList();
@@ -317,10 +334,11 @@ public class Repository extends MySQLRepository
* returns all of the entry ids that are not in any category. * returns all of the entry ids that are not in any category.
*/ */
public int[] getEntryIds (final int categoryid) public int[] getEntryIds (final int categoryid)
throws SQLException throws PersistenceException
{ {
return (int[])execute(new Operation() { return (int[])execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
if (categoryid >= 0) { if (categoryid >= 0) {
String query = "where categoryid=" + categoryid; String query = "where categoryid=" + categoryid;
@@ -374,10 +392,11 @@ public class Repository extends MySQLRepository
* entry can be mapped into multiple categories. * entry can be mapped into multiple categories.
*/ */
public void associateEntry (final Entry entry, final int categoryid) public void associateEntry (final Entry entry, final int categoryid)
throws SQLException throws PersistenceException
{ {
execute(new Operation() { execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
CategoryMapping map = CategoryMapping map =
new CategoryMapping(categoryid, entry.entryid); new CategoryMapping(categoryid, entry.entryid);
@@ -391,10 +410,11 @@ public class Repository extends MySQLRepository
* Disassociates the specified entry from the specified category. * Disassociates the specified entry from the specified category.
*/ */
public void disassociateEntry (final Entry entry, final int categoryid) public void disassociateEntry (final Entry entry, final int categoryid)
throws SQLException throws PersistenceException
{ {
execute(new Operation() { execute(new Operation() {
public Object invoke () throws SQLException public Object invoke (Connection conn, DatabaseLiaison liaison)
throws PersistenceException, SQLException
{ {
CategoryMapping map = CategoryMapping map =
new CategoryMapping(categoryid, entry.entryid); new CategoryMapping(categoryid, entry.entryid);
@@ -1,9 +1,10 @@
// //
// $Id: RepositoryTest.java,v 1.1 2000/11/08 06:42:57 mdb Exp $ // $Id: RepositoryTest.java,v 1.2 2001/09/20 20:42:48 mdb Exp $
package robodj.repository; package robodj.repository;
import java.util.Properties; import java.util.Properties;
import com.samskivert.jdbc.StaticConnectionProvider;
public class RepositoryTest public class RepositoryTest
{ {
@@ -11,12 +12,18 @@ public class RepositoryTest
{ {
try { try {
Properties props = new Properties(); Properties props = new Properties();
props.put("driver", "org.gjt.mm.mysql.Driver"); props.put(Repository.REPOSITORY_DB_IDENT + ".driver",
props.put("url", "jdbc:mysql://localhost:3306/robodj"); "org.gjt.mm.mysql.Driver");
props.put("username", "www"); props.put(Repository.REPOSITORY_DB_IDENT + ".url",
props.put("password", "Il0ve2PL@Y"); "jdbc:mysql://localhost:3306/robodj");
props.put(Repository.REPOSITORY_DB_IDENT + ".username",
"www");
props.put(Repository.REPOSITORY_DB_IDENT + ".password",
"Il0ve2PL@Y");
Repository rep = new Repository(props); StaticConnectionProvider scp =
new StaticConnectionProvider(props);
Repository rep = new Repository(scp);
Entry ient = new Entry(); Entry ient = new Entry();
ient.title = "Test entry"; ient.title = "Test entry";
@@ -34,7 +41,7 @@ public class RepositoryTest
Entry ent = rep.getEntry(ient.entryid); Entry ent = rep.getEntry(ient.entryid);
System.out.println("<-- " + ent); System.out.println("<-- " + ent);
rep.shutdown(); scp.shutdown();
} catch (Exception e) { } catch (Exception e) {
e.printStackTrace(System.err); e.printStackTrace(System.err);