Search in sources :

Example 36 with Column

use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.

the class DfSPolicyCrossSecretary method getSameNameColumnListMap.

protected Map<String, List<Column>> getSameNameColumnListMap(Database database) {
    if (_sameNameColumnListMap != null) {
        return _sameNameColumnListMap;
    }
    // flexible map because column name is treated as flexible in DBFlute (so MEMBER_NAME and MemberName are same-name)
    final Map<String, List<Column>> sameNameColumnListMap = StringKeyMap.createAsFlexible();
    final List<Table> targetTableList = database.getTableList().stream().filter(tbl -> isTargetTable(tbl)).collect(Collectors.toList());
    for (Table myTable : targetTableList) {
        final List<Column> columnList = myTable.getColumnList();
        for (Column myColumn : columnList) {
            if (!isTargetColumn(myColumn)) {
                // non-target
                continue;
            }
            final String myName = myColumn.getName();
            if (sameNameColumnListMap.containsKey(myName)) {
                // registered by the other same-name column
                continue;
            }
            for (Table yourTable : targetTableList) {
                final Column yourColumn = yourTable.getColumn(myName);
                if (yourColumn != null) {
                    if (!isTargetColumn(yourColumn)) {
                        // non-target
                        continue;
                    }
                    List<Column> sameColumnList = sameNameColumnListMap.get(myName);
                    if (sameColumnList == null) {
                        sameColumnList = new ArrayList<Column>();
                        sameColumnList.add(myColumn);
                        sameNameColumnListMap.put(myName, sameColumnList);
                    }
                    sameColumnList.add(yourColumn);
                }
            }
        }
    }
    _sameNameColumnListMap = sameNameColumnListMap;
    return _sameNameColumnListMap;
}
Also used : Column(org.apache.torque.engine.database.model.Column) DfCollectionUtil(org.dbflute.util.DfCollectionUtil) Predicate(java.util.function.Predicate) DfBuildProperties(org.dbflute.DfBuildProperties) DfBasicProperties(org.dbflute.properties.DfBasicProperties) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) Database(org.apache.torque.engine.database.model.Database) List(java.util.List) Table(org.apache.torque.engine.database.model.Table) Map(java.util.Map) StringKeyMap(org.dbflute.helper.StringKeyMap) Table(org.apache.torque.engine.database.model.Table) Column(org.apache.torque.engine.database.model.Column) ArrayList(java.util.ArrayList) List(java.util.List)

Example 37 with Column

use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.

the class DfLReverseOutputHandler method setupXlsDataTable.

// ===================================================================================
// Xls Data
// ========
protected void setupXlsDataTable(DfDataSet dataSet, Table table, List<Map<String, String>> extractedList, int sheetNumber, List<String> sectionInfoList) {
    final List<Map<String, String>> recordList;
    {
        final String tableInfo = "  " + table.getTableDispName() + " (" + extractedList.size() + ")";
        _log.info(tableInfo);
        sectionInfoList.add(tableInfo);
        if (extractedList.size() > _xlsLimit) {
            // just in case
            recordList = extractedList.subList(0, _xlsLimit);
        } else {
            recordList = extractedList;
        }
    }
    final DfDataTable dataTable = new DfDataTable(resolveSheetName(table, sheetNumber));
    final List<Column> columnList = table.getColumnList();
    for (Column column : columnList) {
        if (isExceptCommonColumn(column)) {
            continue;
        }
        dataTable.addColumn(column.getName(), DfDtsColumnTypes.STRING);
    }
    for (Map<String, String> recordMap : recordList) {
        final Set<String> columnNameSet = recordMap.keySet();
        final DfDataRow dataRow = dataTable.addRow();
        for (String columnName : columnNameSet) {
            if (!dataTable.hasColumn(columnName)) {
                // basically excepted common columns
                continue;
            }
            final String value = recordMap.get(columnName);
            dataRow.addValue(columnName, value);
        }
    }
    dataSet.addTable(dataTable);
}
Also used : Column(org.apache.torque.engine.database.model.Column) DfDataTable(org.dbflute.helper.dataset.DfDataTable) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) DfDataRow(org.dbflute.helper.dataset.DfDataRow)

