Hi Dave,
Here is all of my code and configuration files. Not too much...))))
I use Win2000, oracle 8.1.7, the thin driver and jboss 2.0 final
I hope this can help you
JMi
jboss.conf
==========
<MLET CODE = "org.jboss.logging.Logger" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "org.jboss.logging.ConsoleLogging" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
<ARG TYPE="java.lang.String" VALUE="Information,Warning,Error">
<ARG TYPE="java.lang.String" VALUE="[{2}] {4}">
</MLET>
<MLET CODE = "org.jboss.util.ClassPathExtension" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
<ARG TYPE="java.lang.String" VALUE="../../log/">
</MLET>
<MLET CODE = "org.jboss.logging.FileLogging" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
<ARG TYPE="java.lang.String" VALUE="Information,Debug,Warning,Error">
<ARG TYPE="java.lang.String" VALUE="[{2}] {4}">
</MLET>
<MLET CODE = "org.jboss.util.ClassPathExtension" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
<ARG TYPE="java.lang.String" VALUE="../../tmp/">
</MLET>
<MLET CODE = "org.jboss.util.ClassPathExtension" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
<ARG TYPE="java.lang.String" VALUE="../../db/">
</MLET>
<MLET CODE = "org.jboss.util.Info" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "org.jboss.util.ClassPathExtension" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
<ARG TYPE="java.lang.String" VALUE="./">
</MLET>
<MLET CODE = "org.jboss.jdbc.JdbcProvider"
ARCHIVE="jboss.jar,idb.jar,hsql.jar" CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "org.jboss.web.WebService" ARCHIVE="jboss.jar,dynaserver.jar"
CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "org.jboss.naming.NamingService" ARCHIVE="jnpserver.jar"
CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "org.jboss.tm.TransactionManagerService"
ARCHIVE="jboss.jar,jta-spec1_0_1.jar" CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "org.jboss.security.JaasSecurityManagerService"
ARCHIVE="jboss.jar" CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "org.jboss.security.SimpleRealmMappingService"
ARCHIVE="jboss.jar" CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "org.jboss.security.EJBSecurityManagerService"
ARCHIVE="jboss.jar" CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE="org.jboss.jdbc.XADataSourceLoader" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
<ARG TYPE="java.lang.String" VALUE="pyritesDB">
<ARG TYPE="java.lang.String"
VALUE="oracle.jdbc.xa.client.OracleXADataSource">
</MLET>
<MLET CODE = "org.jboss.ejb.ContainerFactory"
ARCHIVE="jboss.jar,ejb.jar,jnp-client.jar,ejxeditor.jar,ejxjboss.jar"
CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "org.jboss.ejb.AutoDeployer" ARCHIVE="jboss.jar">
<ARG TYPE="java.lang.String" VALUE="../deploy/">
</MLET>
<MLET CODE = "org.jboss.jmx.server.JMXAdaptorService" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "org.jboss.jmx.server.RMIConnectorService" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
</MLET>
<MLET CODE = "com.sun.jdmk.comm.HtmlAdaptorServer" ARCHIVE="jmxtools.jar"
CODEBASE="../../lib/ext/" NAME="Adaptor:name=html">
</MLET>
<MLET CODE = "org.jboss.configuration.ConfigurationService"
ARCHIVE="jboss.jar,../xml.jar" CODEBASE="../../lib/ext/">
</MLET>
<!--
-- The j2ee deployer can deploy jar,war and ear files. Its role is to
-- split the archive and hand the parts (jars, wars) to the relevant
-- deployers
--
-- Arguments: #1: where the j2eedeployer should store its config files
-- #2: the jar deployer: currently only ContainerFactory
-- #3: the war deployer: you can use tomcat
(":service=EmbeddedTomcat")
-- or jetty (":service=Jetty")
-- See below to start these services
-->
<MLET CODE = "org.jboss.deployment.J2eeDeployer"
ARCHIVE="jboss.jar,../xml.jar" CODEBASE="../../lib/ext/">
<ARG TYPE="java.lang.String" VALUE="../tmp/deploy">
<ARG TYPE="java.lang.String" VALUE="EJB:service=ContainerFactory">
<ARG TYPE="java.lang.String" VALUE=":service=EmbeddedTomcat">
</MLET>
<!--
-- Uncomment this to add "Stand-alone Stack Tomcat support".
-- This means that JSP and Servlets will work with EJB in different stacks
and
-- communicate through network invocation. If you benchmark j2ee please
use "integrated stack".
-- Also note that you cannot use the J2EE deployer with Tomcat in this
configuration.
-- Be sure to set your 'TOMCAT_HOME' environment variable before starting
JBoss.
-- Note: this reads the server.xml configuration file of Tomcat, you can't
use the j2ee deployer
--
-- MLET CODE = "org.jboss.tomcat.TomcatService" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
-- /MLET>
-->
<!-- WARNING: only one of the tomcat services can be configured, either
"stand alone or integrated" -->
<!--
-- Uncomment this to add "Integrated Stack (fast) Tomcat support".
-- This service allows you to integrate the stack of Tomcat and jboss.
-- Invocations are not going through network but pass native pointers
resulting in dramatic speed increases.
-- This service allows the J2EE deployer to add and remove Tomcat contexts
dynamically
-- through JMX for you and in effect deploy EARs. Note that tomcat's
server.xml file will not be processed:
-- you can only use JMX to add contexts. Use the J2EE deployer to deploy
full EARs on this stack
-- Be sure to set your 'TOMCAT_HOME' environment variable before starting
JBoss.
--
-- The ARG tag is the port to run tomcat on.
--
-->
<MLET CODE = "org.jboss.tomcat.EmbeddedTomcatService" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
<ARG TYPE="int" VALUE=8080>
</MLET>
<!--
-- Uncomment this to add Jetty support.
-- This service allows you to add and remove Jetty contexts dynamically
-- through JMX.
-- Be sure to set your 'JETTY_HOME' environment variable before starting
-- JBoss.
-- Replace the ARG tag to give Jetty's XML configuration file.
-- You can use JBOSS_HOME/conf/default/jetty.xml
--
-- MLET CODE = "org.jboss.jetty.JettyService" ARCHIVE="jetty-service.jar"
CODEBASE="../../lib/ext/">
-- ARG TYPE="java.lang.String"
VALUE="file:/usr/jboss/conf/default/jetty.xml">
-- /MLET>
<MLET CODE = "org.jboss.spydermq.SpyderMQService" ARCHIVE="jboss.jar"
CODEBASE="../../lib/ext/">
</MLET>
jboss.jcml
==========
<?xml version="1.0"?>
<server>
<mbean name="DefaultDomain:service=XADataSource,name=pyritesDB">
<attribute name="Properties"></attribute>
<attribute
name="URL">jdbc:oracle:thin:@localhost:1521:myOracle</attribute>
<attribute name="GCMinIdleTime">1200000</attribute>
<attribute name="JDBCUser">xxxxx</attribute>
<attribute name="MaxSize">0</attribute>
<attribute name="Password">xxxxx</attribute>
<attribute name="GCEnabled">false</attribute>
<attribute name="InvalidateOnError">false</attribute>
<attribute name="TimestampUsed">false</attribute>
<attribute name="Blocking">true</attribute>
<attribute name="GCInterval">120000</attribute>
<attribute name="IdleTimeout">1800000</attribute>
<attribute name="IdleTimeoutEnabled">false</attribute>
<attribute name="LoggingEnabled">false</attribute>
<attribute name="MaxIdleTimeoutPercent">1.0</attribute>
<attribute name="MinSize">0</attribute>
</mbean>
<mbean name="Adaptor:name=html">
<attribute name="MaxActiveClientCount">10</attribute>
<attribute name="Parser" />
<attribute name="Port">8082</attribute>
</mbean>
<mbean name="DefaultDomain:service=MLet">
<attribute
name="LibraryDirectory">D:\java\EJBServers\jboss_tomcat\jboss-2.0-FINAL\bin</attribute>
</mbean>
<mbean name="DefaultDomain:service=TransactionManager">
<attribute name="TransactionTimeout">300</attribute>
</mbean>
<mbean name="DefaultDomain:service=Logging,type=Console">
<attribute name="Format">[{2}] {4}</attribute>
</mbean>
<mbean name="DefaultDomain:service=Webserver">
<attribute name="Port">8083</attribute>
</mbean>
<mbean name="DefaultDomain:service=Logging,type=File">
<attribute name="Format">[{2}] {4}</attribute>
<attribute name="LogName">server</attribute>
</mbean>
<mbean name="EJB:service=ContainerFactory">
<attribute name="VerifyDeployments">true</attribute>
<attribute name="MetricsEnabled">false</attribute>
<attribute name="VerifierVerbose">true</attribute>
</mbean>
</server>
jboss.properties
================
# System properties
# These will be loaded and set by jBoss
#java.rmi.server.useLocalHostName=true
#java.rmi.server.hostname=localhost
#java.rmi.server.codebase=http://localhost:8080/
jboss.xa.xidclass=oracle.jdbc.xa.OracleXid
jdbc.drivers=oracle.jdbc.driver.OracleDriver
#java.security.manager=java.lang.SecurityManager
java.security.auth.login.config==../conf/default/auth.conf
ejb-jar.xml
===========
<?xml version="1.0" encoding="Cp1252"?>
<ejb-jar>
<display-name>IdSector</display-name>
<enterprise-beans>
<entity>
<description>This bean represent the sector BMP entity
bean</description>
<ejb-name>IdSectorBean</ejb-name>
<home>com.id.pyrites.ejb.IdSectorHome</home>
<remote>com.id.pyrites.ejb.IdSector</remote>
<ejb-class>com.id.pyrites.ejb.IdSectorBean</ejb-class>
<persistence-type>Bean</persistence-type>
<prim-key-class>com.id.pyrites.ejb.IdSectorPK</prim-key-class>
<reentrant>false</reentrant>
<resource-ref>
<description>Data Source</description>
<res-ref-name>pyritesDB</res-ref-name>
<res-type>javax.sql.DataSource</res-type>
<res-auth>Container</res-auth>
</resource-ref>
</entity>
</enterprise-beans>
<assembly-descriptor>
<security-role>
<description>This role represents everyone who is allowed full access
to the bean </description>
<role-name>everyone</role-name>
</security-role>
<method-permisson>
<role-name>everyone</role-name>
<method>
<ejb-name>IdSectorBean</ejb-name>
<method-name>*</method-name>
</method>
</method-permisson>
<container-transaction>
<method>
<ejb-name>IdSectorBean</ejb-name>
<method-name>*</method-name>
</method>
<trans-attribute>Required</trans-attribute>
</container-transaction>
</assembly-descriptor>
</ejb-jar>
jboss.xml
=========
<?xml version="1.0" encoding="Cp1252"?>
<jboss>
<secure>false</secure>
<container-configurations />
<resource-managers>
<resource-manager res-class="org.jboss.ejb.deployment.JDBCResource">
<res-name>pyritesDB</res-name>
<res-jndi-name>pyritesDB</res-jndi-name>
</resource-manager>
</resource-managers>
<enterprise-beans>
<entity>
<ejb-name>IdSectorBean</ejb-name>
<jndi-name>IdSector</jndi-name>
</entity>
</enterprise-beans>
</jboss>
SEQUENCE
========
Don't forget to create a sequence called SEQ_VSECT
TABLE sector on which i've build a VSECT view
=============================================
DROP TABLE sectors CASCADE CONSTRAINTS ;
CREATE TABLE sectors (
id_sect NUMBER (15) NOT NULL,
sector_id VARCHAR2 (12) NOT NULL,
name VARCHAR2 (35) NOT NULL,
act VARCHAR2 (1) DEFAULT '1' NOT NULL,
dencod DATE DEFAULT SYSDATE NOT NULL,
signed NUMBER (15) NOT NULL,
CONSTRAINT sect_pk
PRIMARY KEY ( id_sect )
USING INDEX
TABLESPACE pyrites_index PCTFREE 10
STORAGE ( INITIAL 16k NEXT 16k PCTINCREASE 50 ))
TABLESPACE pyrites_data
PCTFREE 10
PCTUSED 40
INITRANS 1
MAXTRANS 255
STORAGE (
INITIAL 16384
NEXT 16384
PCTINCREASE 50
MINEXTENTS 1
MAXEXTENTS 121
FREELISTS 1 FREELIST GROUPS 1 )
NOCACHE;
COMMENT ON COLUMN sectors.name IS 'Sector description';
COMMENT ON COLUMN sectors.sector_id IS 'Logical ID';
IdSectorHome
============
// Title: Pyrites
// Version:
// Copyright: Copyright (c) 2000
// Author: JM Delsaux
// Company: Insurance Data SA
// Description: A simple EJB component
//
// This source file was generated by the JDeveloper EJB Wizard. Subsequent
// generation of this file will overwrite all user modifications.
package com.id.pyrites.ejb;
import java.rmi.*;
import javax.ejb.*;
import java.util.Enumeration;
public interface IdSectorHome extends EJBHome {
// IdSector create(int id, String sectorId, String name,
// String act, String dencod,int signed) throws
RemoteException, CreateException;
IdSector create(String sectorId, String name, int signed) throws
RemoteException, CreateException;
IdSector findByPrimaryKey(IdSectorPK primaryKey) throws RemoteException,
FinderException;
Enumeration findBySectorId(String sectorId) throws RemoteException,
FinderException;
Enumeration findByName(String name) throws RemoteException,
FinderException;
Enumeration findByAct(String act) throws RemoteException, FinderException;
Enumeration findByDencod(String dencod) throws RemoteException,
FinderException;
Enumeration findBySigned(int signed) throws RemoteException,
FinderException;
}
IdSector
========
// Title: Pyrites
// Version:
// Copyright: Copyright (c) 2000
// Author: JM Delsaux
// Company: Insurance Data SA
// Description: A simple EJB component
//
// This source file was generated by the JDeveloper EJB Wizard. Subsequent
// generation of this file will overwrite all user modifications.
package com.id.pyrites.ejb;
import java.rmi.*;
import javax.ejb.*;
public interface IdSector extends EJBObject {
public String getSectorId() throws RemoteException;
public void setSectorId(String value) throws RemoteException;
public String getName() throws RemoteException;
public void setName(String value) throws RemoteException;
public String getAct() throws RemoteException;
public void setAct(String value) throws RemoteException;
public String getDencod() throws RemoteException;
public void setDencod(String value) throws RemoteException;
public int getSigned() throws RemoteException;
public void setSigned(int value) throws RemoteException;
}
IdSectorBean
============
// Title: Pyrites
// Version:
// Copyright: Copyright (c) 2000
// Author: JM Delsaux
// Company: Insurance Data SA
// Description: A simple EJB component
//
// This source file was generated by the JDeveloper EJB Wizard.
package com.id.pyrites.ejb;
import java.rmi.RemoteException;
import javax.naming.Context;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import javax.ejb.EntityBean;
import javax.ejb.CreateException;
import javax.ejb.FinderException;
import javax.ejb.EJBException;
import javax.ejb.ObjectNotFoundException;
import javax.ejb.EntityContext;
import javax.ejb.RemoveException;
import java.sql.SQLException;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.ResultSet;
import javax.sql.DataSource;
import java.util.Enumeration;
import java.util.Vector;
import java.sql.Date;
public class IdSectorBean implements EntityBean {
public int m_ID_SECT;
public String m_SECTOR_ID;
public String m_NAME;
public String m_ACT;
public String m_DENCOD;
public int m_SIGNED;
public EntityContext m_context;
final static String ACTIVE = "1";
final static String INACTIVE = "0";
/*public IdSectorPK ejbCreate(int id,
String sectorId,
String name,
String act,
String dencod,
int signed) throws CreateException {
*/
public IdSectorPK ejbCreate(String sectorId,
String name,
int signed) throws CreateException {
if((sectorId == null) || (name == null))
throw new CreateException("Invalid Parameters");
Date today = new Date(System.currentTimeMillis());
this.m_SECTOR_ID = sectorId;
this.m_NAME = name;
this.m_DENCOD = today.toString();//Today on yyyy-mm-dd format
this.m_ACT = ACTIVE;
this.m_SIGNED = signed;
Connection con = null;
PreparedStatement ps = null;
IdSectorPK primaryKey = null;
ResultSet rs = null;
try {
con = this.getConnection();
//Get the sequence id
ps = con.prepareStatement("SELECT seq_vsect.NEXTVAL as id FROM dual");
rs = ps.executeQuery();
if(!rs.next())
throw new ObjectNotFoundException("Cannot find a valid sequence
number");
this.m_ID_SECT = rs.getInt("id");
ps = con.prepareStatement(
"INSERT INTO VSECT (id_sect, sector_id, name, dencod, act,
signed) " +
"VALUES(?,?,?,TO_DATE(?,'YYYY-MM-DD'),?,?)");
ps.setInt(1, this.m_ID_SECT);
ps.setString(2, this.m_SECTOR_ID);
ps.setString(3, this.m_NAME);
ps.setString(4, this.m_DENCOD);
ps.setString(5, this.m_ACT);
ps.setInt(6, this.m_SIGNED);
//Execute the insert
if(ps.executeUpdate() != 1)
throw new CreateException("Failed to add Sector table");
//Primary key
primaryKey = new IdSectorPK(this.m_ID_SECT);
} catch(SQLException se) {
System.out.println("ejbCreate ERROR: " + se.getMessage());
//throw new EJBException(se);
} finally {
try {
System.out.println("== Finally clause of ejbCreate ==");
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch(SQLException se) {
se.printStackTrace();
} finally {
return primaryKey;
}
}
}
/*public void ejbPostCreate(int id,
String sectorId,
String name,
String act,
String dencod,
int signed) {
*/
public void ejbPostCreate(String sectorId,
String name,
int signed) {
//Do nothing - or do something usefull. Required
}
public IdSectorPK ejbFindByPrimaryKey(IdSectorPK primaryKey) throws
FinderException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
IdSectorPK pk = null;
try {
con = this.getConnection();
ps = con.prepareStatement(
"SELECT id_sect FROM vsect WHERE id_sect = ?");
ps.setInt(1, primaryKey.m_ID_SECT);
//Execute the Query
rs = ps.executeQuery();
//Does it exist
if(!rs.next()) {
throw new ObjectNotFoundException("Cannot find Sector with id = " +
m_ID_SECT);
} else {
pk = new IdSectorPK(rs.getInt("ID_SECT"));
}
} catch(SQLException se) {
//throw new EJBException(se);
} finally {
try {
System.out.println("== Finally clause of ejbPostCreate ==");
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch(SQLException se) {
se.printStackTrace();
} finally {
return pk;
}
}
}
public Enumeration ejbFindBySectorId(String sectorId) throws
FinderException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
Vector keys = new Vector();
try {
con = this.getConnection();
ps = con.prepareStatement(
"SELECT id_sect FROM vsect WHERE sector_id = ?");
ps.setString(1, sectorId);
//Execute the Query
rs = ps.executeQuery();
while(rs.next()) {
IdSectorPK sectorPk = new IdSectorPK(rs.getInt("ID_SECT"));
keys.addElement(sectorPk);
}
} catch(SQLException se) {
//throw new EJBException(se);
} finally {
try {
System.out.println("== Finally clause of ejbFindBySectorId ==");
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch(SQLException se) {
se.printStackTrace();
} finally {
//Always return collection, even if empty
return keys.elements();
}
}
}
public Enumeration ejbFindByName(String name) throws FinderException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
Vector keys = new Vector();
try {
con = this.getConnection();
ps = con.prepareStatement(
"SELECT id_sect FROM vsect WHERE name = ?");
ps.setString(1, name);
//Execute the Query
rs = ps.executeQuery();
while(rs.next()) {
IdSectorPK sectorPk = new IdSectorPK(rs.getInt("ID_SECT"));
keys.addElement(sectorPk);
}
} catch(SQLException se) {
//throw new EJBException(se);
} finally {
try {
System.out.println("== Finally clause of ejbFindByName ==");
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch(SQLException se) {
se.printStackTrace();
} finally {
//Always return collection, even if empty
return keys.elements();
}
}
}
public Enumeration ejbFindByAct(String act) throws FinderException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
Vector keys = new Vector();
try {
con = this.getConnection();
ps = con.prepareStatement(
"SELECT id_sect FROM vsect WHERE act = ?");
ps.setString(1, act);
//Execute the Query
rs = ps.executeQuery();
while(rs.next()) {
IdSectorPK sectorPk = new IdSectorPK(rs.getInt("ID_SECT"));
keys.addElement(sectorPk);
}
//Always return collection, even if empty
return keys.elements();
} catch(SQLException se) {
//throw new EJBException(se);
} finally {
try {
System.out.println("== Finally clause of ejbFindByAct ==");
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch(SQLException se) {
se.printStackTrace();
} finally {
//Always return collection, even if empty
return keys.elements();
}
}
}
public Enumeration ejbFindByDencod(String dencod) throws FinderException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
Vector keys = new Vector();
try {
con = this.getConnection();
ps = con.prepareStatement(
"SELECT id_sect FROM vsect WHERE dencod = TO_DATE(?,'YYYY-MM-DD')");
ps.setString(1, dencod);
//Execute the Query
rs = ps.executeQuery();
while(rs.next()) {
IdSectorPK sectorPk = new IdSectorPK(rs.getInt("ID_SECT"));
keys.addElement(sectorPk);
}
//Always return collection, even if empty
return keys.elements();
} catch(SQLException se) {
//throw new EJBException(se);
} finally {
try {
System.out.println("== Finally clause of ejbFindByDencod ==");
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch(SQLException se) {
se.printStackTrace();
} finally {
//Always return collection, even if empty
return keys.elements();
}
}
}
public Enumeration ejbFindBySigned(int signed) throws FinderException {
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
Vector keys = new Vector();
try {
con = this.getConnection();
ps = con.prepareStatement(
"SELECT id_sect FROM vsect WHERE signed = ?");
ps.setInt(1, signed);
//Execute the Query
rs = ps.executeQuery();
while(rs.next()) {
IdSectorPK sectorPk = new IdSectorPK(rs.getInt("ID_SECT"));
keys.addElement(sectorPk);
}
//Always return collection, even if empty
return keys.elements();
} catch(SQLException se) {
//throw new EJBException(se);
} finally {
try {
System.out.println("== Finally clause of ejbFindBySigned ==");
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch(SQLException se) {
se.printStackTrace();
} finally {
//Always return collection, even if empty
return keys.elements();
}
}
}
//Callback section
public void setEntityContext(EntityContext ctx) throws RemoteException {
m_context = ctx;
}
public void unsetEntityContext() throws RemoteException {
m_context = null;
}
public void ejbActivate() throws RemoteException {
}
public void ejbLoad() throws RemoteException {
IdSectorPK pk = (IdSectorPK) m_context.getPrimaryKey();
Connection con = null;
PreparedStatement ps = null;
ResultSet rs = null;
try {
con = this.getConnection();
ps = con.prepareStatement(
"SELECT sector_id, name, act, TO_CHAR(TRUNC(dencod,
'DD'),'YYYY-MM-DD') AS dencod, signed FROM vsect WHERE id_sect = ?");
ps.setInt(1, pk.m_ID_SECT);
//Execute the Query
rs = ps.executeQuery();
if(rs.next()) {
m_ID_SECT = pk.m_ID_SECT;
m_SECTOR_ID = rs.getString("SECTOR_ID");
m_NAME = rs.getString("NAME");
m_ACT = rs.getString("ACT");
m_DENCOD = rs.getString("DENCOD");
m_SIGNED = rs.getInt("SIGNED");
} else {
//throw new EJBException();
}
} catch(SQLException se) {
//throw new EJBException(se);
} finally {
try {
System.out.println("== Finally clause of ejbLoad ==");
if(rs != null) rs.close();
if(ps != null) ps.close();
if(con != null) con.close();
} catch(SQLException se) {
se.printStackTrace();
}
}
}
public void ejbPassivate() throws RemoteException {
}
public void ejbStore() throws RemoteException {
Connection con = null;
PreparedStatement ps = null;
try {
Date today = new Date(System.currentTimeMillis());
con = this.getConnection();
ps = con.prepareStatement(
"UPDATE vsect " +
"SET sector_id = ?, name = ?, act = ?, " +
"dencod = TO_DATE(?,'YYYY-MM-DD'), signed = ? " +
"WHERE id_sect = ?");
ps.setString(1, m_SECTOR_ID);
ps.setString(2, m_NAME);
ps.setString(3, m_ACT);
// ps.setString(4, m_DENCOD);
ps.setString(4, today.toString());//Today yyyy-mm-dd format
ps.setInt(5, m_SIGNED);
ps.setInt(6, m_ID_SECT);
System.out.println(" m_ID_SECT: " + m_ID_SECT);
System.out.println(" m_SECTOR_ID: " + m_SECTOR_ID);
System.out.println(" m_NAME: " + m_NAME);
System.out.println(" m_ACT: " + m_ACT);
System.out.println(" m_DENCOD: " + m_DENCOD);
System.out.println(" m_SIGNED: " + m_SIGNED);
//Execute the update
if(ps.executeUpdate() != 1) {
System.out.println("Failed to update Sector table - ejbStore");
//throw new CreateException("Failed to update Sector table -
ejbStore");
} else {
System.out.println("Update done - ejbStore");
}
} catch(SQLException se) {
System.out.println("== ERROR - Failed to update Sector table -
ejbStore" + se.getMessage());
//throw new EJBException(se);
} finally {
try {
System.out.println("== Finally clause of ejbStore ==");
if(ps != null) ps.close();
if(con != null) con.close();
} catch(SQLException se) {
se.printStackTrace();
}
}
}
public void ejbRemove() throws RemoteException {
Connection con = null;
PreparedStatement ps = null;
try {
con = this.getConnection();
ps = con.prepareStatement(
"DELETE FROM vsect WHERE id_sect = ?");
ps.setInt(1, m_ID_SECT);
//Execute the update
if(ps.executeUpdate() != 1)
System.out.println("Failed to remove Sector table - ejbRemove");
//throw new CreateException("Failed to remove Sector table -
ejbRemove");
} catch(SQLException se) {
//throw new EJBException(se);
} finally {
try {
System.out.println("== Finally clause of ejbRemove ==");
if(ps != null) ps.close();
if(con != null) con.close();
} catch(SQLException se) {
se.printStackTrace();
}
}
}
private Connection getConnection() throws SQLException {
DataSource ds = null;
try {
Context ctx = new InitialContext();
ds = (DataSource)ctx.lookup("java:/pyritesDB");
} catch(NamingException ne) {
} finally {
return ds.getConnection();
}
}
//Set and get sections
public String getSectorId() throws RemoteException {
return m_SECTOR_ID;
}
public void setSectorId(String value) throws RemoteException {
m_SECTOR_ID = value;
}
public String getName() throws RemoteException {
return m_NAME;
}
public void setName(String value) throws RemoteException {
m_NAME = value;
}
public String getAct() throws RemoteException {
return m_ACT;
}
public void setAct(String value) throws RemoteException {
m_ACT = value;
}
public String getDencod() throws RemoteException {
return m_DENCOD;
}
public void setDencod(String value) throws RemoteException {
m_DENCOD = value;
}
public int getSigned() throws RemoteException {
return m_SIGNED;
}
public void setSigned(int value) throws RemoteException {
m_SIGNED = value;
}
}
IdSectorPK
==========
// Copyright (c) 2000 Insurance Data SA
package com.id.pyrites.ejb;
/**
* A Class class.
* <P>
* @author JM Delsaux
*/
public class IdSectorPK implements java.io.Serializable {
public int m_ID_SECT;
/**
* Constructor
*/
public IdSectorPK() {
}
public IdSectorPK(int value) {
m_ID_SECT = value;
}
public boolean equals(Object obj) {
if((obj == null) || !(obj instanceof IdSectorPK )) return false;
else if(((IdSectorPK)obj).m_ID_SECT == m_ID_SECT) return true;
else return false;
}
public int hashCode() {
return m_ID_SECT;
}
public String toString() {
return String.valueOf(m_ID_SECT);
}
}
A small client that use that EJB
================================
import javax.naming.*;
import java.util.Hashtable;
import javax.rmi.PortableRemoteObject;
import com.id.pyrites.ejb.*;
import java.sql.Date;
/**
This simple application tests the `Interest' Enterprise JavaBean which is
implemented in the package `com.web_tomorrow.interest'. For this to work,
the
Bean must be deployed on an EJB server.
<p>
<b>IMPORTANT</b> If you want to test this in a real client-server
configuration, this class goes on the client; the URL of the naming provider
specifed in the class must be changed from `localhost:1099' to the URL of
the
naming service on the server
*/
class client
{
/**
This method does all the work. It creates an instance of the Interest EJB on
the EJB server, and calls its `calculateCompoundInterest()' method, then
prints
the result of the calculation.
*/
static int type = 100;
public static void main(String[] args)
{
// Set up the naming provider; this may not always be necessary,
depending
// on how your Java system is configured.
System.setProperty("java.naming.factory.initial","org.jnp.interfaces.NamingContextFactory");
System.setProperty("java.naming.provider.url","localhost:1099");
// Enclosing the whole process in a single `try' block is not an ideal
way
// to do exception handling, but I don't want to clutter the program up
// with catch blocks
try {
// Get a naming context
InitialContext jndiContext = new InitialContext();
System.out.println("Got context");
// Get a reference to the Interest Bean
System.out.println ("== TEST ENTITY EJB ==");
Object ref3 = jndiContext.lookup("IdSector");
System.out.println("Got reference");
// Get a reference from this to the Bean's Home interface
IdSectorHome home3 =
(IdSectorHome) PortableRemoteObject.narrow (ref3,
IdSectorHome.class);
/* IdSector sect = null;
try {
type ++;
String stype = "oooooo" + type;
sect = home3.create(stype, "xxxxxx", 1);
// System.out.println("== ID: " +
((IdSectorPK)sect.getPrimaryKey()).m_ID_SECT);
} catch(Exception e) {
System.out.println("== ERROR: " + e.getMessage());
System.out.println("== CLASS: " + e.getClass());
}
//Search for a special pk
IdSectorPK pk = new
IdSectorPK(((IdSectorPK)sect.getPrimaryKey()).m_ID_SECT);*/
IdSectorPK pk = new IdSectorPK(1);
// Create an Interest object from the Home interface
System.out.println("== BEFORE UPDATE ==");
IdSector test3 = home3.findByPrimaryKey(pk);
System.out.println(((IdSectorPK)test3.getPrimaryKey()).m_ID_SECT);
System.out.println(test3.getSectorId());
System.out.println(test3.getName());
System.out.println(test3.getAct());
System.out.println(test3.getDencod());
System.out.println(test3.getSigned());
// test3.setSectorId("tttt");
// test3.setAct("0");
test3.setSigned(22);
// sect.ejbStore();
System.out.println("== AFTER UPDATE ==");
test3 = home3.findByPrimaryKey(pk);
// IdSectorPK pk = new
IdSectorPK(((IdSectorPK)sect.getPrimaryKey()).m_ID_SECT);
System.out.println(((IdSectorPK)test3.getPrimaryKey()).m_ID_SECT);
System.out.println(test3.getSectorId());
System.out.println(test3.getName());
System.out.println(test3.getAct());
System.out.println(test3.getDencod());
System.out.println(test3.getSigned());
System.out.println ("****************************************");
System.out.println ("");
}
catch(Exception e) {
//System.out.println();
e.printStackTrace();
}
}
}
----Original Message Follows----
From: "Bolt, Dave" <[EMAIL PROTECTED]>
Reply-To: "jBoss" <[EMAIL PROTECTED]>
To: jBoss <[EMAIL PROTECTED]>
Subject: RE: [jBoss-User] JBOSS and Oracle
Date: Thu, 25 Jan 2001 10:04:47 -0500
MIME-Version: 1.0
Received: from [205.227.191.14] by hotmail.com (3.2) with ESMTP id
MHotMailBC398CC10097D82197E1CDE3BF0EC00F0; Thu Jan 25 07:10:17 2001
Received: from atsc.army.mil by cgi.clearink.com with SMTP; Thu, 25 Jan 2001
07:05:18 -0800
>From [EMAIL PROTECTED] Thu Jan 25 07:10:19 2001
Message-ID:
<[EMAIL PROTECTED]>
X-Mailer: Internet Mail Service (5.5.2650.21)
Sender: <[EMAIL PROTECTED]>
Precedence: Bulk
List-Software: LetterRip Pro 3.0.7 by Fog City Software, Inc.
List-Subscribe: <mailto:[EMAIL PROTECTED]>
List-Digest: <mailto:[EMAIL PROTECTED]>
List-Unsubscribe: <mailto:[EMAIL PROTECTED]>
I made the changes you suggested, but with no luck. I was still using the
OCI driver, so I also tried the thin driver. But no luck. Here is a dump
of my log file with some print statements and tracing of the datasource
enabled.
The code basically sees if a Product exists, then either UPDATES or INSERTS
it,
then it finds the highest numbered DocumentVersion and creates a new one
with
the highest number + 1. Then DocumentParts are created under the new
version.
DocumentLoader is a session bean, all of the others are entity beans.
What is distrubing to me is that all of my stuff seems to use the same
connection
oracle.jdbc.xa.client.OracleXAConnection@238f4 but I get many different
oracle.jdbc.xa.client.OracleXAResources. Should'nt I be getting the
same Resource consistently. It's almost like everything is it's own
distributed
transaction.
Thanks
Dave
[Default] jBoss 2.0 FINAL Started
[EmbeddedTomcat] path="/staff" :Controller: init
[ddc/Product] ProductEJB.ejbFindByPrimaryKey() getting connection
[ddc/Product] getConnection() getting from datasource
[StaffingDB] Resource 'oracle.jdbc.xa.client.OracleXAResource@472243'
enlisted for 'oracle.jdbc.xa.client.OracleXAConnection@238f4'.
[StaffingDB] Pool StaffingDB [1/25/500] gave out pooled object:
oracle.jdbc.xa.client.OracleXAConnection@238f4
[ddc/Product] ProductEJB.ejbFindByPrimaryKey() got connection
[ddc/Product] ProductEJB.ejbFindByPrimaryKey() freeing connection
[StaffingDB] Pool StaffingDB [0/25/500] returned object
oracle.jdbc.xa.client.OracleXAConnection@238f4 to the pool.
[ddc/Product] ProductEJB.ejbCreate()
[ddc/Product] getConnection() getting from datasource
[StaffingDB] Resource 'oracle.jdbc.xa.client.OracleXAResource@5c9766'
enlisted for 'oracle.jdbc.xa.client.OracleXAConnection@238f4'.
[StaffingDB] Pool StaffingDB [1/25/500] gave out pooled object:
oracle.jdbc.xa.client.OracleXAConnection@238f4
[ddc/Product] ProductEJB.ejbCreate() connection obtained
[ddc/Product] ProductEJB.ejbCreate() releasing connection
[StaffingDB] Pool StaffingDB [0/25/500] returned object
oracle.jdbc.xa.client.OracleXAConnection@238f4 to the pool.
[ddc/DocumentVersion] DocumentVersionEJB.findLatestVersion getting
connection
[ddc/DocumentVersion] getConnection() getting from datasource
[StaffingDB] Resource 'oracle.jdbc.xa.client.OracleXAResource@58ca48'
enlisted for 'oracle.jdbc.xa.client.OracleXAConnection@238f4'.
[StaffingDB] Pool StaffingDB [1/25/500] gave out pooled object:
oracle.jdbc.xa.client.OracleXAConnection@238f4
[ddc/DocumentVersion] DocumentVersionEJB.findLatestVersion got connection
[ddc/DocumentVersion] DocumentVersionEJB.findLatestVersion dropping
connection
[StaffingDB] Pool StaffingDB [0/25/500] returned object
oracle.jdbc.xa.client.OracleXAConnection@238f4 to the pool.
[ddc/DocumentVersion] DocumentVersionEJB.ejbCreate() getting connection
[ddc/DocumentVersion] getConnection() getting from datasource
[StaffingDB] Resource 'oracle.jdbc.xa.client.OracleXAResource@46b6db'
enlisted for 'oracle.jdbc.xa.client.OracleXAConnection@238f4'.
[StaffingDB] Pool StaffingDB [1/25/500] gave out pooled object:
oracle.jdbc.xa.client.OracleXAConnection@238f4
[ddc/DocumentVersion] DocumentVersionEJB.ejbCreate() got connection
[ddc/DocumentVersion] DocumentVersionEJB.ejbCreate() first INSERT
[ddc/DocumentVersion] DocumentVersionEJB.ejbCreate() dropping connection
[StaffingDB] Pool StaffingDB [0/25/500] returned object
oracle.jdbc.xa.client.OracleXAConnection@238f4 to the pool.
[ddc/DocumentLoader] Failed to create version ORA-02049: timeout:
distributed transaction waiting for lock
[ddc/DocumentPart] DocumentPartEJB.ejbCreate() getting connection
[ddc/DocumentPart] getConnection() getting from datasource
[ddc/DocumentPart] javax.transaction.RollbackException: Already marked for
rollback
[ddc/DocumentPart] at
org.jboss.tm.TxCapsule.enlistResource(TxCapsule.java:543)
[ddc/DocumentPart] at
org.jboss.tm.TransactionImpl.enlistResource(TransactionImpl.java:114)
[ddc/DocumentPart] at
org.jboss.minerva.factories.XAConnectionFactory.prepareObject(XAConnectionFa
ctory.java:254)
[ddc/DocumentPart] at
org.jboss.minerva.pools.ObjectPool.getObject(ObjectPool.java:539)
[ddc/DocumentPart] at
org.jboss.minerva.datasource.XAPoolDataSource.getConnection(XAPoolDataSource
.java:169)
[ddc/DocumentPart] at
mil.army.atsc.atia.ddc.ejb.DocumentPartEJB.getConnection(DocumentPartEJB.jav
a:755)
[ddc/DocumentPart] at
mil.army.atsc.atia.ddc.ejb.DocumentPartEJB.ejbCreate(DocumentPartEJB.java:68
)
[ddc/DocumentPart] at java.lang.reflect.Method.invoke(Native Method)
[ddc/DocumentPart] at
org.jboss.ejb.plugins.BMPPersistenceManager.createEntity(BMPPersistenceManag
er.java:120)
[ddc/DocumentPart] at
org.jboss.ejb.EntityContainer.createHome(EntityContainer.java:441)
[ddc/DocumentPart] at java.lang.reflect.Method.invoke(Native Method)
[ddc/DocumentPart] at
org.jboss.ejb.EntityContainer$ContainerInterceptor.invokeHome(EntityContaine
r.java:639)
[ddc/DocumentPart] at
org.jboss.ejb.plugins.EntitySynchronizationInterceptor.invokeHome(EntitySync
hronizationInterceptor.java:160)
[ddc/DocumentPart] at
org.jboss.ejb.plugins.EntityInstanceInterceptor.invokeHome(EntityInstanceInt
erceptor.java:86)
[ddc/DocumentPart] at
org.jboss.ejb.plugins.TxInterceptorCMT.invokeNext(TxInterceptorCMT.java:135)
[ddc/DocumentPart] at
org.jboss.ejb.plugins.TxInterceptorCMT.runWithTransactions(TxInterceptorCMT.
java:263)
[ddc/DocumentPart] at
org.jboss.ejb.plugins.TxInterceptorCMT.invokeHome(TxInterceptorCMT.java:86)
[ddc/DocumentPart] at
org.jboss.ejb.plugins.SecurityInterceptor.invokeHome(SecurityInterceptor.jav
a:126)
[ddc/DocumentPart] at
org.jboss.ejb.plugins.LogInterceptor.invokeHome(LogInterceptor.java:106)
[ddc/DocumentPar
_________________________________________________________________________
Get Your Private, Free E-mail from MSN Hotmail at http://www.hotmail.com.
--
--------------------------------------------------------------
To subscribe: [EMAIL PROTECTED]
To unsubscribe: [EMAIL PROTECTED]
List Help?: [EMAIL PROTECTED]