프로젝트 중의 몇 가지 좋은 방법

2473 단어 DAOJ#
	/**
	 *       (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;

	}

이 블로그는 개인만 볼 수 있다.

좋은 웹페이지 즐겨찾기