📄 oaswitchpersistentbase.java
字号:
/*
* oaswitchPersistentBase.java
* Generated using xgen and texen from beanpersistentbase.vm
* Tue Jun 22 16:48:12 CST 2004
*/
package com.sure.oa.oaswitch;
import java.sql.Connection;
import java.sql.Statement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.DatabaseMetaData;
import java.sql.BatchUpdateException;
import java.math.BigDecimal;
import com.sure.businessmodel.Page;
import java.io.*;
import java.util.*;
import com.sure.util.database.*;
/**
* 存取与OA交换信息的属性
* @author datonghuiren@sohu.com
*/
public abstract class oaswitchPersistentBase {
/** class attributes */
transient protected boolean recordExists = false;
transient protected boolean handleConcurrency = false;
transient protected boolean handleAutoIncrement = true;
protected oaswitch bean;
public oaswitchPersistentBase(oaswitch bean) { setBean(bean); }
public oaswitchPersistentBase(oaswitch bean, boolean recordExists) { setBean(bean); setRecordExists(recordExists); }
public oaswitch getBean() { return bean; }
public void setBean(oaswitch bean) { this.bean = bean; }
public boolean getRecordExists() { return recordExists; }
public void setRecordExists(boolean recordExists) { this.recordExists = recordExists; }
/**
* Load this object from a result set
* If null fields are present in the table, catch the NullPointerException
*/
public static oaswitch load(ResultSet rs) throws SQLException {
oaswitch theBean = new oaswitch ();
try{ theBean.setDocId ( rs.getInt("docId") ); } catch(NullPointerException e){}
try{ theBean.setDocKind ( rs.getString("docKind") ); } catch(NullPointerException e){}
try{ theBean.setDocTitle ( rs.getString("docTitle") ); } catch(NullPointerException e){}
try{ theBean.setSendDate ( rs.getTimestamp("sendDate") ); } catch(NullPointerException e){}
try{ theBean.setSendUnitName ( rs.getString("sendUnitName") ); } catch(NullPointerException e){}
try{ theBean.setSecret ( rs.getString("secret") ); } catch(NullPointerException e){}
try{ theBean.setEmergency ( rs.getString("emergency") ); } catch(NullPointerException e){}
try{ theBean.setSecretTime ( rs.getString("secretTime") ); } catch(NullPointerException e){}
try{ theBean.setDocNoPre ( rs.getString("docNoPre") ); } catch(NullPointerException e){}
try{ theBean.setYearNo ( rs.getString("yearNo") ); } catch(NullPointerException e){}
try{ theBean.setWaterNo ( rs.getString("waterNo") ); } catch(NullPointerException e){}
try{ theBean.setPublishDate ( rs.getTimestamp("publishDate") ); } catch(NullPointerException e){}
try{ theBean.setPublishPerson ( rs.getString("publishPerson") ); } catch(NullPointerException e){}
try{ theBean.setInputPerson ( rs.getString("inputPerson") ); } catch(NullPointerException e){}
try{ theBean.setCheckPerson ( rs.getString("checkPerson") ); } catch(NullPointerException e){}
try{ theBean.setPrintUnit ( rs.getString("printUnit") ); } catch(NullPointerException e){}
try{ theBean.setPrintDate ( rs.getTimestamp("printDate") ); } catch(NullPointerException e){}
try{ theBean.setSendTo ( rs.getString("sendTo") ); } catch(NullPointerException e){}
try{ theBean.setCc ( rs.getString("cc") ); } catch(NullPointerException e){}
try{ theBean.setReportTo ( rs.getString("reportTo") ); } catch(NullPointerException e){}
try{ theBean.setSubject ( rs.getString("subject") ); } catch(NullPointerException e){}
try{ theBean.setSealTime ( rs.getTimestamp("sealTime") ); } catch(NullPointerException e){}
try{ theBean.setSealPerson ( rs.getString("sealPerson") ); } catch(NullPointerException e){}
try{ theBean.setPrintnumber ( rs.getInt("printnumber") ); } catch(NullPointerException e){}
try{ theBean.setDocMemo ( rs.getString("docMemo") ); } catch(NullPointerException e){}
try{ theBean.setStatus ( rs.getString("status") ); } catch(NullPointerException e){}
return theBean;
}
/**
* Load a range of records from a connection, according to the where clause.
* Returns a map of records accessible by a column value. (ie: foreign key)
*/
public static Map loadByKey(Connection conn, String where, String colname)
throws SQLException{
HashMap map = new HashMap();
Statement s = conn.createStatement();
String sql = "SELECT docId,docKind,docTitle,sendDate,sendUnitName,secret,emergency,secretTime,docNoPre,yearNo,waterNo,publishDate,publishPerson,inputPerson,checkPerson,printUnit,printDate,sendTo,cc,reportTo,subject,sealTime,sealPerson,printnumber,docMemo,status FROM oaswitch " + where;
ResultSet rs = s.executeQuery( sql );
while(rs.next()){
oaswitch theBean = new oaswitch ();
int col = rs.findColumn(colname);
String key = rs.getString(col);
theBean = load(rs);
map.put(key, theBean);
}
rs.close();
s.close();
return map;
}
/**
* Load a range of records from a connection, according to the where clause
*/
public static Vector load(Connection conn, String where) throws SQLException{
Vector beans = new Vector();
Statement s = conn.createStatement();
String sql = "SELECT docId,docKind,docTitle,sendDate,sendUnitName,secret,emergency,secretTime,docNoPre,yearNo,waterNo,publishDate,publishPerson,inputPerson,checkPerson,printUnit,printDate,sendTo,cc,reportTo,subject,sealTime,sealPerson,printnumber,docMemo,status FROM oaswitch " + where;
ResultSet rs = s.executeQuery( sql );
while(rs.next()){
oaswitch theBean = new oaswitch ();
theBean = load(rs);
beans.addElement(theBean);
}
rs.close();
s.close();
return beans;
}
/**
* Load a range of records using a scrollable resultset and absolute cursor
*/
public static Vector load(Connection conn, String where,
int startRow, int rowCount) throws SQLException {
Vector beans = new Vector();
String sql = "SELECT docId,docKind,docTitle,sendDate,sendUnitName,secret,emergency,secretTime,docNoPre,yearNo,waterNo,publishDate,publishPerson,inputPerson,checkPerson,printUnit,printDate,sendTo,cc,reportTo,subject,sealTime,sealPerson,printnumber,docMemo,status FROM oaswitch ";
if(where.length() > 0)
sql = sql + where;
Statement s = conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
s.setMaxRows(startRow + rowCount - 1);
ResultSet rs = s.executeQuery( sql );
rs.absolute(startRow);
do {
oaswitch theBean = new oaswitch ();
theBean = load(rs);
beans.addElement(theBean);
} while(rs.next());
rs.close();
s.close();
return beans;
}
/**
* Load a Page of records using a scrollable resultset and absolute cursor
*/
public static Page load(Connection conn, int startRow, int pageSize,
String where) throws SQLException {
int count = getCount(conn, where);
if (count == 0) return new Page(pageSize);
startRow = Page.getValidStart(startRow, count, pageSize);
Vector beans = load(conn, where, startRow, pageSize);
return new Page(beans, startRow, count, pageSize);
}
/**
* Persist the record. Performs a sql update or insert.
* The primary key will be "set" upon insert.
* If autocommit is on, turn it off to make a transactional
* check of the tcn field.
*/
public void persist(Connection conn) throws SQLException{
if(recordExists){
if(handleConcurrency){
//regenerate source if you want the bean to handle concurrency
}else{
update(conn);
}
}else{
if(handleAutoIncrement){
setPrimaryKey(conn);
}
insert(conn);
}
}
/**
* Set the primary key field using the MAX value of the column
* If the primary key is a string, check for existence and return
* If the primary key is already set (in a new bean its 0) return
*/
public void setPrimaryKey(Connection conn) throws SQLException{
try{
IDGeneratorManager idGeneratorManager = new IDGeneratorManager();
bean.setDocId( idGeneratorManager.setNextValue("oaswitch"));
}
catch(SQLException se){
se.printStackTrace();
}
}
/**
* Insert a new record
*/
public void insert(Connection conn) throws SQLException {
PreparedStatement pstmt = null;
pstmt = conn.prepareStatement("INSERT INTO oaswitch ( docId,docKind,docTitle,sendDate,sendUnitName,secret,emergency,secretTime,docNoPre,yearNo,waterNo,publishDate,publishPerson,inputPerson,checkPerson,printUnit,printDate,sendTo,cc,reportTo,subject,sealTime,sealPerson,printnumber,docMemo,status ) VALUES ( ?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,?,? )");
pstmt.setInt ( 1, bean.getDocId().intValue() );
pstmt.setString ( 2, bean.getDocKind() );
pstmt.setString ( 3, bean.getDocTitle() );
pstmt.setTimestamp ( 4, new java.sql.Timestamp ( bean.getSendDate ().getTime() ) );
pstmt.setString ( 5, bean.getSendUnitName() );
pstmt.setString ( 6, bean.getSecret() );
pstmt.setString ( 7, bean.getEmergency() );
pstmt.setString ( 8, bean.getSecretTime() );
pstmt.setString ( 9, bean.getDocNoPre() );
pstmt.setString ( 10, bean.getYearNo() );
pstmt.setString ( 11, bean.getWaterNo() );
pstmt.setTimestamp ( 12, new java.sql.Timestamp ( bean.getPublishDate ().getTime() ) );
pstmt.setString ( 13, bean.getPublishPerson() );
pstmt.setString ( 14, bean.getInputPerson() );
pstmt.setString ( 15, bean.getCheckPerson() );
pstmt.setString ( 16, bean.getPrintUnit() );
pstmt.setTimestamp ( 17, new java.sql.Timestamp ( bean.getPrintDate ().getTime() ) );
pstmt.setString ( 18, bean.getSendTo() );
pstmt.setString ( 19, bean.getCc() );
pstmt.setString ( 20, bean.getReportTo() );
pstmt.setString ( 21, bean.getSubject() );
pstmt.setTimestamp ( 22, new java.sql.Timestamp ( bean.getSealTime ().getTime() ) );
pstmt.setString ( 23, bean.getSealPerson() );
pstmt.setInt ( 24, bean.getPrintnumber().intValue() );
pstmt.setString ( 25, bean.getDocMemo() );
pstmt.setString ( 26, bean.getStatus() );
pstmt.executeUpdate();
pstmt.close();
recordExists = true;
}
/**
* Update an existing record
* (including the primary key)
*/
public void update(Connection conn) throws SQLException{
PreparedStatement pstmt = null;
pstmt = conn.prepareStatement("UPDATE oaswitch SET " +
"docId = ?," +
"docKind = ?," +
"docTitle = ?," +
"sendDate = ?," +
"sendUnitName = ?," +
"secret = ?," +
"emergency = ?," +
"secretTime = ?," +
"docNoPre = ?," +
"yearNo = ?," +
"waterNo = ?," +
"publishDate = ?," +
"publishPerson = ?," +
"inputPerson = ?," +
"checkPerson = ?," +
"printUnit = ?," +
"printDate = ?," +
"sendTo = ?," +
"cc = ?," +
"reportTo = ?," +
"subject = ?," +
"sealTime = ?," +
"sealPerson = ?," +
"printnumber = ?," +
"docMemo = ?," +
"status = ? " +
"WHERE docId = ?" );
pstmt.setInt ( 1, bean.getDocId ().intValue() );
pstmt.setString ( 2, bean.getDocKind () );
pstmt.setString ( 3, bean.getDocTitle () );
pstmt.setTimestamp ( 4, new java.sql.Timestamp ( bean.getSendDate ().getTime() ) );
pstmt.setString ( 5, bean.getSendUnitName () );
pstmt.setString ( 6, bean.getSecret () );
pstmt.setString ( 7, bean.getEmergency () );
pstmt.setString ( 8, bean.getSecretTime () );
pstmt.setString ( 9, bean.getDocNoPre () );
pstmt.setString ( 10, bean.getYearNo () );
pstmt.setString ( 11, bean.getWaterNo () );
pstmt.setTimestamp ( 12, new java.sql.Timestamp ( bean.getPublishDate ().getTime() ) );
pstmt.setString ( 13, bean.getPublishPerson () );
pstmt.setString ( 14, bean.getInputPerson () );
pstmt.setString ( 15, bean.getCheckPerson () );
pstmt.setString ( 16, bean.getPrintUnit () );
pstmt.setTimestamp ( 17, new java.sql.Timestamp ( bean.getPrintDate ().getTime() ) );
pstmt.setString ( 18, bean.getSendTo () );
pstmt.setString ( 19, bean.getCc () );
pstmt.setString ( 20, bean.getReportTo () );
pstmt.setString ( 21, bean.getSubject () );
pstmt.setTimestamp ( 22, new java.sql.Timestamp ( bean.getSealTime ().getTime() ) );
pstmt.setString ( 23, bean.getSealPerson () );
pstmt.setInt ( 24, bean.getPrintnumber ().intValue() );
pstmt.setString ( 25, bean.getDocMemo () );
pstmt.setString ( 26, bean.getStatus () );
pstmt.setInt ( 27, bean.getDocId ().intValue() );
pstmt.executeUpdate();
pstmt.close();
}
/**
* Delete an existing record
*/
public static void delete(Connection conn, String where) throws SQLException{
Statement stmt = conn.createStatement();
String sql = "DELETE FROM oaswitch " + where;
stmt.execute(sql);
stmt.close();
}
/**
* Delete an existing record using a prepared statement
*/
public void delete(Connection conn) throws SQLException{
PreparedStatement pstmt = null;
pstmt = conn.prepareStatement("DELETE FROM oaswitch WHERE docId = ?");
pstmt.setInt( 1, bean.getDocId ().intValue() );
pstmt.executeUpdate();
pstmt.close();
}
/**
* get total count of a range of records from a connection, according to the where clause
*/
protected static int getCount(Connection conn, String where) throws SQLException{
Statement s = conn.createStatement();
String sql = "SELECT count(docId) FROM oaswitch ";
if(where.length() > 0) {
where = where.toLowerCase();
if (where.indexOf("order") > 0) {
where = where.substring(0,where.lastIndexOf("order"));
}
sql = sql + where;
}
ResultSet rs = s.executeQuery( sql );
int count = 0;
if( rs.next()){
count = rs.getInt(1);
}
rs.close();
s.close();
return count;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -