Beginning POJOs From Novice to Professional Brian Sam-Bodden
Contents About the Author Acknowledgments Introduction.XIII xv XVII CHAPTER1 Introduction The Java EE Market Case Study: The TechConf Website... Defining the Stakeholders The Business Problem General Application Requirements. Attendees Presenters 6 Sponsors 7 Administrators 7 Architectural Requirements 8 Open Issues and Assumptions 10 Assumptions 1 0 Open Issues u Design Road Map ^ Finding and Refining Candidate Domain Model Elements 13 Use Case Modeling 16 Modeling Best Practices 18 The Open Source Tools 1 8 Useful Open Source Resources 19 Summary 20 CHAPTER 2 Eclipse Installing Eclipse 24 Using Eclipse 25 23 vii
CONTENTS Creating an Eclipse Project 26 Creating a Java Interface 29 Creating a Java Class 32 Running a Java Class 34 Debugging a Java Class 35 Eclipse Plug-ins 36 Concurrent Versions System 37 Understanding CVS 37 CVS Concepts 37 CVS in Eclipse 38 Database Plug-ins 40 SQL Explorer 40 Web Development Plug-ins 46 Summary 46 SCHAPTER 3 Building with Ant 47 Introduction to Ant 48 Obtaining and Installing Ant 50 Ant's Command-Line Options 51 A Simple Ant Example 52 More on Targets 57 Target Dependencies 58 Tasks 61 Properties 61 Datatypes 63 Case Study: Building TechConf with Ant 65 Compiling 68 Buildfile Reuse with Macros 69 Javadoc Generation 71 Checking Code Conventions with Checkstyle 73 Generating Source-Code Metrics 75 Generating Browsable Source Code 77 Document Generation 79 Cleaning Up 80 The All Target 81 Eclipse Integration 81 Summary 85
CO CHAPTER 4 Object Relational Mapping with Hibernate 87 Introduction to Hibernate 89 How Hibernate Works 91 The Process 95 POJO-Driven Approach 95 Data Model-Driven Approach 96 HBM-Driven Approach 97 The Tools 98 Road Map 99 Hibernate in J2SE 99 Obtaining Hibernate 100 Setup for POJO Development 100 Eclipse Setup 101 Database Setup 102 Quick Start 102 POJO Sample Code. 102 Mapping (HBM) File 104 Creating the Table 105 Primary Key Generation 106 Saving an Object 108 Retrieving a Single Object 112 Retrieving a Collection of Objects 114 Case Study: Mapping the TechConf Domain Model 118 Conferences Home Page 118 One-to-Many Mapping Using a Set 121 Testing Conference and Tracks 124 Many-to-One: Conferences and Venues 129 Inheritance 129 Inheritance: Table-Per-Class Hierarchy 130 Inheritance: Table Per Subclass 141 Summary 143 CHAPTER 5 Business Services with JBoss 145 JBOSS 146 JBOSS JEMS 147 JBoss AS Architecture 147 Installing and Configuring JBoss 149 Service Objects 154 Stateless Session Beans 155
X «CONTENTS Roads to Persistence 157 Hibernate in JBoss 157 Implementing the DAO Pattern with Hibernate 161 Implementing DTO Pattern with DynaDTO 169 Background 169 DynaDTO 170 DynaDTO in a JSE Environment 176 DynaDTO in JBoss 177 Implementing Service Layer for TechConf 180 Message-Driven POJOs 189 Summary 194 CHAPTER 6 The Spring Framework 195 Coding to Interfaces 195 Dependency Injection 196 Aspect Oriented Programming 198 Full-featured Application Framework 198 Installing and Configuring Spring 200 Working with Spring Bean Factories 200 A Simple Spring Web Application 204 Spring's Starter Web Application 204 JAR Dependencies 205 Java Code 205 Configuring the Spring Application Context 206 JSP Test Page 207 Deployment Descriptors and Build Configuration 207 Deploying to Tomcat 209 Business Services with Spring 210 Spring and Hibernate 211 Implementing the DAO Pattern with Spring 213 Implementing DTO Pattern with DynaDTO 218 Implementing Service Layer for TechConf 219 Sending Email 223 Spring MVC 225 Creating an MVC Controller 225 Creating a JSP View 227 Using Tiles 227 Configuring the Web Deployment 229 Mapping URLs to Controllers 231 Page Navigation and Parameter Passing 232 Summary 237
CONTENTS xi CHAPTER 7 Tapestry 239 What Is Tapestry? 241 Tapestry 4 Features 241 Downloading and Configuring Tapestry 242 Your First Tapestry Application 243 Configuring Tapestry 243 HTML Page 244 The Java Code 245 Page XML Descriptor 246 Web Deployment Descriptor 247 Building and Running the Example 249 The Big Picture 251 The Power of Components 252 Simplifying the Simple Example 254 User Input 255 Building the TechConf Ul with Tapestry 261 Building the Home Page 262 HiveMind Services 265 Testing the Home Page 268 Creating a Border Component 269 Conference Summary Page 282 AJAX with Tacos 288 The AJAX-powered Attendee Registration Page 292 Summary 303 CHAPTER 8 Testing 305 Unit Test or Functional Test? 305 Testing in the Development Cycle 306 Testing Best Practices 307 Tools 308 JUnit.' 309 TestNG 312 Groups 315 Dependent Methods 319 Parameters 319 TestNG Eclipse Plug-in 320 TestNG Reports.322 TestNG and Ant 322
xii CONTENTS Testing Against the Database 324 DbUnit 332 Testing the DTO Layer 337 Testing EJB3 Stateless Session Beans 339 Summary 343 CHAPTER g Continuous Integration 345 Cruise Control 347 Configuring the Build Server 348 CruiseControl Working Directory 348 Setting Up a Project for Continuous Integration 351 Notification Mechanisms 356 TechConf on CruiseControl 358 Metrics 360 Summary 361 CHAPTER 10 Additional Topics 363 AOP with AspectJ 363 Obtaining and Installing AspectJ 364 AspectJ and Ant 365 Logging and Tracing with AspectJ 367 AJDT 372 Translating Exceptions 373 Other Applications of AOP 375 RSS with Informa 376 Summary 379 INDEX 381