Using Pooled Data Connections with RS Libs Data Hibernate Library

July 3rd, 2014

The standard way of configuring a data source for RSLib’s Data Hibernate Library is to use the driver’s DataSource implementation as shown here:

1
2
3
4
5
6
7
8
9
10
<?xml version="1.0" encoding="UTF-8"?>
<dbconfig>
   <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
 
   <datasource class="com.mysql.jdbc.jdbc2.optional.MysqlXADataSource">
      <property name="url">jdbc:mysql://db-host:3306/db-name</property>
      <property name="user">db-user</property>
      <property name="password">db-password</property>
   </datasource>
</dbconfig>

However, this setup will result in creating a new connection each time you start a new transaction. This is most likely not what you want in a productive application. Instead you shall use a pooled DataSource, as the c3p0 project provides:

1
2
3
4
5
6
7
8
9
10
11
<?xml version="1.0" encoding="UTF-8"?>
<dbconfig>
   <property name="hibernate.dialect">org.hibernate.dialect.MySQLDialect</property>
 
   <datasource class="com.mchange.v2.c3p0.ComboPooledDataSource">
      <property name="driverClass">com.mysql.jdbc.Driver</property>
      <property name="jdbcUrl">jdbc:mysql://db-host:3306/db-name?autoReconnect=true</property>
      <property name="user">db-user</property>
      <property name="password">db-password</property>
   </datasource>
</dbconfig>

I stumbled across this problem while implementing a project and receiving a

java.net.SocketException: No buffer space available (maximum connections reached?): connect

exception.

Update July 26nd: You will need the autoReconnect=true parameter with MySQL to avoid problems with connections in the pools not being used for quite a long time.

Update August 18th: This URL parameter doesn’t work correctly. The solution is to add a c3p0.properties file in your classpath:

1
2
3
4
5
6
7
8
9
10
11
c3p0.maxPoolSize=50
c3p0.minPoolSize=5
c3p0.timeout=0
c3p0.maxStatements=0
c3p0.maxStatementsPerConnection=0
c3p0.idleConnectionTestPeriod=300
c3p0.acquireIncrement=1
c3p0.validate=true
c3p0.preferredTestQuery=SELECT 1;
c3p0.testConnectionOnCheckin=false
c3p0.testConnectionOnCheckout=true

(Don’t try to set these properties via your hibernate.cfg file. Some of them cannot be set there!)

Robots.txt Recommendation for WebSVN

June 19th, 2014

You are using WebSVN on your server? The I recommend to have the following robots.txt in place:

User-agent: *
Disallow: /websvn/log.php
Disallow: /websvn/comp.php
Disallow: /websvn/blame.php
Disallow: /websvn/rss.php

The reason is that search engine robots could consume your server performance, especially when your Subversion repository contains larger files. But even if not: there is no reason why robots should index each and every diff between revisions. 🙂

Bugzilla 5 brings REST API

June 4th, 2014

A step towards dynamic HTML sites is being prepared at Bugzilla. Besides some efficiency issues in the XML-RPC API, Bugzilla will come along with a REST API. Details can already be seen at their documentation. Once Bugzilla 5 is out, I will try to incorporate the new features into B4J.

Server Relocated

June 1st, 2014

Hi all,

I relocated the server beginning of June. This results in a few outages of Jira and Subversion. Especially SVN users shall be aware that the SVN host is svn.ralph-schuster.eu now. Older SVN URLs will not work anymore.

Almost all services are already fully functioning. The remaining services will be back within a few days.

Thank you for your patience and sorry for the inconvinience.

Ralph

PS: All sites are available with HTTPS now (using a self-signed cetificate).

B4J V2.0.1 releaseed

May 14th, 2014

A new version 2.0.1 of B4J has been released. It fixes issues found by static code analysis. A complete change log is available as well as the mandatory Maven Site.

You can download the new version here or visit the Homepage of the utility where you will find more documentation.

The Maven coordinates are:

<dependency>
      <groupId>eu.ralph-schuster</groupId>
      <artifactId>b4j</artifactId>
      <version>2.0.1</version>
</dependency>

CSV/Excel Utility Package V2.7.1 released

May 8th, 2014

The new version 2.7.1 fixes issues found by static code analysis. A complete change log is available as well as the mandatory Maven Site.

You can download the new version here or visit the Homepage of the utility where you will find some examples on how to use it.

The Maven coordinates are:

<dependency>
      <groupId>eu.ralph-schuster</groupId>
      <artifactId>csv</artifactId>
      <version>2.7.1</version>
</dependency>

RS Library V1.2.5 released

May 8th, 2014

I released RS Library V1.2.5 which mainly contains fixes to issues found by static code analysis. A complete list of changes can be found here.

The Maven repositories shall be up-to-date by now. The Maven coordinates are:

   <dependency>
      <groupId>eu.ralph-schuster</groupId>
      <artifactId>baselib</artifactId>
      <version>1.2.5</version>
   </dependency>
 
   <dependency>
      <groupId>eu.ralph-schuster</groupId>
      <artifactId>data</artifactId>
      <version>1.2.5</version>
   </dependency>
 
   <dependency>
      <groupId>eu.ralph-schuster</groupId>
      <artifactId>data-file</artifactId>
      <version>1.2.5</version>
   </dependency>
 
   <dependency>
      <groupId>eu.ralph-schuster</groupId>
      <artifactId>data-hibernate</artifactId>
      <version>1.2.5</version>
   </dependency>
 
   <dependency>
      <groupId>eu.ralph-schuster</groupId>
      <artifactId>templating</artifactId>
      <version>1.2.5</version>
   </dependency>

Multiple Releases

March 10th, 2014

The last few days I released new versions of three of my projects.

All projects are available through Maven Central.

 

CSV/Excel Utility improves performance

March 7th, 2014

I recently stumbled across a performance test of Java CSV libraries (can’t remember where). To my surprise, someone tested multiple Open Source products including my own CSV/Excel Utility Package. And even more surprising to me, mine was the worst. By far! It took 4 times as much than others spent in parsing a CSV file. Embarrasing! Why did I never spent effort in measuring performance?

Anyway. I took the time and wrote a comparable JUnit perfromance test for all major CSV libraries and gave them a 150MB file to read. Analyzing the results of my own library with JProfiler, I found a very stupid performance eater (simplified here):

1
2
3
4
5
6
String s = "";
for (char c : anotherString.toCharArray()) {
   ...
   s += c;
   ...
}

The “addition” of line 6 was called 150 million times – for each single character in the file. Replacing this by a StringBuilder construct, the performance rose near the other major CSV libraries:

1
2
3
4
5
6
StringBuilder s = new StringBuilder();
for (char c : anotherString.toCharArray()) {
   ...
   s.append(c);
   ...
}

So two things to learn here: (1) Do not under-estimate performance test before releasing something, (2) Take care when using the “addition” operator for strings. 🙂

PS: CSV/Excel Utility Package 1.7 will contain the fix.
PPS: StringBuilder is preferred against StringBuffer as it is not synchronized and therefore faster. Most use cases allow this simplifications.

RsBudget Release Candidate

February 20th, 2014

RsBudgetIt’s done. The last five months I have been preparing an old RCP application for release. I never thought that this would require so much effort in addition to the already existing functionality. I was used to the behaviour and configuration. So I never needed things such as a Preferences Dialog, a Help system, Installation procedure and many other things. In fact, they do exist now for the only purpose to allow every person to use the application.

So here it is. It is the Release Candidate for version 2.0. (The old private application was 1.0 and it will never get released 😉 ) Now I ask you to help me in making it bug-free. Please visit the RsBudget Homepage, download and install it (there are videos available explaining how to install it correctly), and then finally try to use it on a daily basis.

Whatever you think is wrong or not behaving right or not explained correctly: Please tell me! The application is released under GPL, and it’s free of charge. Thank you all for your support – and spread the word 🙂