📄 usedatedao.java
字号:
//---------------------------------------------------------
// Application: Equipment of System
// Author : eSingle
// File : UsedateDAO.java
//
// Copyright 2002 LandSoft Corp.
// Generated at Mon Nov 18 20:14:24 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 UsedateDAO extends DAO {
public UsedateDAO(DataSource ds) {
super(ds);
}
public void insert(Usedate usedate) throws SQLException {
String sql;
sql = "INSERT INTO usedate (usedatename) VALUES (?)";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, usedate.getUsedatename());
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(Usedate usedate) throws SQLException {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = ds.getConnection();
String sql = "UPDATE usedate SET WHERE usedatename=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, usedate.getUsedatename());
pstmt.executeUpdate();
close(pstmt);
conn.commit();
} catch (SQLException e) {
close(pstmt);
rollback(conn);
e.printStackTrace();
} finally {
close(conn);
}
}
public void delete(String usedatename) throws SQLException {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = ds.getConnection();
String sql = "DELETE FROM usedate WHERE usedatename=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, usedatename);
pstmt.executeUpdate();
close(pstmt);
conn.commit();
} catch (SQLException e) {
close(pstmt);
rollback(conn);
e.printStackTrace();
} finally {
close(conn);
}
String[] objKeys = {"Usedate", String.valueOf(usedatename)};
String objKey = CacheManager.createKey(objKeys);
DAOCacheManager.invalidate(objKey);
}
public Usedate retrieve(String usedatename) throws SQLException {
String[] objKeys = {"Usedate", String.valueOf(usedatename)};
String objKey = CacheManager.createKey(objKeys);
Usedate usedate = (Usedate) DAOCacheManager.getCache(objKey);
if (usedate != null)
return usedate;
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
String sql = "SELECT * FROM usedate WHERE usedatename=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, usedatename);
rs = pstmt.executeQuery();
if (rs.next()) {
usedate = new Usedate();
populate(usedate, rs);
}
close(rs);
close(pstmt);
} catch (SQLException e) {
close(rs);
close(pstmt);
rollback(conn);
e.printStackTrace();
} finally {
close(conn);
}
DAOCacheManager.putCache(usedate, objKey, 1);
return usedate;
}
public List list() throws SQLException {
String[] objKeys = {"Usedate", "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 usedatename FROM usedate";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while(rs.next()) {
Usedate usedate = new Usedate();
populate(usedate, rs);
list.add(usedate);
}
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 = {"Usedate", "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 usedatename FROM usedate";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if(offset > 0) rs.absolute(offset);
int recCount = 0;
while((recCount++ < limit) && rs.next()) {
Usedate usedate = new Usedate();
populate(usedate, rs);
list.add(usedate);
}
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 + -