Author Archive

Php code generator

Thursday, June 4th, 2009

After a long search I found a wonderful Php code generator that runs on Windows, connects to your database, allows you to select tables and even asks you about security. It produced about 90% of the final code for me – I just needed to re-arrange certain things, trim certain long descriptions and have my database connection class replace in-place connection strings. Even without any of my work the solution worked out of the package! Impressinve. Here is the link to it: called Php Generator for MySQL.

Plugins I usually use with Eclipse installation

Wednesday, June 3rd, 2009

Here is the list of plugins I usually use with eclipse installation – a quick way for me to upgrade eclipse and still remember the site without searching for them:
Mobile Tools For Java (DSDP/MTJ)
Java Decompiler
Java Auto Documentation Plugin

Spring JDBC and Sybase Temp Tables

Friday, May 8th, 2009

I had a problem with using temp tables and Spring JDBC code lately. The main problem was that in Sybase a temp table can be accessed only on the same connection which created it. When executing several SQl statements in default Spring JDBC usage (DriverManagerDataSource using connection pool) could give different connections from connection pool for each of the statements. So in default implementation we cannot garantee that a temp table is visible. One possible fix is to use transaction (@Transactional) which would ensure that same connection is used. In our case, Sybase is configured in a way that does not allow us to drop temp table in the same transaction as create and select from it.

com.sybase.jdbc3.jdbc.SybSQLException: The ‘DROP TABLE’ command is not allowed within a multi-statement transaction in the ‘tempdb’ database.

 So the only way out was to us SingleConnectionDataSource for one method as described in

I released Configuration Manager 1.7

Thursday, January 8th, 2009

I released configuration manager 1.7. The new release adds support for different configuration values for different environments – like production, qa and development. It also adds a couple of tutorials: Environment settings: dev, qa, etc and How to enable JMX. Here is the link to download the latest release.

How to add sources to Eclipse/Idea project generated by Maven

Friday, November 21st, 2008

Wanted to have a link here, since it takes me a while to find it:

I’ve released configuration manager 1.6

Friday, November 21st, 2008

Configuration Manager 1.6 provides easy API for integrating it into your code (literally 2 lines and a small xml file), and easy Unit testing of the code that is dependent on configuration manager. Visit for more details.

Maven – fixing classpath issues for tests

Monday, November 10th, 2008

We had problems with tests not finding files that we usually package outside the jar. One of such files was log4j.xml and other files were configuration files for spring framework. We need to pass full path to the log4j file, so that we don’t have to rely on class path priorities to look it up. Given that log4j.xml is such a widely used file, it is probable that one of the dependent jar would have a copy in the archive – so we can pick up the wrong file by mistake. On the other hand, we want to have our spring framework configuration files in the class path, but outside the jar. This way we can modify the configuration on the fly if we need to. So to setup integration test case, we needed to get the full path to the log4j.xml file and adding a directory to the class path for test only.
Here is how to do that:
public static String getFullPath(Class c, String name){
     ClassLoader cl = c.getClassLoader();
     URL url = cl.getResource(name);
     return url != null ? url.getPath() : null;
and for adding class path:

Linking between a controller page and a non-initail page of Spring MVC Wizard

Tuesday, October 28th, 2008

For one of the projects where I used Spring MVC 2.5 I had to link a view page with the second page of edit wizard. The reason for the linking is this that view page contains enough information to bypass the first wizard screen for editing the information person is viewing. Here is how to do it.

In the target wizard controller you will need to overwrite the following three methods: two for getting the names of attributes stored in a session and one for getting the page number from request attribute first then request parameter. 
Since wizards work with session based forms, you will need to put the form in the session. To do that, you would need to know the attribute key in your controller. The key value is available in the super class, so you need to make the method visible.

public String getFormSessionAttributeName(HttpServletRequest request) {       
   return super.getFormSessionAttributeName(request);

Same with getting the page attribute, which you will need to control which page of the wizard you will link to.

public String getPageSessionAttributeName(HttpServletRequest request) {  
return super.getPageSessionAttributeName(request);

The other thing is that you will need to pass in the page number, which you can only pass as request argument, not request parameter as expected by the super class. So here is how you can do it:

protected int getTargetPage(HttpServletRequest request, int currentPage) {       
Enumeration requestNamesEnum = request.getAttributeNames();
   while (requestNamesEnum.hasMoreElements()) {           
String requestName = (String) requestNamesEnum.nextElement();
if (requestName.startsWith(AbstractWizardFormController.PARAM_TARGET)) {
for (int i = 0; i < WebUtils.SUBMIT_IMAGE_SUFFIXES.length; i++) {
String suffix = WebUtils.SUBMIT_IMAGE_SUFFIXES[i];
if (requestName.endsWith(suffix)) {
requestName = requestName.substring(0, requestName.length() – suffix.length());   
 return Integer.parseInt(requestName.substring(AbstractWizardFormController.PARAM_TARGET.length()));   
return WebUtils.getTargetPage(request, PARAM_TARGET, currentPage);

Now in your controller you need to prepare all the parameters to call the wizard:

HttpSession session = request.getSession(); 
MyWizardForm wizardForm = new MyWizardForm();
 // populating information from view screen
EditWizardController tempEditWizardController = new EditWizardController();
request.setAttribute(tempEditWizardController.getPageSessionAttributeName(request), new Integer(0)); //as if user had posted data on page 0
request.setAttribute(“_target1″,”_target1”); //and the landing page should be page 2, after page 1 is validated.
session.setAttribute(tempUniverseEditWizardController.getFormSessionAttributeName(request), wizardForm);

return new ModelAndView(“forward:editUniverse.htm”);


And that is it!

Testing Struts Apps With Maven

Thursday, September 11th, 2008

While switching my configuration manager project from Maven 1 to Maven 2, I had to figure out how to add WEB-INF/web.xml located in src/main/webapp directory to the Maven test class path, so that MockStrutsTestCase would be able to access it. After a bit of digging on the net, and experimenting, I found an easy way of accomplishing it. Here is what needs to be added to your POM:

After I’ve added this fragment, all the tests I’ve ported passed! Hurray!

Good article on Building and Deploying with Maven 2

Wednesday, September 3rd, 2008

We are using Maven 2 as part of our build/deploy/dependency management tool. It is great in dependency management, code quality reporting, deploying to repositories, as well as having a very uncomplicated build script and not having to store our Idea or Eclipse project files (since we have them generated). The biggest problem we discovered so far, was that maven is not so well suited to deploy projects into different environments – development, qa, production.  So, if you are developing reusable components – go for Maven, it will make your builds so much easier. If you have to build a product and deploy it to different servers (dev, qa, int, prod and prod_bcp) – it might not be as easy. After a long search on how other people have struggled with this problem, I found a good article The Pain of migrating from Ant to Maven and even though it does not solve my problem, it describes very well the pain points I felt when I worked with Maven.