Mp3dings 
20100427

net.sourceforge.mp3dings.export
Class DatabaseImporter

java.lang.Object
  extended by net.sourceforge.mp3dings.export.DatabaseConnection
      extended by net.sourceforge.mp3dings.export.DatabaseImporter

public class DatabaseImporter
extends DatabaseConnection

Imports data from a JDBC database.

Version:
$Revision: 43 $ ($Date: 2007-10-20 19:39:59 +0200 (Sa, 20 Okt 2007) $)
Author:
Moritz Ringler

Field Summary
static String P_WHERE
          The name of the property holding the where clause for the SQL SELECT statement.
 
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
DatabaseImporter(Properties config, ClassLoaderProvider clp, Field[] dataStructure)
          Establishes a new database connection that can import data from a database table to mp3dings.
 
Method Summary
static Properties editConfig(Frame 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 import connection.
static Properties editWhere(Frame parent, Properties config)
          Displays a wizard to create or modify an SQL WHERE clause that can be used to restrict a query to the database.
 boolean hasResult()
          Returns wether the last query returned another result not yet retrieved with nextResult(java.lang.Object[]).
static Properties loadConfig()
          Tries to load a previously saved database import configuration.
 Object[] nextResult(Object[] result)
          Copies the next result of the last query to the provided array and returns it.
 boolean query(Object[] input)
          Looks for database entries matching the input.
 
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
 

Field Detail

P_WHERE

public static String P_WHERE
The name of the property holding the where clause for the SQL SELECT statement.

Constructor Detail

DatabaseImporter

public DatabaseImporter(Properties config,
                        ClassLoaderProvider clp,
                        Field[] dataStructure)
                 throws SQLException,
                        ExportException
Establishes a new database connection that can import data from a database table to mp3dings. A suitable configuration can be created interactively with the editConfig method.

Parameters:
config - the database import configuration
clp - a classloader provider that manages the dynamic class path for loading the JDBC driver, may be null
dataStructure - the fields that are available in the mp3dings table that will exchange data with the database
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
See Also:
Mp3dingsTableModel.getFields()
Method Detail

query

public boolean query(Object[] input)
              throws SQLException
Looks for database entries matching the input. An SQL SELECT statement is sent to the database whose WHERE-clause is formed from config.getProperty(P_WHERE) by replacing expressions like mp3dings('ARTIST') with the corresponding input values. The default conversion between java and database types is used.

The results of the database query can be retrieved iteratively with nextResult(java.lang.Object[]).

Parameters:
input - values for the fields specified with the dataStructure argument of the constructor. These values will be used to substitute expressions like mp3dings('ARTIST') in the search condition.
Returns:
whether a match was found in the database.
Throws:
SQLException

hasResult

public boolean hasResult()
Returns wether the last query returned another result not yet retrieved with nextResult(java.lang.Object[]).


nextResult

public Object[] nextResult(Object[] result)
                    throws SQLException
Copies the next result of the last query to the provided array and returns it. The default conversion between java and database types is used.

Each result can be retrieved only once. If all results of the last query have already been retrieved the argument array will be returned unchanged.

Parameters:
result - an array to hold the query result. If null or an array of the wrong length is passed a new array will be allocated if necessary.
Returns:
the next result of the last query
Throws:
SQLException

editConfig

public static Properties editConfig(Frame 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 import connection.

Parameters:
parent - the frame 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 import configuration.

Returns:
a previously stored database import 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

editWhere

public static Properties editWhere(Frame parent,
                                   Properties config)
Displays a wizard to create or modify an SQL WHERE clause that can be used to restrict a query to the database.

Parameters:
parent - the frame to use as a dialog owner
config - a database configuration to modify or complement. Such a configuration should be the result of a previous call to editConfig or loadConfig.
See Also:
query(java.lang.Object[])

Mp3dings 
20100427