Archive for September, 2007

Persistence layers and alternatives 1.3.3 Using serialization Java (Web hosting directory)

Sunday, September 30th, 2007

Persistence layers and alternatives 1.3.3 Using serialization Java has a built-in persistence mechanism: Serialization provides the ability to write a snapshot of a network of objects (the state of the application) to a byte stream, which may then be persisted to a file or database. Serialization is also used by Java s Remote Method Invocation (RMI) to achieve pass-by value semantics for complex objects. Another use of serialization is to replicate application state across nodes in a cluster of machines. Why not use serialization for the persistence layer? Unfortunately, a serialized network of interconnected objects can only be accessed as a whole; it s impossible to retrieve any data from the stream without deserializing the entire stream. Thus, the resulting byte stream must be considered unsuitable for arbitrary search or aggregation of large datasets. It isn t even possible to access or update a single object or subset of objects independently. Loading and overwriting an entire object network in each transaction is no option for systems designed to support high concurrency. Given current technology, serialization is inadequate as a persistence mecha nism for high concurrency web and enterprise applications. It has a particular niche as a suitable persistence mechanism for desktop applications. 1.3.4 Object-oriented database systems Because we work with objects in Java, it would be ideal if there were a way to store those objects in a database without having to bend and twist the object model at all. In the mid-1990s, object-oriented database systems gained attention. They re based on a network data model, which was common before the advent of the relational data model decades ago. The basic idea is to store a network of objects, with all its pointers and nodes, and to re-create the same in-memory graph later on. This can be optimized with various metadata and configuration settings. An object-oriented database management system (OODBMS) is more like an extension to the application environment than an external data store. An OODBMS usually features a multitiered implementation, with the backend data store, object cache, and client application coupled tightly together and interacting via a proprietary network protocol. Object nodes are kept on pages of memory, which are transported from and to the data store. Object-oriented database development begins with the top-down definition of host language bindings that add persistence capabilities to the programming language. Hence, object databases offer seamless integration into the object-oriented application environment. This is different from the model used by today s
If you are in need for cheap and reliable webhost to host your website, we recommend http web server services.

CHAPTER 1 (Web server extensions) Understanding object/relational persistence Let s now take

Sunday, September 30th, 2007

CHAPTER 1 Understanding object/relational persistence Let s now take a brief look at the various ways the persistence layer can be implemented by Java applications. Don t worry we ll get to ORM and Hibernate soon. There is much to be learned by looking at other approaches. 1.3.2 Hand-coding a persistence layer with SQL/JDBC The most common approach to Java persistence is for application programmers to work directly with SQL and JDBC. After all, developers are familiar with relational database management systems, they understand SQL, and they know how to work with tables and foreign keys. Moreover, they can always use the well-known and widely used data access object (DAO) pattern to hide complex JDBC code and nonportable SQL from the business logic. The DAO pattern is a good one so good that we often recommend its use even with ORM. However, the work involved in manually coding persistence for each domain class is considerable, particularly when multiple SQL dialects are supported. This work usually ends up consuming a large portion of the development effort. Furthermore, when requirements change, a hand-coded solution always requires more attention and maintenance effort. Why not implement a simple mapping framework to fit the specific requirements of your project? The result of such an effort could even be reused in future projects. Many developers have taken this approach; numerous homegrown object/relational persistence layers are in production systems today. However, we don t recommend this approach. Excellent solutions already exist: not only the (mostly expensive) tools sold by commercial vendors, but also open source projects with free licenses. We re certain you ll be able to find a solution that meets your requirements, both business and technical. It s likely that such a solution will do a great deal more, and do it better, than a solution you could build in a limited time. Developing a reasonably full-featured ORM may take many developers months. For example, Hibernate is about 80,000 lines of code, some of which is much more difficult than typical application code, along with 25,000 lines of unit test code. This may be more code than is in your application. A great many details can easily be overlooked in such a large project as both the authors know from experience! Even if an existing tool doesn t fully implement two or three of your more exotic requirements, it s still probably not worth creating your own tool. Any ORM software will handle the tedious common cases the ones that kill productivity. It s OK if you need to hand-code certain special cases; few applications are composed primarily of special cases.
We recommend high quality webhost to host and run your jsp application: christian web host services.

