📄 productsectestclient1.java~1~
字号:
package product;import javax.naming.*;import java.util.Properties;import javax.rmi.PortableRemoteObject;import java.util.Collection;import java.awt.Image;public class productSecTestClient1 extends Object { private static final String ERROR_NULL_REMOTE = "Remote interface reference is null. It must be created by calling one of the Home interface methods first."; private static final int MAX_OUTPUT_LINE_LENGTH = 100; private boolean logging = true; private productSecHome productSecHomeObject = null; private productSec productSecObject = null; //Construct the EJB test client public productSecTestClient1() { initialize(); } public void initialize() { long startTime = 0; if (logging) { log("Initializing bean access."); startTime = System.currentTimeMillis(); } try { //get naming context Context context = getInitialContext(); //look up jndi name Object ref = context.lookup("productSec"); //look up jndi name and cast to Home interface productSecHomeObject = (productSecHome) PortableRemoteObject.narrow(ref, productSecHome.class); if (logging) { long endTime = System.currentTimeMillis(); log("Succeeded initializing bean access through Home interface."); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed initializing bean access."); } e.printStackTrace(); } } private Context getInitialContext() throws Exception { String url = "t3://j-af3d73a001034:7001"; String user = null; String password = null; Properties properties = null; try { properties = new Properties(); properties.put(Context.INITIAL_CONTEXT_FACTORY, "weblogic.jndi.WLInitialContextFactory"); properties.put(Context.PROVIDER_URL, url); if (user != null) { properties.put(Context.SECURITY_PRINCIPAL, user); properties.put(Context.SECURITY_CREDENTIALS, password == null ? "" : password); } return new InitialContext(properties); } catch(Exception e) { log("Unable to connect to WebLogic server at " + url); log("Please make sure that the server is running."); throw e; } } //---------------------------------------------------------------------------- // Methods that use Home interface methods to generate a Remote interface reference //---------------------------------------------------------------------------- public productSec create() { long startTime = 0; if (logging) { log("Calling create()"); startTime = System.currentTimeMillis(); } try { productSecObject = productSecHomeObject.create(); if (logging) { long endTime = System.currentTimeMillis(); log("Succeeded: create()"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: create()"); } e.printStackTrace(); } if (logging) { log("Return value from create(): " + productSecObject + "."); } return productSecObject; } //---------------------------------------------------------------------------- // Methods that use Remote interface methods to access data through the bean //---------------------------------------------------------------------------- public Collection findbyprimarykey(String p_id) { Collection returnValue = null; if (productSecObject == null) { System.out.println("Error in findbyprimarykey(): " + ERROR_NULL_REMOTE); return returnValue; } long startTime = 0; if (logging) { log("Calling findbyprimarykey(" + p_id + ")"); startTime = System.currentTimeMillis(); } try { returnValue = productSecObject.findbyprimarykey(p_id); if (logging) { long endTime = System.currentTimeMillis(); log("Succeeded: findbyprimarykey(" + p_id + ")"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: findbyprimarykey(" + p_id + ")"); } e.printStackTrace(); } if (logging) { log("Return value from findbyprimarykey(" + p_id + "): " + returnValue + "."); } return returnValue; } public void insertNewProduct(String p_id, String p_type_id, String p_name, String p_spec, String p_model, String p_unit, Image p_image, String p_remark) { if (productSecObject == null) { System.out.println("Error in insertNewProduct(): " + ERROR_NULL_REMOTE); return ; } long startTime = 0; if (logging) { log("Calling insertNewProduct(" + p_id + ", " + p_type_id + ", " + p_name + ", " + p_spec + ", " + p_model + ", " + p_unit + ", " + p_image + ", " + p_remark + ")"); startTime = System.currentTimeMillis(); } try { productSecObject.insertNewProduct(p_id, p_type_id, p_name, p_spec, p_model, p_unit, p_image, p_remark); if (logging) { long endTime = System.currentTimeMillis(); log("Succeeded: insertNewProduct(" + p_id + ", " + p_type_id + ", " + p_name + ", " + p_spec + ", " + p_model + ", " + p_unit + ", " + p_image + ", " + p_remark + ")"); log("Execution time: " + (endTime - startTime) + " ms."); } } catch(Exception e) { if (logging) { log("Failed: insertNewProduct(" + p_id + ", " + p_type_id + ", " + p_name + ", " + p_spec + ", " + p_model + ", " + p_unit + ", " + p_image + ", " + p_remark + ")"); } e.printStackTrace(); } } //---------------------------------------------------------------------------- // Utility Methods //---------------------------------------------------------------------------- private void log(String message) { if (message == null) { System.out.println("-- null"); return ; } if (message.length() > MAX_OUTPUT_LINE_LENGTH) { System.out.println("-- " + message.substring(0, MAX_OUTPUT_LINE_LENGTH) + " ..."); } else { System.out.println("-- " + message); } }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -