use of org.dbflute.logic.doc.lreverse.DfLReverseOutputResource 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.logic.doc.lreverse.DfLReverseOutputResource in project dbflute-core by dbflute.
the class DfLReverseFileOrder method toOverrideReverseOrderedMap.
// -----------------------------------------------------
// Override Reverse
// ----------------
protected Map<File, DfLReverseOutputResource> toOverrideReverseOrderedMap(List<List<Table>> orderedList, File baseDir) {
final DfLReverseExistingXlsInfo existingXlsInfo = extractExistingXlsInfo(baseDir);
final Map<File, DfLReverseOutputResource> orderedMap = createOrderedMap();
final String dataDirPath = resolvePath(baseDir);
final Map<String, String> tableNameMap = _tableNameProp.findTableNameMap(dataDirPath);
final Map<String, File> translatedXlsMap = prepareTranslatedXlsMap(existingXlsInfo, tableNameMap);
final List<Table> addedTableList = DfCollectionUtil.newArrayList();
int sectionNo = 1;
for (List<Table> nestedList : orderedList) {
for (Table table : nestedList) {
final File existingXls = translatedXlsMap.get(table.getTableDbName());
if (existingXls == null) {
addedTableList.add(table);
continue;
}
DfLReverseOutputResource resource = orderedMap.get(existingXls);
if (resource == null) {
final String mainName = extractMainName(nestedList);
final List<Table> initialList = new ArrayList<Table>();
resource = createOutputResource(existingXls, initialList, sectionNo, mainName);
orderedMap.put(existingXls, resource);
++sectionNo;
}
resource.addTable(table);
}
}
registerAddedTableIfExists(orderedMap, addedTableList, sectionNo);
orderTableByExistingOrder(orderedMap, existingXlsInfo);
return orderedMap;
}
use of org.dbflute.logic.doc.lreverse.DfLReverseOutputResource in project dbflute-core by dbflute.
the class DfLReverseFileOrder method toReplaceReverseOrderedMap.
// -----------------------------------------------------
// Replace Reverse
// ---------------
protected Map<File, DfLReverseOutputResource> toReplaceReverseOrderedMap(List<List<Table>> orderedList) {
final Map<File, DfLReverseOutputResource> orderedMap = DfCollectionUtil.newLinkedHashMap();
int sectionNo = 1;
for (List<Table> nestedList : orderedList) {
final String number = (sectionNo < 10 ? "0" + sectionNo : String.valueOf(sectionNo));
final String mainName = extractMainName(nestedList);
final File xlsFile = new File(buildXlsFilePath(number, mainName));
orderedMap.put(xlsFile, createOutputResource(xlsFile, nestedList, sectionNo, mainName));
++sectionNo;
}
return orderedMap;
}
use of org.dbflute.logic.doc.lreverse.DfLReverseOutputResource in project dbflute-core by dbflute.
the class DfLReverseFileOrder method orderTableByExistingOrder.
protected void orderTableByExistingOrder(Map<File, DfLReverseOutputResource> orderedMap, DfLReverseExistingXlsInfo existingXlsInfo) {
final Map<File, List<String>> existingXlsTableListMap = existingXlsInfo.getExistingXlsTableListMap();
for (Entry<File, DfLReverseOutputResource> entry : orderedMap.entrySet()) {
final File existingXls = entry.getKey();
final List<String> tableNameList = existingXlsTableListMap.get(existingXls);
if (tableNameList != null) {
final DfLReverseOutputResource resource = entry.getValue();
resource.acceptTableOrder(tableNameList);
}
}
}
use of org.dbflute.logic.doc.lreverse.DfLReverseOutputResource in project dbflute-core by dbflute.
the class DfLReverseTableData method reverseTableData.
// ===================================================================================
// Reverse Table
// =============
public void reverseTableData(Map<File, DfLReverseOutputResource> orderedMap, File baseDir, List<String> sectionInfoList) {
deletePreviousDataFile(baseDir);
final Integer limit = getRecordLimit();
for (Entry<File, DfLReverseOutputResource> entry : orderedMap.entrySet()) {
final File xlsFile = entry.getKey();
final DfLReverseOutputResource resource = entry.getValue();
final List<Table> tableList = resource.getTableList();
final Map<String, Table> tableInfoMap = DfCollectionUtil.newLinkedHashMap();
for (Table table : tableList) {
tableInfoMap.put(table.getTableDbName(), table);
}
final String sectionTitle = "[" + xlsFile.getName() + "]: tables=" + tableList.size();
_log.info("");
_log.info(sectionTitle);
sectionInfoList.add("");
sectionInfoList.add(sectionTitle);
_outputHandler.outputData(tableInfoMap, limit, xlsFile, resource, sectionInfoList);
}
}
Aggregations