Eugene Burtsev's blog

Merging Unrelated Repositories in Mercurial

Some time ago I had some projects which I wanted to combine in one big project and keep history for all of them. This can be done following to this article. But if I’ll use this solution in result I’ll have more than one tails (how it illustrated in picture below).

1
2
3
4
5
6
7
8
9
10
   @
   |
   o-----------o
   |           |
   .           .
   .           .
   |           |
   o           o
  tail        tail
   #1          #2

But I wanted to make repository structure as on picture below:

1
2
3
4
5
6
7
8
9
10
11
12
   @
   |
   o-----------o
   |           |
   . default   .
   .           . Feature
   |           | branch
   o           o
   |           |
   o-----------o
   |
   o

After some hours with console magic I found solution, and I want to share it.

Maven Custom Repository Layout

I’ve developed maven plugin to access repositories with custom structure. And I would share this solution with community.

Some time ago, I worked on java web project, and I used some JavaScript dependencies for it. I’ve throught about dependency management for javascript dependencies like JQuery. Ordinary JS dependencies is not management, so we need download new versions manually. First I found Bower for javascript dependency management, but I afraid of node.js in dependencies for my project. I thought about CDNs which hosts js libraries. (for example jquery on Google CDN: http://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min.js). I using maven in my projec, so it will be good to use CDNs via maven… Because CDN’s directories stricture is differs from standart maven layout, I decided to write own maven plugin to handle custom repository layout.

JSF2 + Spring Framework Example

Just recently I’ve discovered the Spring Framework. IMHO it is amazing framework. And I decided to rewrite a couple of my applications using Spring. Below I tell how to integrate Spring and JSF2

Google Gdata Maven Repository

Some time ago, I was searching for google gdata maven repository, but I was surprised - it has no any maven repositories! Of course, there are a new google-api-java-client, , but it do not implements all google API’s, for example it don’t implement Provisioning API for domains.

I found some repositories with older versions of library.

Also I found awesome script which helps to create local maven repo for Google’s gdata library.

I used modified version of this script to create my own repository hosted on my server. I’ll happy if it will be helpfull for someone.

Details under the cut

Java 7 Try-with-resources and MyBatis

With Java 7 came analog of using construction from C# - try-with-resources. This feature is very well for automatically close resources such as database connections, etc. For example:

1
2
3
4
try (SqlSession session = ConnectionFactory.getSqlSessionFactory().openSession()) {
  // Work with session
  session.commit();
}

But there are an trouble - class org.apache.ibatis.session.SqlSession from MyBatis 3.0.6 does not implement AutoCloseable interface which is required to work try-with-resources construction. I hope that in next version it will be fixed, but now I can offer small workaround.

Prevent iBatis org.apache.ibatis.transaction. TransactionException if the Database Connection Is Temporarily Lost

Sometimes there is an unpleasant situation when the database server goes to reboot. In this case, we can catch a nasty exception like this:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
Caused by: org.apache.ibatis.exceptions.PersistenceException:
### Error opening session.  Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit.  Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 59,121,876 milliseconds ago.  The last packet sent successfully to the server was 59,121,984 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
### Cause: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit.  Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 59,121,876 milliseconds ago.  The last packet sent successfully to the server was 59,121,984 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
        at org.apache.ibatis.exceptions.ExceptionFactory.wrapException(ExceptionFactory.java:8)
        at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:83)
        at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSession(DefaultSqlSessionFactory.java:32)
        at com.greytower.htmltemplates.core.dao.ibatis.TemplatesDAOImpl.readAll(TemplatesDAOImpl.java:70)
        at com.greytower.htmltemplates.beans.TemplatesEditorBean.init(TemplatesEditorBean.java:86)
        ... 59 more
Caused by: org.apache.ibatis.transaction.TransactionException: Error configuring AutoCommit.  Your driver may not support getAutoCommit() or setAutoCommit(). Requested setting: false.  Cause: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 59,121,876 milliseconds ago.  The last packet sent successfully to the server was 59,121,984 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.
        at org.apache.ibatis.transaction.jdbc.JdbcTransaction.setDesiredAutoCommit(JdbcTransaction.java:51)
        at org.apache.ibatis.transaction.jdbc.JdbcTransaction.<init>(JdbcTransaction.java:19)
        at org.apache.ibatis.transaction.jdbc.JdbcTransactionFactory.newTransaction(JdbcTransactionFactory.java:15)
        at org.apache.ibatis.session.defaults.DefaultSqlSessionFactory.openSessionFromDataSource(DefaultSqlSessionFactory.java:78)
        ... 62 more
Caused by: com.mysql.jdbc.exceptions.jdbc4.CommunicationsException: The last packet successfully received from the server was 59,121,876 milliseconds ago.  The last packet sent successfully to the server was 59,121,984 milliseconds ago. is longer than the server configured value of 'wait_timeout'. You should consider either expiring and/or testing connection validity before use in your application, increasing the server configured values for client timeouts, or using the Connector/J connection property 'autoReconnect=true' to avoid this problem.