Search in sources :

Example 6 with ColumnInfo

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

the class AbstractDBMeta method searchPrimaryInfo.

/**
 * {@inheritDoc}
 */
public OptionalObject<PrimaryInfo> searchPrimaryInfo(Collection<ColumnInfo> columnInfoList) {
    // exception if no PK
    final PrimaryInfo primaryInfo = getPrimaryInfo();
    final Set<ColumnInfo> colSet = new HashSet<ColumnInfo>(columnInfoList);
    final List<ColumnInfo> pkList = primaryInfo.getPrimaryColumnList();
    for (ColumnInfo pk : pkList) {
        if (!colSet.contains(pk)) {
            return OptionalObject.ofNullable(null, () -> {
                throwSpecifiedColumnNotPrimaryException(columnInfoList, pkList);
            });
        }
    }
    return OptionalObject.of(primaryInfo);
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) PrimaryInfo(org.dbflute.dbmeta.info.PrimaryInfo) HashSet(java.util.HashSet)

Example 7 with ColumnInfo

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

the class AbstractDBMeta method setupKeyToLowerMap.

protected Map<String, String> setupKeyToLowerMap(boolean dbNameKey) {
    final Map<String, String> map;
    if (dbNameKey) {
        map = newConcurrentHashMap(getTableDbName().toLowerCase(), getTablePropertyName());
    } else {
        map = newConcurrentHashMap(getTablePropertyName().toLowerCase(), getTableDbName());
    }
    final Method[] methods = this.getClass().getMethods();
    final String columnInfoMethodPrefix = "column";
    try {
        for (Method method : methods) {
            final String name = method.getName();
            if (!name.startsWith(columnInfoMethodPrefix)) {
                continue;
            }
            final ColumnInfo columnInfo = (ColumnInfo) method.invoke(this);
            final String dbName = columnInfo.getColumnDbName();
            final String propertyName = columnInfo.getPropertyName();
            if (dbNameKey) {
                map.put(dbName.toLowerCase(), propertyName);
            } else {
                map.put(propertyName.toLowerCase(), dbName);
            }
        }
        return Collections.unmodifiableMap(map);
    } catch (Exception e) {
        throw new IllegalStateException(e);
    }
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) Method(java.lang.reflect.Method) DBMetaNotFoundException(org.dbflute.exception.DBMetaNotFoundException)

Example 8 with ColumnInfo

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

the class AbstractDBMeta method findColumnInfo.

/**
 * {@inheritDoc}
 */
public ColumnInfo findColumnInfo(String columnFlexibleName) {
    assertStringNotNullAndNotTrimmedEmpty("columnFlexibleName", columnFlexibleName);
    final Map<String, ColumnInfo> flexibleMap = getColumnInfoFlexibleMap();
    final ColumnInfo columnInfo = flexibleMap.get(columnFlexibleName);
    if (columnInfo == null) {
        final String notice = "The column info was not found.";
        final String keyName = "Column";
        throwDBMetaNotFoundException(notice, keyName, columnFlexibleName, flexibleMap.keySet());
    }
    return columnInfo;
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 9 with ColumnInfo

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

the class AbstractDBMeta method doConvertToEntity.

protected <ENTITY extends Entity> void doConvertToEntity(ENTITY entity, Map<String, ? extends Object> columnMap, boolean pkOnly) {
    final List<ColumnInfo> columnInfoList = pkOnly ? getPrimaryInfo().getPrimaryColumnList() : getColumnInfoList();
    final MetaHandlingMapToEntityMapper mapper = createMetaHandlingMapToEntityMapper(columnMap);
    mapper.mappingToEntity(entity, columnMap, columnInfoList);
}
Also used : MetaHandlingMapToEntityMapper(org.dbflute.dbmeta.valuemap.MetaHandlingMapToEntityMapper) ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo)

Example 10 with ColumnInfo

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

the class AbstractDBMeta method doSearchMetaInfoList.

protected <INFO> List<INFO> doSearchMetaInfoList(Collection<ColumnInfo> columnInfoList, List<INFO> infoList, Function<INFO, Collection<ColumnInfo>> oneArgLambda) {
    if (infoList.isEmpty()) {
        return DfCollectionUtil.emptyList();
    }
    final Set<ColumnInfo> specifiedColSet = new HashSet<ColumnInfo>(columnInfoList);
    final List<INFO> foundInfoList = newArrayListSized(infoList.size());
    for (INFO info : infoList) {
        final Collection<ColumnInfo> columnList = oneArgLambda.apply(info);
        boolean notFound = false;
        for (ColumnInfo metaCol : columnList) {
            if (!specifiedColSet.contains(metaCol)) {
                notFound = true;
                break;
            }
        }
        if (!notFound) {
            foundInfoList.add(info);
        }
    }
    return Collections.unmodifiableList(foundInfoList);
}
Also used : ColumnInfo(org.dbflute.dbmeta.info.ColumnInfo) HashSet(java.util.HashSet)

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