start your own blog now!
 
Read other blogs...
Ika's Weblog XML
Architecting the Thought.

After a very painful data-migration process

The blog has moved to a new location: www.freshblurbs.com

Please, kindly update your RSS Reader with the new URL:
http://www.freshblurbs.com/rss.xml

I apologize for the temporary inconvenience but in the long run the new server is going to be much more featue-rich and comfortable, benefiting both me and my kind readers.

10/28/06

Null values in Mysql Not-In Queries Cause Trouble

I was debugging a piece of code today and stumbled upon a non-trivial problem, that IMHO is worth a post about.

Let's take a "simple" example where you want to find records in one table that are not present in another table. "Present" or "Non-present" is determined by comparision against a single column, in both tables.

Sounds like a query as simple as they come, right? Well, not really. Let's look at a sample query:

select * from TMP_USER where UID not in (select EXT_ID from USER )

What does it return? The correct answer is: in MySQL, depends whether there are any null values in EXT_ID. If there are - it returns an empty set!!!

Not too easy to believe, huh? But running the same query with a slight modification:

select * from TMP_USER where UID not in (
select EXT_ID from USER where EXT_ID is not null
)
you empirically get 116 results, none of which have UID null. Furthermore:
select * from HV_TMP_USER where CUID is null
returns empty set. so - believe it or not - that's how "select .. not in" works in MYSQL.

Conclusion: watch-out for "not in" queries in MYSQL on a column that may contain null-values. The resul may be empty set, when you least expect it.

posted by irakli, 23:49 | link | comments

10/27/06

MySpace & YouTube

The two are, probably, the most talked-about Web 2.0 wannabes. They have, obviously, been very lucrative for the respective creators, too - considering how much money they got for them.

But, seriously - will they really make it? Are their business models valid? Or will they continue to suck out the profits off the generous sponsors like Google?

Ok, I do understand the whole social network/high traffic/online marketing speculation/blah-blah but it does not bring money by some magic. Seriously, there is more than that to it. More traffic also means much higher operaitonal costs (especially for high-bandwidth YouTube) - so, come on, wake up!

I like YouTube in the sense that it allows anybody to post large media files - that's cool but would I want to own it? Hell no. Just one fact, ok? When something as ridiculously retarded as lonelygirl15 series tops the charts of YouTube - that makes me sick to my stomach - like, for real.

MySpace is much more complex and sophisticated. Yet, it's still too juvenile and cheesy for my taste. Whatever they say - their age group is really, really limited and I suspect it's quite localized - mostly US users. I think, Google played one of its many dumb curds, when they cut such a huge deal on MySpace ads.

Conclusion: both of them are highly overrated and Google made huge mistake to throw so much money on them. These guys (Google) are really trying to diversify their portfolio, but, sorry, so far they are mostly just wasting profits from their core business, on stupid startups.

P.S. Don't get me wrong - I do find a lot of value in several other Google services, except Search and related AdSense, but owning YouTube, investing so much in MySpace and that lame-ass Checkout are definitely not at the top of my list.

posted by irakli, 23:16 | link | comments

10/24/06

Humanism

"God is so clear, so close, so obvious and so simple - when you see God, you do not realize it is God. That's why people do not believe in God. If God was somewhere else, far away, separate and high above, if God was not inside us - everybody would believe in God." - N. Dumbadze

posted by irakli, 07:10 | link | comments

10/19/06

Subversion Change Log Report

Depending on your perspective, you may call it paranoia or staying on top of the software development process, but, in my experience architects/senior developers need to track changes to the version control. If you are a team lead, you HAVE to know what your developers are putting in the version control.

Back in old days (several years ago), when we were still on CVS, Doug wrote a nice perl script, tied it to a cron job and we were recieving list of daily commits to CVS regularily.

Now, of course SVN makes everything that was hard in CVS easy. You don't need to write perl scripts, any more. A colleague of mine has recently asked me how to do the same in SVN, since they are just moving to Subversion.

This is how:

svn -v -r "HEAD":{20061015} log svn+ssh://user@example.com/svn/module

Which for a crontab-usable script would make a source like:

#!/bin/sh

distList="bill@microsoft.com, steve@microsoft.com, vista@microsoft.com"

yest=`date --date=yesterday +%Y%m%d`

