Wednesday, April 28, 2010

When manually dispatching an event, using uiComponent.dispatchEvent(your-event), you need to add listener to the same component uiComponent. So, uiComponent.addEventListener(type,handler) will work, but uiAnyOtherComponent.addEventListener(type,handler) will not work.

The state changes-related transition effects have to correspond to the type of changes between the corresponding states. Example: I had a vertical group with two components. In State 1, both components show. In State2, Comp1 is not included. I set a Resize transition for Comp1 and a Move transition for Comp2. The effect was surprising: when state changed, Comp1 disappeared and appeared at the bottom of the screen. There it was re-sized. The right fix was to change Comp1: instead of includeIn=State1, I did height.State2=0. That did the trick.

Constraint-based layout is supported only in a container with BasicLayout. If you want to use it inside a VGroup, for example, you can put it inside a Group for which you don't specify any layout (BasicLayout is the default).

Monday, April 19, 2010

When architecting an RIA (aka Web 2.0) application, you have to decide how do you implement the persistence layer. Using the ORM is a standard nowadays, so it's given. Question as to which ORM to use, got easier with strong acceptance of the Sun's JPA standard by the industry. But, how do you apply ORM in an RIA application is not a question with just a one obvious answer. On one side, the choice of the framework (and the architecture with it). This is presented in section 2. Section 3 presents another aspect of persistence layer: session management, that is how you actually use ORM to persist detached objects (detached, because they are received from outside of the application, namely from the client, for example a Flex client).

2. ORM in an RIA Application

Popular options are listed below. Each with advantages and disadvantages.

2.1. Just-JPA Approach:

LCDS, BlazeDS or another Flex remoting framework

JPA (in general: ORM) on the server-side, with an object mapper like Dozer

Pros and Cons:

Pro: Simple and a popular choice.

Con: Doesn't let you take advantage of ORM's lazy loading and lazy initialization.

2.2. LCDS with Built-In Hibernate Adapter:

This solution requires you to purchase a commercial heavy-duty Flex remoting framework Adobe LCDS (LiveCycle Data Services). If you go this way, to integrate it with persistence layer, you create a Hibernate assembler class on the server (Java) and point the LCDS destination to it, as described here.

Provides a complete open-source solution. Described in a nutshell in comment to this article. More complete information, and a comparison with LCDS-with-Hibernate-assembler option, can be found in this article by the same person (as the comment), William Drai. This article has also more general, highly useful, background on the topic as a whole.

Pros and Cons:

Pro: open-source; no vendor lock-in.

Cons: unknown

3. Persisting Detached Objects

The three most common applicable persistence design patterns are (as described by Hibernate documentation):

session per requestThe most common solution. A single Session and a single database transaction implement the processing of a particular request event. Do never use the session-per-operation anti-pattern.

session per conversationOnce persistent objects are considered detached during user think-time and have to be reattached to a new Session after they have been modified.

session-per-request-with-detached-objectRecommended. In this case a single Session has a bigger scope than a single database transaction and it might span several database transactions. Each request event is processed in a single database transaction, but flushing of the Session would be delayed until the end of the conversation and the last database transaction, to make the conversation atomic. The Session is held in disconnected state, with no open database connection, during user think-time.

Let's assume we have an application an RIA with stateless EJB's on the server side. Each request gets a new EntityManager injected. I suggest the following approach to implement session-per-request:

if we receive a new object, persist it using
entityManager.persist(entity)

if we receive an object, that is already in the database, use
entityManager.merge(entity)

There is one narrow case, when this wouldn't work as expected: when we have a bidirectional association between Invoice and InvoiceDetail and we receive and invoiceDetail with the field invoice set to null. If we apply the method as above, the merge() will reset the invoice in invoiceDetail to null, while the field invoiceDetails in invoice object will continue pointing to invoiceDetail. However, I consider this not a practical case.

4. Conclusion
So, a simple starting point that I recommend for your RIA application is to use just JPA with a session-per-request persistence pattern. It can be as simple as:

Previous Flex component architecture and component set was MX, aka as Halo.

Spark components extend the MX class mx.core.UIComponent, and so Spark containers can hold MX components and vice-versa, and Spark and MX components can live side-by-side. The same component lifecycle methods, properties, and events that existed for the MX components apply to Spark components.

Skinning

Three key elements— data, parts, and states—define the skinning contract upon which Spark is founded:

Every Spark component class:

defines the data the component expects,

defines the constituent parts that make up the component (aka skin parts), and

defines the states the component can enter and exit; responsible for all of the event handling needed to identify when a state change has occurred and ensures the component is put in the right state.

The corresponding skin class:

how that data is visually displayed,

how the parts are laid out and visualized (it instantiates the parts), and

what the component looks like as it enters and exits different states.

New Capabilities of Spark Architecture

Effects in Spark: faster and more capable; can be invoked directly within Spark skin classes through state-based transitions.

New layouts

APIs for robust 2D and 3D transformations,

the ability to easily implement custom layouts

assignable layout

FXG and MXML Graphics: graphics library that captures drawing primitives as simple MXML tags. FXG is a declarative XML syntax for defining vector graphics in applications built with Flex and can be created by Adobe Illustrator (or manually) and understood by other Adobe CS tools as well as by FlashPlayer (and probably created and read by Catalyst).

What Next
For more information, read references from the base article by Deepa Subramaniam. For examples and details on skinning read article by Ryan Frishberg. For more information on FXG, read this Adobe well written documentation.

Here, I have annotated the property, rather than the getter (not shown for brevity), since it feels more intuitive to me. I don't know if there is any advantage/difference of one vs the other other than my personal preference. The "@GeneratedValue(...)" annotation for primary key in JPA entity definition is not optional, as I expected. Using just the "@Id" annotation results in the primary key being not set (set to 0).

Can JPA be used to create and index? Yes and no. Not in general. But it provides a limited capability. To create a unique constrain on a table, use @UniqueConstraint(columnNames={"EMP_BDAY", "EMP_NAME"})

How to specify the character column type length? Use @Column(length=50).

What the client can understand about the remote exception, in case the EJB bean fails? The remote exception is wrapped in a EJBException and returned to the client. For example, if the password for the DB is incorrect, the org.hibernate.exception.GenericJDBCException will be returned with a message "Cannot open connection" (when Hibernate is used as JPA provider).

Conclusion A few things to try in the next proof of concept:

test the rollback function, if second of two persistence operations failed when both are in the same method of the BookManager class.

For a good explanation of all options, other than ThreadLocal, see Hibernate document. Note that EJB, as well as JTA, are available even outside the J2EE container as a module. Also, supposedly, the Spring Framework can be easily used just for the functionality you decide to use from it and it doesn't require the application to use all parts of this framework.

Monday, March 8, 2010

What is Android Context class? It's "an interface to global information about an application environment. This is an abstract class whose implementation is provided by the Android system."

The native Android OS support for testing is based on jUnit 3. Don't try to use jUnit 4. The results are not predictable. I had the first test run fine, but no more tests would finish.

Testing support:

Use ActivityInstrumentationTestCase2 for functional testing of a single Activity. The selected activity will be created and managed by the system as specified by the regular activity lifecycle. Tests can interact with the UI widgets to imitate user actions.

Use ActivityUnitTestCase to run unit tests of an isolated activity. Activity under test will not be subject to regular activity lifecycle.

If you see a problem of type error: device not found and shutdown the adb.exe process. It will restart automatically and try to reconnect to the device. Sometimes, starting the intended Instrumentation on emulator (an option in Dev Tools application) does it all for you.

If adb does not connect after restarting it (shows "DeviceMonitor]Connection attempts: 11..." and LogCat nic nie pokazuje), restart PC.

Tuesday, March 2, 2010

This is continuation of my blog on this topic. I'm adding the solution to the questions/issues left out in that first blog as delineated in the last part of the blog. Actually, this effort wasn't successful. I wasn't able to make it work. Although made a good progress, I had to go back to the approach presented in my previous blog. This post is just to document what I was able to achieve.

JTA
Switch to use JTA, instead of native JDBC transactions. All new application servers support JTA natively. With JTA, the session is bound to the transaction. If you call sessionFactory.getCurrentSession(), anytime between userTransaction.begin() and userTransaction.commit(), a session bound to this transaction is returned. User transaction is usually obtained via JNDI. So, an example of code:

Sun/Oracle's J2EE 5 SDK is installed in small pieces. Unlike previous versions of J2EE, there is no j2ee.jar. And so, pieces of it are installed in glassfish\modules folder, as separate jars. For example, the JTA stuff is installed as jta.jar (the implmementation stuff, com.sun....* classes) and javax.transactions.jar, which holds the core of the JTA API.

to return an error code from the restfull webservice, throw a new WebApplicationException(Response.Status.NOT_FOUND), for example. This one would return 404 error. No Need to declare the jersey handler method as "throws ...".

To pass an object retrieved via Hibernate as a response from a webservice, it needs to be serializable. But objects retrieved this way have additional members and so they need to be converted to a pure entity object (Person, in my case). I have used the Dozer library for this purpose (see the code below).

The entity classes (Person and PersonCollection, in my example)need to be annotated with @XmlRootElement.

I'm not sure where the Hibernate session should be closed. I don't think this can be done at the end of each handler method.

How to use JTA for transaction management instead of direct JDBC transaction management?

Most of the Hibernate-specific code should go into a DAO, with most of it into a generic DAO. But the recommended by Hibernate documentation generic DAO is defined in terms of state-oriented data access API (makePersistent() and makeTransient() methods), which are less intuitive for me. What is the advantage of using them and how to use them from CRUD operations?

Wednesday, February 10, 2010

In most data models, there are columns that should take values only from a limited set. For example, a state of License (as in our current project) may only take three values: AppliedFor, Granted or Denied. This kind of restriction is part of what is called Domain Level Integrity. How do you implement it?

Old Way: Separate Table

I used to create a separate table for the allowed values. It can be done, but this table has only couple records in it, is rarely updated and using a whole table for this is almost an overkill. Also, you end up writing more code to manipulate it.

New Way: SQL Rules

There is an SQL construct purpose of which is exactly this kind of constraint: SQL Rule (for Sybase docs: see this). An example:

Saturday, January 2, 2010

Recently, I have been exploring the landscape of web application development a little but. Here are some of the results. Comments are welcome. What is the real trend?

Overall Look
Simple. I have used indeed.com trends tool to compare number of jobs openings for major web application development platforms and technologies. Result is below:

Some conclusions that seem obvious:

Major development platforms had a hit in mid-2008, but recently are slowing down. Note, that the latter can't be explained with economy, since the graph shows the percentage of job postings, not the absolute numbers. Possibly, hiring in IT slowed down as compaed to other areas, though.

Definitely, the Web2.0 (RIA) technologies are experiencing the strongest, or better to say the only growth. Look at Ajax. More analysis on this below.

Now, to verify this result, let's see the results from google.com/trends.

Server-Side Technologies
This comes from google.com/trends:

Server-Side Technologies

One technology, I have definitely missed on the indeed.com side, it seems, is the PHP. A strong player.

Client-Side Technologies

Client-Side Technologies

The most surprising conclusion from the graph above is that Flash technology is so much above all of the rest. And it's significantly more obvious than on the job openings analysis. That may mean, that Flash is coming to the market as a strong candidate. However, since flash is not necessarily used for application development, I am adding another graph, with flex web instead of flash.

RIA (Web2.0) Technologies

Here. it seems we can see the currently strongest players. Ajax, which, unfortunately is split among many libraries, is still the front runner. However, it seems to give in to Flex and Silverlight. That wouldn't be a big surprise, since Ajax based on JavaScript is a rather low-level development hack, only somewhat improved by using an Ajax framework.
Finally, one more graph. It comes from indeed.com. A comparison of job openings for Flex, Silverlight and GWT developer jobs:

And, just for a comparison, a sample of mobile development job trends:

Conclusion
So, that's it for my analysis. What do you think? What is the future of web application development? Specifically: