1 /* 2 * Copyright 2007 Kasper B. Graversen 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package org.supercsv.io; 18 19 import java.io.IOException; 20 import java.sql.ResultSet; 21 import java.sql.SQLException; 22 23 import org.supercsv.cellprocessor.ift.CellProcessor; 24 import org.supercsv.exception.SuperCsvConstraintViolationException; 25 import org.supercsv.exception.SuperCsvException; 26 27 /** 28 * Interface for CSV writers writing JDBC {@code ResultSet} 29 * 30 * @author SingularityFX 31 * @since 2.4.0 32 */ 33 public interface ICsvResultSetWriter extends ICsvWriter { 34 35 /** 36 * Writes a JDBC {@code ResultSet} as a CSV file. Each column in CSV file corresponds to a column in 37 * {@code ResultSet}, column order is preserved. Column names in CSV file corresponds to column names stored in 38 * {@code ResultSetMetaData}. {@code toString} will be called on each element prior to writing. 39 * 40 * @param resultSet 41 * ResultSet containing the values to write 42 * @throws SQLException 43 * if a database access error occurs or this method is called on a closed result set 44 * @throws IOException 45 * if an I/O error occurred 46 * @throws NullPointerException 47 * if resultSet is null 48 * @throws SuperCsvException 49 * if there was a general exception while writing 50 * @since 2.4.0 51 */ 52 void write(ResultSet resultSet) throws SQLException, IOException; 53 54 /** 55 * Writes a JDBC {@code ResultSet} as a CSV file. Each column in CSV file corresponds to a column in 56 * {@code ResultSet}, column order is preserved. Column names in CSV file corresponds to column names stored in 57 * {@code ResultSetMetaData}. {@code toString} will be called on each (processed) element prior to writing. 58 * 59 * @param resultSet 60 * ResultSet containing the values to write 61 * @param cellProcessors 62 * Array of CellProcessors used to further process data before it is written (each element in the 63 * processors array corresponds with a CSV column - the number of processors should match the number of 64 * columns). A {@code null} entry indicates no further processing is required (the value returned by 65 * toString() will be written as the column value). 66 * @throws SQLException 67 * if a database access error occurs or this method is called on a closed result set 68 * @throws IOException 69 * if an I/O error occurred 70 * @throws NullPointerException 71 * if resultSet or cellProcessors is null 72 * @throws SuperCsvConstraintViolationException 73 * if a CellProcessor constraint failed 74 * @throws SuperCsvException 75 * if there was a general exception while writing/processing 76 * @since 2.4.0 77 */ 78 void write(ResultSet resultSet, CellProcessor[] cellProcessors) throws SQLException, IOException; 79 }