Tuesday, August 16, 2005

Hibernate templates

Hibernate infrastructure templates for Netbeans:
Class DAO.java
ClassDAOImpl.java
DAOFactory.java
HBVOClass.java
Hibernate.hbm.xml
Slightly modified HibernateUtil.java
InfrastructureException.java
hibernate.cfg.xml
Since the Hibernate log4j.properties file is used often in many projects, I saved it as a template: log4j.properties

Netbeans Module Development Templates

I have been working on the Netbeans Platform these days. This means I can use the Netbeans API to make my own applications, with the advantage of using several gui and non-gui components provided by Netbeans. To make modules I write a lot of classes for TopComponent and CallableAction so I modified the supplied templates for these to conform to my own style, with some added features. I am making them available for download here.
TopComponent
CallableAction

Monday, July 25, 2005

Postgresql sequences + CJDBC + Hibernate

CJDBC has a problem understanding PostgreSQL sequences. This program solves that problem.
//$Id: CJDBCPostgreSQLDialect.java,v 1.22 2004/08/08 08:23:16 oneovthafew Exp $
package net.sf.hibernate.dialect;

import java.sql.Types;

import net.sf.hibernate.Hibernate;
import net.sf.hibernate.cfg.Environment;

/*************************************************
 *** As of CJDBC 1.1 this file is necessary for Postgresql sequences to
 *** work withCJDBC and Hibernate.
 *** Apparently, CJDBC does not like select statements of the type:
 ***            select nextval('seq_name');
 ***
 *** So, to get around this problem whenever Hibernate requests a
 *** nextval for a Postgres sequence, we have to return:
 ***            {call nextval('seq_name')}
 *** which is something that CJDBC understands and accepts.
 *********************************************/
import net.sf.hibernate.dialect.PostgreSQLDialect;

public class CJDBCPostgreSQLDialect extends PostgreSQLDialect
{
    public String getSequenceNextValString(String sequenceName)
    { return "{call nextval('"+sequenceName+"')}"; }
}
Compile this file and add it in hibernate2.jar at the path:

net/sf/hibernate/dialect


Repackage the jar and drop it whever you have kept the original hibernate.jar.

Remember to specify this dialect in hibernate.cfg.xml:

<propertyname="dialect">
    net.sf.hibernate.dialect.CJDBCPostgreSQLDialect
</property>

Thursday, July 14, 2005

AJAX

Until a few weeks ago, this was just the name of a fictious company in comic books. But now, its what all the really fundoo websites use to amaze their audience -- think Google Maps. Will be studying this too, in the next few days.

http://www.ajaxmatters.com/
http://www.adaptivepath.com/publications/essays/archives/000385.php

Ruby

Have to try out Ruby on Rails. How else will I know whether its better than J2EE for web development?

Check this out:
http://www-128.ibm.com/developerworks/web/library/wa-rubyonrails/

Monday, July 11, 2005

Ever wondered how to create a progress monitor in your C/C++ program??

Here's a small program that shows you how:

# include <iostream>
using namespace std;

void goback();

int main()
{

    // *** CLEAR THE SCREEN ***//
    // method 1
    //printf("%c%c%c%c%c%c",27,'[','H',27,'[','J' );

    // method 2
    printf("\e[H\e[J");

    // *** Rotating Progress Monitor ***//
    while(1)
    {
        printf("|");
        goback();
        printf("\\");
        goback();
        printf("-");
        goback();
        printf("/");
        goback();
    }

}

void goback()
{
    // makes cursor go back one character
    printf("\e[D");
}

Sunday, July 10, 2005

"speed up ur work" script

#!/bin/bash
#
# kmgActionScript
# author: Karan (karanmg@gmail.com)
##########################################
# Sometimes you need to execute an operation on a large no. of files
# and/or directories which are not necessarily in the same dir.
# It can get especially cumbersome, if these files/dirs are hidden.
#
# This script will perform the specified op (cmd) on all the files/dirs
# listed in a file specified by inputFile.
#
# Eg.
# $> find ./ -name .svn > todel
# $> ./kmgActionScript
##########################################

cmd="rm -Rf"
inputFile="todel"

i="1"

cat $inputFile | \
while read line
do
echo "$i: $cmd $line"
i=`expr $i + 1`

$cmd $line
done

Thursday, July 07, 2005

How to use your favorite multimedia keyboard's favorite multimedia keys with Linux

All you need to do, is define mappings for these keys. Just follow these steps:

Run xev from a terminal window
$> xev

This is what you will get:
[karan@karan ~]$ xev
Outer window is 0x3200001, inner window is 0x3200002

PropertyNotify event, serial 8, synthetic NO, window 0x3200001,
    atom 0x27 (WM_NAME), time 754523327, state PropertyNewValue

