Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Cleaning up liquibase.util tests and code
- Upgraded opencsv and moved it to an external but shaded dependency
- Loading branch information
Showing
22 changed files
with
168 additions
and
2,523 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
32 changes: 23 additions & 9 deletions
32
liquibase-core/src/main/java/liquibase/util/csv/CSVReader.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,41 @@ | ||
package liquibase.util.csv; | ||
|
||
import com.opencsv.CSVReaderBuilder; | ||
import com.opencsv.RFC4180ParserBuilder; | ||
import com.opencsv.exceptions.CsvValidationException; | ||
|
||
import java.io.IOException; | ||
import java.io.Reader; | ||
|
||
public class CSVReader extends liquibase.util.csv.opencsv.CSVReader { | ||
public class CSVReader implements AutoCloseable { | ||
|
||
private final com.opencsv.CSVReader delegate; | ||
|
||
public static final char DEFAULT_SEPARATOR = ','; | ||
|
||
public static final char DEFAULT_QUOTE_CHARACTER = '"'; | ||
|
||
|
||
public CSVReader(Reader reader) { | ||
super(reader); | ||
this(reader, DEFAULT_SEPARATOR, DEFAULT_QUOTE_CHARACTER); | ||
} | ||
|
||
public CSVReader(Reader reader, char c) { | ||
super(reader, c); | ||
|
||
public CSVReader(Reader reader, char separator, char quotchar) { | ||
delegate = new CSVReaderBuilder(reader).withCSVParser( | ||
new RFC4180ParserBuilder().withSeparator(separator).withQuoteChar(quotchar).build() | ||
).build(); | ||
} | ||
|
||
public CSVReader(Reader reader, char c, char c1) { | ||
super(reader, c, c1); | ||
@Override | ||
public void close() throws Exception { | ||
delegate.close(); | ||
} | ||
|
||
public CSVReader(Reader reader, char c, char c1, int i) { | ||
super(reader, c, c1, i); | ||
public String[] readNext() throws IOException { | ||
try { | ||
return delegate.readNext(); | ||
} catch (CsvValidationException e) { | ||
throw new IOException(e.getMessage(), e); | ||
} | ||
} | ||
} |
153 changes: 13 additions & 140 deletions
153
liquibase-core/src/main/java/liquibase/util/csv/CSVWriter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,159 +1,32 @@ | ||
package liquibase.util.csv; | ||
|
||
import com.opencsv.CSVWriterBuilder; | ||
import com.opencsv.ICSVWriter; | ||
import liquibase.util.ISODateFormat; | ||
|
||
import java.io.Flushable; | ||
import java.io.IOException; | ||
import java.io.Writer; | ||
import java.sql.ResultSet; | ||
import java.sql.SQLException; | ||
|
||
public class CSVWriter extends liquibase.util.csv.opencsv.CSVWriter { | ||
private static final ISODateFormat ISO_DATE_FORMAT = new ISODateFormat(); | ||
public class CSVWriter implements AutoCloseable, Flushable { | ||
private final ICSVWriter delegate; | ||
|
||
public CSVWriter(Writer writer) { | ||
super(writer); | ||
delegate = new CSVWriterBuilder(writer).build(); | ||
} | ||
|
||
public CSVWriter(Writer writer, char c) { | ||
super(writer, c); | ||
@Override | ||
public void close() throws Exception { | ||
delegate.close(); | ||
} | ||
|
||
public CSVWriter(Writer writer, char c, char c1) { | ||
super(writer, c, c1); | ||
public void writeNext(String[] nextLine) { | ||
delegate.writeNext(nextLine); | ||
} | ||
|
||
public CSVWriter(Writer writer, char c, char c1, char c2) { | ||
super(writer, c, c1, c2); | ||
public void flush() throws IOException { | ||
delegate.flush(); | ||
} | ||
|
||
public CSVWriter(Writer writer, char c, char c1, String s) { | ||
super(writer, c, c1, s); | ||
} | ||
|
||
public CSVWriter(Writer writer, char c, char c1, char c2, String s) { | ||
super(writer, c, c1, c2, s); | ||
} | ||
|
||
|
||
private String getColumnValue(ResultSet rs, int colType, int colIndex) throws SQLException, IOException { | ||
|
||
Object value = rs.getObject(colIndex); | ||
if (rs.wasNull()) { | ||
return "NULL"; | ||
} | ||
|
||
if (value instanceof java.sql.Date) { | ||
return ISO_DATE_FORMAT.format((java.sql.Date) value); | ||
} else if (value instanceof java.sql.Time) { | ||
return ISO_DATE_FORMAT.format((java.sql.Time) value); | ||
} else if (value instanceof java.sql.Timestamp) { | ||
return ISO_DATE_FORMAT.format((java.sql.Timestamp) value); | ||
// } else if (value instanceof oracle.sql.TIMESTAMP) { | ||
// return ISO_DATE_FORMAT.format((oracle.sql.TIMESTAMP) value); | ||
} else { | ||
return value.toString(); | ||
} | ||
|
||
// if (colType == Types.BIT) { | ||
// Object bit = rs.getObject(colIndex); | ||
// if (rs.wasNull()) { | ||
// return null; | ||
// } else { | ||
// return String.valueOf(bit); | ||
// } | ||
// } else if (colType == Types.BOOLEAN) { | ||
// boolean b = rs.getBoolean(colIndex); | ||
// if (rs.wasNull()) { | ||
// return null; | ||
// } else { | ||
// return Boolean.valueOf(b).toString(); | ||
// } | ||
// } else if (colType == Types.CLOB) { | ||
// Clob c = rs.getClob(colIndex); | ||
// if (rs.wasNull()) { | ||
// return null; | ||
// } else { | ||
// return read(c); | ||
// } | ||
// } else if (colType == Types.BIGINT | ||
// || colType == Types.DECIMAL | ||
// || colType == Types.DOUBLE | ||
// || colType == Types.FLOAT | ||
// || colType == Types.REAL | ||
// || colType == Types.NUMERIC) { | ||
// BigDecimal bd = rs.getBigDecimal(colIndex); | ||
// if (rs.wasNull()) { | ||
// return null; | ||
// } else { | ||
// return String.valueOf(bd.doubleValue()); | ||
// } | ||
// | ||
// } else if (colType == Types.INTEGER | ||
// || colType == Types.TINYINT | ||
// || colType == Types.SMALLINT) { | ||
// int intValue = rs.getInt(colIndex); | ||
// if (rs.wasNull()) { | ||
// return null; | ||
// } else { | ||
// return String.valueOf(intValue); | ||
// } | ||
// } | ||
// | ||
// case Types.JAVA_OBJECT: | ||
// Object obj = rs.getObject(colIndex); | ||
// if (obj != null) { | ||
// value = String.valueOf(obj); | ||
// } | ||
// break; | ||
// case Types.DATE: | ||
// java.sql.Date date = rs.getDate(colIndex); | ||
// if (date != null) { | ||
// value = ISO_DATE_FORMAT.format(date); | ||
// ; | ||
// } | ||
// break; | ||
// case Types.TIME: | ||
// Time t = rs.getTime(colIndex); | ||
// if (t != null) { | ||
// value = t.toString(); | ||
// } | ||
// break; | ||
// case Types.TIMESTAMP: | ||
// Timestamp tstamp = rs.getTimestamp(colIndex); | ||
// if (tstamp != null) { | ||
// value = ISO_DATE_FORMAT.format(tstamp); | ||
// } | ||
// break; | ||
// case Types.LONGVARCHAR: | ||
// case Types.VARCHAR: | ||
// case Types.CHAR: | ||
// value = rs.getString(colIndex); | ||
// break; | ||
// default: | ||
// value = ""; | ||
// } | ||
|
||
// if (value == null) | ||
// | ||
// { | ||
// value = ""; | ||
// } | ||
// | ||
// return value; | ||
|
||
} | ||
|
||
// private static String read(Clob c) throws SQLException, IOException { | ||
// StringBuffer sb = new StringBuffer((int) c.length()); | ||
// Reader r = c.getCharacterStream(); | ||
// char[] cbuf = new char[2048]; | ||
// int n = 0; | ||
// while ((n = r.read(cbuf, 0, cbuf.length)) != -1) { | ||
// if (n > 0) { | ||
// sb.append(cbuf, 0, n); | ||
// } | ||
// } | ||
// return sb.toString(); | ||
// } | ||
|
||
} |
58 changes: 0 additions & 58 deletions
58
liquibase-core/src/main/java/liquibase/util/csv/opencsv/CSVIterator.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.