Wednesday 6 May 2009

5-How to Develop Container-Managed-Persistence Entity Beans

MySQL DDL, WLST Data source definition commands, WebLogic system config.xml files.

SCRIPT MySQL DDL for the orders table in the ‘testars’ database
create table orders (order_id varchar(64),
student_id varchar(64),
order_date Date,
status varchar(64),
amount DOUBLE PRECISION(12,2));

SCRIPT WLST Data Source definition commands
edit()
# Change these names as necessary
dsname="myJDBCDataSource"
server="DefaultServer"
cd("Servers/"+server)
target=cmo
cd("../..")
startEdit()
# start creation
print 'Creating JDBCSystemResource with name '+dsname
jdbcSR = create(dsname,"JDBCSystemResource")
theJDBCResource = jdbcSR.getJDBCResource()
theJDBCResource.setName("myJDBCDataSource")

connectionPoolParams = theJDBCResource.getJDBCConnectionPoolParams()
connectionPoolParams.setConnectionReserveTimeoutSeconds(25)
connectionPoolParams.setMaxCapacity(100)
connectionPoolParams.setTestTableName("SYSTABLES")
dsParams = theJDBCResource.getJDBCDataSourceParams()
dsParams.addJNDIName("styejbDB")

driverParams = theJDBCResource.getJDBCDriverParams()
driverParams.setUrl("jdbc:mysql://localhost:3306/testars")
driverParams.setDriverName("com.mysql.jdbc.Driver")

# driverParams.setUrl("jdbc:oracle:thin:@my-oracle-server:my-oracle-server-port:my-oracle-sid")
# driverParams.setDriverName("oracle.jdbc.driver.OracleDriver")
driverParams.setPassword("3391309")
# driverParams.setLoginDelaySeconds(60)
driverProperties = driverParams.getProperties()
proper0 = driverProperties.createProperty("user")
#proper.setName("user")
proper0.setValue("root")
proper1 = driverProperties.createProperty("DatabaseName")
#proper1.setName("DatabaseName")
proper1.setValue("jdbc:mysql://localhost:3306/testars")
jdbcSR.addTarget(target)
save()
activate(block="true")
print 'Done configuring the data source'

FILE WebLogic Default Server config file at C:\oracle\Middleware\jdeveloper\system\system11.1.1.0.31.51.88\DefaultDomain\config
The above script places it at the very bottom otomatically as:

<jdbc-system-resource>
<name>myJDBCDataSource</name>
<target>DefaultServer</target>
<descriptor-file-name>jdbc/myJDBCDataSource-9572-jdbc.xml</descriptor-file-name>
</jdbc-system-resource>
</domain>

And creates the related XXX-jdbc.xml file at
C:\oracle\Middleware\jdeveloper\system\system11.1.1.0.31.51.88\DefaultDomain\config\jdbc

FILE myJDBCDataSource-9572-jdbc.xml
<?xml version='1.0' encoding='UTF-8'?>
<jdbc-data-source xmlns="http://www.bea.com/ns/weblogic/jdbc-data-source" xmlns:sec="http://www.bea.com/ns/weblogic/90/security" xmlns:wls="http://www.bea.com/ns/weblogic/90/security/wls" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.bea.com/ns/weblogic/jdbc-data-source http://www.bea.com/ns/weblogic/jdbc-data-source/1.0/jdbc-data-source.xsd">
<name>myJDBCDataSource</name>
<jdbc-driver-params>
<url>jdbc:mysql://localhost:3306/testars</url>
<driver-name>com.mysql.jdbc.Driver</driver-name>
<properties>
<property>
<name>user</name>
<value>root</value>
</property>
<property>
<name>DatabaseName</name>
<value>jdbc:mysql://localhost:3306/testars</value>
</property>
</properties>
<password-encrypted>{3DES}K0c09YjvYiI=</password-encrypted>
</jdbc-driver-params>
<jdbc-connection-pool-params>
<max-capacity>100</max-capacity>
<connection-reserve-timeout-seconds>25</connection-reserve-timeout-seconds>
<test-table-name>SYSTABLES</test-table-name>
</jdbc-connection-pool-params>
<jdbc-data-source-params>
<jndi-name>styejbDB</jndi-name>
</jdbc-data-source-params>
</jdbc-data-source>