Search in sources :

Example 26 with ColumnInfo

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

the class AbstractConditionQuery method doRegIQ.

protected void doRegIQ(ConditionKey key, Object value, ConditionValue cvalue, String columnDbName, ConditionOption option) {
    if (!prepareQueryChecked(key, value, cvalue, columnDbName).newClause()) {
        return;
    }
    final DBMeta dbmeta = xgetDBMetaProvider().provideDBMetaChecked(asTableDbName());
    final ColumnInfo columnInfo = dbmeta.findColumnInfo(columnDbName);
    final String propertyName = columnInfo.getPropertyName();
    final String uncapPropName = initUncap(propertyName);
    // If Java, it is necessary to use uncapPropName!
    final String location = xgetLocation(uncapPropName);
    key.setupConditionValue(xcreateQueryModeProvider(), cvalue, value, location, option);
    final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
    final ColumnFunctionCipher cipher = xgetSqlClause().findColumnFunctionCipher(columnInfo);
    if (isBaseQuery()) {
        xgetSqlClause().registerBaseTableInlineWhereClause(columnSqlName, key, cvalue, cipher, option);
    } else {
        final String aliasName = xgetAliasName();
        xgetSqlClause().registerOuterJoinInlineWhereClause(aliasName, columnSqlName, key, cvalue, cipher, option, _onClause);
    }
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnFunctionCipher(org.dbflute.cbean.cipher.ColumnFunctionCipher)

Example 27 with ColumnInfo

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

the class HpCalcSpecification method getResolvedSpecifiedColumnDbName.

// -----------------------------------------------------
// Column Name
// -----------
/**
 * @return The column DB name of specified resolved column. (NullAllowed)
 */
public String getResolvedSpecifiedColumnDbName() {
    // resolved plain or deriving sub-query
    checkSpecifiedCB();
    if (_specifedCB.xhasDreamCruiseTicket()) {
        final SpecifiedColumn ticket = _specifedCB.xshowDreamCruiseTicket();
        return ticket.getColumnDbName();
    }
    final ColumnInfo columnInfo = getResolvedSpecifiedColumnInfo();
    return columnInfo != null ? columnInfo.getColumnDbName() : null;
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) SpecifiedColumn(org.dbflute.cbean.dream.SpecifiedColumn)

Example 28 with ColumnInfo

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

the class HpCalcSpecification method getResolvedSpecifiedColumnInfo.

/**
 * @return The column info of specified resolved column. (NullAllowed)
 */
public ColumnInfo getResolvedSpecifiedColumnInfo() {
    // resolved plain or deriving sub-query
    checkSpecifiedCB();
    final ColumnInfo columnInfo = getSpecifiedColumnInfo();
    return columnInfo != null ? columnInfo : getSpecifiedDerivingColumnInfo();
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 29 with ColumnInfo

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

the class DateUpdateAdjuster method truncatePrecisionOfEntityProperty.

// ===================================================================================
// DatetimePrecision Truncation
// ============================
/**
 * @param entity The entity to be adjusted here. (NotNull)
 */
public void truncatePrecisionOfEntityProperty(Entity entity) {
    if (entity == null) {
        throw new IllegalArgumentException("The argument 'entity' should not be null.");
    }
    final DBMeta dbmeta = entity.asDBMeta();
    final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
    final boolean createdBySelect = entity.createdBySelect();
    if (createdBySelect) {
        // to avoid non-specified column check
        entity.clearMarkAsSelect();
    }
    try {
        for (ColumnInfo columnInfo : columnInfoList) {
            if (columnInfo.isObjectNativeTypeDate()) {
                // it does not need to read/write if LocalDate, but no-if to be simple
                // (and read/write by columnInfo does not use reflection so no worry)
                // is date
                final Object dateValue = columnInfo.read(entity);
                if (dateValue != null) {
                    columnInfo.write(entity, doTruncatePrecisionIfHasTime(columnInfo, dateValue));
                }
            }
        }
    } finally {
        if (createdBySelect) {
            // restore
            entity.markAsSelect();
        }
    }
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 30 with ColumnInfo

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

the class InsertOption method xacceptInsertColumnModifiedPropertiesIfNeeds.

// -----------------------------------------------------
// Modified Properties
// -------------------
public void xacceptInsertColumnModifiedPropertiesIfNeeds(List<? extends Entity> entityList) {
    // internal
    if (entityList == null) {
        throw new IllegalArgumentException("The argument 'entityList' should not be null.");
    }
    if (_insertColumnSpecification != null) {
        // already specified
        return;
    }
    if (entityList.isEmpty()) {
        // do nothing
        return;
    }
    if (xisCompatibleBatchInsertDefaultEveryColumn()) {
        // every column for compatible
        return;
    }
    final Entity firstEntity = entityList.get(0);
    if (firstEntity.createdBySelect()) {
        // all columns e.g. copy insert
        specify(new SpecifyQuery<CB>() {

            public void specify(CB cb) {
                final List<ColumnInfo> infoList = firstEntity.asDBMeta().getColumnInfoList();
                for (ColumnInfo info : infoList) {
                    if (!info.isPrimary()) {
                        // except PK
                        cb.localSp().xspecifyColumn(info.getColumnDbName());
                    }
                }
            }
        });
    } else {
        // least common multiple or same-set columns
        final Set<String> targetProps = xgatherInsertColumnModifiedProperties(entityList, firstEntity);
        final DBMeta dbmeta = firstEntity.asDBMeta();
        specify(new SpecifyQuery<CB>() {

            public void specify(CB cb) {
                // you don't need to specify primary key because primary key has special handling
                for (String prop : targetProps) {
                    final ColumnInfo info = dbmeta.findColumnInfo(prop);
                    if (!info.isPrimary()) {
                        // except PK
                        cb.localSp().xspecifyColumn(info.getColumnDbName());
                    }
                }
            }
        });
    }
}
Also used : Entity(org.dbflute.Entity) DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) List(java.util.List)

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