Wednesday, December 12, 2007

Good use of maven2 profiles

As my previous blog eluded to, I work on a project that has to support multiple databases. Having continuous integration servers is key to ensuring the quality of your software across multiple databases. We have successfully supported multiple database almost from the inception of the project. Starting with SQL Server (client mandated) and PostgreSql, we're now moving to Oracle.

Our CI environment will run tests against the multiple DBs as necessary. But how can I run integration tests against the different databases, easily, to ensure my code changes work on supported DBs?

Enter, maven profiles.

In my development environment, I have 3 profiles declared just for this project. The first is declared with 'activeByDefault' set to true. All of the generic or common settings for my project are found in this profile. Samples of the settings include my log4j file location, web application home directories (JBoss in our case), and overall maven settings (tests on/off).

The second and third profiles include information specific database information. One profile runs against SQL server and another against Oracle. Both of these profiles are activated by a specified environment variable on the maven command line.

How does this help with testing? If I have a DB instance for both SQL server & Oracle already set to go, I can simply run maven specifying my environment and have integration tests executed against the DB of my choice.

mvn -Denv=ENV1 install

vs

mvn -Denv=ENV2 install

It doesn't get much simpler than that!

Friday, December 7, 2007

JBoss: Configuring Data Sources

Configuring data sources in JBoss is quite simple but documentation may be a little difficult to find. Hopefully, this will demonstrate HOW simple it really is.

First, let's say that you have a web application (or some other application) that is expecting a data source to be present in JNDI. Maybe you have designed the application that needs to support multiple databases (kudos to you). Or maybe the application will be deployed into multiple environments and you do not want to force clients to configure the data source your way with your connection information. Whatever the reason, the data source configured within the container and handed to your application.

Next comes the real easy steps. To configure the data source in jboss, you need to perform 2 steps.

  1. Drop the JDBC driver jar file into the JBoss classpath. If you're running the 'default' server under JBoss, drop the jar file in $JBOSS_HOME/server/default/lib. JBoss will pick it when the server starts. Here are 2 links to JDBC driver jars:

    • PostgreSql
    • SQL Server
    • Oracle drivers are located under the Oracle installation directory. For 10g, look under C:\oracle\product\10.2.0\db_1\jdbc\lib.

  2. Create the data source XML file in the deploy directory. Once again, if you're running the 'default' server, create the XML file in $JBOSS_HOME/server/default/deploy. Upon startup, JBoss will load this DS file and configure the data source according to the XML file. Sample XML files for the different DBs are located in the $JBOSS_HOME/docs/examples/jca directory.

    • Sample Oracle DS

      <datasources>
      <local-tx-datasource>
      <jndi-name>COP-DS</jndi-name>
      <connection-url>jdbc:oracle:thin:@localhost:1521:ORCL</connection-url>
      <driver-class>oracle.jdbc.driver.OracleDriver</driver-class>
      <user-name>user</user-name>
      <password>password</password>
      <valid-connection-checker-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleValidConnectionChecker</valid-connection-checker-class-name>
      <exception-sorter-class-name>org.jboss.resource.adapter.jdbc.vendor.OracleExceptionSorter</exception-sorter-class-name>
      <min-pool-size>2</min-pool-size>
      <max-pool-size>5</max-pool-size>
      <metadata>
      <type-mapping>Oracle9i</type-mapping>
      </metadata>
      </local-tx-datasource>
      </datasources>


    • Sample SQL Server DS

      <datasources>
      <local-tx-datasource>
      <jndi-name>COP-DS</jndi-name>
      <connection-url>jdbc:jtds:sqlserver://localhost:1433/cop</connection-url>
      <driver-class>net.sourceforge.jtds.jdbc.Driver</driver-class>
      <user-name>affor</user-name>
      <password>password</password>
      <check-valid-connection-sql>select 1</check-valid-connection-sql>
      <min-pool-size>2</min-pool-size>
      <max-pool-size>10</max-pool-size>

      <metadata>
      <type-mapping>MS SQLSERVER2000</type-mapping>
      </metadata>
      </local-tx-datasource>
      </datasources>



BEWARE: The data source file must be name with '-ds.xml'. That's a dash and NOT an underscore. That little character cost me a few hours of troubleshooting only to be identified by another person.

For more detailed information or for other DB configurations, visit the JBoss wiki on data sources.

Saturday, September 29, 2007

ESB diagramming

Bear with me on my first blog!

On my current project, I recently found myself having to diagram the architecture of an ESB to demonstrate how applications, our own included, would connect to existing services as well as expose services for others to consume. The diagrams were for both developers and managers to understand how the ESB was going to be the 'glue' that integrates existing systems and provide the ability to make composite applications by integrating services in ways only previously imagined.

Typically, I use Visio to diagram and was going to start using UML but felt that it just was too low level. Class diagrams would be way too low level giving a view into one application. Deployment diagrams are great but I don't feel they are able to depict an SOA/ESB environment very well, from a high level, showing multiple services across disparate, distributed systems.

After googling, I found another architect's SOA blog regarding ESB & SOA Visio Stencils. After trying the EAI stencils, I registered for Sonic's ESB Icon and Diagram library stencils. Having read David Chappell's book Enterprise Service Bus several years ago, the blog & Visio stencils re-opened some old, locked brain cells reminding me of how well the book and diagrams depict an ESB architecture. The icons are a little big but can be reduced in size (or the entire picture reduced). If you work with ESBs, in an SOA, or plan to, this book should definitely be part of your personal library!

When needing to drill down into the details of an implementation on the ESB, other diagrams may be better suited (i.e. UML, EAI, BPMN, etc).