Mp3dings 
20100427

net.sourceforge.mp3dings.export
Class DatabaseExporter

java.lang.Object
  extended by net.sourceforge.mp3dings.export.DatabaseConnection
      extended by net.sourceforge.mp3dings.export.DatabaseExporter
All Implemented Interfaces:
Exporter

public class DatabaseExporter
extends DatabaseConnection
implements Exporter

Exports data to a JDBC database.

Version:
$Revision: 143 $ ($Date: 2008-05-14 09:18:25 +0200 (Mi, 14 Mai 2008) $)
Author:
Moritz Ringler

Field Summary
 
Fields inherited from class net.sourceforge.mp3dings.export.DatabaseConnection
P_CLASSPATH, P_DRIVER, P_FIELD_PREFIX, P_PASSWORD, P_TABLE, P_URL, P_USER, PREF_EXPORT, PREF_IMPORT
 
Constructor Summary
DatabaseExporter(Properties config, ClassLoaderProvider clp)
          Establishes a new database connection that can export data from mp3dings to the database.
 
Method Summary
static Properties editConfig(Component parent, Properties config, Field[] availableFields, ClassLoaderProvider clp)
          Displays a wizard to interactively create or modify a JDBC configuration that can be used to establish a database export connection.
 int export(Object[] keys, Object[][] data)
          Inserts the data passed as the second argument into the database table to which we are connected.
 boolean getFileFallback()
          Returns false.
 Object[] getKeys()
          Gets the keys to use when passing data to this exporter.
 String getName()
          Returns a localized name for this exporter.
static Properties loadConfig()
          Tries to load a previously saved database export configuration.
 boolean setEncoding(String enc)
          Does nothing.
 
Methods inherited from class net.sourceforge.mp3dings.export.DatabaseConnection
close, editConfig, getConnection, isAlive, loadConfig
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DatabaseExporter

public DatabaseExporter(Properties config,
                        ClassLoaderProvider clp)
                 throws ExportException,
                        SQLException
Establishes a new database connection that can export data from mp3dings to the database. A suitable configuration can be created interactively with the editConfig method.

Parameters:
config - the jdbc configuration
clp - a classloader provider that manages the dynamic class path for loading the JDBC driver, may be null
Throws:
ExportException - if a required property is missing in config, or if the JDBC driver cannot be loaded
SQLException - if an SQL/JDBC error occurs
Method Detail

editConfig

public static Properties editConfig(Component parent,
                                    Properties config,
                                    Field[] availableFields,
                                    ClassLoaderProvider clp)
                             throws SQLException
Displays a wizard to interactively create or modify a JDBC configuration that can be used to establish a database export connection.

Parameters:
parent - the GUI component to use as a dialog owner
config - the previous configuration if any, may be null
availableFields - the fields that are available in the mp3dings table that will exchange data with the database
clp - a classloader provider that manages the dynamic class path for loading the JDBC driver, may be null
Throws:
SQLException
See Also:
Mp3dingsTableModel.getFields()

loadConfig

public static Properties loadConfig()
                             throws IOException
Tries to load a previously saved database export configuration.

Returns:
a previously stored database export configuration or null if no such configuration exists
Throws:
IOException - if the JDBC configuration cannot be read from the properties file whose location was stored in the preferences

export

public int export(Object[] keys,
                  Object[][] data)
           throws ExportException
Inserts the data passed as the second argument into the database table to which we are connected.

Specified by:
export in interface Exporter
Parameters:
data - data[i][j] is the value for keys[j] in the ith record
Returns:
the number of records that were successfully exported
Throws:
ExportException
See Also:
getKeys()

getKeys

public Object[] getKeys()
Gets the keys to use when passing data to this exporter.

Specified by:
getKeys in interface Exporter
Returns:
an array of Field objects

getFileFallback

public boolean getFileFallback()
Returns false.

Specified by:
getFileFallback in interface Exporter
Returns:
whether to read id3 tags as a fallback

setEncoding

public boolean setEncoding(String enc)
Does nothing.

Specified by:
setEncoding in interface Exporter
Parameters:
enc - ignored

getName

public String getName()
Returns a localized name for this exporter.

Specified by:
getName in interface Exporter
Returns:
the name of an implementation's target type

Mp3dings 
20100427