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: http://www.sqlmaestro.com/products/mysql/phpgenerator/download/ 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:
FindBugs http://findbugs.cs.umd.edu/eclipse
DBViewer http://www.ne.jp/asahi/zigen/home/plugin/dbviewer/
PHPeclipse http://phpeclipse.sourceforge.net/update/stable/1.2.x/
PERL EPIC http://e-p-i-c.sf.net/updates
EMMA http://update.eclemma.org/
Mobile Tools For Java (DSDP/MTJ) http://download.eclipse.org/dsdp/mtj/updates/0.9/stable/
Java Decompiler http://java.decompiler.free.fr/
Java Auto Documentation Plugin http://jautodoc.sourceforge.net/update/

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 http://forum.springsource.org/showthread.php?p=239922&posted=1#post239922

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: http://maven.apache.org/plugins/maven-eclipse-plugin/examples/attach-library-sources.html.

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 http://configmanager.sourceforge.net/ 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:
<plugin>
     <groupId>org.apache.maven.plugins</groupId>
     <artifactId>maven-surefire-plugin</artifactId>
     <configuration>
     <additionalClasspathElements>
          <additionalClasspathElement>./src/main/config/</additionalClasspathElement>
          <additionalClasspathElement>./mymodule/src/main/config/</additionalClasspathElement>
      </additionalClasspathElements>
    </configuration>
</plugin>

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();
  
wizardForm.setDataId(viewForm.getDataId());
 // populating information from view screen
wizardForm.setMoreData(viewForm.getMoreData());
 
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:
<plugins>
<
plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<additionalClasspathElements>
<additionalClasspathElement>${basedir}/src/main/webapp</additionalClasspathElement>
</additionalClasspathElements>
</configuration>
</plugin>
</plugin>

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.