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

📄 client.java

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

import javax.ejb.*;
import javax.naming.*;
import java.rmi.*;
import java.util.Enumeration;

/**
 * Client test application on a Container-Managed Entity Bean, Product.
 */
public class Client {

	public static void main(String[] args) {

		ProductHome home = null;

		try {
			/*
			 * Get a reference to the Product Home Object - the
			 * factory for Product EJB Objects
			 */
			Context ctx = new InitialContext(System.getProperties());
			home = (ProductHome) ctx.lookup("ProductHome");

			/*
			 * Use the factory to create the Product EJB Object
			 */
			home.create("123-456-7890", "P5-350", "350 Mhz Pentium", 200);
			home.create("123-456-7891", "P5-400", "400 Mhz Pentium", 300);
			home.create("123-456-7892", "P5-450", "450 Mhz Pentium", 400);
			home.create("123-456-7893", "SD-64", "64 MB SDRAM", 50);
			home.create("123-456-7894", "SD-128", "128 MB SDRAM", 100);
			home.create("123-456-7895", "SD-256", "256 MB SDRAM", 200);

			/*
			 * Find a Product, and print out it's description
			 */
			Enumeration enum = home.findByName("SD-64");
			System.out.println("The following product descriptions match the product name SD-64:");
			while (enum.hasMoreElements()) {
				Product prod = (Product) enum.nextElement();
				System.out.println(prod.getDescription());
			}

			/*
			 * Find all products that cost $200
			 */
			System.out.println("Calling finder to find all products that cost $200");
			enum = home.findByBasePrice(200);

			while (enum.hasMoreElements()) {
				Product prod = (Product) enum.nextElement();
				System.out.println(prod.getDescription());
			}
		}
		catch (Exception e) {
			e.printStackTrace();
		}
		finally {
		    if (home != null) {
			try {
				System.out.println("Destroying products..");
				
				/*
				 * Find all the products
				 */
				Enumeration enum = home.findAllProducts();
				while (enum.hasMoreElements()) {
					try {
						Product prod = (Product) enum.nextElement();
						if (prod.getProductID().startsWith("123")) {
							prod.remove();
						}
					}
					catch (Exception e) {
						e.printStackTrace();
					}
				}
			}
			catch (Exception e) {
				e.printStackTrace();
			}
		    }
		}
	}
}

⌨️ 快捷键说明

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