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

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

?? jobbean.java

?? 21天學通J2EE的例子4
?? 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一区二区在线观看| 亚洲成人一二三| 国产精品一二一区| 欧美影院午夜播放| 国产精品久久久久久久裸模| 日韩高清在线一区| 9色porny自拍视频一区二区| 日韩一区二区三区电影 | 日韩女优电影在线观看| 国产精品久久久久久久久久久免费看 | 亚洲精品高清在线观看| 国内精品视频666| 91精品国产综合久久久久| 亚洲第一福利视频在线| 91视频xxxx| 欧美国产一区二区| 国产精品一区二区三区乱码| 制服视频三区第一页精品| 一区二区三区免费在线观看| 不卡欧美aaaaa| 日韩一区中文字幕| 成人毛片在线观看| 中日韩免费视频中文字幕| 国产99久久久精品| 国产精品国产自产拍在线| 国产1区2区3区精品美女| 国产欧美一区二区精品久导航| 久久99精品视频| 欧美大片拔萝卜| 捆绑调教一区二区三区| 日韩亚洲欧美在线| 久久精品国产一区二区三| 日韩免费高清视频| 国产精品主播直播| 国产片一区二区| 成人精品免费看| 国产精品久久三| 91在线观看美女| 亚洲宅男天堂在线观看无病毒| 色噜噜狠狠成人中文综合 | 91免费视频网| 一片黄亚洲嫩模| 欧美三级电影在线看| 婷婷开心久久网| 精品国产一区二区精华| 国产精品99精品久久免费| 国产精品久久久久桃色tv| 91浏览器在线视频| 丝袜美腿亚洲色图| 久久视频一区二区| av爱爱亚洲一区| 日韩av中文在线观看| 久久精品视频网| 91性感美女视频| 美女网站色91| 国产精品剧情在线亚洲| 欧美日韩一区二区在线观看视频 | 欧美一区二区日韩| 国产一区不卡精品| 亚洲精品视频在线| 欧美一级淫片007| 国产69精品久久777的优势| 亚洲图片有声小说| 久久久久久久久久看片| 91福利在线观看| 国产在线精品一区二区不卡了| 自拍视频在线观看一区二区| 欧美日韩国产bt| 大陆成人av片| 日本伊人精品一区二区三区观看方式| 亚洲精品在线观| 欧美在线免费观看视频| 国产麻豆一精品一av一免费| 亚洲欧美福利一区二区| 欧美成人一区二区三区片免费 | 欧美日韩在线播放三区四区| 精品一区二区精品| 亚洲综合在线电影| 久久久久国产精品厨房| 在线成人av网站| 日韩欧美成人一区二区| 一本一本大道香蕉久在线精品 | 蜜臀久久久99精品久久久久久| 国产精品久久久久久久久图文区 | 日本高清无吗v一区| 久久国产精品露脸对白| 亚洲综合色视频| 国产精品视频一区二区三区不卡| 欧美日韩电影在线播放| 91在线观看高清| 懂色av中文一区二区三区| 蜜桃视频在线观看一区| 亚洲国产wwwccc36天堂| 欧美国产丝袜视频| 久久久国产午夜精品 | 国产日韩欧美精品电影三级在线 | 色拍拍在线精品视频8848| 国产精品一区二区果冻传媒| 日韩va亚洲va欧美va久久| 一区二区三区加勒比av| 日本一区二区三区高清不卡 | 精久久久久久久久久久| 国产一区二区电影| 日本美女一区二区三区| 婷婷综合久久一区二区三区| 亚洲精品成人少妇| 欧美高清在线一区| 欧美mv日韩mv国产网站app| 波多野结衣亚洲| 成人av在线资源| 国产mv日韩mv欧美| 高清beeg欧美| 丁香五精品蜜臀久久久久99网站 | 国产欧美一区在线| 久久久国产一区二区三区四区小说 | 亚洲国产精品久久艾草纯爱| 亚洲男人的天堂一区二区| 国产精品久久久99| 怡红院av一区二区三区| 亚洲免费伊人电影| 亚洲电影一区二区| 亚洲成人在线观看视频| 日韩av一区二区三区四区| 日韩高清一区在线| 国产精品综合网| 成人国产精品免费观看视频| 国产91精品露脸国语对白| 97久久精品人人做人人爽| 99久久久精品免费观看国产蜜| 一本到高清视频免费精品| 欧美中文字幕亚洲一区二区va在线| 欧美亚洲一区二区三区四区| 欧美麻豆精品久久久久久| 日韩午夜电影av| 久久亚洲精品小早川怜子| 一区二区中文字幕在线| 亚洲激情av在线| 丝袜美腿高跟呻吟高潮一区| 狠狠狠色丁香婷婷综合久久五月| 国产福利91精品| 色吊一区二区三区| 日韩视频免费观看高清完整版| 国产精品久久久久久户外露出| 国产精品乱码一区二三区小蝌蚪| 亚洲激情图片一区| 久久成人av少妇免费| 成人午夜电影网站| 欧美日韩久久久一区| 国产欧美一区二区精品婷婷| 一区二区三区日韩欧美精品| 日韩高清不卡一区二区三区| 国产成人高清视频| 欧亚洲嫩模精品一区三区| 欧美成人女星排名| 中文字幕一区二区三区av| 日韩精品午夜视频| 白白色亚洲国产精品| 91精品国产色综合久久不卡电影| 国产午夜精品福利| 丝袜亚洲另类欧美综合| 99r国产精品| 精品美女在线播放| 亚洲成人动漫精品| jvid福利写真一区二区三区| 欧美一级二级三级蜜桃| 亚洲欧美日韩国产另类专区| 国产一级精品在线| 日韩一级片在线播放| 亚洲综合色区另类av| 国产91高潮流白浆在线麻豆 | 久久不见久久见免费视频7| 在线一区二区三区做爰视频网站| 久久蜜桃香蕉精品一区二区三区| 亚洲一区二区av电影| 成人av免费在线| 久久综合九色综合97_久久久| 亚洲成人综合视频| 99精品国产99久久久久久白柏| 亚洲精品一区二区三区影院| 婷婷国产v国产偷v亚洲高清| 色妞www精品视频| 国产精品美女久久久久av爽李琼 | 蜜桃视频一区二区三区在线观看| 日本精品免费观看高清观看| 欧美激情在线看| 粉嫩嫩av羞羞动漫久久久| 精品福利一二区| 蜜桃久久久久久| 欧美一区日韩一区| 亚洲v中文字幕| 色婷婷激情综合| 亚洲精品福利视频网站| jvid福利写真一区二区三区| 国产精品国产三级国产aⅴ入口| 国内久久精品视频| 久久综合国产精品| 国产一区二区精品久久99| 久久久99免费| 国产成人综合在线|