Squeak and MySQL

Recently I tried to use Squeak and MySQL. The Jdm classes that I pulled down from package universe got me connected just fine but there was no transaction support in the Jdm code. I wanted to begin, commit and rollback transactions. I added this behavior by doing the following.

1) I added this code to my subclass of JdmConnection in the class initialize method. This makes it so the Jdm infrastructure will allow you to execute a query that starts with these phrases (START, COMMIT, ROLLBACK).

JdmFactory40 instance queries
     at: 'START' put: #(#update);
     at: 'COMMIT' put: #(#update);
     at: 'ROLLBACK' put: #(#update);
     yourself.

JdmFactory41 instance queries
     at: 'START' put: #(#update);
     at: 'COMMIT' put: #(#update);
     at: 'ROLLBACK' put: #(#update);
     yourself

2) I created helper methods on my JdmConnection subclass to actually do the begin, commit and rollback:

begin
     self createStatement executeQuery: 'BEGIN'.

rollback
     self createStatement executeQuery: 'ROLLBACK'.

commit
     self createStatement executeQuery: 'COMMIT'.

I ended up not using MySQL (not yet) because I decided to just use some cheap xml persistence until our business outgrows it.  But, I’m sure I will eventually end up using this code again.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s