?? roledaoimp.java
字號:
package com.tairun.component.popedom.dao.daoimp;
import com.tairun.component.popedom.dao.RoleDAO;
import com.tairun.component.popedom.model.Role;
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;
/**
* Created by IntelliJ IDEA.
* User: Administrator
* Date: 2005-12-6
* Time: 9:04:57
* To change this template use File | Settings | File Templates.
*/
public class RoleDAOImp implements RoleDAO{
DataSource ds;
public void setDataSource(DataSource ds){
this.ds=ds;
}
public void create(Role role)throws DAORuntimeException{
final Role role1=role;
JdbcTemplate jt=new JdbcTemplate(ds);
jt.update("insert into role values(?,?,?,?,?,?,?,?)",new PreparedStatementSetter() {
public void setValues(PreparedStatement ps) throws SQLException {
ps.setLong(1,role1.getRoleID());
ps.setString(2,role1.getRolename());
ps.setString(3,role1.getDiscription());
ps.setShort(4,Primary.ENABLE);
ps.setTimestamp(5,new Timestamp(System.currentTimeMillis()));
ps.setTimestamp(6,new Timestamp(System.currentTimeMillis()));
ps.setString(7,role1.getWill1());
ps.setString(8,role1.getWill2());
}
});
}
public void update(Role role)throws DAORuntimeException{
final Role role1=role;
JdbcTemplate jt=new JdbcTemplate(ds);
jt.update("update role set role_name=?,discription=?,updatetime=?,will1=?,will2=? where PK_roleID="+role.getRoleID()+" and status="+Primary.ENABLE,new PreparedStatementSetter() {
public void setValues(PreparedStatement ps) throws SQLException {
ps.setString(1,role1.getRolename());
ps.setString(2,role1.getDiscription());
ps.setTimestamp(3,new Timestamp(System.currentTimeMillis()));
ps.setString(4,role1.getWill1());
ps.setString(5,role1.getWill2());
}
});
}
public void delete(Role role)throws DAORuntimeException{
JdbcTemplate jt=new JdbcTemplate(ds);
jt.update("update role set status=? where PK_roleID="+role.getRoleID(),new PreparedStatementSetter() {
public void setValues(PreparedStatement ps) throws SQLException {
ps.setShort(1,Primary.DISABLE);
}
});
jt.update("update popedom set status=? where FK_roleID="+role.getRoleID(),new PreparedStatementSetter() {
public void setValues(PreparedStatement ps) throws SQLException {
ps.setShort(1,Primary.DISABLE);
}
});
}
public Role getdetail(long roleID)throws DAORuntimeException{
final Role role=new Role();
JdbcTemplate jt=new JdbcTemplate(ds);
jt.query("select * from role where PK_roleID="+roleID+" and status="+Primary.ENABLE,new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
role.setRoleID(rs.getLong("PK_roleID"));
try {
role.setRolename(getString(rs,"role_name"));
role.setDiscription(getString(rs,"discription"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
role.setStatus(rs.getShort("status"));
role.setCreatetime(rs.getString("createtime"));
role.setUpdatetime(rs.getString("updatetime"));
role.setWill1(rs.getString("will1"));
role.setWill2(rs.getString("will2"));
}
});
return role;
}
public List getlist()throws DAORuntimeException{
final List list=new Vector();
JdbcTemplate jt=new JdbcTemplate(ds,true);
jt.query("select * from role where status="+Primary.ENABLE,new RowCallbackHandler() {
public void processRow(ResultSet rs) throws SQLException {
Role role=new Role();
role.setRoleID(rs.getLong("PK_roleID"));
try {
role.setRolename(getString(rs,"role_name"));
role.setDiscription(getString(rs,"discription"));
} catch (UnsupportedEncodingException e) {
e.printStackTrace(); //To change body of catch statement use File | Settings | File Templates.
}
role.setStatus(rs.getShort("status"));
role.setCreatetime(rs.getString("createtime"));
role.setUpdatetime(rs.getString("updatetime"));
role.setWill1(rs.getString("will1"));
role.setWill2(rs.getString("will2"));
list.add(role);
}
});
return list;
}
public boolean isexist(long roleID,String role_name)throws DAORuntimeException{
if(roleID>0){
JdbcTemplate jt=new JdbcTemplate(ds,true);
int result=jt.queryForInt("select count(PK_roleID) from role where status="+Primary.ENABLE+" and role_name='"+role_name+"' and PK_roleID!="+roleID);
return result>0;
}
else{
JdbcTemplate jt=new JdbcTemplate(ds,true);
int result=jt.queryForInt("select count(PK_roleID) from role where status="+Primary.ENABLE+" and role_name='"+role_name+"'");
return result>0;
}
}
public long getroleID(String rolename)throws DAORuntimeException{
JdbcTemplate jt=new JdbcTemplate(ds,true);
long roleID=jt.queryForLong("select PK_roleID from role where role_name='"+rolename+"' and status="+Primary.ENABLE);
return roleID;
}
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 + -