This chapter is example driven. In it, you will work with a crime portal application that stores information about imaginary criminal organizations. The data model you will work with is shown in Figure 11.1. Figure 11.1. The crime portal example classes.The source code for the crime portal is available in the src/main/org/jboss/cmp2 directory of the example code. To build the example code, you run Ant, as shown here: [examples]$ ant -Dchap=cmp2 config This command builds and deploys the application to the JBoss server. When you start your JBoss server, or if it is already running, you should see the following deployment messages: 15:46:36,704 INFO [OrganizationBean$Proxy] Creating organization Yakuza, Japanese Gangsters 15:46:36,790 INFO [OrganizationBean$Proxy] Creating organization Mafia, Italian Bad Guys 15:46:36,797 INFO [OrganizationBean$Proxy] Creating organization Triads, Kung Fu Movie Extras 15:46:36,877 INFO [GangsterBean$Proxy] Creating Gangster 0 'Bodyguard' Yojimbo 15:46:37,003 INFO [GangsterBean$Proxy] Creating Gangster 1 'Master' Takeshi 15:46:37,021 INFO [GangsterBean$Proxy] Creating Gangster 2 'Four finger' Yuriko 15:46:37,040 INFO [GangsterBean$Proxy] Creating Gangster 3 'Killer' Chow 15:46:37,106 INFO [GangsterBean$Proxy] Creating Gangster 4 'Lightning' Shogi 15:46:37,118 INFO [GangsterBean$Proxy] Creating Gangster 5 'Pizza-Face' Valentino 15:46:37,133 INFO [GangsterBean$Proxy] Creating Gangster 6 'Toothless' Toni 15:46:37,208 INFO [GangsterBean$Proxy] Creating Gangster 7 'Godfather' Corleone 15:46:37,238 INFO [JobBean$Proxy] Creating Job 10th Street Jeweler Heist 15:46:37,247 INFO [JobBean$Proxy] Creating Job The Great Train Robbery 15:46:37,257 INFO [JobBean$Proxy] Creating Job Cheap Liquor Snatch and Grab Because the beans in the examples are configured to have their tables removed on undeployment, any time you restart the JBoss server, you need to rerun the config target to reload the example data and redeploy the application. Enabling CMP Debug LoggingTo get meaningful feedback from the example code, you will want to increase the log level of the CMP subsystem before running the test. To enable debug logging, you need to add the following category to your log4j.xml file: <category name="org.jboss.ejb.plugins.cmp"> <priority value="DEBUG"/> </category> In addition, you need to decrease the threshold on the CONSOLE appender to allow debug-level messages to be logged to the console. You also need to apply the following changes to the log4j.xml file: <appender name="CONSOLE" > <errorHandler /> <param name="Target" value="System.out"/> <param name="Threshold" value="DEBUG" /> <layout > <!-- The default pattern: Date Priority [Category] Message\n --> <param name="ConversionPattern" value="%d{ABSOLUTE} %-5p [%c{1}] %m%n"/> </layout> </appender> To see the full workings of the CMP engine, you need to enable the custom TRACE level priority on the org.jboss.ejb.plugins.cmp category, as shown here: <category name="org.jboss.ejb.plugins.cmp"> <priority value="TRACE" /> </category> Running the ExamplesThe first test target illustrates a number of the customization features that are discussed in this chapter. To run these tests, you execute the following Ant target: [examples]$ ant -Dchap=cmp2 -Dex=test run-example The output log will show the following output:
These tests, which are mentioned throughout this chapter, exercise various finders, selectors, and object-to-table mapping issues. The other main target runs a set of tests to demonstrate the optimized loading configurations presented in the section "Optimized Loading," later in this chapter. When the logging is set up correctly, the read-ahead tests will display useful information about the queries performed. Note that you do not have to restart the JBoss server for it to recognize the changes to the log4j.xml file, but it may take a minute or so. Running the following shows the actual execution of the read-ahead client: [examples]$ ant -Dchap=cmp2 -Dex=readahead run-example When the read-ahead client is executed, all the SQL queries executed during the test are displayed in the JBoss server console. The important items of note when analyzing the output are the number of queries executed, the columns selected, and the number of rows loaded. The following shows the read-ahead none portion of the JBoss server console output from read-ahead:
We will revisit this example and explore the output when we discuss the settings for optimized loading later in this chapter. |