oracle中tlog表,SLog在oracle下的实现

slog在oracle下使用遇到的问题:

1.SLogBean 中的msg字段默认长度8192,而oracle的varchar2最大长度4000

2.id字段类型默认long类型,我习惯定义位string类型

3.我的userid也是string类型的,所以uid也要定义位string

基于以上,做了如下尝试:

1.新建YlogBean, 重新定义msg和id字段(本来想继承一下,发现字段类型不同是不让继承的)

2.新建YlogService,*重新写*create()代替父类c(), 重写父类的sync(), log(), Callable GET_USER_ID, dao(),

搞定, 附一下代码:

@Table("ysm_sys_log_${ym}")

public class YlogBean implements Serializable {

private static final long serialVersionUID = 4048681972879639280L;

@Name

@Prev({

@SQL( db = DB.ORACLE, value = "SELECT SYS_GUID() FROM DUAL")

})

private String id;

@Column("t")// aop.before aop.after aop.error

private String t;

@Column("tg")

private String tag;

@Column("src")

@ColDefine(width=1024)

private String source;

@Column("u_id")

private String uid;

@Column("ip")

private String ip;

@Column

@ColDefine(width=4000)

private String msg;

@Column("ct")

protected Date createTime;

public String getTag() {

return tag;

}

public void setTag(String tag) {

this.tag = tag;

}

public String getT() {

return t;

}

public void setT(String t) {

this.t = t;

}

public String getSource() {

return source;

}

public void setSource(String source) {

this.source = source;

}

public String getId() {

return id;

}

public void setId(String id) {

this.id = id;

}

public String getUid() {

return uid;

}

public void setUid(String uid) {

this.uid = uid;

}

public String getMsg() {

return msg;

}

public void setMsg(String msg) {

this.msg = msg;

}

public Date getCreateTime() {

return createTime;

}

public void setCreateTime(Date createTime) {

this.createTime = createTime;

}

public String getIp() {

return ip;

}

public void setIp(String ip) {

this.ip = ip;

}

}

public class YlogService extends SlogService{

private static final Log log = Logs.get();

/**

* 创建一个YlogBean对象

* @param t

* @param tag

* @param source

* @param msg

* @return

*/

public YlogBean create(String t, String tag, String source, String msg) {

YlogBean ylog = new YlogBean();

ylog.setCreateTime(new Date());

if (t == null || tag == null || msg == null) {

throw new RuntimeException("t/tag/msg can't null");

}

if (source == null) {

StackTraceElement[] tmp = Thread.currentThread().getStackTrace();

if (tmp.length > 2) {

source = tmp[2].getClassName() + "#" + tmp[2].getMethodName();

} else {

source = "main";

}

}

ylog.setT(t);

ylog.setTag(tag);

ylog.setSource(source);

ylog.setMsg(msg);

if (Mvcs.getReq() != null) {

ylog.setIp(Lang.getIP(Mvcs.getReq()));

}

return ylog;

}

/**

* 重写父类方法

* 将原来调用dao().fastInsert()改为dao().insert(),原因是将id改成String类型了

* @param ylog

*/

@Override

public void sync(Object ylog) {

try {

this.dao().insert(ylog);

} catch (Throwable var3) {

log.info("insert syslog sync fail", var3);

}

}

/**

* 重写父类方法

* 此处做修改: ylog.setUid(uid.toString());

* @param t

* @param tag

* @param source

* @param msg

* @param async

*/

@Override

public void log(String t, String tag, String source, String msg, boolean async) {

YlogBean ylog = this.create(t, tag, source, msg);

try {

Object uid = GET_USER_ID.call();

if (uid != null )

ylog.setUid(uid.toString());

}

catch (Exception e) {

log.debug("get user id fail", e);

}

if (async)

async(ylog);

else

sync(ylog);

}

/**

* 改为从Session中获取uid

*/

public static Callable GET_USER_ID = new Callable() {

public String call() throws Exception {

Object uid;

try {

uid = Mvcs.getSessionAttrSafe("uid");

} catch (Throwable e) {

return null;

}

if (uid != null) {

return uid.toString();

}

return null;

};

};

/**

* 重写父类方法

* 获取特定月份的Dao实例

* 修改为:以YlogBean建表

* @param key

* @return

*/

@Override

protected Dao dao(String key) {

Dao dao = ymDaos.get(key);

if (dao == null) {

synchronized (this) {

dao = ymDaos.get(key);

if (dao == null) {

dao = Daos.ext(this.dao, key);

dao.create(YlogBean.class, false);

ymDaos.put(key, dao);

}

}

}

return dao;

}

}

还有个疑问:ColType这个枚举好像比较偏MySql, 能不能支持一下Oracle,比如Clob,Blog, Long...遇到这几种就只能手动操作了。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值