Search in sources :

Example 1 with ColumnInfo

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

the class TnRowCreatorExtension method adjustCreatedRow.

// ===================================================================================
// Fix Row
// =======
/**
 * Adjust created row. (clearing modified info, ...)
 * @param row The row of result list. (NotNull)
 * @param checkNonSp Does is use the check of access to non-specified column?
 * @param colNullObj Does is use the handling of column null object?
 * @param basePointBmd The bean meta data of the row for base-point table. (NotNull)
 * @param cb The condition-bean for the select. (NullAllowed: when not condition-bean select)
 */
public static void adjustCreatedRow(final Object row, boolean checkNonSp, boolean colNullObj, TnBeanMetaData basePointBmd, ConditionBean cb) {
    // _/_/_/_/_/_/_/_/_/_/
    if (row instanceof Entity) {
        final Entity entity = (Entity) row;
        // _/_/_/_/_/_/_/_/_/_/
        if (checkNonSp) {
            // contains enabled by CB and using SpecifyColumn
            entity.modifiedToSpecified();
            // _/_/_/_/_/_/_/_/_/_/
            if (colNullObj && cb != null) {
                // check 'cb' just in case
                final SqlClause sqlClause = cb.getSqlClause();
                for (ColumnInfo columnInfo : sqlClause.getLocalSpecifiedNullObjectColumnSet()) {
                    entity.myspecifyProperty(columnInfo.getPropertyName());
                }
            }
        }
        // only table that has null object target column is object-able (generated as it)
        if (colNullObj && 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
        basePointBmd.getModifiedPropertyNames(row).clear();
    }
}
Also used : Entity(org.dbflute.Entity) SqlClause(org.dbflute.cbean.sqlclause.SqlClause) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) ColumnNullObjectable(org.dbflute.dbmeta.accessory.ColumnNullObjectable)

Example 2 with ColumnInfo

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

the class TnRelationPropertyTypeImpl method deriveUniqueKeys.

protected List<TnPropertyType> deriveUniqueKeys(String[] yourKeys, TnBeanMetaData yourBeanMetaData) {
    final DBMeta dbmeta = yourBeanMetaData.getDBMeta();
    final List<TnPropertyType> uniquePropertyTypeList;
    if (dbmeta != null && dbmeta.hasPrimaryKey()) {
        final PrimaryInfo primaryInfo = dbmeta.getPrimaryInfo();
        final List<ColumnInfo> primaryColumnList = primaryInfo.getPrimaryColumnList();
        uniquePropertyTypeList = new ArrayList<TnPropertyType>(primaryColumnList.size());
        for (ColumnInfo pk : primaryColumnList) {
            final TnPropertyType pt = yourBeanMetaData.getPropertyTypeByColumnName(pk.getColumnDbName());
            uniquePropertyTypeList.add(pt);
        }
    } else {
        uniquePropertyTypeList = new ArrayList<TnPropertyType>(yourKeys.length);
        for (String yourKey : yourKeys) {
            final TnPropertyType pt = yourBeanMetaData.getPropertyTypeByColumnName(yourKey);
            uniquePropertyTypeList.add(pt);
        }
    }
    return uniquePropertyTypeList;
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo)

Example 3 with ColumnInfo

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

the class AbstractConditionQuery method doInvokeQuery.

