Archive for the ‘Technology’ Category

Nuances of open source technologies…

September 24, 2007

I have always faced these problems during last 4 years of J2EE development. This problem that I faced now, is an epitome of that.

1. I am using Hibernate3 with Weblogic. So I tried the new feature of delete HQL query. Steangely, it says…”org.hibernate.QueryException: query must begin with SELECT or FROM“.

2. Digging on this, I found this – http://forum.springframework.org/showthread.php?t=18732 which asked me to use the new HQL parsing version ASTQueryTranslatorFactory instead of ClassicQueryTranslatorFactory.

3. Upon using that, I found this , this and this (Weblogic issues).

4. To summarize, Weblogic uses some old version of a parsing library (antlr), and it loads that library before loading application. This prevents HB3 to see the new version of antlr, which is needed to parse this new kind of queries (HQL update or HQL delete).

So, in the end, it looks like it’s not possible to use these queries. 😥

I just wanted to delete some rows from database god damn !!! 

This problem summarizes typical compatibility issues every open source developer faces so often. I wonder whether .NET developers are free from such weird issues?

P.S. Hibernate 3 does not support SQL update/delete queries with createSQLQuery() API…why? why? why? 🙂

Finally…I used session.Connection() API to get the connection and used good old PreparedeStatement to do the work for me.

Advertisements

HashMap sorted based on values…

June 24, 2007

Just wrote a simple HashMap class to have entries sorted based on values…i.e. the keySet() method will return the keys based on sorted order of their corresponding values…

Here it goes…

import java.util.*;
import java.util.*;
/**
* HashMap with entries sorted based on Values. (keySet() method will return keys sorted based on values.)
* @author Sumedh Inamdar
*/
public class ValueSortedHashMap extends HashMap {
  
  public Set keySet() {
    TreeSet s = new TreeSet(new MapValueComparator(this));
    s.addAll(super.keySet());
    return s;
  }
  
  /**
   * Comparator class for comparing keys based on values. Assumes that values are ‘Comparable’.
   */
  class MapValueComparator implements Comparator {
    MapValueComparator(Map m) {
      map = m;
    }
   public int compare(Object k1, Object k2) {
     if(!(map.get(k1) instanceof Comparable)) {
       System.out.println(“ERROR…ValueSortedHashMap could not compare the values…”);
       return 0;
     }
     return ((Comparable)map.get(k1)).compareTo(map.get(k2));
   }
   Map map;
  }
}

By the way…does any one know a quick way to post formatted code on site? This was pain in a$$…Blogger just removes my spaces after I do some editing…and for even adding spaces, I had to hack it like this 😦

That Javascript thing…

April 26, 2007

I have always tried to stay away from Javascript…

I used to write some code hesitantly, say to move data between two listboxes, re-calculating some stuff when values change etc. etc. But overall, I avoided it for the simple reason that it appeared a very weired language to me especially as I cam from strongly typed languages like C++ and Java.

Even simple things like DOM manipulation with getElementById() becomes a challenge with JS.

I know very little Javascript, but a few questions I searched for didnt yield many answers on web…

1. Why there is no standardized library for Javascript, as say there is for JSP custom tags (JSTL) or C++ standard template library?

2. Why IDE’s dont have great support for Javascript? Why do I need to download a plugin like JSEclipse for JS editing in Eclipse?

3. Why javascript is not statically typed? Now dynamic typing might have some benefits, but the winner is clear now. Dynamic typing makes extremely difficult to provide auto completion for IDE’s, Dynamic typing can’t find out all bugs while coding etc. etc.

4. What is happening with Javascript 2.0? Are there any revolutionary changes? I dont have the patience to read through the proposal. 😛

Any way, with a strong arrival of AJAX, I’ll have learn javascript now…planning to get started… 🙂

Eclipse + Weblogic + Debugging with hot deployment

April 25, 2007

I had this simple problem…

I have a web application…to be deployed on weblogic…I use Eclipse to work on it…I am in development mode, so I make frequent changes to Java files and JSP’s and want to see the effect of changes immediately on browser.

In obscure world of Java…it was not that easy I found…

It has to be an open deployment (where you dont create an archive, but ask the App server to point to your development directory)…


With normal Eclipse debugging using Weblogic instance…it unnecessarily creates an archive…I didnt find an option to use open deployment here.

So one needs to use Remote debugging…It is something with which the server needs to expose its debug data to the IDE on some port (in this case 1044). IDE attaches itself to it.


One needs to make changes to the startup file of the App server to use -Xdebug option to start the JVM in debug mode and expose debug data on some port.

In my case, I created a new CMD file from existing weblogic startup file with following debug options added to JVM startup command.

set DEBUG_OPTS= -Xdebug -Xrunjdwp:transport=dt_socket,address=1044,server=y,suspend=y

Finally, it did work after some worries and mistakes…
Now I can put a console print in some java class and just refresh my browser to see the output in the console…(of course you need to set ‘Build Automatically’ in Eclipse)

What a relief… 🙂

Reference: http://www.jacoozi.com/index.php?option=com_content&task=view&id=119&Itemid=134

Googleto ergo sum !!!

April 18, 2007

Google is getting all pervasive on web…not a news of course…but I had a strong realization about this when I created a small tool of custom search using Google tools…

1. Google offers a way to create your own custom search engine. (http://www.google.com/coop). You can basically customize what sites should be scanned for the search and some more parameters. I used this feature to create a custom search engine for Indian stock markets. It was frustrating sometimes to see results from all over the world when all you care about is really NSE listed stocks. Google’s indian site also works, but includes a lot of indian sites I don’t care about.

2. Then I used Google pages (http://pages.google.com/) to create a small home page to host this search. Google pages has a HUGE collection of gadgets, right from news tickers to proxy sites. Not all of them work though. Overall I had a feeling that there is a lot of scope of improvement in Google pages interface. E.g. you cannot edit the overall structure of the page, but have restrict yourself to edit only sections as given by the template.

3. Once my page was online (http://stocksearchindia.googlepages.com/) I entered small code snippets from Google AdSense (https://www.google.com/adsense) to have some Ads on my page. Not sure if it will earn any money though. 😉

4. I put another small snippet from Google Analytics (http://www.google.com/analytics) to get all the statistics about my site’s clients with clean graphs et al. The facilities given by Google Analytics are really awesome, moreover all free of cost of course :).

5. And right now, I am conveying all of this in Blogger.com, which is again a Google acquired company of course. As Descartes once said, ‘Cogito ergo sum’ (I think, therefore I am), a netizen from 21st century (at least from first few years of it…) would certainly say…’Googleto ergo sum’…’I google, therefore I am’ !