Re: Maven based build and refactoring

From: Sebastian Hennebrueder <usenet(at)laliluna(dot)de>
To: Dave Cramer <pg(at)fastcrypt(dot)com>
Cc: pgsql-jdbc(at)postgresql(dot)org
Subject: Re: Maven based build and refactoring
Date: 2012-03-26 10:38:00
Message-ID: 8BCCCC43-79E3-44FB-B757-8D1A68BD28FB@laliluna.de
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-jdbc

Am 26.03.2012 um 00:39 schrieb Dave Cramer:

> Dave Cramer
>
> dave.cramer(at)credativ(dot)ca
> http://www.credativ.ca
>
>
>
> On Sun, Mar 25, 2012 at 12:16 PM, Sebastian Hennebrueder
> <usenet(at)laliluna(dot)de> wrote:
>> Hello to all,
>>
>> actually I only wanted to have a look which JDBC 4 methods had been missing
>> and provide a helping hand to implement those.
>>
>> The reason is that Hibernate requires now JDBC 4 and Hibernate is the
>> underlying JPA provider in the JBoss application server as well. I prefer
>> PostgreSQL over other open source database server, so JDBC 4 is an absolute
>> requirement.
>
> What methods are missing that Hibernate actually uses ?

At least I am aware of createBlob/Clob but I haven't done a complete check.

>>
>> I found the building mechanism a little bit special and played with
>> refactoring the code such that a Maven build could work.
>
> What is wrong with using ant ? It is simple and it works. How does
> maven improve this ?

Maven repositories as a common way to store open source artifacts and is easier to manage using Maven.
Maven build projects can be easily imported into any IDE (Eclipse, Netbeans, IntelliJ)
If I want to work on the project, I can be up an running in seconds by checking out and importing a Maven project into my IDE without the need to understand the details of a Ant build and excluding paths to be considered as source code.

>>
>> I split the code into common and jdbc version specific versions and found
>> clean ways to solve the version, minor and major version infos, exception
>> factories and logger control but reached now a point where the refactoring
>> would require deeper code changes.
>>
>> Before I spent time doing this, I would like to know if there is any
>> interest in this.
>
> I would need to be convinced.

I will try my best ;-), see below

>>
>> Here is my plan:
>>
>> separation of the projects into
>> common (all which is not in the other packages)
>> jdbc3 (contains generated classes)
>> jdbc3g (contains generated classes)
>> jdbc4 (contains generated classes + jdbc4 only code)
>> common-test (all tests)
>>
>> Version information are loaded from property files which can be replaced
>> during build time. The Driver delegates to a DriverVersion class in the
>> common module which provides the version information.
>> An exceptionFactory in the common module provides the "unimplemented"
>> factory method for exceptions.
>>
>> As there are classes in common which references classes in jdbc(3 | 3G | 4)
>> the code needs to be decoupled using interfaces. The lack of interfaces and
>> the wildly use of inheritance instead of composition is the biggest obstacle
>> to decouple modules.
>
> There is a very good reason for this. All of the various versions of
> the driver use common routines to do the heavy lifting. This
> guarantees that regardless of which version you are using it will be
> well tested as the code path is more or less the same.

I agree with reusing the same code for various pieces but this does not require the approach used. Common code can still reside int the common module but the jdbc version specific code can be put into a dedicated project. The fact that a PGPooledconnection extends a AbstractJDBC4* class and a AbstractJDBC3* class is version specific for example.

Introducing interfaces just disconnects from the implementation and as a consequence shared code needs no longer be aware of the implementation. If it asks the service registry for a factory (or service provider) to create a pooled connection it will get a jdbc4 pooled connection if it is a jdbc4 driver. This is more a technical consequence as the common module has no dependency on the jdbc specific project.

This allows to avoid using a script to change parent classes in existing classes. An approach which makes it more difficult to refactor code as the changes cannot be applied to all jdbc versions in parallel. I assume that you have to switch between versions while being coding and reply refactorings as well to the *in Files, as they are not done by the IDE.

A final advantage is that we can compile the different modules with different Java versions and this can be done in your IDE as well. You can use Java version specific language changes which is probably latest required with Java 8 and the new date API.

>
> Dave
>
> --
> Sent via pgsql-jdbc mailing list (pgsql-jdbc(at)postgresql(dot)org)
> To make changes to your subscription:
> http://www.postgresql.org/mailpref/pgsql-jdbc

In response to

Responses

Browse pgsql-jdbc by date

  From Date Subject
Next Message Lew 2012-03-28 04:54:25 Re: Maven based build and refactoring
Previous Message Atri Sharma 2012-03-26 04:29:50 Re: Maven based build and refactoring