Search in sources :

Example 6 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.

the class TnBeanMetaDataFactoryExtension method createBeanMetaDataImpl.

@Override
protected TnBeanMetaDataImpl createBeanMetaDataImpl(Class<?> beanClass) {
    // /= = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = =
    // for ConditionBean and insert() and update() and delete() and so on...
    // = = = = = = = = = =/
    final DBMeta dbmeta = provideDBMeta(beanClass);
    return new TnBeanMetaDataImpl(beanClass, dbmeta) {

        /**
         * The internal list of identifier generator. Elements of this list should be added when initializing.
         */
        protected final List<TnIdentifierGenerator> _internalIdentifierGeneratorList = new ArrayList<TnIdentifierGenerator>();

        /**
         * The internal map of identifier generator by property name.
         */
        protected final Map<String, TnIdentifierGenerator> _internalIdentifierGeneratorsByPropertyName = newConcurrentHashMap();

        // /= = = = = = =
        // for cache
        // = = = = =/
        @Override
        public void initialize() {
            // non thread safe so this is called immediately after creation
            final Class<?> myBeanClass = getBeanClass();
            if (isDBFluteEntity(myBeanClass)) {
                final TnBeanMetaData cachedMeta = getMetaFromCache(myBeanClass);
                if (cachedMeta == null) {
                    if (isInternalDebugEnabled()) {
                        _log.debug("...Caching the bean: " + DfTypeUtil.toClassTitle(myBeanClass));
                    }
                    _metaMap.put(myBeanClass, this);
                }
            }
            super.initialize();
        }

        // /= = = = = = =
        // for insert()
        // = = = = =/
        // The attributes 'identifierGenerators' and 'identifierGeneratorsByPropertyName'
        // of super class are unused. It prepares original attributes here.
        @Override
        protected void setupIdentifierGenerator(TnPropertyType propertyType) {
            // only called in the initialize() process
            final DfPropertyDesc pd = propertyType.getPropertyDesc();
            final String propertyName = propertyType.getPropertyName();
            final String idType = _beanAnnotationReader.getId(pd);
            final TnIdentifierGenerator generator = createInternalIdentifierGenerator(propertyType, idType);
            _internalIdentifierGeneratorList.add(generator);
            _internalIdentifierGeneratorsByPropertyName.put(propertyName, generator);
        }

        protected TnIdentifierGenerator createInternalIdentifierGenerator(TnPropertyType propertyType, String idType) {
            return TnIdentifierGeneratorFactory.createIdentifierGenerator(propertyType, idType);
        }

        @Override
        public TnIdentifierGenerator getIdentifierGenerator(int index) {
            return _internalIdentifierGeneratorList.get(index);
        }

        @Override
        public int getIdentifierGeneratorSize() {
            return _internalIdentifierGeneratorList.size();
        }

        @Override
        public TnIdentifierGenerator getIdentifierGenerator(String propertyName) {
            return _internalIdentifierGeneratorsByPropertyName.get(propertyName);
        }
    };
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) DBMeta(org.dbflute.dbmeta.DBMeta) TnBeanMetaData(org.dbflute.s2dao.metadata.TnBeanMetaData) ArrayList(java.util.ArrayList) List(java.util.List) TnBeanMetaDataImpl(org.dbflute.s2dao.metadata.impl.TnBeanMetaDataImpl) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType) TnIdentifierGenerator(org.dbflute.s2dao.identity.TnIdentifierGenerator)

Example 7 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.

the class TnRelationRowOptionalHandler method filterOptionalRelationRowIfNeeds.

// ===================================================================================
// Filtering
// =========
/**
 * Filter the relation row as optional object if it needs.
 * @param row The base point row, which is previous relation row. (NotNull)
 * @param rpt The property type for the relation. (NotNull)
 * @param relationRow The row instance of relation entity. (NullAllowed)
 * @return The filtered instance of relation entity. (NullAllowed)
 */
public Object filterOptionalRelationRowIfNeeds(Object row, TnRelationPropertyType rpt, Object relationRow) {
    final Class<?> optionalType = getOptionalEntityType();
    final DfPropertyDesc pd = rpt.getPropertyDesc();
    if (optionalType.isAssignableFrom(pd.getPropertyType())) {
        if (relationRow == null) {
            return createOptionalNullEntity(row, rpt);
        }
        if (!optionalType.isInstance(relationRow)) {
            return createOptionalPresentEntity(relationRow);
        }
    }
    return relationRow;
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc)

Example 8 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.

the class TnIdentifierGeneratorFactory method setProperty.

protected static void setProperty(TnIdentifierGenerator generator, String propertyName, String value) {
    final DfBeanDesc beanDesc = DfBeanDescFactory.getBeanDesc(generator.getClass());
    final DfPropertyDesc pd = beanDesc.getPropertyDesc(propertyName);
    pd.setValue(generator, value);
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Example 9 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.

the class TnDBMetaPropertyTypeFactory method createBeanPropertyTypes.

// ===================================================================================
// Implementation
// ==============
public TnPropertyType[] createBeanPropertyTypes() {
    final List<TnPropertyType> list = new ArrayList<TnPropertyType>();
    final DfBeanDesc beanDesc = getBeanDesc();
    final List<String> proppertyNameList = beanDesc.getProppertyNameList();
    for (String proppertyName : proppertyNameList) {
        final DfPropertyDesc pd = beanDesc.getPropertyDesc(proppertyName);
        // read-only property (that is NOT column) is unnecessary!
        if (!pd.isWritable()) {
            // is set by classification writer method.
            if (!isColumn(pd)) {
                continue;
            }
        }
        // (because native type is valid)
        if (isClassification(pd)) {
            continue;
        }
        // (because a relation mapping is other process)
        if (isRelation(pd)) {
            continue;
        }
        final TnPropertyType pt = createPropertyType(pd);
        pt.setPrimaryKey(isPrimaryKey(pd));
        pt.setPersistent(isPersistent(pt));
        list.add(pt);
    }
    return list.toArray(new TnPropertyType[list.size()]);
}
Also used : DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) ArrayList(java.util.ArrayList) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Example 10 with DfPropertyDesc

use of org.dbflute.helper.beans.DfPropertyDesc in project dbflute-core by dbflute.

the class TnRelationPropertyTypeFactoryImpl method createRelationPropertyTypes.

// ===================================================================================
// Create Relation
// ===============
public TnRelationPropertyType[] createRelationPropertyTypes() {
    final List<TnRelationPropertyType> relList = new ArrayList<TnRelationPropertyType>(RELATION_SIZE_CAPACITY);
    final DfBeanDesc localBeanDesc = getLocalBeanDesc();
    final List<String> proppertyNameList = localBeanDesc.getProppertyNameList();
    for (String proppertyName : proppertyNameList) {
        final DfPropertyDesc propertyDesc = localBeanDesc.getPropertyDesc(proppertyName);
        if (_stopRelationCreation || !isRelationProperty(propertyDesc)) {
            continue;
        }
        relList.add(createRelationPropertyType(propertyDesc));
    }
    return relList.toArray(new TnRelationPropertyType[relList.size()]);
}
Also used : TnRelationPropertyType(org.dbflute.s2dao.metadata.TnRelationPropertyType) DfPropertyDesc(org.dbflute.helper.beans.DfPropertyDesc) ArrayList(java.util.ArrayList) DfBeanDesc(org.dbflute.helper.beans.DfBeanDesc)

Aggregations

DfPropertyDesc (org.dbflute.helper.beans.DfPropertyDesc)22 DfBeanDesc (org.dbflute.helper.beans.DfBeanDesc)10 ArrayList (java.util.ArrayList)4 Map (java.util.Map)4 List (java.util.List)3 DfBeanIllegalPropertyException (org.dbflute.helper.beans.exception.DfBeanIllegalPropertyException)3 MapParameterBean (org.dbflute.twowaysql.pmbean.MapParameterBean)3 TnIdentifierGenerator (org.dbflute.s2dao.identity.TnIdentifierGenerator)2 TnPropertyType (org.dbflute.s2dao.metadata.TnPropertyType)2 Field (java.lang.reflect.Field)1 Method (java.lang.reflect.Method)1 Timestamp (java.sql.Timestamp)1 Set (java.util.Set)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 Entity (org.dbflute.Entity)1 DBMeta (org.dbflute.dbmeta.DBMeta)1 DfBeanMethodNotFoundException (org.dbflute.helper.beans.exception.DfBeanMethodNotFoundException)1 TnBeanMetaData (org.dbflute.s2dao.metadata.TnBeanMetaData)1 TnModifiedPropertySupport (org.dbflute.s2dao.metadata.TnModifiedPropertySupport)1 TnRelationPropertyType (org.dbflute.s2dao.metadata.TnRelationPropertyType)1