?? htdaoimpl.java
字號:
/*
* Author :Cao guangxin
* on 26-三月-2005 at 09:54:55
*
* Mail:relationinfo@hotmail.com
*
* visit:www.relaioninfo.com or www.helpsoft.org
*/
package org.helpsoft.contract.jdbc;
import org.helpsoft.contract.dao.*;
import org.helpsoft.contract.factory.*;
import java.util.Date;
import org.helpsoft.contract.dto.*;
import org.helpsoft.contract.exceptions.*;
import java.sql.Connection;
import java.sql.Types;
import java.util.Collection;
import org.apache.log4j.Logger;
import java.sql.PreparedStatement;
import java.sql.Statement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Time;
import java.util.List;
import java.util.Iterator;
import java.util.ArrayList;
public class HtDaoImpl extends AbstractDataAccessObject implements HtDao
{
/**
* The factory class for this DAO has two versions of the create() method - one that
takes no arguments and one that takes a Connection argument. If the Connection version
is chosen then the connection will be stored in this attribute and will be used by all
calls to this DAO, otherwise a new Connection will be allocated for each operation.
*/
protected java.sql.Connection userConn;
protected static final Logger logger = Logger.getLogger( HtDaoImpl.class );
/**
* All finder methods in this class use this SELECT constant to build their queries
*/
protected final String SQL_SELECT = "SELECT htbm, jfdlrbm, jfbm, qsdd, yf, yfdlr, jfqzrq, yfqzrq, xmmc, htnr FROM " + getTableName() + "";
/**
* Finder methods will pass this value to the JDBC setMaxRows method
*/
private int maxRows;
/**
* SQL INSERT statement for this table
*/
protected final String SQL_INSERT = "INSERT INTO " + getTableName() + " ( htbm, jfdlrbm, jfbm, qsdd, yf, yfdlr, jfqzrq, yfqzrq, xmmc, htnr ) VALUES ( ?, ?, ?, ?, ?, ?, ?, ?, ?, ? )";
/**
* SQL UPDATE statement for this table
*/
protected final String SQL_UPDATE = "UPDATE " + getTableName() + " SET htbm = ?, jfdlrbm = ?, jfbm = ?, qsdd = ?, yf = ?, yfdlr = ?, jfqzrq = ?, yfqzrq = ?, xmmc = ?, htnr = ? WHERE htbm = ?";
/**
* SQL DELETE statement for this table
*/
protected final String SQL_DELETE = "DELETE FROM " + getTableName() + " WHERE htbm = ?";
/**
* Index of column htbm
*/
protected static final int COLUMN_HTBM = 1;
/**
* Index of column jfdlrbm
*/
protected static final int COLUMN_JFDLRBM = 2;
/**
* Index of column jfbm
*/
protected static final int COLUMN_JFBM = 3;
/**
* Index of column qsdd
*/
protected static final int COLUMN_QSDD = 4;
/**
* Index of column yf
*/
protected static final int COLUMN_YF = 5;
/**
* Index of column yfdlr
*/
protected static final int COLUMN_YFDLR = 6;
/**
* Index of column jfqzrq
*/
protected static final int COLUMN_JFQZRQ = 7;
/**
* Index of column yfqzrq
*/
protected static final int COLUMN_YFQZRQ = 8;
/**
* Index of column xmmc
*/
protected static final int COLUMN_XMMC = 9;
/**
* Index of column htnr
*/
protected static final int COLUMN_HTNR = 10;
/**
* Number of columns
*/
protected static final int NUMBER_OF_COLUMNS = 10;
/**
* Index of primary-key column htbm
*/
protected static final int PK_COLUMN_HTBM = 1;
/**
* Inserts a new row in the ht table.
*/
public HtPk insert(Ht dto) throws HtDaoException
{
long t1 = System.currentTimeMillis();
// 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();
stmt = conn.prepareStatement( SQL_INSERT );
stmt.setString( COLUMN_HTBM, dto.getHtbm() );
stmt.setString( COLUMN_JFDLRBM, dto.getJfdlrbm() );
stmt.setString( COLUMN_JFBM, dto.getJfbm() );
stmt.setString( COLUMN_QSDD, dto.getQsdd() );
stmt.setString( COLUMN_YF, dto.getYf() );
stmt.setString( COLUMN_YFDLR, dto.getYfdlr() );
stmt.setTimestamp(COLUMN_JFQZRQ, dto.getJfqzrq()==null ? null : new java.sql.Timestamp( dto.getJfqzrq().getTime() ) );
stmt.setTimestamp(COLUMN_YFQZRQ, dto.getYfqzrq()==null ? null : new java.sql.Timestamp( dto.getYfqzrq().getTime() ) );
stmt.setString( COLUMN_XMMC, dto.getXmmc() );
stmt.setString( COLUMN_HTNR, dto.getHtnr() );
if (logger.isDebugEnabled()) {
logger.debug( "Executing " + SQL_INSERT + " with DTO: " + dto);
}
int rows = stmt.executeUpdate();
long t2 = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug( rows + " rows affected (" + (t2-t1) + " ms)");
}
return dto.createPk();
}
catch (SQLException _e) {
logger.error( "SQLException: " + _e.getMessage(), _e );
throw new HtDaoException( "SQLException: " + _e.getMessage(), _e );
}
catch (Exception _e) {
logger.error( "Exception: " + _e.getMessage(), _e );
throw new HtDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Updates a single row in the ht table.
*/
public void update(HtPk pk, Ht dto) throws HtDaoException
{
long t1 = System.currentTimeMillis();
// declare variables
final boolean isConnSupplied = (userConn != null);
Connection conn = null;
PreparedStatement stmt = null;
try {
// get the user-specified connection or get a connection from the ResourceManager
conn = isConnSupplied ? userConn : ResourceManager.getConnection();
if (logger.isDebugEnabled()) {
logger.debug( "Executing " + SQL_UPDATE + " with DTO: " + dto);
}
stmt = conn.prepareStatement( SQL_UPDATE );
stmt.setString( COLUMN_HTBM, dto.getHtbm() );
stmt.setString( COLUMN_JFDLRBM, dto.getJfdlrbm() );
stmt.setString( COLUMN_JFBM, dto.getJfbm() );
stmt.setString( COLUMN_QSDD, dto.getQsdd() );
stmt.setString( COLUMN_YF, dto.getYf() );
stmt.setString( COLUMN_YFDLR, dto.getYfdlr() );
stmt.setTimestamp(COLUMN_JFQZRQ, dto.getJfqzrq()==null ? null : new java.sql.Timestamp( dto.getJfqzrq().getTime() ) );
stmt.setTimestamp(COLUMN_YFQZRQ, dto.getYfqzrq()==null ? null : new java.sql.Timestamp( dto.getYfqzrq().getTime() ) );
stmt.setString( COLUMN_XMMC, dto.getXmmc() );
stmt.setString( COLUMN_HTNR, dto.getHtnr() );
stmt.setString( 11, pk.getHtbm() );
int rows = stmt.executeUpdate();
long t2 = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug( rows + " rows affected (" + (t2-t1) + " ms)");
}
}
catch (SQLException _e) {
logger.error( "SQLException: " + _e.getMessage(), _e );
throw new HtDaoException( "SQLException: " + _e.getMessage(), _e );
}
catch (Exception _e) {
logger.error( "Exception: " + _e.getMessage(), _e );
throw new HtDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Deletes a single row in the ht table.
*/
public void delete(HtPk pk) throws HtDaoException
{
long t1 = System.currentTimeMillis();
// declare variables
final boolean isConnSupplied = (userConn != null);
Connection conn = null;
PreparedStatement stmt = null;
try {
// get the user-specified connection or get a connection from the ResourceManager
conn = isConnSupplied ? userConn : ResourceManager.getConnection();
if (logger.isDebugEnabled()) {
logger.debug( "Executing " + SQL_DELETE + " with PK: " + pk);
}
stmt = conn.prepareStatement( SQL_DELETE );
stmt.setString( 1, pk.getHtbm() );
int rows = stmt.executeUpdate();
long t2 = System.currentTimeMillis();
if (logger.isDebugEnabled()) {
logger.debug( rows + " rows affected (" + (t2-t1) + " ms)");
}
}
catch (SQLException _e) {
logger.error( "SQLException: " + _e.getMessage(), _e );
throw new HtDaoException( "SQLException: " + _e.getMessage(), _e );
}
catch (Exception _e) {
logger.error( "Exception: " + _e.getMessage(), _e );
throw new HtDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Returns the rows from the ht table that matches the specified primary-key value.
*/
public Ht findByPrimaryKey(HtPk pk) throws HtDaoException
{
return findByPrimaryKey( pk.getHtbm() );
}
/**
* Returns all rows from the ht table that match the criteria ''.
*/
public Ht[] findAll() throws HtDaoException
{
return findByDynamicSelect( SQL_SELECT + " ORDER BY htbm", null );
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -