📄 pmattachmentdaoimpljdbc.java
字号:
} finally {
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
/*
* Included columns: PmAttachID, MemberID, PmAttachFilename, PmAttachFileSize, PmAttachMimeType,
* PmAttachDesc, PmAttachCreationIP, PmAttachCreationDate, PmAttachModifiedDate, PmAttachDownloadCount,
* PmAttachOption, PmAttachStatus
* Excluded columns:
*/
public PmAttachmentBean getPmAttachment(int pmAttachID)
throws ObjectNotFoundException, DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT PmAttachID, MemberID, PmAttachFilename, PmAttachFileSize, PmAttachMimeType, PmAttachDesc, PmAttachCreationIP, PmAttachCreationDate, PmAttachModifiedDate, PmAttachDownloadCount, PmAttachOption, PmAttachStatus");
sql.append(" FROM " + TABLE_NAME);
sql.append(" WHERE PmAttachID = ?");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
statement.setInt(1, pmAttachID);
resultSet = statement.executeQuery();
if(!resultSet.next()) {
throw new ObjectNotFoundException("Cannot find the row in table PmAttachment where primary key = (" + pmAttachID + ").");
}
PmAttachmentBean bean = new PmAttachmentBean();
// @todo: uncomment the following line(s) as needed
//bean.setPmAttachID(pmAttachID);
bean.setPmAttachID(resultSet.getInt("PmAttachID"));
bean.setMemberID(resultSet.getInt("MemberID"));
bean.setPmAttachFilename(resultSet.getString("PmAttachFilename"));
bean.setPmAttachFileSize(resultSet.getInt("PmAttachFileSize"));
bean.setPmAttachMimeType(resultSet.getString("PmAttachMimeType"));
bean.setPmAttachDesc(resultSet.getString("PmAttachDesc"));
bean.setPmAttachCreationIP(resultSet.getString("PmAttachCreationIP"));
bean.setPmAttachCreationDate(resultSet.getTimestamp("PmAttachCreationDate"));
bean.setPmAttachModifiedDate(resultSet.getTimestamp("PmAttachModifiedDate"));
bean.setPmAttachDownloadCount(resultSet.getInt("PmAttachDownloadCount"));
bean.setPmAttachOption(resultSet.getInt("PmAttachOption"));
bean.setPmAttachStatus(resultSet.getInt("PmAttachStatus"));
return bean;
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in PmAttachmentDAOImplJDBC.getPmAttachment(pk).");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
/**
* This method should be call only when we can make sure that postID is in database
*/
public void increaseDownloadCount(int pmAttachID)
throws DatabaseException, ObjectNotFoundException {
Connection connection = null;
PreparedStatement statement = null;
String sql = "UPDATE " + TABLE_NAME + " SET PmAttachDownloadCount = PmAttachDownloadCount + 1 WHERE PmAttachID = ?";
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql);
statement.setInt(1, pmAttachID);
if (statement.executeUpdate() != 1) {
throw new ObjectNotFoundException("Cannot update the PmAttachDownloadCount in table PmAttachment. Please contact Web site Administrator.");
}
// @todo: review these lines below
// ATTENTION !!!
setDirty(true);
} catch (SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in PmAttachmentDAOImplJDBC.increaseDownloadCount(pk).");
} finally {
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
/*
* Included columns: PmAttachID, MemberID, PmAttachFilename, PmAttachFileSize, PmAttachMimeType,
* PmAttachDesc, PmAttachCreationIP, PmAttachCreationDate, PmAttachModifiedDate, PmAttachDownloadCount,
* PmAttachOption, PmAttachStatus
* Excluded columns:
*/
public Collection getPmAttachments_inMessage(int messageID)
throws DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
Collection retValue = new ArrayList();
StringBuffer sql = new StringBuffer(512);
sql.append("SELECT pmattachment.PmAttachID, MemberID, PmAttachFilename, PmAttachFileSize, PmAttachMimeType, PmAttachDesc, PmAttachCreationIP, PmAttachCreationDate, PmAttachModifiedDate, PmAttachDownloadCount, PmAttachOption, PmAttachStatus");
sql.append(" FROM " + TABLE_NAME + " pmattachment, " + PmAttachMessageDAO.TABLE_NAME + " pmattachmessage");
sql.append(" WHERE pmattachment.PmAttachID = pmattachmessage.PmAttachID AND pmattachmessage.MessageID = ?");
sql.append(" ORDER BY pmattachment.PmAttachID ASC ");
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
statement.setInt(1, messageID);
resultSet = statement.executeQuery();
while (resultSet.next()) {
PmAttachmentBean bean = new PmAttachmentBean();
bean.setPmAttachID(resultSet.getInt("PmAttachID"));
bean.setMemberID(resultSet.getInt("MemberID"));
bean.setPmAttachFilename(resultSet.getString("PmAttachFilename"));
bean.setPmAttachFileSize(resultSet.getInt("PmAttachFileSize"));
bean.setPmAttachMimeType(resultSet.getString("PmAttachMimeType"));
bean.setPmAttachDesc(resultSet.getString("PmAttachDesc"));
bean.setPmAttachCreationIP(resultSet.getString("PmAttachCreationIP"));
bean.setPmAttachCreationDate(resultSet.getTimestamp("PmAttachCreationDate"));
bean.setPmAttachModifiedDate(resultSet.getTimestamp("PmAttachModifiedDate"));
bean.setPmAttachDownloadCount(resultSet.getInt("PmAttachDownloadCount"));
bean.setPmAttachOption(resultSet.getInt("PmAttachOption"));
bean.setPmAttachStatus(resultSet.getInt("PmAttachStatus"));
retValue.add(bean);
}
return retValue;
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in PmAttachmentDAOImplJDBC.getPmAttachments_inMessage.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
/*
* Included columns: PmAttachID, MemberID, PmAttachFilename, PmAttachFileSize, PmAttachMimeType,
* PmAttachDesc, PmAttachCreationIP, PmAttachCreationDate, PmAttachModifiedDate, PmAttachDownloadCount,
* PmAttachOption, PmAttachStatus
* Excluded columns:
*/
// Note: this method using LEFT JOIN
public Collection getOrphanPmAttachments()
throws DatabaseException {
Connection connection = null;
PreparedStatement statement = null;
ResultSet resultSet = null;
Collection retValue = new ArrayList();
StringBuffer sql = new StringBuffer(512);
if (DBUtils.getDatabaseType() == DBUtils.DATABASE_ORACLE) {
// Oracle query
sql.append("SELECT pmattachment.PmAttachID, MemberID, PmAttachFilename, PmAttachFileSize, PmAttachMimeType, PmAttachDesc, PmAttachCreationIP, PmAttachCreationDate, PmAttachModifiedDate, PmAttachDownloadCount, PmAttachOption, PmAttachStatus");
sql.append(" FROM " + TABLE_NAME + " pmattachment , " + PmAttachMessageDAO.TABLE_NAME + " pmattachmessage");
sql.append(" WHERE pmattachment.PmAttachID = pmattachmessage.PmAttachID (+) ");
sql.append(" AND pmattachmessage.PmAttachID IS NULL ");
} else {
// standard query
sql.append("SELECT pmattachment.PmAttachID, MemberID, PmAttachFilename, PmAttachFileSize, PmAttachMimeType, PmAttachDesc, PmAttachCreationIP, PmAttachCreationDate, PmAttachModifiedDate, PmAttachDownloadCount, PmAttachOption, PmAttachStatus");
sql.append(" FROM " + TABLE_NAME + " pmattachment LEFT JOIN " + PmAttachMessageDAO.TABLE_NAME + " pmattachmessage");
sql.append(" ON pmattachment.PmAttachID = pmattachmessage.PmAttachID ");
sql.append(" WHERE pmattachmessage.PmAttachID IS NULL ");
}
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql.toString());
resultSet = statement.executeQuery();
while (resultSet.next()) {
PmAttachmentBean bean = new PmAttachmentBean();
bean.setPmAttachID(resultSet.getInt("PmAttachID"));
bean.setMemberID(resultSet.getInt("MemberID"));
bean.setPmAttachFilename(resultSet.getString("PmAttachFilename"));
bean.setPmAttachFileSize(resultSet.getInt("PmAttachFileSize"));
bean.setPmAttachMimeType(resultSet.getString("PmAttachMimeType"));
bean.setPmAttachDesc(resultSet.getString("PmAttachDesc"));
bean.setPmAttachCreationIP(resultSet.getString("PmAttachCreationIP"));
bean.setPmAttachCreationDate(resultSet.getTimestamp("PmAttachCreationDate"));
bean.setPmAttachModifiedDate(resultSet.getTimestamp("PmAttachModifiedDate"));
bean.setPmAttachDownloadCount(resultSet.getInt("PmAttachDownloadCount"));
bean.setPmAttachOption(resultSet.getInt("PmAttachOption"));
bean.setPmAttachStatus(resultSet.getInt("PmAttachStatus"));
retValue.add(bean);
}
return retValue;
} catch(SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in PmAttachmentDAOImplJDBC.getOrphanPmAttachments.");
} finally {
DBUtils.closeResultSet(resultSet);
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
public void updatePmAttachOption(int pmAttachID, int pmAttachOption)
throws DatabaseException, ObjectNotFoundException {
Connection connection = null;
PreparedStatement statement = null;
String sql = "UPDATE " + TABLE_NAME + " SET PmAttachOption = ? WHERE PmAttachID = ?";
try {
connection = DBUtils.getConnection();
statement = connection.prepareStatement(sql);
statement.setInt(1, pmAttachOption);
statement.setInt(2, pmAttachID);
if (statement.executeUpdate() != 1) {
throw new ObjectNotFoundException("Cannot update the Option in table PmAttachment. Please contact Web site Administrator.");
}
setDirty(true);
} catch (SQLException sqle) {
log.error("Sql Execution Error!", sqle);
throw new DatabaseException("Error executing SQL in PmAttachmentDAOImplJDBC.updatePmAttachOption.");
} finally {
DBUtils.closeStatement(statement);
DBUtils.closeConnection(connection);
}
}
}// end of class PmAttachmentDAOImplJDBC
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -