Search in sources :

Example 41 with ColumnInfo

use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.

the class InsertEntityCommand method createNonPrimaryInsertSqlExecution.

/**
 * @param bmd The meta data of bean. (NotNull)
 * @return Whether the method is target. (For example if it has primary key, returns false.)
 */
protected SqlExecution createNonPrimaryInsertSqlExecution(TnBeanMetaData bmd) {
    final DBMeta dbmeta = findDBMeta();
    if (dbmeta.hasPrimaryKey()) {
        return null;
    }
    final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
    final StringBuilder columnDefSb = new StringBuilder();
    for (org.dbflute.dbmeta.info.ColumnInfo columnInfo : columnInfoList) {
        columnDefSb.append(", ").append(columnInfo.getColumnSqlName());
    }
    columnDefSb.delete(0, ", ".length()).insert(0, "(").append(")");
    final StringBuilder columnValuesSb = new StringBuilder();
    for (org.dbflute.dbmeta.info.ColumnInfo columnInfo : columnInfoList) {
        columnValuesSb.append(", /*pmb.").append(columnInfo.getPropertyName()).append("*/null");
    }
    columnValuesSb.delete(0, ", ".length()).insert(0, "(").append(")");
    final String sql = "insert into " + dbmeta.getTableSqlName() + columnDefSb + " values" + columnValuesSb;
    return createOutsideSqlExecuteExecution(_entity.getClass(), sql);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 42 with ColumnInfo

use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.

the class SelectCBExecution method processPagingSelectAndQuerySplit.

// ===================================================================================
// Paging Select and Query Split
// =============================
protected Object processPagingSelectAndQuerySplit(Object[] args, ConditionBean cb) {
    if (!cb.canPagingSelectAndQuerySplit()) {
        return null;
    }
    if (!cb.isFetchScopeEffective()) {
        return null;
    }
    final DBMeta dbmeta = cb.asDBMeta();
    final PrimaryInfo primaryInfo = dbmeta.getPrimaryInfo();
    if (primaryInfo.isCompoundKey()) {
        // basically no way, already checked
        return null;
    }
    final ColumnInfo pkColumn = primaryInfo.getFirstColumn();
    final SqlClause sqlClause = cb.getSqlClause();
    final List<Object> pkList = doSplitSelectFirst(args, cb, dbmeta, sqlClause);
    if (pkList == null) {
        // no way just in case
        return null;
    }
    if (pkList.isEmpty()) {
        return pkList;
    }
    return doSplitSelectSecond(args, cb, pkColumn, sqlClause, pkList);
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo)

Example 43 with ColumnInfo

use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.

the class TnRelationRowCreatorExtension method adjustCreatedRelationRow.

/**
 * Adjust created row for relation tables.
 * @param relationRow The relation row of tables related to the base-point table. (NotNull)
 * @param relationNoSuffix The suffix of relation no, e.g. _0, _1_3. (NotNull)
 * @param relSelector The selector of relation, which has various determination. (NotNull)
 * @param rpt The property type of the relation. (NotNull)
 */
public static void adjustCreatedRelationRow(Object relationRow, String relationNoSuffix, TnRelationSelector relSelector, TnRelationPropertyType rpt) {
    // *similar implementation for base-point row exists, see it for the details
    if (relationRow instanceof Entity) {
        final Entity entity = (Entity) relationRow;
        // check access to non-specified-column
        if (// not allowed
        !relSelector.isNonSpecifiedColumnAccessAllowed(relationNoSuffix) && relSelector.isUsingSpecifyColumnInRelation(relationNoSuffix)) {
            // and use SpecifyColumn
            // so check it
            entity.modifiedToSpecified();
            // adjust specification for column null object handling
            final Set<ColumnInfo> nullObjectColumnSet = relSelector.getRelationSpecifiedNullObjectColumnSet(relationNoSuffix);
            for (ColumnInfo columnInfo : nullObjectColumnSet) {
                // might be empty loop if no null object
                entity.myspecifyProperty(columnInfo.getPropertyName());
            }
        }
        // enable the handling of column null object if allowed and object-able
        if (relSelector.isColumnNullObjectEnabled(relationNoSuffix) && entity instanceof ColumnNullObjectable) {
            ((ColumnNullObjectable) entity).enableColumnNullObject();
        }
        // clear modified properties for update process using selected entity
        entity.clearModifiedInfo();
        // mark as select to determine the entity is selected or user-created
        // basically for e.g. determine columns of batch insert
        entity.markAsSelect();
    } else {
        // not DBFlute entity
        // actually any bean meta data can be accepted
        // because only it gets modified properties
        rpt.getYourBeanMetaData().getModifiedPropertyNames(relationRow).clear();
    }
}
Also used : Entity(org.dbflute.Entity) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnNullObjectable(org.dbflute.dbmeta.accessory.ColumnNullObjectable)

Example 44 with ColumnInfo

use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.

the class TnAbstractPropertyTypeFactory method createPropertyType.

protected TnPropertyType createPropertyType(DfPropertyDesc propertyDesc) {
    final ValueType valueType = getValueType(propertyDesc);
    final String columnDbName = getColumnDbName(propertyDesc);
    final ColumnSqlName columnSqlName = getColumnSqlName(columnDbName);
    final ColumnInfo entityColumnInfo = getEntityColumnInfo(columnDbName);
    return new TnPropertyTypeImpl(propertyDesc, valueType, columnDbName, columnSqlName, entityColumnInfo);
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) ValueType(org.dbflute.jdbc.ValueType) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) TnPropertyTypeImpl(org.dbflute.s2dao.metadata.impl.TnPropertyTypeImpl)

