Package org.intermine.sql.writebatch
Class BatchWriterSimpleImpl
- java.lang.Object
-
- 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.- Author:
- Matthew Wakeling
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.List<FlushJob>
addBatches
protected java.sql.Connection
con
protected java.util.List<FlushJob>
deleteBatches
protected int
deleteTempTableSize
protected java.sql.Statement
lastBatch
protected java.sql.Statement
postDeleteBatch
protected java.sql.Statement
preDeleteBatch
protected java.util.Map<java.lang.String,org.intermine.sql.writebatch.BatchWriterSimpleImpl.Statistic>
stats
-
Constructor Summary
Constructors Constructor Description BatchWriterSimpleImpl()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description 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<FlushJob> batches)
Performs all the insert operations for the given IndirectionTableBatch and name.protected int
doInserts(java.lang.String name, TableBatch table, java.util.List<FlushJob> 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<java.lang.String,java.lang.Integer> 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<FlushJob>
write(java.sql.Connection con, java.util.Map<java.lang.String,? extends Table> tables, java.util.Set<java.lang.String> filter)
Performs all the processing for flushing a few tables to the connection, and returns a List of jobs to do the actual flushing.
-
-
-
Field Detail
-
deleteTempTableSize
protected int deleteTempTableSize
-
con
protected java.sql.Connection con
-
preDeleteBatch
protected java.sql.Statement preDeleteBatch
-
deleteBatches
protected java.util.List<FlushJob> deleteBatches
-
postDeleteBatch
protected java.sql.Statement postDeleteBatch
-
addBatches
protected java.util.List<FlushJob> addBatches
-
lastBatch
protected java.sql.Statement lastBatch
-
stats
protected java.util.Map<java.lang.String,org.intermine.sql.writebatch.BatchWriterSimpleImpl.Statistic> stats
-
-
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<FlushJob> write(java.sql.Connection con, java.util.Map<java.lang.String,? extends Table> tables, java.util.Set<java.lang.String> 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 interfaceBatchWriter
- Parameters:
con
- the SQL connectiontables
- a Map from table name to Tablefilter
- 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<FlushJob> batches) throws java.sql.SQLException
Performs all the inserts for the given table name and table batch.- Parameters:
name
- the name of the tabletable
- the table batchbatches
- 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 tabletable
- 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 tabletable
- 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<FlushJob> batches) throws java.sql.SQLException
Performs all the insert operations for the given IndirectionTableBatch and name.- Parameters:
name
- the name of the tabletable
- the IndirectionTableBatchbatches
- 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<java.lang.String,java.lang.Integer> 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 interfaceBatchWriter
- Parameters:
activity
- a Map from table name to the amount of activity (in rows) as an Integerconn
- 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 tableconn
- 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 tableconn
- a Connection to use- Throws:
java.sql.SQLException
- if something goes wrong
-
-