📄 usergroupdb.java
字号:
package com.redmoon.forum.person;
import java.sql.*;
import cn.js.fan.db.*;
import cn.js.fan.util.*;
import com.cloudwebsoft.framework.base.ObjectDb;
import cn.js.fan.web.SkinUtil;
import com.cloudwebsoft.framework.db.JdbcTemplate;
import com.cloudwebsoft.framework.db.DataSource;
import com.cloudwebsoft.framework.base.IObjectDb;
public class UserGroupDb extends ObjectDb {
private String code;
private String desc;
public UserGroupDb() {
init();
}
public UserGroupDb(String code) {
this.code = code;
load(new JdbcTemplate(new DataSource()));
init();
}
public UserGroupDb(String code, String desc) {
init();
this.code = code;
this.desc = desc;
}
public void initDB() {
this.tableName = "sq_user_group";
primaryKey = new PrimaryKey("code", PrimaryKey.TYPE_STRING);
objectCache = new UserGroupCache(this);
QUERY_CREATE = "insert into sq_user_group (code, description) values (?,?)";
QUERY_SAVE = "update sq_user_group set description=? where code=?";
QUERY_LIST = "select code from sq_user_group order by isSystem desc, description asc";
QUERY_DEL = "delete from sq_user_group where code=?";
QUERY_LOAD = "select code, description, isSystem from sq_user_group where code=?";
isInitFromConfigDB = false;
}
public IObjectDb getObjectRaw(PrimaryKey pk) {
return new UserGroupDb(pk.getStrValue());
}
public String getCode() {
return code;
}
public void setCode(String c) {
code = c;
}
public String getDesc() {
return desc;
}
public boolean isSystem() {
return system;
}
public void setDesc(String desc) {
this.desc = desc;
}
public void setSystem(boolean system) {
this.system = system;
}
private boolean system = false;
public boolean create(JdbcTemplate jt) throws ResKeyException {
boolean re = false;
try {
re = jt.executeUpdate(QUERY_CREATE, new Object[] {code, desc}) == 1;
}
catch (SQLException e) {
logger.info("create:" + e.getMessage());
throw new ResKeyException(SkinUtil.ERR_DB);
}
UserGroupCache ugc = new UserGroupCache(this);
ugc.refreshCreate();
return re;
}
public void load(JdbcTemplate jt) {
try {
ResultIterator ri = jt.executeQuery(QUERY_LOAD, new Object[] {code});
if (ri.hasNext()) {
ResultRecord rr = (ResultRecord) ri.next();
code = rr.getString(1);
desc = rr.getString(2);
system = rr.getBoolean(3);
loaded = true;
primaryKey.setValue(code);
}
}
catch (SQLException e) {
logger.info("load:" + e.getMessage());
}
}
public boolean save(JdbcTemplate jt) throws ResKeyException {
boolean re = false;
try {
re = jt.executeUpdate(QUERY_SAVE, new Object[] {desc, code}) == 1;
} catch (SQLException e) {
logger.info("save:" + e.getMessage());
throw new ResKeyException(SkinUtil.ERR_DB);
}
UserGroupCache uc = new UserGroupCache(this);
primaryKey.setValue(code);
uc.refreshSave(primaryKey);
return re;
}
public boolean del(JdbcTemplate jt) throws ResKeyException {
if (isSystem())
return false;
boolean re = false;
try {
re = jt.executeUpdate(QUERY_DEL, new Object[] {code}) == 1;
} catch (SQLException e) {
logger.error("del:" + e.getMessage());
throw new ResKeyException(SkinUtil.ERR_DB);
}
UserGroupCache uc = new UserGroupCache(this);
primaryKey.setValue(code);
uc.refreshDel(primaryKey);
return re;
}
public IObjectDb getObjectDb(Object primaryKeyValue) {
UserGroupCache uc = new UserGroupCache(this);
primaryKey.setValue(primaryKeyValue);
return (UserGroupDb)uc.getObjectDb(primaryKey);
}
public UserGroupDb getUserGroupDb(String code) {
return (UserGroupDb)getObjectDb(code);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -