net.sourceforge.jdbcimporter
Class Importer

java.lang.Object
  extended bynet.sourceforge.jdbcimporter.Importer

public class Importer
extends java.lang.Object

The Importer class is the main class that controls the import of data to the database.

Version:
0.6
Author:
Chris Nagy

Field Summary
protected  CustomObjectFactory binaryDelimiterParserFactory
          Custom object factory used to create binary delimiter parsers.
static java.lang.String COLUMNTRANSLATOR_PREFIX
          Prefix for the column translator type to class in the custom properties.
protected  CustomObjectFactory columnTranslatorFactory
          Custom object factory used to create column translators.
protected  CustomObjectFactory columnValueGeneratorFactory
          Custom object factory used to create column generators.
static java.lang.String CONNECTION_PREFIX
          Prefix for the connection definition type to class in the custom properties.
protected  CustomObjectFactory connectionDefFactory
          Custom object factory used to create connection definitions.
static java.lang.String DELIMITER_PREFIX
          Prefix for the delimiter parser type to class in the custom properties.
protected  CustomObjectFactory delimiterParserFactory
          Custom object factory used to create delimiter parsers.
protected  java.lang.String engineClassname
          The import engine classname.
protected  boolean failOnError
          Flag indicating that the import should stop on the first error (default is false).
static java.lang.String GENERATOR_PREFIX
          Prefix for the column value generator classes to use.
protected  ImportDef importDef
          The import definition.
protected  boolean importFailed
          Flag indicating that the import failed and the fail on error flag is set to true.
protected  java.util.List importListeners
          The list of import listeners.
protected static org.apache.commons.logging.Log LOG
          The log for debug information.
static java.lang.String ROWTRANSLATOR_PREFIX
          Prefix for the row translator type to class in the custom properties.
protected  CustomObjectFactory rowTranslatorFactory
          Custom object factory used to create row translators.
 
Constructor Summary
Importer()
          Constructs a new importer.
 
Method Summary
 void addImportListener(ImportListener listener)
          Adds an import listener.
 void beginImport()
          Import data into the database by processing each entity definition via the import engine.
protected  void executeSQLFile(java.sql.Connection connection, java.io.File SQLFile)
          Execute a series of sql statements stored in a file.
protected  void fireImportEntityEvent(ImportEntityEvent e, boolean start)
          Fire an import entity event to the listeners.
protected  void fireImportEvent(ImportEvent e, boolean start)
          Fire an import event to the listeners.
 ImportDef getImportDef()
          Returns the ImportDef.
 boolean hasImportFailed()
          Returns the flag indicating that the import failed.
 void initImportDef(org.xml.sax.InputSource input)
          Read and parse the import config file into an ImportDef class.
 void initPlugins(java.util.Properties pluginProperties)
          Initialize the plugin mappings.
 void initPlugins(java.lang.String pluginFile)
          Parse the plugin property file and adds the external connection definition config classes and delimiter parser config classes to the appropriate factories.
static void main(java.lang.String[] args)
           
 void removeImportListener(ImportListener listener)
          Removes an import listener.
 void setEngine(java.lang.String engineClassname)
          Sets the import engine to use.
 void setFailonerror(boolean flag)
          Sets a flag to indicate that the import should stop after the first error.
 void setImportDef(ImportDef importDef)
          Sets the ImportDef.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LOG

protected static org.apache.commons.logging.Log LOG
The log for debug information.


CONNECTION_PREFIX

public static final java.lang.String CONNECTION_PREFIX
Prefix for the connection definition type to class in the custom properties.

See Also:
Constant Field Values

DELIMITER_PREFIX

public static final java.lang.String DELIMITER_PREFIX
Prefix for the delimiter parser type to class in the custom properties.

See Also:
Constant Field Values

COLUMNTRANSLATOR_PREFIX

public static final java.lang.String COLUMNTRANSLATOR_PREFIX
Prefix for the column translator type to class in the custom properties.

See Also:
Constant Field Values

GENERATOR_PREFIX

public static final java.lang.String GENERATOR_PREFIX
Prefix for the column value generator classes to use.

See Also:
Constant Field Values

ROWTRANSLATOR_PREFIX

public static final java.lang.String ROWTRANSLATOR_PREFIX
Prefix for the row translator type to class in the custom properties.

Since:
0.72
See Also:
Constant Field Values

connectionDefFactory

