The instructions in the following sections describe deploying a BC4J application
as an EJB Session Bean. The information in this topic is also available from
http://otn.oracle.com/products/jdev/howtos/appservers/deploy_bc4j_to_jboss.html.
Note:Before you start a BC4J project to be deployed as an EJB session to JBoss, you must select a connection type and the corresponding SQL dialect, type maps or domains. For instructions, see Understanding Connections, SQL Dialect, Type Maps, and Domains.
To create a data source for the Oracle JDBC driver, edit the jboss.jcml
file which is located in the JBoss/conf/<configuration> directory.
For example:
C:\<JBoss_install>\jboss\conf\catalina
There is one modification, and one addition to make to this file.
<mbean code="org.jboss.jdbc.JdbcProvider" name="DefaultDomain:service=JdbcProvider">
<attribute name="Drivers">org.hsqldb.jdbcDriver</attribute>
</mbean>
|
With this entry:
<mbean code="org.jboss.jdbc.JdbcProvider" name="DefaultDomain:service=JdbcProvider">
<attribute name="Drivers">oracle.jdbc.driver.OracleDriver,org.hsqldb.jdbcDriver</attribute>
</mbean>
|
</mbean> that
was just modified. Change the properties of the URL, JDBCUser,
and Password to match your database configuration.
<mbean code="org.jboss.jdbc.XADataSourceLoader"
name="DefaultDomain:service=XADataSource,name=OracleDS">
<attribute name="PoolName">OracleDS</attribute>
<attribute name="DataSourceClass">
org.jboss.pool.jdbc.xa.wrapper.XADataSourceImpl
</attribute>
<attribute name="URL">
jdbc:oracle:thin:@rcleveng-sun:1521:RCLEVENG
</attribute>
<attribute name="JDBCUser">scott</attribute>
<attribute name="Password">tiger</attribute>
<attribute name="MinSize">0</attribute>
<attribute name="MaxSize">10</attribute>
</mbean>
|
The first modification allows the Oracle JDBC driver to be loaded and thus
registered with the JDBC DriverManager class.
The second modification creates a JDBC data source bound to the JNDI name of
java:/OracleDS.
The JDeveloper deployment profile wizards create all the necessary code to deploy business components as a J2EE EJB JAR module to the target server. This section covers creating a deployment profile for the BC4J application module for an Oracle Application Server deployment which will be copied to JBoss.
<YourApplicationModule>9iAS
configuration.java:/OracleDSTo test the business components, create a new JSP application which will use them.
<JBoss_install>\deploy
directory. For example: C:\<JBoss_install>\jboss\deploy.You now have a fully functional BC4J JSP application deployed as a web module. You may now invoke the application in your web browser by entering the application URL similar to the following:
http://localhost:8080/<context root>
where <context root> is the J2EE context root for
your project containing the BC4J JSP application. For example, Workspace1-Project1-context-root/.
Apart from the JSP client, a standalone Java application can access your BC4J application module which is deployed as an EJB Session Bean.
We will create a new class to talk to the BC4J application module deployed
as a session bean. This will be a standalone Java application which will lookup
the session bean and then use an ApplicationModuleProxy class to
obtain a reference to the application module.
import oracle.jbo.*; import javax.naming.*; import java.util.*; import mypackage2.common.ejb.beanmanaged.Mypackage2ModuleHome; import oracle.jbo.client.remote.ejb.ApplicationModuleProxy; |
public static void main(String[] args)
{
try
{
Hashtable env = new Hashtable();
env.put(Context.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
env.put(Context.PROVIDER_URL, "localhost");
env.put(Context.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces" );
Context ctx = new InitialContext(env);
Mypackage2ModuleHome beanHome = (Mypackage2ModuleHome )ctx.lookup("mypackage2.Mypackage2Module");
// Create the proxy. If you have exported methods then you can cast it to your common am interface.
ApplicationModule am = ApplicationModuleProxy.create(beanHome, env);
//
// Note: Change this connect string to the connect string you use to connect to your database
//
am.getTransaction().connectToDataSource( null, "java:/OracleDS", null, null, false );
System.out.println( am.getClass() );
String[] voNames = am.getViewObjectNames();
ViewObject vo = am.findViewObject("DeptView");
Row row;
while ( ( row = vo.next() ) != null )
{
int numAttrs = row.getAttributeCount();
for ( int i=0; i < numAttrs; i++ )
{
System.out.println( "Name= " + vo.getAttributeDef(i).getName() +
" Value= " + row.getAttribute(i) );
}
System.out.println("");
}
am.getTransaction().disconnect();
}
catch ( Exception ex )
{
ex.printStackTrace();
}
}
|
DEPT database table are displayed
in the Log window of your application. Note: You may need to choose View | Log Window from the main menu if the message log is not already visible.
http://www.jboss.org/online-manual/HTML/index.htmlhttp://www.jboss.org