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:
@@ -32,6 +32,9 @@
|
||||
<fileset dir="${src.dir}" includes="**/*.gif"/>
|
||||
<fileset dir="${src.dir}" includes="**/*.jpg"/>
|
||||
</copy>
|
||||
<copy todir="${deploy.dir}/classes/conf">
|
||||
<fileset dir="conf"/>
|
||||
</copy>
|
||||
</target>
|
||||
|
||||
<!-- cleans out the installed application -->
|
||||
@@ -67,7 +70,7 @@
|
||||
|
||||
<!-- builds our distribution files (war and jar) -->
|
||||
<target name="dist" depends="prepare,compile">
|
||||
<jar jarfile="${deploy.dir}/${dist.jar}"
|
||||
<jar file="${deploy.dir}/${dist.jar}"
|
||||
basedir="${deploy.dir}/classes"/>
|
||||
</target>
|
||||
|
||||
|
||||
@@ -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
|
||||
@@ -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;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.io.IOException;
|
||||
import java.sql.SQLException;
|
||||
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.util.ConfigUtil;
|
||||
import com.samskivert.util.PropertiesUtil;
|
||||
|
||||
import robodj.Log;
|
||||
@@ -33,25 +38,31 @@ public class Chooser
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
// set up our configuration by hand for now
|
||||
config = new Properties();
|
||||
config.setProperty("repository.db.driver", "org.gjt.mm.mysql.Driver");
|
||||
config.setProperty("repository.db.username", "www");
|
||||
config.setProperty("repository.db.password", "Il0ve2PL@Y");
|
||||
config.setProperty("repository.db.url",
|
||||
"jdbc:mysql://depravity:3306/robodj");
|
||||
config.setProperty("repository.basedir", "/export/robodj/repository");
|
||||
// load our main configuration
|
||||
String cpath = "conf/chooser.properties";
|
||||
try {
|
||||
config = ConfigUtil.loadProperties(cpath);
|
||||
} catch (IOException ioe) {
|
||||
String err = "Unable to load configuration " +
|
||||
"[path=" + cpath + "]: " + ioe;
|
||||
reportError(err);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
// create an interface to the database repository
|
||||
try {
|
||||
Properties dbprops =
|
||||
PropertiesUtil.getSubProperties(config, "repository.db");
|
||||
repository = new Repository(dbprops);
|
||||
StaticConnectionProvider scp =
|
||||
new StaticConnectionProvider("conf/repository.properties");
|
||||
repository = new Repository(scp);
|
||||
model = new Model(repository);
|
||||
|
||||
} catch (SQLException sqe) {
|
||||
Log.warning("Unable to establish communication with music " +
|
||||
"database: " + sqe);
|
||||
} catch (IOException ioe) {
|
||||
reportError("Error loading repository config: " + ioe);
|
||||
System.exit(-1);
|
||||
|
||||
} catch (PersistenceException pe) {
|
||||
reportError("Unable to establish communication " +
|
||||
"with music database: " + pe);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
@@ -81,4 +92,13 @@ public class Chooser
|
||||
SwingUtil.centerWindow(frame);
|
||||
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;
|
||||
|
||||
@@ -8,8 +8,7 @@ import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import javax.swing.*;
|
||||
|
||||
import java.sql.SQLException;
|
||||
|
||||
import com.samskivert.jdbc.PersistenceException;
|
||||
import com.samskivert.swing.*;
|
||||
import com.samskivert.swing.util.*;
|
||||
|
||||
@@ -78,7 +77,7 @@ public class EditDialog
|
||||
* Updates the entry in the repository.
|
||||
*/
|
||||
public void updateEntry ()
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
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;
|
||||
|
||||
import java.awt.Font;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.sql.SQLException;
|
||||
import java.util.*;
|
||||
import javax.swing.*;
|
||||
import javax.swing.event.*;
|
||||
|
||||
import com.samskivert.jdbc.PersistenceException;
|
||||
import com.samskivert.swing.*;
|
||||
import com.samskivert.swing.util.*;
|
||||
|
||||
@@ -93,7 +93,7 @@ public class EntryList
|
||||
* Reads the entries from the database.
|
||||
*/
|
||||
public Entry[] readEntries ()
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
return Chooser.model.getEntries(_catid);
|
||||
}
|
||||
@@ -102,7 +102,7 @@ public class EntryList
|
||||
* Reads the entries from the database.
|
||||
*/
|
||||
public void readSongs ()
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
Chooser.repository.populateSongs(_entry);
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class EntryList
|
||||
* Reads the entries from the database and plays them all.
|
||||
*/
|
||||
public void readAndPlay ()
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
Chooser.repository.populateSongs(_entry);
|
||||
}
|
||||
@@ -120,7 +120,7 @@ public class EntryList
|
||||
* Updates the category for the displayed entry.
|
||||
*/
|
||||
public void recategorizeEntry ()
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
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;
|
||||
|
||||
import java.awt.*;
|
||||
import java.awt.event.ActionEvent;
|
||||
import java.awt.event.ActionListener;
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import javax.swing.*;
|
||||
|
||||
import com.samskivert.jdbc.PersistenceException;
|
||||
import com.samskivert.swing.*;
|
||||
import com.samskivert.swing.util.*;
|
||||
import com.samskivert.util.StringUtil;
|
||||
@@ -129,7 +129,7 @@ public class PlaylistPanel
|
||||
}
|
||||
|
||||
public void readPlaylist ()
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
// clear out any previous playlist
|
||||
_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;
|
||||
|
||||
@@ -10,8 +10,8 @@ import javax.swing.table.AbstractTableModel;
|
||||
import javax.swing.text.Document;
|
||||
import javax.swing.text.BadLocationException;
|
||||
|
||||
import com.samskivert.util.Log;
|
||||
import com.samskivert.net.cddb.CDDB;
|
||||
import robodj.Log;
|
||||
|
||||
public class DetailTableModel
|
||||
extends AbstractTableModel
|
||||
@@ -99,8 +99,8 @@ public class DetailTableModel
|
||||
}
|
||||
|
||||
} catch (BadLocationException ble) {
|
||||
Importer.log.warning("Can't extract text from text field?!");
|
||||
Importer.log.logStackTrace(Log.WARNING, ble);
|
||||
Log.warning("Can't extract text from text field?!");
|
||||
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;
|
||||
|
||||
import java.awt.Dimension;
|
||||
import java.awt.Toolkit;
|
||||
import java.sql.SQLException;
|
||||
import java.io.IOException;
|
||||
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.util.Log;
|
||||
import com.samskivert.util.ConfigUtil;
|
||||
import com.samskivert.util.PropertiesUtil;
|
||||
|
||||
import robodj.Log;
|
||||
import robodj.repository.Repository;
|
||||
|
||||
/**
|
||||
@@ -26,31 +32,36 @@ public class Importer
|
||||
*/
|
||||
public static final String ENTRY_SOURCE = "CD";
|
||||
|
||||
public static Log log = new Log("importer");
|
||||
|
||||
public static Properties config;
|
||||
|
||||
public static Repository repository;
|
||||
|
||||
public static void main (String[] args)
|
||||
{
|
||||
// set up our configuration by hand for now
|
||||
config = new Properties();
|
||||
config.setProperty("repository.db.driver", "org.gjt.mm.mysql.Driver");
|
||||
config.setProperty("repository.db.username", "www");
|
||||
config.setProperty("repository.db.password", "Il0ve2PL@Y");
|
||||
config.setProperty("repository.db.url",
|
||||
"jdbc:mysql://depravity:3306/robodj");
|
||||
config.setProperty("repository.basedir", "/export/robodj/repository");
|
||||
// load our main configuration
|
||||
String cpath = "rsrc/importer.properties";
|
||||
try {
|
||||
config = ConfigUtil.loadProperties(cpath);
|
||||
} catch (IOException ioe) {
|
||||
String err = "Unable to load configuration " +
|
||||
"[path=" + cpath + "]: " + ioe;
|
||||
reportError(err);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
// create an interface to the database repository
|
||||
try {
|
||||
Properties dbprops =
|
||||
PropertiesUtil.getSubProperties(config, "repository.db");
|
||||
repository = new Repository(dbprops);
|
||||
} catch (SQLException sqe) {
|
||||
System.err.println("Unable to establish communication " +
|
||||
"with music database: " + sqe);
|
||||
StaticConnectionProvider scp =
|
||||
new StaticConnectionProvider("rsrc/repository.properties");
|
||||
repository = new Repository(scp);
|
||||
|
||||
} catch (IOException ioe) {
|
||||
reportError("Error loading repository config: " + ioe);
|
||||
System.exit(-1);
|
||||
|
||||
} catch (PersistenceException pe) {
|
||||
reportError("Unable to establish communication " +
|
||||
"with music database: " + pe);
|
||||
System.exit(-1);
|
||||
}
|
||||
|
||||
@@ -64,4 +75,13 @@ public class Importer
|
||||
SwingUtil.centerWindow(frame);
|
||||
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;
|
||||
|
||||
import java.sql.SQLException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Comparator;
|
||||
|
||||
import com.samskivert.jdbc.PersistenceException;
|
||||
import com.samskivert.util.*;
|
||||
|
||||
/**
|
||||
@@ -24,7 +24,7 @@ public class Model
|
||||
* Constructs a new model instance from the supplied repository.
|
||||
*/
|
||||
public Model (Repository rep)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
_rep = rep;
|
||||
|
||||
@@ -74,7 +74,7 @@ public class Model
|
||||
* if database access takes place.
|
||||
*/
|
||||
public Entry getEntry (int entryid)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
Entry entry = (Entry)_entries.get(entryid);
|
||||
if (entry == null) {
|
||||
@@ -91,7 +91,7 @@ public class Model
|
||||
* category. This call blocks if database access takes place.
|
||||
*/
|
||||
public Entry[] getEntries (int categoryid)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
ArrayList catlist = getCatList(categoryid);
|
||||
Entry[] ents = new Entry[catlist.size()];
|
||||
@@ -105,7 +105,7 @@ public class Model
|
||||
* artist, names) may have changed.
|
||||
*/
|
||||
public void updateEntry (Entry entry)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
_rep.updateEntry(entry);
|
||||
}
|
||||
@@ -115,7 +115,7 @@ public class Model
|
||||
* entry can be mapped into multiple categories.
|
||||
*/
|
||||
public void associateEntry (Entry entry, int categoryid)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
// keep our category mapping up to date
|
||||
ArrayList catlist = getCatList(categoryid);
|
||||
@@ -133,7 +133,7 @@ public class Model
|
||||
* Disassociates the specified entry from the specified category.
|
||||
*/
|
||||
public void disassociateEntry (Entry entry, int categoryid)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
// keep our category mapping up to date
|
||||
ArrayList catlist = getCatList(categoryid);
|
||||
@@ -163,7 +163,7 @@ public class Model
|
||||
* temporary until we fully implement multi-category support.
|
||||
*/
|
||||
public void recategorize (Entry entry, int categoryid)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
// see if we need to change categories
|
||||
int curcatid = _entmap.get(entry.entryid);
|
||||
@@ -178,13 +178,13 @@ public class Model
|
||||
* if database access takes place.
|
||||
*/
|
||||
public void populateSongs (Entry entry)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
_rep.populateSongs(entry);
|
||||
}
|
||||
|
||||
protected ArrayList getCatList (int categoryid)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
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;
|
||||
|
||||
@@ -8,8 +8,7 @@ import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
|
||||
import com.samskivert.jdbc.MySQLRepository;
|
||||
import com.samskivert.jdbc.JDBCUtil;
|
||||
import com.samskivert.jdbc.*;
|
||||
import com.samskivert.jdbc.jora.*;
|
||||
import com.samskivert.util.*;
|
||||
|
||||
@@ -22,70 +21,77 @@ import com.samskivert.util.*;
|
||||
* <p> Entries are stored in the repository according to genre. An entry
|
||||
* 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
|
||||
* object should be supplied with the following fields:
|
||||
*
|
||||
* <pre>
|
||||
* 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.
|
||||
* The database identifier that the repository will use when fetching
|
||||
* a connection from the connection provider. The value is
|
||||
* <code>robodj</code> which you'll probably need to know to properly
|
||||
* configure your connection provider.
|
||||
*/
|
||||
public Repository (Properties props)
|
||||
throws SQLException
|
||||
public static final String REPOSITORY_DB_IDENT = "robodj";
|
||||
|
||||
/**
|
||||
* 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 ()
|
||||
throws SQLException
|
||||
protected void createTables (Session session)
|
||||
{
|
||||
// create our table objects
|
||||
_etable = new Table(Entry.class.getName(), "entries", _session,
|
||||
_etable = new Table(Entry.class.getName(), "entries", session,
|
||||
"entryid");
|
||||
_stable = new Table(Song.class.getName(), "songs", _session,
|
||||
_stable = new Table(Song.class.getName(), "songs", session,
|
||||
"songid");
|
||||
_ctable = new Table(Category.class.getName(), "category_names",
|
||||
_session, "categoryid");
|
||||
session, "categoryid");
|
||||
_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
|
||||
* with that id exists.
|
||||
*/
|
||||
public Entry getEntry (int entryid)
|
||||
throws SQLException
|
||||
public Entry getEntry (final int entryid)
|
||||
throws PersistenceException
|
||||
{
|
||||
// make sure the connection is open
|
||||
ensureConnection();
|
||||
return (Entry)execute(new Operation() {
|
||||
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
|
||||
Cursor ec = _etable.select("where entryid = " + entryid);
|
||||
// fetch the entry from the cursor
|
||||
Entry entry = (Entry)ec.next();
|
||||
|
||||
// fetch the entry from the cursor
|
||||
Entry entry = (Entry)ec.next();
|
||||
if (entry != null) {
|
||||
// and call next() again to cause the cursor to close
|
||||
// itself
|
||||
ec.next();
|
||||
|
||||
if (entry != null) {
|
||||
// and call next() again to cause the cursor to close itself
|
||||
ec.next();
|
||||
// load up the songs for this entry
|
||||
Cursor sc = _stable.select("where entryid = " + entryid);
|
||||
List slist = sc.toArrayList();
|
||||
entry.songs = new Song[slist.size()];
|
||||
slist.toArray(entry.songs);
|
||||
}
|
||||
|
||||
// load up the songs for this entry
|
||||
Cursor sc = _stable.select("where entryid = " + entryid);
|
||||
List slist = sc.toArrayList();
|
||||
entry.songs = new Song[slist.size()];
|
||||
slist.toArray(entry.songs);
|
||||
}
|
||||
|
||||
return entry;
|
||||
return entry;
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -98,10 +104,11 @@ public class Repository extends MySQLRepository
|
||||
* <code>populateSongs</code> on an entry by entry basis for that.
|
||||
*/
|
||||
public Entry[] getEntries (final String query)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
return (Entry[])execute(new Operation() {
|
||||
public Object invoke () throws SQLException
|
||||
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws PersistenceException, SQLException
|
||||
{
|
||||
// look up the entry
|
||||
Cursor ec = _etable.select(query);
|
||||
@@ -122,22 +129,25 @@ public class Repository extends MySQLRepository
|
||||
* function does nothing.
|
||||
*/
|
||||
public void populateSongs (final Entry entry)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
if (entry.songs == null) {
|
||||
execute(new Operation() {
|
||||
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;
|
||||
}
|
||||
});
|
||||
if (entry.songs != null) {
|
||||
return;
|
||||
}
|
||||
|
||||
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.
|
||||
*/
|
||||
public void insertEntry (final Entry entry)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
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
|
||||
_etable.insert(entry);
|
||||
|
||||
// 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
|
||||
if (entry.songs != null) {
|
||||
@@ -167,7 +178,7 @@ public class Repository extends MySQLRepository
|
||||
entry.songs[i].entryid = entry.entryid;
|
||||
_stable.insert(entry.songs[i]);
|
||||
// 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
|
||||
*/
|
||||
public void updateEntry (final Entry entry)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
execute(new Operation() {
|
||||
public Object invoke () throws SQLException
|
||||
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws PersistenceException, SQLException
|
||||
{
|
||||
// update the entry
|
||||
_etable.update(entry);
|
||||
@@ -211,10 +223,11 @@ public class Repository extends MySQLRepository
|
||||
* Removes the entry (and all associated songs) from the database.
|
||||
*/
|
||||
public void deleteEntry (final Entry entry)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
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
|
||||
// key constraints will automatically remove all of the
|
||||
@@ -238,10 +251,11 @@ public class Repository extends MySQLRepository
|
||||
* @see updateSong
|
||||
*/
|
||||
public void addSongToEntry (final Entry entry, final Song song)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
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
|
||||
song.entryid = entry.entryid;
|
||||
@@ -249,7 +263,7 @@ public class Repository extends MySQLRepository
|
||||
// and stick the song into the database
|
||||
_stable.insert(song);
|
||||
// communicate the songid back to the caller
|
||||
song.songid = lastInsertedId();
|
||||
song.songid = liaison.lastInsertedId(conn);
|
||||
|
||||
return null;
|
||||
}
|
||||
@@ -261,10 +275,11 @@ public class Repository extends MySQLRepository
|
||||
* parameters should already be set to the appropriate values.
|
||||
*/
|
||||
public void updateSong (final Song song)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
execute(new Operation() {
|
||||
public Object invoke () throws SQLException
|
||||
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws PersistenceException, SQLException
|
||||
{
|
||||
_stable.update(song);
|
||||
return null;
|
||||
@@ -277,19 +292,20 @@ public class Repository extends MySQLRepository
|
||||
* that new category.
|
||||
*/
|
||||
public int createCategory (final String name)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
execute(new Operation() {
|
||||
public Object invoke () throws SQLException
|
||||
Integer catid = (Integer)execute(new Operation() {
|
||||
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws PersistenceException, SQLException
|
||||
{
|
||||
Category cat = new Category();
|
||||
cat.name = name;
|
||||
_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.
|
||||
*/
|
||||
public Category[] getCategories ()
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
return (Category[])execute(new Operation() {
|
||||
public Object invoke () throws SQLException
|
||||
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws PersistenceException, SQLException
|
||||
{
|
||||
Cursor ccur = _ctable.select("");
|
||||
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.
|
||||
*/
|
||||
public int[] getEntryIds (final int categoryid)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
return (int[])execute(new Operation() {
|
||||
public Object invoke () throws SQLException
|
||||
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws PersistenceException, SQLException
|
||||
{
|
||||
if (categoryid >= 0) {
|
||||
String query = "where categoryid=" + categoryid;
|
||||
@@ -374,10 +392,11 @@ public class Repository extends MySQLRepository
|
||||
* entry can be mapped into multiple categories.
|
||||
*/
|
||||
public void associateEntry (final Entry entry, final int categoryid)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
execute(new Operation() {
|
||||
public Object invoke () throws SQLException
|
||||
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws PersistenceException, SQLException
|
||||
{
|
||||
CategoryMapping map =
|
||||
new CategoryMapping(categoryid, entry.entryid);
|
||||
@@ -391,10 +410,11 @@ public class Repository extends MySQLRepository
|
||||
* Disassociates the specified entry from the specified category.
|
||||
*/
|
||||
public void disassociateEntry (final Entry entry, final int categoryid)
|
||||
throws SQLException
|
||||
throws PersistenceException
|
||||
{
|
||||
execute(new Operation() {
|
||||
public Object invoke () throws SQLException
|
||||
public Object invoke (Connection conn, DatabaseLiaison liaison)
|
||||
throws PersistenceException, SQLException
|
||||
{
|
||||
CategoryMapping map =
|
||||
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;
|
||||
|
||||
import java.util.Properties;
|
||||
import com.samskivert.jdbc.StaticConnectionProvider;
|
||||
|
||||
public class RepositoryTest
|
||||
{
|
||||
@@ -11,12 +12,18 @@ public class RepositoryTest
|
||||
{
|
||||
try {
|
||||
Properties props = new Properties();
|
||||
props.put("driver", "org.gjt.mm.mysql.Driver");
|
||||
props.put("url", "jdbc:mysql://localhost:3306/robodj");
|
||||
props.put("username", "www");
|
||||
props.put("password", "Il0ve2PL@Y");
|
||||
props.put(Repository.REPOSITORY_DB_IDENT + ".driver",
|
||||
"org.gjt.mm.mysql.Driver");
|
||||
props.put(Repository.REPOSITORY_DB_IDENT + ".url",
|
||||
"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();
|
||||
ient.title = "Test entry";
|
||||
@@ -34,7 +41,7 @@ public class RepositoryTest
|
||||
Entry ent = rep.getEntry(ient.entryid);
|
||||
System.out.println("<-- " + ent);
|
||||
|
||||
rep.shutdown();
|
||||
scp.shutdown();
|
||||
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace(System.err);
|
||||
|
||||
Reference in New Issue
Block a user