Thursday, December 10, 2009

reserved words in MVC

There is no other words to express my disappointment with object relational mapping framworks than: woeful

I have played with three MVC frameworks (Catalyst/perl, rails/ruby, grails/groovy) and by one metric, Rails is pittyful. That metric is narrow but significant (in my opinion) and is described below.

The object-relational mapping frameworks in question are:

Catalyst/DBIC
Rails/ActiveRecord
Grails/Hibernate

My issue is that all these frameworks have implicit 'reserved words'. These typically throw an obscure error if you use in your Models because they collide with either framework or DB reserved words.


Let me draw up a table:

Framework
# reserved words
notes
DBIC
0 + db dependent
DB reserved words are not permitted.
Hibernate
0 + db dependent
DB reserved words are not permitted.
ActiveRecord
7 + db dependent
based on Reserved words in Rails blog post from 2007

So, there is an important uncertainty here: DB reserved words.

Irrespective of db reserved words, the frameworks differed on DB reserved words - so your models aren't portable across DBs. Am I alone in feeling this is a real lost opportunity for relational mapping frameworks?

I have still not seen a reason why these 'reserved words' restrictions exist
All (?) decent DBs will (I think) allow you arbetary table names with by quoting db names...
From an architecture perspective, having reserved words for something which is supposed by be abstract is just perverse.

I await the end of 'reserved words'.

UPDATE: This post is poorly researched. I discovered an additional resource in a blog post by Daniel Butler. However, my experience still points to Catalyst being an good choice of MVC framework when dealing with large legacy databases.

Sunday, December 6, 2009

postgresql search_path with ruby on rails

I studied (amongh other things) electrical engineering at Univsrity. One of the lectures said that you only need one forumal to master the subject: V=IR. However, the lecture warned, you have to know that forumla inside out.

Indeed, you could argue that V=IR is a simplification of Maxwells law, so V=IR not only covers you for EE, but a large chunk of physics (astro, plasma for example) as well.

Some times, I think MVC frameworks are similar.

Anyways... .I'm finding myself using Rails today. I've used it before with some success but didn't like the way it wanted to dominate the DB. My current thinking is that this approach is alright unless you want to integrate a legacy DB.

I'm integrating a legacy DB. It's in PostgreSQL and it uses schema namespaces. Namespaces are really worth the effort. They look great if you use PgAdminIII.

I struggled for a hour or so with my namespaces and then I discovered that I could include a search_path in ./config/database.yml. Now everything is working well again.

Saturday, December 5, 2009

discovering namespaces in postgresql

I've been working on a project with a friend. We're using PostgreSQL for our db...

I thoughtfully prepared the DB locally. I then did a complete dump of it and gave it to my chum...

However, I hadn't anticipated a few things:
  1. I didn't tell my friend the username I had used when creating the database. The PostgreSQL dump had helpfully included a bunch of 'ALTER TABLE, OWNER TO' commands. If you haven't anticipated this - and the user doesn't exist - you will end up with a bunch of problems when ingesting the dump.
    Proposed solutions:

    1. Create a user with the name recorded in the dump file before ingestion
    2. when doing a pg_dump, add the --no-owner flag.


  2.  I didn't tell my friend that I have used schema in the db. Once they had got over the first problem, they were greeted with an apprently empty database! If you don't set your search_path to add the relevant schema names, \dt will tell you 'no relations found'
    Proposed solutions:


    1. Tell my friend the names of the schema that i've used - maybe even in the form of a SET search_path=newschema,"$user",public; command.
    2. Let my friend grep the dump file for 'search_path'.
    3. Let my friend figure out the relevant names of the schema by having them do a SELECT * FROM pg_namespaces;



I think I could improve on the namespace discovery query, possibably by just suggesting that my friend does a SELECT * FROM pg_tables; which seems to reveal more useful information.

UPDATE: after some more playing around, I've discovered that I'll will save myself alot of time by editing the dump file to remove all the 'alter to' commands. One it is ingested, the resulting db requires alot of effort to manipulate all the permissions.

Wednesday, November 25, 2009

maven, fedora.

I've been tipped that Maven is worth the learning curve.

I had a go, on Fedora 11. I can't wait for Fedora 12.

My first tip, is download and install locally: maven 2.2.1.
Install this into /usr/local/maven...

Use that in your Eclipse/NetBeans.

I'm on holiday for a few days... but I will post on how to get Eclipse and NetBeans building a distributable (all dependencies included) jar from the IDE when I return.

In conclusion: Maven is worth the learning curve.

UPDATE: After reflecting on actual use of Maven, I can add the following:

  1. Because it manages the build process, the IDE does not manage the build process. This means that you reduce your dependence on a given IDE. The project I'm working on is now developed by NetBeans and Eclipse folks. At the same time.
  2. Because it manages the build process, you are not dependent on IDE specific tools to build your distribution Jar. I like One-Jar but it is an extra dependency.
  3. By allowing you to collect all dependent code in your own repository, Maven enables a new level of technical management to be applied across a project, group, division etc.

Thursday, November 19, 2009

vlc, jackd no audio

I've been playing with Jack.

I'm feeling like I should always have it running since it works pretty well on the machine i'm using (xubuntu 9.10) and I'm going to want to use some audio production applications in future.

But, today I wanted to play a movie in VLC.

The sound didn't work and patchage didn't show 'vlc'. A brief search and I discovered that there is a jack plugin for vlc.

apt-get install vlc-plugin-jack

fixes that... Then within VLC, you need to switch to jack output:

tools->preferences->audio output label 'jack audio output'

then, I had to switch to 'show settings' all.
Open the audio->output modules->jack tree
and check the 'automatically connect to writable clients'

This made it work. I expect I'm going to experience some problems when I have more than one 'writable client', but I'll burn that bridge when I get to it.

Wednesday, November 4, 2009

basic http auth with Shiro in Grails

A quick note:

I found a blog nice simple recipe for basic http auth using Shiro in Grails. However, since this was published, JSecurity has been renamed Apache Shiro and so some minor changes need to be made at the end of the blog.

I posted them as a comment to that page but will repeat them here for good measure:

the last additions to Config.groovy when using Shiro should be:
security.shiro.filter.config = """
[filters]
authcBasic = org.apache.shiro.web.filter.authc.BasicHttpAuthenticationFilter
authcBasic.applicationName = Demo app name
 
[urls]
/rest/** = authcBasic
"""

Monday, November 2, 2009

Grails, Shiro, addToPermissions() error

I've been playing with Grails with an eye to using it on a new project.

Apache Shiro looks like a suitable security framework for me so I thought I'd use it right from the off. There is even a plugin for Grails to simplify installation.

I discovered that you still have to create your own shiro.jar from the shiro source - but that was relatively straight forward....

[... once I had downloaded a new version of Maven (Fedora 11 packaged version wasn't recent enough)....]

So, once I had installed shiro.jar, and the plugin, I decided to run:
'grails create-db-realm' and
'grails create-authcontroller'
and added bootstrap code according to the plugin advice

ASIDE: for the purposes of just playing around. A better choice for 'playing around' is to do:
'grails quick-start'


If you followed the same route as me, you may have experienced:

Caused by: groovy.lang.MissingMethodException: No signature of method: static groovy.lang.MissingMethodException.addToPermissions() is applicable for argument types: (java.lang.String) values: [*:*]

The fix I arrived at is to add the line:
static hasMany = [ roles: ShiroRole, permissions: String ]
to ShiroUser.groovy so it becomes:

class ShiroUser {
String username
String passwordHash

static hasMany = [ roles: ShiroRole, permissions: String ]

static constraints = {
username(nullable: false, blank: false)
}
}


This got me past this error, however since I feel that I still don't properly 'get it', I expect more issues (and possibably blog posts) in the future!