关于包(Package)应用规范的说明

    技术2022-05-11  131

    一、 dataBase端开发介绍:package分为两个部分:1、package head,2、package body。前者为包头的定义,后者为过程及方法的实体。只要包头定义中描述足够详细,可以隐藏包体的细节。举例如下:package head pkg_topnetis--user define data type—--用户自定义数据类型--

       --user define procedure and function—   --用户自定义过程和函数—   --the procedure proc_password_validate is the process ofpassword validate—   --the param log_id is the pa_id coloum—   --the param log_pass is the pb_yhpwd coloum—   --the param member_name is the pb_name coloum—   --if the member_name is return value “none”,it indicate that the—   --login process has been crash—   --proc_password_validate过程用于密码的验证—   --参数log_id为pa_id字段—   --参数log_pass为pb_yhpwd字段—   --参数member_name为pb_name字段—   --如果member_name的返回值为”none”,则说明验证过程出错--   procedure proc_password_validate(    log_id in number,    log_pass in varchar2,    member_name out varchar2   );

       --the procedure proc_password_change is the process ofpassword change—   --the param log_id is the pa_id coloum—   --the param org_pass is the user’s original password—   --the param new_pass is the user’s new password—   --the param status is the status of this process—   --if the status is return value 0,it indicate that the—   --change process has been validate—--if the status is return value 1,it indicate that the—   --user’s original password make misetake—   --proc_password_change过程用于密码的修改—   --参数log_id为pa_id字段—   --参数org_pass为用户原来的密码—   --参数new_pass为用户新的密码—   --参数status为该过程的状态返回值--   --如果status的返回值为0,则说明修改过程成功—   --如果status的返回值为1,则说明用户的原始密码有错--   procedure proc_password_change(    log_id in number,    org_pass in varchar2,     new_pass in varchar2,    status out number   );      end;

    因此,我们只需要提供一个规范的包头信息就可以满足大家的开发需要,而包体的详细过程则可以隐藏,当有新的需要时,只需更新包,然后给大家重发一个包头的描述就可以了,在开发阶段中,可以先采用procedure,然后统一将所有的procedure打包,在app端的修改很小,只需要更新三行代码。二、 appServer端开发解释:1、 jdbc描述:package pepper_dog999.UseJdbc;

    import java.sql.*;

    public class JdbcCallPackage {

      public static void main(String[] args) {    Connection conn;    String driver="oracle.jdbc.driver.OracleDriver";    String url="jdbc:oracle:thin:@192.168.128.41:1521:ORC2";    try{      conn=JdbcConnDb.connDb(driver,url,"pepper_dog999","bad_boy2");      CallableStatement cstmt=conn.prepareCall("{call                      pkg_topnet.proc_password_validate(?,?,?)}");      cstmt.setInt(1,10001);      cstmt.setString(2,"pass1");      cstmt.registerOutParameter(3,Types.VARCHAR);      cstmt.executeQuery();      String pbName=cstmt.getString(3);      System.out.println("the output param is pbName,and its value is:"+pbName);    }catch(SQLException ex){      System.out.println("SQL Exception:"+ex.getMessage());    }  }}

    class JdbcConnDb {

      public static Connection connDb(String driver,String url,String user,String pass){    Connection conn=null;    try{      Class.forName(driver);    }catch(java.lang.ClassNotFoundException e){      System.out.println("Class Not Found Exception:"+e.getMessage());    }    try{      conn=DriverManager.getConnection(url,user,pass);    }catch(SQLException ex){       System.out.println("SQL Exception:"+ex.getMessage());    }    return(conn);  }}

    其中类connDb类为自定义类,用来产生一个连接的对象实例。

    2、 ODBC中ADO数据模型描述:(各语言根据自身特点调整)function ConnectOra8(dsn_name,user,password) set conn=server.CreateObject("ADODB.Connection") conn.Connectionstring="DSN="&dsn_name&";uid="&user&";pwd="&password&";" conn.Open conn=ConnectOra8("dsn_name","user","password")  end funcation

      sub ODBCCallPackage()   const adOpenStatic=3   const adCmdText=&h0001   const adCmdStoredProcedure=&H0004   const adParamInput=&H0001   const adParamOutput=&H0002   const adVarChar=200   const adInteger=3   const adDate=7   SQLString="{call pkg_topnet_package.proc_password_validate(?,?,?)}"   conn=connectOra8("conn_Ora","pepper_dog999","bad_boy2")   set comm=server.createObject("ADODB.Command")   with comm    .activeConnection=conn    .commandType=adCmdText    .commandText=SQLString   end with   set pa_id=comm.CreateParameter(pa_id,adInteger,adParamInput,12) pa_id.value=10001 comm.parameters.append pa_id set pb_yhpwd=comm.CreateParameter(pb_yhpwd,adVarChar,adParamInput,20) pb_yhpwd.value="pass1" comm.parameters.append pb_yhpwd 'output set pb_name=comm.CreateParameter(pp_name,adVarChar,adParamOutput,20) comm.parameters.append pb_name   comm.execute   response.write “the output param is member_name and it’s value is”&pb_name  end sub

    三、 优越性描述:使用统一的包(package)管理可以将开发过程中无序的开发工作协调,而又不会对现有的代码造成太大的改动。其优点如下:1、 权限的管理:可以由专人管理包的更新,和包头描述的发放,由于隐藏了包体,可以使不太熟悉该开发需求的人很快的上手,因为前端开发的格式可以统一。2、 性能的改善:可以将核心的过程和性能要求较高的过程封装包体中,对性能提升大有好处。3、 代码的管理:由于包体和前端程序的分离,当需求改变时可以很快的修改。


    最新回复(0)