Example 38 with Column

use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.

the class DfColumnListToStringBuilder method getColumnArgsSetupString.

public static String getColumnArgsSetupString(String beanName, List<Column> columnList) {
    validateColumnList(columnList);
    final boolean hasPrefix = beanName != null;
    final String beanPrefix = (hasPrefix ? beanName + "." : "");
    final DfLanguageDependency lang = getBasicProperties().getLanguageDependency();
    final DfLanguageImplStyle implStyle = lang.getLanguageImplStyle();
    String result = "";
    for (Iterator<Column> ite = columnList.iterator(); ite.hasNext(); ) {
        final Column column = (Column) ite.next();
        final String javaName = column.getJavaName();
        final String variable = column.getUncapitalisedJavaName();
        final String cls = column.getClassificationName();
        final String basic;
        if (column.isForceClassificationSetting()) {
            basic = "set" + javaName + "As" + cls + "(" + variable + ")";
        } else {
            basic = "set" + javaName + "(" + variable + ")";
        }
        final String adjusted = implStyle.adjustEntitySetMethodCall(basic, !hasPrefix);
        final String setter = beanPrefix + adjusted + ";";
        if ("".equals(result)) {
            result = setter;
        } else {
            result = result + setter;
        }
    }
    return result;
}
Also used : Column(org.apache.torque.engine.database.model.Column) DfLanguageDependency(org.dbflute.logic.generate.language.DfLanguageDependency) DfLanguageImplStyle(org.dbflute.logic.generate.language.implstyle.DfLanguageImplStyle)

Example 39 with Column

use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.

the class DfColumnListToStringBuilder method getColumnArgsSetupStringCSharp.

public static String getColumnArgsSetupStringCSharp(String beanName, List<Column> columnList) {
    validateColumnList(columnList);
    final String beanPrefix = (beanName != null ? beanName + "." : "");
    String result = "";
    for (Iterator<Column> ite = columnList.iterator(); ite.hasNext(); ) {
        final Column column = (Column) ite.next();
        final String javaName = column.getJavaName();
        final String variable = column.getUncapitalisedJavaName();
        final String setter = beanPrefix + javaName + " = " + variable + ";";
        if ("".equals(result)) {
            result = setter;
        } else {
            result = result + setter;
        }
    }
    return result;
}
Also used : Column(org.apache.torque.engine.database.model.Column)

Example 40 with Column

use of org.apache.torque.engine.database.model.Column in project dbflute-core by dbflute.

the class DfColumnListToStringBuilder method getColumnNameCommaString.

public static String getColumnNameCommaString(List<Column> columnList) {
    validateColumnList(columnList);
    String result = "";
    for (Column column : columnList) {
        final String name = column.getName();
        if ("".equals(result)) {
            result = name;
        } else {
            result = result + ", " + name;
        }
    }
    return result;
}
Also used : Column(org.apache.torque.engine.database.model.Column)

Aggregations

Column (org.apache.torque.engine.database.model.Column)50 Table (org.apache.torque.engine.database.model.Table)16 List (java.util.List)10 Map (java.util.Map)8 ForeignKey (org.apache.torque.engine.database.model.ForeignKey)8 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)6 Database (org.apache.torque.engine.database.model.Database)5 DfBuildProperties (org.dbflute.DfBuildProperties)4 DfDataRow (org.dbflute.helper.dataset.DfDataRow)4 DfDataTable (org.dbflute.helper.dataset.DfDataTable)4 ExceptionMessageBuilder (org.dbflute.helper.message.ExceptionMessageBuilder)4 DfLanguageDependency (org.dbflute.logic.generate.language.DfLanguageDependency)4 Function (java.util.function.Function)3 File (java.io.File)2 IOException (java.io.IOException)2 SQLException (java.sql.SQLException)2 Entry (java.util.Map.Entry)2 Set (java.util.Set)2 Predicate (java.util.function.Predicate)2