java - 如何在 EJB 2.x 中将会话 bean 识别为有状态或无状态?
问题描述
我正在从事从 EJB 2.x 到 3.1 的迁移项目。由于 EJB 2.x 中没有注释,我无法确定会话 bean 是无状态的还是无状态的。
下面是应用程序中的会话 bean 之一:
package com.guycarp.fac.casualty.ejb.copyFacAccount;
import javax.ejb.*;
import weblogic.ejb.*;
import com.guycarp.common.gcerror.GCException;
import java.rmi.RemoteException;
import java.sql.*;
import javax.ejb.*;
import javax.naming.InitialContext;
import javax.sql.DataSource;
import javax.transaction.UserTransaction;
import java.math.BigDecimal;
import com.guycarp.fac.casualty.facManager.*;
import com.guycarp.fac.casualty.ejb.company.EBCompany.*;
import com.guycarp.common.util.*;
import com.guycarp.fac.casualty.util.*;
/**
* @ejbgen:session enable-call-by-reference="true" default-transaction="Supports"
* ejb-name = "SBCopyFacAccount"
*
* @ejbgen:jndi-name local="ejb.SBCopyFacAccountLocalHome"
* remote = "ejb.SBCopyFacAccountRemoteHome"
*
* @ejbgen:file-generation remote-class = "true" remote-class-name="SBCopyFacAccountRemote" remote-home = "true" remote-home-name="SBCopyFacAccountRemoteHome" local-class="true" local-class-name="SBCopyFacAccount" local-home="true" local-home-name="SBCopyFacAccountHome"
*/
public class SBCopyFacAccountBean
extends GenericSessionBean
implements SessionBean
{
public void ejbCreate() {
// Your code here
}
private SessionContext m_ctx = null;
protected final String SBCOPY_JDBC_URL = "COPYACCOUNT_JDBC_URL";
protected final String CLASS_NAME = "com.guycarp.fac.casualty.ejb.copyFacAccount.SBCopyFacAccountBean";
private EBCompanyHome m_EBCompanyHome = null;
/**
* @ejbgen:local-method
* @ejbgen:remote-method
*/
public String copyAccount(String p_OldCedantCompany, String p_OldFacAccountNumber , Double p_OldFacAccountVersion,
String p_NewCedantCompany, String p_UserId,
BigDecimal idSubmission,Boolean isCedant,String lines, String renewal) throws GCException
{
Connection conn = null;
CallableStatement cs = null;
//UserTransaction utx = null;
String newFacAccountNumber=null;
try {
conn = getConnection();
/** Using the new procedure for getUID which has an OUTPUT Parameter.
*/
//utx = m_ctx.getUserTransaction();
//utx.begin();
//System.out.println("lines " + lines);
cs = conn.prepareCall("{call procCopyFacAccount(?, ?, ?, ?, ?, ?, ?, ?, ?,"+lines+",?,?,?)}");
//System.out.println("p_OldCedantCompany " + p_OldCedantCompany);
cs.setString(1,p_OldCedantCompany);
//System.out.println("p_OldFacAccountNumber " + p_OldFacAccountNumber);
cs.setString(2,p_OldFacAccountNumber);
//System.out.println("p_OldFacAccountVersion " + p_OldFacAccountVersion);
cs.setDouble(3,p_OldFacAccountVersion.doubleValue());
//System.out.println("p_NewCedantCompany " + p_NewCedantCompany);
cs.setString(4,p_NewCedantCompany);
cs.setString(5,"FacExchange");
cs.setString(6,"SBCopyFacAccount");
//System.out.println("p_UserId " + p_UserId);
cs.setString(7,p_UserId);
//System.out.println("idSubmission " + idSubmission);
cs.setBigDecimal(8,idSubmission);
if (isCedant != null) {
//System.out.println("cedant");
if (isCedant.booleanValue()) {
//System.out.println("cedant true");
cs.setInt(9,1);
} else {
//System.out.println("cedant false");
cs.setInt(9,0);
}
}
cs.setString(10,renewal);
cs.registerOutParameter(11,java.sql.Types.VARCHAR);
cs.registerOutParameter(12,java.sql.Types.VARCHAR);
boolean b = cs.execute(); //HRH 2002-08-19 : Unused local variable
int i = cs.getUpdateCount();// HRH 2002-08-19 : Unused local variable
String ErrorMessage = cs.getString(11);
//System.out.println("ErrorMessage= " + ErrorMessage);
newFacAccountNumber = cs.getString(12);
//System.out.println("SBCopyFacAccountBean newFacAccountNumber " + newFacAccountNumber);
if ( ErrorMessage != null && !ErrorMessage.equals("") ) {
throw new GCException( new Exception(ErrorMessage), ErrorMessage, false, false);
}
//utx.commit();
//utx = null;
} catch ( Exception e ) {
GCUtility.errorInfo(e.getMessage());
throw new GCException( e, "Exception thrown in copyAccount.", false, false);
} finally {
/*
if ( utx!= null ) {
try {
utx.rollback();
} catch ( Exception e ) {
e.printStackTrace();
throw new GCException( e, "Exception thrown in copyAccount.", false, false);
}
}
*/
try {
if ( cs != null ) cs.close();
if ( conn != null ) conn.close();
} catch ( Exception e ) {
GCUtility.errorInfo(e.getMessage());
throw new GCException( e, "Exception thrown in copyAccount.", false, false);
}
}
//before sending this newFacAccountNumber back, set the optprimary for this account as 1.
if (newFacAccountNumber != null) {
newFacAccountNumber= newFacAccountNumber.trim();
String accountNumber = p_OldCedantCompany + " " + newFacAccountNumber + " " + FacConstant.FACACCOUNTVERSION_01;
Connection con = null;
PreparedStatement stmt= null;
try {
String sql = "UPDATE TBLFACACCOUNT SET OPTACCOUNTPRIMARY = 1 WHERE CDEFACACCOUNTNUMBER="+newFacAccountNumber
+" and UIDCEDANTCOMPANY = "+getEBCompany(p_NewCedantCompany) +" and NUMFACACCOUNTVERSION="+FacConstant.FACACCOUNTVERSION_01;
con = getConnection();
stmt = con.prepareStatement(sql);
int success = stmt.executeUpdate();
} catch (Exception e) {
GCUtility.errorInfo("Exception in copy account bean"+e.getMessage());
}
}
return newFacAccountNumber ;
}
/**
* @ejbgen:local-method
* @ejbgen:remote-method
*/
public void copyAccount(BigDecimal idSubmission, String newCedantCompany,
String userId) throws GCException {
Connection conn = null;
CallableStatement cs = null;
//UserTransaction utx = null;
try {
conn = getConnection();
/** Using the new procedure for getUID which has an OUTPUT Parameter.
*/
//utx = m_ctx.getUserTransaction();
//utx.begin();
cs = conn.prepareCall("{call procCopyFacAccountsSubmission(?, ?, ?, ?, ?)}");
cs.setDouble(1,idSubmission.doubleValue());
cs.setString(2,newCedantCompany);
cs.setString(3,"FacExchange");
cs.setString(4,"SBCopyFacAccountBean");
cs.setString(5,userId);
cs.registerOutParameter(6,java.sql.Types.VARCHAR);
boolean b = cs.execute();
int i = cs.getUpdateCount();
String ErrorMessage = cs.getString(6);
if ( ErrorMessage != null && !ErrorMessage.equals("") ) {
throw new GCException( new Exception(ErrorMessage), ErrorMessage, false, false);
}
//utx.commit();
//utx = null;
} catch ( Exception e ) {
GCUtility.errorInfo(e.getMessage());
throw new GCException( e, "Exception thrown in copyAccount of "+ CLASS_NAME, false, false);
} finally {
/*
if ( utx!= null ) {
try {
utx.rollback();
} catch ( Exception e ) {
e.printStackTrace();
throw new GCException( e, "Exception while rolling back in copyAccount of "+ CLASS_NAME, false, false);
}
}
*/
try {
if ( cs != null ) cs.close();
if ( conn != null ) conn.close();
} catch ( Exception e ) {
GCUtility.errorInfo(e.getMessage());
throw new GCException( e, "Exception while closing connection in copyAccount of "+ CLASS_NAME, false, false);
}
}
}
private Double getEBCompany(String cdeCompanyNumber) throws GCException{
Double uidCompany = null;
// @@ uncomment this line when eb is ready
//
try {
EBCompanyHome m_EBCompanyHome = (EBCompanyHome)GCHomesCache.getHome(EBCompanyHome.class,FacConstant.EBCOMPANY_JNDI_URL);
EBCompany ebCompany = m_EBCompanyHome.findByCompanyNumber(cdeCompanyNumber);
if (ebCompany != null) {
// @@ line changed
//uidCompany = ebCompany.getID();
uidCompany = new Double(ebCompany.getM_uidCompany().doubleValue());
}
return uidCompany;
} catch (ObjectNotFoundException e) {
return null;
} catch(Exception e) {
throw new GCException (e,"Exception in getEBCompany(String cdeCompanyNumber) of copy account process",false,false);
}
//
}
protected Connection getConnection() throws Exception {
InitialContext ic = new InitialContext();
DataSource dataSource = (DataSource) ic.lookup("jdbc.FacExchangeDS");
return dataSource.getConnection();
}
}
我使用 JDeveloper 作为 IDE。我对迁移有一些疑问。我可以看到 EJB 2.x 项目中有多个实体 bean。但是 EJB 3.1 中没有实体 bean。实体 bean 的目的和替代方法是什么?
解决方案
您的项目中可能有一个ejb-jar.xml
.ear 或 .jar,这个 XML 具有关于您的 EJB 的属性。那里应该有关于无状态或有状态的信息。在此 XML 中可能还需要其他信息,例如远程或本地接口、链接和类名称。
这里我有一个例子:
...
...
<session>
<display-name>myEjbExample</display-name>
<ejb-name>myEjbExample</ejb-name>
<home>com.test.myEjbExampleHome</home>
<remote>com.test.myEjbExampleRemote</remote>
<ejb-class>com.test.myEjbExample</ejb-class>
<!-- this tag indicates what you need -->
<session-type>Stateless</session-type>
<transaction-type>Bean</transaction-type>
<ejb-ref>
<ejb-ref-name>EjbExample</ejb-ref-name>
<ejb-ref-type>Entity</ejb-ref-type>
<home>com.test.myEjbExampleHome</home>
<remote>com.test.myEjbExample</remote>
<ejb-link>myEjbExample</ejb-link>
</ejb-ref>
<resource-ref>
<res-ref-name>jdbc/myConn</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Application</res-auth>
</resource-ref>
</session>
...
...
推荐阅读
- kdb - q kdb 中 iasc 与 rank 的关系
- algolia - Algolia 搜索包含值的数组
- jira - 在 JIRA 中的已解决票证中格式化解决方案详细信息
- google-apps-script - 创建添加 BottomBar 的 Google App Scripts 插件
- arrays - 解释这个for循环在python中的工作原理
- c# - 社交分享授权页面
- c++ - 如何使用移位运算符分配 BH1750 光传感器中的值 <
我正在使用带有 arduino 的 BH1750 光传感器在 LCD 上显示勒克斯值。但在代码中,我无法得到公式。谁能给我解释一下公式?
我试图在 BH1750 的数据表中找到它,但我无法理解这一行:
value = ((buff[0]<<8)|buff[1])/1.2;
整个代码:
- google-apps - 用户与许可 Google Apps 免费版
- reactjs - 重定向无法正常工作。它不断重新加载页面
- c++ - 错误:二进制表达式的操作数无效(映射使用查找函数错误)