public class ImportUtil
extends java.lang.Object
ImportUtil.Builder for convenient configuration of the
import functionality. Note that most scenarios for customizing input data
can be handled by implementing a custom ImportFilter.| Modifier and Type | Class and Description |
|---|---|
static class |
ImportUtil.Builder
Builder which simplifies configuration of an import operation.
|
| Modifier and Type | Field and Description |
|---|---|
private static int |
COPY_TABLE_BATCH_SIZE
Batch commit size for copying other result sets into this database
|
(package private) static java.lang.String |
LINE_SEPARATOR
the platform line separator
|
| Modifier | Constructor and Description |
|---|---|
private |
ImportUtil() |
| Modifier and Type | Method and Description |
|---|---|
private static Table |
createUniqueTable(Database db,
java.lang.String name,
java.util.List<ColumnBuilder> columns,
java.sql.ResultSetMetaData md,
ImportFilter filter)
Returns a new table with a unique name and the given table definition.
|
static java.lang.String |
importFile(java.io.File f,
Database db,
java.lang.String name,
java.lang.String delim)
Copy a delimited text file into a new table in this database.
|
static java.lang.String |
importFile(java.io.File f,
Database db,
java.lang.String name,
java.lang.String delim,
char quote,
ImportFilter filter,
boolean useExistingTable)
Copy a delimited text file into a new table in this database.
|
static java.lang.String |
importFile(java.io.File f,
Database db,
java.lang.String name,
java.lang.String delim,
char quote,
ImportFilter filter,
boolean useExistingTable,
boolean header)
Copy a delimited text file into a new table in this database.
|
static java.lang.String |
importFile(java.io.File f,
Database db,
java.lang.String name,
java.lang.String delim,
ImportFilter filter)
Copy a delimited text file into a new table in this database.
|
static java.lang.String |
importReader(java.io.BufferedReader in,
Database db,
java.lang.String name,
java.lang.String delim)
Copy a delimited text file into a new table in this database.
|
static java.lang.String |
importReader(java.io.BufferedReader in,
Database db,
java.lang.String name,
java.lang.String delim,
char quote,
ImportFilter filter,
boolean useExistingTable)
Copy a delimited text file into a new (or optionally exixsting) table in
this database.
|
static java.lang.String |
importReader(java.io.BufferedReader in,
Database db,
java.lang.String name,
java.lang.String delim,
char quote,
ImportFilter filter,
boolean useExistingTable,
boolean header)
Copy a delimited text file into a new (or optionally exixsting) table in
this database.
|
static java.lang.String |
importReader(java.io.BufferedReader in,
Database db,
java.lang.String name,
java.lang.String delim,
ImportFilter filter)
Copy a delimited text file into a new table in this database.
|
static java.lang.String |
importReader(java.io.BufferedReader in,
Database db,
java.lang.String name,
java.lang.String delim,
ImportFilter filter,
boolean useExistingTable)
Copy a delimited text file into a new (or optionally exixsting) table in
this database.
|
static java.lang.String |
importResultSet(java.sql.ResultSet source,
Database db,
java.lang.String name)
Copy an existing JDBC ResultSet into a new table in this database.
|
static java.lang.String |
importResultSet(java.sql.ResultSet source,
Database db,
java.lang.String name,
ImportFilter filter)
Copy an existing JDBC ResultSet into a new table in this database.
|
static java.lang.String |
importResultSet(java.sql.ResultSet source,
Database db,
java.lang.String name,
ImportFilter filter,
boolean useExistingTable)
Copy an existing JDBC ResultSet into a new (or optionally existing) table
in this database.
|
private static java.lang.Object[] |
splitLine(java.lang.String line,
java.util.regex.Pattern delim,
char quote,
java.io.BufferedReader in,
int numColumns)
Splits the given line using the given delimiter pattern and quote
character.
|
static java.util.List<ColumnBuilder> |
toColumns(java.sql.ResultSetMetaData md)
Returns a List of Column instances converted from the given
ResultSetMetaData (this is the same method used by the various
importResultSet() methods). |
private static final int COPY_TABLE_BATCH_SIZE
static final java.lang.String LINE_SEPARATOR
public static java.util.List<ColumnBuilder> toColumns(java.sql.ResultSetMetaData md) throws java.sql.SQLException
importResultSet() methods).java.sql.SQLExceptionpublic static java.lang.String importResultSet(java.sql.ResultSet source,
Database db,
java.lang.String name)
throws java.sql.SQLException,
java.io.IOException
Equivalent to:
importResultSet(source, db, name, SimpleImportFilter.INSTANCE);
name - Name of the new table to createsource - ResultSet to copy fromjava.sql.SQLExceptionjava.io.IOExceptionimportResultSet(ResultSet,Database,String,ImportFilter),
ImportUtil.Builderpublic static java.lang.String importResultSet(java.sql.ResultSet source,
Database db,
java.lang.String name,
ImportFilter filter)
throws java.sql.SQLException,
java.io.IOException
Equivalent to:
importResultSet(source, db, name, filter, false);
name - Name of the new table to createsource - ResultSet to copy fromfilter - valid import filterjava.sql.SQLExceptionjava.io.IOExceptionimportResultSet(ResultSet,Database,String,ImportFilter,boolean),
ImportUtil.Builderpublic static java.lang.String importResultSet(java.sql.ResultSet source,
Database db,
java.lang.String name,
ImportFilter filter,
boolean useExistingTable)
throws java.sql.SQLException,
java.io.IOException
name - Name of the new table to createsource - ResultSet to copy fromfilter - valid import filteruseExistingTable - if true use current table if it already
exists, otherwise, create new table with unique
namejava.sql.SQLExceptionjava.io.IOExceptionImportUtil.Builderpublic static java.lang.String importFile(java.io.File f,
Database db,
java.lang.String name,
java.lang.String delim)
throws java.io.IOException
Equivalent to:
importFile(f, name, db, delim, SimpleImportFilter.INSTANCE);
name - Name of the new table to createf - Source file to importdelim - Regular expression representing the delimiter string.java.io.IOExceptionimportFile(File,Database,String,String,ImportFilter),
ImportUtil.Builderpublic static java.lang.String importFile(java.io.File f,
Database db,
java.lang.String name,
java.lang.String delim,
ImportFilter filter)
throws java.io.IOException
Equivalent to:
importFile(f, name, db, delim, "'", filter, false);
name - Name of the new table to createf - Source file to importdelim - Regular expression representing the delimiter string.filter - valid import filterjava.io.IOExceptionimportReader(BufferedReader,Database,String,String,ImportFilter),
ImportUtil.Builderpublic static java.lang.String importFile(java.io.File f,
Database db,
java.lang.String name,
java.lang.String delim,
char quote,
ImportFilter filter,
boolean useExistingTable)
throws java.io.IOException
Equivalent to:
importReader(new BufferedReader(new FileReader(f)), db, name, delim, "'", filter, useExistingTable, true);
name - Name of the new table to createf - Source file to importdelim - Regular expression representing the delimiter string.quote - the quote characterfilter - valid import filteruseExistingTable - if true use current table if it already
exists, otherwise, create new table with unique
namejava.io.IOExceptionimportReader(BufferedReader,Database,String,String,ImportFilter,boolean),
ImportUtil.Builderpublic static java.lang.String importFile(java.io.File f,
Database db,
java.lang.String name,
java.lang.String delim,
char quote,
ImportFilter filter,
boolean useExistingTable,
boolean header)
throws java.io.IOException
Equivalent to:
importReader(new BufferedReader(new FileReader(f)), db, name, delim, "'", filter, useExistingTable, header);
name - Name of the new table to createf - Source file to importdelim - Regular expression representing the delimiter string.quote - the quote characterfilter - valid import filteruseExistingTable - if true use current table if it already
exists, otherwise, create new table with unique
nameheader - if false the first line is not a header row, only
valid if useExistingTable is truejava.io.IOExceptionimportReader(BufferedReader,Database,String,String,char,ImportFilter,boolean,boolean),
ImportUtil.Builderpublic static java.lang.String importReader(java.io.BufferedReader in,
Database db,
java.lang.String name,
java.lang.String delim)
throws java.io.IOException
Equivalent to:
importReader(in, db, name, delim, SimpleImportFilter.INSTANCE);
name - Name of the new table to createin - Source reader to importdelim - Regular expression representing the delimiter string.java.io.IOExceptionimportReader(BufferedReader,Database,String,String,ImportFilter),
ImportUtil.Builderpublic static java.lang.String importReader(java.io.BufferedReader in,
Database db,
java.lang.String name,
java.lang.String delim,
ImportFilter filter)
throws java.io.IOException
Equivalent to:
importReader(in, db, name, delim, filter, false);
name - Name of the new table to createin - Source reader to importdelim - Regular expression representing the delimiter string.filter - valid import filterjava.io.IOExceptionimportReader(BufferedReader,Database,String,String,ImportFilter,boolean),
ImportUtil.Builderpublic static java.lang.String importReader(java.io.BufferedReader in,
Database db,
java.lang.String name,
java.lang.String delim,
ImportFilter filter,
boolean useExistingTable)
throws java.io.IOException
Equivalent to:
importReader(in, db, name, delim, '"', filter, false);
name - Name of the new table to createin - Source reader to importdelim - Regular expression representing the delimiter string.filter - valid import filteruseExistingTable - if true use current table if it already
exists, otherwise, create new table with unique
namejava.io.IOExceptionImportUtil.Builderpublic static java.lang.String importReader(java.io.BufferedReader in,
Database db,
java.lang.String name,
java.lang.String delim,
char quote,
ImportFilter filter,
boolean useExistingTable)
throws java.io.IOException
Equivalent to:
importReader(in, db, name, delim, '"', filter, useExistingTable, true);
name - Name of the new table to createin - Source reader to importdelim - Regular expression representing the delimiter string.quote - the quote characterfilter - valid import filteruseExistingTable - if true use current table if it already
exists, otherwise, create new table with unique
namejava.io.IOExceptionImportUtil.Builderpublic static java.lang.String importReader(java.io.BufferedReader in,
Database db,
java.lang.String name,
java.lang.String delim,
char quote,
ImportFilter filter,
boolean useExistingTable,
boolean header)
throws java.io.IOException
name - Name of the new table to createin - Source reader to importdelim - Regular expression representing the delimiter string.quote - the quote characterfilter - valid import filteruseExistingTable - if true use current table if it already
exists, otherwise, create new table with unique
nameheader - if false the first line is not a header row, only
valid if useExistingTable is truejava.io.IOExceptionImportUtil.Builderprivate static java.lang.Object[] splitLine(java.lang.String line,
java.util.regex.Pattern delim,
char quote,
java.io.BufferedReader in,
int numColumns)
throws java.io.IOException
java.io.IOExceptionprivate static Table createUniqueTable(Database db, java.lang.String name, java.util.List<ColumnBuilder> columns, java.sql.ResultSetMetaData md, ImportFilter filter) throws java.io.IOException, java.sql.SQLException
java.io.IOExceptionjava.sql.SQLException