⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 functiondaoimp.java

📁 权限系统以为业务逻辑提供服务为目标。这个系统的设计目的
💻 JAVA
字号:
package com.tairun.component.popedom.dao.daoimp;

import com.tairun.component.popedom.dao.FunctionDAO;
import com.tairun.component.popedom.model.Function;
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:05:11
 * To change this template use File | Settings | File Templates.
 */
public class FunctionDAOImp implements FunctionDAO {

        DataSource ds;

   public void setDataSource(DataSource ds){
         this.ds=ds;
     }

    public void create(Function function)throws DAORuntimeException{
        final Function fun=function;
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        jt.update("insert into function values(?,?,?,?,?,?,?,?,?)",new PreparedStatementSetter() {
            public void setValues(PreparedStatement ps) throws SQLException {
                ps.setLong(1,fun.getFunction());
                ps.setString(2,fun.getFunctionID());
                ps.setString(3,fun.getFunctionname());
                ps.setString(4,fun.getDiscription());
                ps.setShort(5,Primary.ENABLE);
                ps.setTimestamp(6,new Timestamp(System.currentTimeMillis()));
                ps.setTimestamp(7,new Timestamp(System.currentTimeMillis()));
                ps.setString(8,fun.getWill1());
                ps.setString(9,fun.getWill2());
            }
        });

    }

    public void update(Function function)throws DAORuntimeException{
        final Function fun=function;
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        jt.update("update function set function_name=?,discription=?,updatetime=?,will1=?,will2=? where status="+Primary.ENABLE+" and PK_function="+function.getFunction(),new PreparedStatementSetter() {
            public void setValues(PreparedStatement ps) throws SQLException {

                ps.setString(1,fun.getFunctionname());
                ps.setString(2,fun.getDiscription());
                ps.setTimestamp(3,new Timestamp(System.currentTimeMillis()));
                ps.setString(4,fun.getWill1());
                ps.setString(5,fun.getWill2());

            }
        });

    }

    public void delete(Function function)throws DAORuntimeException{
        final Function fun=function;
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        jt.query("select functionID from function where PK_function="+function.getFunction()+" and status="+Primary.ENABLE,new RowCallbackHandler() {
            public void processRow(ResultSet rs) throws SQLException {
                fun.setFunctionID(rs.getString(1));
            }
        });

        jt.update("update function set status="+Primary.DISABLE+" where functionID like '"+fun.getFunctionID()+"%' and status="+Primary.ENABLE);
        jt.update("update popedom set status="+Primary.DISABLE+" where FK_function like '"+fun.getFunctionID()+"%' and status="+Primary.ENABLE);

    }

    public Function getdetail(long function)throws DAORuntimeException{
        final Function fun=new Function();
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        jt.query("select * from function where status="+Primary.ENABLE+" and PK_function="+function,new RowCallbackHandler() {
            public void processRow(ResultSet rs) throws SQLException {
                   fun.setFunction(rs.getLong("PK_function"));
                   fun.setFunctionID(rs.getString("functionID"));
                   fun.setFunction(rs.getLong("PK_function"));
                    try {
                     fun.setFunctionname(getString(rs,"function_name"));
                     fun.setDiscription(getString(rs,"discription"));
                     } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                 }
                   fun.setCreatetime(rs.getString("createtime"));
                   fun.setUpdatetime(rs.getString("updatetime"));
                   fun.setWill1(rs.getString("will1"));
                   fun.setWill2(rs.getString("will2"));
            }
        });
        
