Search in sources :

Example 6 with TnRelationPropertyType

use of org.dbflute.s2dao.metadata.TnRelationPropertyType in project dbflute-core by dbflute.

the class TnBeanMetaDataImpl method setupProperty.

protected void setupProperty() {
    // only called in the initialize() process
    final TnPropertyType[] propertyTypes = _propertyTypeFactory.createBeanPropertyTypes();
    for (int i = 0; i < propertyTypes.length; i++) {
        TnPropertyType pt = propertyTypes[i];
        addPropertyType(pt);
        _columnPropertyTypeMap.put(pt.getColumnDbName(), pt);
    }
    final TnRelationPropertyType[] rptTypes = _relationPropertyTypeFactory.createRelationPropertyTypes();
    for (int i = 0; i < rptTypes.length; i++) {
        TnRelationPropertyType rpt = rptTypes[i];
        addRelationPropertyType(rpt);
    }
}
Also used : TnRelationPropertyType(org.dbflute.s2dao.metadata.TnRelationPropertyType) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType)

Example 7 with TnRelationPropertyType

use of org.dbflute.s2dao.metadata.TnRelationPropertyType in project dbflute-core by dbflute.

the class TnRelationRowCreatorExtension method setupNextRelationRow.

// -----------------------------------------------------
// Next Relation
// -------------
protected void setupNextRelationRow(TnRelationRowCreationResource res) throws SQLException {
    final TnBeanMetaData nextBmd = res.getRelationBeanMetaData();
    final Object row = res.getRow();
    res.prepareNextLevelMapping();
    try {
        final List<TnRelationPropertyType> nextRptList = nextBmd.getRelationPropertyTypeList();
        for (TnRelationPropertyType nextRpt : nextRptList) {
            setupNextRelationRowElement(res, row, nextRpt);
        }
    } finally {
        res.setRow(row);
        res.closeNextLevelMapping();
    }
}
Also used : TnRelationPropertyType(org.dbflute.s2dao.metadata.TnRelationPropertyType) TnBeanMetaData(org.dbflute.s2dao.metadata.TnBeanMetaData)

Example 8 with TnRelationPropertyType

use of org.dbflute.s2dao.metadata.TnRelationPropertyType in project dbflute-core by dbflute.

the class TnRelationRowCreatorExtension method mappingNextRelation.

/**
 * Do mapping next relation row. <br>
 * This logic is similar to first relation mapping in {@link TnBeanListResultSetHandler}. <br>
 * So you should check it when this logic has modification.
 * @param res The resource of relation row creation. (NotNull)
 * @param row The base point row, which is previous relation row. (NotNull)
 * @throws SQLException When it fails to handle the SQL.
 */
protected void mappingNextRelation(TnRelationRowCreationResource res, Object row) throws SQLException {
    if (res.isStopCurrentRelationMapping()) {
        return;
    }
    // also saves it in resource
    final TnRelationKey relKey = res.prepareRelationKey();
    final TnRelationPropertyType rpt = res.getRelationPropertyType();
    Object relationRow = null;
    if (relKey != null) {
        final String relationNoSuffix = res.getRelationNoSuffix();
        final boolean canUseRelationCache = res.canUseRelationCache();
        TnRelationRowCache relRowCache = null;
        if (canUseRelationCache) {
            relRowCache = res.getRelRowCache();
            relationRow = relRowCache.getRelationRow(relationNoSuffix, relKey);
        }
        if (relationRow == null) {
            // when no cache
            relationRow = createRelationRow(res);
            if (relationRow != null) {
                // is new created relation row
                adjustCreatedRelationRow(relationRow, res.getRelationNoSuffix(), res.getRelationSelector(), rpt);
                if (canUseRelationCache) {
                    relRowCache.addRelationRow(relationNoSuffix, relKey, relationRow);
                }
            }
        }
    }
    // if exists, optional or plain value
    // if null, empty optional or nothing
    relationRow = filterOptionalRelationRowIfNeeds(row, rpt, relationRow);
    if (relationRow != null) {
        // exists or empty optional
        rpt.getPropertyAccessor().setValue(row, relationRow);
    }
}
Also used : TnRelationPropertyType(org.dbflute.s2dao.metadata.TnRelationPropertyType) TnRelationKey(org.dbflute.s2dao.rowcreator.TnRelationKey) TnRelationRowCache(org.dbflute.s2dao.rowcreator.TnRelationRowCache)

Example 9 with TnRelationPropertyType

use of org.dbflute.s2dao.metadata.TnRelationPropertyType in project dbflute-core by dbflute.

the class TnRelationRowCreatorExtension method setupRelationKeyValue.

// ===================================================================================
// Relation KeyValue Setup
// =======================
@Override
protected void setupRelationKeyValue(TnRelationRowCreationResource res) {
    // /= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    // setup of relation key is handled at all-value setup marked as '#RELKEY'
    // so only entity instance creation exists in this method
    // = = = = = = = = = =/
    final TnRelationPropertyType rpt = res.getRelationPropertyType();
    final TnBeanMetaData yourBmd = rpt.getYourBeanMetaData();
    if (!res.hasRowInstance()) {
        // always no instance here (check just in case)
        final DBMeta dbmeta = yourBmd.getDBMeta();
        final Object row = newRelationRow(rpt, res.getRelationSelector(), res.getRelationNoSuffix(), dbmeta);
        res.setRow(row);
    }
}
Also used : TnRelationPropertyType(org.dbflute.s2dao.metadata.TnRelationPropertyType) DBMeta(org.dbflute.dbmeta.DBMeta) TnBeanMetaData(org.dbflute.s2dao.metadata.TnBeanMetaData)

Example 10 with TnRelationPropertyType

use of org.dbflute.s2dao.metadata.TnRelationPropertyType in project dbflute-core by dbflute.

the class TnBeanMetaDataImpl method convertFullColumnName.

public String convertFullColumnName(String alias) {
    if (hasPropertyTypeByColumnName(alias)) {
        return _tableName + "." + alias;
    }
    final int index = alias.lastIndexOf('_');
    if (index < 0) {
        String msg = "The alias was not found in the table: table=" + _tableName + " alias=" + alias;
        throw new IllegalStateException(msg);
    }
    final String columnName = alias.substring(0, index);
    final String relnoStr = alias.substring(index + 1);
    int relno = -1;
    try {
        relno = Integer.parseInt(relnoStr);
    } catch (Throwable t) {
        String msg = "The alias was not found in the table: table=" + _tableName + " alias=" + alias;
        throw new IllegalStateException(msg, t);
    }
    final TnRelationPropertyType rpt = getRelationPropertyType(relno);
    if (!rpt.getYourBeanMetaData().hasPropertyTypeByColumnName(columnName)) {
        String msg = "The alias was not found in the table: table=" + _tableName + " alias=" + alias;
        throw new IllegalStateException(msg);
    }
    return rpt.getPropertyName() + "." + columnName;
}
Also used : TnRelationPropertyType(org.dbflute.s2dao.metadata.TnRelationPropertyType)

Aggregations

TnRelationPropertyType (org.dbflute.s2dao.metadata.TnRelationPropertyType)10 TnBeanMetaData (org.dbflute.s2dao.metadata.TnBeanMetaData)3 Map (java.util.Map)2 TnRelationRowCache (org.dbflute.s2dao.rowcreator.TnRelationRowCache)2 ArrayList (java.util.ArrayList)1 ConditionBean (org.dbflute.cbean.ConditionBean)1 DBMeta (org.dbflute.dbmeta.DBMeta)1 StringKeyMap (org.dbflute.helper.StringKeyMap)1 DfBeanDesc (org.dbflute.helper.beans.DfBeanDesc)1 DfPropertyDesc (org.dbflute.helper.beans.DfPropertyDesc)1 OutsideSqlContext (org.dbflute.outsidesql.OutsideSqlContext)1 TnPropertyMapping (org.dbflute.s2dao.metadata.TnPropertyMapping)1 TnPropertyType (org.dbflute.s2dao.metadata.TnPropertyType)1 TnRelationKey (org.dbflute.s2dao.rowcreator.TnRelationKey)1 TnRelationRowCreationResource (org.dbflute.s2dao.rowcreator.TnRelationRowCreationResource)1 TnRelationSelector (org.dbflute.s2dao.rowcreator.TnRelationSelector)1