📄 feedbackdaoimpl.java
字号:
int rows = stmt.executeUpdate();
long t2 = System.currentTimeMillis();
System.out.println( rows + " rows affected (" + (t2-t1) + " ms)" );
}
catch (SQLException _e) {
_e.printStackTrace();
throw new FeedbackDaoException( "SQLException: " + _e.getMessage(), _e );
}
catch (Exception _e) {
_e.printStackTrace();
throw new FeedbackDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Returns the rows from the Feedback table that matches the specified primary-key value.
*/
public Feedback findByPrimaryKey(FeedbackPk pk) throws FeedbackDaoException
{
return findByPrimaryKey( pk.getArticleID() );
}
/**
* Returns all rows from the Feedback table that match the criteria ''.
*/
public Feedback[] findAll() throws FeedbackDaoException
{
return findByDynamicSelect( SQL_SELECT + " ORDER BY ArticleID", null );
}
/**
* Returns all rows from the Feedback table that match the criteria 'ArticleID = :articleID'.
*/
public Feedback findByPrimaryKey(int articleID) throws FeedbackDaoException
{
Feedback ret[] = findByDynamicSelect( SQL_SELECT + " WHERE ArticleID = ?", new Object[] { new Integer(articleID) } );
return ret.length==0 ? null : ret[0];
}
/**
* Returns all rows from the Feedback table that match the criteria 'ArticleID = :articleID'.
*/
public Feedback[] findByArticle(int articleID) throws FeedbackDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE ArticleID = ?", new Object[] { new Integer(articleID) } );
}
/**
* Returns all rows from the Feedback table that match the criteria 'ArticleID = :articleID'.
*/
public Feedback[] findWhereArticleIDEquals(int articleID) throws FeedbackDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE ArticleID = ? ORDER BY ArticleID", new Object[] { new Integer(articleID) } );
}
/**
* Returns all rows from the Feedback table that match the criteria 'FeedBackID = :feedBackID'.
*/
public Feedback[] findWhereFeedBackIDEquals(int feedBackID) throws FeedbackDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE FeedBackID = ? ORDER BY FeedBackID", new Object[] { new Integer(feedBackID) } );
}
/**
* Returns all rows from the Feedback table that match the criteria 'Subject = :subject'.
*/
public Feedback[] findWhereSubjectEquals(String subject) throws FeedbackDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE Subject = ? ORDER BY Subject", new Object[] { subject } );
}
/**
* Returns all rows from the Feedback table that match the criteria 'Content = :content'.
*/
public Feedback[] findWhereContentEquals(String content) throws FeedbackDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE Content = ? ORDER BY Content", new Object[] { content } );
}
/**
* Method 'FeedbackDaoImpl'
*
*/
public FeedbackDaoImpl()
{
}
/**
* Method 'FeedbackDaoImpl'
*
* @param userConn
*/
public FeedbackDaoImpl(final java.sql.Connection userConn)
{
this.userConn = userConn;
}
/**
* Sets the value of maxRows
*/
public void setMaxRows(int maxRows)
{
this.maxRows = maxRows;
}
/**
* Gets the value of maxRows
*/
public int getMaxRows()
{
return maxRows;
}
/**
* Method 'getTableName'
*
* @return String
*/
public String getTableName()
{
return "MyBlog..Feedback";
}
/**
* Fetches a single row from the result set
*/
protected Feedback fetchSingleResult(ResultSet rs) throws SQLException
{
if (rs.next()) {
Feedback dto = new Feedback();
populateDto( dto, rs);
return dto;
} else {
return null;
}
}
/**
* Fetches multiple rows from the result set
*/
protected Feedback[] fetchMultiResults(ResultSet rs) throws SQLException
{
Collection resultList = new ArrayList();
while (rs.next()) {
Feedback dto = new Feedback();
populateDto( dto, rs);
resultList.add( dto );
}
Feedback ret[] = new Feedback[ resultList.size() ];
resultList.toArray( ret );
return ret;
}
/**
* Populates a DTO with data from a ResultSet
*/
protected void populateDto(Feedback dto, ResultSet rs) throws SQLException
{
dto.setArticleID( rs.getInt( COLUMN_ARTICLE_I_D ) );
dto.setFeedBackID( rs.getInt( COLUMN_FEED_BACK_I_D ) );
if (rs.wasNull()) {
dto.setFeedBackIDNull( true );
}
dto.setSubject( rs.getString( COLUMN_SUBJECT ) );
dto.setContent( rs.getString( COLUMN_CONTENT ) );
}
/**
* Returns all rows from the Feedback table that match the specified arbitrary SQL statement
*/
public Feedback[] findByDynamicSelect(String sql, Object[] sqlParams) throws FeedbackDaoException
{
// declare variables
final boolean isConnSupplied = (userConn != null);
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
// get the user-specified connection or get a connection from the ResourceManager
conn = isConnSupplied ? userConn : ResourceManager.getConnection();
// construct the SQL statement
final String SQL = sql;
System.out.println( "Executing " + SQL );
// prepare statement
stmt = conn.prepareStatement( SQL );
stmt.setMaxRows( maxRows );
// bind parameters
for (int i=0; sqlParams!=null && i<sqlParams.length; i++ ) {
stmt.setObject( i+1, sqlParams[i] );
}
rs = stmt.executeQuery();
// fetch the results
return fetchMultiResults(rs);
}
catch (SQLException _e) {
_e.printStackTrace();
throw new FeedbackDaoException( "SQLException: " + _e.getMessage(), _e );
}
catch (Exception _e) {
_e.printStackTrace();
throw new FeedbackDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(rs);
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Returns all rows from the Feedback table that match the specified arbitrary SQL statement
*/
public Feedback[] findByDynamicWhere(String sql, Object[] sqlParams) throws FeedbackDaoException
{
// declare variables
final boolean isConnSupplied = (userConn != null);
Connection conn = null;
PreparedStatement stmt = null;
ResultSet rs = null;
try {
// get the user-specified connection or get a connection from the ResourceManager
conn = isConnSupplied ? userConn : ResourceManager.getConnection();
// construct the SQL statement
final String SQL = SQL_SELECT + " WHERE " + sql;
System.out.println( "Executing " + SQL );
// prepare statement
stmt = conn.prepareStatement( SQL );
stmt.setMaxRows( maxRows );
// bind parameters
for (int i=0; sqlParams!=null && i<sqlParams.length; i++ ) {
stmt.setObject( i+1, sqlParams[i] );
}
rs = stmt.executeQuery();
// fetch the results
return fetchMultiResults(rs);
}
catch (SQLException _e) {
_e.printStackTrace();
throw new FeedbackDaoException( "SQLException: " + _e.getMessage(), _e );
}
catch (Exception _e) {
_e.printStackTrace();
throw new FeedbackDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(rs);
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -