|
|
YOUR FEEDBACK
SOA World Conference
Virtualization Conference $200 Savings Expire May 16, 2008... – Register Today!
SYS-CON.TV |
TOP LINKS YOU MUST CLICK ON Workshop
Considering MySQL? Read On... (Part I)
A powerful combination creates a strong architecture
By: Prakash Malani
Digg This!
MySQL is a small, fast, and efficient database. This article discusses leveraging MySQL as the database with BEA WebLogic Server 8.1. We will look at using MySQL as the database engine where the application is developed using BEA WebLogic Workshop 8.1 and deployed to BEA WebLogic Server 8.1. Using an archetypical Java 2 Enterprise Edition (J2EE) architecture, I will evaluate the impact of using MySQL from various aspects such as choosing the correct version of MySQL, setting up the server, and making development adjustments. The impact on development and deployment of bread-and-butter technologies such as Enterprise JavaBeans (EJBs), Java DataBase Connectivity (JDBC), Java Message Service (JMS), and the Java Transaction API (JTA) are evaluated. Various pitfalls are uncovered, logically approached, and methodically solved. The information presented here will not only enhance your understanding of the tools and technologies utilized, but also save you countless hours. Even readers who employ different database technologies will find the information and material practical and useful. Introduction Architecture Choosing the "Right" MySQL MySQL presents a number of choices for table types, each offering features that have their own pros and cons. The table types are ISAM, MyISAM, HEAP, MERGE, BDB, and InnoDB. Many factors determine the choice of a table type. These factors include, but are not limited to, performance, transactions, row-level locking, and crash recovery. However, the crucial features for the sample application are transactions and referential-integrity constraints. The InnoDB table type is the only one that meets the criteria. There are at least two ways to specify an InnoDB table type. One is to start the MySQL database server using --default-table-type=InnoDB. A table created with this option is of InnoDB type. (Note: If the default table type of InnoDB is not specified, the default table type is MyISAM.) The other way to specify InnoDB table type is to explicitly mention table type in the Data Description Language (DDL) of the create table script. (More information about MySQL table types is available at www.mysql.com/doc/en/Table_types.html.) A specific feature about MySQL and foreign constraints is that before the constraint can be created, an index on the column must already exist. For example, consider a one-to-one relationship between the tables Person and Buyer. Buyer has a foreign key to Person. Buyer has a column named Person_Id that is a foreign key to a column named Person_Id in the Person table. But before the foreign key can be established, an index must be created on column Person_Id in the Buyer table. Otherwise, the creation of a foreign key constraint fails. Refer to the sem.sql DDL file in the source code example (the source code is online at www.sys-con.com/ weblogic/sourcec.cfm). The default database privileges are different for different operating systems. For example, the default privileges on Windows give all local users full privileges without specifying a username or password. Therefore, an important validation is being able to connect to the MySQL database server engine. One way to connect is by using the client program that comes with MySQL. Another way is by using JDBC and a program like DbVisualizer. (See the section "Verify Connectivity using DbVisualizer". Information about default privileges is available at www.mysql.com/doc/en/Default_privileges.html.) The default case sensitivity of table names is based upon the operating system. For example, on Windows the table names are case insensitive. This is especially important if development is done on one platform but deployment is on another. To avoid such problems, one recommendation is to start the server by setting lower_case_table_names=1 variable. (More information on this variable is available at www.mysql.com/doc/en/Name_case_sensitivity.html.) Logging is enabled in MySQL by starting the MySQL database server using the --log option. Starting the MySQL server with logging enabled is highly recommended. Logging enables monitoring of Structured Query Language (SQL) statements executed by MySQL and can be a crucial tool in debugging and trouble-shooting issues. (More information on the MySQL log file is available at www.mysql.com/doc/en/Query_log.html.) The various options, such as default table type and logging, can be specified in a couple of ways. One is to pass the options in as command-line arguments to mysqld, the MySQL database engine executable. The other option is to specify these options in either a my.ini file or my.cnf option file. (More information on option files, including where to place them, is available at www.mysql.com/doc/en/Option_files.html.) Before we proceed further, complete the following steps:
JDBC requires a JDBC driver to connect to the database server. Connector/J is the JDBC driver for MySQL. Download and install Connector/J from www.mysql.com/downloads/api-jdbc-stable.html. The download contains a mysql-connector-java-3.0.9-stable-bin.jar file that contains the JDBC drivers. The following section on verifying the connectivity to MySQL server is optional, but highly recommended. Verify Connectivity Using DbVisualizer Adding JDBC Drivers to DbVisualizer
The following steps describe connecting to the MySQL database instance.
The BEA WebLogic Domain Configuration Wizard is used to create WebLogic Server domains. A particular type of domain is created based on functionality required. For this particular application, create a WebLogic Workshop domain. For example, create a WebLogic Workshop domain named SEMDomain. In order to use JDBC with BEA WebLogic Server, WebLogic Server needs to know about the JDBC driver. The JDBC driver needs to be in the CLASSPATH so that the server can locate the driver. For the SEMDomain, add the JDBC driver to the CLASSPATH so that the WebLogic Server can find the JDBC driver. Add JDBC Driver To The CLASSPATH
WebLogic Logging Changing the Logging Level
By default, a newly created domain like the SEMDomain uses PointBase as the database. A connection pool named cgPool connects to PointBase and a corresponding datasource named cgDataSource. The JMS server uses the cgDataSource as the persistence store. To use another database, such as Oracle, just change the configuration of the connection pool. The JMS server then uses Oracle as the persistence store. However, simply changing the connection pool to MySQL does not work, because when the WebLogic server boots-up, the JMS server complains that MySQL is not a supported database. A practical alternative is to change from using a database as the persistence store to using a file as the persistence store. WebLogic JMS supports a persistence file store. For the SEMDomain, change the persistence store to a file store. Changing the File Store
In order to follow the source code example, complete an additional JMS configuration for the sample application before proceeding further:
To utilize the JDBC API in the BEA WebLogic Server applications, create and deploy a connection pool and a datasource. First, create the connection pool, then create the datasource on top of the connection pool. Before proceeding further, complete the JDBC configuration for the sample application. Set up the following: Configuring the Connection Pool
The following steps describe configuration of the datasource:
This article discussed how to select the "right" version of MySQL and described various changes to the BEA WebLogic Domain Configuration to support key J2EE technologies such as JDBC and the Java Message Service. My next article will explore advanced topics such as EJBs and JTA. Understanding the impact of leveraging MySQL on technologies such as JDBC and JMS is crucial to successful project implementation. As illustrated here, MySQL, BEA WebLogic Workshop, and BEA WebLogic Server form a powerful combination to architect, design, and deploy real-world applications. I want to thank Steve Ditlinger, Roshni Malani, and Sarah Woo for reviewing this article and providing invaluable feedback. References LATEST ECLIPSE STORIES . . .
SUBSCRIBE TO THE WORLD'S MOST POWERFUL NEWSLETTERS SUBSCRIBE TO OUR RSS FEEDS & GET YOUR SYS-CON NEWS LIVE!
|
SYS-CON FEATURED WHITEPAPERS MOST READ THIS WEEK |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||