use of org.dbflute.helper.token.file.FileMakingCallback in project dbflute-core by dbflute.
the class DfLReverseOutputHandler method outputDelimiterData.
// ===================================================================================
// Delimiter Data
// ==============
protected void outputDelimiterData(final Table table, DfLReverseDataResult templateDataResult, final int limit, DfLReverseOutputResource resource, int sheetNumber, List<String> sectionInfoList) {
if (_delimiterDataDir == null) {
return;
}
final File delimiterDir = new File(_delimiterDataDir);
// fixed
final String ext = "tsv";
if (!delimiterDir.exists()) {
delimiterDir.mkdirs();
}
final FileToken fileToken = new FileToken();
// file name uses DB name (no display name) just in case
final String delimiterFilePath = buildDelimiterFilePath(table, resource, sheetNumber, delimiterDir, ext);
final List<String> columnNameList = new ArrayList<String>();
for (Column column : table.getColumnList()) {
if (!_containsCommonColumn && column.isCommonColumn()) {
continue;
}
columnNameList.add(column.getName());
}
final DfJFadCursorCallback cursorCallback = templateDataResult.getCursorCallback();
cursorCallback.select(new DfJFadCursorHandler() {
int count = 0;
public void handle(final DfJFadResultSetWrapper wrapper) {
try {
fileToken.make(delimiterFilePath, new FileMakingCallback() {
public void write(FileMakingRowWriter writer) throws IOException, SQLException {
while (wrapper.next()) {
if (limit >= 0 && limit < count) {
break;
}
final List<String> valueList = new ArrayList<String>();
for (String columnName : columnNameList) {
valueList.add(wrapper.getString(columnName));
}
writer.writeRow(valueList);
++count;
}
}
}, op -> op.encodeAsUTF8().separateByLf().delimitateByTab().headerInfo(columnNameList));
} catch (IOException e) {
handleDelimiterDataFailureException(table, delimiterFilePath, e);
}
final String delimiterInfo = " " + delimiterFilePath + " (" + count + ")";
_log.info(delimiterInfo);
sectionInfoList.add(delimiterInfo);
}
});
}
use of org.dbflute.helper.token.file.FileMakingCallback in project dbflute-core by dbflute.
the class DfLReverseOutputHandler method outputDelimiterData.
// ===================================================================================
// Delimiter Data
// ==============
protected void outputDelimiterData(final Table table, DfLReverseDataResult templateDataResult, final int limit, DfLReverseOutputResource resource, int sheetNumber, List<String> sectionInfoList) {
if (_delimiterDataDir == null) {
return;
}
final File delimiterDir = new File(_delimiterDataDir);
// fixed
final String ext = "tsv";
final String outputInfo = "...Outputting the over-xls-limit table: " + table.getTableDispName();
_log.info(outputInfo);
sectionInfoList.add(outputInfo);
if (!delimiterDir.exists()) {
delimiterDir.mkdirs();
}
final FileToken fileToken = new FileToken();
// file name uses DB name (no display name) just in case
final String delimiterFilePath = buildDelimiterFilePath(table, resource, sheetNumber, delimiterDir, ext);
final List<String> columnNameList = new ArrayList<String>();
for (Column column : table.getColumnList()) {
if (!_containsCommonColumn && column.isCommonColumn()) {
continue;
}
columnNameList.add(column.getName());
}
final DfJFadCursorCallback cursorCallback = templateDataResult.getCursorCallback();
cursorCallback.select(new DfJFadCursorHandler() {
int count = 0;
public void handle(final DfJFadResultSetWrapper wrapper) {
try {
fileToken.make(delimiterFilePath, new FileMakingCallback() {
public void write(FileMakingRowWriter writer) throws IOException, SQLException {
while (wrapper.next()) {
if (limit >= 0 && limit < count) {
break;
}
final List<String> valueList = new ArrayList<String>();
for (String columnName : columnNameList) {
valueList.add(wrapper.getString(columnName));
}
writer.writeRow(valueList);
++count;
}
}
}, op -> op.encodeAsUTF8().separateByLf().delimitateByTab().headerInfo(columnNameList));
} catch (IOException e) {
handleDelimiterDataFailureException(table, delimiterFilePath, e);
}
final String delimiterInfo = " -> " + delimiterFilePath + " (" + count + ")";
_log.info(delimiterInfo);
sectionInfoList.add(delimiterInfo);
}
});
}
Aggregations