📄 tempfile.tmp
字号:
/*
* 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.ejb;
import java.rmi.RemoteException;
import java.util.ArrayList;
import java.util.Vector;
import javax.ejb.CreateException;
import javax.ejb.EJBException;
import javax.ejb.SessionBean;
import javax.ejb.SessionContext;
import jp.co.ntt.awgview.server.common.AlarmType;
import jp.co.ntt.awgview.server.common.LogWriter;
import jp.co.ntt.awgview.server.dao.DBFunctionsManager;
import jp.co.ntt.awgview.server.dao.JResult;
import jp.co.ntt.awgview.server.vo.BlockVO;
import jp.co.ntt.awgview.server.vo.NodeHelper;
import jp.co.ntt.awgview.server.vo.NodeVO;
import jp.co.ntt.awgview.server.vo.OperationVO;
import jp.co.ntt.awgview.server.vo.PackageTypeVO;
import jp.co.ntt.awgview.server.vo.PackageVO;
import jp.co.ntt.awgview.server.vo.PortVO;
import jp.co.ntt.awgview.server.vo.TrapVO;
import jp.co.ntt.awgview.server.vo.UserVO;
import jp.co.ntt.awgview.server.vo.ConnectorVO.PPConnection;
import jp.co.ntt.awgview.server.vo.ConnectorVO.PackageConnection;
/**
* Class name : EJBBeanManager <BR>
*
* Package : jp.co.ntt.awgview.server.ejb <BR>
*
* Description: EJBBeanManager is the Enterprise Bean. It implements SessionBean,
* provides the business logic for the developer-defined methods,
* and implements SessionBean methods for creating the Bean and
* setting the session context.
*
* @author : AI&T
* @version : 1.0
*/
public class EJBBeanManager implements SessionBean{
private static final long serialVersionUID = 7095658285730522186L;
private DBFunctionsManager dbServerBean;
public SessionContext ctx;
/**
* EJBBeanManager constructor.
* Create new DBFunctionsManager
*/
public EJBBeanManager(){
// constructor
dbServerBean = new DBFunctionsManager();
}
/**
* Create instance of EJB. It implements the SessionBean interface.
*
* @throws CreateException
*/
public void ejbCreate() throws CreateException{
try {
Thread currThread = Thread.currentThread();
String currentThreadName = currThread.getName();
LogWriter.getDBLogger().info("Thread name: "+ currentThreadName);
int begin = currentThreadName.indexOf('[') +1;
int end = currentThreadName.indexOf(']');
String remoteClient = currentThreadName.substring(begin, end);
LogWriter.getDBLogger().info("Remote client: "+remoteClient );
dbServerBean.setUserIP(remoteClient);
} catch (Exception e){
LogWriter.getDBLogger().error("Create instance of EJB error: " + e.getMessage());
}
}
/**
* The activate method is called when the instance is activated from its "passive" state.
* It implements the SessionBean interface.
*/
public void ejbActivate(){
}
/**
* The passivate method is called before the instance enters the "passive" state.
*/
public void ejbPassivate(){
//Unjoined user from list of online manager
DBFunctionsManager.unjoin(dbServerBean.getUserIP());
//Release queue name resource for another user
DBFunctionsManager.releaseQueueRes(dbServerBean.getUserRequestQueueName()
, dbServerBean.getUserResponseQueueName());
//Delete virtual view table of trap and operation log if exists
DBFunctionsManager.deleteViewTbl(dbServerBean.getAlarmViewTbl());
DBFunctionsManager.deleteViewTbl(dbServerBean.getOperationViewTbl());
//Close connection to the database
dbServerBean.close();
LogWriter.getDBLogger().warn("Instance EJB of client: " +
dbServerBean.getUserIP() + " DEACTIVED!");
}
/**
* A container invokes this method before it ends the life of the session object.
* It implements the SessionBean interface.
*/
public void ejbRemove(){
// when bean is removed
LogWriter.getDBLogger().warn(
"Instance EJB of client: " + dbServerBean.getUserIP() + " REMOVED!");
}
/*
* The SessionContext that the container passes to a session bean is also an EJBContext,
* which is a general representation for runtime context information, regardless of
* whether the bean is an entity or session bean
*/
public void setSessionContext(SessionContext ctx){
this.ctx = ctx;
}
/*
* Unset the associated session context.
*/
public void unsetSessionContext(){
this.ctx = null;
}
/**
* Tests EJB connection is working
* @return String
* @throws EJBException
*/
public String ping() throws EJBException{
return ("Welcome to EJB manager from AWGView Team! It's OK... :)");
}
/**
* Receive a connection to the database
*
* @return JResult object. Check method isSucceeded() of this is true for
* success, otherwise false.
* @throws Exception
*/
public JResult open() throws EJBException, Exception{
sendLivingSign();
return (dbServerBean.open()) ;
}
/**
* Free the current connection
*
* @return true if success. Otherwise return false.
*/
public boolean close() throws EJBException , Exception{
return (dbServerBean.close());
}
/**
* Delete object (node, block ...) and all related data from the database
* @param objectType
* Specify a constant corresponding with object, such as:
* DBConstants.NODE_OBJECT for Node object ...
* @param objectID
* Object's ID
* @return JResult object. Check method isSucceeded() of this is true for success, otherwise false.
*/
public JResult deleteObject(int objectType, long objectID) throws EJBException, Exception{
JResult ret = open();
if(ret.isSucceeded()){
ret =dbServerBean.deleteObject(objectType, objectID);
close();
} else {
throw new Exception(ret.getMessage());
}
return ret;
}
/**
* add an object into database
*
* @param object
* Type of object is valid consists of NodeVO, BlockVO PortVO,
* UserVO, TrapVO, OperationVO, PackageConnection and
* PPConnection
* @return a JResult object. Check method isSucceeded() true if success.
* @throws Exception if error occurs
*/
public JResult addObject2DB(Object object) throws EJBException, Exception{
JResult ret = open();
try{
if(ret.isSucceeded()){
ret =dbServerBean.addObject2DB(object);
} else {
throw new Exception(ret.getMessage());
}
return ret;
} finally {
close();
}
}
/**
* add new one package into database
* @param object
* @return a JResult object contains a PackageVO (consists of list ports),
* use method getObjectData() of JResult to get this.
* @throws Exception
* throws a exception if one unknown error is occurred.
*/
public JResult addPackage2DB(PackageVO object) throws EJBException, Exception{
JResult ret = open();
try{
if(ret.isSucceeded()){
ret =dbServerBean.addPackage2DB(object);
} else {
throw new Exception(ret.getMessage());
}
return ret;
} finally {
close();
}
}
/**
* add a list of package-package connections into database
*
* @param lstLogicalConn
* list of package-package connections
* @return a JResult object. Check method isSucceeded() true if success.
* @throws Exception
* throws a exception if an error occurs.
*/
public JResult addLogicalConnection2DB(ArrayList<PackageConnection> lstLogicalConn)
throws EJBException, Exception{
JResult ret = open();
try {
if(ret.isSucceeded()){
ret =dbServerBean.addLogicalConnection2DB(lstLogicalConn);
} else {
throw new Exception(ret.getMessage());
}
return ret;
} finally {
close();
}
}
/**
* Update object data in database
*
* @param object
* Type of object is valid consists of NodeVO, BlockVO PortVO,
* UserVO, PackageConnection and PPConnection (not for Trap and
* Operation)
* @return a JResult object. Check method isSucceeded() true if success.
* @throws Exception
* throws a exception if an error occurs.
*/
public JResult updateObjectSeparator2DB(Object object) throws EJBException, Exception{
JResult ret = open();
try {
if(ret.isSucceeded()){
ret =dbServerBean.updateObjectSeparator2DB(object);
} else {
throw new Exception(ret.getMessage());
}
return ret;
} finally {
close();
}
}
/**
* Update the position and dimension of node, block and package
*
* @param nodeHelper
* NodeHelper object contains new position of node, block and
* package
* @return a JResult object. Check method isSucceeded() true if success.
* @throws Exception
* throws a exception if an error occurs.
*/
public JResult updateObjectPosition2DB(NodeHelper nodeHelper) throws EJBException, Exception{
try {
JResult ret = open();
if(ret.isSucceeded()){
ret =dbServerBean.updateObjectPosition2DB(nodeHelper);
} else {
throw new Exception(ret.getMessage());
}
return ret;
} catch (Exception e){
throw e;
} finally {
close();
}
}
/**
* Update for only alarm field of function block object
*
* @param id
* Block ID
* @param value
* Value of alarm
* @return JResult
*/
public JResult updateBlockAlarm(long id, int value) throws EJBException, Exception{
JResult ret = open();
if(ret.isSucceeded()){
ret =dbServerBean.updateBlockAlarm(id, value);
close();
}else{
throw new Exception(ret.getMessage());
}
return ret;
}
/**
* Update alarm corresponding with each window view
* @param id
* Package's ID
* @param wview
* Specify value Constants.DIAGRAM_VIEW if want to update
* for window diagram or Constants.PACKAGE_IMPL_VIEW for
* Package implement window
*
* @param value
* Value of alarm level, this will be added immediately into database
* @return JResult object. Check method isSucceeded() true if success, otherwise false
*/
public JResult updatePackageAlarm(long id, int wview, int value) throws EJBException, Exception{
JResult ret = open();
if(ret.isSucceeded()){
ret =dbServerBean.updatePackageAlarm(id, wview, value);
close();
}else{
throw new Exception(ret.getMessage());
}
return ret;
}
/**
* Find one object with it's ID. This method only detects that one object is existed or not
* @param objectType
* Specify a constant corresponding with object, such as:
* DBConstants.NODE_OBJECT for Node object ...
* @param objectID
* Specify a number >0 is object's ID
*
* @return JResult object. Check JResult.getValue()>0 if object is found,
* -1 if an error occurred, and equal 0 if object not found
*/
public JResult findObject(int objectType, int objectID) throws EJBException, Exception{
JResult ret = open();
if(ret.isSucceeded()){
ret.returnCode(JResult.DBOPR_SUCCESS);
ret.setValue(dbServerBean.findObject(objectType, objectID));
close();
}else{
throw new Exception(ret.getMessage());
}
return ret;
}
/**
* Find object with condition specified
* @param objectType
* @param condition
* @return JResult object. Check JResult.getValue()>0 if object is found,
* -1 if an error occurred, and equal 0 if object not found
*/
public JResult findObject(int objectType, String condition) throws EJBException, Exception{
JResult ret = open();
if(ret.isSucceeded()){
ret.returnCode(JResult.DBOPR_SUCCESS);
ret.setValue(dbServerBean.findObject(objectType, condition));
close();
}else{
throw new Exception(ret.getMessage());
}
return ret;
}
/**
* Build a tree object data with root is NodeHelper object.
* Order parent-child as follows:
* NodeHelper -> NodeVO -> BlockVO -> PackageVO -> PortVO
* @return NodeHelper object
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -