package cn.ksource.beans; import java.sql.ResultSet; import java.sql.SQLException; import java.util.HashMap; import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.commons.lang.StringUtils; import cn.ksource.core.dao.BaseBean; import cn.ksource.core.util.ConvertUtil; import cn.ksource.core.util.StringUtil; /** * */ public class KM_LIBRARY_CATEGORY extends BaseBean{ public final static Map KEYS = new HashMap(); private Map BEAN_VALUES = null; static { KEYS.put("id", "String"); KEYS.put("title", "String"); KEYS.put("tag", "String"); KEYS.put("level", "Integer"); KEYS.put("create_user_id", "String"); KEYS.put("create_user_name", "String"); KEYS.put("create_time", "Long"); KEYS.put("state", "Integer"); KEYS.put("note", "String"); KEYS.put("serial", "Integer"); } public Map getColumnMap(){ return KEYS; } private String id; private Boolean isSetted_id = false;; private String title; private Boolean isSetted_title = false; private String tag; private Boolean isSetted_tag = false; private Integer level; private Boolean isSetted_level = false; private String create_user_id; private Boolean isSetted_create_user_id = false; private String create_user_name; private Boolean isSetted_create_user_name = false; private Long create_time; private Boolean isSetted_create_time = false; private Integer state; private Boolean isSetted_state = false; private String note; private Boolean isSetted_note = false; private Integer serial; private Boolean isSetted_serial = false; private void initBeanValues(){ BEAN_VALUES = new HashMap(); BEAN_VALUES.put("id",id); BEAN_VALUES.put("title", null); BEAN_VALUES.put("tag", null); BEAN_VALUES.put("level", null); BEAN_VALUES.put("create_user_id", null); BEAN_VALUES.put("create_user_name", null); BEAN_VALUES.put("create_time", null); BEAN_VALUES.put("state", null); BEAN_VALUES.put("note", null); BEAN_VALUES.put("serial", null); } public KM_LIBRARY_CATEGORY() { initBeanValues(); } public KM_LIBRARY_CATEGORY(String id) { super(); this.id = id; initBeanValues(); BEAN_VALUES.put("id",id); } /** * 获取ID */ public String getId() { return this.id; } /** * 设置ID */ public KM_LIBRARY_CATEGORY setId(String id) { this.id = id; this.isSetted_id = true; BEAN_VALUES.put("id",id); return this; } @Override public String getUpdateSql() { StringBuffer sBuffer = new StringBuffer("update KM_LIBRARY_CATEGORY set "); if (isSetted_title) { sBuffer.append("title=:title,"); } if (isSetted_tag) { sBuffer.append("tag=:tag,"); } if (isSetted_level) { sBuffer.append("level=:level,"); } if (isSetted_create_user_id) { sBuffer.append("create_user_id=:create_user_id,"); } if (isSetted_create_user_name) { sBuffer.append("create_user_name=:create_user_name,"); } if (isSetted_create_time) { sBuffer.append("create_time=:create_time,"); } if (isSetted_state) { sBuffer.append("state=:state,"); } if (isSetted_note) { sBuffer.append("note=:note,"); } if (isSetted_serial) { sBuffer.append("serial=:serial,"); } String sql = sBuffer.toString(); return StringUtils.removeEnd(sql, ",") + " where id=:id"; } @Override public String getInsertSql() { StringBuffer sBuffer = new StringBuffer("insert into KM_LIBRARY_CATEGORY("); StringBuffer fileds = new StringBuffer("id,"); StringBuffer values = new StringBuffer(":id,"); fileds.append("title,"); values.append(":title,"); fileds.append("tag,"); values.append(":tag,"); fileds.append("level,"); values.append(":level,"); fileds.append("create_user_id,"); values.append(":create_user_id,"); fileds.append("create_user_name,"); values.append(":create_user_name,"); fileds.append("create_time,"); values.append(":create_time,"); fileds.append("state,"); values.append(":state,"); fileds.append("note,"); values.append(":note,"); fileds.append("serial,"); values.append(":serial,"); sBuffer.append(StringUtils.removeEnd(fileds.toString(), ",") + ") values("+StringUtils.removeEnd(values.toString(), ",")+")"); return sBuffer.toString(); } /** * 获取分类名称
* 䣺2016-14-30 hh:06 */ public String getTitle() { return title; } /** * 设置分类名称
* 2016-14-30 hh:06 */ public KM_LIBRARY_CATEGORY setTitle(String title) { this.title = title; this.isSetted_title = true; BEAN_VALUES.put("title",title); return this; } /** * 获取上级分类编号
* 䣺2016-14-30 hh:06 */ public String getTag() { return tag; } /** * 设置上级分类编号
* 2016-14-30 hh:06 */ public KM_LIBRARY_CATEGORY setTag(String tag) { this.tag = tag; this.isSetted_tag = true; BEAN_VALUES.put("tag",tag); return this; } /** * 获取层级
* 䣺2016-14-30 hh:06 */ public Integer getLevel() { return level; } /** * 设置层级
* 2016-14-30 hh:06 */ public KM_LIBRARY_CATEGORY setLevel(Integer level) { this.level = level; this.isSetted_level = true; BEAN_VALUES.put("level",level); return this; } /** * 获取记录创建人
* 䣺2016-14-30 hh:06 */ public String getCreate_user_id() { return create_user_id; } /** * 设置记录创建人
* 2016-14-30 hh:06 */ public KM_LIBRARY_CATEGORY setCreate_user_id(String create_user_id) { this.create_user_id = create_user_id; this.isSetted_create_user_id = true; BEAN_VALUES.put("create_user_id",create_user_id); return this; } /** * 获取记录创建人姓名
* 䣺2016-14-30 hh:06 */ public String getCreate_user_name() { return create_user_name; } /** * 设置记录创建人姓名
* 2016-14-30 hh:06 */ public KM_LIBRARY_CATEGORY setCreate_user_name(String create_user_name) { this.create_user_name = create_user_name; this.isSetted_create_user_name = true; BEAN_VALUES.put("create_user_name",create_user_name); return this; } /** * 获取记录创建时间
* 䣺2016-14-30 hh:06 */ public Long getCreate_time() { return create_time; } /** * 设置记录创建时间
* 2016-14-30 hh:06 */ public KM_LIBRARY_CATEGORY setCreate_time(Long create_time) { this.create_time = create_time; this.isSetted_create_time = true; BEAN_VALUES.put("create_time",create_time); return this; } /** * 获取记录状态(1=启用;2=禁用)
* 䣺2016-14-30 hh:06 */ public Integer getState() { return state; } /** * 设置记录状态(1=启用;2=禁用)
* 2016-14-30 hh:06 */ public KM_LIBRARY_CATEGORY setState(Integer state) { this.state = state; this.isSetted_state = true; BEAN_VALUES.put("state",state); return this; } /** * 获取说明
* 䣺2016-14-30 hh:06 */ public String getNote() { return note; } /** * 设置说明
* 2016-14-30 hh:06 */ public KM_LIBRARY_CATEGORY setNote(String note) { this.note = note; this.isSetted_note = true; BEAN_VALUES.put("note",note); return this; } /** * 获取顺序号
* 䣺2016-14-30 hh:06 */ public Integer getSerial() { return serial; } /** * 设置顺序号
* 2016-14-30 hh:06 */ public KM_LIBRARY_CATEGORY setSerial(Integer serial) { this.serial = serial; this.isSetted_serial = true; BEAN_VALUES.put("serial",serial); return this; } /** * 使用ID删除Bean
*/ public void deleteById() { if (StringUtils.isBlank(id)) { throw new RuntimeException("删除bean时ID不能为空"); } dao.execute("delete from " + getTableName() + " where id = :id", BEAN_VALUES); } @Override public KM_LIBRARY_CATEGORY getInstanceById() { if (StringUtils.isBlank(id)) { throw new RuntimeException("获取Bean时ID不能为空"); } return dao.queryForBean("select * from " + getTableName() + " where id=:id", BEAN_VALUES, this); } @Override public KM_LIBRARY_CATEGORY queryForBean() { StringBuffer sBuffer = new StringBuffer("select * from KM_LIBRARY_CATEGORY where "); if(isSetted_id){ sBuffer.append("id=:id and "); } if (isSetted_title) { sBuffer.append("title=:title and "); } if (isSetted_tag) { sBuffer.append("tag=:tag and "); } if (isSetted_level) { sBuffer.append("level=:level and "); } if (isSetted_create_user_id) { sBuffer.append("create_user_id=:create_user_id and "); } if (isSetted_create_user_name) { sBuffer.append("create_user_name=:create_user_name and "); } if (isSetted_create_time) { sBuffer.append("create_time=:create_time and "); } if (isSetted_state) { sBuffer.append("state=:state and "); } if (isSetted_note) { sBuffer.append("note=:note and "); } if (isSetted_serial) { sBuffer.append("serial=:serial and "); } String sql = sBuffer.toString(); sql = StringUtils.removeEnd(sql, " and "); return dao.queryForBean(sql,this); } @Override public String getTableName() { return "KM_LIBRARY_CATEGORY"; } public Map getBeanValues(){ return this.BEAN_VALUES; } @Override public KM_LIBRARY_CATEGORY insert() { if (StringUtils.isBlank(id)) { this.setId(StringUtil.getUUID()); } dao.execute(getInsertSql(),BEAN_VALUES); return this; } @Override public KM_LIBRARY_CATEGORY update() { if (StringUtils.isBlank(id)) { throw new RuntimeException("更新Bean时ID不能为空"); } dao.execute(getUpdateSql(),BEAN_VALUES); return this; } public KM_LIBRARY_CATEGORY insertOrUpdate(){ if (StringUtils.isNotBlank(id)) { return update(); } else { return insert(); } } /** * 通过ID获取该条信息的Map结构 */ public Map getBeanMapById() { if (StringUtils.isBlank(id)) { throw new RuntimeException("ID不能为空!"); } return dao.queryForMap("select * from KM_LIBRARY_CATEGORY where id=:id",BEAN_VALUES); } public Object mapRow(ResultSet rs, int rownum) throws SQLException { Object id = rs.getObject("ID"); this.setId(ConvertUtil.obj2Str(id)); BEAN_VALUES.put("id",id); Object obj = null; obj = rs.getObject("TITLE"); BEAN_VALUES.put("title",obj); this.setTitle(ConvertUtil.obj2Str(obj)); obj = rs.getObject("TAG"); BEAN_VALUES.put("tag",obj); this.setTag(ConvertUtil.obj2Str(obj)); obj = rs.getObject("LEVEL"); BEAN_VALUES.put("level",obj); this.setLevel(ConvertUtil.obj2Integer(obj)); obj = rs.getObject("CREATE_USER_ID"); BEAN_VALUES.put("create_user_id",obj); this.setCreate_user_id(ConvertUtil.obj2Str(obj)); obj = rs.getObject("CREATE_USER_NAME"); BEAN_VALUES.put("create_user_name",obj); this.setCreate_user_name(ConvertUtil.obj2Str(obj)); obj = rs.getObject("CREATE_TIME"); BEAN_VALUES.put("create_time",obj); this.setCreate_time(ConvertUtil.obj2Long(obj)); obj = rs.getObject("STATE"); BEAN_VALUES.put("state",obj); this.setState(ConvertUtil.obj2Integer(obj)); obj = rs.getObject("NOTE"); BEAN_VALUES.put("note",obj); this.setNote(ConvertUtil.obj2Str(obj)); obj = rs.getObject("SERIAL"); BEAN_VALUES.put("serial",obj); this.setSerial(ConvertUtil.obj2Integer(obj)); return this; } public String toString() { StringBuffer sb = new StringBuffer("["); for (Iterator iterator = KEYS.keySet().iterator(); iterator.hasNext();) { String key = (String) iterator.next(); sb.append(key+"=" + BEAN_VALUES.get(key)+","); } sb.append("]"); return sb.toString(); } public KM_LIBRARY_CATEGORY newInstance(){ return new KM_LIBRARY_CATEGORY(); } }