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 CMS_ATTACHEMENTS extends BaseBean{
|
|
public final static Map<String, String> KEYS = new HashMap<String, String>();
|
private Map BEAN_VALUES = null;
|
|
static {
|
KEYS.put("id", "String");
|
KEYS.put("news_id", "String");
|
KEYS.put("filename", "String");
|
KEYS.put("filepath", "String");
|
KEYS.put("filetype", "String");
|
KEYS.put("filesize", "String");
|
}
|
public Map getColumnMap(){
|
return KEYS;
|
}
|
|
private String id;
|
private Boolean isSetted_id = false;;
|
|
private String news_id;
|
private Boolean isSetted_news_id = false;
|
private String filename;
|
private Boolean isSetted_filename = false;
|
private String filepath;
|
private Boolean isSetted_filepath = false;
|
private String filetype;
|
private Boolean isSetted_filetype = false;
|
private String filesize;
|
private Boolean isSetted_filesize = false;
|
|
private void initBeanValues(){
|
BEAN_VALUES = new HashMap<String, Object>();
|
BEAN_VALUES.put("id",id);
|
BEAN_VALUES.put("news_id", null);
|
BEAN_VALUES.put("filename", null);
|
BEAN_VALUES.put("filepath", null);
|
BEAN_VALUES.put("filetype", null);
|
BEAN_VALUES.put("filesize", null);
|
}
|
|
public CMS_ATTACHEMENTS() {
|
initBeanValues();
|
}
|
|
public CMS_ATTACHEMENTS(String id) {
|
super();
|
this.id = id;
|
initBeanValues();
|
BEAN_VALUES.put("id",id);
|
}
|
|
/**
|
* 获取ID
|
*/
|
public String getId() {
|
return this.id;
|
}
|
/**
|
* 设置ID
|
*/
|
public CMS_ATTACHEMENTS 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 CMS_ATTACHEMENTS set ");
|
if (isSetted_news_id) {
|
sBuffer.append("news_id=:news_id,");
|
}
|
if (isSetted_filename) {
|
sBuffer.append("filename=:filename,");
|
}
|
if (isSetted_filepath) {
|
sBuffer.append("filepath=:filepath,");
|
}
|
if (isSetted_filetype) {
|
sBuffer.append("filetype=:filetype,");
|
}
|
if (isSetted_filesize) {
|
sBuffer.append("filesize=:filesize,");
|
}
|
String sql = sBuffer.toString();
|
return StringUtils.removeEnd(sql, ",") + " where id=:id";
|
}
|
|
|
@Override
|
public String getInsertSql() {
|
StringBuffer sBuffer = new StringBuffer("insert into CMS_ATTACHEMENTS(");
|
StringBuffer fileds = new StringBuffer("id,");
|
StringBuffer values = new StringBuffer(":id,");
|
fileds.append("news_id,");
|
values.append(":news_id,");
|
fileds.append("filename,");
|
values.append(":filename,");
|
fileds.append("filepath,");
|
values.append(":filepath,");
|
fileds.append("filetype,");
|
values.append(":filetype,");
|
fileds.append("filesize,");
|
values.append(":filesize,");
|
sBuffer.append(StringUtils.removeEnd(fileds.toString(), ",") + ") values("+StringUtils.removeEnd(values.toString(), ",")+")");
|
return sBuffer.toString();
|
}
|
|
|
/**
|
* 获取<BR/>
|
* 䣺2014-00-20 hh:08
|
*/
|
public String getNews_id() {
|
return news_id;
|
}
|
/**
|
* 设置<BR/>
|
* 2014-00-20 hh:08
|
*/
|
public CMS_ATTACHEMENTS setNews_id(String news_id) {
|
this.news_id = news_id;
|
this.isSetted_news_id = true;
|
BEAN_VALUES.put("news_id",news_id);
|
return this;
|
}
|
/**
|
* 获取<BR/>
|
* 䣺2014-00-20 hh:08
|
*/
|
public String getFilename() {
|
return filename;
|
}
|
/**
|
* 设置<BR/>
|
* 2014-00-20 hh:08
|
*/
|
public CMS_ATTACHEMENTS setFilename(String filename) {
|
this.filename = filename;
|
this.isSetted_filename = true;
|
BEAN_VALUES.put("filename",filename);
|
return this;
|
}
|
/**
|
* 获取<BR/>
|
* 䣺2014-00-20 hh:08
|
*/
|
public String getFilepath() {
|
return filepath;
|
}
|
/**
|
* 设置<BR/>
|
* 2014-00-20 hh:08
|
*/
|
public CMS_ATTACHEMENTS setFilepath(String filepath) {
|
this.filepath = filepath;
|
this.isSetted_filepath = true;
|
BEAN_VALUES.put("filepath",filepath);
|
return this;
|
}
|
/**
|
* 获取<BR/>
|
* 䣺2014-00-20 hh:08
|
*/
|
public String getFiletype() {
|
return filetype;
|
}
|
/**
|
* 设置<BR/>
|
* 2014-00-20 hh:08
|
*/
|
public CMS_ATTACHEMENTS setFiletype(String filetype) {
|
this.filetype = filetype;
|
this.isSetted_filetype = true;
|
BEAN_VALUES.put("filetype",filetype);
|
return this;
|
}
|
/**
|
* 获取<BR/>
|
* 䣺2014-00-20 hh:08
|
*/
|
public String getFilesize() {
|
return filesize;
|
}
|
/**
|
* 设置<BR/>
|
* 2014-00-20 hh:08
|
*/
|
public CMS_ATTACHEMENTS setFilesize(String filesize) {
|
this.filesize = filesize;
|
this.isSetted_filesize = true;
|
BEAN_VALUES.put("filesize",filesize);
|
return this;
|
}
|
|
/**
|
* 使用ID删除Bean<BR/>
|
*/
|
public void deleteById() {
|
if (StringUtils.isBlank(id)) {
|
throw new RuntimeException("删除bean时ID不能为空");
|
}
|
dao.execute("delete from " + getTableName() + " where id = :id", BEAN_VALUES);
|
}
|
|
@Override
|
public CMS_ATTACHEMENTS getInstanceById() {
|
if (StringUtils.isBlank(id)) {
|
throw new RuntimeException("获取Bean时ID不能为空");
|
}
|
return dao.queryForBean("select * from " + getTableName() + " where id=:id", BEAN_VALUES, this);
|
}
|
|
|
|
@Override
|
public CMS_ATTACHEMENTS queryForBean() {
|
StringBuffer sBuffer = new StringBuffer("select * from CMS_ATTACHEMENTS where ");
|
if(isSetted_id){
|
sBuffer.append("id=:id and ");
|
}
|
if (isSetted_news_id) {
|
sBuffer.append("news_id=:news_id and ");
|
}
|
if (isSetted_filename) {
|
sBuffer.append("filename=:filename and ");
|
}
|
if (isSetted_filepath) {
|
sBuffer.append("filepath=:filepath and ");
|
}
|
if (isSetted_filetype) {
|
sBuffer.append("filetype=:filetype and ");
|
}
|
if (isSetted_filesize) {
|
sBuffer.append("filesize=:filesize and ");
|
}
|
String sql = sBuffer.toString();
|
sql = StringUtils.removeEnd(sql, " and ");
|
return dao.queryForBean(sql,this);
|
}
|
|
@Override
|
public String getTableName() {
|
return "CMS_ATTACHEMENTS";
|
}
|
|
|
public Map getBeanValues(){
|
return this.BEAN_VALUES;
|
}
|
|
@Override
|
public CMS_ATTACHEMENTS insert() {
|
if (StringUtils.isBlank(id)) {
|
this.setId(StringUtil.getUUID());
|
}
|
dao.execute(getInsertSql(),BEAN_VALUES);
|
return this;
|
}
|
|
@Override
|
public CMS_ATTACHEMENTS update() {
|
if (StringUtils.isBlank(id)) {
|
throw new RuntimeException("更新Bean时ID不能为空");
|
}
|
dao.execute(getUpdateSql(),BEAN_VALUES);
|
return this;
|
}
|
|
public CMS_ATTACHEMENTS 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 CMS_ATTACHEMENTS 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("NEWS_ID");
|
BEAN_VALUES.put("news_id",obj);
|
this.setNews_id(ConvertUtil.obj2Str(obj));
|
obj = rs.getObject("FILENAME");
|
BEAN_VALUES.put("filename",obj);
|
this.setFilename(ConvertUtil.obj2Str(obj));
|
obj = rs.getObject("FILEPATH");
|
BEAN_VALUES.put("filepath",obj);
|
this.setFilepath(ConvertUtil.obj2Str(obj));
|
obj = rs.getObject("FILETYPE");
|
BEAN_VALUES.put("filetype",obj);
|
this.setFiletype(ConvertUtil.obj2Str(obj));
|
obj = rs.getObject("FILESIZE");
|
BEAN_VALUES.put("filesize",obj);
|
this.setFilesize(ConvertUtil.obj2Str(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 CMS_ATTACHEMENTS newInstance(){
|
return new CMS_ATTACHEMENTS();
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|