dpHibernate - Hibernate lazy loading with Adobe BlazeDS

One of the biggest problems with working with data in a RIA/Flex application is that it's all or nothing. You either need to get all of the data or write a lot of code to return the data in multiple requests. The problem is that good design means that we want to design our data object to match the data, not the UI. For instance a User might have an array of Orders which each have an array of Items. Seems simple enough, right. The problem is that this is a large complex objects which could require a query that joins multiple tables when returning data to your application. No big deal if you want to display all of the data. But if you are just trying to output the users name and email in a search result screen then this is a huge performance hit.

Luckily there is a solution, It is called lazy loading. JSP developers, which use the java hibernate framework, have been able to use lazy loading for years. But until now this did not work with remote client applications like Flex. For those of you who have tried, I'm sure your familiar with the dreaded LazyLoadingException. Frustrating huh. Lazy loading let's your define a complete object model, such as a User with an array of Orders. But only return the data you are actually using in your presentation layer (Flex). Avoiding that all or nothing data problem that is so common.

I'm happy to announce a new Digital Primates open source project. dpHibernate, add support to BlazeDS for Hibernate lazy loading. You can find both the java and the ActionScript parts of the project here: http://code.google.com/p/dphibernate

If you're not familiar with hibernate, check out http://www.hibernate.org. At a real high level, Hibernate is a java ORM tool, which lets you map java beans to a relation database. Hibernate does all of the sql work for you.

So how do dpHibernate work? dpHibernate is actually a combination of two code bases. First, there is a custom java adapter for the BlazeDS server. This HibernateAdapter understands the hibernate proxy objects and knows how to convert them into a special dpHibernate proxy which the AMF serializer will ignore and not try to initialize. This is how the proxy objects are able to go back to the client without getting the LazyLoadingException.

The second part of dpHibernate is an ActionScript library which gives your application the code it needs to understand these dpHibernate proxy objects. This AS library has the code to manage your ActionScript beans and knows how to call back to the server to load a proxy once that object has been touched, usually with a binding expression.

In case your wondering, how does dpHibernate differ from the hibernate support in LiveCycle Data Services ES? For one dpHibernate doesn't require LCDS it works with the open source BlazeDS server. The other big difference is that hibernate support in LCDS requires you to duplicate the lazy associations in the services-config.xml and you need to use an Assembler class to get the hibernate objects. dpHibernate let's you call any java method and return any hibernate object.

So check it out, if you can use it I'd love to hear about it. If it doesn't work for you I want to know about that too. And as with all open source projects this one can use as many eyes as possible on it too. If you find any hibernate configurations that don't work let me know. Or better yet, send me a test case with the right hibernate mapping files to recreate the issue.

Thanks, ---mike nimer mikenimer at yahoo.com

Making air do crazy things

So technically Adobe Air doesn't have direct OS level integration, we can only hope the next version does. But that doesn't mean it's not possible. Louie Penaflor (a member of the Digital Primates team) has still been able to make AIR bend to his will, with some help from the Artemis project. He has written an application that let's AIR control his scanner. So from inside his application he can scan his travel receipts.

Read all about it here: http://www.restlessthinker.com/blog/?p=69

FlexCamp Chicago presentation and examples

First I just want to thank everyone who attended the FlexCamp in Chicago. As promised here is the presentation I did and the two examples I walked through.

Presentation
Examples
(these use the sample database that ship with ColdFusion)

Flex Camp Chicago! - limited space available, sign up now while you still can

Are you a flex developer? Are you still learning new things about flex? Are you planning on learning flex? Do you want to meet other flex developers in the area? Do you live near Chicago, IL?

Then you need to register and come to the next Flex Camp right here in Chicago, on Jan 18th, before it sells out. Plus you get a FREE COPY OF "Adobe Flex 2: Training from the Source" - thanks to PeachPit Press.

Flex Camp is a one day, all day, conference about Flex with something for everyone - Flex Component development, Air development, CF Integration, and Java Integration. Plus I'm a speaker!

And it's easy to get to, Flex Camp will be located at the Illinois Technology Association, 200 S. Wacker Drive, 15th Floor. Which is right by Union Station in downtown Chicago.

Click here to learn more and register:
http://www.flexcampchicago.com/

Tapper, Nimer & Assoc. + Digital Primates IT Consulting

I'm happy to finally be able to tell the world that Tapper, Nimer & Associates and Digital Primates have decided to join forces. Now that the lawyers are done the merger is complete.

The new company will be keeping the name Digital Primates. If you'd like to learn more about Digital Primates check out our web site at http://www.digitalprimates.net

It's an exciting time in the RIA world and for us it just got a lot more exciting!

P.S. We are looking for a few great flex developers and flash video experts. If you're interested send me your resume.

dpUnit = new flex unit testing framework

[Update] Correction: The name is dpUint, not dpUnit. I guess I'm so used to all of XUnit frameworks I didn't even notice the spelling difference at first.

In case you didn't see this earlier Mike Labriola from Digital Primates (http://www.digitalprimates.net) has released a new open source unit testing framework for flex this week ( dpUnit )

Why is this cool?:

  • 1. Support full testing of Asynchronous actions (correctly).
  • 2. Trigger and listen for any event in your application and validate it in the unit test.(UI, Validation, or server).
  • 3. hain a series of actions into a sequence.
    This means you can define a series of application actions in your test case and they will be executed in sequence during the test. But even better - you can also add waits between these steps so the test case will not perform the next step until some event has been fired from the current step or timed-out and failed. For instance until a property has been set (VALUE_COMMIT event).
  • 4.You can write UI Component unit tests!!!!
    This is unique to dpUnit - With dpUnit you can instantiate a new UI Component and trigger events and test that the UI Component actual does what it should. Instead of just testing individual functions or classes


    For instance if have a edit form component, you can create a new instance and set the values of the different form fields. Then you can trigger the validation and run asserts in your unit tests to check that the form validation happened correctly.

Let me say this again, you can write UI Component Unit tests!.

Download it here

Baby meet world - world meet baby nimer!

No one ever called me the quickest blogger, but I'm excited to announce the newest nimer in the world.



Kayden Michael Nimer
Born: Oct 29th 2007
7lbs 10oz - 21" long


Kayden is a perfectly healthy baby boy and both mom and are baby are doing great. So being a new dad I can't stop thinking about the question where do I start with all of these cool toy options? :)

Flex Tip - Trigger validation when submitting form

I just noticed a common pattern in the way I do validation, so I thought I would share. (in case you didn't know this already)

The validators are great at telling the user what is required or failing validation as the tab through the form. However they don't actually block the user from submitting the invalid form. But there is a simple way to do this with the validators.

1. Group all of the validators into an MX:ARRAY tag, and give it a unique id. - I usually use "validators"

<mx:Array id="validators">
   <mx:StringValidator source="{abbreviations}" property="text" required="true"/>
   <mx:StringValidator source="{subcode}" property="text" required="true"/>
   <mx:StringValidator source="{name}" property="text" required="true"/>
   <mx:StringValidator source="{letterType}" property="text" required="true"/>
   <mx:StringValidator   source="{scheduleType}" property="text" required="true"/>
</mx:Array>

Since the validators are now all grouped in an Array, you can call the Validator.validateAll() function to check them all at once.

2. Use this if statement in the click event of your form submit button to check the validators before submitting. You can also add this if check inside your doSave() method too. whichever you prefer.

if( Validator.validateAll(validators).length==0 ){ doSave() }

<mx:Button
   label="Save"
   click="if( Validator.validateAll(validators).length==0 ){ doSave() }"/>

Suddenly I don't want anything to do with plastic products.

"A vast swath of the Pacific, twice the size of Texas, is full of a plastic stew that is entering the food chain. Scientists say these toxins are causing obesity, infertility...and worse"

There is everything wrong with the fact that this pile of trash exists. And even worse, there is more than one in the world.

I don't even know where to begin with a solution. But cutting back on the use of plastic seems like a good place to start. Everything doesn't need to be made out of plastic, I know I prefer the glass coke bottles to the plastic ones. Maybe some mandatory recycling programs are needed. I just hope something changes other wise the world 20 years from now could be a nasty place to live.

Read article

I want to see this - looks like I need to go to Berlin

"Placed at the lobby of the Radisson SAS Hotel in Berlin, the 25 meters high AquaDom is the largest cylindrical aquarium ever built." http://fogonazos.blogspot.com/2007/01/aquadom-worlds-largest-cylindrical.html

More Entries

BlogCFC was created by Raymond Camden. This blog is running version 5.9.001.