📄 dtpropertiesdaoimpl.java
字号:
}
/**
* Deletes a single row in the dtproperties table.
*/
public void delete(DtpropertiesPk pk) throws DtpropertiesDaoException
{
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();
System.out.println( "Executing " + SQL_DELETE + " with PK: " + pk );
stmt = conn.prepareStatement( SQL_DELETE );
stmt.setInt( 1, pk.getId() );
stmt.setString( 2, pk.getProperty() );
int rows = stmt.executeUpdate();
long t2 = System.currentTimeMillis();
System.out.println( rows + " rows affected (" + (t2-t1) + " ms)" );
}
catch (SQLException _e) {
_e.printStackTrace();
throw new DtpropertiesDaoException( "SQLException: " + _e.getMessage(), _e );
}
catch (Exception _e) {
_e.printStackTrace();
throw new DtpropertiesDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Returns the rows from the dtproperties table that matches the specified primary-key value.
*/
public Dtproperties findByPrimaryKey(DtpropertiesPk pk) throws DtpropertiesDaoException
{
return findByPrimaryKey( pk.getId(), pk.getProperty() );
}
/**
* Returns all rows from the dtproperties table that match the criteria ''.
*/
public Dtproperties[] findAll() throws DtpropertiesDaoException
{
return findByDynamicSelect( SQL_SELECT + " ORDER BY id, property", null );
}
/**
* Returns all rows from the dtproperties table that match the criteria 'id = :id AND property = :property'.
*/
public Dtproperties findByPrimaryKey(int id, String property) throws DtpropertiesDaoException
{
Dtproperties ret[] = findByDynamicSelect( SQL_SELECT + " WHERE id = ? AND property = ?", new Object[] { new Integer(id), property } );
return ret.length==0 ? null : ret[0];
}
/**
* Returns all rows from the dtproperties table that match the criteria 'id = :id'.
*/
public Dtproperties[] findWhereIdEquals(int id) throws DtpropertiesDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE id = ? ORDER BY id", new Object[] { new Integer(id) } );
}
/**
* Returns all rows from the dtproperties table that match the criteria 'objectid = :objectid'.
*/
public Dtproperties[] findWhereObjectidEquals(int objectid) throws DtpropertiesDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE objectid = ? ORDER BY objectid", new Object[] { new Integer(objectid) } );
}
/**
* Returns all rows from the dtproperties table that match the criteria 'property = :property'.
*/
public Dtproperties[] findWherePropertyEquals(String property) throws DtpropertiesDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE property = ? ORDER BY property", new Object[] { property } );
}
/**
* Returns all rows from the dtproperties table that match the criteria 'value = :value'.
*/
public Dtproperties[] findWhereValueEquals(String value) throws DtpropertiesDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE value = ? ORDER BY value", new Object[] { value } );
}
/**
* Returns all rows from the dtproperties table that match the criteria 'uvalue = :uvalue'.
*/
public Dtproperties[] findWhereUvalueEquals(String uvalue) throws DtpropertiesDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE uvalue = ? ORDER BY uvalue", new Object[] { uvalue } );
}
/**
* Returns all rows from the dtproperties table that match the criteria 'lvalue = :lvalue'.
*/
public Dtproperties[] findWhereLvalueEquals(byte[] lvalue) throws DtpropertiesDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE lvalue = ? ORDER BY lvalue", new Object[] { lvalue } );
}
/**
* Returns all rows from the dtproperties table that match the criteria 'version = :version'.
*/
public Dtproperties[] findWhereVersionEquals(int version) throws DtpropertiesDaoException
{
return findByDynamicSelect( SQL_SELECT + " WHERE version = ? ORDER BY version", new Object[] { new Integer(version) } );
}
/**
* Method 'DtpropertiesDaoImpl'
*
*/
public DtpropertiesDaoImpl()
{
}
/**
* Method 'DtpropertiesDaoImpl'
*
* @param userConn
*/
public DtpropertiesDaoImpl(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..dtproperties";
}
/**
* Fetches a single row from the result set
*/
protected Dtproperties fetchSingleResult(ResultSet rs) throws SQLException
{
if (rs.next()) {
Dtproperties dto = new Dtproperties();
populateDto( dto, rs);
return dto;
} else {
return null;
}
}
/**
* Fetches multiple rows from the result set
*/
protected Dtproperties[] fetchMultiResults(ResultSet rs) throws SQLException
{
Collection resultList = new ArrayList();
while (rs.next()) {
Dtproperties dto = new Dtproperties();
populateDto( dto, rs);
resultList.add( dto );
}
Dtproperties ret[] = new Dtproperties[ resultList.size() ];
resultList.toArray( ret );
return ret;
}
/**
* Populates a DTO with data from a ResultSet
*/
protected void populateDto(Dtproperties dto, ResultSet rs) throws SQLException
{
dto.setId( rs.getInt( COLUMN_ID ) );
dto.setObjectid( rs.getInt( COLUMN_OBJECTID ) );
if (rs.wasNull()) {
dto.setObjectidNull( true );
}
dto.setProperty( rs.getString( COLUMN_PROPERTY ) );
dto.setValue( rs.getString( COLUMN_VALUE ) );
dto.setUvalue( rs.getString( COLUMN_UVALUE ) );
dto.setLvalue( super.getBlobColumn(rs, COLUMN_LVALUE ) );
dto.setVersion( rs.getInt( COLUMN_VERSION ) );
}
/**
* Returns all rows from the dtproperties table that match the specified arbitrary SQL statement
*/
public Dtproperties[] findByDynamicSelect(String sql, Object[] sqlParams) throws DtpropertiesDaoException
{
// 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 DtpropertiesDaoException( "SQLException: " + _e.getMessage(), _e );
}
catch (Exception _e) {
_e.printStackTrace();
throw new DtpropertiesDaoException( "Exception: " + _e.getMessage(), _e );
}
finally {
ResourceManager.close(rs);
ResourceManager.close(stmt);
if (!isConnSupplied) {
ResourceManager.close(conn);
}
}
}
/**
* Returns all rows from the dtproperties table that match the specified arbitrary SQL statement
*/
public Dtproperties[] findByDynamicWhere(String sql, Object[] sqlParams) throws DtpropertiesDaoException
{
// 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 DtpropertiesDaoException( "SQLException: " + _e.getMessage(), _e );
}
catch (Exception _e) {
_e.printStackTrace();
throw new DtpropertiesDaoException( "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 + -