|By Daniel O'Connor||
|June 1, 2000 12:00 AM EDT||
Say you're writing an Enterprise JavaBean that represents a persistent object, such as a customer or a product. You have two choices for getting data (such as customer name and product number) from the bean to the database and back:
- You can let the bean's runtime environment its container, in EJB speak do the heavy lifting for you....
- ....or you can provide the logic yourself along with your bean.
According to the current version of the Enterprise JavaBeans Specification (v1.1), a compliant EJB container isn't required to provide any support for mapping the container-managed fields to a database schema. For instance, it could use Java serialization to save the beans to a file. Most if not all commercial and open-source containers will map fields to table columns in a database. But some will do it better than others. You'll have trouble with some products, for example, if you want to map your bean to multiple rows in multiple tables.
In fact, you probably do want to map your bean to multiple rows in multiple tables. Your beans should be coarse-grained, managing their own dependent objects. Your order bean should have line items implemented as a helper class, rather than as references to line-item EJBs. Your customer bean should have addresses rather than references to address beans. The overhead of bean-to-bean calls between an order and its line items, or a customer and its addresses, would be prohibitive. Your EJB server can provide you with many services, such as declarative transactions, security, and even load balancing and failover. But there's no free lunch, and the price you pay is indirection. Every call you make goes through a layer whose purpose is to provide these services (see Figure 1). Managing dependent objects reduces the frequency of trips through this indirection layer (see Figure 2). And a bean with multiple dependent objects needs to be stored in multiple tables, in multiple rows, if you want to maintain a normalized schema.
Technically, bean-managed persistence doesn't mean you have to write your own database access code. It just means the bean, rather than the container, provides the persistence logic. Several good object-relational mapping tools are on the market, and they can be portable from server to server along with your bean. But you may find it impossible to use these tools because of cost (some have runtime fees and/or a hefty per-developer price tag), distribution practicalities or reasons of your own. This article will tell you what you need to do to write your own persistence for a coarse-grained entity bean.
Requirements for Dependent Objects
An efficient implementation of bean-managed persistence for dependent objects will have two features:
- Partitioned storage logic
Load-on-demand means that the dependent objects aren't loaded until they're actually needed. The EJB framework will call a function in your entity bean to indicate that persistent data should be made available to the bean's business logic. The bean could load the dependent data at this point. But if the business logic doesn't make use of certain dependent data during the current transaction, that database access was wasted. For instance, changing a customer's credit rating may not require access to any address, so the addresses shouldn't be loaded. If the dependent data is accessed, it can be loaded at that time. (This is also known as lazy loading.) Partitioned storage logic is necessary so that the bean updates the database the way a relational database expects: new data is inserted, changed data is updated, discarded data is deleted and unchanged data is left alone (see Figure 3). The alternative wiping out the records and reinserting them is too horrible even to contemplate.
A Good Idiom
To implement load-on-demand, you could scatter calls throughout your business logic to functions with names like "ensureAddressListLoaded" and "ensureLineItemListLoaded" that is, if you want to be the poster child for ugly code. And to store your dependent objects to the database, you could have each object keep track of its status: NEW, UPDATED, DELETED or UNMODIFIED. As you totaled the line items in a purchase order, you'd need to check each object to see if it had been deleted (see Figure 4). Don't forget, or you're going to have some unhappy customers.
A better idiom is to group the logic related to persistence with a collection class. Your business logic for an order probably works with a list of line items. To delete an object, the most natural thing to do is probably to remove it from the list. To add an object, the most natural thing is to append it to the list. And simply calling a method on the list should be the signal to your persistence logic that the items in the list need to be loaded from the database. If you use a smart list that knows how to do these things, nothing else needs to be done from the perspective of the business logic programmer. In the example of totaling line items in a purchase order, you'd simply iterate through the objects in the list (see Figure 5).
Behind the scenes, a smart list implementation is keeping track of an "isLoaded" variable. When the list is accessed, it checks this variable first to see if the data needs to be loaded from the database. If so, it loads it. It keeps a set of references to all the objects it loads to distinguish them from new objects added to the list. If an object is removed from the list, it's added to an internal list of deleted objects. This deleted objects list is used by the persistence logic, but not, typically, by the business logic programmer.
The Proxy List
The smart list needs a layer of indirection between the list interface and the actual list storage. At this layer a method call on the list to remove objects will first add those objects to the internal deleted objects list. Also, a call to any function will check to see if the list data has been loaded. One possible way to gain this indirection is simply to implement the java.util.List interface and delegate the calls to a private internal "backing" list. A more elegant way is to use the java.lang.reflect.Proxy class newly available in JDK 1.3. (Note: Using the Proxy class limits your bean's portability to servers that support JDK 1.3. All the techniques and code discussed in this article are easily adapted to the "delegation list" compatible with earlier JDKs.)
The Proxy class dynamically creates an implementation of an interface that will automatically forward all its calls to a middle layer called InvocationHandler (also in package java.lang.reflect). In a subclass of InvocationHandler you can forward the method call (or not), take action before or after forwarding it, alter its parameters and change the returned object (see Figure 6). As you can see, this is more than enough functionality to implement our smart list. The uses for this Proxy are many: it can be used to handle user interface events and to provide a "poor man's multiple inheritance," and has even been used to implement an open-source EJB server, EJBoss. (For more information on the Proxy and InvocationHandler classes, see the article at http://java.sun.com/products/jfc/tsc/articles/generic-listener2/index.html on Sun's Web site.)
Take a look at ListInvocationHandler (see Listing 1). It's the smart list implementation that keeps track of deleted objects, the set of original objects and whether the data has been loaded from the database. It also takes as a constructor parameter its "backing" list so that any class implementing the List interface (LinkedList or ArrayList) can be used, depending on how the data is typically accessed. The main functionality is in the invoke method. Here I check to make sure the data has been loaded from the database. I also check for any List function that removes an object so I can make a copy to use for calling "delete" later on the database. An important point: several List functions will return a reference to the backing list unless these too are interposed on. Any method that returns an Iterator (which points to the backing list) must instead be made to return an Iterator pointing to the interposed list. I did this using you guessed it another Proxy (see Listing 2). Any method that returns a Collection must either be interposed on or made unmodifiable.
My smart list implementation uses two persistence-specific interfaces (see Figure 7). The first, PersistentOperations (see Listing 3), is implemented by the smart list itself (in ListInvocationHandler). It's for list operations needed by the bean's persistence plumbing, rather than the business logic. You can get a list of deleted objects to actually delete them. You can get the set of original objects to decide between insert and update operations. You can add an object to the list so that it's tagged as an original object rather than a new one. You can tell the list that the bean has been asked to save itself to persistent storage, and to take whatever actions are necessary. For symmetry more than need, you can also ask the list to load itself from persistent storage. Typically, you'll let the list decide this for itself.
The second persistence-specific interface used by the list is DataStore (see Listing 4). Although your business logic can treat the smart list as a regular list, you need to put the SQL somewhere, and this interface is the gateway to that "somewhere." Your bean will pass an implementation of this interface to the smart list factory (DemandListFactory; see Listing 5). When the list needs to save or restore its data, it will call methods in this interface, passing a reference to its PersistentOperations interface.
A simplified example of using a proxy list with an EJB with bean-managed persistence is available on the Java Developer's Journal Web site. The bean implements a customer-has-line-items model. A customer has an ID and a name, and an unlimited number of line items of products he or she has ordered. In order to give the smart list a workout, I've written functions so the business logic programmer can add, delete or change a line item, and use the entire set of line items at once. The list is initialized when the bean is created (a new customer record is inserted) or loaded (an existing customer record is read from the database). An anonymous DataStore implementation is passed to the DemandListFactory, which will call bean methods whenever DataStore methods are called by the list.
One bean method will do a simple select on the database table where line items are stored. As it iterates through the result set, it calls the PersistentOperations's addFromStore method, which will indicate to the list that the object already exists in the database and needs to be updated, not inserted, when the list is stored. Another bean method that stores the list is only slightly more complicated. It must use the information available from the PersistentOperations interface to partition the objects into three sets: insertions, updates and deletes. You'll notice that I'm using an isModified function to further partition updates from unmodified instances. It's possible to do this in the smart list as well by keeping a copy of each original object and then comparing it to the object's state just before the database update. There are disadvantages to this technique, however, depending on the memory required to keep copies of those objects and the processing time required to compare object states. In any case, implementing this is beyond the scope of this article.
To test my Customer implementation, I've included a stateless session EJB that will give it a good workout. Fronting an entity EJB with a "business process" session, EJB is a common design pattern. Here it allows us to include multiple adds, deletes, updates and totals within one transaction. Since the typical EJB server will load and store persistent data on transaction boundaries (load when the transaction begins and store when it ends), this is important for our testing. Obviously, the stateless session EJB isn't a good example of an actual business process.
It isn't difficult to write an efficient, easy-to-use Enterprise JavaBean using bean-managed persistence. Well, what I should really say is that it's not much harder than writing the SQL code that your bean will use. If you need to roll your own persistence for EJBs, there's no better place for the persistence logic than a collection class. In this case we used a list, but the same technique would work for a Set or a Map, or even a tree document, depending on your needs. And if your target market allows you to write to the JDK 1.3, the new Proxy class can increase the expressiveness and effectiveness of your code.
GENBAND has announced that SageNet is leveraging the Nuvia platform to deliver Unified Communications as a Service (UCaaS) to its large base of retail and enterprise customers. Nuvia’s cloud-based solution provides SageNet’s customers with a full suite of business communications and collaboration tools. Two large national SageNet retail customers have recently signed up to deploy the Nuvia platform and the company will continue to sell the service to new and existing customers. Nuvia’s capabilities include HD voice, video, multimedia messaging, mobility, conferencing, Web collaboration, deskt...
Apr. 28, 2015 03:00 AM EDT Reads: 1,923
Sonus Networks introduced the Sonus WebRTC Services Solution, a virtualized Web Real-Time Communications (WebRTC) offer, purpose-built for the Cloud. The WebRTC Services Solution provides signaling from WebRTC-to-WebRTC applications and interworking from WebRTC-to-Session Initiation Protocol (SIP), delivering advanced real-time communications capabilities on mobile applications and on websites, which are accessible via a browser.
Apr. 28, 2015 02:15 AM EDT Reads: 2,004
Temasys has announced senior management additions to its team. Joining are David Holloway as Vice President of Commercial and Nadine Yap as Vice President of Product. Over the past 12 months Temasys has doubled in size as it adds new customers and expands the development of its Skylink platform. Skylink leads the charge to move WebRTC, traditionally seen as a desktop, browser based technology, to become a ubiquitous web communications technology on web and mobile, as well as Internet of Things compatible devices.
Apr. 28, 2015 01:45 AM EDT Reads: 2,334
SYS-CON Events announced today that AIC, a leading provider of OEM/ODM server and storage solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. AIC is a leading provider of both standard OTS, off-the-shelf, and OEM/ODM server and storage solutions. With expert in-house design capabilities, validation, manufacturing and production, AIC's broad selection of products are highly flexible and are configurable to any form factor or custom configuration. AIC leads the industry with nearly 20 years of ...
Apr. 28, 2015 01:30 AM EDT Reads: 5,051
“With easy-to-use SDKs for Atmel’s platforms, IoT developers can now reap the benefits of realtime communication, and bypass the security pitfalls and configuration complexities that put IoT deployments at risk,” said Todd Greene, founder & CEO of PubNub. PubNub will team with Atmel at CES 2015 to launch full SDK support for Atmel’s MCU, MPU, and Wireless SoC platforms. Atmel developers now have access to PubNub’s secure Publish/Subscribe messaging with guaranteed ¼ second latencies across PubNub’s 14 global points-of-presence. PubNub delivers secure communication through firewalls, proxy ser...
Apr. 28, 2015 01:00 AM EDT Reads: 3,883
SYS-CON Events announced today that Vicom Computer Services, Inc., a provider of technology and service solutions, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. They are located at booth #427. Vicom Computer Services, Inc. is a progressive leader in the technology industry for over 30 years. Headquartered in the NY Metropolitan area. Vicom provides products and services based on today’s requirements around Unified Networks, Cloud Computing strategies, Virtualization around Software defined Data Ce...
Apr. 28, 2015 12:30 AM EDT Reads: 1,767
SYS-CON Events announced today that Gridstore™, the leader in hyper-converged infrastructure purpose-built to optimize Microsoft workloads, will exhibit at SYS-CON's 16th International Cloud Expo®, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Gridstore™ is the leader in hyper-converged infrastructure purpose-built for Microsoft workloads and designed to accelerate applications in virtualized environments. Gridstore’s hyper-converged infrastructure is the industry’s first all flash version of HyperConverged Appliances that include both compute and storag...
Apr. 28, 2015 12:00 AM EDT Reads: 4,665
Chuck Piluso will present a study of cloud adoption trends and the power and flexibility of IBM Power and Pureflex cloud solutions. Speaker Bio: Prior to Data Storage Corporation (DSC), Mr. Piluso founded North American Telecommunication Corporation, a facilities-based Competitive Local Exchange Carrier licensed by the Public Service Commission in 10 states, serving as the company's chairman and president from 1997 to 2000. Between 1990 and 1997, Mr. Piluso served as chairman & founder of International Telecommunications Corporation, a facilities-based international carrier licensed by t...
Apr. 27, 2015 11:00 PM EDT
There are lots of challenges in IoT around secure, scalable and business friendly infrastructure for enterprises. For large corporations, IoT implementations are one of the top priorities of the decade. All industries are seeing a competitive need to sustain by investing in IoT initiatives. The value addition comes from improved customer service, innovative product and additional revenue streams. The data from these IP-connected devices can be leveraged for a variety of business applications as well as responsive action controls. The various architectural building blocks of an IoT ...
Apr. 27, 2015 09:00 PM EDT
“In the past year we've seen a lot of stabilization of WebRTC. You can now use it in production with a far greater degree of certainty. A lot of the real developments in the past year have been in things like the data channel, which will enable a whole new type of application," explained Peter Dunkley, Technical Director at Acision, in this SYS-CON.tv interview at @ThingsExpo, held Nov 4–6, 2014, at the Santa Clara Convention Center in Santa Clara, CA.
Apr. 27, 2015 06:00 PM EDT Reads: 4,492
SYS-CON Events announced today that Ciqada will exhibit at SYS-CON's @ThingsExpo, which will take place on June 9-11, 2015, at the Javits Center in New York City, NY. Ciqada™ makes it easy to connect your products to the Internet. By integrating key components - hardware, servers, dashboards, and mobile apps - into an easy-to-use, configurable system, your products can quickly and securely join the internet of things. With remote monitoring, control, and alert messaging capability, you will meet your customers' needs of tomorrow - today! Ciqada. Let your products take flight. For more inform...
Apr. 27, 2015 04:00 PM EDT Reads: 1,934
WebRTC is an up-and-coming standard that enables real-time voice and video to be directly embedded into browsers making the browser a primary user interface for communications and collaboration. WebRTC runs in a number of browsers today and is currently supported in over a billion installed browsers globally, across a range of platform OS and devices. Today, organizations that choose to deploy WebRTC applications and use a host machine that supports audio through USB or Bluetooth can use Plantronics products to connect and transit or receive the audio associated with the WebRTC session.
Apr. 27, 2015 04:00 PM EDT Reads: 1,913
The best mobile applications are augmented by dedicated servers, the Internet and Cloud services. Mobile developers should focus on one thing: writing the next socially disruptive viral app. Thanks to the cloud, they can focus on the overall solution, not the underlying plumbing. From iOS to Android and Windows, developers can leverage cloud services to create a common cross-platform backend to persist user settings, app data, broadcast notifications, run jobs, etc. This session provides a high level technical overview of many cloud services available to mobile app developers, includi...
Apr. 27, 2015 04:00 PM EDT Reads: 1,429
SYS-CON Media announced today that @WebRTCSummit Blog, the largest WebRTC resource in the world, has been launched. @WebRTCSummit Blog offers top articles, news stories, and blog posts from the world's well-known experts and guarantees better exposure for its authors than any other publication. @WebRTCSummit Blog can be bookmarked ▸ Here @WebRTCSummit conference site can be bookmarked ▸ Here
Apr. 27, 2015 04:00 PM EDT Reads: 2,515
Health care systems across the globe are under enormous strain, as facilities reach capacity and costs continue to rise. M2M and the Internet of Things have the potential to transform the industry through connected health solutions that can make care more efficient while reducing costs. In fact, Vodafone's annual M2M Barometer Report forecasts M2M applications rising to 57 percent in health care and life sciences by 2016. Lively is one of Vodafone's health care partners, whose solutions enable older adults to live independent lives while staying connected to loved ones. M2M will continue to gr...
Apr. 27, 2015 03:00 PM EDT Reads: 1,535
Dave will share his insights on how Internet of Things for Enterprises are transforming and making more productive and efficient operations and maintenance (O&M) procedures in the cleantech industry and beyond. Speaker Bio: Dave Landa is chief operating officer of Cybozu Corp (kintone US). Based in the San Francisco Bay Area, Dave has been on the forefront of the Cloud revolution driving strategic business development on the executive teams of multiple leading Software as a Services (SaaS) application providers dating back to 2004. Cybozu's kintone.com is a leading global BYOA (Build Your O...
Apr. 27, 2015 02:00 PM EDT Reads: 1,579
As enterprises move to all-IP networks and cloud-based applications, communications service providers (CSPs) – facing increased competition from over-the-top providers delivering content via the Internet and independently of CSPs – must be able to offer seamless cloud-based communication and collaboration solutions that can scale for small, midsize, and large enterprises, as well as public sector organizations, in order to keep and grow market share. The latest version of Oracle Communications Unified Communications Suite gives CSPs the capability to do just that. In addition, its integration ...
Apr. 27, 2015 01:30 PM EDT Reads: 4,429
The IoT Bootcamp is coming to Cloud Expo | @ThingsExpo on June 9-10 at the Javits Center in New York. Instructor. Registration is now available at http://iotbootcamp.sys-con.com/ Instructor Janakiram MSV previously taught the famously successful Multi-Cloud Bootcamp at Cloud Expo | @ThingsExpo in November in Santa Clara. Now he is expanding the focus to Janakiram is the founder and CTO of Get Cloud Ready Consulting, a niche Cloud Migration and Cloud Operations firm that recently got acquired by Aditi Technologies. He is a Microsoft Regional Director for Hyderabad, India, and one of the f...
Apr. 27, 2015 12:00 PM EDT Reads: 1,678
The 17th International Cloud Expo has announced that its Call for Papers is open. 17th International Cloud Expo, to be held November 3-5, 2015, at the Santa Clara Convention Center in Santa Clara, CA, brings together Cloud Computing, APM, APIs, Microservices, Security, Big Data, Internet of Things, DevOps and WebRTC to one location. With cloud computing driving a higher percentage of enterprise IT budgets every year, it becomes increasingly important to plant your flag in this fast-expanding business opportunity. Submit your speaking proposal today!
Apr. 27, 2015 12:00 PM EDT Reads: 2,329
While not quite mainstream yet, WebRTC is starting to gain ground with Carriers, Enterprises and Independent Software Vendors (ISV’s) alike. WebRTC makes it easy for developers to add audio and video communications into their applications by using Web browsers as their platform. But like any market, every customer engagement has unique requirements, as well as constraints. And of course, one size does not fit all. In her session at WebRTC Summit, Dr. Natasha Tamaskar, Vice President, Head of Cloud and Mobile Strategy at GENBAND, will explore what is needed to take a real time communications ...
Apr. 27, 2015 12:00 PM EDT Reads: 1,801