![]() |
Chapter 14 Storing the DataIn this chapter we will very briefly introduce three database products that run on the Linux platform and will support our sample applications. We will also select one of the three and explain how to set up our database tables. 14.1 WHAT YOU WILL LEARNIn this chapter you will learn a little bit about database server products available for Linux, including both commercial and Free or Open Source products. We will briefly discuss some factors that might enter into choosing one over the other. We will then describe how one might design tables to back our applica- tion, and how to create and implement those tables in two Open Source databases: MySQL and PostgreSQL. 315 14.2 FOLLOW THE OBJECTSOne of the consequences of a good object design is a relatively simple database design. For the most part, each class will end up as a database table where each row represents an instance of that class. Beyond that, all that is needed are those tables required to represent relationships between objects. In this chapter we will show you examples of these relationships, and we will do so in a manner that should easily port to any SQL relational database. 14.3 OF PERSISTENCEPrograms cannot be assured of running forever. Virtually all computer main memory (i.e., RAM) is volatile, meaning that if the power is removed, the data is lost. Since computers are sometimes rebooted, and since the power sometimes goes out, we obviously need some place besides memory to store our class in- stances. We need persistent (nonvolatile) storage. This can be as simple as streaming our classes out to flat file, or it can be as complex as a clustered multi- user database. We will discuss the selection criteria and how you might choose your persistent storage strategy. 14.4 THINKING OF THE FUTURE, OR PAINTING IN CORNERSIt is important that you try, in your class design, to avoid making the persis- tence system dependent on a particular storage method or product. If you do this, you can switch storage products or solutions relatively easily. 14.5 ORACLE, POSTGRESQL, MYSQLOne of the first major decisions you must make is what to use as a database server. On Linux systems, you have both Free Software and commercial soft- ware options. As we have said before, we will tend to focus on Free Software in this text, but we cannot ignore the most popular database software package out there, which is, of course, Oracle. Let’s take a quick look at each of the “big 3” database choices on Linux platforms. 14.5 Oracle, PostgreSQL, MySQL 317
14.5.1 MySQL 14.5.2 PostgreSQL 14.5.3 Oracle 14.5.4 Selection Criteria Hibernate4 Castor6 pBeans7 14.9.1 Installing PostgreSQL 14.9.3 Creating Our Database 14.9.4 Straight JDBC
|