?? userdaoimp.java
字號:
package com.tairun.component.popedom.dao.daoimp;
import com.tairun.component.popedom.dao.UserDAO;
import com.tairun.component.popedom.model.User;
import com.tairun.component.popedom.util.Primary;
import com.tairun.component.popedom.util.DAORuntimeException;
import javax.sql.DataSource;
import java.util.List;
import java.util.Vector;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.ResultSet;
import java.io.UnsupportedEncodingException;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.PreparedStatementSetter;
import org.springframework.jdbc.core.RowCallbackHandler;
import com.org.common.Encrypt;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2005-12-6
* Time: 9:03:54
* To change this template use File | Settings | File Templates.
*/
public class UserDAOImp implements UserDAO{
DataSource ds;
public void setDataSource(DataSource ds){
this.ds=ds;
}
public void create(User user)throws DAORuntimeException{
final User user1=user;
JdbcTemplate jt=new JdbcTemplate(ds,true);
jt.update("insert into user values(?,?,?,?,?,?,?,?,?,?,?)",new PreparedStatementSetter() {
public void setValues(PreparedStatement ps) throws SQLException {
ps.setLong(1,user1.getAccountID());
ps.setString(2,user1.getUserID());
ps.setString(3,Encrypt.encode(user1.getPassword()));
ps.setInt(4,user1.getPersonID());
ps.setLong(5,user1.getRoleID());
ps.setShort(6,user1.getWorkstatusID());
ps.setShort(7,Primary.ENABLE);
ps.setTimestamp(8,new Timestamp(System.currentTimeMillis()));
ps.setTimestamp(9,new Timestamp(System.currentTimeMillis()));
ps.setString(10,user1.getWill1());
ps.setString(11,user1.getWill2());
}
});
}
public void update(User user)throws DAORuntimeException{
final User user1=user;
JdbcTemplate jt=new JdbcTemplate(ds,true);
jt.update("update user set userID=?,password=?,FK_personID=?,FK_roleID=?,workstatusID=?,createtime=?,updatetime=?,will1=?,will2=? where PK_accountID='"+ user1.getAccountID()+"' and status='"+Primary.ENABLE+"'",new PreparedStatementSetter() {
public void setValues(PreparedStatement ps) throws SQLException {
ps.setString(1,user1.getUserID());
ps.setString(2,Encrypt.encode(user1.getPassword()));
ps.setInt(3,user1.getPersonID());
ps.setLong(4,user1.getRoleID());
ps.setShort(5,user1.getWorkstatusID());
ps.setTimestamp(6,new Timestamp(System.currentTimeMillis()));
ps.setTimestamp(7,new Timestamp(System.currentTimeMillis()));
ps.setString(8,user1.getWill1());
ps.setString(9,user1.getWill2());
}
});
}
public void delete(User user)throws DAORuntimeException{
final User user1=user;
JdbcTemplate jt=new JdbcTemplate(ds,true);
jt.update("update user set status=? where PK_accountID='"+ user1.getAccountID()+"' and status='"+Primary.ENABLE+"'",new PreparedStatementSetter() {
public void setValues(PreparedStatement ps) throws SQLException {
ps.setShort(1,Primary.DISABLE);
}
});
}
public User getdetail(long accountID)throws DAORuntimeException{
final User user=new User();
JdbcTemplate jt=new JdbcTemplate(ds,true);
jt.query("select * from user where PK_accountID="+accountID+" and status="+Primary.ENABLE,new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
user.setAccountID(rs.getLong("PK_accountID"));
try {
user.setUserID(getString(rs,"userID"));
user.setPassword(getString(rs,"password"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
user.setPersonID(rs.getInt("FK_personID"));
user.setRoleID(rs.getLong("FK_roleID"));
user.setWorkstatusID(rs.getShort("workstatusID"));
user.setStatus(rs.getShort("status"));
user.setCreatetime(rs.getString("createtime"));
user.setUpdatetime(rs.getString("updatetime"));
user.setWill1(rs.getString("will1"));
user.setWill2(rs.getString("will2"));
}
});
return user;
}
public List getlist()throws DAORuntimeException{
final List list=new Vector();
JdbcTemplate jt=new JdbcTemplate(ds,true);
jt.query("select * from user where status="+Primary.ENABLE,new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
User user=new User();
user.setAccountID(rs.getLong("PK_accountID"));
try {
user.setUserID(getString(rs,"userID"));
user.setPassword(getString(rs,"password"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
user.setPersonID(rs.getInt("FK_personID"));
user.setRoleID(rs.getLong("FK_roleID"));
user.setWorkstatusID(rs.getShort("workstatusID"));
user.setStatus(rs.getShort("status"));
user.setCreatetime(rs.getString("createtime"));
user.setUpdatetime(rs.getString("updatetime"));
user.setWill1(rs.getString("will1"));
user.setWill2(rs.getString("will2"));
list.add(user);
}
});
return list;
}
public boolean isexist(long accountID,String userID)throws DAORuntimeException{
if(accountID>0){
JdbcTemplate jt=new JdbcTemplate(ds,true);
int result=jt.queryForInt("select count(PK_accountID) from user where status="+Primary.ENABLE+" and userID='"+userID+"' and PK_accountID!="+accountID);
return result>0;
}
else{
JdbcTemplate jt=new JdbcTemplate(ds,true);
int result=jt.queryForInt("select count(PK_accountID) from user where status="+Primary.ENABLE+" and userID='"+userID+"'");
return result>0;
}
}
private String getString(ResultSet rs,String colName) throws SQLException, UnsupportedEncodingException {
return new String((""+ rs.getString(colName)).getBytes(),"8859_1");
}
}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -