⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 bookbean.java

📁 Java项目案例导航源代码
💻 JAVA
字号:
package examples;

import javax.ejb.*;

/**
 * Entity Bean which demonstrates Container-Managed persistence.
 *
 * This is a Book that's persistent.  It has an ID #, a name,
 * a description, and a base price.
 */
public abstract class BookBean implements EntityBean {

	protected EntityContext ctx;

	public BookBean() {
	}

	//-----------------------------------------------
	// Begin abstract get/set methods
	//-----------------------------------------------

   
     /**
     * Returns the name of the Book
     */
	public abstract String getName();
    
    /**
     * Sets the name of the Book
     */
	public abstract void setName(String name);
    
    /**
     * Returns the description of the Book
     */
	public abstract String getDescription();
    
    /**
     * Sets the description of the Book
     */
	public abstract void setDescription(String description);
    
    /**
     * Returns the base price of the Book
     */
	public abstract double getBasePrice();	
    
     /**
     * Sets the base price of the Book
     */
	public abstract void setBasePrice(double price);	
    
     /**
     * Returns the id of the Book.
     */
    public abstract String getBookID();
    
    /**
     * Sets the id of the Book.
     */
	public abstract void setBookID(String bookID);

	//-----------------------------------------------
	// End abstract get/set methods
	//-----------------------------------------------
	
	//-----------------------------------------------
	// Begin EJB-required methods.  The methods below
	// are called by the Container, and never called
	// by client code.
	//-----------------------------------------------

	/**
	 * Called by Container.
	 * Implementation can acquire needed resources.
	 */
	public void ejbActivate() {
		System.out.println("ejbActivate() called.");
	}

	/**
	 * EJB Container calls this method right before it
	 * removes the Entity Bean from the database.
	 * Corresponds to when client calls home.remove().
	 */
	public void ejbRemove() {
		System.out.println("ejbRemove() called.");
	}

	/**
	 * Called by Container.
	 * Releases held resources for passivation.
	 */
	public void ejbPassivate() {
		System.out.println("ejbPassivate () called.");
	}

	/**
	 * Called from the Container.  Updates the entity bean
	 * instance to reflect the current value stored in
	 * the database.
	 *
	 * Since we're using Container-Managed Persistence, we
	 * can leave this method blank.  The EJB Container will
	 * automatically load us in the subclass.
	 */
	public void ejbLoad() {
		System.out.println("ejbLoad() called.");
	}

	/**
	 * Called from the Container.  Updates the database to
	 * reflect the current values of this in-memory Entity Bean
	 * instance representation.
	 *
	 * Since we're using Container-Managed Persistence, we can
	 * leave this method blank.  The EJB Container will
	 * automatically save us in the subclass.
	 */
	public void ejbStore() {
		System.out.println("ejbStore() called.");
	}

	/**
	 * Called by Container.  Associates this Bean instance with
	 * a particular context.  Once done, we can query the
	 * Context for environment info
	 */
	public void setEntityContext(EntityContext ctx) {
		System.out.println("setEntityContext called");
		this.ctx = ctx;
	}

	/**
	 * Called by Container.  Disassociates this Bean instance
	 * with a particular context environment.
	 */
	public void unsetEntityContext() {
		System.out.println("unsetEntityContext called");
		this.ctx = null; 
	}

	/**
	 * Called after ejbCreate().  Now, the Bean can retrieve
	 * its EJBObject from its context, and pass it as a 'this'
	 * argument.
	 */
	public void ejbPostCreate(String bookID, String name, String description, double basePrice) {
		System.out.println("ejbPostCreate() called");
	}

	/**
	 * This is the initialization method that corresponds to the
	 * create() method in the Home Interface.
	 *
	 * When the client calls the Home Object's create() method,
	 * the Home Object then calls this ejbCreate() method.
	 *
	 * We need to initialize our Bean's fields with the
	 * parameters passed from the client, so that the Container
	 * can create the corresponding database entries in the
	 * subclass after this method completes.
	 */
	public String ejbCreate(String bookID, String name, String description, double basePrice) throws CreateException {
		System.out.println("ejbCreate() called");

		setBookID(bookID);
		setName(name);
		setDescription(description);
		setBasePrice(basePrice);

		/*
		 * CMP entity beans' ejbCreate() always return null.
		 * The ejbCreate() method has a non-void return signature so
		 * that the ejbCreate() signature matches that of a
		 * BMP entity bean, allowing you to create a BMP entity bean
		 * that subclasses a CMP entity bean.
		 */
		return null;
	}

	// No finder methods
	// (they are implemented by Container)

	//-----------------------------------------------
	// End EJB-required methods
	//-----------------------------------------------
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -