Permalink
Browse files

refactor: fix getDriverVersion, getDriverName and getJDBCMajor/MinorV…

…ersion methods (#668)
  • Loading branch information...
jorsol authored and vlsi committed Jan 20, 2017
1 parent e1a2578 commit aa9743417f18a10a1a7c7a4bc25ad2862155ddc8
@@ -447,37 +447,14 @@ public boolean acceptsURL(String url) {
return props;
}
public static final int MAJORVERSION =
/*$mvn.project.property.parsedversion.majorversion+";"$*//*-*/9;
/**
* Gets the drivers major version number
*
* @return the drivers major version number
*/
@Override
public int getMajorVersion() {
return MAJORVERSION;
return org.postgresql.util.DriverInfo.MAJOR_VERSION;
}
public static final int MINORVERSION =
/*$mvn.project.property.parsedversion.minorversion+";"$*//*-*/4;
/**
* Get the drivers minor version number
*
* @return the drivers minor version number
*/
@Override
public int getMinorVersion() {
return MINORVERSION;
}
/**
* Returns the server version series of this driver and the specific build number.
*
* @return JDBC driver version
*/
public static String getVersion() {
return "PostgreSQL /*$mvn.project.property.parsedversion.osgiversion$*/";
return org.postgresql.util.DriverInfo.MINOR_VERSION;
}
/**
@@ -5,6 +5,7 @@
package org.postgresql;
import org.postgresql.util.DriverInfo;
import org.postgresql.util.GT;
import org.postgresql.util.PSQLException;
import org.postgresql.util.PSQLState;
@@ -281,7 +282,7 @@
/**
* The application name (require server version >= 9.0)
*/
APPLICATION_NAME("ApplicationName", null, "name of the application (backend >= 9.0)"),
APPLICATION_NAME("ApplicationName", DriverInfo.DRIVER_NAME, "Name of the Application (backend >= 9.0)"),
/**
* Specifies the name of the JAAS system or application login configuration.
@@ -44,7 +44,7 @@
* Gets a description of this DataSource.
*/
public String getDescription() {
return "ConnectionPoolDataSource from " + org.postgresql.Driver.getVersion();
return "ConnectionPoolDataSource from " + org.postgresql.util.DriverInfo.DRIVER_FULL_NAME;
}
/**
@@ -78,7 +78,7 @@ public static PGPoolingDataSource getDataSource(String name) {
* Gets a description of this DataSource.
*/
public String getDescription() {
return "Pooling DataSource '" + dataSourceName + " from " + org.postgresql.Driver.getVersion();
return "Pooling DataSource '" + dataSourceName + " from " + org.postgresql.util.DriverInfo.DRIVER_FULL_NAME;
}
/**
@@ -28,7 +28,7 @@
* Gets a description of this DataSource.
*/
public String getDescription() {
return "Non-Pooling DataSource from " + org.postgresql.Driver.getVersion();
return "Non-Pooling DataSource from " + org.postgresql.util.DriverInfo.DRIVER_FULL_NAME;
}
private void writeObject(ObjectOutputStream out) throws IOException {
@@ -214,7 +214,7 @@ public PgConnection(HostSpec[] hostSpecs,
// Print out the driver version number
if (logger.logInfo()) {
logger.info(Driver.getVersion());
logger.info(org.postgresql.util.DriverInfo.DRIVER_FULL_NAME);
}
// Now make the initial connection and set up local state
@@ -5,7 +5,6 @@
package org.postgresql.jdbc;
import org.postgresql.Driver;
import org.postgresql.core.BaseStatement;
import org.postgresql.core.Field;
import org.postgresql.core.Oid;
@@ -37,7 +36,6 @@ public PgDatabaseMetaData(PgConnection conn) {
this.connection = conn;
}
private static final String keywords = "abort,acl,add,aggregate,append,archive,"
+ "arch_store,backward,binary,boolean,change,cluster,"
+ "copy,database,delimiter,delimiters,do,extend,"
@@ -138,35 +136,39 @@ public boolean nullsAreSortedAtEnd() throws SQLException {
}
/**
* What is the name of this database product - we hope that it is PostgreSQL, so we return that
* Retrieves the name of this database product. We hope that it is PostgreSQL, so we return that
* explicitly.
*
* @return the database product name
*
* @exception SQLException if a database access error occurs
* @return "PostgreSQL"
*/
@Override
public String getDatabaseProductName() throws SQLException {
return "PostgreSQL";
}
@Override
public String getDatabaseProductVersion() throws SQLException {
return connection.getDBVersionNumber();
}
public String getDriverName() throws SQLException {
return "PostgreSQL Native Driver";
@Override
public String getDriverName() {
return org.postgresql.util.DriverInfo.DRIVER_NAME;
}
public String getDriverVersion() throws SQLException {
return Driver.getVersion();
@Override
public String getDriverVersion() {
return org.postgresql.util.DriverInfo.DRIVER_VERSION;
}
@Override
public int getDriverMajorVersion() {
return Driver.MAJORVERSION;
return org.postgresql.util.DriverInfo.MAJOR_VERSION;
}
@Override
public int getDriverMinorVersion() {
return Driver.MINORVERSION;
return org.postgresql.util.DriverInfo.MINOR_VERSION;
}
/**
@@ -2539,11 +2541,6 @@ public ResultSet getFunctionColumns(String catalog, String schemaPattern,
return getProcedureColumns(catalog, schemaPattern, functionNamePattern, columnNamePattern);
}
public int getJDBCMajorVersion() throws SQLException {
// FIXME: dependent on JDBC version
return 4;
}
public ResultSet getPseudoColumns(String catalog, String schemaPattern, String tableNamePattern,
String columnNamePattern) throws SQLException {
throw org.postgresql.Driver.notImplemented(this.getClass(),
@@ -2599,20 +2596,28 @@ public int getResultSetHoldability() throws SQLException {
return ResultSet.HOLD_CURSORS_OVER_COMMIT;
}
@Override
public int getDatabaseMajorVersion() throws SQLException {
return connection.getServerMajorVersion();
}
@Override
public int getDatabaseMinorVersion() throws SQLException {
return connection.getServerMinorVersion();
}
public int getJDBCMinorVersion() throws SQLException {
return 0; // This class implements JDBC 3.0
@Override
public int getJDBCMajorVersion() {
return org.postgresql.util.DriverInfo.JDBC_MAJOR_VERSION;
}
@Override
public int getJDBCMinorVersion() {
return org.postgresql.util.DriverInfo.JDBC_MINOR_VERSION;
}
public int getSQLStateType() throws SQLException {
return sqlStateSQL99;
return sqlStateSQL;
}
public boolean locatorsUpdateCopy() throws SQLException {
@@ -24,8 +24,8 @@
public void start(BundleContext context) throws Exception {
Dictionary<String, Object> properties = new Hashtable<String, Object>();
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_CLASS, Driver.class.getName());
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_NAME, "PostgreSQL JDBC Driver");
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_VERSION, Driver.getVersion());
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_NAME, org.postgresql.util.DriverInfo.DRIVER_NAME);
properties.put(DataSourceFactory.OSGI_JDBC_DRIVER_VERSION, org.postgresql.util.DriverInfo.DRIVER_VERSION);
try {
_registration = context.registerService(DataSourceFactory.class.getName(),
new PGDataSourceFactory(), properties);
@@ -0,0 +1,33 @@
/*
* Copyright (c) 2017, PostgreSQL Global Development Group
* See the LICENSE file in the project root for more information.
*/
package org.postgresql.util;
/**
* Utility class with constants of Driver information.
*/
public final class DriverInfo {
private DriverInfo() {
}
// Driver name
public static final String DRIVER_NAME = "PostgreSQL JDBC Driver";
public static final String DRIVER_SHORT_NAME = "PgJDBC";
public static final String DRIVER_VERSION = "/*$mvn.project.property.parsedversion.osgiversion$*/";
public static final String DRIVER_FULL_NAME = DRIVER_NAME + " " + DRIVER_VERSION;
// Driver version
public static final int MAJOR_VERSION = /*$mvn.project.property.parsedversion.majorversion+";"$*//*-*/42;
public static final int MINOR_VERSION = /*$mvn.project.property.parsedversion.minorversion+";"$*//*-*/0;
public static final int PATCH_VERSION = /*$mvn.project.property.parsedversion.incrementalversion+";"$*//*-*/0;
// JDBC specification
public static final String JDBC_VERSION = "/*$mvn.project.property.jdbc.specification.version$*/";
private static final int JDBC_INTVERSION = /*$mvn.project.property.jdbc.specification.version.nodot+";"$*//*-*/42;
public static final int JDBC_MAJOR_VERSION = JDBC_INTVERSION / 10;
public static final int JDBC_MINOR_VERSION = JDBC_INTVERSION % 10;
}
@@ -5,19 +5,23 @@
package org.postgresql.util;
import org.postgresql.Driver;
public class PGJDBCMain {
public static void main(String[] args) {
PSQLDriverVersion.main(args);
java.net.URL url = Driver.class.getResource("/org/postgresql/Driver.class");
System.out.printf("%n%s%n", org.postgresql.util.DriverInfo.DRIVER_FULL_NAME);
System.out.printf("Found in: %s%n%n", url);
System.out.println("\nThe PgJDBC driver is not an executable Java program.\n\n"
+ "You must install it according to the JDBC driver installation "
+ "instructions for your application / container / appserver, "
+ "then use it by specifying a JDBC URL of the form \n" + " jdbc:postgresql://\n"
+ "or using an application specific method.\n\n"
+ "See the PgJDBC documentation: http://jdbc.postgresql.org/documentation/head/index.html\n\n"
+ "This command has had no effect.\n");
System.out.printf("The PgJDBC driver is not an executable Java program.%n%n"
+ "You must install it according to the JDBC driver installation "
+ "instructions for your application / container / appserver, "
+ "then use it by specifying a JDBC URL of the form %n jdbc:postgresql://%n"
+ "or using an application specific method.%n%n"
+ "See the PgJDBC documentation: http://jdbc.postgresql.org/documentation/head/index.html%n%n"
+ "This command has had no effect.%n");
System.exit(1);
}

This file was deleted.

Oops, something went wrong.
@@ -50,7 +50,7 @@ public XAConnection getXAConnection(String user, String password) throws SQLExce
}
public String getDescription() {
return "JDBC3 XA-enabled DataSource from " + org.postgresql.Driver.getVersion();
return "XA-enabled DataSource from " + org.postgresql.util.DriverInfo.DRIVER_FULL_NAME;
}
/**
@@ -195,16 +195,21 @@ public void testDbProductDetails() throws SQLException {
assertNotNull(dbmd);
assertTrue(dbmd.getDatabaseProductName().equals("PostgreSQL"));
assertTrue(dbmd.getDatabaseMajorVersion() >= 8);
assertTrue(dbmd.getDatabaseMinorVersion() >= 0);
assertTrue(dbmd.getDatabaseProductVersion().startsWith(String.valueOf(dbmd.getDatabaseMajorVersion())));
}
@Test
public void testDriverVersioning() throws SQLException {
DatabaseMetaData dbmd = con.getMetaData();
assertNotNull(dbmd);
assertTrue(dbmd.getDriverVersion().equals(org.postgresql.Driver.getVersion()));
assertTrue(dbmd.getDriverMajorVersion() == org.postgresql.Driver.MAJORVERSION);
assertTrue(dbmd.getDriverMinorVersion() == org.postgresql.Driver.MINORVERSION);
assertTrue(dbmd.getDriverName().equals("PostgreSQL JDBC Driver"));
assertTrue(dbmd.getDriverVersion().equals(org.postgresql.util.DriverInfo.DRIVER_VERSION));
assertTrue(dbmd.getDriverMajorVersion() == new org.postgresql.Driver().getMajorVersion());
assertTrue(dbmd.getDriverMinorVersion() == new org.postgresql.Driver().getMinorVersion());
assertTrue(dbmd.getJDBCMajorVersion() >= 4);
assertTrue(dbmd.getJDBCMinorVersion() >= 0);
}
}

0 comments on commit aa97434

Please sign in to comment.