簡単なコンテナ管理の永続性Entity Bean

コンテナ管理の永続性Entity Beanの簡単なアプリケーションです。

このサンプルは、クライアントからcreateメソッドを呼び出す コンテナ管理の永続性Entity Beanです。

ソースコードはsamples/j2ee/ejb/SimpleCMP/srcに、 ビルド済みアプリケーションはsamples/j2ee/ejb/SimpleCMP/jarsにあります。

 
ホーム・インタフェース

SimpleCMPHome.java


/*
  Copyright (C) NEC Corporation 2004
  NEC CONFIDENTIAL AND PROPRIETARY
  All rights reserved by NEC Corporation.
  This program must be used solely for the purpose for which
  it was furnished by NEC Corporation. No part of this
  program may be reproduced or disclosed to others, in any
  form, without the prior written permission of NEC
  Corporation. Use of copyright notice does not evidence
  publication of the program. 
 */
package sample;

import javax.ejb.*;
import java.rmi.*;

public interface SimpleCMPHome extends EJBHome {

    public SimpleCMP findByPrimaryKey(java.lang.String pk)
        throws FinderException, java.rmi.RemoteException;
    public SimpleCMP create(String name,Integer zaiko)
        throws RemoteException, CreateException; 
}

 
リモート・インタフェース

SimpleCMP.java


/*
  Copyright (C) NEC Corporation 2004
  NEC CONFIDENTIAL AND PROPRIETARY
  All rights reserved by NEC Corporation.
  This program must be used solely for the purpose for which
  it was furnished by NEC Corporation. No part of this
  program may be reproduced or disclosed to others, in any
  form, without the prior written permission of NEC
  Corporation. Use of copyright notice does not evidence
  publication of the program. 
 */
package sample;

import javax.ejb.*;

public interface SimpleCMP extends EJBObject {

    public java.lang.Integer getZaiko() throws java.rmi.RemoteException;
    public void setZaiko(java.lang.Integer zaiko)
        throws java.rmi.RemoteException;
    public java.lang.String getName() throws java.rmi.RemoteException;
}

 
Enterprise Beanクラス

SimpleCMPBean.java


/*
  Copyright (C) NEC Corporation 2004
  NEC CONFIDENTIAL AND PROPRIETARY
  All rights reserved by NEC Corporation.
  This program must be used solely for the purpose for which
  it was furnished by NEC Corporation. No part of this
  program may be reproduced or disclosed to others, in any
  form, without the prior written permission of NEC
  Corporation. Use of copyright notice does not evidence
  publication of the program. 
 */
package sample;

import javax.ejb.*;

public abstract class SimpleCMPBean implements EntityBean {

    private EntityContext entityContext;

    public SimpleCMPBean() {
    }

    public void setEntityContext(EntityContext arg0) {
        this.entityContext = arg0;
    }

    public void unsetEntityContext() {
        // TODO 自動生成されたメソッド・スタブ
    }

    public void ejbRemove() {
        // TODO 自動生成されたメソッド・スタブ
    }

    public void ejbActivate() {
        // TODO 自動生成されたメソッド・スタブ
    }

    public void ejbPassivate() {
        // TODO 自動生成されたメソッド・スタブ
    }

    public void ejbLoad() {
        // TODO 自動生成されたメソッド・スタブ
    }

    public void ejbStore() {
        // TODO 自動生成されたメソッド・スタブ
    }

    public abstract java.lang.Integer getZaiko();
    public abstract void setZaiko(java.lang.Integer zaiko);
    public abstract java.lang.String getName();
    public abstract void setName(java.lang.String name);

    public String ejbCreate(String name, Integer zaiko) throws CreateException {
        setName(name);
        setZaiko(zaiko);
        return null;
    }

    public void ejbPostCreate(String name, Integer zaiko) {}
}

 
クライアントクラス

Client.java


/*
  Copyright (C) NEC Corporation 2004
  NEC CONFIDENTIAL AND PROPRIETARY
  All rights reserved by NEC Corporation.
  This program must be used solely for the purpose for which
  it was furnished by NEC Corporation. No part of this
  program may be reproduced or disclosed to others, in any
  form, without the prior written permission of NEC
  Corporation. Use of copyright notice does not evidence
  publication of the program. 

*/
import javax.naming.InitialContext;
import javax.rmi.PortableRemoteObject;
import java.rmi.RemoteException;
import javax.ejb.*;
import sample.*;

public class Client {
    public static void main(String args[]) {
        new Client();
    }
    public Client() {
        try {
            InitialContext initial = new InitialContext();
            Object obj = initial.lookup("SimpleCMP");
            SimpleCMPHome home = (SimpleCMPHome)PortableRemoteObject.narrow(obj, SimpleCMPHome.class);
            SimpleCMP remote = home.create("webotx", new Integer(10));
//          SimpleCMP remote = home.findByPrimaryKey("webotx");
            Integer work = remote.getZaiko();
            System.out.println("zaiko : " + work);
        } catch (Exception ex) {
            ex.printStackTrace();
        }
    }
}


 

Copyright (C) 1998 - 2004 NEC Corporation.All rights reserved.