亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? jobbean.java

?? 21天學通J2EE的例子
?? JAVA
字號:
package data;

import java.rmi.*;
import java.sql.*;
import java.util.*;
import javax.ejb.*;
import javax.naming.*;
import javax.sql.*;

public class JobBean implements EntityBean
{
    private DataSource dataSource;
    private SkillLocalHome skillHome;
    private LocationLocalHome locationHome;
    private CustomerLocalHome customerHome;

    private String ref;
    private String customer;
    private String description;
    private LocationLocal location;

    private CustomerLocal customerObj; // derived

    // vector attribute; list of SkillLocal ref's.
    private List skills;

    public String getRef () {
        return ref;
    }

    public String getCustomer () {
        return customer;
    }

    public CustomerLocal getCustomerObj () {
        return customerObj;
    }

    public String getDescription () {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public LocationLocal getLocation () {
        return location;
    }

    public void setLocation(LocationLocal location) {
        this.location = location;
    }

    /** returns (copy of) skills */
    public Collection getSkills() {
        return new ArrayList(skills);
    }

    public void setSkills(Collection skills) {
        // just validate that the collection holds references to SkillLocal's
        for(Iterator iter = getSkills().iterator(); iter.hasNext(); ) {
            SkillLocal skill = (SkillLocal)iter.next();
        }

        // replace the list of skills with that defined.
        this.skills = new ArrayList(skills);
    }

    // EJB methods start here

    public void ejbPostCreate (String ref, String customer) {}

    public JobPK ejbCreate (String ref, String customer) throws CreateException {

        // validate customer login is valid.
        try {
            customerObj = customerHome.findByPrimaryKey(customer);
        } catch(FinderException ex) {
            error("Invalid customer.", ex);
        }

        JobPK key = new JobPK(ref,customer);
        try {
            // workaround; should call ejbHome.findByPrimaryKey, but
            // ctx.getEJBHome() returns null...
            /*
            JobLocalHome jobHome = (JobLocalHome)ctx.getEJBHome();
            System.out.println("jobHome = " + jobHome + ", key = " + key);
            */
            ejbFindByPrimaryKey(key);
            throw new CreateException("Duplicate job name: "+key);
        }
        catch (FinderException ex) {}
        
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            con = dataSource.getConnection();
            stmt = con.prepareStatement(
            "INSERT INTO Job (ref,customer) VALUES (?,?)");

            stmt.setString(1, ref);
            stmt.setString(2, customerObj.getLogin());
            stmt.executeUpdate();
        }
        catch (SQLException e) {
            error("Error creating job "+key,e);
        }
        finally {
            closeConnection(con, stmt, null, null);
        }
        this.ref = ref;
        this.customer = customer;
        this.description = description;
        this.location = null;

        this.skills = new ArrayList();
        return key;
    }
    
