package com.naver.jr.fun.model.quiz.handler;
import java.sql.SQLException;
import org.apache.commons.lang.StringUtils;
import com.ibatis.sqlmap.client.extensions.ParameterSetter;
import com.ibatis.sqlmap.client.extensions.ResultGetter;
import com.ibatis.sqlmap.client.extensions.TypeHandlerCallback;
import com.naver.jr.fun.model.quiz.QuizCategory;
public class QuizCategoryTypeHandler implements TypeHandlerCallback {
@Override
public Object getResult(ResultGetter getter) throws SQLException {
String str = getter.getString();
if (StringUtils.equals(QuizCategory.COMMON.toString(), str)) {
return QuizCategory.COMMON;
} else if (StringUtils.equals(QuizCategory.COUNTRY.toString(), str)) {
return QuizCategory.COUNTRY;
} else if (StringUtils.equals(QuizCategory.PROVERB.toString(), str)) {
return QuizCategory.PROVERB;
} else if (StringUtils.equals(QuizCategory.RIDDLE.toString(), str)) {
return QuizCategory.RIDDLE;
} else if (StringUtils.equals(QuizCategory.TEXTBOOK.toString(), str)) {
return QuizCategory.TEXTBOOK;
} else if (StringUtils.equals(QuizCategory.TV.toString(), str)) {
return QuizCategory.TV;
}
else {
throw new SQLException("Unexpceted value " + str + " found. " + QuizCategory.class.toString()
+ " was expected.");
}
}
@Override
public void setParameter(ParameterSetter setter, Object parameter) throws SQLException {
switch ((QuizCategory)parameter) {
case COMMON:
setter.setString(QuizCategory.COMMON.toString());
break;
case COUNTRY:
setter.setString(QuizCategory.COUNTRY.toString());
break;
case PROVERB:
setter.setString(QuizCategory.PROVERB.toString());
break;
case RIDDLE:
setter.setString(QuizCategory.RIDDLE.toString());
break;
case TEXTBOOK:
setter.setString(QuizCategory.TEXTBOOK.toString());
break;
case TV:
setter.setString(QuizCategory.TV.toString());
break;
default:
throw new SQLException("Unexpceted value found. " + QuizCategory.class.toString() + " was expected.");
}
}
@Override
public Object valueOf(String str) {
if (StringUtils.equals(QuizCategory.COMMON.toString(), str)) {
return QuizCategory.COMMON;
} else if (StringUtils.equals(QuizCategory.COUNTRY.toString(), str)) {
return QuizCategory.COUNTRY;
} else if (StringUtils.equals(QuizCategory.PROVERB.toString(), str)) {
return QuizCategory.PROVERB;
} else if (StringUtils.equals(QuizCategory.RIDDLE.toString(), str)) {
return QuizCategory.RIDDLE;
} else if (StringUtils.equals(QuizCategory.TEXTBOOK.toString(), str)) {
return QuizCategory.TEXTBOOK;
} else if (StringUtils.equals(QuizCategory.TV.toString(), str)) {
return QuizCategory.TV;
}
return null;
}
}
2010년 9월 5일 일요일
TypeHandlerCallback 예시
피드 구독하기:
댓글 (Atom)
댓글 없음:
댓글 쓰기