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

📄 jresult.java

📁 this is example use EJB with jboss.
💻 JAVA
字号:
/*
 * Copyright(C) 2008, NTT AT Co., Ltd.
 * Project: AWGStar
 *
 * Notes:
 *  N/A
 *
 * Record of change:
 * Date         Version      Name       Content
 * 2008/12/15   1.0          TuanNA      First create       
 */

package jp.co.ntt.awgview.server.dao;

import java.io.Serializable;
import java.util.Hashtable;

/**
 * Class name : JResult <BR>
 * 
 * Package : jp.co.nttat.awgstar.server.dao <BR>
 * 
 * Description: This object created in order to contains result of operation
 * calling method. It consists of code of error and message appropriate.<BR>
 * 
 * @author : AI&T
 * @version : 1.0
 */
public class JResult implements Serializable {

	private static final long serialVersionUID = 5245639764350429433L;

	/*Error code and message definitions for the Database operation functions*/
	public static final long DBOPR_SUCCESS =  0x0L;
	public static final long DBOPR_FAILED  =   0x01L;

	//Error code for common operations
	public static final long DBOPR_ERROR_INSERT_FAILED		      = 0x04L;
	public static final long DBOPR_ERROR_UPDATE_FAILED 		      = 0x05L;
	public static final long DBOPR_ERROR_OBJECT_NOT_SUPPORTED     = 0x06L;
	public static final long DBOPR_ERROR_OBJECT_NO_SET_PARENT 	  = 0x07L;
	public static final long DBOPR_ERROR_PARENT_OBJECT_NOT_FOUND  = 0x08;
	public static final long DBOPR_ERROR_OBJECT_NOT_FOUND 		  = 0x09L;
	public static final long ERROR_PARAM_NOT_FOUND 				  = 0x011L;
	public static final long ERROR_FILE_CONFIG_NOT_FOUND  		  = 0x012L;
	public static final long DBOPR_ERROR_GET_CONNECTION_POOL  	  = 0x013L;
	public static final long DBOPR_ERROR_RECV_CONN_POOL  		  = 0x014L;
	public static final long DBOPR_ERROR_CONNECT_DB_FAILED  	  = 0x015L;
	public static final long DBOPR_ERROR_LOAD_DATA_FAILED  		  = 0x016L;
	public static final long DBOPR_DELETE_COMPLETE_WITH_ERROR 	  = 0x017;
	
	/** Message for function specified */
	private static Hashtable<Long, String> hastError = new Hashtable<Long, String>();
	/* Code of error */
	private long errorCode = -1;
	/* Message of error */
	private String errorMessage = null;

	/*
	 * Used when we want to method returning some value apart error code and
	 * message
	 */

	//Login-logout system
	public static final long DBFUNC_ERROR_LOGIN_USERNAME  		  = 0x018L;
	public static final long DBFUNC_ERROR_LOGIN_PASSWORD          = 0x019L;
	public static final long DBFUNC_ERROR_LOGIN_ADMIN             = 0x020L;
	public static final long DBFUNC_ERROR_LOGIN_LIMIT_EXCEEDED    = 0x022L;

	private long lValue = -1;
	/* Object attached result returned */
	private Object objectData;
	private static boolean initialized = false;

	/**
	 * Constructor default
	 */
	public JResult() {
		if (!initialized) {
			initialize();
			initialized = true;
		}
	}

	/**
	 * Constructor with error code and message
	 * 
	 * @param errorCode
	 * @param msg
	 */
	public JResult(long errorCode, String msg) {
		if (!initialized) {
			initialize();
			initialized = true;
		}
		this.errorMessage = msg;
		this.errorCode = errorCode;
	}

	/**
	 * Initialize message default for error code. This used in the case if
	 * method setMessage is not called.
	 */
	public void initialize() {
		hastError.put(DBOPR_ERROR_INSERT_FAILED,
				"The insert operation object into the database has been failed.");
		hastError.put(DBOPR_ERROR_OBJECT_NOT_SUPPORTED,
				"The type of object specified is not supported.");
		hastError.put(DBOPR_ERROR_OBJECT_NOT_FOUND,
				"The object specified was not found on the database.");
		hastError.put(DBFUNC_ERROR_LOGIN_ADMIN,
				"This admin (or another admin) is logged in.");
		hastError.put(DBOPR_ERROR_PARENT_OBJECT_NOT_FOUND,
				"The object's parent was not found");
	}

	/**
	 * Return error code
	 * 
	 * @param errorCode
	 */
	public void returnCode(long errorCode) {
		this.errorCode = errorCode;
	}

	/**
	 * Return Result code that error code of system
	 * 
	 * @return errorCode
	 */
	public long getResultCode() {
		return this.errorCode;
	}

	/**
	 * Returns the Message
	 * 
	 * @return String
	 */
	private String getMessageDefault() {
		String msg = "";
		try {
			initialize();
			msg = hastError.get(errorCode);
			if (msg == null) {
				msg = "No info available for this CODE_RETURNED " + "<0x"
						+ Long.toHexString(errorCode) + ">";
			}
		} catch (Exception e) {
			msg = e.toString();
		}
		return msg;
	}

	/**
	 * Set result message
	 * 
	 * @param message
	 *            Message
	 */
	public void setMessage(String message) {
		this.errorMessage = message;
	}

	/**
	 * Get message contained in JResult
	 * 
	 * @return String
	 */
	public String getMessage() {
		if (this.errorMessage != null) {
			return this.errorMessage;
		} else {
			return getMessageDefault();
		}

	}

	/**
	 * Set value attach result returned
	 * 
	 * @param val
	 */
	public void setValue(long val) {
		this.lValue = val;
	}

	/**
	 * Return the value of apart error code and message
	 * 
	 * @return long
	 */
	public long getValue() {
		return (this.lValue);
	}

	/**
	 * Set object attach JResult
	 * 
	 * @param object
	 *            Any object
	 */
	public void setObjectData(Object object) {
		this.objectData = object;
	}

	/**
	 * Get object attached JResult object
	 */
	public Object getObjectData() {
		return (this.objectData);
	}

	/**
	 * Check result of operation
	 * 
	 * @return true if operation success, otherwise false
	 */
	public boolean isSucceeded() {
		if (errorCode == DBOPR_SUCCESS) {
			return true;
		} else {
			return false;
		}
	}

	/**
	 * Return the value of connection flag
	 * 
	 * @return boolean
	 */
	public boolean isFailed() {
		return (!isSucceeded());
	}
}

⌨️ 快捷键说明

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