org.intermine.sql.writebatch
Class BatchWriterSimpleImpl

java.lang.Object
  extended by org.intermine.sql.writebatch.BatchWriterSimpleImpl
All Implemented Interfaces:
BatchWriter
Direct Known Subclasses:
BatchWriterPreparedStatementImpl

public class BatchWriterSimpleImpl
extends java.lang.Object
implements BatchWriter

An implementation of the BatchWriter interface that uses simple JDBC addBatch() and executeBatch() methods.


Field Summary
protected  java.util.List addBatches
           
protected  java.sql.Connection con
           
protected  java.util.List deleteBatches
           
protected  int deleteTempTableSize
           
protected  java.sql.Statement lastBatch
           
protected  java.sql.Statement postDeleteBatch
           
protected  java.sql.Statement preDeleteBatch
           
protected  java.util.Map stats
           
 
Constructor Summary
BatchWriterSimpleImpl()
           
 
Method Summary
protected  void addToLastBatch(java.lang.String sql)
          Adds a statement to the lastBatch.
protected  void addToPostDeleteBatch(java.lang.String sql)
          Adds a statement to the postDeleteBatch.
protected  void addToPreDeleteBatch(java.lang.String sql)
          Adds a statement to the preDeleteBatch.
protected  void doAnalyse(java.lang.String name, java.sql.Connection conn)
          Performs an ANALYSE of a table.
protected  int doDeletes(java.lang.String name, TableBatch table)
          Performs all the deletes for the given table name and table batch.
protected  int doIndirectionDeletes(java.lang.String name, IndirectionTableBatch table)
          Performs all the delete operations for the given IndirectionTableBatch and name.
protected  int doIndirectionInserts(java.lang.String name, IndirectionTableBatch table, java.util.List batches)
          Performs all the insert operations for the given IndirectionTableBatch and name.
protected  int doInserts(java.lang.String name, TableBatch table, java.util.List batches)
          Performs all the inserts for the given table name and table batch.
protected  int getTableSize(java.lang.String name, java.sql.Connection conn)
          Returns the approximate number of rows in a table.
 void setThreshold(int deleteTempTableSize)
          This sets the threshold above which a temp table will be used for deletes.
 void updateStatistics(java.util.Map activity, java.sql.Connection conn)
          Updates the per-table statistics held in this object, and may tell the SQL database to update its statistics using the supplied Connection.
 java.util.List write(java.sql.Connection con, java.util.Map tables, java.util.Set filter)
          Performs all the processing for flushing a few tables to the connection, and returns a List of jobs to do the actual flushing.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

deleteTempTableSize

protected int deleteTempTableSize

con

protected java.sql.Connection con

preDeleteBatch

protected java.sql.Statement preDeleteBatch

deleteBatches

protected java.util.List deleteBatches

postDeleteBatch

protected java.sql.Statement postDeleteBatch

addBatches

protected java.util.List addBatches

lastBatch

protected java.sql.Statement lastBatch

stats

protected java.util.Map stats
Constructor Detail

BatchWriterSimpleImpl

public BatchWriterSimpleImpl()
Method Detail

setThreshold

public void setThreshold(int deleteTempTableSize)
This sets the threshold above which a temp table will be used for deletes.

Parameters:
deleteTempTableSize - the threshold

write

public java.util.List write(java.sql.Connection con,
                            java.util.Map tables,
                            java.util.Set filter)
                     throws java.sql.SQLException
Performs all the processing for flushing a few tables to the connection, and returns a List of jobs to do the actual flushing.

Specified by:
write in interface BatchWriter
Parameters:
con - the SQL connection
tables - a Map from table name to Table
filter - a Set of table names to write, or null to write all tables
Returns:
a List of jobs to run to actually do the flushing
Throws:
java.sql.SQLException - if there is an underlying DB problem

doInserts

protected int doInserts(java.lang.String name,
                        TableBatch table,
                        java.util.List batches)
                 throws java.sql.SQLException
Performs all the inserts for the given table name and table batch.

Parameters:
name - the name of the table
table - the table batch
batches - the List of batches into which new flushjobs should be placed
Returns:
the number of rows inserted
Throws:
java.sql.SQLException - if an error occurs

doDeletes

protected int doDeletes(java.lang.String name,
                        TableBatch table)
                 throws java.sql.SQLException
Performs all the deletes for the given table name and table batch.

Parameters:
name - the name of the table
table - the table batch
Returns:
the number of rows deleted
Throws:
java.sql.SQLException - if an error occurs

doIndirectionDeletes

protected int doIndirectionDeletes(java.lang.String name,
                                   IndirectionTableBatch table)
                            throws java.sql.SQLException
Performs all the delete operations for the given IndirectionTableBatch and name.

Parameters:
name - the name of the table
table - the IndirectionTableBatch
Returns:
the number of rows deleted
Throws:
java.sql.SQLException - if an error occurs

doIndirectionInserts

protected int doIndirectionInserts(java.lang.String name,
                                   IndirectionTableBatch table,
                                   java.util.List batches)
                            throws java.sql.SQLException
Performs all the insert operations for the given IndirectionTableBatch and name.

Parameters:
name - the name of the table
table - the IndirectionTableBatch
batches - the List of flushjobs to add further actions to
Returns:
the number of rows inserted
Throws:
java.sql.SQLException - if an error occurs

addToPreDeleteBatch

protected void addToPreDeleteBatch(java.lang.String sql)
                            throws java.sql.SQLException
Adds a statement to the preDeleteBatch.

Parameters:
sql - the statement
Throws:
java.sql.SQLException - if an error occurs

addToPostDeleteBatch

protected void addToPostDeleteBatch(java.lang.String sql)
                             throws java.sql.SQLException
Adds a statement to the postDeleteBatch.

Parameters:
sql - the statement
Throws:
java.sql.SQLException - if an error occurs

addToLastBatch

protected void addToLastBatch(java.lang.String sql)
                       throws java.sql.SQLException
Adds a statement to the lastBatch.

Parameters:
sql - the statement
Throws:
java.sql.SQLException - if an error occurs

updateStatistics

public void updateStatistics(java.util.Map activity,
                             java.sql.Connection conn)
                      throws java.sql.SQLException
Updates the per-table statistics held in this object, and may tell the SQL database to update its statistics using the supplied Connection.

Specified by:
updateStatistics in interface BatchWriter
Parameters:
activity - a Map from table name to the amount of activity (in rows) as an Integer
conn - a Connection, over which to talk to the database
Throws:
java.sql.SQLException - if there is an underlying DB problem

getTableSize

protected int getTableSize(java.lang.String name,
                           java.sql.Connection conn)
                    throws java.sql.SQLException
Returns the approximate number of rows in a table.

Parameters:
name - the name of the table
conn - a Connection to use
Returns:
an int
Throws:
java.sql.SQLException - if there is a problem

doAnalyse

protected void doAnalyse(java.lang.String name,
                         java.sql.Connection conn)
                  throws java.sql.SQLException
Performs an ANALYSE of a table.

Parameters:
name - the name of the table
conn - a Connection to use
Throws:
java.sql.SQLException - if something goes wrong