com.agimatec.utility.fileimport
Class ImportController

java.lang.Object
  extended by com.agimatec.utility.fileimport.ImportController

public class ImportController
extends Object

Description: Responsible to simplify the management of multiple imports that should not run parallel. Relies on database table 'IMPORT_CONTROL', accessed via JDBC.
User: roman.stumm
Date: 30.08.2007
Time: 13:02:51
Copyright: Agimatec GmbH


Field Summary
protected  Connection connection
           
protected  String deleteById
           
protected  String deleteByName
           
protected  String insert
           
protected  String lockByName
           
protected static org.apache.log4j.Logger log
           
protected  String selectAll
           
protected  String selectById
           
protected  String selectByName
           
protected  SqlUtil sqlUtil
           
protected  String update
           
 
Constructor Summary
ImportController(Connection connection, SqlUtil util)
           
ImportController(Connection connection, SqlUtil util, String sequenceName)
           
 
Method Summary
 boolean delete(long importId)
          delete the import with the given importid (primary key)
 boolean delete(String importName)
          delete the imports with the given name from the control table
 void end(ImportControl imp)
          markiert den import mit dem angeg.
 void end(ImportControl imp, Importer importer)
           
 void end(long importId, Importer importer)
          convenience method that takes infos from the importer.
 List<ImportControl> findAll()
           
 ImportControl findById(long importId)
           
 List<ImportControl> findByName(String importName)
           
 SqlUtil getSqlUtil()
           
 long join(ImportControl imp)
           
 ImportControl join(String importName)
          create import in database for the type and call start() after a lock() has been aquired.
 boolean lock(String importName)
          aquire a lock for imports of the given name.
 long start(ImportControl imp)
          insert the importcontrol row into the database.
 void update(ImportControl imp)
          calls start() if not already done so!
 void update(ImportControl imp, Importer importer)
          update rowCount, errorCount during running import.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

log

protected static final org.apache.log4j.Logger log

connection

protected Connection connection

sqlUtil

protected SqlUtil sqlUtil

selectAll

protected String selectAll

selectByName

protected String selectByName

selectById

protected String selectById

insert

protected String insert

lockByName

protected String lockByName

update

protected String update

deleteByName

protected String deleteByName

deleteById

protected String deleteById
Constructor Detail

ImportController

public ImportController(Connection connection,
                        SqlUtil util)
Parameters:
util - - a sequence under symbolic name "import_id" must be defined!!

ImportController

public ImportController(Connection connection,
                        SqlUtil util,
                        String sequenceName)
Parameters:
sequenceName - - name of sequence, to generate primary keys
Method Detail

findAll

public List<ImportControl> findAll()
                            throws SQLException
Throws:
SQLException

findByName

public List<ImportControl> findByName(String importName)
                               throws SQLException
Throws:
SQLException

findById

public ImportControl findById(long importId)
                       throws SQLException
Throws:
SQLException

delete

public boolean delete(String importName)
               throws SQLException
delete the imports with the given name from the control table

Returns:
true wenn etwas geloescht wurde, sonst false
Throws:
SQLException

delete

public boolean delete(long importId)
               throws SQLException
delete the import with the given importid (primary key)

Returns:
true when something has been deleted, false otherwise (not found)
Throws:
SQLException

lock

public boolean lock(String importName)
             throws SQLException
aquire a lock for imports of the given name. block until lock aquired by database.

Parameters:
importName -
Returns:
Throws:
SQLException

join

public ImportControl join(String importName)
                   throws SQLException
create import in database for the type and call start() after a lock() has been aquired. update the import_control table for this kind of import to wait until running imports have finished. (wait with database lock. this requires that imports use a single transaction for accessing the import_control table. in case of importing large datasets, this might be a problem. maybe it is neccessary to extend this class with strategies for long-transactions-support, or you need to use two connections: one for accessing import_control the other to import the data with intermediate commits.

Remember: changes written with insert() or update() are only visible after the running transaction has been committed. So you have to decide a) use autocommit / own short transactions to monitor running imports or b) use single transaction to access importcontrol, so lock() works, but all changes are only visible after import is finished!)

Returns:
the new import
Throws:
SQLException

join

public long join(ImportControl imp)
          throws SQLException
Throws:
SQLException

update

public void update(ImportControl imp)
            throws SQLException
calls start() if not already done so! update status, rowCount, errorCount during running import.

Throws:
SQLException

update

public void update(ImportControl imp,
                   Importer importer)
            throws SQLException
update rowCount, errorCount during running import.

Throws:
SQLException

start

public long start(ImportControl imp)
           throws SQLException
insert the importcontrol row into the database. set startTime=now() and status=RUNNING with still null. call this only once per instance!

Parameters:
imp -
Returns:
Throws:
SQLException

end

public void end(ImportControl imp)
         throws SQLException
markiert den import mit dem angeg. Namen als beendet. Falls er noch nicht in der Datenbank stand, wird er jetzt angelegt.

Throws:
SQLException

end

public void end(long importId,
                Importer importer)
         throws SQLException
convenience method that takes infos from the importer.

Parameters:
importer - - a fileimport after import has ended
Throws:
SQLException

end

public void end(ImportControl imp,
                Importer importer)
         throws SQLException
Throws:
SQLException

getSqlUtil

public SqlUtil getSqlUtil()


Copyright © 2008-2011. All Rights Reserved.