protected void doInvokeQuery(String colName, String ckey, Object value, ConditionOption option) {
    assertStringNotNullAndNotTrimmedEmpty("columnFlexibleName", colName);
    assertStringNotNullAndNotTrimmedEmpty("conditionKeyName", ckey);
    final boolean noArg = Srl.equalsIgnoreCase(ckey, "IsNull", "IsNotNull", "IsNullOrEmpty", "EmptyString");
    if (!noArg && (value == null || "".equals(value))) {
        if (xgetSqlClause().isNullOrEmptyQueryChecked()) {
            // as default
            String msg = "The conditionValue is required but null or empty: column=" + colName + " value=" + value;
            throw new IllegalConditionBeanOperationException(msg);
        } else {
            // e.g. when cb.ignoreNullOrEmptyQuery()
            return;
        }
    }
    final PropertyNameCQContainer container = xhelpExtractingPropertyNameCQContainer(colName);
    final String flexibleName = container.getFlexibleName();
    final ConditionQuery cq = container.getConditionQuery();
    final DBMeta dbmeta = findDBMeta(cq.asTableDbName());
    final ColumnInfo columnInfo;
    try {
        columnInfo = dbmeta.findColumnInfo(flexibleName);
    } catch (RuntimeException e) {
        throwConditionInvokingColumnFindFailureException(colName, ckey, value, option, e);
        // unreachable (to avoid compile error)
        return;
    }
    final String columnCapPropName = initCap(columnInfo.getPropertyName());
    final boolean rangeOf = Srl.equalsIgnoreCase(ckey, "RangeOf");
    final boolean fromTo = Srl.equalsIgnoreCase(ckey, "FromTo", "DateFromTo");
    final boolean inScope = Srl.equalsIgnoreCase(ckey, "InScope");
    if (!noArg) {
        try {
            // convert type
            value = columnInfo.convertToObjectNativeType(value);
        } catch (RuntimeException e) {
            throwConditionInvokingValueConvertFailureException(colName, ckey, value, option, e);
        }
    }
    final String methodName = xbuildQuerySetMethodName(ckey, columnCapPropName);
    final List<Class<?>> typeList = newArrayListSized(4);
    final Class<?> propertyType = columnInfo.getObjectNativeType();
    if (fromTo) {
        if (LocalDate.class.isAssignableFrom(propertyType)) {
            // #date_parade
            typeList.add(propertyType);
            typeList.add(propertyType);
        } else if (LocalDateTime.class.isAssignableFrom(propertyType)) {
            typeList.add(propertyType);
            typeList.add(propertyType);
        } else {
            // fixedly util.Date
            typeList.add(Date.class);
            typeList.add(Date.class);
        }
    } else if (rangeOf) {
        typeList.add(propertyType);
        typeList.add(propertyType);
    } else {
        if (!noArg) {
            final Class<?> instanceType = value.getClass();
            if (inScope && Collection.class.isAssignableFrom(instanceType)) {
                // double check just in case
                // inScope's argument is fixed type
                typeList.add(Collection.class);
            } else {
                typeList.add(instanceType);
            }
        }
    }
    if (option != null) {
        typeList.add(option.getClass());
    }
    final List<Class<?>> filteredTypeList = newArrayListSized(typeList.size());
    for (Class<?> parameterType : typeList) {
        filteredTypeList.add(xfilterInvokeQueryParameterType(colName, ckey, parameterType));
    }
    final Class<?>[] parameterTypes = filteredTypeList.toArray(new Class<?>[filteredTypeList.size()]);
    final Method method = xhelpGettingCQMethod(cq, methodName, parameterTypes);
    if (method == null) {
        throwConditionInvokingSetMethodNotFoundException(colName, ckey, value, option, methodName, parameterTypes);
    }
    try {
        final List<Object> argList = newArrayList();
        if (fromTo || rangeOf) {
            if (!(value instanceof List<?>)) {
                // check type
                throwConditionInvokingDateFromToValueInvalidException(colName, ckey, value, option, methodName, parameterTypes);
            }
            argList.addAll((List<?>) value);
        } else {
            if (!noArg) {
                argList.add(value);
            }
        }
        if (option != null) {
            argList.add(option);
        }
        final List<Object> filteredArgList = newArrayListSized(argList.size());
        for (Object arg : argList) {
            filteredArgList.add(xfilterInvokeQueryParameterValue(colName, ckey, arg));
        }
        xhelpInvokingCQMethod(cq, method, filteredArgList.toArray());
    } catch (ReflectionFailureException e) {
        throwConditionInvokingSetReflectionFailureException(colName, ckey, value, option, methodName, parameterTypes, e);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) Method(java.lang.reflect.Method) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException) Date(java.util.Date) LocalDate(java.time.LocalDate) DBMeta(org.dbflute.dbmeta.DBMeta) IllegalConditionBeanOperationException(org.dbflute.exception.IllegalConditionBeanOperationException) Collection(java.util.Collection) List(java.util.List) ArrayList(java.util.ArrayList)

Example 4 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 5 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)

Aggregations

ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)72 DBMeta (org.dbflute.dbmeta.DBMeta)26 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