use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class TnQueryUpdateDynamicCommand method buildQueryUpdateTwoWaySql.
// ===================================================================================
// Build SQL
// =========
/**
* @param entity The entity for update. (NotNull)
* @param cb The condition-beanĀ for query. (NotNull)
* @param option The option of update. (NullAllowed)
* @param boundPropTypeList The type list of bound property. (NotNull, AlwaysEmpty)
* @return The two-way SQL of query update. (NullAllowed: if non-modification, return null)
*/
protected String buildQueryUpdateTwoWaySql(Entity entity, ConditionBean cb, final UpdateOption<ConditionBean> option, List<TnPropertyType> boundPropTypeList) {
final Map<String, Object> columnParameterMap = new LinkedHashMap<String, Object>();
final DBMeta dbmeta = entity.asDBMeta();
final Set<String> modifiedSet = entity.mymodifiedProperties();
final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
for (final ColumnInfo columnInfo : columnInfoList) {
if (columnInfo.isOptimisticLock()) {
// exclusive control columns are processed after here
continue;
}
final String columnDbName = columnInfo.getColumnDbName();
if (option != null && option.hasStatement(columnDbName)) {
// prior to specified
columnParameterMap.put(columnDbName, new SqlClause.QueryUpdateSetCalculationHandler() {
public String buildStatement(String aliasName) {
return option.buildStatement(columnDbName, aliasName);
}
});
continue;
}
if (isSpecifiedProperty(option, modifiedSet, columnInfo)) {
final String propertyName = columnInfo.getPropertyName();
final Object value = columnInfo.read(entity);
if (value != null) {
columnParameterMap.put(columnDbName, "/*entity." + propertyName + "*/null");
// add bound property type
final TnPropertyType propertyType = _beanMetaData.getPropertyType(propertyName);
boundPropTypeList.add(propertyType);
} else {
// it uses null literal on query
// because the SQL analyzer blocks null parameters
// (the analyzer should do it for condition-bean)
columnParameterMap.put(columnDbName, "null");
}
continue;
}
}
if (columnParameterMap.isEmpty()) {
return null;
}
if (dbmeta.hasVersionNo()) {
final ColumnInfo columnInfo = dbmeta.getVersionNoColumnInfo();
final String columnDbName = columnInfo.getColumnDbName();
columnParameterMap.put(columnDbName, new SqlClause.QueryUpdateSetCalculationHandler() {
public String buildStatement(String aliasName) {
// cipher for versionNo is unsupported
final ColumnSqlName columnSqlName = columnInfo.getColumnSqlName();
return (aliasName != null ? aliasName : "") + columnSqlName + " + 1";
}
});
}
if (dbmeta.hasUpdateDate()) {
ColumnInfo columnInfo = dbmeta.getUpdateDateColumnInfo();
columnInfo.write(entity, ResourceContext.getAccessTimestamp());
final String columnDbName = columnInfo.getColumnDbName();
final String propertyName = columnInfo.getPropertyName();
columnParameterMap.put(columnDbName, "/*entity." + propertyName + "*/null");
// add bound property type
boundPropTypeList.add(_beanMetaData.getPropertyType(propertyName));
}
if (option != null && option.isQueryUpdateForcedDirectAllowed()) {
cb.getSqlClause().enableQueryUpdateForcedDirect();
}
return cb.getSqlClause().getClauseQueryUpdate(columnParameterMap);
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class TnQueryInsertDynamicCommand method buildQueryInsertTwoWaySql.
// ===================================================================================
// Build SQL
// =========
/**
* @param entity The entity for fixed values. (NotNull)
* @param intoCB The condition-bean for insert into. (NotNull)
* @param resourceCB The condition-bean for resource. (NotNull)
* @param option The option of insert. (NullAllowed)
* @param boundPropTypeList The type list of bound property. (NotNull, Empty)
* @return The two-way SQL of query-insert. (NotNull)
*/
protected String buildQueryInsertTwoWaySql(Entity entity, ConditionBean intoCB, ConditionBean resourceCB, InsertOption<ConditionBean> option, List<TnPropertyType> boundPropTypeList) {
final StringKeyMap<String> fixedValueQueryExpMap = StringKeyMap.createAsFlexibleOrdered();
final Set<String> modifiedProperties = entity.mymodifiedProperties();
final DBMeta dbmeta = entity.asDBMeta();
final List<ColumnInfo> columnInfoList = dbmeta.getColumnInfoList();
for (ColumnInfo columnInfo : columnInfoList) {
final String propertyName = columnInfo.getPropertyName();
if (!modifiedProperties.contains(propertyName)) {
continue;
}
final Object value = columnInfo.read(entity);
final String fixedValueQueryExp = (value != null ? "/*entity." + propertyName + "*/null" : null);
fixedValueQueryExpMap.put(columnInfo.getColumnDbName(), fixedValueQueryExp);
}
return intoCB.getSqlClause().getClauseQueryInsert(fixedValueQueryExpMap, resourceCB.getSqlClause());
}
use of org.dbflute.dbmeta.info.ColumnInfo in project dbflute-core by dbflute.
the class TnDBMetaBeanAnnotationReader method getRelationKey.
public String getRelationKey(DfPropertyDesc pd) {
if (_simpleType) {
return null;
}
if (_fieldBeanAnnotationReader != null) {
return _fieldBeanAnnotationReader.getRelationKey(pd);
}
if (!_dbmeta.hasForeign(pd.getPropertyName())) {
return null;
}
final ForeignInfo foreignInfo = _dbmeta.findForeignInfo(pd.getPropertyName());
final Map<ColumnInfo, ColumnInfo> localForeignColumnInfoMap = foreignInfo.getLocalForeignColumnInfoMap();
final Set<ColumnInfo> keySet = localForeignColumnInfoMap.keySet();
final StringBuilder sb = new StringBuilder();
for (ColumnInfo localColumnInfo : keySet) {
final ColumnInfo foreignColumnInfo = localForeignColumnInfoMap.get(localColumnInfo);
if (sb.length() > 0) {
sb.append(", ");
}
sb.append(localColumnInfo.getColumnDbName());
sb.append(":").append(foreignColumnInfo.getColumnDbName());
}
return sb.toString();
}
Aggregations