Search in sources :

Example 21 with Table

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

the class DfLReverseOutputHandler method transferToXls.

/**
 * Transfer data to excel. (state-less)
 * @param tableMap The map of table. (NotNull)
 * @param loadDataMap The map of load data. (NotNull)
 * @param limit The limit of extracted record. (MinusAllowed: if minus, no limit)
 * @param xlsFile The file of XLS. (NotNull)
 * @param resource The resource information of output data. (NotNull)
 * @param sectionInfoList The list of section info. (NotNull)
 */
protected void transferToXls(Map<String, Table> tableMap, Map<String, DfLReverseDataResult> loadDataMap, int limit, File xlsFile, DfLReverseOutputResource resource, List<String> sectionInfoList) {
    final DfDataSet dataSet = new DfDataSet();
    int sheetNumber = 0;
    for (Entry<String, Table> entry : tableMap.entrySet()) {
        ++sheetNumber;
        final String tableDbName = entry.getKey();
        final Table table = entry.getValue();
        final DfLReverseDataResult dataResult = loadDataMap.get(tableDbName);
        if (dataResult.isLargeData()) {
            outputDelimiterData(table, dataResult, limit, resource, sheetNumber, sectionInfoList);
        } else {
            final List<Map<String, String>> extractedList = dataResult.getResultList();
            setupXlsDataTable(dataSet, table, extractedList, sheetNumber, sectionInfoList);
        }
    }
    if (dataSet.getTableSize() > 0) {
        writeXlsData(dataSet, xlsFile);
    }
}
Also used : Table(org.apache.torque.engine.database.model.Table) DfDataTable(org.dbflute.helper.dataset.DfDataTable) DfDataSet(org.dbflute.helper.dataset.DfDataSet) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map)

Example 22 with Table

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

the class DfOldClassHandler method setCustomizeTableList.

// ===================================================================================
// Accessor
// ========
public void setCustomizeTableList(List<Table> customizeTableList) {
    final Map<String, Map<String, Table>> cmentityLocationMap = new LinkedHashMap<String, Map<String, Table>>();
    for (Table table : customizeTableList) {
        final String outputDirectory = table.getSql2EntityOutputDirectory();
        Map<String, Table> elementMap = cmentityLocationMap.get(outputDirectory);
        if (elementMap == null) {
            elementMap = new LinkedHashMap<String, Table>();
            cmentityLocationMap.put(outputDirectory, elementMap);
        }
        elementMap.put(table.getTableDbName(), table);
    }
    if (cmentityLocationMap.isEmpty()) {
        // no outsideSql (all classes for outsideSql are old)
        // main directory only
        final String mainDir = getOutsideSqlProperties().getSql2EntityOutputDirectory();
        cmentityLocationMap.put(mainDir, new HashMap<String, Table>());
    }
    _cmentityLocationMap = cmentityLocationMap;
}
Also used : Table(org.apache.torque.engine.database.model.Table) HashMap(java.util.HashMap) LinkedHashMap(java.util.LinkedHashMap) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap)

Example 23 with Table

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

the class DfSPolicyLogicalSecretary method toColumnDisp.

public String toColumnDisp(Column column) {
    // e.g. (Sea.Sea Name)SEA.SEA_NAME VARCHAR(100) (NotNull)
    final Table table = column.getTable();
    final StringBuilder sb = new StringBuilder();
    if (table.hasAlias()) {
        sb.append("(");
        sb.append(table.getAlias());
        if (column.hasAlias()) {
            sb.append(".");
            sb.append(column.getAlias());
        }
        sb.append(")");
    }
    sb.append(table.getTableDispName());
    sb.append(".").append(column.getName());
    sb.append(" ").append(column.hasDbType() ? column.getDbType() : "(unknownType)");
    if (column.hasColumnSize()) {
        sb.append("(").append(column.getColumnSize()).append(")");
    }
    sb.append(" ").append(column.isNotNull() ? "(NotNull)" : "(NullAllowed)");
    if (column.hasComment()) {
        sb.append(" // ").append(Srl.cut(column.getComment(), 10, "..."));
    }
    return sb.toString();
}
Also used : Table(org.apache.torque.engine.database.model.Table)

