|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object net.sf.farrago.syslib.FarragoExportSchemaUDR
public abstract class FarragoExportSchemaUDR
FarragoExportSchemaUDR provides system procedures to export tables from a local or foreign schema into CSV files.
Field Summary | |
---|---|
private static String[] |
EXPORT_TYPES
|
private static int |
FULL_EXPORT
|
private static int |
INCR_EXPORT
|
private static String |
LOGFILE_PREFIX
|
private static int |
MERGE_EXPORT
|
private static String |
NEWLINE
|
private static String |
QUOTE
|
private static String |
TAB
|
private static String[] |
TABLE_TYPES
|
private static Logger |
tracer
|
Constructor Summary | |
---|---|
FarragoExportSchemaUDR()
|
Method Summary | |
---|---|
private static String |
buildImportForeignSchemaSql(String foreignServer,
String foreignSchema,
String tableList,
String tablePattern,
boolean exclude,
String tempSchema)
Helper function to build the import foreign schema SQL used in exporting from a foreign schema |
private static String |
buildQuerySql(int expType,
String catalog,
String schema,
String tblName,
Timestamp lastModifiedTs,
String colName,
String incrCatalog,
String incrSchema)
Helper function to build sql to query tables |
private static int |
checkColumnName(int expType,
String catalog,
String schema,
String incrCatalog,
String incrSchema,
String tableName,
String columnName,
Connection conn)
Checks the column names passed in are valid for a table; last modified column for incremental export and id column for merge export |
private static void |
exportForeignSchemaHelper(int expType,
String foreignServer,
String foreignSchema,
boolean exclude,
String tableList,
String tablePattern,
Timestamp lastModified,
String lastModifiedColumn,
String directory,
boolean withBcp,
boolean deleteFailedFiles)
Helper function for full and incremental exports of tables within a foreign schema |
static void |
exportForeignSchemaIncrementalToCsv(String foreignServer,
String foreignSchema,
boolean exclude,
String tableList,
String tablePattern,
Timestamp lastModified,
String lastModifiedColumn,
String directory)
Standard version of incremental foreign schema export which always creates bcp files and deletes any leftover files from failed table exports |
static void |
exportForeignSchemaIncrementalToCsv(String foreignServer,
String foreignSchema,
boolean exclude,
String tableList,
String tablePattern,
Timestamp lastModified,
String lastModifiedColumn,
String directory,
boolean withBcp,
boolean deleteFailedFiles)
Exports tables within a foreign schema to CSV/BCP files for rows modified after a specified timestamp |
static void |
exportForeignSchemaToCsv(String foreignServer,
String foreignSchema,
boolean exclude,
String tableList,
String tablePattern,
String directory)
Standard version of foreign schema export which always creates bcp files and deletes any leftover files from failed table exports |
static void |
exportForeignSchemaToCsv(String foreignServer,
String foreignSchema,
boolean exclude,
String tableList,
String tablePattern,
String directory,
boolean withBcp,
boolean deleteFailedFiles)
Exports tables within a foreign schema to CSV/BCP files |
static void |
exportMergedSchemas(String origCatalog,
String origSchema,
String incrCatalog,
String incrSchema,
boolean exclude,
String tableList,
String tablePattern,
String idColumn,
String directory)
Standard version of local merge schema export which always creates bcp files and deletes any leftover files from failed table exports |
static void |
exportMergedSchemas(String origCatalog,
String origSchema,
String incrCatalog,
String incrSchema,
boolean exclude,
String tableList,
String tablePattern,
String idColumn,
String directory,
boolean withBcp,
boolean deleteFailedFiles)
Used to combine original data and incremental data. |
static void |
exportQueryToFile(String querySql,
String pathWithoutExtension,
boolean withBcp,
boolean deleteFailedFiles)
Deprecated. Use widest version instead. |
static void |
exportQueryToFile(String querySql,
String pathWithoutExtension,
boolean withBcp,
boolean withData,
boolean deleteFailedFiles,
String fieldDelimiter,
String fileExtension,
String dateFormat,
String timeFormat,
String timestampFormat)
Exports results of a single query to CSV/BCP files. |
static void |
exportQueryToFile(String querySql,
String pathWithoutExtension,
boolean withBcp,
boolean deleteFailedFiles,
String fieldDelimiter,
String fileExtension,
String dateFormat,
String timeFormat,
String timestampFormat)
Deprecated. Use widest version instead. |
static void |
exportSchemaIncrementalToCsv(String catalog,
String schema,
boolean exclude,
String tableList,
String tablePattern,
Timestamp lastModified,
String lastModifiedColumn,
String directory)
Standard version of incremental local schema export which always creates bcp files and deletes any leftover files from failed table exports |
static void |
exportSchemaIncrementalToCsv(String catalog,
String schema,
boolean exclude,
String tableList,
String tablePattern,
Timestamp lastModified,
String lastModifiedColumn,
String directory,
boolean withBcp,
boolean deleteFailedFiles)
Exports tables within a schema to CSV/BCP files for rows modified after a specified timestamp |
static void |
exportSchemaToCsv(String catalog,
String schema,
boolean exclude,
String tableList,
String tablePattern,
String directory)
Standard version of local schema export which always creates bcp files and deletes any leftover files from failed table exports |
static void |
exportSchemaToCsv(String catalog,
String schema,
boolean exclude,
String tableList,
String tablePattern,
String directory,
boolean withBcp,
boolean deleteFailedFiles)
Exports tables within a schema to flat files with BCP files Older version of the export local schema UDP without file extension, field delimiter and datetime format parameters. |
static void |
exportSchemaToFile(String catalog,
String schema,
boolean exclude,
String tableList,
String tablePattern,
String directory,
boolean withBcp,
boolean deleteFailedFiles,
String fieldDelimiter,
String fileExtension)
Exports tables within a schema to flat files with BCP files |
static void |
exportSchemaToFile(String catalog,
String schema,
boolean exclude,
String tableList,
String tablePattern,
String directory,
boolean withBcp,
boolean deleteFailedFiles,
String fieldDelimiter,
String fileExtension,
String dateFormat,
String timeFormat,
String timestampFormat)
Exports tables within a schema to flat files with BCP files |
static String |
getBcpLine(int colNum,
ResultSetMetaData rsmd,
String fieldDelim)
Helper function which returns a line in BCP file format for a specified column in a table. |
private static HashSet<String> |
getLocalTableNames(String catalog,
String schema,
boolean exclude,
String tableList,
String tablePattern,
Connection conn)
Helper function which gets the set of local table names to be exported |
private static String |
getTimestampString()
Helper function which returns the current timestamp as a string |
private static String |
quote(String value)
Helper function which escapes the quotes by quoting them |
private static void |
toCsv(int expType,
String catalog,
String schema,
Timestamp lastModified,
String columnName,
String incrCatalog,
String incrSchema,
String directory,
boolean withBcp,
boolean withData,
boolean deleteFailedFiles,
String fieldDelimiter,
String fileExtension,
String dateFormat,
String timeFormat,
String timestampFormat,
HashSet<String> tableNames,
String querySql,
Connection conn)
Helper function which creates and writes data to CSV and BCP files |
Methods inherited from class java.lang.Object |
---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
Field Detail |
---|
private static Logger tracer
private static final String QUOTE
private static final String TAB
private static final String NEWLINE
private static final String[] TABLE_TYPES
private static final String LOGFILE_PREFIX
private static final int FULL_EXPORT
private static final int INCR_EXPORT
private static final int MERGE_EXPORT
private static final String[] EXPORT_TYPES
Constructor Detail |
---|
public FarragoExportSchemaUDR()
Method Detail |
---|
public static void exportSchemaToFile(String catalog, String schema, boolean exclude, String tableList, String tablePattern, String directory, boolean withBcp, boolean deleteFailedFiles, String fieldDelimiter, String fileExtension, String dateFormat, String timeFormat, String timestampFormat) throws SQLException
catalog
- name of the catalog where schema resides, if null, default
catalogschema
- name of local schemaexclude
- if true, tables matching either the table_list of the
table_pattern will be excluded. if false, tables will be includedtableList
- comma separated list of tables or null value if
table_pattern is being usedtablePattern
- table name pattern where '_' represents any single
characterdirectory
- the directory in which to place the exported CSV and BCP
fileswithBcp
- indicates whether BCP files should be created. If true,
BCP files will be created. If false, they will not be createddeleteFailedFiles
- if true, csv and bcp files for tables which fail
during export will be deleted, otherwise they will remainfieldDelimiter
- used to delimit column fields in the flat file if
null, defaults to tab separatedfileExtension
- the file extension for the created flat file, if
null, defaults to .txtdateFormat
- format for DATE fields (SimpleDateFormat
)timeFormat
- format for TIME fields (SimpleDateFormat
)timestampFormat
- format for TIMESTAMP fields (SimpleDateFormat
)
SQLException
public static void exportSchemaToFile(String catalog, String schema, boolean exclude, String tableList, String tablePattern, String directory, boolean withBcp, boolean deleteFailedFiles, String fieldDelimiter, String fileExtension) throws SQLException
catalog
- name of the catalog where schema resides, if null, default
catalogschema
- name of local schemaexclude
- if true, tables matching either the table_list of the
table_pattern will be excluded. if false, tables will be includedtableList
- comma separated list of tables or null value if
table_pattern is being usedtablePattern
- table name pattern where '_' represents any single
characterdirectory
- the directory in which to place the exported CSV and BCP
fileswithBcp
- indicates whether BCP files should be created. If true,
BCP files will be created. If false, they will not be createddeleteFailedFiles
- if true, csv and bcp files for tables which fail
during export will be deleted, otherwise they will remainfieldDelimiter
- used to delimit column fields in the flat file if
null, defaults to tab separatedfileExtension
- the file extension for the created flat file, if
null, defaults to .txt
SQLException
public static void exportSchemaToCsv(String catalog, String schema, boolean exclude, String tableList, String tablePattern, String directory, boolean withBcp, boolean deleteFailedFiles) throws SQLException
catalog
- name of the catalog where schema resides, if null, default
catalogschema
- name of local schemaexclude
- if true, tables matching either the table_list of the
table_pattern will be excluded. if false, tables will be includedtableList
- comma separated list of tables or null value if
table_pattern is being usedtablePattern
- table name pattern where '_' represents any single
characterdirectory
- the directory in which to place the exported CSV and BCP
fileswithBcp
- indicates whether BCP files should be created. If true,
BCP files will be created. If false, they will not be createddeleteFailedFiles
- if true, csv and bcp files for tables which fail
during export will be deleted, otherwise they will remain
SQLException
public static void exportSchemaToCsv(String catalog, String schema, boolean exclude, String tableList, String tablePattern, String directory) throws SQLException
SQLException
public static void exportForeignSchemaToCsv(String foreignServer, String foreignSchema, boolean exclude, String tableList, String tablePattern, String directory, boolean withBcp, boolean deleteFailedFiles) throws SQLException
foreignServer
- name of the foreign serverforeignSchema
- name of the foreign schemaexclude
- if true, tables matching either the tableList of the
tablePattern will be excluded. if false, tables will be includedtableList
- comma separated list of tables or null value if
tablePattern is being usedtablePattern
- table name pattern where '_' represents any single
character and '%' represents any sequence of zero or more characters. Set
to null value if tableList is being useddirectory
- the directory in which to place the exported CSV and BCP
fileswithBcp
- indicates whether bcp files should be created. if true,
bcp files will be created. If false, they will not be createddeleteFailedFiles
- if true, csv and bcp files for tables which fail
during export will be deleted, otherwise they will remain
SQLException
public static void exportForeignSchemaToCsv(String foreignServer, String foreignSchema, boolean exclude, String tableList, String tablePattern, String directory) throws SQLException
SQLException
public static void exportSchemaIncrementalToCsv(String catalog, String schema, boolean exclude, String tableList, String tablePattern, Timestamp lastModified, String lastModifiedColumn, String directory, boolean withBcp, boolean deleteFailedFiles) throws SQLException
catalog
- name of the catalog where schema resides, if null, default
catalogschema
- name of local schemaexclude
- if true, tables matching either the tableList of the
tablePattern will be excluded. if false, tables will be includedtableList
- comma separated list of tables or null value if
tablePattern is being usedtablePattern
- table name pattern where '_' represents any single
characterlastModified
- if specified, only rows which were modified after
this timestamp will be written to the csv file; lastModifiedColumn must
be valid for this field to be usedlastModifiedColumn
- name of the column for last modified timestamp,
if not specified then all rows will be writtendirectory
- the directory in which to place the exported CSV and BCP
fileswithBcp
- indicates whether BCP files should be created. If true,
BCP files will be created. If false, they will not be createddeleteFailedFiles
- if true, csv and bcp files for tables which fail
during export will be deleted, otherwise they will remain
SQLException
public static void exportSchemaIncrementalToCsv(String catalog, String schema, boolean exclude, String tableList, String tablePattern, Timestamp lastModified, String lastModifiedColumn, String directory) throws SQLException
SQLException
public static void exportForeignSchemaIncrementalToCsv(String foreignServer, String foreignSchema, boolean exclude, String tableList, String tablePattern, Timestamp lastModified, String lastModifiedColumn, String directory, boolean withBcp, boolean deleteFailedFiles) throws SQLException
foreignServer
- name of the foreign serverforeignSchema
- name of the foreign schemaexclude
- if true, tables matching either the tableList of the
tablePattern will be excluded. if false, tables will be includedtableList
- comma separated list of tables or null value if
tablePattern is being usedtablePattern
- table name pattern where '_' represents any single
character and '%' represents any sequence of zero or more characters. Set
to null value if tableList is being usedlastModified
- only rows which were modified after this timestamp
will be returnedlastModifiedColumn
- name of the column for last modified timestamp;
if not valid for a table, all rows will be returneddirectory
- the directory in which to place the exported CSV and BCP
fileswithBcp
- indicates whether bcp files should be created. if true,
bcp files will be created. If false, they will not be createddeleteFailedFiles
- if true, csv and bcp files for tables which fail
during export will be deleted, otherwise they will remain
SQLException
public static void exportForeignSchemaIncrementalToCsv(String foreignServer, String foreignSchema, boolean exclude, String tableList, String tablePattern, Timestamp lastModified, String lastModifiedColumn, String directory) throws SQLException
SQLException
public static void exportMergedSchemas(String origCatalog, String origSchema, String incrCatalog, String incrSchema, boolean exclude, String tableList, String tablePattern, String idColumn, String directory, boolean withBcp, boolean deleteFailedFiles) throws SQLException
origCatalog
- name of catalog where original data tables resideorigSchema
- name of schema where original data tables resideincrCatalog
- name of catalog where incremental data tables resideincrSchema
- name of schema where incremental data tables resideidColumn
- name of the id column used to join tablesdirectory
- the directory in which to place the exported CSV and BCP
fileswithBcp
- indicates whether bcp files should be created. if true,
bcp files will be created. If false, they will not be createddeleteFailedFiles
- if true, csv and bcp files for tables which fail
during export will be deleted, otherwise they will remain
SQLException
public static void exportMergedSchemas(String origCatalog, String origSchema, String incrCatalog, String incrSchema, boolean exclude, String tableList, String tablePattern, String idColumn, String directory) throws SQLException
SQLException
private static HashSet<String> getLocalTableNames(String catalog, String schema, boolean exclude, String tableList, String tablePattern, Connection conn) throws SQLException
catalog
- name of catalogschema
- name of local schemaexclude
- if true, tables matching either the tableList of the
tablePattern will be excluded. if false, tables will be includedtableList
- comma separated list of tables or null value if
tablePattern is being usedtablePattern
- table name pattern where '_' represents any single
characterconn
- connection to the database
SQLException
private static void exportForeignSchemaHelper(int expType, String foreignServer, String foreignSchema, boolean exclude, String tableList, String tablePattern, Timestamp lastModified, String lastModifiedColumn, String directory, boolean withBcp, boolean deleteFailedFiles) throws SQLException
expType
- type of exportforeignServer
- name of the foreign serverforeignSchema
- name of the foreign schemaexclude
- if true, tables matching either the tableList of the
tablePattern will be excluded. if false, tables will be includedtableList
- comma separated list of tables or null value if
tablePattern is being usedtablePattern
- table name pattern where '_' represents any single
character and '%' represents any sequence of zero or more characters. Set
to null value if tableList is being usedlastModified
- if specified, only rows which were modified after
this timestamp will be returned; lastModifiedColumn must be valid for
this field to be usedlastModifiedColumn
- name of the column for last modified timestamp,
if not specified all rows will be returneddirectory
- the directory in which to place the exported CSV and BCP
fileswithBcp
- indicates whether bcp files should be created. if true,
bcp files will be created. If false, they will not be createddeleteFailedFiles
- if true, csv and bcp files for tables which fail
during export will be deleted, otherwise they will remain
SQLException
private static void toCsv(int expType, String catalog, String schema, Timestamp lastModified, String columnName, String incrCatalog, String incrSchema, String directory, boolean withBcp, boolean withData, boolean deleteFailedFiles, String fieldDelimiter, String fileExtension, String dateFormat, String timeFormat, String timestampFormat, HashSet<String> tableNames, String querySql, Connection conn) throws SQLException
expType
- type of exportcatalog
- name of catalogschema
- name of local schemalastModified
- only used for incremental export, rows which were
modified after this timestamp will be written to the csv file
lastModifiedColumn must be valid for this field to be usedcolumnName
- for incremental export, name of the last modified
timestamp column, for merge export, name of the id columnincrCatalog
- only valid for merge export; name of catalog for
incremental dataincrSchema
- only valid for merge export; name of schema for
incremental datadirectory
- location to write CSV and BCP fileswithBcp
- if true creates BCP files, if false, doesn'twithData
- if true creates data files, if false, doesn'tdeleteFailedFiles
- if true, csv and bcp files for tables which fail
during export will be deleted, otherwise they will remaindateFormat
- format for DATE fields (SimpleDateFormat
)timeFormat
- format for TIME fields (SimpleDateFormat
)timestampFormat
- format for TIMESTAMP fields (SimpleDateFormat
)tableNames
- HashSet with names of the table to exportquerySql
- SQL query to execute (if non-null, all table-related
parameters should be null; and vice versa)conn
- connection to the dtaabase
SQLException
public static void exportQueryToFile(String querySql, String pathWithoutExtension, boolean withBcp, boolean deleteFailedFiles) throws SQLException
querySql
- query whose result is to be executedpathWithoutExtension
- location to write CSV and BCP files; this
should be a directory-qualified filename without an extension (correct
extension will be appended automatically)withBcp
- if true creates BCP files, if false, doesn'tdeleteFailedFiles
- if true, csv and bcp files will be deleted if
export fails, otherwise they may remain rowcount
SQLException
public static void exportQueryToFile(String querySql, String pathWithoutExtension, boolean withBcp, boolean deleteFailedFiles, String fieldDelimiter, String fileExtension, String dateFormat, String timeFormat, String timestampFormat) throws SQLException
querySql
- query whose result is to be executedpathWithoutExtension
- location to write CSV and BCP files; this
should be a directory-qualified filename without an extension (correct
extension will be appended automatically)withBcp
- if true creates BCP files, if false, doesn'tdeleteFailedFiles
- if true, csv and bcp files will be deleted if
export fails, otherwise they may remain rowcountfieldDelimiter
- used to delimit column fields in the flat file if
null, defaults to tab separatedfileExtension
- the file extension for the created flat file, if
null, defaults to .txtdateFormat
- format for DATE fields (SimpleDateFormat
)timeFormat
- format for TIME fields (SimpleDateFormat
)timestampFormat
- format for TIMESTAMP fields (SimpleDateFormat
)
SQLException
public static void exportQueryToFile(String querySql, String pathWithoutExtension, boolean withBcp, boolean withData, boolean deleteFailedFiles, String fieldDelimiter, String fileExtension, String dateFormat, String timeFormat, String timestampFormat) throws SQLException
querySql
- query whose result is to be executedpathWithoutExtension
- location to write CSV and BCP files; this
should be a directory-qualified filename without an extension (correct
extension will be appended automatically)withBcp
- if true creates BCP file, if false, doesn'twithData
- if true creates data file, if false, doesn'tdeleteFailedFiles
- if true, csv and bcp files will be deleted if
export fails, otherwise they may remain rowcountfieldDelimiter
- used to delimit column fields in the flat file if
null, defaults to tab separatedfileExtension
- the file extension for the created flat file, if
null, defaults to .txtdateFormat
- format for DATE fields (SimpleDateFormat
)timeFormat
- format for TIME fields (SimpleDateFormat
)timestampFormat
- format for TIMESTAMP fields (SimpleDateFormat
)
SQLException
public static String getBcpLine(int colNum, ResultSetMetaData rsmd, String fieldDelim) throws SQLException
colNum
- column number to return BCP control data forrsmd
- metadata for the table
SQLException
private static String quote(String value)
value
- string in which to replace quotes with quoted quotes
private static String getTimestampString()
private static String buildQuerySql(int expType, String catalog, String schema, String tblName, Timestamp lastModifiedTs, String colName, String incrCatalog, String incrSchema)
private static String buildImportForeignSchemaSql(String foreignServer, String foreignSchema, String tableList, String tablePattern, boolean exclude, String tempSchema)
private static int checkColumnName(int expType, String catalog, String schema, String incrCatalog, String incrSchema, String tableName, String columnName, Connection conn) throws SQLException
SQLException
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |