Search in sources :

Example 16 with TnPropertyType

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

the class TnRelationRowCache method doCreateRelationKeyCompound.

protected TnRelationKey doCreateRelationKeyCompound(ResultSet rs, TnRelationPropertyType rpt, Map<String, String> selectColumnMap, Map<String, Map<String, Integer>> selectIndexMap, String relationNoSuffix) throws SQLException {
    final List<TnPropertyType> uniquePropertyTypeList = rpt.getUniquePropertyTypeList();
    Map<String, Object> relKeyValues = null;
    for (TnPropertyType pt : uniquePropertyTypeList) {
        final String columnKeyName = buildColumnKeyName(pt, relationNoSuffix);
        final Object keyValue = setupKeyElement(rs, rpt, selectColumnMap, selectIndexMap, columnKeyName, pt, relationNoSuffix);
        if (keyValue == null) {
            if (relKeyValues != null) {
                relKeyValues.clear();
            }
            // if either one is null, treated as no data
            break;
        }
        if (relKeyValues == null) {
            // lazy-load for performance
            relKeyValues = new HashMap<String, Object>(uniquePropertyTypeList.size());
        }
        relKeyValues.put(columnKeyName, keyValue);
    }
    return (relKeyValues != null && !relKeyValues.isEmpty()) ? new TnRelationKeyCompound(relKeyValues) : null;
}
Also used : TnRelationKeyCompound(org.dbflute.s2dao.rowcreator.impl.TnRelationKeyCompound) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType)

Example 17 with TnPropertyType

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

the class TnAbstractEntityDynamicCommand method setupUpdateWhere.

protected void setupUpdateWhere(StringBuilder sb, Set<String> uniqueDrivenPropSet, boolean optimisticLockHandling) {
    final TnBeanMetaData bmd = _beanMetaData;
    sb.append(" where ");
    prepareWherePrimaryKey(sb, uniqueDrivenPropSet);
    if (optimisticLockHandling && bmd.hasVersionNoPropertyType()) {
        final TnPropertyType pt = bmd.getVersionNoPropertyType();
        sb.append(" and ").append(pt.getColumnSqlName()).append(" = ?");
    }
    if (optimisticLockHandling && bmd.hasTimestampPropertyType()) {
        final TnPropertyType pt = bmd.getTimestampPropertyType();
        sb.append(" and ").append(pt.getColumnSqlName()).append(" = ?");
    }
}
Also used : TnBeanMetaData(org.dbflute.s2dao.metadata.TnBeanMetaData) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType)

Example 18 with TnPropertyType

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

the class TnInsertEntityDynamicCommand method createInsertPropertyTypes.

// ===================================================================================
// Insert Column
// =============
protected TnPropertyType[] createInsertPropertyTypes(TnBeanMetaData bmd, Object bean, String[] propertyNames, InsertOption<ConditionBean> option) {
    if (0 == propertyNames.length) {
        String msg = "The property name was not found in the bean: " + bean;
        throw new IllegalStateException(msg);
    }
    final List<TnPropertyType> typeList = new ArrayList<TnPropertyType>();
    final Set<?> modifiedSet = getModifiedPropertyNames(bean);
    final String timestampProp = bmd.getTimestampPropertyName();
    final String versionNoProp = bmd.getVersionNoPropertyName();
    for (int i = 0; i < propertyNames.length; ++i) {
        final TnPropertyType pt = bmd.getPropertyType(propertyNames[i]);
        if (pt.isPrimaryKey()) {
            if (option == null || !option.isPrimaryKeyIdentityDisabled()) {
                final TnIdentifierGenerator generator = bmd.getIdentifierGenerator(pt.getPropertyName());
                if (!generator.isSelfGenerate()) {
                    continue;
                }
            }
            typeList.add(pt);
        } else {
            if (// OptimisticLock
            isOptimisticLockProperty(timestampProp, versionNoProp, pt) || isSpecifiedProperty(bean, option, modifiedSet, pt)) {
                // Specified
                typeList.add(pt);
            }
        }
    }
    if (typeList.isEmpty()) {
        throwEntityInsertPropertyNotFoundException(bmd, bean);
    }
    return (TnPropertyType[]) typeList.toArray(new TnPropertyType[typeList.size()]);
}
Also used : ArrayList(java.util.ArrayList) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType) TnIdentifierGenerator(org.dbflute.s2dao.identity.TnIdentifierGenerator)

Example 19 with TnPropertyType

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

the class TnInsertEntityDynamicCommand method execute.

// ===================================================================================
// Execute
// =======
public Object execute(Object[] args) {
    final Object bean = extractBeanFromArgsChecked(args);
    final InsertOption<ConditionBean> option = extractInsertOptionChecked(args);
    prepareStatementConfigOnThreadIfExists(option);
    final TnBeanMetaData bmd = _beanMetaData;
    final TnPropertyType[] propertyTypes = createInsertPropertyTypes(bmd, bean, _propertyNames, option);
    final String sql = filterExecutedSql(createInsertSql(bmd, propertyTypes, option));
    return doExecute(bean, propertyTypes, sql, option);
}
Also used : TnBeanMetaData(org.dbflute.s2dao.metadata.TnBeanMetaData) ConditionBean(org.dbflute.cbean.ConditionBean) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType)

Example 20 with TnPropertyType

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

the class TnInsertEntityDynamicCommand method createInsertSql.

// ===================================================================================
// Insert SQL
// ==========
protected String createInsertSql(TnBeanMetaData bmd, TnPropertyType[] propertyTypes, InsertOption<ConditionBean> option) {
    final String tableDbName = _targetDBMeta.getTableDbName();
    final StringBuilder columnSb = new StringBuilder(48);
    final StringBuilder valuesSb = new StringBuilder(48);
    for (int i = 0; i < propertyTypes.length; ++i) {
        final TnPropertyType pt = propertyTypes[i];
        final ColumnSqlName columnSqlName = pt.getColumnSqlName();
        if (i > 0) {
            columnSb.append(", ");
            valuesSb.append(", ");
        }
        columnSb.append(columnSqlName);
        final String columnDbName = pt.getColumnDbName();
        valuesSb.append(encryptIfNeeds(tableDbName, columnDbName, "?"));
    }
    final StringBuilder sb = new StringBuilder(128);
    sb.append("insert into ").append(_targetDBMeta.getTableSqlName());
    sb.append(" (").append(columnSb).append(")");
    sb.append(ln()).append(" values (").append(valuesSb).append(")");
    return sb.toString();
}
Also used : ColumnSqlName(org.dbflute.dbmeta.name.ColumnSqlName) TnPropertyType(org.dbflute.s2dao.metadata.TnPropertyType)

Aggregations

TnPropertyType (org.dbflute.s2dao.metadata.TnPropertyType)25 ArrayList (java.util.ArrayList)12 TnBeanMetaData (org.dbflute.s2dao.metadata.TnBeanMetaData)7 ConditionBean (org.dbflute.cbean.ConditionBean)3 DBMeta (org.dbflute.dbmeta.DBMeta)3 ColumnSqlName (org.dbflute.dbmeta.name.ColumnSqlName)3 ValueType (org.dbflute.jdbc.ValueType)3 Timestamp (java.sql.Timestamp)2 Entity (org.dbflute.Entity)2 ColumnInfo (org.dbflute.dbmeta.info.ColumnInfo)2 DfPropertyDesc (org.dbflute.helper.beans.DfPropertyDesc)2 TnIdentifierGenerator (org.dbflute.s2dao.identity.TnIdentifierGenerator)2 TnCommandContextHandler (org.dbflute.s2dao.sqlhandler.TnCommandContextHandler)2 CommandContext (org.dbflute.twowaysql.context.CommandContext)2 LinkedHashMap (java.util.LinkedHashMap)1 List (java.util.List)1 Map (java.util.Map)1 Entry (java.util.Map.Entry)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 SqlClause (org.dbflute.cbean.sqlclause.SqlClause)1