the need for speed, tests and clean code
test driving of java applications
Dienstag, 28. Dezember 2010
Synaptics,UltraNav,Thinkpad Scrolling in Netbeans,IntelliJ or other Java Swing Appz
*,*,idea.exe,*,*,*,WheelStd,1,9
It may be necessary to restart windows. If its not working try to add this line at the top of the ruleset definitions right under the comment
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
; Pass 0 rules (These rules run first)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
and confront your brave Windows Machine with the challenge of a reboot. If its still not working rename the idea.exe file to java.exe. (There is a predefined rule for java in the TP4table.dat file) and start IntelliJ using this exe. If scrolling is working now you made a mistake copy and pasting or forgot to reboot your machine.
Happy new year with scrolling in Swing appz!
Montag, 13. September 2010
HOWTO do global JNDI registered Connection Pooling (DataSource) in Tomcat
Using a connection pool of the servlet container seems to be a good idea IMHO. Here's a litlle HOWTO do so using tomcat and postgresql.
- Provide the jdbc driver by copying the postgresql-8.4-701.jdbc4.jar (or any other version working for you) to the CATALINA_HOME/lib directory.
- Register the jndi resource by adding the following lines to your CATALINA_HOME/conf/server.xml under <GlobalNamingResources>
<Resource name="jdbc/postgres-ds" type="javax.sql.DataSource" driverClassName="org.postgresql.Driver" url="jdbc:postgresql://MYSERVER:5432/testdb" username="MYUSER" password="MYPASS" defaultAutoCommit="false" maxActive="5" maxIdle="2" maxWait="30000" initialSize="0" validationQuery="SELECT 1;" testOnBorrow="true" testWhileIdle="false" />
- Create or user the file /META-INF/context.xml(Using maven it is src/main/webapp/META-INF/context.xml in your webapps project with the following content:
<?xml version="1.0" encoding="UTF-8"?> <Context> <ResourceLink name="jdbc/dbds" global="jdbc/postgres-ds" type="javax.sql.DataSource"/> </Context>
- edit your web.xml and add the following lines to the root node:
<resource-ref> <description>postgreSQL Datasource example</description> <res-ref-name>jdbc/dbds</res-ref-name> <res-type>javax.sql.DataSource</res-type> <res-auth>Container</res-auth> </resource-ref>
- Use the connection in a way like this:
InitialContext cxt = new InitialContext(); DataSource ds = (DataSource) cxt.lookup("java:/comp/env/jdbc/dbds"); Connection con = ds.getConnection(); con.setAutoCommit(false); Statement statement = con.createStatement(); ResultSet rs = statement.executeQuery("SELECT id, \"name\" FROM test;"); while (rs.next()) { long long1 = rs.getLong("id"); String name = rs.getString("name"); System.out.println(long1 + " - " + name); } rs.close(); statement.close(); con.commit(); con.close();
Additional Info:
Tomcat 6 is using the Apache dbcp project to do connection pooling. So the available connection pool configuration parameters are described here
The pool is created at the time of the first connection request.
Make sure to always close the connection. Connections that are not closed are not released. This means those connections can't be reused.
If you are using eclipse wtp and Tomcat 7 you may get a nasty java.lang.NullPointerException at org.apache.catalina.core.StandardContext.getObjectNameKeyProperties. It is related to the <ResourceLink name="jdbc/dbds" global="jdbc/postgres-ds" type="javax.sql.DataSource"/> setting in the context.xml file. The problem is described here in more detail. Just enable the server option "Publish module contexts to separate XML files" and the problem is solved.
If you are using eclipse wtp and Tomcat you may need to remove and add the tomcat server again so the wtp plugin recognizes the changed server.xml file.
I'll provide an example project if someone requests :-)
Mittwoch, 8. September 2010
Montag, 16. August 2010
Joomla template development using Ant
My personal 3 Problems developing Joomla templates
First it is necessary to maintain a file called templateDetails.xml. In this file you have to define all the files used by the template. Adding a picture means adding this picture to the list of files. If you forget to do so, the file is not installed which results in template bugs.
Second building the template package means creating a zip file. This is like creating a jar file - who would want to do it using a file manager and a zip tool?
Last but not least it is not possible to reinstall a template. Once installed, you have to uninstall it prior to installing the new version of the template. Who would like to do this every time a css file changed? So most people are using a ftp client like FileZilla which supports "online file edit" or directory synchronization. In my case this means opening files with FileZilla, not with eclipse. DO NOT forget to sync them back!
Ant to the rescue
I spent some time and created a custom ant task and a build script using the ftp sync feature built into ant. The custom ant task is responsible for maintaining the file list of the templateDetails.xml. It scans the template directory recursively and replaces the files section with the results. You can download it here. You can find the source code included in the jar file. I don't want to include those ugly lines doing their dirty job in this article.
The ant build script is quite simple:
<?xml version="1.0" encoding="UTF-8"?> <project name="MyKewlTemplate" default="myKewlTemplate"> <target name="refreshFileList"> <taskdef name="TemplateDetailsGenerator" classname="de.rhauswald.ant.joomla.TemplateDetailsGenerator" classpath="ant/TemplateDetailsGenerator.jar" /> <TemplateDetailsGenerator templatedirectory="myKewlTemplate" /> </target> <target name="clean"> <delete file="build/myKewlTemplate.zip" /> </target> <target name="myKewlTemplate" depends="clean"> <antcall target="refreshFileList" /> <zip destfile="build/myKewlTemplate.zip" basedir="myKewlTemplate" /> </target> <!-- include apache commons-net into ant lib directory--> <target name="sync"> <antcall target="refreshFileList" /> <ftp password="XXX" server="XXX" userid="XXX" passive="true" newer="true" remotedir="templates/myKewlTemplate" verbose="true" binary="true"> <fileset dir="myKewlTemplate"> </fileset> </ftp> </target> </project>Now my three problems are solved: The file list is auto generated before every build(ftp sync or zip). I can build the installation zip file with just one click. The ftp sync works like a charm. Change something, click the build button and ant uploads the changes only. In case I add a background picture and the proper lines to the css file a click at the build button does the following:
- Add the new picture to the file list
- Upload the templateDetails.xml file
- Upload the picture
- Upload the css file
Samstag, 14. August 2010
Speeding up maven dependency report
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 44 seconds [INFO] Finished at: Fri Aug 13 09:31:14 CEST 2010 [INFO] Final Memory: 69M/429M [INFO] ------------------------------------------------------------------------The docs of the dependency report module offered two options enabled by default. Disabling both of them is done in the reporting section of the project pom this way:
<plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-project-info-reports-plugin</artifactId> <version>2.1</version> <configuration> <dependencyDetailsEnabled>false</dependencyDetailsEnabled> <dependencyLocationsEnabled>false</dependencyLocationsEnabled> </configuration> </plugin>This speeds up the site generation extremely:
[INFO] ------------------------------------------------------------------------ [INFO] BUILD SUCCESSFUL [INFO] ------------------------------------------------------------------------ [INFO] Total time: 22 seconds [INFO] Finished at: Fri Aug 13 09:33:44 CEST 2010 [INFO] Final Memory: 65M/395M [INFO] ------------------------------------------------------------------------
Freitag, 13. August 2010
Windows Command / CMD Alternative
I found an awesome tool today named "console". It can be used as an alternative command line window for windows. Everyone who has broken his fingers a hundred times using the cmd tool shipped with windows should give this piece of software a try!
The website states: Console is a Windows console window enhancement. Console features include: multiple tabs, text editor-like text selection, different background types, alpha and color-key transparency, configurable font, different window styles
Dienstag, 13. April 2010
Howto set the Bacula Storage Daemon 's (bacula-sd) umask in Debian
The solution is to use a pam module named pam_umask. It is contained in the package libpam-modules which should be installed by default. After switching on the module the only thing that needs to be done is to add a umask setting to the Bacula users GECOS field.
For the copy paste fraction:
apt-get install libpam-modules echo "session optional pam_umask.so" >> /etc/pam.d/common-session usermod -c umask=027 bacula /etc/init.d/bacula-sd restartpam_umask can also be used this way to modify the umask of any specific daemon user without a shell.
Samstag, 27. März 2010
TrueCrypt and Ubuntu 9
Freitag, 26. März 2010
Debian Bacula vulnerability / security leak
Montag, 15. Februar 2010
How to determine the size of all postgres databases
A manic Monday, reading log files, a big WTF: No space left on device external backups... WTF? .... 5 Minutes later: found a reason: The backups of the test database server... 30 databases on this machine.... which ones are the biggest?
This query to the rescue:
select databases.datname, pg_database_size(databases.datname)/1024/1024 as size from (SELECT datname as datname FROM pg_database) as databases ORDER BY size DESC;
One test database with 1,4GB ... another one with 0.9G... WTF? - Drop database... war is over