Search in sources :

Example 11 with Column

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

the class DfLReverseDataExtractor method buildSelfReferenceExtractingTrySqlList.

// ===================================================================================
// Extraction SQL
// ==============
// -----------------------------------------------------
// Self Reference
// --------------
protected OptionalThing<List<String>> buildSelfReferenceExtractingTrySqlList(Table table) {
    final ForeignKey selfReferenceFK = table.getSelfReferenceForeignKey();
    if (selfReferenceFK == null || !selfReferenceFK.isSimpleKeyFK()) {
        return OptionalThing.empty();
    }
    final String tableSqlName = table.getTableSqlNameDirectUse();
    final Column firstLocalColumn = table.getColumn(selfReferenceFK.getFirstLocalColumnName());
    final String firstLocalName = firstLocalColumn.getColumnSqlNameDirectUse();
    final Column firstForeignColumn = table.getColumn(selfReferenceFK.getFirstForeignColumnName());
    final String firstForeignName = firstForeignColumn.getColumnSqlNameDirectUse();
    final List<String> sqlList = DfCollectionUtil.newArrayList();
    sqlList.add(doBuildSelfReferenceRecursiveSql(table, tableSqlName, firstLocalName, firstForeignName));
    sqlList.add(doBuildSelfReferenceJoinJoinSql(table, tableSqlName, firstLocalName, firstForeignName));
    return OptionalThing.of(sqlList);
}
Also used : Column(org.apache.torque.engine.database.model.Column) ForeignKey(org.apache.torque.engine.database.model.ForeignKey)

Example 12 with Column

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

the class DfLReverseDataExtractor method buildOrderByClause.

protected String buildOrderByClause(Table table) {
    final ForeignKey selfReferenceFK = table.getSelfReferenceForeignKey();
    final String orderBy;
    if (selfReferenceFK != null && selfReferenceFK.isSimpleKeyFK()) {
        final Column firstColumn = table.getColumn(selfReferenceFK.getFirstLocalColumnName());
        final String firstName = firstColumn.getColumnSqlNameDirectUse();
        orderBy = buildOrderByNullsFirst(firstName);
    } else {
        orderBy = "";
    }
    return orderBy;
}
Also used : Column(org.apache.torque.engine.database.model.Column) ForeignKey(org.apache.torque.engine.database.model.ForeignKey)

Example 13 with Column

use of org.apache.torque.engine.database.model.Column 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 14 with Column

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

the class DfColumnListToStringBuilder method getColumnArgsSetupPropertyString.

public static String getColumnArgsSetupPropertyString(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.adjustEntitySetPropertyCall(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 15 with Column

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

the class DfColumnListToStringBuilder method getColumnUncapitalisedJavaNameCommaString.

public static String getColumnUncapitalisedJavaNameCommaString(List<Column> columnList) {
    validateColumnList(columnList);
    String result = "";
    for (Column column : columnList) {
        final String name = column.getUncapitalisedJavaName();
        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