📄 watchdaoimpljdbc.java
字号:
throw new DatabaseException("Error executing SQL in WatchDAOImplJDBC.getWatch_byAlternateKey_MemberID_CategoryID_ForumID_ThreadID(ak).");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
/*
* Included columns: WatchID, MemberID, CategoryID, ForumID, ThreadID,
* WatchType, WatchOption, WatchStatus, WatchCreationDate, WatchLastSentDate,
* WatchEndDate
* Excluded columns:
*/
public Collection getWatches()
throws DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
Collection retValue = new ArrayList();
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT WatchID, MemberID, CategoryID, ForumID, ThreadID, WatchType, WatchOption, WatchStatus, WatchCreationDate, WatchLastSentDate, WatchEndDate");
sql.append(" FROM " + TABLE_NAME);
//sql.append(" WHERE "); // @todo: uncomment as needed
//sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
resultSet = statement.executeQuery();
while (resultSet.next()) {
WatchBean bean = new WatchBean();
bean.setWatchID(resultSet.getInt("WatchID"));
bean.setMemberID(resultSet.getInt("MemberID"));
bean.setCategoryID(resultSet.getInt("CategoryID"));
bean.setForumID(resultSet.getInt("ForumID"));
bean.setThreadID(resultSet.getInt("ThreadID"));
bean.setWatchType(resultSet.getInt("WatchType"));
bean.setWatchOption(resultSet.getInt("WatchOption"));
bean.setWatchStatus(resultSet.getInt("WatchStatus"));
bean.setWatchCreationDate(resultSet.getTimestamp("WatchCreationDate"));
bean.setWatchLastSentDate(resultSet.getTimestamp("WatchLastSentDate"));
bean.setWatchEndDate(resultSet.getTimestamp("WatchEndDate"));
retValue.add(bean);
}
return retValue;
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in WatchDAOImplJDBC.getWatchs.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
public int getNumberOfWatches()
throws AssertionException, DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT Count(*)");
sql.append(" FROM " + TABLE_NAME);
//sql.append(" WHERE "); // @todo: uncomment as needed
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
resultSet = statement.executeQuery();
if (!resultSet.next()) {
throw new AssertionException("Assertion in WatchDAOImplJDBC.getNumberOfWatches.");
}
return resultSet.getInt(1);
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in WatchDAOImplJDBC.getNumberOfWatches.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
public int getNumberOfWatches_forMember(int memberID)
throws AssertionException, DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT Count(*)");
sql.append(" FROM " + TABLE_NAME);
sql.append(" WHERE MemberID = ?");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
statement.setInt(1, memberID);
resultSet = statement.executeQuery();
if (!resultSet.next()) {
throw new AssertionException("Assertion in WatchDAOImplJDBC.getNumberOfWatches_forMember.");
}
return resultSet.getInt(1);
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in WatchDAOImplJDBC.getNumberOfWatches_forMember.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
/***************************************************************************
* Customized methods come below
***************************************************************************/
/*
* Included columns: MemberID, WatchLastSentDate
* Excluded columns: WatchID, CategoryID, ForumID, ThreadID, WatchType,
* WatchOption, WatchStatus, WatchCreationDate, WatchEndDate
*/
public Collection getMemberBeans()
throws DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
Collection retValue = new ArrayList();
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT DISTINCT MemberID, MIN(WatchLastSentDate) AS lastsent");// postgreSQL need AS
sql.append(" FROM " + TABLE_NAME);
//sql.append(" WHERE "); // @todo: uncomment as needed
//sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
sql.append(" GROUP BY MemberID ");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
resultSet = statement.executeQuery();
while (resultSet.next()) {
WatchBean bean = new WatchBean();
bean.setMemberID(resultSet.getInt("MemberID"));
bean.setWatchLastSentDate(resultSet.getTimestamp("lastsent"));
retValue.add(bean);
}
return retValue;
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in WatchDAOImplJDBC.getMemberBeans.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
/*
* Included columns: WatchID, MemberID, CategoryID, ForumID, ThreadID,
* WatchType, WatchOption, WatchStatus, WatchCreationDate, WatchLastSentDate,
* WatchEndDate
* Excluded columns:
*/
public Collection getWatches_forMember(int memberID)
throws DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
Collection retValue = new ArrayList();
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT WatchID, MemberID, CategoryID, ForumID, ThreadID, WatchType, WatchOption, WatchStatus, WatchCreationDate, WatchLastSentDate, WatchEndDate");
sql.append(" FROM " + TABLE_NAME);
sql.append(" WHERE MemberID = ? ");
//sql.append(" ORDER BY ColumnName ASC|DESC "); // @todo: uncomment as needed
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
statement.setInt(1, memberID);
resultSet = statement.executeQuery();
while (resultSet.next()) {
WatchBean bean = new WatchBean();
bean.setWatchID(resultSet.getInt("WatchID"));
bean.setMemberID(resultSet.getInt("MemberID"));
bean.setCategoryID(resultSet.getInt("CategoryID"));
bean.setForumID(resultSet.getInt("ForumID"));
bean.setThreadID(resultSet.getInt("ThreadID"));
bean.setWatchType(resultSet.getInt("WatchType"));
bean.setWatchOption(resultSet.getInt("WatchOption"));
bean.setWatchStatus(resultSet.getInt("WatchStatus"));
bean.setWatchCreationDate(resultSet.getTimestamp("WatchCreationDate"));
bean.setWatchLastSentDate(resultSet.getTimestamp("WatchLastSentDate"));
bean.setWatchEndDate(resultSet.getTimestamp("WatchEndDate"));
retValue.add(bean);
}
return retValue;
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in WatchDAOImplJDBC.getWatches_forMember.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
/*
* Included columns: WatchLastSentDate
* Excluded columns: WatchID, MemberID, CategoryID, ForumID, ThreadID,
* WatchType, WatchOption, WatchStatus, WatchCreationDate, WatchEndDate
*/
public void updateLastSentDate_forMember(int memberID,
Timestamp watchLastSentDate)
throws ObjectNotFoundException, DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
StringBuffer sql = new StringBuffer(512);
sql.append("UPDATE " + TABLE_NAME + " SET WatchLastSentDate = ?");
sql.append(" WHERE MemberID = ?");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
// // column(s) to update
statement.setTimestamp(1, watchLastSentDate);
// primary key column(s)
statement.setInt(2, memberID);
if (statement.executeUpdate() < 1) {
throw new ObjectNotFoundException("Cannot update table Watch where primary key = (" + memberID + ").");
}
m_dirty = true;
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in WatchDAOImplJDBC.updateLastSentDate_forMember.");
} finally {
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
}// end of class WatchDAOImplJDBC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -