protected void SetupUpdateWhere(StringBuilder sb) { IBeanMetaData bmd = BeanMetaData; sb.Append(" WHERE "); for (int i = 0; i < bmd.PrimaryKeySize; ++i) { sb.Append(bmd.GetPrimaryKey(i)); sb.Append(" = ? AND "); } sb.Length = sb.Length - 5; if (bmd.HasVersionNoPropertyType) { IPropertyType pt = bmd.VersionNoPropertyType; sb.Append(" AND "); sb.Append(pt.ColumnName); sb.Append(" = ?"); } if (bmd.HasTimestampPropertyType) { IPropertyType pt = bmd.TimestampPropertyType; sb.Append(" AND "); sb.Append(pt.ColumnName); sb.Append(" = ?"); } }
protected void AddAutoUpdateWhereBindVariables(ArrayList varList, ArrayList varTypeList, Object bean) { IBeanMetaData bmd = BeanMetaData; for (int i = 0; i < bmd.PrimaryKeySize; ++i) { IPropertyType pt = bmd.GetPropertyTypeByColumnName(bmd.GetPrimaryKey(i)); PropertyInfo pi = pt.PropertyInfo; varList.Add(pi.GetValue(bean, null)); varTypeList.Add(pi.PropertyType); } if (bmd.HasVersionNoPropertyType) { IPropertyType pt = bmd.VersionNoPropertyType; PropertyInfo pi = pt.PropertyInfo; varList.Add(pi.GetValue(bean, null)); varTypeList.Add(pi.PropertyType); } if (bmd.HasTimestampPropertyType) { IPropertyType pt = bmd.TimestampPropertyType; PropertyInfo pi = pt.PropertyInfo; varList.Add(pi.GetValue(bean, null)); varTypeList.Add(pi.PropertyType); } }
protected virtual string CreateNoUpdateLogMessage(object bean, IBeanMetaData bmd) { StringBuilder builder = new StringBuilder(); builder.Append("skip UPDATE: table="); builder.Append(bmd.TableName); int size = bmd.PrimaryKeySize; for (int i = 0; i < size; i++) { if (i == 0) { builder.Append(", key{"); } else { builder.Append(", "); } string keyName = bmd.GetPrimaryKey(i); builder.Append(keyName); builder.Append("="); builder.Append(bmd.GetPropertyTypeByColumnName(keyName) .PropertyInfo.GetValue(bean, null)); if (i == size - 1) { builder.Append("}"); } } return(builder.ToString()); }
protected virtual String CreateUpdateSql(IBeanMetaData bmd, IPropertyType[] propertyTypes, Object bean) { if (bmd.PrimaryKeySize == 0) { String msg = "The table '" + bmd.TableName + "' does not have primary keys!"; throw new SystemException(msg); } StringBuilder sb = new StringBuilder(100); sb.Append("UPDATE ").Append(bmd.TableName).Append(" SET "); String versionNoPropertyName = bmd.VersionNoPropertyName; for (int i = 0; i < propertyTypes.Length; ++i) { IPropertyType pt = propertyTypes[i]; String columnName = pt.ColumnName; if (i > 0) { sb.Append(", "); } if (String.Compare(pt.PropertyName, versionNoPropertyName, true) == 0) { if (!IsVersionNoAutoIncrementOnMemory()) { SetupVersionNoAutoIncrementOnQuery(sb, columnName); continue;// because of always 'VERSION_NO = VERSION_NO + 1' } Object value = pt.PropertyInfo.GetValue(bean, null); if (value == null) { SetupVersionNoAutoIncrementOnQuery(sb, columnName); continue; } } sb.Append(columnName).Append(" = ?"); } sb.Append(" WHERE "); const string ADD_AND = " AND "; for (int i = 0; i < bmd.PrimaryKeySize; ++i) { sb.Append(bmd.GetPrimaryKey(i)).Append(" = ?").Append(ADD_AND); } sb.Length = sb.Length - ADD_AND.Length; if (bmd.HasVersionNoPropertyType) { IPropertyType pt = bmd.VersionNoPropertyType; sb.Append(ADD_AND).Append(pt.ColumnName).Append(" = ?"); } if (bmd.HasTimestampPropertyType) { IPropertyType pt = bmd.TimestampPropertyType; sb.Append(ADD_AND).Append(pt.ColumnName).Append(" = ?"); } return(sb.ToString()); }