Search in sources :

Example 1 with DfLReverseOutputResource

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);
        }
    });
}
Also used : DfJFadCursorHandler(org.dbflute.helper.jdbc.facade.DfJFadCursorHandler) Column(org.apache.torque.engine.database.model.Column) DfTableXlsWriter(org.dbflute.helper.io.xls.DfTableXlsWriter) LoggerFactory(org.slf4j.LoggerFactory) DfJFadResultSetWrapper(org.dbflute.helper.jdbc.facade.DfJFadResultSetWrapper) ArrayList(java.util.ArrayList) LinkedHashMap(java.util.LinkedHashMap) SQLException(java.sql.SQLException) Table(org.apache.torque.engine.database.model.Table) Map(java.util.Map) DfLittleAdjustmentProperties(org.dbflute.properties.DfLittleAdjustmentProperties) DataSource(javax.sql.DataSource) DfDataTable(org.dbflute.helper.dataset.DfDataTable) DfDataSet(org.dbflute.helper.dataset.DfDataSet) FileMakingRowWriter(org.dbflute.helper.token.file.FileMakingRowWriter) Logger(org.slf4j.Logger) DfJFadCursorCallback(org.dbflute.helper.jdbc.facade.DfJFadCursorCallback) FileToken(org.dbflute.helper.token.file.FileToken) FileMakingCallback(org.dbflute.helper.token.file.FileMakingCallback) Set(java.util.Set) DfLReverseOutputResource(org.dbflute.logic.doc.lreverse.DfLReverseOutputResource) IOException(java.io.IOException) DfBuildProperties(org.dbflute.DfBuildProperties) File(java.io.File) DfDtsColumnTypes(org.dbflute.helper.dataset.types.DfDtsColumnTypes) List(java.util.List) Entry(java.util.Map.Entry) DfDataRow(org.dbflute.helper.dataset.DfDataRow) DfAdditionalTableProperties(org.dbflute.properties.DfAdditionalTableProperties) ArrayList(java.util.ArrayList) IOException(java.io.IOException) FileMakingCallback(org.dbflute.helper.token.file.FileMakingCallback) DfJFadResultSetWrapper(org.dbflute.helper.jdbc.facade.DfJFadResultSetWrapper) Column(org.apache.torque.engine.database.model.Column) DfJFadCursorHandler(org.dbflute.helper.jdbc.facade.DfJFadCursorHandler) FileMakingRowWriter(org.dbflute.helper.token.file.FileMakingRowWriter) DfJFadCursorCallback(org.dbflute.helper.jdbc.facade.DfJFadCursorCallback) File(java.io.File) FileToken(org.dbflute.helper.token.file.FileToken)

Example 2 with DfLReverseOutputResource

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;
}
Also used : DfLReverseOutputResource(org.dbflute.logic.doc.lreverse.DfLReverseOutputResource) Table(org.apache.torque.engine.database.model.Table) DfLReverseExistingXlsInfo(org.dbflute.logic.doc.lreverse.existing.DfLReverseExistingXlsInfo) ArrayList(java.util.ArrayList) File(java.io.File)

Example 3 with DfLReverseOutputResource

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;
}
Also used : DfLReverseOutputResource(org.dbflute.logic.doc.lreverse.DfLReverseOutputResource) Table(org.apache.torque.engine.database.model.Table) File(java.io.File)

Example 4 with DfLReverseOutputResource

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);
        }
    }
}
Also used : DfLReverseOutputResource(org.dbflute.logic.doc.lreverse.DfLReverseOutputResource) ArrayList(java.util.ArrayList) List(java.util.List) File(java.io.File)

Example 5 with DfLReverseOutputResource

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);
    }
}
Also used : DfLReverseOutputResource(org.dbflute.logic.doc.lreverse.DfLReverseOutputResource) Table(org.apache.torque.engine.database.model.Table) File(java.io.File)

Aggregations

File (java.io.File)5 DfLReverseOutputResource (org.dbflute.logic.doc.lreverse.DfLReverseOutputResource)5 Table (org.apache.torque.engine.database.model.Table)4 ArrayList (java.util.ArrayList)3 List (java.util.List)2 IOException (java.io.IOException)1 SQLException (java.sql.SQLException)1 LinkedHashMap (java.util.LinkedHashMap)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 Set (java.util.Set)1 DataSource (javax.sql.DataSource)1 Column (org.apache.torque.engine.database.model.Column)1 DfBuildProperties (org.dbflute.DfBuildProperties)1 DfDataRow (org.dbflute.helper.dataset.DfDataRow)1 DfDataSet (org.dbflute.helper.dataset.DfDataSet)1 DfDataTable (org.dbflute.helper.dataset.DfDataTable)1 DfDtsColumnTypes (org.dbflute.helper.dataset.types.DfDtsColumnTypes)1 DfTableXlsWriter (org.dbflute.helper.io.xls.DfTableXlsWriter)1 DfJFadCursorCallback (org.dbflute.helper.jdbc.facade.DfJFadCursorCallback)1