Maven based build and refactoring - Mailing list pgsql-jdbc

From Sebastian Hennebrueder
Subject Maven based build and refactoring
Date
Msg-id CADD181A-426A-4134-95E0-A1C25C154993@laliluna.de
Whole thread Raw
Responses Re: Maven based build and refactoring  ("Atri Sharma" <atri.jiit@gmail.com>)
Re: Maven based build and refactoring  (Dave Cramer <pg@fastcrypt.com>)
List pgsql-jdbc
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.

I found the building mechanism a little bit special and played with refactoring the code such that a Maven build could work.

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.

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.
This is the bigger change, I am about to do. 

I would introduce a Service registry, which can create providers for various interfaces. The driver could register on start up (static block) . Here is a conceptual piece of code:

class ServiceRegistry{
 static Map<Class,Provider> interfaceProviderMap
public static Provider getProvider(Class aClass){ … }
}

The code in the class PGObjectFactory in the method could then be changed from

private Object loadSimpleDataSource(Reference ref)
    {
        PGSimpleDataSource ds = new PGSimpleDataSource();
        return loadBaseDataSource(ds, ref);
    }

to
private Object loadSimpleDataSource(Reference ref)
    {
Provider provider = ServiceRegistry.getProvider(PGSimpleDataSourceInterface.class);
        PGSimpleDataSourceInterface ds = provider.create();
        return loadBaseDataSource(ds, ref);
    }


-- 
Best Regards / Viele Grüße

Sebastian Hennebrueder

-----
http://www.laliluna.de
Java software developer and trainer for Hibernate and Java Persistence

pgsql-jdbc by date:

Previous
From: Sebastian Hennebrueder
Date:
Subject: Official source repository
Next
From: "Atri Sharma"
Date:
Subject: Re: Maven based build and refactoring