Search in sources :

Example 21 with ColumnInfo

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

the class AbstractBatchUpdateCommand method getPersistentPropertyNames.

/**
 * Get persistent property names. <br>
 * Basically this method should be called when initializing only.
 * @param bmd The bean meta data. (NotNull)
 * @return Persistent property names. (NotNull)
 */
protected String[] getPersistentPropertyNames(TnBeanMetaData bmd) {
    final DBMeta dbmeta = findDBMeta();
    if (dbmeta != null) {
        final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
        final List<String> propertyNameList = new ArrayList<String>();
        for (ColumnInfo columnInfo : columnInfoList) {
            propertyNameList.add(columnInfo.getPropertyName());
        }
        return propertyNameList.toArray(new String[] {});
    } else {
        // when the entity does not have its DB meta.
        return createNonOrderedPropertyNames(bmd);
    }
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ArrayList(java.util.ArrayList) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 22 with ColumnInfo

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

the class AbstractCountableUpdateCommand method getPersistentPropertyNames.

/**
 * Get persistent property names. <br>
 * Basically this method should be called when initializing only.
 * @param bmd The bean meta data. (NotNull)
 * @return Persistent property names. (NotNull)
 */
protected String[] getPersistentPropertyNames(TnBeanMetaData bmd) {
    final DBMeta dbmeta = findDBMeta();
    if (dbmeta != null) {
        final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
        final List<String> propertyNameList = new ArrayList<String>();
        for (ColumnInfo columnInfo : columnInfoList) {
            propertyNameList.add(columnInfo.getPropertyName());
        }
        return propertyNameList.toArray(new String[] {});
    } else {
        // when the entity does not have its DB meta.
        return createNonOrderedPropertyNames(bmd);
    }
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) ArrayList(java.util.ArrayList) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 23 with ColumnInfo

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

the class TnBeanListResultSetHandler method createRelationSelector.

/**
 * Create the selector of relation.
 * @param hasCB Does the select use condition-bean?
 * @param cb The condition-bean for the select. (NullAllowed: not condition-bean select)
 * @return The created selector instance. (NotNull)
 */
protected TnRelationSelector createRelationSelector(final boolean hasCB, ConditionBean cb) {
    final boolean undefClsSel = isUndefinedClassificationSelectAllowed(hasCB, cb);
    final boolean colNullObj = isUseColumnNullObjectHandling(hasCB, cb);
    return new TnRelationSelector() {

        public boolean isNonLimitMapping() {
            return hasCB;
        }

        public boolean isNonSelectedRelation(String relationNoSuffix) {
            return hasCB && !cb.getSqlClause().hasSelectedRelation(relationNoSuffix);
        }

        public boolean isNonSelectedNextConnectingRelation(String relationNoSuffix) {
            return hasCB && !cb.getSqlClause().isSelectedNextConnectingRelation(relationNoSuffix);
        }

        public boolean canUseRelationCache(String relationNoSuffix) {
            return hasCB && cb.getSqlClause().canUseRelationCache(relationNoSuffix);
        }

        public boolean isNonSpecifiedColumnAccessAllowed(String relationNoSuffix) {
            return hasCB && cb.isNonSpecifiedColumnAccessAllowed();
        }

        public boolean isUsingSpecifyColumnInRelation(String relationNoSuffix) {
            if (!hasCB) {
                return false;
            }
            final SqlClause sqlClause = cb.getSqlClause();
            final String tableAlias = sqlClause.translateSelectedRelationPathToTableAlias(relationNoSuffix);
            if (tableAlias == null) {
                // no way but just in case
                return false;
            }
            return sqlClause.hasSpecifiedSelectColumn(tableAlias);
        }

        public Set<ColumnInfo> getRelationSpecifiedNullObjectColumnSet(String relationNoSuffix) {
            if (!hasCB) {
                return DfCollectionUtil.emptySet();
            }
            return cb.getSqlClause().getRelationSpecifiedNullObjectColumnSet(relationNoSuffix);
        }

        public boolean isUndefinedClassificationSelectAllowed(String relationNoSuffix) {
            return undefClsSel;
        }

        public boolean isColumnNullObjectEnabled(String relationNoSuffix) {
            return colNullObj;
        }
    };
}
Also used : SqlClause(org.dbflute.cbean.sqlclause.SqlClause) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) TnRelationSelector(org.dbflute.s2dao.rowcreator.TnRelationSelector)

Example 24 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 25 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)

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