[ Pobierz całość w formacie PDF ]
.Remember that you packaged a session bean, the SequenceBean, with the Forethoughtentities already.In this same fashion, manager components that implement the façade designpattern can be packaged with entity beans, ensuring that RMI communication is as fast aspossible; this also provides logical divisions between entities and their accessor classes (themanager components) and business-driven components (the rest of the session beans).Figure 8-4 shows this configuration in action.Here, the manager components are packaged inthe forethoughtEntities.jar archive, and in that way, become simple entities.Figure 8-4.Logical separation of beansAdditionally, almost all manager components turn out to be stateless; in other words, eachmethod of the component operates on its own without any saved information.Using statelesscomponents also helps to offset penalties incurred through using the façade pattern.Asmentioned several times, stateless session beans outperform all other types of entity beans2In fact, most advanced EJB containers have optimizations for these "in-VM" calls, and will essentially drop the calls off the RMI stack and makethe calls locally, removing any RMI penalties at all.143Building Java"! Enterprise Applications Volume I: Architecturesubstantially.Interestingly enough, entity beans consume the most resources of any bean, asoften one single instance is shared for containers (although there are as many variations onthis theme as there are container vendors).So it is safe to make your manager session beansstateless.These changes address the major downside of using the façade pattern; there are really noother penalties (other than some extra coding) to this approach.Clearly it makes sense, then,to implement it in the Forethought application as well as in your own.8.2 The UserManagerOnce offices are set up, the next logical step is to deal with Forethought users.Users arecrucial to any application, which makes the UserManager component a critical part of theForethought application.This particular manager component will also illustrate some of theimportant reasons for using managers at all.Chief among those reasons are data sourcetransparency and data format transparency.Both offer advantages to the manager clients andprovide many of the security and ease-of-use benefits discussed earlier with regard to theOfficeManager.8.2.1 Data Source TransparencyIn the case of Forethought offices, all information related to an office is stored in a singletable, in a single data source: the Forethought RDBMS OFFICES table, which we set up inChapter 3.While extremely convenient, this is most often not the case.It's a lot morecommon to find that a single logical entity (like a user) has its information stored in multipletables (like the USERS and USER_TYPES tables), and even in multiple data sources (like theForethought database and the Forethought directory server).As a result, working with onelogical piece of data often requires operating upon multiple physical pieces of data.This canbecome quite a pain for application clients: they must use JDBC to connect to a database,SQL to select from and join together tables, and then JNDI to operate upon a directory server;finally, the resultant information has to be spliced together in some meaningful form.As agood developer, you should seek to avoid this complexity.The User entity bean and the LDAPManager component have already alleviated some ofthese problems; these two components abstract all the details of connection and specific SQLand LDAP statements from the client.However, a client (or piece of code) would still have toknow that the core information about a user is in the database, and therefore an entity bean isneeded, while the authentication information is in a directory server, so the manager isemployed.Add to that the need to not only utilize the User entity bean, but the UserType andpossibly Office entity beans as well, and things are only marginally better than they werewithout beans and managers at all.What is obviously needed here is another level ofabstraction.As the saying goes, "Everything in programming can be solved with another layerof abstraction." It is here that UserManager-type components come in.By providing a singlecomponent for working with users, the data sources involved with that component are hiddenfrom the client.For example, consider the process of adding a new user
[ Pobierz całość w formacie PDF ]