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

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

?? jobbean.java

?? 21天學通J2EE的例子3
?? 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 {
            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一区二区三区免费野_久草精品视频
欧美欧美欧美欧美首页| 亚洲成av人片在www色猫咪| 成人午夜看片网址| 亚洲丶国产丶欧美一区二区三区| 欧美成人a∨高清免费观看| 盗摄精品av一区二区三区| 国产精品成人免费| 欧美电影一区二区三区| 成+人+亚洲+综合天堂| 日本不卡一二三| 亚洲在线一区二区三区| 国产亚洲综合色| 日韩欧美国产高清| 色欧美88888久久久久久影院| 国产一区二区精品在线观看| 亚洲国产成人av| 精品理论电影在线观看| 欧美日韩在线直播| 91色在线porny| 国产91精品在线观看| 精品在线播放免费| 午夜久久久影院| 一区二区成人在线观看| 中文字幕亚洲一区二区va在线| 26uuu欧美| 在线亚洲高清视频| 91蝌蚪porny成人天涯| 成人激情动漫在线观看| 国产乱码字幕精品高清av| 精品在线播放免费| 麻豆国产欧美一区二区三区| 水野朝阳av一区二区三区| 亚洲精品亚洲人成人网在线播放| 欧美激情中文字幕| 中文子幕无线码一区tr| 国产日韩高清在线| 日本一区二区三区视频视频| 国产精品网站导航| 亚洲天堂成人网| 综合在线观看色| 亚洲一区成人在线| 一级精品视频在线观看宜春院 | 久久久精品综合| 久久青草国产手机看片福利盒子 | 成人免费毛片app| 国产精选一区二区三区| 国产福利精品导航| 国产福利一区二区三区视频在线 | av在线一区二区| 色综合久久88色综合天天免费| 日本精品视频一区二区| 91久久奴性调教| 97精品视频在线观看自产线路二| 色呦呦日韩精品| 欧美一区二区三区视频| 久久欧美中文字幕| 亚洲视频一区二区在线观看| 亚洲国产精品久久久男人的天堂| 亚洲欧美韩国综合色| 亚洲成a人v欧美综合天堂下载 | 久久久久9999亚洲精品| 日韩理论在线观看| 天天操天天干天天综合网| 日韩成人免费电影| 高清av一区二区| 欧美色视频一区| 精品理论电影在线观看 | 在线观看网站黄不卡| 欧美一区二区在线免费观看| 久久亚洲精精品中文字幕早川悠里 | 亚洲欧美一区二区在线观看| 天堂精品中文字幕在线| 国产成人无遮挡在线视频| 成人av网站在线观看免费| 欧美日韩精品是欧美日韩精品| 精品黑人一区二区三区久久| 亚洲人亚洲人成电影网站色| 日韩国产欧美三级| 97精品国产露脸对白| 欧美精品国产精品| 亚洲欧洲色图综合| 狂野欧美性猛交blacked| 色综合视频在线观看| 日韩欧美成人激情| 一区二区不卡在线视频 午夜欧美不卡在| 五月天久久比比资源色| 国产成人av影院| 欧美一区二区三区精品| 亚洲色欲色欲www| 国产尤物一区二区| 91精品国产一区二区三区香蕉 | 国产在线不卡视频| 色婷婷久久久久swag精品| 日韩你懂的在线播放| 亚洲影视在线播放| 国产91富婆露脸刺激对白| 精品少妇一区二区三区日产乱码 | 日韩av电影一区| 在线看日韩精品电影| 国产欧美日韩三区| 激情文学综合网| 日韩欧美高清在线| 免费在线视频一区| 欧美日韩国产中文| 一区二区三区四区激情 | 亚洲欧美日韩小说| www.在线成人| 国产精品福利一区| 成人av电影在线观看| 精品三级在线看| 久久er99热精品一区二区| 欧美浪妇xxxx高跟鞋交| 亚洲午夜三级在线| 91国产丝袜在线播放| 日本一二三四高清不卡| 国产福利一区在线| 久久精品一二三| 国产乱码一区二区三区| 久久久青草青青国产亚洲免观| 亚洲小说春色综合另类电影| 欧美视频一区二区三区在线观看| 亚洲毛片av在线| 欧美午夜精品久久久久久超碰 | 国内精品伊人久久久久av一坑| 日韩三级伦理片妻子的秘密按摩| 奇米色一区二区| 欧美日韩一区高清| 亚洲v精品v日韩v欧美v专区 | 久久久久久电影| 国产成人在线观看免费网站| 国产精品污www在线观看| 99久久久免费精品国产一区二区| 亚洲色图欧洲色图| 欧美老肥妇做.爰bbww| 免费成人在线影院| 91麻豆精品国产91久久久更新时间| 蜜臀av性久久久久蜜臀aⅴ流畅| 日韩精品影音先锋| 高清在线观看日韩| 欧美国产一区二区在线观看| 色综合久久久久综合体| 亚洲r级在线视频| 欧美精品一区男女天堂| av高清不卡在线| 视频一区在线视频| 久久久久久久久久久黄色| 色婷婷激情久久| 麻豆精品视频在线观看免费| 欧美精品一区视频| 色综合天天在线| 日本不卡123| 国产精品丝袜久久久久久app| 成人天堂资源www在线| 尤物视频一区二区| 精品国产91亚洲一区二区三区婷婷| 国产福利视频一区二区三区| 一区二区三区在线免费播放| 久久综合精品国产一区二区三区| 色婷婷精品大在线视频| 亚洲国产欧美在线| 国产精品少妇自拍| 91精品国产91久久久久久一区二区| 国产传媒欧美日韩成人| 亚洲欧美视频在线观看视频| 国产在线国偷精品产拍免费yy | 日韩免费观看高清完整版| 91亚洲精品一区二区乱码| 国产精品一线二线三线精华| 青青草97国产精品免费观看无弹窗版| 一区二区三区日韩欧美精品| 一区精品在线播放| 国产精品污网站| 国产精品网站在线播放| 久久久久国产精品麻豆ai换脸 | 欧美男同性恋视频网站| 在线观看91视频| 91国产免费观看| 91成人免费网站| 欧美性猛片xxxx免费看久爱| 91麻豆蜜桃一区二区三区| 91在线免费视频观看| 91麻豆免费观看| 欧美三级在线视频| 欧美在线|欧美| 538在线一区二区精品国产| 欧美美女一区二区| 欧美成va人片在线观看| 久久嫩草精品久久久久| 亚洲国产精品黑人久久久| 国产精品成人免费| 亚洲精品一卡二卡| 亚洲成人动漫精品| 久草热8精品视频在线观看| 国产做a爰片久久毛片| 成人亚洲精品久久久久软件| 日本乱码高清不卡字幕| 91精品一区二区三区在线观看| 欧美一区二区精美| 国产午夜亚洲精品羞羞网站| 中文字幕不卡在线播放|