    public JobPK ejbFindByPrimaryKey(JobPK key) throws FinderException {
        Connection con = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            con = dataSource.getConnection();
            stmt = con.prepareStatement(
            "SELECT ref FROM Job WHERE ref = ? AND customer = ?");

            stmt.setString(1, key.getRef());
            stmt.setString(2, key.getCustomer());
            rs = stmt.executeQuery();

            if (!rs.next()) {
                throw new FinderException("Unknown job: "+key);
            }
            return key;
        }
        catch (SQLException e) {
            error("Error in findByPrimaryKey for "+key,e);
        }
        finally {
            closeConnection(con, stmt, null, rs);
        }
        return null;
    }
    
    public Collection ejbFindByCustomer(String customer) throws FinderException {
        Connection con = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            con = dataSource.getConnection();
            stmt = con.prepareStatement(
            "SELECT ref, customer FROM Job WHERE customer = ? ORDER BY ref");

            stmt.setString(1, customer);
            rs = stmt.executeQuery();

            Collection col = new ArrayList();
            while (rs.next()) {
                String nextRef = rs.getString(1);
                String nextCustomer = rs.getString(2);
                // validate customer exists
                CustomerLocal nextCustomerObj = customerHome.findByPrimaryKey(nextCustomer);
                col.add(new JobPK(nextRef,nextCustomerObj.getLogin()));
            }
            return col;
        }
        catch (SQLException e) {
            error("Error in findByCustomer: "+customer,e);
        }
        catch (FinderException e) {
            error("Error in findByCustomer, invalid customer: "+customer,e);
        }
        finally {
            closeConnection(con, stmt, null, rs);
        }
        return null;
    }

    public Collection ejbFindByLocation(String location) throws FinderException {
        Connection con = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            con = dataSource.getConnection();
            stmt = con.prepareStatement(
            "SELECT ref, customer FROM Job WHERE location = ? ORDER BY customer, ref");

            stmt.setString(1, location);
            rs = stmt.executeQuery();

            Collection col = new ArrayList();
            while (rs.next()) {
                String ref = rs.getString(1);
                String customer = rs.getString(2);
                // validate customer exists
                CustomerLocal customerObj = customerHome.findByPrimaryKey(customer);
                col.add(new JobPK(ref,customer));
            }
            return col;
        }
        catch (SQLException e) {
            error("Error in findByLocation: "+location,e);
        }
        catch (FinderException e) {
            error("Error in findByLocation, invalid customer: "+customer,e);
        }
        finally {
            closeConnection(con, stmt, null, rs);
        }
        return null;
    }

    public void ejbHomeDeleteByCustomer(String customer) {

        Connection con = null;
        PreparedStatement stmt2 = null;
        PreparedStatement stmt1 = null;
        try {
            con = dataSource.getConnection();

            stmt1 = con.prepareStatement(
            "DELETE FROM JobSkill WHERE customer = ?");
            stmt2 = con.prepareStatement(
            "DELETE FROM Job WHERE customer = ?");

            stmt1.setString(1, customer);
            stmt2.setString(1, customer);

            stmt1.executeUpdate();
            stmt2.executeUpdate();
        }
        catch (SQLException e) {
            error("Error removing all jobs for "+customer,e);
        }
        finally {
            closeConnection(con, stmt1, stmt2, null);
        }
    }

    public void ejbLoad(){
        JobPK key= (JobPK)ctx.getPrimaryKey();
        Connection con = null;
        PreparedStatement stmt = null;
        ResultSet rs = null;
        try {
            con = dataSource.getConnection();
            stmt = con.prepareStatement(
            "SELECT description,location FROM Job WHERE ref = ? AND customer = ?");

            stmt.setString(1, key.getRef());
            stmt.setString(2, key.getCustomer());
            rs = stmt.executeQuery();

            if (!rs.next()) {
                error("No data found in ejbLoad for "+key,null);
            }
            this.ref = key.getRef();
            this.customer = key.getCustomer();
            this.customerObj = customerHome.findByPrimaryKey(this.customer); // derived
            this.description = rs.getString(1);
            String locationName = rs.getString(2);
            this.location = (locationName != null)?locationHome.findByPrimaryKey(locationName):null;

            // load skills
            stmt = con.prepareStatement(
            "SELECT job, customer, skill FROM JobSkill WHERE job = ? AND customer = ? ORDER BY skill");

            stmt.setString(1, ref);
            stmt.setString(2, customerObj.getLogin());
            rs = stmt.executeQuery();

            List skillNameList = new ArrayList();
            while (rs.next()) {
                skillNameList.add(rs.getString(3));
            }

            this.skills = skillHome.lookup(skillNameList);
        }
        catch (SQLException e) {
            error("Error in ejbLoad for "+key,e);
        }
        catch (FinderException e) {
            error("Error in ejbLoad (invalid customer or location) for "+key,e);
        }
        finally {
            closeConnection(con, stmt, null, rs);
        }
    }

    public void ejbStore(){
        Connection con = null;
        PreparedStatement stmt = null;
        try {
            con = dataSource.getConnection();
            stmt = con.prepareStatement(
            "UPDATE Job SET description = ?, location = ? WHERE ref = ? AND customer = ?");

            stmt.setString(1, description);
            if (location != null) {
                stmt.setString(2, location.getName());
            } else {
                stmt.setNull(2, java.sql.Types.VARCHAR);
            }
            stmt.setString(3, ref);
            stmt.setString(4, customerObj.getLogin());
            stmt.executeUpdate();

            // delete all skills
            stmt = con.prepareStatement(
            "DELETE FROM JobSkill WHERE job = ? and customer = ?");
    
            stmt.setString(1, ref);
            stmt.setString(2, customerObj.getLogin());
            stmt.executeUpdate();
    
            // add back in all skills
            for(Iterator iter = getSkills().iterator(); iter.hasNext(); ) {
                SkillLocal skill = (SkillLocal)iter.next();
    
                stmt = con.prepareStatement(
                "INSERT INTO JobSkill (job,customer,skill) VALUES (?,?,?)");
    
                stmt.setString(1, ref);
                stmt.setString(2, customerObj.getLogin());
                stmt.setString(3, skill.getName());
                stmt.executeUpdate();
            }
        }
        catch (SQLException e) {
            error("Error in ejbStore for "+ref+","+customer,e);
        }
        finally {
            closeConnection(con, stmt, null, null);
        }
    }

    public void ejbPassivate(){
        ref = null;
        customer = null;
        customerObj = null;
        description = null;
        location = null;
    }

    public void ejbActivate(){
    }

    public void ejbRemove(){
        JobPK key = (JobPK)ctx.getPrimaryKey();
        
        Connection con = null;
        PreparedStatement stmt1 = null;
        PreparedStatement stmt2 = null;
        try {
            con = dataSource.getConnection();

            stmt1 = con.prepareStatement(
            "DELETE FROM JobSkill WHERE job = ? and customer = ?");

            stmt1.setString(1, ref);
            stmt1.setString(2, customerObj.getLogin());

            stmt2 = con.prepareStatement(
            "DELETE FROM Job WHERE ref = ? and customer = ?");

            stmt2.setString(1, ref);
            stmt2.setString(2, customerObj.getLogin());

            stmt1.executeUpdate();
            stmt2.executeUpdate();
        }
        catch (SQLException e) {
            error("Error removing job "+key,e);
        }
        finally {
            closeConnection(con, stmt1, stmt2, null);
        }
        ref = null;
        customer = null;
        customerObj = null;
        description = null;
        location = null;
    }

    private EntityContext ctx;
    
    public void setEntityContext(EntityContext ctx) {
        this.ctx = ctx;
        InitialContext ic = null;
        try {
            ic = new InitialContext();
            dataSource = (DataSource)ic.lookup("java:comp/env/jdbc/Agency");
            skillHome = (SkillLocalHome)ic.lookup("java:comp/env/ejb/SkillLocal");
            locationHome = (LocationLocalHome)ic.lookup("java:comp/env/ejb/LocationLocal");
            customerHome = (CustomerLocalHome)ic.lookup("java:comp/env/ejb/CustomerLocal");
        }
        catch (NamingException ex) {
            error("Error looking up depended EJB or resource",ex);
            return;
        }
    }

    public void unsetEntityContext() {
        this.ctx = null;
        dataSource = null;
        skillHome = null;
        locationHome = null;
        customerHome = null;
    }

    private void closeConnection (Connection con, PreparedStatement stmt1, PreparedStatement stmt2, ResultSet rslt) {
        if (rslt != null) {
            try {
                rslt.close();
            }
            catch (SQLException e) {}
        }
        if (stmt1 != null) {
            try {
                stmt1.close();
            }
            catch (SQLException e) {}
        }
        if (stmt2 != null) {
            try {
                stmt2.close();
            }
            catch (SQLException e) {}
        }
        if (con != null) {
            try {
                con.close();
            }
            catch (SQLException e) {}
        }
    }

    private void error (String msg, Exception ex) {
        String s = "JobBean: "+msg + "\n" + ex;
        System.out.println(s);
        throw new EJBException(s,ex);
    }
}

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美va亚洲va香蕉在线| 成人免费高清在线| 91精品国产综合久久久蜜臀图片| 亚洲精品一二三区| 欧洲色大大久久| 午夜精品123| 日韩一级欧美一级| 国产传媒欧美日韩成人| 久久精品人人爽人人爽| 91视频国产资源| 亚洲综合一区二区| 日韩精品在线一区二区| 国产一区二区三区在线看麻豆| 久久精品男人天堂av| 99在线视频精品| 全国精品久久少妇| 国产亚洲精品aa| 欧美亚洲愉拍一区二区| 美女脱光内衣内裤视频久久影院| 久久精品亚洲国产奇米99| 色综合欧美在线| 蜜桃视频一区二区三区在线观看| 久久久久久一级片| 91传媒视频在线播放| 久久99精品国产.久久久久久| 国产女主播在线一区二区| 99re视频精品| 精品亚洲成a人在线观看| 欧美国产精品劲爆| 欧美高清你懂得| 高清在线不卡av| 日韩影院免费视频| 日本一区二区三区四区| 欧美日韩激情在线| 国产一区二区久久| 亚洲成av人影院| 日本一区二区免费在线观看视频| 欧美日韩久久一区| 床上的激情91.| 日本美女一区二区三区| 亚洲欧洲美洲综合色网| 日韩一区二区三区免费观看| 99久久精品免费看国产免费软件| 奇米亚洲午夜久久精品| 一区二区三区精品在线观看| 久久品道一品道久久精品| 91久久线看在观草草青青| 精品亚洲免费视频| 日韩av电影免费观看高清完整版 | 蜜桃av一区二区三区| 亚洲欧美影音先锋| 久久免费电影网| 91精品国产综合久久蜜臀| 91久久香蕉国产日韩欧美9色| 国产一区999| 日本免费在线视频不卡一不卡二| 亚洲视频一区在线| 国产婷婷一区二区| 日韩精品一区二区三区swag| 欧美视频在线观看一区| 91香蕉视频污| 成人a级免费电影| 国产一区二区在线电影| 久久国产精品一区二区| 日韩中文字幕亚洲一区二区va在线| 亚洲人成精品久久久久| 国产精品剧情在线亚洲| 日本一区二区成人| 国产欧美精品一区| 亚洲国产精品传媒在线观看| 久久精品一区二区三区不卡| 欧美va亚洲va国产综合| 精品日韩一区二区三区免费视频| 6080yy午夜一二三区久久| 欧美日韩综合一区| 欧美亚洲愉拍一区二区| 欧美日韩亚州综合| 欧美肥妇毛茸茸| 777亚洲妇女| 日韩欧美久久久| 精品va天堂亚洲国产| 精品福利av导航| 国产亚洲综合色| 欧美国产欧美亚州国产日韩mv天天看完整| 久久久精品免费免费| 国产校园另类小说区| 国产精品欧美久久久久一区二区| 国产农村妇女精品| 中文字幕制服丝袜成人av| 亚洲视频综合在线| 亚洲成av人影院| 日本成人中文字幕| 国产成人aaa| 91美女片黄在线观看91美女| 色悠悠亚洲一区二区| 欧美视频精品在线观看| 91精品在线免费| 久久久久国产一区二区三区四区 | 欧美一区二区三区视频免费| 日韩一级在线观看| 中文字幕欧美国产| 亚洲影院免费观看| 久久99久久99精品免视看婷婷 | 性感美女久久精品| 亚洲欧美日韩国产手机在线 | 亚洲精品日韩一| 日本欧美在线看| 国产91丝袜在线18| 欧美视频在线一区二区三区| 日韩午夜av电影| 国产精品高清亚洲| 天天爽夜夜爽夜夜爽精品视频| 久久精品国产999大香线蕉| 麻豆国产一区二区| 亚洲乱码日产精品bd| 日韩久久久久久| 中文字幕+乱码+中文字幕一区| 亚洲色大成网站www久久九九| 亚洲.国产.中文慕字在线| 韩国三级中文字幕hd久久精品| av电影一区二区| 日韩三级在线观看| ...av二区三区久久精品| 日韩av不卡在线观看| 99久久久久免费精品国产 | 欧美日韩mp4| 国产精品久久久久久久裸模 | 久久精品水蜜桃av综合天堂| 亚洲综合免费观看高清完整版在线| 久久精品国产99| 色婷婷久久一区二区三区麻豆| 精品久久久久一区| 亚洲一区二区在线观看视频| 国产精品亚洲一区二区三区妖精| 在线一区二区三区四区五区| 欧美精品一区二区三区蜜臀 | 精品国产乱码久久久久久久久 | 久久综合狠狠综合久久综合88| 国产精品另类一区| 极品尤物av久久免费看| 欧美在线制服丝袜| 国产精品沙发午睡系列990531| 免费成人美女在线观看.| 色av成人天堂桃色av| 国产欧美一区二区三区网站| 免费高清成人在线| 欧美视频中文字幕| 亚洲精品成人少妇| 成人国产精品视频| 国产日韩影视精品| 韩国精品在线观看| 欧美一区二区观看视频| 亚洲成人av电影| 色中色一区二区| 亚洲同性同志一二三专区| 成人一区二区视频| 日本一区二区三区久久久久久久久不| 久久国产综合精品| 欧美变态tickle挠乳网站| 亚洲一级在线观看| 色老汉av一区二区三区| 中文字幕一区二区日韩精品绯色| 国产福利电影一区二区三区| 久久久久久久电影| 国产精品亚洲视频| 久久久久9999亚洲精品| 国产精品一区二区久久不卡| 久久网站热最新地址| 国产另类ts人妖一区二区| 久久久欧美精品sm网站| 国产精品18久久久久久久久 | 国产尤物一区二区| 久久久久高清精品| 国产福利不卡视频| 国产精品不卡一区| 色婷婷av一区二区三区软件 | 国产精品无圣光一区二区| 国产不卡在线播放| 中文字幕一区二区在线播放| 99在线精品一区二区三区| 亚洲免费三区一区二区| 欧美少妇bbb| 免费在线观看视频一区| 久久亚洲精品国产精品紫薇| 岛国精品在线观看| 亚洲激情自拍视频| 正在播放亚洲一区| 国产精品一区在线| 亚洲视频一区二区在线| 欧美久久婷婷综合色| 精品午夜一区二区三区在线观看 | 在线欧美一区二区| 人人狠狠综合久久亚洲| 国产欧美日韩精品一区| 色噜噜夜夜夜综合网| 蜜桃一区二区三区在线观看| 国产欧美一区二区三区鸳鸯浴| 日本道色综合久久| 精品无码三级在线观看视频| 国产精品美女久久福利网站|