Example 45 with ColumnInfo

use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.

the class TnRowCreatorExtension method createRow.

// ===================================================================================
// Main
// ====
/**
 * {@inheritDoc}
 */
public Object createRow(ResultSet rs, Map<String, Map<String, Integer>> selectIndexMap, Map<String, TnPropertyMapping> propertyCache, Class<?> beanClass, ConditionBean cb) throws SQLException {
    if (propertyCache.isEmpty()) {
        String msg = "The propertyCache should not be empty: bean=" + beanClass.getName();
        throw new IllegalStateException(msg);
    }
    // temporary variable, for exception message, debug message
    String columnName = null;
    TnPropertyMapping mapping = null;
    String propertyName = null;
    Object selectedValue = null;
    ColumnInfo columnInfo = null;
    final Object row;
    final DBMeta dbmeta;
    if (_fixedDBMeta != null) {
        if (_creatableByDBMeta) {
            // mainly here
            final Entity entity = _fixedDBMeta.newEntity();
            reflectConditionBeanOptionToEntity(cb, entity);
            row = entity;
        } else {
            // e.g. manual-extended entity
            row = newBean(beanClass);
        }
        dbmeta = _fixedDBMeta;
    } else {
        // e.g. manual-created bean of outsideSql
        row = newBean(beanClass);
        // find just in case
        dbmeta = findCachedDBMeta(row);
    }
    try {
        if (dbmeta != null) {
            // mainly here
            // almost always true
            final boolean isEntity = row instanceof Entity;
            final Entity entityRow = isEntity ? (Entity) row : null;
            for (Entry<String, TnPropertyMapping> entry : propertyCache.entrySet()) {
                columnName = entry.getKey();
                mapping = entry.getValue();
                propertyName = mapping.getPropertyName();
                selectedValue = getValue(rs, columnName, mapping.getValueType(), selectIndexMap);
                columnInfo = mapping.getEntityColumnInfo();
                if (columnInfo != null && isEntity) {
                    columnInfo.write(entityRow, selectedValue);
                } else {
                    mapping.getPropertyAccessor().setValue(row, selectedValue);
                }
            }
            if (canHandleDerivedMap(row)) {
                processDerivedMap(rs, selectIndexMap, propertyCache, row);
            }
        } else {
            // not DBFlute entity
            for (Entry<String, TnPropertyMapping> entry : propertyCache.entrySet()) {
                columnName = entry.getKey();
                mapping = entry.getValue();
                propertyName = mapping.getPropertyName();
                selectedValue = getValue(rs, columnName, mapping.getValueType(), selectIndexMap);
                mapping.getPropertyAccessor().setValue(row, selectedValue);
            }
        }
        return row;
    } catch (ClassCastException e) {
        throwMappingClassCastException(row, dbmeta, mapping, selectedValue, e);
        // unreachable
        return null;
    } catch (SQLException e) {
        if (_log.isDebugEnabled()) {
            String msg = "Failed to get selected values while resultSet handling:";
            msg = msg + " target=" + DfTypeUtil.toClassTitle(beanClass) + "." + propertyName;
            _log.debug(msg);
        }
        throw e;
    }
}
Also used : Entity(org.dbflute.Entity) DBMeta(org.dbflute.dbmeta.DBMeta) TnPropertyMapping(org.dbflute.s2dao.metadata.TnPropertyMapping) SQLException(java.sql.SQLException) MappingClassCastException(org.dbflute.exception.MappingClassCastException) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Aggregations

ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)73 DBMeta (org.dbflute.dbmeta.DBMeta)27 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)14 Entity (org.dbflute.Entity)8 SpecifiedColumn (org.dbflute.cbean.dream.SpecifiedColumn)7 SqlClause (org.dbflute.cbean.sqlclause.SqlClause)7 ArrayList (java.util.ArrayList)6 LinkedHashMap (java.util.LinkedHashMap)5 PrimaryInfo (org.dbflute.dbmeta.info.PrimaryInfo)5 ColumnRealName (org.dbflute.dbmeta.name.ColumnRealName)5 List (java.util.List)4 ForeignInfo (org.dbflute.dbmeta.info.ForeignInfo)4 HashSet (java.util.HashSet)3 ColumnFunctionCipher (org.dbflute.cbean.cipher.ColumnFunctionCipher)3 IllegalConditionBeanOperationException (org.dbflute.exception.IllegalConditionBeanOperationException)3 Method (java.lang.reflect.Method)2 LocalDate (java.time.LocalDate)2 LocalDateTime (java.time.LocalDateTime)2 Collection (java.util.Collection)2 Date (java.util.Date)2