Thursday, June 23, 2011

Create JDBC resources using commands in Glassfish 2.0

Display the list of JDBC connection pool within the specified domain

/opt/JCAPS62/appserver/bin/asadmin list-jdbc-connection-pools --user Administrator --passwordfile /home/midw/jcaps/SIT-pwd.txt --host un228sesb1 --port 18348


Display the list of JDBC resources within the specified domain

/opt/JCAPS62/appserver/bin/asadmin list-jdbc-resources --user Administrator --passwordfile /home/midw/jcaps/SIT-pwd.txt --host un228sesb1 --port 18348


Delete the specified JDBC resource within the specified domain

/opt/JCAPS62/appserver/bin/asadmin delete-jdbc-resource --user Administrator --passwordfile /home/midw/jcaps/SIT-pwd.txt --host un228sesb1 --port 18348 jdbc/esbfoundation



Delete the specified JDBC connection pool within the specified domain

/opt/JCAPS62/appserver/bin/asadmin delete-jdbc-connection-pool --user Administrator --passwordfile /home/midw/jcaps/SIT-pwd.txt --host un228sesb1 --port 18348 ESBFoundationDBPool



Create the JDBC connection pool within the specified domain

/opt/JCAPS62/appserver/bin/asadmin create-jdbc-connection-pool --restype javax.sql.ConnectionPoolDataSource --datasourceclassname oracle.jdbc.pool.OracleConnectionPoolDataSource --user Administrator --passwordfile /home/midw/jcaps/SIT-pwd.txt --host un228sesb1 --port 18348 --validationtable DUAL --property DataSourceName=OracleConnectionPoolDataSource:NetworkProtocol=tcp:User=softrules:Password=softrules_sit:DatabaseName=softrules:ServerName=un128dora:port=1523:URL=jdbc\\:oracle\\:thin\\:@un128dora\\:1523\\:ESBRNSIT ESBFoundationDBPool


Create the JDBC resource within the specified domain

/opt/JCAPS62/appserver/bin/asadmin create-jdbc-resource --host un228sesb1 --port 18348 --user Administrator --passwordfile /home/midw/jcaps/SIT-pwd.txt --connectionpoolid ESBFoundationDBPool jdbc/esbfoundation

Wednesday, June 22, 2011

One tricky issue of creating Oracle trigger

I came across one tricky issue which puzzled me for a while when I was tring to create one trigger in Oracle.

The SQL statement is as the follow:

CREATE OR REPLACE
TRIGGER
prsd_nonidmp_req_ins_trigger
BEFORE INSERT
ON PROCESSED_NON_IDEMPOTENT_REQ
REFERENCING NEW AS NEW_ROW
FOR EACH ROW
BEGIN
SELECT processed_nonidmp_req_sequence.nextval INTO :NEW_ROW.ID FROM dual;
END;

When it is executed in Oracle SQL Developer there is no error and the trigger is created successfully.

But when it is executed from one Ant script the script always complain the error:

java.sql.SQLException: ORA-00900: invalid SQL statement.

The complain comes from the semicolon ; after dual. Ant thinks this as the end the SQL statement because when Ant processes the SQL statements bt default it uses the semicolon ; as the delimiter of the each SQL statement.

But in the above the statement which creates the trigger the semicolon is required after dual otherwise the trigger will be created with the compiler error.

Saturday, June 18, 2011

JTA Transaction attribute

The below diagrams show the meaning of different transaction attributes.
The client can be other EJBs or web-ties clients and etc.




NOT_SUPPORTED






REQUIRES_NEW







MANDATORY








SUPPORTS






NEVER






REQUIRED


















Thursday, June 16, 2011

What is BMT?

BMT stands for Bean Managed Transaction. It is one of the way EJB prvides for the transaction management. Another one is CMT - Container Managed Transaction.
Unlike CMT, which let the application server handles the most of transaction management issues, BMT gives the developers more control over the transaction management. such as the transaction demarcation, start, commit or rollback the transaction.

The bean that can use BMT must be a session bean or MDB.

Although it is BMT, the container actually still does the most hard work of transaction management for the bean which manage the transaction itself. The container creates the physical transaction for the bean. This transaction is injected into the bean as one instance of javax.transaction.UserTransaction. The bean uses this instance of UserTransaction to start, commit or rollback the transaction.

Unit Testing Good Practices

    Here are some points which, I think, can help you make good unit testing



  • Unit test should be simple logically. One unit test should test one functionality only.



  • Don't add the conditions in the unit testing.



  • Don't have multiple assertations.



  • Use the constant value in the assertation.



  • Give each unit test a meaningful name.



  • Whenever a bug is found add unit tests for it.



  • Make the unit tests automatic and add the unit testing into the build scripts.