Sunday, May 27, 2007

ActiveRecord-JDBC db:schema:dump

AcitveRecord-JDBC JTDS db:schema:dump

I have a MS-Sql Server DB that I would like to test out under JRuby (0.9) and ActiveRecord-JDBC (0.3.1). I'm using JTDS. Two problems I ran into, and the patches that to fix them:

  • The first problem is "no type for date", and the fix has been posted somewhere by can-remember-who: add the bold line to ../ActiveRecord-JDBC-0.3.1/lib/active_record/connection_adapters/jdbc_adapter.rb
:date => [ lambda {|r| Jdbc::Types::DATE == r['data_type'].to_i},
lambda {|r| r['type_name'] =~ /^date$/i},
lambda {|r| r['type_name'] =~ /^datetime$/i}],

  • The next problem occures when I try to do a "rake db:schema:dump". I've search the web but failed to come up with any solution. There is actually a multitude of related problems:
    • method indexes is no defined in ../ActiveRecord-JDBC-0.3.1/lib/jdbc_adapter/jdbc_mssql.rb. So I simply copy it from jdbc_mysql.rb:
#### copy from mysql ###
def indexes(table_name, name = nil)#:nodoc:
r = @connection.indexes(table_name.upcase)
end
    • with the above modification, the tables are dumped in the resulting schema.rb (althought it also dump a bunch of system-tables and numeric(xx,yy) columns are not defined properly with the correct precision and scale, I could live with that for now). But all index tables failed. This look like a peculiarity with the JTDS driver that is not properly handled by jdbc_adapter. Here is the fix to jdbc_adapter.rb:

def indexes(table_name, name = nil)
metadata = @connection.getMetaData
unless String === table_name
table_name = table_name.to_s
else
table_name = table_name.dup
end
table_name.upcase! if metadata.storesUpperCaseIdentifiers
table_name.downcase! if metadata.storesLowerCaseIdentifiers
resultset = metadata.getIndexInfo(nil, nil, table_name, false, false)
primary_keys = primary_keys(table_name)
indexes = []
current_index = nil
while resultset.next
# index_name = resultset.get_string(Jdbc::IndexMetaData::INDEX_NAME).downcase
# The first resultset seems to contain information other than that of a index's column. INDEX_NAME is null.
# And you get a nil.downcase not defined
index_name = resultset.get_string(Jdbc::IndexMetaData::INDEX_NAME)
# just ignore if index_name is null
next if !index_name
index_name.downcase! if index_name
column_name = resultset.get_string(Jdbc::IndexMetaData::COLUMN_NAME).downcase


Note that the above fixes are more of a hack than a real solution.

I'm actually using Dr. Nic Magic Models on the legacy SQL Server database. I may blog about that when I find time for that.

Sunday, March 4, 2007

Upgrading to Webwork 2.2.5

I've been working on a project for the past months. In this project we use Webwork 2.2.4 as the presentation framework.

Last week, I tried to upgrading to 2.2.5(svn) which has upgraded to use Dojo 0.4.1. First I check out the source from http://svn.opensymphony.com/svn/webwork/trunk. Then I build and test the showcase example. So far so good.

Migrating to 2.2.5


I took a quick look at the setup of the showcase example: web.xml, webwork.xml and webwork.properties. It look like there is nothing incompatible. So I proceed to try it out with my project. I replaced the two jars (webwork.jar and xwork.jar) and fire up the application.

When I point the browser to the application, I got a bunch of javascript error, this is what reported by FireBug:
GET http://localhost:8080/fow225/src/storage/__package__.js 404 (21ms)dojo.js
symbol 'dojo.storage' is not defined after loading '__package__.js' throw _13||Error(_12);
Looking at the same in the showcase example:
GET http://localhost:8080/showcase/webwork/dojo/src/storage/__package__.js (60ms)
So Dojo is not able to require the javascripts. Look simple enough: in 2.2.4, you tell Dojo where to load it's file in template/ajax/head.ftl:
djConfig = {
baseRelativePath: "<@ww.url includeParams='none' value='/webwork/dojo/' encode='false'/>",
isDebug: ${parameters.debug?default(false)},
bindEncoding: "${parameters.encoding}",
debugAtAllCosts: true // not needed, but allows the Venkman debugger to work with the includes
};
But the baseRelativePath is missing in 2.2.5. I spent hours tring to figure out why it works for the showcase example but not for my application, but got nowhere. So for now, I just override head.ftl by creating a template/ajax/head.ftl in my application root.

If you happened to know the answer, please leave a comment.

Friday, February 23, 2007

Hosted, finally

After years of hosting my own blog, I finally take the dive. Now the question, what do I do with the old content?

Wonder if anyone have export from snipsnap and inport into there blogger before. Any experience to share?