Skip to main content
Participant
April 7, 2009
Question

Should every SQL query have its own event and command?

  • April 7, 2009
  • 2 replies
  • 1873 views

Hello,

I am developing an application using Cairngorm. My app uses SQL databases.

I'm creating a separate event and command for each SQL query my application requires. I end up with many events  and commands - twenty different event/command pairs and I'm not even done yet.

I was wondering if this is the right way to go, or if somehow similar SQL queries should be grouped together in the same event/command, and if so, how would I implement that elegantly?

I've never used Cairngorm before so I want to make sure I do it correctly.

Thank you for your time and any assistance you can offer.

This topic has been closed for replies.

2 replies

Participant
January 20, 2010

From my point of view, writing any SQL query or making queries directly from the presentation layer (eg. flex) to the db server it's almost always incorrect, awfull and maybe even insecure. The client layer should be more independent from the implementation layer as for instance the db server you are using. Instead you should call services on the server side and then they should have a DAO layer o whatever where the queries are done. You could then invoke one of this services and pass parameters that indicates what you want to do. (except you are using remoting where you will be invoking methods directly)

Consider the case where you have a Java implemented service layer, you could be using hibernate to access the database and not writing a single line of SQL (maybe some HQL) and then you could do all the queries you need and return the beans retrieved from the database to the client layer using AMF3 and it's serialization/deserialization mechanisms. In a future you could modify your app to use JPA and then this layer use hibernate, then you client layer will remain the same the only changes will be done under the DAO layer.

So again, in my opinion, db server should never be accesed directly from the presentation layer (Flex, Air or whatever) but from the backend services and this sould be completly abstract to the client layer. I have seen some people trying to do SQL queries from Flash but that it's giving a task to the Flash player it has never been intended to do. A miss use of the thin client the Flash Player is and an bad architecture.

It would be great to hear others opinions.

Participant
April 17, 2009

Hi,


In SQL, it is a good practice to send parameterized queries. Some of the underlying databasescache query results for better performance. Considering that you should use this practice, you can write events based on Types of queries like "Select", "Update", "Create" etc.


Your events can contain parameters like table name, array of column names and array of values. Command can then create a query and send it off to the server.


This will also reduce the number of classes you create.