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

📄 productbean.java

📁 EJB_原代码多例-好好东西啊
💻 JAVA
字号:
package com.wiley.compBooks.roman.entity.product;

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

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

	protected EntityContext ctx;

	// Container-managed state fields.  Note that they must
	// be public.
	public String productID;	// PK
	public String name;
	public String description;
	public double basePrice;

	public ProductBean() {
		System.out.println("New Product Entity Bean Java Object created by EJB Container.");
	}

	//
	// Business Logic Methods
	//

	// Simple getter/setter methods of Entity Bean fields.

        public String getName() throws RemoteException {
		System.out.println("getName() called.");
		return name;
	}
	
        public void setName(String name) throws RemoteException {
		System.out.println("getName() called.");
		this.name = name;
	}
	
        public String getDescription() throws RemoteException {
		System.out.println("getDescription() called.");
		return description;
	}
	
        public void setDescription(String description) throws RemoteException {
		System.out.println("setDescription() called.");
		this.description = description;
	}
	
        public double getBasePrice() throws RemoteException {
		System.out.println("getBasePrice() called.");
		return basePrice;
	}
	
        public void setBasePrice(double price) throws RemoteException {
		System.out.println("setBasePrice() called.");
		this.basePrice = price;
	}
	
	public String getProductID() {
		System.out.println("getProductID() called.");
		return productID;
	}

	//
	// EJB-required methods
	//

	/**
	 * Called by Container.
	 * Implementation can acquire needed resources.
	 */
	public void ejbActivate() throws RemoteException {
		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() throws RemoteException {
		System.out.println("ejbRemove() called.");
	}

	/**
	 * Called by Container.
	 * Releases held resources for passivation.
	 */
	public void ejbPassivate() throws RemoteException {
		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 set our public fields to the correct values.
	 */
	public void ejbLoad() throws RemoteException {
		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 our public fields into the database.
	 */
	public void ejbStore() throws RemoteException {
		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, such as Bean customizations
	 * via properties.
	 */
	public void setEntityContext(EntityContext ctx) throws RemoteException {
		System.out.println("setEntityContext called");
		this.ctx = ctx;
	}

	/**
	 * Called by Container.  Disassociates this Bean instance
	 * with a particular context environment.
	 */
	public void unsetEntityContext() throws RemoteException {
		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 productID, String name, String description, double basePrice) throws RemoteException {
		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.
	 *
	 * NOTE: Since we're using Container-Managed persistence,
	 * this method returns void.  With Bean-Managed Persistence,
	 * we returned the PK.  This is because our Bean was
	 * responsible for dealing with PKs and accessing
	 * the database.  Now that we let the Container handle
	 * persistence, the Container makes the Primary Key.
	 *
	 * We still need to initialize our Bean's fields with the
	 * parameters passed from the client, so that the Container
	 * can inspect our Bean and create the corresponding database
	 * entries.
	 */
	public void ejbCreate(String productID, String name, String description, double basePrice) throws CreateException, RemoteException {
		System.out.println("ejbCreate(" + productID + ", " + name + ", " + description + ", " + basePrice + ") called");

		this.productID = productID;
		this.name = name;
		this.description = description;
		this.basePrice = basePrice;
	}

	// No finder methods - they are implemented by Container
}

⌨️ 快捷键说明

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