Package com.microsoft.sqlserver.jdbc
Class SQLServerBulkCSVFileRecord
java.lang.Object
com.microsoft.sqlserver.jdbc.SQLServerBulkCSVFileRecord
- All Implemented Interfaces:
ISQLServerBulkData,ISQLServerBulkRecord,java.io.Serializable,java.lang.AutoCloseable
public class SQLServerBulkCSVFileRecord
extends java.lang.Object
implements java.lang.AutoCloseable
Provides a simple implementation of the ISQLServerBulkRecord interface that can be used to read in the basic Java
data types from a delimited file where each line represents a row of data.
- See Also:
- Serialized Form
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.Integer,com.microsoft.sqlserver.jdbc.SQLServerBulkRecord.ColumnMetadata>columnMetadataprotected java.lang.String[]columnNamesprotected java.time.format.DateTimeFormatterdateTimeFormatterprotected static java.util.logging.LoggerloggerExternalprotected java.lang.StringloggerPackageNameprotected java.time.format.DateTimeFormattertimeFormatter -
Constructor Summary
Constructors Constructor Description SQLServerBulkCSVFileRecord(java.io.InputStream fileToParse, java.lang.String encoding, java.lang.String delimiter, boolean firstLineIsColumnNames)Constructs a SQLServerBulkCSVFileRecord to parse data from a delimited file with the given encoding.SQLServerBulkCSVFileRecord(java.lang.String fileToParse, boolean firstLineIsColumnNames)Constructs a SQLServerBulkCSVFileRecord to parse data from a CSV file with the default encoding.SQLServerBulkCSVFileRecord(java.lang.String fileToParse, java.lang.String encoding, boolean firstLineIsColumnNames)Constructs a SQLServerBulkCSVFileRecord to parse data from a CSV file with the given encoding.SQLServerBulkCSVFileRecord(java.lang.String fileToParse, java.lang.String encoding, java.lang.String delimiter, boolean firstLineIsColumnNames)Constructs a simple reader to parse data from a delimited file with the given encoding. -
Method Summary
Modifier and Type Method Description voidaddColumnMetadata(int positionInSource, java.lang.String name, int jdbcType, int precision, int scale)Adds metadata for the given column in the file.voidaddColumnMetadata(int positionInSource, java.lang.String name, int jdbcType, int precision, int scale, java.time.format.DateTimeFormatter dateTimeFormatter)Adds metadata for the given column in the file.protected voidcheckDuplicateColumnName(int positionInTable, java.lang.String colName)voidclose()Releases any resources associated with the file reader.java.time.format.DateTimeFormattergetColumnDateTimeFormatter(int column)Returns thedateTimeFormatterfor the given column.java.lang.StringgetColumnName(int column)Returns the name of the given column.java.util.Set<java.lang.Integer>getColumnOrdinals()Returns the ordinals for each of the columns represented in this data record.intgetColumnType(int column)Returns the JDBC data type of the given column.intgetPrecision(int column)Returns the precision for the given column.java.lang.Object[]getRowData()Returns the data for the current row as an array of Objects.intgetScale(int column)Returns the scale for the given column.booleanisAutoIncrement(int column)Returns whether the column represents an identity column.booleannext()Advances to the next data row.voidsetTimestampWithTimezoneFormat(java.lang.String dateTimeFormat)Sets the format for reading in dates from the file.voidsetTimestampWithTimezoneFormat(java.time.format.DateTimeFormatter dateTimeFormatter)Sets the format for reading in dates from the file.voidsetTimeWithTimezoneFormat(java.lang.String timeFormat)Sets the format for reading in dates from the file.voidsetTimeWithTimezoneFormat(java.time.format.DateTimeFormatter dateTimeFormatter)Sets the format for reading in dates from the file.protected voidthrowInvalidArgument(java.lang.String argument)
-
Field Details
-
columnNames
protected java.lang.String[] columnNames -
columnMetadata
protected java.util.Map<java.lang.Integer,com.microsoft.sqlserver.jdbc.SQLServerBulkRecord.ColumnMetadata> columnMetadata -
dateTimeFormatter
protected java.time.format.DateTimeFormatter dateTimeFormatter -
timeFormatter
protected java.time.format.DateTimeFormatter timeFormatter -
loggerPackageName
protected java.lang.String loggerPackageName -
loggerExternal
protected static java.util.logging.Logger loggerExternal
-
-
Constructor Details
-
SQLServerBulkCSVFileRecord
public SQLServerBulkCSVFileRecord(java.lang.String fileToParse, java.lang.String encoding, java.lang.String delimiter, boolean firstLineIsColumnNames) throws SQLServerExceptionConstructs a simple reader to parse data from a delimited file with the given encoding.- Parameters:
fileToParse- File to parse data fromencoding- Charset encoding to use for reading the file, or NULL for the default encoding.delimiter- Delimiter to used to separate each columnfirstLineIsColumnNames- True if the first line of the file should be parsed as column names; false otherwise- Throws:
SQLServerException- If the arguments are invalid, there are any errors in reading the file, or the file is empty
-
SQLServerBulkCSVFileRecord
public SQLServerBulkCSVFileRecord(java.io.InputStream fileToParse, java.lang.String encoding, java.lang.String delimiter, boolean firstLineIsColumnNames) throws SQLServerExceptionConstructs a SQLServerBulkCSVFileRecord to parse data from a delimited file with the given encoding.- Parameters:
fileToParse- InputStream to parse data fromencoding- Charset encoding to use for reading the file, or NULL for the default encoding.delimiter- Delimiter to used to separate each columnfirstLineIsColumnNames- True if the first line of the file should be parsed as column names; false otherwise- Throws:
SQLServerException- If the arguments are invalid, there are any errors in reading the file, or the file is empty
-
SQLServerBulkCSVFileRecord
public SQLServerBulkCSVFileRecord(java.lang.String fileToParse, java.lang.String encoding, boolean firstLineIsColumnNames) throws SQLServerExceptionConstructs a SQLServerBulkCSVFileRecord to parse data from a CSV file with the given encoding.- Parameters:
fileToParse- File to parse data fromencoding- Charset encoding to use for reading the file.firstLineIsColumnNames- True if the first line of the file should be parsed as column names; false otherwise- Throws:
SQLServerException- If the arguments are invalid, there are any errors in reading the file, or the file is empty
-
SQLServerBulkCSVFileRecord
public SQLServerBulkCSVFileRecord(java.lang.String fileToParse, boolean firstLineIsColumnNames) throws SQLServerExceptionConstructs a SQLServerBulkCSVFileRecord to parse data from a CSV file with the default encoding.- Parameters:
fileToParse- File to parse data fromfirstLineIsColumnNames- True if the first line of the file should be parsed as column names; false otherwise- Throws:
SQLServerException- If the arguments are invalid, there are any errors in reading the file, or the file is empty
-
-
Method Details
-
close
Releases any resources associated with the file reader.- Specified by:
closein interfacejava.lang.AutoCloseable- Throws:
SQLServerException- when an error occurs
-
getRowData
Description copied from interface:ISQLServerBulkDataReturns the data for the current row as an array of Objects. Each Object must match the Java language Type that is used to represent the indicated JDBC data type for the given column. For more information, see 'Understanding the JDBC Driver Data Types' for the appropriate mappings.- Specified by:
getRowDatain interfaceISQLServerBulkData- Returns:
- The data for the row.
- Throws:
SQLServerException- If there are any errors in obtaining the data.
-
next
Description copied from interface:ISQLServerBulkDataAdvances to the next data row.- Specified by:
nextin interfaceISQLServerBulkData- Returns:
- True if rows are available; false if there are no more rows
- Throws:
SQLServerException- If there are any errors in advancing to the next row.
-
addColumnMetadata
public void addColumnMetadata(int positionInSource, java.lang.String name, int jdbcType, int precision, int scale, java.time.format.DateTimeFormatter dateTimeFormatter) throws SQLServerExceptionDescription copied from interface:ISQLServerBulkRecordAdds metadata for the given column in the file.- Specified by:
addColumnMetadatain interfaceISQLServerBulkRecord- Parameters:
positionInSource- Indicates which column the metadata is for. Columns start at 1.name- Name for the column (optional if only using column ordinal in a mapping for SQLServerBulkCopy operation)jdbcType- JDBC data type of the columnprecision- Precision for the column (ignored for the appropriate data types)scale- Scale for the column (ignored for the appropriate data types)dateTimeFormatter- format to parse data that is sent- Throws:
SQLServerException- when an error occurs
-
addColumnMetadata
public void addColumnMetadata(int positionInSource, java.lang.String name, int jdbcType, int precision, int scale) throws SQLServerExceptionDescription copied from interface:ISQLServerBulkRecordAdds metadata for the given column in the file.- Specified by:
addColumnMetadatain interfaceISQLServerBulkRecord- Parameters:
positionInSource- Indicates which column the metadata is for. Columns start at 1.name- Name for the column (optional if only using column ordinal in a mapping for SQLServerBulkCopy operation)jdbcType- JDBC data type of the columnprecision- Precision for the column (ignored for the appropriate data types)scale- Scale for the column (ignored for the appropriate data types)- Throws:
SQLServerException- when an error occurs
-
setTimestampWithTimezoneFormat
public void setTimestampWithTimezoneFormat(java.lang.String dateTimeFormat)Description copied from interface:ISQLServerBulkRecordSets the format for reading in dates from the file.- Specified by:
setTimestampWithTimezoneFormatin interfaceISQLServerBulkRecord- Parameters:
dateTimeFormat- format to parse data sent as java.sql.Types.TIMESTAMP_WITH_TIMEZONE
-
setTimestampWithTimezoneFormat
public void setTimestampWithTimezoneFormat(java.time.format.DateTimeFormatter dateTimeFormatter)Description copied from interface:ISQLServerBulkRecordSets the format for reading in dates from the file.- Specified by:
setTimestampWithTimezoneFormatin interfaceISQLServerBulkRecord- Parameters:
dateTimeFormatter- format to parse data sent as java.sql.Types.TIMESTAMP_WITH_TIMEZONE
-
setTimeWithTimezoneFormat
public void setTimeWithTimezoneFormat(java.lang.String timeFormat)Description copied from interface:ISQLServerBulkRecordSets the format for reading in dates from the file.- Specified by:
setTimeWithTimezoneFormatin interfaceISQLServerBulkRecord- Parameters:
timeFormat- format to parse data sent as java.sql.Types.TIME_WITH_TIMEZONE
-
setTimeWithTimezoneFormat
public void setTimeWithTimezoneFormat(java.time.format.DateTimeFormatter dateTimeFormatter)Description copied from interface:ISQLServerBulkRecordSets the format for reading in dates from the file.- Specified by:
setTimeWithTimezoneFormatin interfaceISQLServerBulkRecord- Parameters:
dateTimeFormatter- format to parse data sent as java.sql.Types.TIME_WITH_TIMEZONE
-
throwInvalidArgument
- Throws:
SQLServerException
-
checkDuplicateColumnName
protected void checkDuplicateColumnName(int positionInTable, java.lang.String colName) throws SQLServerException- Throws:
SQLServerException
-
getColumnDateTimeFormatter
public java.time.format.DateTimeFormatter getColumnDateTimeFormatter(int column)Description copied from interface:ISQLServerBulkRecordReturns thedateTimeFormatterfor the given column.- Specified by:
getColumnDateTimeFormatterin interfaceISQLServerBulkRecord- Parameters:
column- Column ordinal- Returns:
- dateTimeFormatter
-
getColumnOrdinals
public java.util.Set<java.lang.Integer> getColumnOrdinals()Description copied from interface:ISQLServerBulkDataReturns the ordinals for each of the columns represented in this data record.- Specified by:
getColumnOrdinalsin interfaceISQLServerBulkData- Returns:
- Set of ordinals for the columns.
-
getColumnName
public java.lang.String getColumnName(int column)Description copied from interface:ISQLServerBulkDataReturns the name of the given column.- Specified by:
getColumnNamein interfaceISQLServerBulkData- Parameters:
column- Column ordinal- Returns:
- Name of the column
-
getColumnType
public int getColumnType(int column)Description copied from interface:ISQLServerBulkDataReturns the JDBC data type of the given column.- Specified by:
getColumnTypein interfaceISQLServerBulkData- Parameters:
column- Column ordinal- Returns:
- JDBC data type of the column
-
getPrecision
public int getPrecision(int column)Description copied from interface:ISQLServerBulkDataReturns the precision for the given column.- Specified by:
getPrecisionin interfaceISQLServerBulkData- Parameters:
column- Column ordinal- Returns:
- Precision of the column
-
getScale
public int getScale(int column)Description copied from interface:ISQLServerBulkDataReturns the scale for the given column.- Specified by:
getScalein interfaceISQLServerBulkData- Parameters:
column- Column ordinal- Returns:
- Scale of the column
-
isAutoIncrement
public boolean isAutoIncrement(int column)Description copied from interface:ISQLServerBulkRecordReturns whether the column represents an identity column.- Specified by:
isAutoIncrementin interfaceISQLServerBulkRecord- Parameters:
column- Column ordinal- Returns:
- True if the column is an identity column; false otherwise.
-