use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class TnUpdateEntityDynamicCommand method createUpdateSql.
// ===================================================================================
// Update SQL
// ==========
/**
* Create update SQL. The update is by the primary keys or unique keys.
* @param bean The bean of the entity to update. (NotNull)
* @param propertyTypes The types of property for update. (NotNull)
* @param option An option of update. (NullAllowed)
* @return The update SQL. (NotNull)
*/
protected String createUpdateSql(Object bean, TnPropertyType[] propertyTypes, UpdateOption<ConditionBean> option) {
checkPrimaryKey();
final String tableDbName = _targetDBMeta.getTableDbName();
final Set<String> uniqueDrivenPropSet = extractUniqueDrivenPropSet(bean);
final StringBuilder sb = new StringBuilder(96);
sb.append("update ").append(_targetDBMeta.getTableSqlName()).append(" set ");
final String versionNoPropertyName = _beanMetaData.getVersionNoPropertyName();
int columnCount = 0;
for (TnPropertyType pt : propertyTypes) {
final String columnDbName = pt.getColumnDbName();
final ColumnSqlName columnSqlName = pt.getColumnSqlName();
final String propertyName = pt.getPropertyName();
if (uniqueDrivenPropSet != null && uniqueDrivenPropSet.contains(propertyName)) {
if (option != null && option.hasStatement(columnDbName)) {
throwUniqueDrivenColumnUpdateStatementException(tableDbName, columnDbName, uniqueDrivenPropSet);
}
continue;
}
if (columnCount > 0) {
sb.append(", ");
}
++columnCount;
if (propertyName.equalsIgnoreCase(versionNoPropertyName)) {
if (!isVersionNoAutoIncrementOnMemory()) {
setupVersionNoAutoIncrementOnQuery(sb, columnSqlName);
continue;
}
}
sb.append(columnSqlName).append(" = ");
final String valueExp;
if (option != null && option.hasStatement(columnDbName)) {
// prior to specified
final String statement = option.buildStatement(columnDbName);
valueExp = encryptIfNeeds(tableDbName, columnDbName, statement);
} else {
valueExp = encryptIfNeeds(tableDbName, columnDbName, "?");
}
sb.append(valueExp);
}
sb.append(ln());
setupUpdateWhere(sb, uniqueDrivenPropSet, _optimisticLockHandling);
return sb.toString();
}
use of org.dbflute.dbmeta.name.ColumnSqlName in project dbflute-core by dbflute.
the class TnAbstractEntityDynamicCommand method prepareWherePrimaryKey.
protected void prepareWherePrimaryKey(StringBuilder sb, Set<String> uniqueDrivenPropSet) {
final String bindingSuffix = " = ?";
final String connectorSuffix = " and ";
if (uniqueDrivenPropSet != null && !uniqueDrivenPropSet.isEmpty()) {
for (String uniqueProp : uniqueDrivenPropSet) {
final ColumnSqlName sqlName = _targetDBMeta.findColumnInfo(uniqueProp).getColumnSqlName();
sb.append(sqlName).append(bindingSuffix).append(connectorSuffix);
}
} else {
// basically here
for (int i = 0; i < _beanMetaData.getPrimaryKeySize(); i++) {
// never zero loop
ColumnSqlName sqlName = _beanMetaData.getPrimaryKeySqlName(i);
sb.append(sqlName).append(bindingSuffix).append(connectorSuffix);
}
}
// for deleting extra ' and '
sb.setLength(sb.length() - connectorSuffix.length());
}
use of org.dbflute.dbmeta.name.ColumnSqlName 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();
}
Aggregations