Web site design and hosting - Persistence layers and alternatives Figure 1.4 A persistence

Saturday, September 29th, 2007

Persistence layers and alternatives Figure 1.4 A persistence layer is the basis in a layered architecture Presentation layer The user interface logic is topmost. Code responsible for the presentation and control of page and screen navigation is in the presentation layer. Business layer The exact form of the next layer varies widely between applications. It s generally agreed, however, that the business layer is responsible for implementing any business rules or system requirements that would be understood by users as part of the problem domain. This layer usually includes some kind of controlling component code that knows when to invoke which business rule. In some systems, this layer has its own internal representation of the business domain entities, and in others it reuses the model defined by the persistence layer. We revisit this issue in chapter 3. Persistence layer The persistence layer is a group of classes and components responsible for storing data to, and retrieving it from, one or more data stores. This layer necessarily includes a model of the business domain entities (even if it s only a metadata model). Database The database exists outside the Java application itself. It s the actual, persistent representation of the system state. If an SQL database is used, the database includes the relational schema and possibly stored procedures. Helper and utility classes Every application has a set of infrastructural helper or utility classes that are used in every layer of the application (such as Exception classes for error handling). These infrastructural elements don t form a layer, because they don t obey the rules for interlayer dependency in a layered architecture.
We would like to recommend you tested and proved virtual web hosting services, which you will surely find to be of great quality.

CHAPTER 1 Understanding object/relational persistence manipulate data, the (Web hosting contract)

Saturday, September 29th, 2007

CHAPTER 1 Understanding object/relational persistence manipulate data, the tables and columns involved must be specified at least three times (insert, update, select), adding to the time required for design and implementation. The distinct dialects for every SQL database management system don t improve the situation. To round out your understanding of object persistence, and before we approach possible solutions, we need to discuss application architecture and the role of a persistence layer in typical application design. 1.3 Persistence layers and alternatives In a medium- or large-sized application, it usually makes sense to organize classes by concern. Persistence is one concern; others include presentation, workflow, and business logic.1 A typical object-oriented architecture includes layers of code that represent the concerns. It s normal and certainly best practice to group all classes and components responsible for persistence into a separate persistence layer in a layered system architecture. In this section, we first look at the layers of this type of architecture and why we use them. After that, we focus on the layer we re most interested in the persis tence layer and some of the ways it can be implemented. 1.3.1 Layered architecture A layered architecture defines interfaces between code that implements the various concerns, allowing changes to be made to the way one concern is implemented without significant disruption to code in the other layers. Layering also determines the kinds of interlayer dependencies that occur. The rules are as follows: Layers communicate from top to bottom. A layer is dependent only on the layer directly below it. Each layer is unaware of any other layers except for the layer just below it. Different systems group concerns differently, so they define different layers. A typical, proven, high-level application architecture uses three layers: one each for presentation, business logic, and persistence, as shown in figure 1.4. Let s take a closer look at the layers and elements in the diagram: 1 There are also the so-called cross-cutting concerns, which may be implemented generically by framework code, for example. Typical cross-cutting concerns include logging, authorization, and transaction demarcation.
You want to have a cheap webhost for your apache application, then check apache web hosting services.

The paradigm mismatch selects, which retrieve unnecessary information (Web design tools)

Friday, September 28th, 2007

The paradigm mismatch selects, which retrieve unnecessary information into memory. Yet, although we ve been blessed with innumerable books and magazine articles advising us to use StringBuffer for string concatenation, it seems impossible to find any advice about strategies for avoiding the n+1 selects problem. Fortunately, Hibernate provides sophisticated features for efficiently and transparently fetching networks of objects from the database to the application accessing them. We discuss these features in chapters 13, 14, and 15. 1.2.6 The cost of the mismatch We now have quite a list of object/relational mismatch problems, and it will be costly (in time and effort) to find solutions, as you may know from experience. This cost is often underestimated, and we think this is a major reason for many failed software projects. In our experience (regularly confirmed by developers we talk to), the main purpose of up to 30 percent of the Java application code written is to handle the tedious SQL/JDBC and manual bridging of the object/relational paradigm mismatch. Despite all this effort, the end result still doesn t feel quite right. We ve seen projects nearly sink due to the complexity and inflexibility of their database abstraction layers. We also see Java developers (and DBAs) quickly lose their confidence when design decisions about the persistence strategy for a project have to be made. One of the major costs is in the area of modeling. The relational and domain models must both encompass the same business entities, but an object-oriented purist will model these entities in a different way than an experienced relational data modeler would. The usual solution to this problem is to bend and twist the domain model and the implemented classes until they match the SQL database schema. (Which, following the principle of data independence, is certainly a safe long-term choice.) This can be done successfully, but only at the cost of losing some of the advantages of object orientation. Keep in mind that relational modeling is underpinned by relational theory. Object orientation has no such rigorous mathematical definition or body of theoretical work, so we can t look to mathematics to explain how we should bridge the gap between the two paradigms there is no elegant transformation waiting to be discovered. (Doing away with Java and SQL, and starting from scratch isn t considered elegant.) The domain modeling mismatch isn t the only source of the inflexibility and the lost productivity that lead to higher costs. A further cause is the JDBC API itself. JDBC and SQL provide a statement-oriented (that is, command-oriented) approach to moving data to and from an SQL database. If you want to query or
In case you need affordable webhost to host your website, our recommendation is ecommerce web host services.

Submit web site - CHAPTER 1 Understanding object/relational persistence 1.2.5 The problem

Friday, September 28th, 2007

CHAPTER 1 Understanding object/relational persistence 1.2.5 The problem of data navigation There is a fundamental difference in the way you access data in Java and in a relational database. In Java, when you access a user s billing information, you call aUser.getBillingDetails().getAccountNumber() or something similar. This is the most natural way to access object-oriented data, and it s often described as walking the object network. You navigate from one object to another, following pointers between instances. Unfortunately, this isn t an efficient way to retrieve data from an SQL database. The single most important thing you can do to improve the performance of data access code is to minimize the number of requests to the database. The most obvious way to do this is to minimize the number of SQL queries. (Of course, there are other more sophisticated ways that follow as a second step.) Therefore, efficient access to relational data with SQL usually requires joins between the tables of interest. The number of tables included in the join when retrieving data determines the depth of the object network you can navigate in memory. For example, if you need to retrieve a User and aren t interested in the user s billing information, you can write this simple query: select * from USERS u where u.USER_ID = 123 On the other hand, if you need to retrieve a User and then subsequently visit each of the associated BillingDetails instances (let s say, to list all the user s credit cards), you write a different query: select * from USERS u left outer join BILLING_DETAILS bd on bd.USER_ID = u.USER_ID where u.USER_ID = 123 As you can see, to efficiently use joins you need to know what portion of the object network you plan to access when you retrieve the initial User this is before you start navigating the object network! On the other hand, any object persistence solution provides functionality for fetching the data of associated objects only when the object is first accessed. However, this piecemeal style of data access is fundamentally inefficient in the context of a relational database, because it requires executing one statement for each node or collection of the object network that is accessed. This is the dreaded n+1 selects problem. This mismatch in the way you access objects in Java and in a relational database is perhaps the single most common source of performance problems in Java applications. There is a natural tension between too many selects and too big
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.

The paradigm (Web design portfolio) mismatch the data, to an application-dependent

Thursday, September 27th, 2007