        return fun;
    }

    public List getlist()throws DAORuntimeException{
        final List list=new Vector();
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        jt.query("select * from function where status="+Primary.ENABLE+" order by 0+RPAD(functionID,6,'0') asc",new RowCallbackHandler() {
            public void processRow(ResultSet rs) throws SQLException {
                   Function fun=new Function();
                   fun.setFunction(rs.getLong("PK_function"));
                   fun.setFunctionID(rs.getString("functionID"));
                   fun.setFunction(rs.getLong("PK_function"));
                    try {
                     fun.setFunctionname(getString(rs,"function_name"));
                     fun.setDiscription(getString(rs,"discription"));
                     } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                 }
                   fun.setStatus(rs.getShort("status"));
                   fun.setCreatetime(rs.getString("createtime"));
                   fun.setUpdatetime(rs.getString("updatetime"));
                   fun.setWill1(rs.getString("will1"));
                   fun.setWill2(rs.getString("will2"));
                   list.add(fun);
            }
        });
        return list;
    }

    public List getfunID_list()throws DAORuntimeException{
        final List list=new Vector();
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        jt.query("select PK_function,functionID from function where status="+Primary.ENABLE+" order by 0+RPAD(functionID,6,'0') asc",new RowCallbackHandler() {
            public void processRow(ResultSet rs) throws SQLException {
                Function fun=new Function();
                fun.setFunction(rs.getLong("PK_function"));
                fun.setFunctionID(rs.getString("functionID"));
                list.add(fun);
            }
        });
        return list;

    }

    public List getfirstall_list()throws DAORuntimeException{
        final List list=new Vector();
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        jt.query("select PK_function,functionID,function_name,discription  from function where status="+Primary.ENABLE+" and functionID like '__'",new RowCallbackHandler() {
            public void processRow(ResultSet rs) throws SQLException {
                Function fun=new Function();
                fun.setFunction(rs.getLong("PK_function"));
                fun.setFunctionID(rs.getString("functionID"));
                 try {
                     fun.setFunctionname(getString(rs,"function_name"));
                     fun.setDiscription(getString(rs,"discription"));
                     } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                 }
                list.add(fun);
            }
        });
        return list;
    }

    public List getsecond_list(String functionID)throws DAORuntimeException{
        final List list=new Vector();
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        jt.query("select PK_function,functionID,function_name,discription from function where status="+Primary.ENABLE+" and functionID like '"+functionID+"__'",new RowCallbackHandler() {
                public void processRow(ResultSet rs) throws SQLException {
                Function fun=new Function();
                fun.setFunction(rs.getLong("PK_function"));
                fun.setFunctionID(rs.getString("functionID"));
                 try {
                     fun.setFunctionname(getString(rs,"function_name"));
                     fun.setDiscription(getString(rs,"discription"));
                     } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                 }
                list.add(fun);
                }
            });

        return list;
    }

    public boolean isexist(String functionID,String func_name)throws DAORuntimeException{
        if(functionID!=""){
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        int result=jt.queryForInt("select count(PK_function) from function where function_name='"+func_name+"' and status="+Primary.ENABLE+" and functionID!='"+functionID+"' and functionID like '"+functionID+"__'");
        return result>0;
        }
        else{
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        int result=jt.queryForInt("select count(PK_function) from function where function_name='"+func_name+"' and status="+Primary.ENABLE+" and functionID like '"+functionID+"__'");
        return result>0;
        }
    }


    public String getmaxID(String functionID){
         JdbcTemplate jt=new JdbcTemplate(ds,true);
         final Function fun=new Function();
         jt.query("select  max(functionID) from function where status="+Primary.ENABLE+" and functionID like '"+functionID+"__' or functionID like '"+functionID+"'",new RowCallbackHandler() {
             public void processRow(ResultSet rs) throws SQLException {
                 fun.setFunctionID(rs.getString(1));
             }
         });
        String sb=fun.getFunctionID() ;
         if(sb.length()==functionID.length()+2){
          if(sb.startsWith("0"))
            return "0"+String.valueOf(Integer.parseInt(sb)+1);
          else
            return String.valueOf(Integer.parseInt(sb)+1);
         }
         else
             return functionID+"01";
     }

    public String getmaxID(){
        if(isFunctionEmpty()) {
          JdbcTemplate jt=new JdbcTemplate(ds,true);
          final Function fun=new Function();
          jt.query("select  max(functionID) from function where status='"+Primary.ENABLE+"' and functionID like '__' ",new RowCallbackHandler() {
            public void processRow(ResultSet rs) throws SQLException {
                fun.setFunctionID(rs.getString(1));
            }
        });

         String sb=fun.getFunctionID() ;
       if(sb.startsWith("0"))
          return "0"+String.valueOf(Integer.parseInt(sb)+1);
        else
          return String.valueOf(Integer.parseInt(sb)+1);
        }
        else
          return "01";
      }

    private boolean isFunctionEmpty(){
        JdbcTemplate jt=new JdbcTemplate(ds,true);
         int a= jt.queryForInt("select  count(functionID) from function where status='"+Primary.ENABLE+"' ");
          return a>=1;
    }

    public Function getdetailby_funID(String functionID){
        final Function fun=new Function();
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        jt.query("select * from function where status="+Primary.ENABLE+" and functionID='"+functionID+"'",new RowCallbackHandler() {
            public void processRow(ResultSet rs) throws SQLException {
                   fun.setFunction(rs.getLong("PK_function"));
                   fun.setFunction(rs.getLong("PK_function"));
                   fun.setFunctionID(rs.getString("functionID"));
                try {
                     fun.setFunctionname(getString(rs,"function_name"));
                     fun.setDiscription(getString(rs,"discription"));
                     } catch (UnsupportedEncodingException e) {
                    e.printStackTrace();  //To change body of catch statement use File | Settings | File Templates.
                 }
                   fun.setCreatetime(rs.getString("createtime"));
                   fun.setUpdatetime(rs.getString("updatetime"));
                   fun.setWill1(rs.getString("will1"));
                   fun.setWill2(rs.getString("will2"));

            }
        });

        return fun;

    }
    public boolean isexist_update(String functionID,String func_name)throws DAORuntimeException{
       if(functionID.length()==2){
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        int result=jt.queryForInt("select count(PK_function) from function where function_name='"+func_name+"' and status="+Primary.ENABLE+" and functionID!='"+functionID+"' and functionID like '__'");
        return result>0;
        }
        else{
           String str=functionID.substring(0,functionID.length()-2);
        JdbcTemplate jt=new JdbcTemplate(ds,true);
        int result=jt.queryForInt("select count(PK_function) from function where function_name='"+func_name+"' and status="+Primary.ENABLE+" and functionID!='"+functionID+"' and functionID like '"+str+"__'");
        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 + -