/**
* 根据操作类型(add 还是 update)从Data Entity中的Hashtable中获取所有被使用过的字段名称
*
* @return String[]
* @param String1:
* @param String2
* update操作不使用该返回值
* @throws ITreasuryDAOException
*/
public String[] getAllFieldNameBuffer(ITreasuryBaseDataEntity dataEntity,
int operationType) throws ITreasuryDAOException {
StringBuffer buffer1 = new StringBuffer();// 名称
StringBuffer buffer2 = new StringBuffer();// 问号
HashMap allFields = dataEntity.gainAllUsedFieldsAndValue();
Set allFieldNames = allFields.keySet();
int j = 1;
Iterator it = allFieldNames.iterator();
while (it.hasNext()) {
String fieldName = (String) it.next();
log.debug("Used Field Name: " + fieldName);
if (operationType == DAO_OPERATION_ADD) {
buffer1.append(fieldName + ",");
} else if (operationType == DAO_OPERATION_UPDATE
|| operationType == DAO_OPERATION_FIND) {
if (operationType == DAO_OPERATION_UPDATE
&& fieldName.compareToIgnoreCase("id") == 0)// 更新操作不对id进行处理
continue;
// do not modify any blank at below codes because "= ?," is
// match condition for split field name
if (operationType == DAO_OPERATION_FIND)
buffer1.append(fieldName + " = ? AND ");
else
buffer1.append(fieldName + " = ?,");
} else {
throw new ITreasuryDAOException(
"DAO getAllFieldNameBuffer,错误的操作类型", null);
}
buffer2.append("?,");
}
String strBuffer1 = buffer1.toString();
String strBuffer2 = buffer2.toString();
// log.debug("----before cut-------");
// log.debug(strBuffer1+strBuffer2);
if (operationType == DAO_OPERATION_FIND)// cut last "and"
strBuffer1 = strBuffer1.substring(0, (strBuffer1.length() - 4));
else
// cut last ","
strBuffer1 = strBuffer1.substring(0, (strBuffer1.length() - 1));
strBuffer2 = strBuffer2.substring(0, (strBuffer2.length() - 1));
// log.debug("----afer cut-------");
// log.debug(strBuffer1+strBuffer2);
String[] strs = { strBuffer1, strBuffer2 };
return strs;
}
此博仅个人可见。