📄 logdb.java
字号:
package com.redmoon.oa;import java.sql.*;import cn.js.fan.base.*;import cn.js.fan.db.*;import cn.js.fan.util.*;import com.redmoon.oa.db.SequenceManager;public class LogDb extends ObjectDb { public static final int TYPE_LOGIN = 0; public static final int TYPE_LOGOUT = 1; public static final int TYPE_ACTION = 2; public static final int TYPE_WARN = 3; public static final int TYPE_ERROR = 4; public LogDb() { init(); } public LogDb(int id) { init(); this.id = id; load(); } public void initDB() { tableName = "log"; primaryKey = new PrimaryKey("ID", PrimaryKey.TYPE_INT); objectCache = new LogCache(this); isInitFromConfigDB = false; QUERY_CREATE = "insert into " + tableName + " (USER_NAME, IP, LOG_TYPE, ACTION, LOG_DATE, ID) values (?,?,?,?,?,?)"; QUERY_SAVE = "update " + tableName + " set USER_NAME=?, IP=?, LOG_TYPE=?, ACTION=?, LOG_DATE=? where ID=?"; QUERY_LOAD = "select USER_NAME, IP, LOG_TYPE, ACTION, LOG_DATE from " + tableName + " where ID=?"; QUERY_DEL = "delete from " + tableName + " where ID=?"; QUERY_LIST = "select ID from " + tableName + " order by LOG_DATE desc"; } public ObjectDb getObjectRaw(PrimaryKey pk) { return new LogDb(pk.getIntValue()); } public LogDb getLogDb(int id) { LogDb log = (LogDb)getObjectDb(new Integer(id)); return log; } public void setUserName(String userName) { this.userName = userName; } public void setId(int id) { this.id = id; } public void setType(int type) { this.type = type; } public void setAction(String action) { this.action = action; } public void setIp(String ip) { this.ip = ip; } public void setDate(Date date) { this.date = date; } public String getUserName() { return userName; } public int getId() { return id; } public int getType() { return type; } public String getAction() { return action; } public String getIp() { return ip; } public java.util.Date getDate() { return date; } public boolean create() { Conn conn = new Conn(connname); boolean re = false; id = (int)SequenceManager.nextID(SequenceManager.OA_LOG); try { PreparedStatement pstmt = conn.prepareStatement(QUERY_CREATE); pstmt.setString(1, userName); pstmt.setString(2, ip); pstmt.setInt(3, type); pstmt.setString(4, action); pstmt.setString(5, "" + new java.util.Date().getTime()); pstmt.setInt(6, id); re = conn.executePreUpdate()==1?true:false; if (re) { LogCache rc = new LogCache(this); rc.refreshCreate(); } } catch (SQLException e) { logger.error("create:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public boolean save() { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement pstmt = conn.prepareStatement(QUERY_SAVE); pstmt.setString(1, userName); pstmt.setString(2, ip); pstmt.setInt(3, type); pstmt.setString(4, action); pstmt.setString(5, "" + date.getTime()); pstmt.setInt(6, id); re = conn.executePreUpdate()==1?true:false; if (re) { LogCache rc = new LogCache(this); primaryKey.setValue(new Integer(id)); rc.refreshSave(primaryKey); return true; } } catch (SQLException e) { logger.error("save:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } public void load() { Conn conn = new Conn(connname); ResultSet rs = null; try { PreparedStatement pstmt = conn.prepareStatement(QUERY_LOAD); pstmt.setInt(1, id); rs = conn.executePreQuery(); if (rs != null) { if (rs.next()) { userName = StrUtil.getNullStr(rs.getString(1)); ip = StrUtil.getNullStr(rs.getString(2)); type = rs.getInt(3); action = rs.getString(4); date = new java.util.Date(Long.parseLong(rs.getString(5). trim())); loaded = true; primaryKey.setValue(new Integer(id)); } } } catch (Exception e) { logger.error("load:" + e.getMessage()); } finally { if (rs != null) { try { rs.close(); } catch (Exception e) {} rs = null; } if (conn != null) { conn.close(); conn = null; } } } public boolean del() { Conn conn = new Conn(connname); boolean re = false; try { PreparedStatement pstmt = conn.prepareStatement(QUERY_DEL); pstmt.setInt(1, id); re = conn.executePreUpdate()==1?true:false; if (re) { re = conn.executePreUpdate() >= 0 ? true : false; LogCache rc = new LogCache(this); rc.refreshDel(primaryKey); return true; } } catch (SQLException e) { logger.error("del:" + e.getMessage()); } finally { if (conn != null) { conn.close(); conn = null; } } return re; } private String userName; private int id; private int type; private String action; private String ip; private java.util.Date date;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -