Archive for the 'Software' Category

Static SQL vs Dynamic SQL

Monday, January 14th, 2008

I have been wanting to write a few technical articles here on the blog, so I’ll start with something that is related with what I have been looking into at work: Static and Dynamic SQL.

From the conversations I have had with both DBAs and developers, it is clear that DBAs prefer static SQL, while developers prefer Dynamic SQL.

The difference between static and dynamic SQL is that static SQL needs to be compiled and bound to the database before application runtime, while dynamic SQL is compiled during runtime. Next, I’ll show a list of pros and cons regarding each one. 

Static SQL

Pros:

  • compile at bind time. Since the statement is compiled only once and before we run our workload, we have all the database resources in order to generate the most optimal query execution plan. In DB2, there are 9 levels of optimization, being 5 the default one. When we bing our application package, we can pick the highest optimization level – 9 – and get the most optimal execution plan. Using a higher optimization level requires more resources for the compile phase, but since our workload is not yet running, we can afford this high resources requirement.
  • security. Security is probably the most common reason why people use static SQL instead of dynamic SQL. Static SQL allows the DBA to set authorization at the package level. For example, consider an application package app1, that provides SQL functionality to select employee’s name and address from the table employees. The DBA can five user JOHN execution privileges on package app1, even if user JOHN does not have SELECT authority on table employees. Static SQL provides a much finer layer of security.

Cons:

  • need to bind before runtime. Although binding before runtime usually allows for more optimized access plans, doing this in a test or development environment can be cumbersome.
  • lack of tooling support. most of current IDEs provide coding assistance with support for APIs like JDBC. The lack of support from development tools discourages the use of static SQL.

Dynamic SQL

Pros:

  • IDEs and APIs: using eclipse to develop Java code that interacts with the database using JDBC or JPA is much simpler than developing a SQLJ application.
  • statement caching. Dynamic statement caching avoids the need to compile the same statement multiple times, increasing the performance to values close to static SQL. However, bear in mind that a cache miss will be extremely expensive.
  • better statistics. Because the statement is compiled at runtime, it uses the latest statistics available, contributing to a better execution plan.

Cons:

  • compile at runtime. There are a few reasons why compile at runtime can be a bad thing:

    • every time a statement is executed, it needs to be compiled, increasing the total statement execution time
    • the compile time will account for the total execution time, so using higher optimization levels may slow down the overall performance instead of improving it.
    • because the statement is only compiled at runtime, errors in the SQL statement won’t be detected until runtime.

As you can see, there are several reasons why you would choose one over the other. There is no perfect solution! But if you ask me, I would suggest the following: use Static SQL if security is your main concern and use Dynamic SQL if ease of development is your main concern.

VN:F [1.8.1_1037]
Rating: 4.3/10 (4 votes cast)
VN:F [1.8.1_1037]
Rating: +3 (from 3 votes)

Popularity: 35% [?]

Harvard and MIT

Friday, November 2nd, 2007


Originally uploaded by Vitor Rodrigues.

Last month I completed the visit of the 4 major US universities that were on my To Visit list. After Sanford and Berkeley during my internship in California, visited Boston this October for a conference and had the opportunity to visit the Harvard and MIT campuses.

While Harvard is a beautiful place to visit with all the fancy coffee shops and restaurants around Harvard Square and a very nice bookstore, that makes you feel you are still in the XVIII century.

As for MIT, not much to see, besides lots of geeks (yes, they are easily spotable) and lots lots of bicycles in the parking lots. Just a few funny buildings like the ones in the picture.

As for Boston city, although at first it looks just like a small size NYC, after a few walks around the city you can feel its own vibe and style. For food, you must try the Italian restaurantss in the North End. For guided tours, the list of attractions listed on the trolleys is just a joke, i.e., “Access to MIT campus and Harvard Square” means: we let you out close to a subway station where you can catch the subway to there :-)


VN:F [1.8.1_1037]
Rating: 2.5/10 (2 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 22% [?]

Persisting XML with OpenJPA

Tuesday, October 23rd, 2007

I’ve been looking at JPA – Java Persistence Architecture and decided to play a bit with OpenJPA using DB2 as the back-end. My goal: to persist and query XML data in DB2, making use of DB2’s pureXML capabilities to query the XML data using SQL/XML’s XMLQUERY() function.

However, while OpenJPA has an extensive documentation, the examples are not always complete and there isn’t a lot of information on the web regarding OpenJPA error determination and solving. So, here are some recommendations for some of the problems I have encountered. The class xml.Address is the one to be persisted as XML in the database using JPA and it is stored as the field shipAddress of the Order objects.

 [java] Exception in thread "main" <openjpa-1.0.0-r420667:568756 fatal user error>
org.apache.openjpa.persistence.ArgumentException:
Type "class xml.Address" does not have persistence metadata. 

Suggestion: Remove the reference to xml.Address from persistence.xml

[java] Exception in thread "main" <openjpa-1.0.0-r420667:568756 nonfatal user error>
org.apache.openjpa.persistence.InvalidStateException:
Encountered unmanaged object "xml.Address@9b2a51" in
persistent field "xml.Order.shipAddress" of managed object "xml.Order@12b3349"
during flush.  However, this field does not allow cascade persist. 
You cannot flush unmanaged objects.
  [java] FailedObject: xml.Address@9b2a51

Suggestion: Make sure you have no @Entity or @Embeddable annotations in xml.Address. The main annotation is @XmlRootElement.

 [java] Exception in thread "main" <openjpa-1.0.0-r420667:568756 fatal general error>
org.apache.openjpa.persistence.PersistenceException:
"xml" doesnt contain ObjectFactory.class or jaxb.index

Suggestion: add a file jaxb.index into your xml package containing all the classes to be persisted as XML: a file containing Address in our case.

VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 19% [?]

Photoshop filters on GIMP

Thursday, October 18th, 2007

For the GIMP users that, like me, keep complaining that Photoshop has so much more filters to do some fancy effects, the agony is over :-)

I just found this today, but it dates back to 2004. There is a GIMP plugin that handles Photoshop plugins. It is called PSPI and it works like a charm on the filters I have tested so far.

Here are the instructions on how to get it working on Windows:

  1. download the binary package from here.
  2. copy the plugin file to “C:\Program Files\GIMP-2.0\lib\gimp\2.0\plug-ins”
  3. start GIMP
  4. click on Menu Xtns -> Photoshop Plug-in Settings
  5. add the folders where you have your photoshop plugins (.exe or .8bf files)
  6. restart GIMP
  7. all the compatible plugins in the folders you specified in step 5 will show up under the Filters menu (*)

This was a new for me, and I’m quite happy as there was a couple of photoshop filters that I like to play with sometimes (just for fun, but still).

(*) For some odd reason, all my plugins appear under the sub-menu “Flaming Pear”, the creators of the first photoshop plugin I loaded into GIMP.

VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 18% [?]

DB2 on Rails update

Wednesday, October 17th, 2007

I’m back to fiddling around with my Ruby on Rails experiments(1)(2). I was able to create a very useful 2-way mapping between Ruby objects and xml data stored in DB2 pureXML. Basically, trying to replicate some of ActiveRecord’s functionality but for XML data. I still find it odd, though, that both ROXML and xml-mapping haven’t had much activity as of late. I’m wondering if there is any new OXM library around that I don’t know of.

Also on the same topic:

  • the main DB2 on Rails website is up and running again, with a revamped design and now using wordpress instead of typo.
  • a new version of the ibm_db driver was also released, containing several bugfixes. Update it through gems (gem update ibm_db) or from here: http://rubyforge.org/projects/rubyibm/ 
VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 17% [?]

DB2 on Mac

Monday, September 24th, 2007

Last week, after my presentation at University of Minho about the DB2 on Campus and DB2 Student Ambassador programs and the pureXML features in DB2, one student came to me and asked me if DB2 was available for Mac. My answer was a ‘no’, but things will change pretty soon. 

My ‘office neighbor’ Antonio Cangiano just made public IBM’s intention of releasing a DB2 Express-C port to Intel Mac. This is one more big step from DB2 Express-C towards the community, after very open licensing conditions, Ruby on Rails driver and adapter, soon-to-come Python and Django driver and adapter, DB2 Express-C orum and DB2 Express-C blog, etc….

 

VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 11% [?]

DB2 Student Ambassador

Saturday, September 15th, 2007

After reading Alcides Fonseca’s post regarding is opportunity to become an MSP and asking whether other companies have similar programs, I would like to introduce two programs related with DB2 that are targeted for university students: DB2 On Campus and DB2 Student Ambassador.

DB2 on Campus: The DB2 on Campus Program is a project designed to promote the use of DB2 in universities. The logistics and delivery of the program is performed between the DB2 Express-C team, and the local IBM Academic Initiative representative. The program consists of the following items and activities:

  1. A speech titled “The role of DB2 Express-C in the Information on Demand World”. This speech explains DB2 9 technology, with an emphasis on pureXML™, and encourages students to use DB2 Express-C, create university DB2 user groups, participate in the DB2 forums, and write documents about DB2. All of these activities can help them to advance their future careers.
  2. Introductory DB2 courses to obtain DBA and developer skills.
  3. Free DB2 books donated to the university library
  4. Free DB2 certification exams offered to the students

I will be at University of Minho on September 19th doing the speech for the DB2 on Campus program. There was not enough time to prepare the full-day event, but if you or someone at your university is interested in having this full-day event happening at your university, please feel free to email me and I’ll put you in contact with the program’s manager in order to schedule the event (my email is vrodrig at us.ibm.com).

There is a DB2 On Campus Facebook group. Follow these instructions to join. 

Subscribe to the DB2 Express-C blog to keep updated on news regarding this free to develop, deploy and distribute database(1). 

DB2 Student Ambassador: This is a program for individual students that want to promote the use of DB2 at their education institutions. Though the program is voluntary, it gives students a chance to learn more about DB2, develop presentation skills and marketing skills. All of these skills will be valuable in their careers. At the end of the program, the student will receive a letter of recommendation from IBM including all the details of the activities performed. The more activities performed, the better the letter of recommendation! We hope this will help the student get a job more easily in the future.

I consider this to be an excellent opportunity to get involved and interact with developers from a huge project like DB2, distributed across Toronto and Silicon Valley laboratories.

More information  about this program can be found here: http://www-306.ibm.com/software/data/db2/express/students_programs.html#ambassador

 

Although I’m only familiar with the DB2 programs, for the ones interested, there is also an IBM Academic Initiative program, focused on Open Standars, Open Source and IBM resources for the academic world.

The opportunities are out there, so just grab the one you like and boost your career :-)

(1) Yes, it is the fully loaded version available for free, with one limitation: it can only use up to 4GB of RAM :-)  

 

VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 11% [?]

XML and Databases

Monday, August 13th, 2007

I just stumbled across an excellent resource regarding XML technology in databases. Ronald Bourret has the most extensive research I’ve seen on the global XML and databases state of the art. It has an extensive list of databases with XML support (native or by means of extenders/adapters) recently updated and several papers on XML and databases

A must read, that I will be consuming over the coming weeks. 

VN:F [1.8.1_1037]
Rating: 6.0/10 (1 vote cast)
VN:F [1.8.1_1037]
Rating: +1 (from 1 vote)

Popularity: 8% [?]

Recent readings

Tuesday, August 7th, 2007

 Latest articles checked out from my “toread” folder in delicious:

VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 14% [?]

XML Mapping in Ruby

Thursday, July 5th, 2007

Dear lazy web…

I’ve been playing with Ruby and XML lately, and one of the key features I need to use is XML mapping from XML to Ruby objects and vice versa. However, both ROXML and XML::Mapping do not seem to be very active at the moment. Both forums contain un-replied questions  several months old, and I can’t find any examples that are not a couple of years old.

Is there any XML Mapping library for Ruby that is currently active(*)? XML::Mapping was serving me good enough, until the moment that I needed some of the documented features and found that they are not supported in the current release :-(

 (*) by active I don’t mean it needs to be in exclusively in code development, but at least with some recent activity in forums, documentation, examples, etc..

VN:F [1.8.1_1037]
Rating: 0.0/10 (0 votes cast)
VN:F [1.8.1_1037]
Rating: 0 (from 0 votes)

Popularity: 10% [?]