Package org.intermine.sql.logging
Class DatabaseWriter
- java.lang.Object
-
- java.io.Writer
-
- org.intermine.sql.logging.DatabaseWriter
-
- All Implemented Interfaces:
java.io.Closeable
,java.io.Flushable
,java.lang.Appendable
,java.lang.AutoCloseable
public class DatabaseWriter extends java.io.Writer
Writes tab-separated Strings to a database table- Author:
- Andrew Varley
-
-
Constructor Summary
Constructors Constructor Description DatabaseWriter()
Construct an empty DatabaseWriter for testing purposesDatabaseWriter(java.sql.Connection con, java.lang.String table)
Construct a DatabaseWriter
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
close()
Close this Writerprotected java.lang.String
createSQLStatement(java.lang.String table, java.lang.String row)
Creates an SQL String suitable for initialising a PreparedStatementvoid
flush()
Flush completed rows to the databasevoid
write(char[] cbuff, int off, int len)
Write a portion of an array to the database
-
-
-
Constructor Detail
-
DatabaseWriter
public DatabaseWriter()
Construct an empty DatabaseWriter for testing purposes
-
DatabaseWriter
public DatabaseWriter(java.sql.Connection con, java.lang.String table)
Construct a DatabaseWriter- Parameters:
con
- a database Connectiontable
- the table to write to- Throws:
java.lang.NullPointerException
- if either con or table are null
-
-
Method Detail
-
write
public void write(char[] cbuff, int off, int len) throws java.io.IOException
Write a portion of an array to the database- Specified by:
write
in classjava.io.Writer
- Parameters:
cbuff
- the array of charactersoff
- the start pointlen
- the number of characters to write- Throws:
java.io.IOException
- if an error occurs when writing to the underlying database
-
flush
public void flush()
Flush completed rows to the database- Specified by:
flush
in interfacejava.io.Flushable
- Specified by:
flush
in classjava.io.Writer
-
close
public void close()
Close this Writer- Specified by:
close
in interfacejava.lang.AutoCloseable
- Specified by:
close
in interfacejava.io.Closeable
- Specified by:
close
in classjava.io.Writer
-
createSQLStatement
protected java.lang.String createSQLStatement(java.lang.String table, java.lang.String row)
Creates an SQL String suitable for initialising a PreparedStatement- Parameters:
table
- the table to insert inrow
- an example row- Returns:
- the SQL String
- Throws:
java.lang.NullPointerException
- if any arguments are null
-
-