/usr/local/bin/svn -v -r "HEAD":{$yest} log file:///reproot/module |
mail -s "Daily Commits to Module" "$distList" 

where file:///reproot/module is your SVN URL, of course. The last two lines should be on the same line (we just can't do it here due to space constraints) and you have to indicate full path to svn binary, otherwise it will not work from cron (even if it works from just shell).

I like to recieve updates twice a day, so my crontab looks like:

0 1,18 * * * /home/irakli/bin/dailysvnchangelog.sh > /tmp/dailysvnchangelog.log
P.S. I'd like to thank Doug for his comments of improvement regarding the initial version.

posted by irakli, 05:22 | link | comments

10/18/06

Exception Handling and the Chain of Responsibility Design Pattern

Developers often compain about explicit Exceptions, especially in a strongly typed language like Java, and how much real estate handling those takes up in source code.

I have seen approaches when people try to avoid java.lang.Exception and fall back to java.lang.RuntimeException for most cases. Is that a good thing to do? RuntimeException is a valid choice for certain cases but overusing it beats the whole idea of exception-handling, really.

As part of my responsibilites as a software architect, I get to review code of many developers. I think the problem, in most cases, is incorrect usage of exception-handling. More specificly, developers overdo with catching exceptions at the lowest level - at the same spot they expect exception to be fired. Passing it up the class hierarchy is often needed but not done. It is especially true in the case of more junior developers (however, you quickly find out that many "senior" developers are vulnarable, as well).

If you look at a software system, especially a web-application and more so a well-design one, it is, basically, an implementation of the Chain of Responsibility pattern for different use-cases. Developer immidiately catching an exception wherever it is fired is often a bad thing to do. In many cases, a much more correct (and elegant) approach is to pass it up the chain of responsibility. Unfortunately, if you look at a common code, you rarely see a method declared with "throws" keyword. So, a lot of times, developers try to handle exception in the lowest methods and do not pass it up the chain. That's bad. Many errors can/should be grouped and handled uniformally.

For instance, when you have a database transaction that spans across several methods, do not try to handle JDBC/Hibernate/EJB exceptions in each method - declare a sensible exception subclass and pass it up, at least to the class that is handling the entire transaction. Then the upper-level class can handle all these exceptions and make a decision of rolling back the entire transaction, which in most cases is what should happen, indeed.

Bottomline: "throws" is just as useful as try/catch - use it!

posted by irakli, 12:28 | link | comments

10/14/06

DC Panorama

I was jailed into my computer for the entire last week (and then some more) so I decided to take a long walk this morning. I dropped my car off in Courthouse, for oil change and walked back home.

It is a beautiful, sunny day. As I was crossing the K bridge I could not help admire the view of DC, so I grabbed my cell out and took a photo. Here it is:


(click on the photo to view larger version)

posted by irakli, 17:14 | link | comments

10/11/06

Apple iPhone

So, T-Mobile or Cingular?

I was about to switch to Cingular and now they leave me wondering, again. I still think Cingular is MUCH more solid of a partner than T-Mobile. I guess, the real question for Apple, right now, is - which one of them will be able to roll-out wider, better 3G coverage? Clearly, that's what iPhone will be all about, not just a lame-ass let's talk phone.

Can't wait

posted by irakli, 01:01 | link | comments

10/09/06

JDBC: Get Last Insert's ID

OK, so I need this frequently enough to care (when I do direct JDBC for some data-mining, data-migration or any other mass-db operations) but not frequently enough to memorize (as I use Hibernate normally). Therefore, it seems like a good idea to post it here and be able to find it later, if I need it again :)

Oh, and maybe somebody else may benefit from it too. Heh

So, if, in JDBC, you need to get the IDs of the last inserts when using auto_generated primary keys on the database side (e.g. sequences) you should use getGeneratedKeys() method of java.sql.PreparedStatement

resultSet = pstmt.getGeneratedKeys(); 

if ( resultSet != null && resultSet.next() ) 
{ 
    newid = resultSet.getInt(1); 
}
The example shows how to get one ID but you can get all IDs of a mass-insert, as well. Pretty cool.

posted by irakli, 13:03 | link | comments

10/01/06

Widgets You Have to Have

This is a list of third-party widgets that are way too useful/necessary (at least, for geeks) to miss out on them:

posted by irakli, 13:50 | link | comments


Copyright (C). Irakli Nadareishvili. Picktek Ltd.