protected CustomObjectFactory connectionDefFactory
Custom object factory used to create connection definitions.


delimiterParserFactory

protected CustomObjectFactory delimiterParserFactory
Custom object factory used to create delimiter parsers.


binaryDelimiterParserFactory

protected CustomObjectFactory binaryDelimiterParserFactory
Custom object factory used to create binary delimiter parsers.

Since:
0.74

columnTranslatorFactory

protected CustomObjectFactory columnTranslatorFactory
Custom object factory used to create column translators.


columnValueGeneratorFactory

protected CustomObjectFactory columnValueGeneratorFactory
Custom object factory used to create column generators.


rowTranslatorFactory

protected CustomObjectFactory rowTranslatorFactory
Custom object factory used to create row translators.

Since:
0.72

importDef

protected ImportDef importDef
The import definition.


engineClassname

protected java.lang.String engineClassname
The import engine classname.


importListeners

protected java.util.List importListeners
The list of import listeners.


failOnError

protected boolean failOnError
Flag indicating that the import should stop on the first error (default is false).


importFailed

protected boolean importFailed
Flag indicating that the import failed and the fail on error flag is set to true.

Constructor Detail

Importer

public Importer()
Constructs a new importer.

Method Detail

setImportDef

public void setImportDef(ImportDef importDef)
Sets the ImportDef.

Parameters:
importDef - import def

setFailonerror

public void setFailonerror(boolean flag)
Sets a flag to indicate that the import should stop after the first error.

Parameters:
flag - flag
Since:
0.69

hasImportFailed

public boolean hasImportFailed()
Returns the flag indicating that the import failed.

Returns:
if true then the import failed
Since:
0.69

initImportDef

public void initImportDef(org.xml.sax.InputSource input)
                   throws java.io.IOException,
                          javax.xml.parsers.ParserConfigurationException,
                          org.xml.sax.SAXException,
                          org.w3c.dom.DOMException,
                          InvalidCustomObjectDefException
Read and parse the import config file into an ImportDef class.

Parameters:
input - import config as xml
Throws:
java.io.IOException - if the import config cannot be read
javax.xml.parsers.ParserConfigurationException
org.xml.sax.SAXException
org.w3c.dom.DOMException
InvalidCustomObjectDefException

getImportDef

public ImportDef getImportDef()
Returns the ImportDef.

Returns:
ImportDef

initPlugins

public void initPlugins(java.lang.String pluginFile)
                 throws java.io.FileNotFoundException,
                        java.io.IOException
Parse the plugin property file and adds the external connection definition config classes and delimiter parser config classes to the appropriate factories.

Parameters:
pluginFile - plugin property file
Throws:
java.io.FileNotFoundException - if the plugin file cannot be found
java.io.IOException - if the plugin file cannot be opened and read

initPlugins

public void initPlugins(java.util.Properties pluginProperties)
Initialize the plugin mappings.

Parameters:
pluginProperties - the defined plugin mappings

setEngine

public void setEngine(java.lang.String engineClassname)
Sets the import engine to use.

Parameters:
engineClassname - the classname of the import engine

beginImport

public void beginImport()
                 throws java.io.FileNotFoundException,
                        java.io.IOException
Import data into the database by processing each entity definition via the import engine.

Throws:
java.io.FileNotFoundException - if the log file or bad log file is not valid
java.io.IOException - if the log file or bad log file cannot be opened and written to

addImportListener

public void addImportListener(ImportListener listener)
Adds an import listener.

Parameters:
listener - an import listener

removeImportListener

public void removeImportListener(ImportListener listener)
Removes an import listener.

Parameters:
listener - an import listener

fireImportEvent

protected void fireImportEvent(ImportEvent e,
                               boolean start)
Fire an import event to the listeners.

Parameters:
e - the import event
start - true if the import is starting and false if the import is finished

fireImportEntityEvent

protected void fireImportEntityEvent(ImportEntityEvent e,
                                     boolean start)
Fire an import entity event to the listeners.

Parameters:
e - the import entity event
start - true if the import of the entity is starting and false if the import of the entity is finished

executeSQLFile

protected void executeSQLFile(java.sql.Connection connection,
                              java.io.File SQLFile)
Execute a series of sql statements stored in a file.

Parameters:
connection - The JDBC Connection
SQLFile - The file containing sql statements

main

public static void main(java.lang.String[] args)