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;
}
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(" = ?");
}
}
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()]);
}
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);
}
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();
}
Aggregations