PropertyNotify event, serial 9, synthetic NO, window 0x3200001,
    atom 0x22 (WM_COMMAND), time 754523327, state PropertyNewValue
.
.
.
.
After the long list of messages, xev will open a little window in a corner of your screen, and will be ready to accept input from all input devices.

Now press the keys you want to map
When you press the keys, you will get the keycode output from xev.
For eg. i press the "search" key on my keyboard, and this is what I get:

KeyRelease event, serial 30, synthetic NO, window 0x3200001,
    root 0xd4, subw 0x0, time 754840349, (-658,866), root:(2012,892),
    state 0x0, keycode 229 (keysym 0x0, NoSymbol), same_screen YES,
    XLookupString gives 0 bytes:


We are interested in the keycode Note down the values that you get for the different keys that you press.

Change /usr/X11R6/lib/X11/XKeysymDB
Add the following lines to the bottom of this file:
vol_up         :10090000
vol_down    :10090001
mute            :10090002
.
.
The nos. can be anything, just keep them high, so that they don't clash with other values. The above lines specify that you will be referring to keys vol_up, vol_down, mute,.... so that system should watch out for these referrals.

Create/Update your .xmodmap file in your home dir
keycode 176 = vol_up
keycode 174 = vol_down
keycode 160 = mute

Run xmodmap from a terminal
$> xmodmap ~/.xmodmap

Now you have made these keys recognizable, but they are still not mapped to any actions. I have mapped these keys to the SoundMixer applet running in my taskbar. Map them however you want.

Wednesday, June 29, 2005

Using Subversion (SVN) Properties to improve version control

This is a tutorial by example...

Lets say you check out the MyApplication tree by using:
$> svn co svn+ssh://repos@server.domain.com/home/repos/repository/trunk/MyApplication/java Java

Now you have the MyApplication source in Java/ and this is what the tree looks like:

[karan@karan Java]$ ll
total 68K
-rw-rw-r--     1 karan karan 3.3K Jun 29 16:54 build.xml
drwxrwxr-x  3 karan karan 4.0K Jun 29 16:23 config
drwxrwxr-x  3 karan karan 4.0K Jun 29 16:23 lib
drwxrwxr-x  4 karan karan 4.0K Jun 29 16:40 nbproject
drwxrwxr-x  3 karan karan 4.0K Jun 29 16:23 other
drwxrwxr-x  4 karan karan 4.0K Jun 29 16:23 resources
drwxrwxr-x  4 karan karan 4.0K Jun 29 16:23 src
lrwxrwxrwx  1 karan karan   36 Jun 29 16:23 swingSkins -> /usr/local/skinlf-1.2.11/swingSkins/
drwxrwxr-x  3 karan karan 4.0K Jun 29 16:23 impFiles

When you run ant to build the src, the Java/ tree is going to look like this:
[karan@karan Java]$ ll
total 84K
drwxrwxr-x  3 karan karan 4.0K Jun 29 17:08 build
-rw-rw-r--     1 karan karan 3.3K Jun 29 16:54 build.xml
drwxrwxr-x  3 karan karan 4.0K Jun 29 16:23 config
drwxrwxr-x  3 karan karan 4.0K Jun 29 17:08 dist
drwxrwxr-x  3 karan karan 4.0K Jun 29 16:23 lib
drwxrwxr-x  4 karan karan 4.0K Jun 29 16:40 nbproject
drwxrwxr-x  3 karan karan 4.0K Jun 29 16:23 other
drwxrwxr-x  4 karan karan 4.0K Jun 29 16:23 resources
drwxrwxr-x  4 karan karan 4.0K Jun 29 16:23 src
lrwxrwxrwx  1 karan karan   36 Jun 29 16:23 swingSkins -> /usr/local/skinlf-1.2.11/swingSkins/
drwxrwxr-x  3 karan karan 4.0K Jun 29 16:23 impFiles

Notice the build/, dist/ directories.
If you would have compiled the sources from NetBeansant would also have created a manifest.mf and a test/ directory.

Users of SVN would notice that if I run svn status right now, I am going to be bugged by a whole lot of "?s" which is SVN's way of asking
"what do i do with build/, dist/, test/.....??"
I can either choose to leave them as it is, checking in/out only the dirs that I know I need. However, as the application grows, so does your margin for error to miss a directory or file.

So to make SVN conveniently ignore the build/, dist/, etc. trees and files do the following in Java/:
$> export SVN_EDITOR=nano
$> svn propedit svn:ignore .
In the nano editor window that opens up write the following:
build
dist
test
manifest*
+ any other files that you want to be ignored

Hit ^o to save and ^x to exit.
Now if you run svn status you will see that svn conveniently ignores the build/, dist/, etc. directory structures.
So you can safely filter the directory structure processed by SVN, to keep in the repository.
Mission accomplished!

Powered by Blogger