Example 24 with Table

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

the class DfLReverseProcess method execute.

// ===================================================================================
// Execute
// =======
public void execute() {
    final Database database = prepareDatabase();
    final List<Table> tableList = filterTableList(database);
    final List<String> sectionInfoList = prepareTitleSection(tableList);
    final File baseDir = prepareBaseDir();
    final Map<File, DfLReverseOutputResource> orderedMap = prepareOrderedMap(tableList, baseDir);
    reverseTableData(orderedMap, baseDir, sectionInfoList);
    outputTableNameMap();
    synchronizeOriginDateIfNeeds(sectionInfoList);
    outputResultMark(sectionInfoList);
}
Also used : Table(org.apache.torque.engine.database.model.Table) Database(org.apache.torque.engine.database.model.Database) File(java.io.File)

Example 25 with Table

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

the class DfSPolicyTableStatementChecker method doEvaluateColumnThenItemValue.

protected String doEvaluateColumnThenItemValue(DfSPolicyStatement statement, DfSPolicyThenPart thenPart, Table table, Function<String, String> violationCall) {
    final String thenItem = thenPart.getThenItem();
    final String thenValue = thenPart.getThenValue();
    final boolean notThenValue = thenPart.isNotThenValue();
    if (thenItem.equalsIgnoreCase("tableName")) {
        // e.g. tableName is prefix:CLS_
        final String tableName = toComparingTableName(table);
        if (!isHitExp(statement, tableName, toTableNameComparingThenValue(table, thenValue)) == !notThenValue) {
            return violationCall.apply(tableName);
        }
    } else if (thenItem.equalsIgnoreCase("alias")) {
        // e.g. alias is suffix:History
        final String alias = table.getAlias();
        if (!isHitExp(statement, alias, toAliasComparingThenValue(table, thenValue)) == !notThenValue) {
            return violationCall.apply(alias);
        }
    } else if (thenItem.equalsIgnoreCase("comment")) {
        // e.g. comment is contain:SEA
        final String comment = table.getComment();
        if (!isHitExp(statement, comment, thenValue) == !notThenValue) {
            return violationCall.apply(comment);
        }
    } else if (thenItem.equalsIgnoreCase("pkName")) {
        // e.g. pkName is prefix:PK_
        if (table.hasPrimaryKey()) {
            final List<Column> columnList = table.getPrimaryKey();
            // same name if compound
            final Column pk = columnList.get(0);
            final String pkName = pk.getPrimaryKeyName();
            final String comparingThenValue = toConstraintNameComparingThenValue(table, thenValue, columnList);
            if (!isHitExp(statement, pkName, comparingThenValue) == !notThenValue) {
                final String disp = pkName + (pk.isAdditionalPrimaryKey() ? ADDITIONAL_SUFFIX : "");
                return violationCall.apply(disp);
            }
        }
    } else if (thenItem.equalsIgnoreCase("fkName")) {
        // e.g. fkName is prefix:FK_
        for (ForeignKey fk : table.getForeignKeyList()) {
            final String fkName = fk.getName();
            final String comparingThenValue = toConstraintNameComparingThenValue(table, thenValue, fk.getLocalColumnList());
            if (!isHitExp(statement, fkName, comparingThenValue) == !notThenValue) {
                final String disp = fkName + (fk.isAdditionalForeignKey() ? ADDITIONAL_SUFFIX : "");
                return violationCall.apply(disp);
            }
        }
    } else if (thenItem.equalsIgnoreCase("uniqueName")) {
        // e.g. uniqueName is prefix:UQ_
        for (Unique uq : table.getUniqueList()) {
            final String uqName = uq.getName();
            final String comparingThenValue = toConstraintNameComparingThenValue(table, thenValue, uq.getColumnList());
            if (!isHitExp(statement, uqName, comparingThenValue)) {
                final String disp = uqName + (uq.isAdditional() ? ADDITIONAL_SUFFIX : "");
                return violationCall.apply(disp);
            }
        }
    } else if (thenItem.equalsIgnoreCase("indexName")) {
        // e.g. indexName is prefix:IX_
        for (Index ix : table.getIndexList()) {
            final String ixName = ix.getName();
            final String comparingThenValue = toConstraintNameComparingThenValue(table, thenValue, ix.getColumnList());
            if (!isHitExp(statement, ixName, comparingThenValue) == !notThenValue) {
                return violationCall.apply(ixName);
            }
        }
    } else if (thenItem.equalsIgnoreCase("pk_columnName")) {
        return determinePkSomethingThenValue(statement, table, violationCall, thenValue, notThenValue, pk -> toComparingColumnName(pk));
    } else if (thenItem.equalsIgnoreCase("pk_dbType") || thenItem.equalsIgnoreCase("pkDbType")) {
        // for compatible
        return determinePkSomethingThenValue(statement, table, violationCall, thenValue, notThenValue, pk -> pk.getDbType());
    } else if (thenItem.equalsIgnoreCase("pk_size")) {
        return determinePkSomethingThenValue(statement, table, violationCall, thenValue, notThenValue, pk -> pk.getColumnSize());
    } else if (thenItem.equalsIgnoreCase("pk_dbType_with_size")) {
        // e.g. char(3)
        return determinePkSomethingThenValue(statement, table, violationCall, thenValue, notThenValue, pk -> toComparingDbTypeWithSize(pk));
    } else {
        throwSchemaPolicyCheckIllegalIfThenStatementException(statement, "Unknown then-item: " + thenItem);
    }
    // no violation
    return null;
}
Also used : DfSPolicyStatement(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement) DfSPolicyThenClause(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenClause) Column(org.apache.torque.engine.database.model.Column) DfSPolicyThenPart(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyThenPart) DfSPolicyIfPart(org.dbflute.logic.doc.spolicy.parsed.DfSPolicyStatement.DfSPolicyIfPart) DfSPolicyFirstDateSecretary(org.dbflute.logic.doc.spolicy.secretary.DfSPolicyFirstDateSecretary) DfSPolicyLogicalSecretary(org.dbflute.logic.doc.spolicy.secretary.DfSPolicyLogicalSecretary) Function(java.util.function.Function) ForeignKey(org.apache.torque.engine.database.model.ForeignKey) List(java.util.List) Unique(org.apache.torque.engine.database.model.Unique) Index(org.apache.torque.engine.database.model.Index) Table(org.apache.torque.engine.database.model.Table) DfSPolicyResult(org.dbflute.logic.doc.spolicy.result.DfSPolicyResult) Srl(org.dbflute.util.Srl) Column(org.apache.torque.engine.database.model.Column) List(java.util.List) Unique(org.apache.torque.engine.database.model.Unique) Index(org.apache.torque.engine.database.model.Index) ForeignKey(org.apache.torque.engine.database.model.ForeignKey)

Aggregations

Table (org.apache.torque.engine.database.model.Table)58 Column (org.apache.torque.engine.database.model.Column)16 ArrayList (java.util.ArrayList)15 List (java.util.List)14 File (java.io.File)11 LinkedHashMap (java.util.LinkedHashMap)10 Map (java.util.Map)10 ForeignKey (org.apache.torque.engine.database.model.ForeignKey)9 HashSet (java.util.HashSet)8 DfDataTable (org.dbflute.helper.dataset.DfDataTable)8 Database (org.apache.torque.engine.database.model.Database)6 IOException (java.io.IOException)4 Entry (java.util.Map.Entry)4 DfBuildProperties (org.dbflute.DfBuildProperties)4 DfDataSet (org.dbflute.helper.dataset.DfDataSet)4 HashMap (java.util.HashMap)3 Function (java.util.function.Function)3 DfLReverseOutputResource (org.dbflute.logic.doc.lreverse.DfLReverseOutputResource)3 BufferedWriter (java.io.BufferedWriter)2 FileOutputStream (java.io.FileOutputStream)2