📄 lenddao.java
字号:
//---------------------------------------------------------
// Application: equipment of System
// Author : eSingle
// File : LendDAO.java
//
// Copyright 2002 LandSoft Corp.
// Generated at Mon Nov 18 20:13:57 CST 2002
// Created by caoguangxin
// mailto:gxcao@mail.tsinghua.edu.cn
//---------------------------------------------------------
package com.landsoft.equipment.dao;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import com.landsoft.equipment.model.*;
import com.landsoft.equipment.util.CacheManager;
public class LendDAO extends DAO {
public LendDAO(DataSource ds) {
super(ds);
}
public void insert(Lend lend) throws SQLException {
String sql;
sql = "INSERT INTO lend (lendid, lender, borrower, auditing, lendadd, lenddate, returndate, other) VALUES (?, ?, ?, ?, ?, ?, ?, ?)";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lend.getLendid());
pstmt.setString(2, lend.getLender());
pstmt.setString(3, lend.getBorrower());
pstmt.setString(4, lend.getAuditing());
pstmt.setString(5, lend.getLendadd());
pstmt.setString(6, lend.getLenddate());
pstmt.setString(7, lend.getReturndate());
// pstmt.setDate(6, new java.sql.Date(lend.getLenddate().getTime()));
// pstmt.setDate(7, new java.sql.Date(lend.getReturndate().getTime()));
pstmt.setString(8, lend.getOther());
pstmt.executeUpdate();
pstmt.close();
conn.commit();
} catch (SQLException sqle) {
close(rs);
close(pstmt);
rollback(conn);
sqle.printStackTrace();
throw sqle;
} finally {
close(conn);
}
}
public void update(Lend lend) throws SQLException {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = ds.getConnection();
String sql = "UPDATE lend SET lender=?, borrower=?, auditing=?, lendadd=?, lenddate=?, returndate=?, other=? WHERE lendid=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lend.getLender());
pstmt.setString(2, lend.getBorrower());
pstmt.setString(3, lend.getAuditing());
pstmt.setString(4, lend.getLendadd());
pstmt.setString(5, lend.getLenddate());
pstmt.setString(6, lend.getReturndate());
// pstmt.setDate(5, new java.sql.Date(lend.getLenddate().getTime()));
// pstmt.setDate(6, new java.sql.Date(lend.getReturndate().getTime()));
pstmt.setString(7, lend.getOther());
pstmt.setString(8, lend.getLendid());
pstmt.executeUpdate();
close(pstmt);
conn.commit();
} catch (SQLException e) {
close(pstmt);
rollback(conn);
e.printStackTrace();
} finally {
close(conn);
}
}
public void delete(String lendid) throws SQLException {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = ds.getConnection();
String sql = "DELETE FROM lend WHERE lendid=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lendid);
pstmt.executeUpdate();
close(pstmt);
conn.commit();
} catch (SQLException e) {
close(pstmt);
rollback(conn);
e.printStackTrace();
} finally {
close(conn);
}
String[] objKeys = {"Lend", String.valueOf(lendid)};
String objKey = CacheManager.createKey(objKeys);
DAOCacheManager.invalidate(objKey);
}
public Lend retrieve(String lendid) throws SQLException {
String[] objKeys = {"Lend", String.valueOf(lendid)};
String objKey = CacheManager.createKey(objKeys);
Lend lend = (Lend) DAOCacheManager.getCache(objKey);
if (lend != null)
return lend;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
String sql = "SELECT * FROM lend WHERE lendid=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, lendid);
rs = pstmt.executeQuery();
if (rs.next()) {
lend = new Lend();
populate(lend, rs);
}
close(rs);
close(pstmt);
} catch (SQLException e) {
close(rs);
close(pstmt);
rollback(conn);
e.printStackTrace();
} finally {
close(conn);
}
DAOCacheManager.putCache(lend, objKey, 1);
return lend;
}
public List list() throws SQLException {
String[] objKeys = {"Lend", "list"};
String objKey = CacheManager.createKey(objKeys);
ArrayList list = (ArrayList) DAOCacheManager.getCache(objKey);
if (list != null)
return list;
list = new ArrayList();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
String sql = "SELECT lender, borrower, auditing, lendadd, lenddate, returndate, other, lendid FROM lend";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
Lend lend = new Lend();
populate(lend, rs);
list.add(lend);
}
close(rs);
close(pstmt);
} catch (SQLException e) {
close(rs);
close(pstmt);
rollback(conn);
e.printStackTrace();
} finally {
close(conn);
}
DAOCacheManager.putCache(list, objKey, 1);
return list;
}
public List list(int offset, int limit) throws SQLException {
String[] objKeys = {"Lend", "list", String.valueOf(offset), String.valueOf(limit)};
String objKey = CacheManager.createKey(objKeys);
ArrayList list = (ArrayList) DAOCacheManager.getCache(objKey);
if (list != null)
return list;
list = new ArrayList();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
String sql = "SELECT lender, borrower, auditing, lendadd, lenddate, returndate, other, lendid FROM lend";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(offset > 0) rs.absolute(offset);
int recCount = 0;
while((recCount++ < limit) && rs.next()) {
Lend lend = new Lend();
populate(lend, rs);
list.add(lend);
}
close(rs);
close(pstmt);
} catch (SQLException e) {
close(rs);
close(pstmt);
rollback(conn);
e.printStackTrace();
} finally {
close(conn);
}
DAOCacheManager.putCache(list, objKey, 1);
return list;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -