User: peter
Date: 01/01/24 18:45:34
Modified: src/main/org/jboss/test/cts/ejb StatefulSessionBean.java
StatelessSessionBean.java
Added: src/main/org/jboss/test/cts/ejb CtsBmpBean.java
Log:
Added rudimentary BMP tests.
Revision Changes Path
1.9 +24 -13
jbosstest/src/main/org/jboss/test/cts/ejb/StatefulSessionBean.java
Index: StatefulSessionBean.java
===================================================================
RCS file:
/products/cvs/ejboss/jbosstest/src/main/org/jboss/test/cts/ejb/StatefulSessionBean.java,v
retrieving revision 1.8
retrieving revision 1.9
diff -u -r1.8 -r1.9
--- StatefulSessionBean.java 2001/01/21 17:59:39 1.8
+++ StatefulSessionBean.java 2001/01/25 02:45:33 1.9
@@ -15,8 +15,8 @@
/**
*
* @see <related>
- * @author $Author: osh $
- * @version $Revision: 1.8 $
+ * @author $Author: peter $
+ * @version $Revision: 1.9 $
*/
public class StatefulSessionBean
@@ -146,7 +146,7 @@
*/
public BeanContextInfo getBeanContextInfo ()
- throws java.rmi.RemoteException
+ throws java.rmi.RemoteException
{
BeanContextInfo ctx = new BeanContextInfo();
@@ -163,17 +163,20 @@
ctx.homeInterface = homeInterface.getName();
System.out.println("Getting CallerPrincipal...");
+
Principal principal = sessionCtx.getCallerPrincipal();
- if( principal == null )
+ if (principal == null)
{
- System.out.println( "Went to get 'Principal', principal is null!" );
- throw new java.rmi.RemoteException( "Unable to get Principal,
getCallerPrincipal() returned NULL");
+ System.out.println("Went to get 'Principal', principal is null!");
+
+ throw new java.rmi.RemoteException(
+ "Unable to get Principal, getCallerPrincipal() returned NULL");
}
- ctx.principleName = principal.getName();
- ctx.isCallerInRole =
- new Boolean(sessionCtx.isCallerInRole("bean tester"));
+ ctx.principleName = principal.getName();
+ ctx.isCallerInRole =
+ new Boolean(sessionCtx.isCallerInRole("bean tester"));
System.out.println("calling setRollbackOnly( ) on context");
sessionCtx.setRollbackOnly();
@@ -190,10 +193,18 @@
*/
public void loopbackTest ()
- throws java.rmi.RemoteException
+ throws java.rmi.RemoteException
{
try
{
+<<<<<<< StatefulSessionBean.java
+ Context ctx = new InitialContext();
+ StatefulSessionHome home =
+ ( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
+ StatefulSession sessionBean = home.create();
+
+ sessionBean.loopbackTest(sessionCtx.getEJBObject());
+=======
Context ctx = new InitialContext();
StatefulSessionHome home =
( StatefulSessionHome ) ctx.lookup("ejbcts/StatefulSessionBean");
@@ -205,12 +216,12 @@
throw new EJBException(ex);
}
sessionBean.loopbackTest(sessionCtx.getEJBObject());
+>>>>>>> 1.8
}
- catch( javax.naming.NamingException nex )
+ catch (javax.naming.NamingException nex)
{
- System.out.println( "Could not locate bean instance" );
+ System.out.println("Could not locate bean instance");
}
-
}
/**
1.4 +27 -7
jbosstest/src/main/org/jboss/test/cts/ejb/StatelessSessionBean.java
Index: StatelessSessionBean.java
===================================================================
RCS file:
/products/cvs/ejboss/jbosstest/src/main/org/jboss/test/cts/ejb/StatelessSessionBean.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- StatelessSessionBean.java 2001/01/21 17:59:39 1.3
+++ StatelessSessionBean.java 2001/01/25 02:45:34 1.4
@@ -1,5 +1,7 @@
package org.jboss.test.cts.ejb;
+
+
import org.jboss.test.util.ejb.*;
import java.util.*;
import javax.naming.*;
@@ -8,9 +10,18 @@
import org.jboss.test.util.ejb.SessionSupport;
+/**
+ * Class StatelessSessionBean
+ *
+ *
+ * @author
+ * @version %I%, %G%
+ */
+
public class StatelessSessionBean
- extends SessionSupport
+ extends SessionSupport
{
+
/**
* Method ejbCreate
*
@@ -24,7 +35,7 @@
{
}
- /* The following included will not deploy as per the
+ /* The following included will not deploy as per the
EJB 1.1 spec: [6.8] "There can be no other create methods
in the home interface.
public void ejbCreate (String aString)
@@ -55,10 +66,19 @@
*/
public void loopbackTest ()
- throws java.rmi.RemoteException
+ throws java.rmi.RemoteException
{
try
{
+<<<<<<< StatelessSessionBean.java
+ Context ctx = new InitialContext();
+ StatelessSessionHome home =
+ ( StatelessSessionHome ) ctx.lookup(
+ "ejbcts/StatelessSessionBean");
+ StatelessSession sessionBean = home.create();
+
+ sessionBean.loopbackTest(sessionCtx.getEJBObject());
+=======
Context ctx = new InitialContext();
StatelessSessionHome home =
( StatelessSessionHome ) ctx.lookup("ejbcts/StatelessSessionBean");
@@ -70,12 +90,12 @@
throw new EJBException(ex);
}
sessionBean.loopbackTest(sessionCtx.getEJBObject());
+>>>>>>> 1.3
}
- catch( javax.naming.NamingException nex )
+ catch (javax.naming.NamingException nex)
{
- System.out.println( "Could not locate bean instance" );
+ System.out.println("Could not locate bean instance");
}
-
}
/**
@@ -97,7 +117,7 @@
bean.method1("Hello");
}
-
}
+/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/
1.1 jbosstest/src/main/org/jboss/test/cts/ejb/CtsBmpBean.java
Index: CtsBmpBean.java
===================================================================
package org.jboss.test.cts.ejb;
import org.jboss.test.cts.keys.*;
import java.rmi.RemoteException;
import java.util.Vector;
import java.util.Collection;
import java.sql.*;
import javax.naming.*;
import javax.ejb.*;
import javax.sql.DataSource;
/**
* Class CtsBmpBean
*
*
* @author
* @version %I%, %G%
*/
public class CtsBmpBean
implements EntityBean
{
private static final String TABLE_NAME = "BMP_BEAN_TBL";
EntityContext ctx = null;
DataSource ds = null;
// bmp fields
String accountNumber;
String personsName;
/**
* Method ejbCreate
*
*
* @param pk
* @param personsName
*
* @return
*
* @throws CreateException
* @throws DuplicateKeyException
* @throws EJBException
* @throws RemoteException
*
*/
public AccountPK ejbCreate (AccountPK pk, String personsName)
throws CreateException, DuplicateKeyException, EJBException,
RemoteException
{
System.out.println("ejbCreate (AccountPK, String) called");
tearDown();
setUp();
this.accountNumber = pk.getKey();
this.personsName = personsName;
boolean duplicate = false;
Connection con = null;
try
{
con = ds.getConnection();
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("SELECT accountNumber FROM "
+ TABLE_NAME + " WHERE accountNumber="
+ accountNumber);
duplicate = rs.next();
rs.close();
s.close();
if (!duplicate)
{
PreparedStatement ps = con.prepareStatement("INSERT INTO "
+ TABLE_NAME
+ " VALUES (?,?)");
ps.setString(1, accountNumber);
ps.setString(2, personsName);
ps.execute();
ps.close();
}
}
catch (Exception ex)
{
ex.printStackTrace();
throw new EJBException("Entity bean creation failure: "
+ ex.getMessage());
}
finally
{
try
{
if (con != null) con.close();
}
catch (Exception _sqle){}
}
if (duplicate)
throw new DuplicateKeyException("Bean with accountNumber="
+ accountNumber
+ " already exists.");
return new AccountPK(accountNumber);
}
/**
* Method ejbFindByPrimaryKey
*
*
* @param pk
*
* @return
*
* @throws EJBException
* @throws FinderException
* @throws RemoteException
*
*/
public AccountPK ejbFindByPrimaryKey (AccountPK pk)
throws FinderException, EJBException, RemoteException
{
System.out.println("ejbFindByPrimaryKey (Integer) called");
Connection con = null;
boolean found = false;
try
{
con = ds.getConnection();
PreparedStatement ps =
con.prepareStatement("SELECT accountNumber FROM " + TABLE_NAME
+ " WHERE accountNumber=?");
ps.setString(1, pk.getKey());
ResultSet rs = ps.executeQuery();
found = rs.next();
rs.close();
ps.close();
}
catch (Exception ex)
{
throw new EJBException("couldnt seek: " + ex.getMessage());
}
finally
{
try
{
if (con != null) con.close();
}
catch (Exception _sqle){}
}
if (!found)
throw new FinderException("No bean with accountNumber="
+ pk.getKey() + " found.");
return pk;
}
/**
* Method ejbFindAll
*
*
* @return
*
* @throws EJBException
* @throws FinderException
* @throws RemoteException
*
*/
public Collection ejbFindAll ()
throws EJBException, FinderException, RemoteException
{
System.out.println("ejbFindAll () called");
Connection con = null;
Vector result = new Vector();
try
{
con = ds.getConnection();
Statement s = con.createStatement();
ResultSet rs = s.executeQuery("SELECT accountNumber FROM "
+ TABLE_NAME + "");
while (rs.next())
{
result.add(rs.getString("accountNumber"));
}
rs.close();
s.close();
}
catch (Exception ex)
{
throw new EJBException("couldnt seek: " + ex.getMessage());
}
finally
{
try
{
if (con != null) con.close();
}
catch (Exception _sqle){}
}
return result;
}
/**
* Method ejbPostCreate
*
*
* @param pk
* @param personsName
*
* @throws CreateException
* @throws DuplicateKeyException
* @throws EJBException
* @throws RemoteException
*
*/
public void ejbPostCreate (AccountPK pk, String personsName)
throws CreateException, DuplicateKeyException, EJBException,
RemoteException
{
System.out.println("ejbPostCreate (AccountPK, String) called");
}
/**
* Method ejbLoad
*
*
* @throws EJBException
* @throws RemoteException
*
*/
public void ejbLoad ()
throws EJBException, RemoteException
{
System.out.println("ejbLoad () called");
Connection con = null;
try
{
con = ds.getConnection();
PreparedStatement ps =
con.prepareStatement("SELECT accountNumber,name FROM "
+ TABLE_NAME + " WHERE accountNumber=?");
ps.setInt(1, (( Integer ) ctx.getPrimaryKey()).intValue());
ResultSet rs = ps.executeQuery();
if (rs.next())
{
accountNumber = rs.getString("accountNumber");
personsName = rs.getString("name");
}
rs.close();
ps.close();
}
catch (Exception ex)
{
throw new EJBException("couldnt load: " + ex.getMessage());
}
finally
{
try
{
if (con != null) con.close();
}
catch (Exception sqlex){}
}
}
/**
* Method ejbStore
*
*
* @throws EJBException
* @throws RemoteException
*
*/
public void ejbStore ()
throws EJBException, RemoteException
{
System.out.println("ejbStore () called");
Connection con = null;
try
{
con = ds.getConnection();
PreparedStatement ps =
con.prepareStatement("UPDATE " + TABLE_NAME
+ " SET name=? WHERE accountNumber=?");
ps.setString(1, personsName);
ps.setString(2, accountNumber);
ps.execute();
ps.close();
}
catch (Exception ex)
{
throw new EJBException("couldnt store: " + ex.getMessage());
}
finally
{
try
{
if (con != null) con.close();
}
catch (Exception _sqle){}
}
}
/**
* Method ejbRemove
*
*
* @throws EJBException
* @throws RemoteException
*
*/
public void ejbRemove ()
throws EJBException, RemoteException
{
System.out.println("ejbRemove () called");
Connection con = null;
try
{
con = ds.getConnection();
PreparedStatement ps =
con.prepareStatement("DELETE FROM " + TABLE_NAME
+ " WHERE accountNumber=?");
ps.setString(1, accountNumber);
ps.execute();
ps.close();
}
catch (Exception ex)
{
throw new EJBException("couldnt remove: " + ex.getMessage());
}
finally
{
try
{
tearDown();
if (con != null) con.close();
}
catch (Exception _sqle){}
}
}
/**
* Method ejbActivate
*
*
* @throws EJBException
* @throws RemoteException
*
*/
public void ejbActivate ()
throws EJBException, RemoteException
{
System.out.println("ejbActivate () called");
}
/**
* Method ejbPassivate
*
*
* @throws EJBException
* @throws RemoteException
*
*/
public void ejbPassivate ()
throws EJBException, RemoteException
{
System.out.println("ejbPassivate () called");
}
/**
* Method setEntityContext
*
*
* @param ctx
*
* @throws EJBException
* @throws RemoteException
*
*/
public void setEntityContext (EntityContext ctx)
throws EJBException, RemoteException
{
System.out.println("setEntityContext (\"" + ctx.getPrimaryKey()
+ "\") called");
this.ctx = ctx;
// lookup the datasource
try
{
ds = ( DataSource ) new InitialContext().lookup(
"java:comp/env/datasource");
}
catch (NamingException nex)
{
throw new EJBException("Datasource not found: " + nex.getMessage());
}
}
/**
* Method unsetEntityContext
*
*
* @throws EJBException
* @throws RemoteException
*
*/
public void unsetEntityContext ()
throws EJBException, RemoteException
{
System.out.println("unsetEntityContext () called");
ctx = null;
}
/**
* Method setPersonsName
*
*
* @param personsName
*
* @throws RemoteException
*
*/
public void setPersonsName (String personsName)
throws RemoteException
{
this.personsName = personsName;
}
/**
* Method getPersonsName
*
*
* @return
*
* @throws RemoteException
*
*/
public String getPersonsName ()
throws RemoteException
{
return this.personsName;
}
private void setUp ()
throws CreateException, EJBException
{
System.out.println("Setting up DATBASE tables for BMP test...");
try
{
ds = ( DataSource ) new InitialContext().lookup(
"java:comp/env/datasource");
}
catch (NamingException nmEx)
{
throw new CreateException("Datasource not found: "
+ nmEx.getMessage());
}
Connection con = null;
try
{
con = ds.getConnection();
Statement s = con.createStatement();
s.executeUpdate("CREATE TABLE " + TABLE_NAME
+ " (accountNumber VARCHAR(25), name VARCHAR(200))");
s.close();
}
catch (Exception ex)
{
ex.printStackTrace();
}
finally
{
try
{
if (con != null) con.close();
}
catch (Exception sqlEx){}
}
}
private void tearDown ()
{
System.out.println("Cleaning up DATABASE tables for BMP test...");
Connection con = null;
try
{
con = ds.getConnection();
Statement s = con.createStatement();
s.executeUpdate("DROP TABLE " + TABLE_NAME);
s.close();
}
catch (Exception ex)
{
System.out.println("Error while dropping table: " + ex.getMessage());
}
finally
{
try
{
if (con != null) con.close();
}
catch (Exception sqlEx)
{ // ignore..
}
}
}
}
/*------ Formatted by Jindent 3.23 Basic 1.0 --- http://www.jindent.de ------*/