我的DAO层应该怎么修改或者替换?

09-02-06 sjbwylbs

我的项目是跟人家买来的。

说说我的DAO层是怎么样的吧

来个代码说明更加明白

package com.common.dao;

public class AdminDao extends BaseDao {

/**

* SQL statement for this table

*/

public static final String SQL_SELECT = "select * FROM TBLAdmin";

public static final String SQL_INSERT = "insert TBL_Admin(userID,username,password) values(?,?,?)";

public static final String SQL_UPDATE = "update TBL_Admin set username=?,password=? where userID=?";

public static final String SQL_DELETE = "delete from TBL_Admin where userID=?";

public static Admin AllAdmin[] = null;

private static AdminDao adminDao = new AdminDao();

private static DateFormat defaultFormat = DateFormat.getDateTimeInstance();

public static AdminDao getInstance()

{

return adminDao;

}

synchronized public void delete(int id) throws AdminDaoException

{

Connection conn = null;

Statement stmt = null;

PreparedStatement pstmt = null;

ResultSet rs = null;

conn = connMgr.getConnection("hqdbpool");

try

{

final String SQL = SQL_DELETE;

pstmt = conn.prepareStatement(SQL);

pstmt.setInt(1, id);

pstmt.executeUpdate();

}

catch (SQLException sqlException)

{

throw new AdminDaoException(sqlException.getMessage());

}

finally

{

boolean closeSuccess = true;

try

{

if (rs != null)

{

rs.close();

}

if (stmt != null)

{

stmt.close();

}

if (pstmt != null)

{

pstmt.close();

}

if (conn != null && !conn.isClosed())

{

connMgr.freeConnection("hqdbpool", conn);

}

}

catch (SQLException ex)

{

closeSuccess = false;

log.error("数据库连接失败", ex);

}

finally

{

if (!closeSuccess)

{

try

{

conn.close();

}

catch (Exception ex)

{

System.out.println("finally关闭数据库连接失败");

log.error("finally关闭数据库连接失败", ex);

}

}

}

}

/* 同步更新缓存数组 */

List<Admin> list = new ArrayList<Admin>();

if (null != AllAdmin && AllAdmin.length > 0)

{

for (int j = 0; j < AllAdmin.length; j++)

{

if (AllAdmin[j].getUserID() == id)

{

continue;

}

list.add(AllAdmin[j]);

}

Admin[] buList = new Admin[list.size()];

list.toArray(buList);

AllAdmin = buList;

}

}

public Admin[] findAll() throws AdminDaoException

{

if (AllAdmin != null && AllAdmin.length > 0)

{

return AllAdmin;

}

Connection conn = null;

Statement stmt = null;

PreparedStatement pstmt = null;

ResultSet rs = null;

conn = connMgr.getConnection("hqdbpool");

try

{

final String SQL = SQL_SELECT + " Order By UserID";

pstmt = conn.prepareStatement(SQL);

rs = pstmt.executeQuery();

List<Admin> temp = new ArrayList<Admin>();

while (rs.next())

{

int i = 1;

Admin valueObject = new Admin();

try

{

valueObject.setUserID(rs.getInt(i++));

valueObject.setUsername(rs.getString(i++));

valueObject.setPassword(rs.getString(i++));

}

catch (SQLException sqlException)

{

throw new AdminDaoException(sqlException.getMessage());

}

temp.add(valueObject);

}

Admin[] ret = new Admin[temp.size()];

temp.toArray(ret);

AllAdmin = ret;

return ret;

}

catch (SQLException sqlException)

{

throw new AdminDaoException(sqlException.getMessage());

}

...............

}

我提出2个疑问:

1。这样加载的内存会申请不到吗?会不会太多,假如我别的数据库太大的话

2. 有没有别的数据库方案,可以替换掉我的DAO层

sjbwylbs
2009-02-07 03:06
我不在看这个帖子了。应该没人会帮忙或者知道的了。。

有心人PM我一下吧,谢谢

猜你喜欢