The paradigm mismatch the data, to an application-dependent navigational model, a constrained view of the associations needed by this particular application. It isn t possible to determine the multiplicity of a unidirectional association by looking only at the Java classes. Java associations can have many-to-many multiplicity. For example, the classes could look like this: public class User { private Set billingDetails; … } public class BillingDetails { private Set users; … } Table associations, on the other hand, are always one-to-many or one-to-one. You can see the multiplicity immediately by looking at the foreign key definition. The following is a foreign key declaration on the BILLING_DETAILS table for a one-tomany association (or, if read in the other direction, a many-to-one association): USER_ID bigint foreign key references USERS These are one-to-one associations: USER_ID bigint unique foreign key references USERS BILLING_DETAILS_ID bigint primary key foreign key references USERS If you wish to represent a many-to-many association in a relational database, you must introduce a new table, called a link table. This table doesn t appear anywhere in the domain model. For our example, if we consider the relationship between the user and the billing information to be many-to-many, the link table is defined as follows: create table USER_BILLING_DETAILS ( USER_ID bigint foreign key references USERS, BILLING_DETAILS_ID bigint foreign key references BILLING_DETAILS, PRIMARY KEY (USER_ID, BILLING_DETAILS_ID) ) We discuss association and collection mappings in great detail in chapters 6 and 7. So far, the issues we ve considered are mainly structural. We can see them by considering a purely static view of the system. Perhaps the most difficult problem in object persistence is a dynamic problem. It concerns associations, and we ve already hinted at it when we drew a distinction between object network navigation and table joins in section 1.1.4, Persistence in object-oriented applications. Let s explore this significant mismatch problem in more depth.
You want to have a cheap webhost for your apache application, then check apache web hosting services.

CHAPTER 1 Understanding object/relational persistence (if at all) (Abyss web server)

Thursday, September 27th, 2007

CHAPTER 1 Understanding object/relational persistence (if at all) should they be represented in the domain model? We discuss this question in chapter 4, section 4.2, Mapping entities with identity, and we find a solution with ORM. In the context of persistence, identity is closely related to how the system handles caching and transactions. Different persistence solutions have chosen different strategies, and this has been an area of confusion. We cover all these interesting topics and show how they re related in chapters 10 and 13. So far, the skeleton e-commerce application we ve designed has identified the mismatch problems with mapping granularity, subtypes, and object identity. We re almost ready to move on to other parts of the application, but first we need to discuss the important concept of associations: how the relationships between our classes are mapped and handled. Is the foreign key in the database all you need? 1.2.4 Problems relating to associations In our domain model, associations represent the relationships between entities. The User, Address, and BillingDetails classes are all associated; but unlike Address, BillingDetails stands on its own. BillingDetails instances are stored in their own table. Association mapping and the management of entity associations are central concepts in any object persistence solution. Object-oriented languages represent associations using object references; but in the relational world, an association is represented as a foreign key column, with copies of key values (and a constraint to guarantee integrity). There are substantial differences between the two representations. Object references are inherently directional; the association is from one object to the other. They re pointers. If an association between objects should be navigable in both directions, you must define the association twice, once in each of the associated classes. You ve already seen this in the domain model classes: public class User { private Set billingDetails; … } public class BillingDetails { private User user; … } On the other hand, foreign key associations aren t by nature directional. Navigation has no meaning for a relational data model because you can create arbitrary data associations with table joins and projection. The challenge is to bridge a completely open data model, which is independent of the application that works with
You want to have a cheap webhost for your apache application, then check apache web hosting services.

Web hosting faq - The paradigm mismatch this problem: two in the

Wednesday, September 26th, 2007

The paradigm mismatch this problem: two in the Java world and one in our SQL database. As expected, they work together only with some help. Java objects define two different notions of sameness: Object identity (roughly equivalent to memory location, checked with a==b) Equality as determined by the implementation of the equals() method (also called equality by value) On the other hand, the identity of a database row is expressed as the primary key value. As you ll see in chapter 9, section 9.2, Object identity and equality, neither equals() nor == is naturally equivalent to the primary key value. It s common for several nonidentical objects to simultaneously represent the same row of the database, for example, in concurrently running application threads. Furthermore, some subtle difficulties are involved in implementing equals() correctly for a persistent class. Let s discuss another problem related to database identity with an example. In our table definition for USERS, we used USERNAME as a primary key. Unfortunately, this decision makes it difficult to change a username; we need to update not only the USERNAME column in USERS, but also the foreign key column in BILLING_ DETAILS. To solve this problem, later in the book we ll recommend that you use surrogate keys whenever you can t find a good natural key (we ll also discuss what makes a key good). A surrogate key column is a primary key column with no meaning to the user; in other words, a key that isn t presented to the user and is only used for identification of data inside the software system. For example, we may change our table definitions to look like this: create table USERS ( USER_ID bigint not null primary key, USERNAME varchar(15) not null unique, NAME varchar(50) not null, … ) create table BILLING_DETAILS ( BILLING_DETAILS_ID bigint not null primary key, ACCOUNT_NUMBER VARCHAR(10) not null unique, ACCOUNT_NAME VARCHAR(50) not null, ACCOUNT_TYPE VARCHAR(2) not null, USER_ID bigint foreign key references USER ) The USER_ID and BILLING_DETAILS_ID columns contain system-generated values. These columns were introduced purely for the benefit of the data model, so how
If you are looking for cheap and quality webhost to host and run your website check Jboss Web Hosting services.

CHAPTER 1 Understanding object/relational persistence its parent. However, (Sex offenders web site)

Wednesday, September 26th, 2007

CHAPTER 1 Understanding object/relational persistence its parent. However, such a feature would be questionable, because it would introduce a new notion: virtual columns in base tables. Traditionally, we expect virtual columns only in virtual tables, which are called views. Furthermore, on a theoretical level, the inheritance we applied in Java is type inheritance. A table isn t a type, so the notion of supertables and subtables is questionable. In any case, we can take the short route here and observe that SQL database products don t generally implement type or table inheritance, and if they do implement it, they don t follow a standard syntax and usually expose you to data integrity problems (limited integrity rules for updatable views). In chapter 5, section 5.1, Mapping class inheritance, we discuss how ORM solutions such as Hibernate solve the problem of persisting a class hierarchy to a database table or tables. This problem is now well understood in the community, and most solutions support approximately the same functionality. But we aren t finished with inheritance. As soon as we introduce inheritance into the model, we have the possibility of polymorphism. The User class has an association to the BillingDetails superclass. This is a polymorphic association. At runtime, a User object may reference an instance of any of the subclasses of BillingDetails. Similarly, we want to be able to write polymorphic queries that refer to the BillingDetails class, and have the query return instances of its subclasses. SQL databases also lack an obvious way (or at least a standardized way) to represent a polymorphic association. A foreign key constraint refers to exactly one target table; it isn t straightforward to define a foreign key that refers to multiple tables. We d have to write a procedural constraint to enforce this kind of integrity rule. The result of this mismatch of subtypes is that the inheritance structure in your model must be persisted in an SQL database that doesn t offer an inheritance strategy. Fortunately, three of the inheritance mapping solutions we show in chapter 5 are designed to accommodate the representation of polymorphic associations and the efficient execution of polymorphic queries. The next aspect of the object/relational mismatch problem is the issue of object identity. You probably noticed that we defined USERNAME as the primary key of our USERS table. Was that a good choice? How do we handle identical objects in Java? 1.2.3 The problem of identity Although the problem of object identity may not be obvious at first, we ll encounter it often in our growing and expanding e-commerce system, such as when we need to check whether two objects are identical. There are three ways to tackle
If you are looking for affordable and reliable webhost to host and run your business application visit our ftp web hosting services.