Search in sources :

Example 11 with DBMeta

use of org.dbflute.dbmeta.DBMeta 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 12 with DBMeta

use of org.dbflute.dbmeta.DBMeta 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 13 with DBMeta

use of org.dbflute.dbmeta.DBMeta 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 14 with DBMeta

use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.

the class TnRelationPropertyTypeImpl method createPropertyAccessor.

protected DfPropertyAccessor createPropertyAccessor(final DfPropertyDesc propertyDesc, TnBeanMetaData myBeanMetaData) {
    final DBMeta dbmeta = myBeanMetaData.getDBMeta();
    assertDBMetaExists(dbmeta, myBeanMetaData);
    final String propertyName = propertyDesc.getPropertyName();
    final ForeignInfo foreignInfo = dbmeta.hasForeign(propertyName) ? dbmeta.findForeignInfo(propertyName) : null;
    return new DfPropertyAccessor() {

        public String getPropertyName() {
            return foreignInfo != null ? foreignInfo.getForeignPropertyName() : propertyName;
        }

        public Class<?> getPropertyType() {
            return foreignInfo != null ? foreignInfo.getPropertyAccessType() : propertyDesc.getPropertyType();
        }

        public Class<?> getGenericType() {
            return propertyDesc.getGenericType();
        }

        public Object getValue(Object target) {
            if (foreignInfo != null && target instanceof Entity) {
                // basically here
                return foreignInfo.read((Entity) target);
            } else {
                return propertyDesc.getValue(target);
            }
        }

        public void setValue(Object target, Object value) {
            if (foreignInfo != null && target instanceof Entity) {
                // basically here
                foreignInfo.write((Entity) target, value);
            } else {
                propertyDesc.setValue(target, value);
            }
        }

        public boolean isReadable() {
            return propertyDesc.isReadable();
        }

        public boolean isWritable() {
            return propertyDesc.isWritable();
        }
    };
}
Also used : DfPropertyAccessor(org.dbflute.helper.beans.DfPropertyAccessor) ForeignInfo(org.dbflute.dbmeta.info.ForeignInfo) Entity(org.dbflute.Entity) DBMeta(org.dbflute.dbmeta.DBMeta)

Example 15 with DBMeta

use of org.dbflute.dbmeta.DBMeta in project dbflute-core by dbflute.

the class AbstractConditionQuery method invokeOrderBy.

/**
 * {@inheritDoc}
 */
public void invokeOrderBy(String columnFlexibleName, boolean isAsc) {
    assertStringNotNullAndNotTrimmedEmpty("columnFlexibleName", columnFlexibleName);
    final PropertyNameCQContainer container = xhelpExtractingPropertyNameCQContainer(columnFlexibleName);
    final String flexibleName = container.getFlexibleName();
    final ConditionQuery cq = container.getConditionQuery();
    final String ascDesc = isAsc ? "Asc" : "Desc";
    final DBMeta dbmeta = findDBMeta(cq.asTableDbName());
    final String columnCapPropName = initCap(dbmeta.findColumnInfo(flexibleName).getPropertyName());
    final String methodName = "addOrderBy_" + columnCapPropName + "_" + ascDesc;
    final Method method = xhelpGettingCQMethod(cq, methodName, (Class<?>[]) null);
    if (method == null) {
        throwConditionInvokingOrderMethodNotFoundException(columnFlexibleName, isAsc, methodName);
    }
    try {
        xhelpInvokingCQMethod(cq, method, (Object[]) null);
    } catch (ReflectionFailureException e) {
        throwConditionInvokingOrderReflectionFailureException(columnFlexibleName, isAsc, methodName, e);
    }
}
Also used : DBMeta(org.dbflute.dbmeta.DBMeta) Method(java.lang.reflect.Method) ReflectionFailureException(org.dbflute.util.DfReflectionUtil.ReflectionFailureException)

Aggregations

DBMeta (org.dbflute.dbmeta.DBMeta)64 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)32 ArrayList (java.util.ArrayList)13 ForeignInfo (org.dbflute.dbmeta.info.ForeignInfo)13 List (java.util.List)12 LinkedHashMap (java.util.LinkedHashMap)11 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)10 Entity (org.dbflute.Entity)9 PrimaryInfo (org.dbflute.dbmeta.info.PrimaryInfo)9 ReferrerInfo (org.dbflute.dbmeta.info.ReferrerInfo)9 Method (java.lang.reflect.Method)8 ReflectionFailureException (org.dbflute.util.DfReflectionUtil.ReflectionFailureException)8 Map (java.util.Map)7 ColumnFunctionCipher (org.dbflute.cbean.cipher.ColumnFunctionCipher)7 RelationInfo (org.dbflute.dbmeta.info.RelationInfo)7 LocalDate (java.time.LocalDate)6 LocalDateTime (java.time.LocalDateTime)6 Collection (java.util.Collection)6 Date (java.util.Date)6 HashMap (java.util.HashMap)6