📄 generaldbconnwriter.java
字号:
package com.gisinfo.common.log.general;
import com.gisinfo.common.log.LogWriter;
import com.gisinfo.common.log.LogEvent;
import com.gisinfo.common.log.LogException;
import com.gisinfo.common.util.CommonUtil;
import com.gisinfo.common.util.IDCreator;
import com.gisinfo.common.util.DBUtil;
import com.gisinfo.sql.delegater.Connection;
import java.util.List;
import java.util.ArrayList;
import java.sql.PreparedStatement;
import java.sql.Timestamp;
/**
* User: Ken
* Date: 2008-6-18
* Time: 17:09:32
*/
public class GeneralDBConnWriter extends LogWriter {
private String tableName = "T_COMMON_LOG";
private String dbConnName = null;
@Override
protected void init() {
if (CommonUtil.isNotNullOrEmpty(getProperties().get("table")))
tableName = (String) getProperties().get("table");
if (CommonUtil.isNotNullOrEmpty(getProperties().get("dbConn")))
dbConnName = (String) getProperties().get("dbConn");
}
//id ip who where when action lvl systemName what description
protected void writeLog(List<LogEvent> event) throws LogException {
if (event.size() == 0) return;
List<GeneralLogEvent> result = new ArrayList<GeneralLogEvent>();
for (LogEvent e : event) {
if (e instanceof GeneralLogEvent) result.add((GeneralLogEvent) e);
else
result.add(new GeneralLogEvent(IDCreator.getUUID(), "", e.getWhen(), "", "", "", e.getDescription(), "", ""));
}
try {
GeneralLogEventDao.saveLog(result, tableName, dbConnName);
} catch (Exception e) {
e.printStackTrace();
throw new LogException(e);
}
/*
create table T_COMMON_LOG (
F_ID varchar(32) not null,
F_WHO varchar(20),
F_WHERE varchar(50),
F_WHEN datetime not null,
F_ACTIOIN varchar(32),
F_WHAT varchar(32),
F_LVL varchar(12) not null,
F_IP varchar(15),
F_SYSTEMNAME varchar(32)
);
*/
/*String sql = "insert into " + this.tableName + "(F_ID,F_WHO,F_WHERE,F_WHEN,F_ACTION,F_WHAT,F_LVL,F_IP,F_SYSTEMNAME)values(?,?,?,?,?,?,?,?,?)";
Connection con = null;
PreparedStatement pstmt = null;
try {
con = DBUtil.getConnection(dbConnName);
con.setAutoCommit(false);
pstmt = con.prepareStatement(sql);
for (GeneralLogEvent e : result) {
pstmt.setString(1, e.getId());
pstmt.setString(2, CommonUtil.trimToEmpty(e.getWho()));
pstmt.setString(3, CommonUtil.trimToEmpty(e.getWhere()));
pstmt.setTimestamp(4, new Timestamp(e.getWhen().getTime()));
pstmt.setString(5, CommonUtil.trimToEmpty(e.getAction()));
pstmt.setString(6, CommonUtil.trimToEmpty(e.getWhat()));
pstmt.setString(7, e.getLvl());
pstmt.setString(8, CommonUtil.trimToEmpty(e.getIp()));
pstmt.setString(9, CommonUtil.trimToEmpty(e.getSystemName()));
pstmt.addBatch();
}
pstmt.executeBatch();
con.commit();
} catch (Exception e) {
DBUtil.rollBack(con);
throw new LogException(e);
} finally {
DBUtil.close(con, pstmt, null);
}
*/
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -