PSE Pro for Java Tutorial
Total Page:16
File Type:pdf, Size:1020Kb
PSE Pro for Java Tutorial Release 7.1 Copyright PSE Pro for Java Tutorial PSE Pro for Java Release 7.1 for all platforms, August 2008 © 2008 Progress Software Corporation. All rights reserved. Progress® software products are copyrighted and all rights are reserved by Progress Software Corporation. This manual is also copyrighted and all rights are reserved. This manual may not, in whole or in part, be copied, photocopied, translated, or reduced to any electronic medium or machine-readable form without prior consent, in writing, from Progress Software Corporation. The information in this manual is subject to change without notice, and Progress Software Corporation assumes no responsibility for any errors that may appear in this document. The references in this manual to specific platforms supported are subject to change. A (and design), Actional, Actional (and design), Allegrix, Allegrix (and design), Apama, Apama (and Design), Business Empowerment, DataDirect (and design), DataDirect Connect, DataDirect Connect64, DataDirect Technologies, DataDirect XQuery, DataXtend, Dynamic Routing Architecture, EasyAsk, EdgeXtend, Empowerment Center, Fathom, IntelliStream, Mindreef, Neon, Neon New Era of Networks, O (and design), ObjectStore, OpenEdge, PeerDirect, Persistence, POSSENET, Powered by Progress, PowerTier, Progress, Progress DataXtend, Progress Dynamics, Progress Business Empowerment, Progress Empowerment Center, Progress Empowerment Program, Progress OpenEdge, Progress Profiles, Progress Results, Progress Software Developers Network, Progress Sonic, ProVision, PS Select, SequeLink, Shadow, ShadowDirect, Shadow Interface, Shadow Web Interface, SOAPscope, SOAPStation, Sonic, Sonic ESB, SonicMQ, Sonic Orchestration Server, Sonic Software (and design), SonicSynergy, SpeedScript, Stylus Studio, Technical Empowerment, WebSpeed, and Your Software, Our Technology–Experience the Connection are registered trademarks of Progress Software Corporation or one of its subsidiaries or affiliates in the U.S. and/or other countries. AccelEvent, Apama Dashboard Studio, Apama Event Manager, Apama Event Modeler, Apama Event Store, AppsAlive, AppServer, ASPen, ASP-in-a-Box, BusinessEdge, Cache-Forward, DataDirect Spy, DataDirect SupportLink, DataDirect XML Converters, Future Proof, Ghost Agents, GVAC, Looking Glass, ObjectCache, ObjectStore Inspector, ObjectStore Performance Expert, Pantero, POSSE, ProDataSet, Progress ESP Event Manager, Progress ESP Event Modeler, Progress Event Engine, Progress RFID, PSE Pro, SectorAlliance, SmartBrowser, SmartComponent, SmartDataBrowser, SmartDataObjects, SmartDataView, SmartDialog, SmartFolder, SmartFrame, SmartObjects, SmartPanel, SmartQuery, SmartViewer, SmartWindow, Sonic Business Integration Suite, Sonic Process Manager, Sonic Collaboration Server, Sonic Continuous Availability Architecture, Sonic Database Service, Sonic Workbench, Sonic XML Server, The Brains Behind BAM, WebClient, Who Makes Progress, and Your World. Your SOA. are trademarks or service marks of Progress Software Corporation or one of its subsidiaries or affiliates in the U.S. and other countries. Java and all Java-based marks are trademarks or registered trademarks of Sun Microsystems, Inc. in the U.S. and other countries. Any other trademarks or trade names contained herein are the property of their respective owners. ObjectStore includes software developed by the Apache Software Foundation (http://www.apache.org/). Copyright ? 2000-2003 The Apache Software Foundation. All rights reserved. The names “Ant,” “Xerces,” and “Apache Software Foundation” must not be used to endorse or promote products derived from the Products without prior written permission. Any product derived from the Products may not be called “Apache”, nor may “Apache” appear in their name, without prior written permission. For written permission, please contact [email protected]. ObjectStore includes the RSA Data Security, Inc. MD5 Message-Digest Algorithm. Copyright © 1991-2, RSA Data Security, Inc. Created 1991. All rights reserved. ObjectStore includes Yahoo! User Interface Library - V 0.12.1. Copyright © 2006 Yahoo! Inc. All rights reserved. The name Yahoo! Inc. nor the names of its contributors may be used to endorse or promote products derived from this Software and products derived from this software without specific prior written permission of Yahoo! Inc. Copyright Updated: June 2008 Contents Preface . .7 Chapter 1 Benefits of PSE Pro for Java . .13 Overview of PSE Pro Benefits . 13 Serialization and Persistence . 13 Description of Serialization. 14 Disadvantages of Serialization . 14 The Way PSE Pro Improves on Serialization . 14 Improved Performance for Accessing Large Numbers of Objects. 15 Reliable Object Management . 15 Queries . 15 Ease of Use . 15 Chapter 2 Description of the Personalization Application . .17 Overview of the Data Model . 17 Personalization Application Architecture . 19 Description of the UserManager Class. 19 Description of the User and Interest Classes . 20 Adding New Interests . 20 Adding New User Types . 20 Source Code for the Interest Class . 20 Source Code for the User Class . 21 Chapter 3 Writing Your Application to Use PSE Pro . .23 Basic ObjectStore Operations . 23 Getting Ready to Store Objects . 24 Creating Sessions . 24 Creating, Opening, and Closing Databases. 25 Starting Transactions . 26 Creating Database Entry Points . 27 Description of Database Roots . 27 Creating Database Roots . 28 Example of Creating Database Roots. 28 Release 7.1 3 Contents Storing Objects in a Database . .29 Example of Storing Objects in a Database . .29 Definition of Persistence Capable . .30 Accessing Objects in the Database . .30 Example of Using a Database Root . .30 Example of Using References . .30 Retaining Objects or References to Objects . .31 Deleting Objects . .32 Example of Deleting an Object . .32 Destroying an Object . .33 Destroying Objects Referenced by Destroyed Objects . .33 Destroying Strings . .34 About the PSE Pro Persistent Garbage Collector . .34 Using Collections . .34 Chapter 4 Compiling and Running a PSE Pro Program . .37 Installing PSE Pro . .37 Adding Entries to Your CLASSPATH . .38 Entries Required to Run PSE Pro Applications. .38 Entries Required to Develop PSE Pro Applications. .38 Background About Different Kinds of Class Files . .39 Compiling the Program . .39 Running the Postprocessor. .40 Description of Output from the Postprocessor . .40 Example of Postprocessing Classes in Place . .40 Specifying an Input File to the Postprocessor. .40 Placing the Annotated Files in a Separate Directory . .41 Additional Information About the Postprocessor . .41 Running the Program . .42 Chapter 5 Using PSE Pro to Query a Database . .43 Querying Collections . .43 Creating Queries . .44 Running Queries Against Collections . .44 Specifying Variables in Queries . .44 Using Indexes to Speed Query Performance. .46 What an Index Does . .46 Creating an Index . .46 Example of Creating an Index . .47 Maintenance Required After Changing Indexed Elements . .47 4 Chapter 6 Choosing PSE Pro or ObjectStore . .49 4 PSE Pro for Java Tutorial Contents Overall Capability . 49 Database Size . 50 Concurrent Users . 50 Collections . 50 Integrity, Reliability, and Recovery . 50 Multimedia Content Management. 51 Ease of Using Java . 51 Appendix A Source Code . .53 Source Code for Interest.java . 53 Source Code for User.java . 54 Source Code for UserManager.java . 56 Source Code for TestDriver.java . 62 Source Code for PersonalizationException.java . 66 Appendix B Sample Output . .67 Release 7.1 5 Contents 6 6 PSE Pro for Java Tutorial Preface Purpose Purpose PSE Pro for Java Tutorial provides an overview of the basic concepts of PSE Pro for Java. It uses an example application to show you the way to define persistent classes and manipulate persistent objects. It also shows you the way to develop and run applications that use the PSE Pro for Java. Audience Audience This book is for experienced Java programmers who are new to writing applications that use PSE Pro for Java. If you are new to PSE Pro for Java, you should read the tutorial, and then look at the demonstration programs. Scope Scope This book supports Release 7.1 of PSE Pro for Java. How the Tutorial Is Organized The tutorial provides an introduction to PSE Pro for Java. The basic concepts are illustrated with a sample application called the Personalization application. In Chapter 5, you can find information that goes beyond the sample application. • Chapter 1, Benefits of PSE Pro for Java, on page 13, introduces the concept of persistence and compares object serialization to the features provided by PSE Pro. • Chapter 2, Description of the Personalization Application, on page 17, presents a small sample application to show the way to use PSE Pro. • Chapter 3, Writing Your Application to Use PSE Pro, on page 23, introduces the core concepts of PSE Pro through explanation of code samples drawn from the Personalization application. • Chapter 4, Compiling and Running a PSE Pro Program, on page 37, describes the compile and build phases of PSE Pro development using code from the Personalization application. • Chapter 5, Using PSE Pro to Query a Database, on page 43, discusses queries and indexing, which are available in ObjectStore and PSE Pro. The tutorial application does not implement queries, but the information in this chapter is a basis for getting started. • Chapter 6, Choosing PSE Pro or ObjectStore, on page 49, provides information to help you decide whether PSE Pro, or ObjectStore is the most appropriate solution for your requirements. Release 7.1 7 Preface • Appendix.