📄 dtpropertiesdaoimpl.java
字号:
/*
* This source file was generated by FireStorm/DAO 3.0 (build 99)
* on 26-十月-2005 at 09:50:56
*
* If you purchase a full license for FireStorm/DAO you can customize this file header.
*
* For more information please visit http://www.codefutures.com/products/firestorm
*/
package cn.wanfeng.myblog.jdbc;
import cn.wanfeng.myblog.dao.*;
import cn.wanfeng.myblog.factory.*;
import cn.wanfeng.myblog.dto.*;
import cn.wanfeng.myblog.exceptions.*;
import java.sql.Connection;
import java.sql.Types;
import java.util.Collection;
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;
import java.sql.CallableStatement;
public class DtpropertiesDaoImpl extends AbstractDataAccessObject implements DtpropertiesDao
{
/**
* The factory class for this DAO has two versions of the create() method - one thattakes no arguments and one that takes a Connection argument. If the Connection versionis chosen then the connection will be stored in this attribute and will be used by allcalls to this DAO, otherwise a new Connection will be allocated for each operation.
*/
protected java.sql.Connection userConn;
/**
* All finder methods in this class use this SELECT constant to build their queries
*/
protected final String SQL_SELECT = "SELECT id, objectid, property, value, uvalue, lvalue, version 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() + " ( objectid, property, value, uvalue, lvalue, version ) VALUES ( ?, ?, ?, ?, ?, ? );SELECT @@IDENTITY";
/**
* SQL UPDATE statement for this table
*/
protected final String SQL_UPDATE = "UPDATE " + getTableName() + " SET objectid = ?, property = ?, value = ?, uvalue = ?, lvalue = ?, version = ? WHERE id = ? AND property = ?";
/**
* SQL DELETE statement for this table
*/
protected final String SQL_DELETE = "DELETE FROM " + getTableName() + " WHERE id = ? AND property = ?";
/**
* Index of column id
*/
protected static final int COLUMN_ID = 1;
/**
* Index of column objectid
*/
protected static final int COLUMN_OBJECTID = 2;
/**
* Index of column property
*/
protected static final int COLUMN_PROPERTY = 3;
/**
* Index of column value
*/
protected static final int COLUMN_VALUE = 4;
/**
* Index of column uvalue
*/
protected static final int COLUMN_UVALUE = 5;
/**
* Index of column lvalue
*/
protected static final int COLUMN_LVALUE = 6;
/**
* Index of column version
*/
protected static final int COLUMN_VERSION = 7;
/**
* Number of columns
*/
protected static final int NUMBER_OF_COLUMNS = 7;
/**
* Index of primary-key column id
*/
protected static final int PK_COLUMN_ID = 1;
/**
* Index of primary-key column property
*/
protected static final int PK_COLUMN_PROPERTY = 2;
/**
* Inserts a new row in the dtproperties table.
*/
public DtpropertiesPk insert(Dtproperties dto) throws DtpropertiesDaoException
{
long t1 = System.currentTimeMillis();
// declare variables
final boolean isConnSupplied = (userConn != null);
Connection conn = null;
CallableStatement 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.prepareCall( SQL_INSERT );
// no bind statement for auto increment column 'id
if (dto.isObjectidNull()) {
stmt.setNull( COLUMN_OBJECTID - 1, Types.INTEGER );
} else {
stmt.setInt( COLUMN_OBJECTID - 1, dto.getObjectid() );
}
stmt.setString( COLUMN_PROPERTY - 1, dto.getProperty() );
stmt.setString( COLUMN_VALUE - 1, dto.getValue() );
stmt.setString( COLUMN_UVALUE - 1, dto.getUvalue() );
super.setBlobColumn(stmt, COLUMN_LVALUE - 1, dto.getLvalue() );
stmt.setInt( COLUMN_VERSION - 1, dto.getVersion() );
System.out.println( "Executing " + SQL_INSERT + " with DTO: " + dto );
stmt.execute();
int rows = stmt.getUpdateCount();
System.out.println( rows + " rows affected" );
// retrieve values from IDENTITY columns
boolean moreResults = true;
while (moreResults || rows != -1) {
try {
rs = stmt.getResultSet();
}
catch (IllegalArgumentException e) {
e.printStackTrace();
}
if (rs != null) {
rs.next();
dto.setId( rs.getInt( 1 ) );
}
moreResults = stmt.getMoreResults();
rows = stmt.getUpdateCount();
}
return dto.createPk();
}
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);
}
}
}
/**
* Updates a single row in the dtproperties table.
*/
public void update(DtpropertiesPk pk, Dtproperties dto) 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();
StringBuffer sql = new StringBuffer();
sql.append( "UPDATE " + getTableName() + " SET " );
boolean modified = false;
if (dto.isIdModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "id=?" );
modified=true;
}
if (dto.isObjectidModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "objectid=?" );
modified=true;
}
if (dto.isPropertyModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "property=?" );
modified=true;
}
if (dto.isValueModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "value=?" );
modified=true;
}
if (dto.isUvalueModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "uvalue=?" );
modified=true;
}
if (dto.isLvalueModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "lvalue=?" );
modified=true;
}
if (dto.isVersionModified()) {
if (modified) {
sql.append( ", " );
}
sql.append( "version=?" );
modified=true;
}
if (!modified) {
// nothing to update
return;
}
sql.append( " WHERE id=? AND property=?" );
System.out.println( "Executing " + sql.toString() + " with values: " + dto );
stmt = conn.prepareStatement( sql.toString() );
int index = 1;
if (dto.isIdModified()) {
stmt.setInt( index++, dto.getId() );
}
if (dto.isObjectidModified()) {
if (dto.isObjectidNull()) {
stmt.setNull( index++, Types.INTEGER );
} else {
stmt.setInt( index++, dto.getObjectid() );
}
}
if (dto.isPropertyModified()) {
stmt.setString( index++, dto.getProperty() );
}
if (dto.isValueModified()) {
stmt.setString( index++, dto.getValue() );
}
if (dto.isUvalueModified()) {
stmt.setString( index++, dto.getUvalue() );
}
if (dto.isLvalueModified()) {
super.setBlobColumn(stmt, index++, dto.getLvalue() );
}
if (dto.isVersionModified()) {
stmt.setInt( index++, dto.getVersion() );
}
stmt.setInt( index++, pk.getId() );
stmt.setString( index++, 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);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -