📄 rolefunctiondao.java
字号:
//---------------------------------------------------------
// Application: Portal of Enterprice
// Author : eSingle
// File : RolefunctionDAO.java
//
// Copyright 2002 LandSoft Corp.
// Generated at Mon Nov 18 19:57:57 CST 2002
// Created by caoguangxin
// mailto:gxcao@mail.tsinghua.edu.cn
//---------------------------------------------------------
package com.landsoft.portal.managent.dao;
import java.io.*;
import java.sql.*;
import java.util.*;
import javax.sql.*;
import com.landsoft.portal.managent.model.*;
import com.landsoft.portal.managent.util.CacheManager;
public class RolefunctionDAO
extends DAO {
public RolefunctionDAO(DataSource ds) {
super(ds);
}
public void insert(Rolefunction rolefunction) throws SQLException {
String sql;
sql = "INSERT INTO rolefunction (rolename, functionname) VALUES (?, ?)";
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, rolefunction.getRolename());
pstmt.setString(2, rolefunction.getFunctionname());
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(Rolefunction rolefunction) throws SQLException {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = ds.getConnection();
String sql =
"UPDATE rolefunction SET WHERE rolename=? AND functionname=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, rolefunction.getRolename());
pstmt.setString(2, rolefunction.getFunctionname());
pstmt.executeUpdate();
close(pstmt);
conn.commit();
}
catch (SQLException e) {
close(pstmt);
rollback(conn);
e.printStackTrace();
}
finally {
close(conn);
}
}
public void delete(String rolename, String functionname) throws SQLException {
Connection conn = null;
PreparedStatement pstmt = null;
try {
conn = ds.getConnection();
String sql =
"DELETE FROM rolefunction WHERE rolename=? AND functionname=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, rolename);
pstmt.setString(2, functionname);
pstmt.executeUpdate();
close(pstmt);
conn.commit();
}
catch (SQLException e) {
close(pstmt);
rollback(conn);
e.printStackTrace();
}
finally {
close(conn);
}
String[] objKeys = {
"Rolefunction", String.valueOf(rolename), String.valueOf(functionname)};
String objKey = CacheManager.createKey(objKeys);
DAOCacheManager.invalidate(objKey);
}
public Rolefunction retrieve(String rolename, String functionname) throws
SQLException {
String[] objKeys = {
"Rolefunction", String.valueOf(rolename), String.valueOf(functionname)};
String objKey = CacheManager.createKey(objKeys);
Rolefunction rolefunction = (Rolefunction) DAOCacheManager.getCache(objKey);
if (rolefunction != null) {
return rolefunction;
}
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
String sql =
"SELECT * FROM rolefunction WHERE rolename=? AND functionname=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, rolename);
pstmt.setString(2, functionname);
rs = pstmt.executeQuery();
if (rs.next()) {
rolefunction = new Rolefunction();
rolefunction.setRolename(rs.getString(1));
rolefunction.setFunctionname(rs.getString(2));
populate(rolefunction, rs);
}
close(rs);
close(pstmt);
}
catch (SQLException e) {
close(rs);
close(pstmt);
rollback(conn);
e.printStackTrace();
}
finally {
close(conn);
}
DAOCacheManager.putCache(rolefunction, objKey, 1);
return rolefunction;
}
public List all() throws SQLException {
ArrayList list = new ArrayList();
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
try {
conn = ds.getConnection();
String sql = "SELECT rolename, functionname FROM rolefunction";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
Rolefunction rolefunction = new Rolefunction();
rolefunction.setRolename(rs.getString(1));
rolefunction.setFunctionname(rs.getString(2));
populate(rolefunction, rs);
list.add(rolefunction);
}
close(rs);
close(pstmt);
}
catch (SQLException e) {
close(rs);
close(pstmt);
rollback(conn);
e.printStackTrace();
}
finally {
close(conn);
}
return list;
}
public List list() throws SQLException {
String[] objKeys = {
"Rolefunction", "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 rolename, functionname FROM rolefunction";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
while (rs.next()) {
Rolefunction rolefunction = new Rolefunction();
rolefunction.setRolename(rs.getString(1));
rolefunction.setFunctionname(rs.getString(2));
populate(rolefunction, rs);
list.add(rolefunction);
}
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 = {
"Rolefunction", "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 rolename, functionname FROM rolefunction";
pstmt = conn.prepareStatement(sql);
rs = pstmt.executeQuery();
if (offset > 0) {
rs.absolute(offset);
}
int recCount = 0;
while ( (recCount++ < limit) && rs.next()) {
Rolefunction rolefunction = new Rolefunction();
rolefunction.setRolename(rs.getString(1));
rolefunction.setFunctionname(rs.getString(2));
populate(rolefunction, rs);
list.add(rolefunction);
}
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 + -