Welcome!

Weblogic Authors: Yeshim Deniz, Elizabeth White, Michael Meiner, Michael Bushong, Avi Rosenthal

Related Topics: Weblogic

Weblogic: Article

Considering MySQL? Read On... (Part I)

A powerful combination creates a strong architecture

  • Read Part 2 of this 2-part article

    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
    The development tool of choice is BEA WebLogic Workshop 8.1. I'll describe an archetypical J2EE architecture and explore the impact of the decision to use MySQL with J2EE technologies such as JDBC and JMS. Part 2 of this series will evaluate the impact of EJBs, the core component model of J2EE as well as the JTA. The article describes configuration and development changes, adjustments, and modifications.

    Architecture
    The sample application has a standard J2EE architecture consisting of a database tier, an application tier, and an interface tier as depicted in the Figure 1. The database, or back-end, tier consists of MySQL as the Relational DataBase Management System (RDBMS). The application tier is BEA WebLogic Server 8.1. The application server includes a JMS server and an EJB container. The JMS server hosts destinations such as a queue utilized by the sample application for asynchronous processing. The sample application consists of many EJBs that leverage container managed transaction demarcation (CMTD). Tables in the database are mapped to entity EJBs with container-managed persistence (CMP). The entity EJBs are fronted with a session EJB facade. There is a Message-Driven Bean (MDB) that listens to a queue and processes messages. Other applications, such as command-line applications, rich graphical user interface (GUI) applications, or Web applications, leverage the EJB components through the facade. They exchange data with the session facade using value objects (also known as data transfer objects). The value objects corresponding directly to the entity beans are automatically generated by WebLogic Workshop.

    Choosing the "Right" MySQL
    MySQL comes in various shapes and forms and has at least four different incarnations: MySQL Standard, MySQL Max, MySQL Pro, and MySQL Classic. MySQL Standard and MySQL Pro are identical except for the license. MySQL Standard is licensed under the GNU Public License (GPL), whereas MySQL Pro is a commercially licensed version of MySQL Standard. MySQL Max includes cutting-edge and experimental features and is not recommended for production use. MySQL Classic is available only under commercial license and excludes important features. For this application, support is required for critical features such as transactions and referential-integrity (i.e., foreign key) constraints. The choice of MySQL among its various incarnations is either MySQL Standard or MySQL Pro. Note: Any further reference in this article to MySQL implies usage of MySQL Standard. (More information about the different types of MySQL is available at www.mysql.com/products/mysql/index.html.)

    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:

    1. Download MySQL: www.mysql.com/downloads/mysql-4.0.html.
    2. Install MySQL with these instructions: www.mysql.com/doc/en/Installing.html.
    3. Specify additional options such as logging and table type.
    4. Start MySQL (e.g., using mysqld -- console).
    5. Verify connectivity to the server using mysql (e.g., mysql -p -u root). Note: Just press enter when prompted for a password if local on Windows)
    6. Create a database named semdb using create database semdb.
    7. Use the database semdb using semdb.
    8. Load schema using mysql command source and specifying the fully qualified path to sem.sql (e.g., source c:/MySQL_WLS/db/sem.sql). Note: Use forward slashes even on Windows.
    9. Using the grant.sql file available in the source code, grant privileges using source fully qualified path to grant.sql. Note: Use forward slashes even on Windows.
    Downloading the JDBC Driver
    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
    DbVisualizer ships with BEA WebLogic Platform 8.1. Launch DbVisualizer (e.g., Start Menu > BEA WebLogic Platform 8.1 > Other Development Tools > DbVisualizer on Windows) and add the drivers to DbVisualizer. Using the Connection/J MySQL JDBC driver, connect to MySQL instance (see the section, "Connection to MySQL Database Instance)

    Adding JDBC Drivers to DbVisualizer
    The following steps describe adding the drivers to DbVisualizer.

    1. Select Database Menu.
    2. Select DriverManager Menu item.
    3. Select Add new driver location toolbar menu item.
    4. Select mysql-connector-java-3.0.9-stable-bin.jar.
    5. Close.
    Connection to MySQL Database Instance
    The following steps describe connecting to the MySQL database instance.
    1. Select Database Menu.
    2. Select Add Database Connection Menu Item.
    3. Specify Connection Alias (e.g., sem).
    4. Choose JDBC Driver as com.mysql.jdbc.Driver from the dropdown list.
    5. Choose Database URL as jdbc:mysql://<host>/<database> from the drop-down list.
    6. Change <host> (e.g. localhost).
    7. Change <database> to semdb.
    8. Specify Userid as sem.
    9. Specify Password as sem.
    10. Select Connect.
    WebLogic Domain Configuration Changes
    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
    The following steps describe adding the Connector/J MySQL JDBC driver to the CLASSPATH.

    1. Edit .../SEMDomain/_cfgwiz_donotdelete/startscript.xml.
    2. Add mysql-connector-java-3.0.9-stable-bin.jar to the CLASSPATH. Refer tothe startscript.xml file in the source code.
    3. Add system property Dweblogic.ejb20.cmp.rdbms.codegen.verbose=true as JAVA_OPTIONS. Refer to the startscript.xml file in the source code.
    4. Run the Configuration Wizard to extend the SEMDomain.
    5. Select DefaultWebApp as the extension.
    6. Finish the Configuration Wizard.
    The following section on enabling more WebLogic Server logging is optional, but highly recommended.

    WebLogic Logging
    By default, BEA WebLogic Server performs only limited logging. During development, logging and observing of more information is very useful. For the SEMDomain, change the logging level to Info.

    Changing the Logging Level
    The following steps describe changing the BEA WebLogic Server logging configuration.

    1. Make sure BEA WebLogic Server is running.
    2. Launch the WebLogic Server Console.
    3. Log into the Console.
    4. Select Servers/cgServer.
    5. Select Logging tab.
    6. Check Debug to Stdout checkbox.
    7. Select Stdout Severity Threshold as Info from the drop-down list.
    JMS Domain Configuration Changes
    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
    The following steps describe configuring the file store:

    1. Create a directory where the file store is going to be placed.
    2. Make sure BEA WebLogic Server is running.
    3. Launch the WebLogic Server Console.
    4. Log into the console.
    5. Select Services/JMS/Stores in the left navigation pane.
    6. Select Configure a new JMS File Store.
    7. Specify Name (e.g., cgJMSFileStore).
    8. Specify Directory that was created in the earlier step.
    9. Select Services/JMS/Servers/cgJMSServer.
    10. Change the Persistence Store (to, for example, cgJMSFileStore) by selecting it from the drop-down list.
    The bottom line is that MySQL cannot be used as a persistence store for JMS. Using a file persistence store is a viable alternative. Keep this in mind when creating other JMS servers.

    In order to follow the source code example, complete an additional JMS configuration for the sample application before proceeding further:

    • Set up a JMS file store named semJMSFileStore.
    • Set up a JMS connection factory named semJMSConnectionFactory with jms/semJMSConnectionFactory as the JNDI name.
    • Set up a JMS server named semJMSServer with semJMSFileStore as the persistent store.
    • Set up a distributed destination named PersonQueue with jms/PersonQueue as the JNDI name.
    • Deploy the PersonQueue on the semJMSServer.
    JDBC Domain Configuration Changes
    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:

  • Connection pool: Refer to "Configuring the Connection Pool" for detailed instructions.
  • Datasource: Use jdbc/semJDBCDataSource as the JNDI name. Refer to "Configuring the Datasource" for detailed instructions.

    Configuring the Connection Pool
    The following steps describe configuration of the connection pool.

    1. Make sure BEA WebLogic Server is running.
    2. Launch the WebLogic Server Console.
    3. Log into the console.
    4. Select Services/JDBC/Connection Pools.
    5. Select Configure a New JDBC Connection Pool.
    6. Select MySQL from the Database Type drop down list.
    7. Select MySQL's Driver (Type 4) Version: Any from Database Driver.
    8. Specify Name (e.g., semJDBCConnectionPool).
    9. Specify Database Name (e.g., semdb).
    10. Specify Host Name (e.g., localhost).
    11. Specify Username (e.g., sem).
    12. Specify Password (e.g., sem).
    13. Test the driver configuration.
    14. Create and deploy.
    Configuring the Datasource
    The following steps describe configuration of the datasource:
    1. Select Services/JDBC/Data Sources.
    2. Select Configure a New JDBC Data Source.
    3. Specify Name (e.g. semJDBCDataSource).
    4. Specify JNDI Name (e.g., jdbc/semJDBCDataSource).
    5. Select Continue.
    6. Specify Pool Name (e.g., semJDBCConnectionPool).
    7. Target the datasource by clicking on Create.
    Conclusion
    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

  • To discuss the article and ask questions: http://groups.yahoo.com/group/bartssandbox. Free membership enrollment is required.
  • Main MySQL Web site: www.mysql.com
  • Starting point for MySQL documentation: www.mysql.com/documentation/index.html
  • www.oreillynet.com/lpt/wlg/3946
  • DuBois, Paul (2003). MySQL: The Definitive Guide to Using, Programming, and Administering MySQL 4 databases. Sams. An excellent reference. (www.bookpool.com/.x/d4jha9om4m/sm/0735712123).
  • J2EE patterns: http://java.sun.com/blueprints/patterns/index.html). For the Session Facade Pattern used in the sample application refer to http://java.sun.com/blueprints/corej2eepatterns/Patterns/SessionFacade.html and http://java.sun.com/blueprints/patterns/SessionFacade.html. For the Value Object Pattern used in the sample application refer to http://java.sun.com/blueprints/corej2eepatterns/Patterns/TransferObject.html and http://java.sun.com/blueprints/patterns/TransferObject.html
  • More Stories By Prakash Malani

    Prakash Malani has extensive experience in architecting, designing, and developing object-oriented software and has done software development in many application domains such as entertainment, retail, medicine, communications, and interactive television.He practices and mentors leading technologies such as J2EE, UML, and XML. Prakash has published various articles in industry- leading publications.

    Comments (0)

    Share your thoughts on this story.

    Add your comment
    You must be signed in to add a comment. Sign-in | Register

    In accordance with our Comment Policy, we encourage comments that are on topic, relevant and to-the-point. We will remove comments that include profanity, personal attacks, racial slurs, threats of violence, or other inappropriate material that violates our Terms and Conditions, and will block users who make repeated violations. We ask all readers to expect diversity of opinion and to treat one another with dignity and respect.


    @ThingsExpo Stories
    The 22nd International Cloud Expo | 1st DXWorld Expo has announced that its Call for Papers is open. Cloud Expo | DXWorld Expo, to be held June 5-7, 2018, at the Javits Center in New York, NY, brings together Cloud Computing, Digital Transformation, Big Data, Internet of Things, DevOps, Machine Learning and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding busin...
    Smart cities have the potential to change our lives at so many levels for citizens: less pollution, reduced parking obstacles, better health, education and more energy savings. Real-time data streaming and the Internet of Things (IoT) possess the power to turn this vision into a reality. However, most organizations today are building their data infrastructure to focus solely on addressing immediate business needs vs. a platform capable of quickly adapting emerging technologies to address future ...
    Nordstrom is transforming the way that they do business and the cloud is the key to enabling speed and hyper personalized customer experiences. In his session at 21st Cloud Expo, Ken Schow, VP of Engineering at Nordstrom, discussed some of the key learnings and common pitfalls of large enterprises moving to the cloud. This includes strategies around choosing a cloud provider(s), architecture, and lessons learned. In addition, he covered some of the best practices for structured team migration an...
    No hype cycles or predictions of a gazillion things here. IoT is here. You get it. You know your business and have great ideas for a business transformation strategy. What comes next? Time to make it happen. In his session at @ThingsExpo, Jay Mason, an Associate Partner of Analytics, IoT & Cybersecurity at M&S Consulting, presented a step-by-step plan to develop your technology implementation strategy. He also discussed the evaluation of communication standards and IoT messaging protocols, data...
    With tough new regulations coming to Europe on data privacy in May 2018, Calligo will explain why in reality the effect is global and transforms how you consider critical data. EU GDPR fundamentally rewrites the rules for cloud, Big Data and IoT. In his session at 21st Cloud Expo, Adam Ryan, Vice President and General Manager EMEA at Calligo, examined the regulations and provided insight on how it affects technology, challenges the established rules and will usher in new levels of diligence arou...
    In his Opening Keynote at 21st Cloud Expo, John Considine, General Manager of IBM Cloud Infrastructure, led attendees through the exciting evolution of the cloud. He looked at this major disruption from the perspective of technology, business models, and what this means for enterprises of all sizes. John Considine is General Manager of Cloud Infrastructure Services at IBM. In that role he is responsible for leading IBM’s public cloud infrastructure including strategy, development, and offering m...
    In his session at 21st Cloud Expo, Raju Shreewastava, founder of Big Data Trunk, provided a fun and simple way to introduce Machine Leaning to anyone and everyone. He solved a machine learning problem and demonstrated an easy way to be able to do machine learning without even coding. Raju Shreewastava is the founder of Big Data Trunk (www.BigDataTrunk.com), a Big Data Training and consulting firm with offices in the United States. He previously led the data warehouse/business intelligence and B...
    Recently, REAN Cloud built a digital concierge for a North Carolina hospital that had observed that most patient call button questions were repetitive. In addition, the paper-based process used to measure patient health metrics was laborious, not in real-time and sometimes error-prone. In their session at 21st Cloud Expo, Sean Finnerty, Executive Director, Practice Lead, Health Care & Life Science at REAN Cloud, and Dr. S.P.T. Krishnan, Principal Architect at REAN Cloud, discussed how they built...
    22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
    22nd International Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, and co-located with the 1st DXWorld Expo will feature technical sessions from a rock star conference faculty and the leading industry players in the world. Cloud computing is now being embraced by a majority of enterprises of all sizes. Yesterday's debate about public vs. private has transformed into the reality of hybrid cloud: a recent survey shows that 74% of enterprises have a hybrid cloud ...
    DevOps at Cloud Expo – being held June 5-7, 2018, at the Javits Center in New York, NY – announces that its Call for Papers is open. Born out of proven success in agile development, cloud computing, and process automation, DevOps is a macro trend you cannot afford to miss. From showcase success stories from early adopters and web-scale businesses, DevOps is expanding to organizations of all sizes, including the world's largest enterprises – and delivering real results. Among the proven benefits,...
    @DevOpsSummit at Cloud Expo, taking place June 5-7, 2018, at the Javits Center in New York City, NY, is co-located with 22nd Cloud Expo | 1st DXWorld Expo and will feature technical sessions from a rock star conference faculty and the leading industry players in the world. The widespread success of cloud computing is driving the DevOps revolution in enterprise IT. Now as never before, development teams must communicate and collaborate in a dynamic, 24/7/365 environment. There is no time to wait...
    Cloud Expo | DXWorld Expo have announced the conference tracks for Cloud Expo 2018. Cloud Expo will be held June 5-7, 2018, at the Javits Center in New York City, and November 6-8, 2018, at the Santa Clara Convention Center, Santa Clara, CA. Digital Transformation (DX) is a major focus with the introduction of DX Expo within the program. Successful transformation requires a laser focus on being data-driven and on using all the tools available that enable transformation if they plan to survive ov...
    SYS-CON Events announced today that T-Mobile exhibited at SYS-CON's 20th International Cloud Expo®, which will take place on June 6-8, 2017, at the Javits Center in New York City, NY. As America's Un-carrier, T-Mobile US, Inc., is redefining the way consumers and businesses buy wireless services through leading product and service innovation. The Company's advanced nationwide 4G LTE network delivers outstanding wireless experiences to 67.4 million customers who are unwilling to compromise on qua...
    SYS-CON Events announced today that Cedexis will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 - Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Cedexis is the leader in data-driven enterprise global traffic management. Whether optimizing traffic through datacenters, clouds, CDNs, or any combination, Cedexis solutions drive quality and cost-effectiveness. For more information, please visit https://www.cedexis.com.
    SYS-CON Events announced today that Google Cloud has been named “Keynote Sponsor” of SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Companies come to Google Cloud to transform their businesses. Google Cloud’s comprehensive portfolio – from infrastructure to apps to devices – helps enterprises innovate faster, scale smarter, stay secure, and do more with data than ever before.
    SYS-CON Events announced today that Vivint to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. As a leading smart home technology provider, Vivint offers home security, energy management, home automation, local cloud storage, and high-speed Internet solutions to more than one million customers throughout the United States and Canada. The end result is a smart home solution that sav...
    SYS-CON Events announced today that Opsani will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Opsani is the leading provider of deployment automation systems for running and scaling traditional enterprise applications on container infrastructure.
    SYS-CON Events announced today that Nirmata will exhibit at SYS-CON's 21st International Cloud Expo®, which will take place on Oct 31 – Nov 2, 2017, at the Santa Clara Convention Center in Santa Clara, CA. Nirmata provides a comprehensive platform, for deploying, operating, and optimizing containerized applications across clouds, powered by Kubernetes. Nirmata empowers enterprise DevOps teams by fully automating the complex operations and management of application containers and its underlying ...
    SYS-CON Events announced today that Opsani to exhibit at SYS-CON's 21st Cloud Expo, which will take place on October 31 through November 2nd 2017 at the Santa Clara Convention Center in Santa Clara, California. Opsani is creating the next generation of automated continuous deployment tools designed specifically for containers. How is continuous deployment different from continuous integration and continuous delivery? CI/CD tools provide build and test. Continuous Deployment is the means by which...