Skip to content

Commit

Permalink
Merge pull request vitessio#4441 from systay/jdbc-cleanup
Browse files Browse the repository at this point in the history
Minor cleanups of the JDBC code
  • Loading branch information
mpawliszyn authored Dec 20, 2018
2 parents 7fff616 + 40dafcf commit a3143fe
Show file tree
Hide file tree
Showing 27 changed files with 1,333 additions and 1,341 deletions.
9 changes: 0 additions & 9 deletions java/jdbc/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -81,15 +81,6 @@

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.5</version>
<configuration>
<source>7</source>
<target>7</target>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
Expand Down
10 changes: 5 additions & 5 deletions java/jdbc/src/main/java/io/vitess/jdbc/ConnectionProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@

package io.vitess.jdbc;

import io.vitess.proto.Query;
import io.vitess.proto.Topodata;
import io.vitess.util.Constants;
import io.vitess.util.StringUtils;

import java.io.UnsupportedEncodingException;
import java.lang.reflect.Field;
import java.sql.DriverPropertyInfo;
Expand All @@ -27,11 +32,6 @@
import java.util.Properties;
import java.util.concurrent.TimeUnit;

import io.vitess.proto.Query;
import io.vitess.proto.Topodata;
import io.vitess.util.Constants;
import io.vitess.util.StringUtils;

public class ConnectionProperties {

private static final ArrayList<java.lang.reflect.Field> PROPERTY_LIST = new ArrayList<>();
Expand Down
7 changes: 4 additions & 3 deletions java/jdbc/src/main/java/io/vitess/jdbc/FieldWithMetadata.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,17 @@
package io.vitess.jdbc;

import com.google.common.annotations.VisibleForTesting;
import java.sql.SQLException;
import java.sql.Types;
import java.util.regex.PatternSyntaxException;

import io.vitess.proto.Query;
import io.vitess.util.Constants;
import io.vitess.util.MysqlDefs;
import io.vitess.util.StringUtils;
import io.vitess.util.charset.CharsetMapping;

import java.sql.SQLException;
import java.sql.Types;
import java.util.regex.PatternSyntaxException;

public class FieldWithMetadata {

private final ConnectionProperties connectionProperties;
Expand Down
44 changes: 16 additions & 28 deletions java/jdbc/src/main/java/io/vitess/jdbc/VitessConnection.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

package io.vitess.jdbc;

import io.vitess.client.Context;
import io.vitess.client.VTGateConnection;
import io.vitess.client.VTSession;
import io.vitess.proto.Query;
import io.vitess.util.CommonUtils;
import io.vitess.util.Constants;
import io.vitess.util.MysqlDefs;

import java.sql.Array;
import java.sql.Blob;
import java.sql.CallableStatement;
Expand All @@ -41,24 +49,13 @@
import java.util.Properties;
import java.util.Set;
import java.util.concurrent.Executor;
import java.util.logging.Logger;

import io.vitess.client.Context;
import io.vitess.client.VTGateConnection;
import io.vitess.client.VTSession;
import io.vitess.proto.Query;
import io.vitess.proto.Vtgate;
import io.vitess.util.CommonUtils;
import io.vitess.util.Constants;
import io.vitess.util.MysqlDefs;

/**
* Created by harshit.gangal on 23/01/16.
*/
public class VitessConnection extends ConnectionProperties implements Connection {

/* Get actual class name to be printed on */
private static Logger logger = Logger.getLogger(VitessConnection.class.getName());
private static DatabaseMetaData databaseMetaData = null;

/**
Expand Down Expand Up @@ -223,9 +220,8 @@ public void close() throws SQLException {
* Return Connection state
*
* @return DatabaseMetadata Object
* @throws SQLException
*/
public boolean isClosed() throws SQLException {
public boolean isClosed() {
return this.closed;
}

Expand Down Expand Up @@ -486,19 +482,17 @@ public void setClientInfo(String name, String value) throws SQLClientInfoExcepti
*
* @param name - Property Name
* @return Property Value
* @throws SQLException
*/
public String getClientInfo(String name) throws SQLException {
public String getClientInfo(String name) {
return null;
}

/**
* TODO: For Implementation Possibility
*
* @return - Property Object
* @throws SQLException
*/
public Properties getClientInfo() throws SQLException {
public Properties getClientInfo() {
return null;
}

Expand Down Expand Up @@ -818,11 +812,11 @@ private String initializeDBProperties() throws SQLException {

if (metadataNullOrClosed()) {
String versionValue;
ResultSet resultSet = null;
VitessStatement vitessStatement = new VitessStatement(this);
try {
resultSet = vitessStatement.executeQuery(
"SHOW VARIABLES WHERE VARIABLE_NAME IN (\'tx_isolation\',\'INNODB_VERSION\', \'lower_case_table_names\')");

try(VitessStatement vitessStatement = new VitessStatement(this);
ResultSet resultSet = vitessStatement.executeQuery(
"SHOW VARIABLES WHERE VARIABLE_NAME IN (\'tx_isolation\',\'INNODB_VERSION\', \'lower_case_table_names\')")
) {
while (resultSet.next()) {
dbVariables.put(resultSet.getString(1), resultSet.getString(2));
}
Expand Down Expand Up @@ -855,13 +849,7 @@ private String initializeDBProperties() throws SQLException {
}
this.dbProperties =
new DBProperties(productVersion, majorVersion, minorVersion, isolationLevel, lowerCaseTables);
} finally {
if (null != resultSet) {
resultSet.close();
}
vitessStatement.close();
}

}
return dbEngine;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

package io.vitess.jdbc;

import io.vitess.util.Constants;

import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

import io.vitess.util.Constants;

/**
* Created by harshit.gangal on 25/01/16.
*/
Expand Down
9 changes: 3 additions & 6 deletions java/jdbc/src/main/java/io/vitess/jdbc/VitessDriver.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@

package io.vitess.jdbc;

import io.vitess.util.Constants;

import java.sql.Connection;
import java.sql.Driver;
import java.sql.DriverManager;
Expand All @@ -25,8 +27,6 @@
import java.util.Properties;
import java.util.logging.Logger;

import io.vitess.util.Constants;

/**
* VitessDriver is the official JDBC driver for Vitess.
*
Expand All @@ -38,9 +38,6 @@
*/
public class VitessDriver implements Driver {

/* Get actual class name to be printed on */
private static Logger logger = Logger.getLogger(VitessDriver.class.getName());

static {
try {
DriverManager.registerDriver(new VitessDriver());
Expand Down Expand Up @@ -73,7 +70,7 @@ public Connection connect(String url, Properties info) throws SQLException {
* TODO: Write a better regex
*/
@Override
public boolean acceptsURL(String url) throws SQLException {
public boolean acceptsURL(String url) {
return null != url && url.startsWith(Constants.URL_PREFIX);
}

Expand Down
6 changes: 3 additions & 3 deletions java/jdbc/src/main/java/io/vitess/jdbc/VitessJDBCUrl.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.vitess.jdbc;

import io.vitess.util.Constants;
import io.vitess.util.StringUtils;

import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.sql.SQLException;
Expand All @@ -26,9 +29,6 @@
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import io.vitess.util.Constants;
import io.vitess.util.StringUtils;

/**
* VitessJDBCUrl is responsible for parsing a driver URL and Properties object,
* returning a new Properties object with configuration from the URL and passed in Properties
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@

package io.vitess.jdbc;

import io.vitess.proto.Query;
import io.vitess.util.Constants;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
Expand All @@ -24,9 +27,6 @@
import java.sql.SQLFeatureNotSupportedException;
import java.util.logging.Logger;

import io.vitess.proto.Query;
import io.vitess.util.Constants;

/**
* Created by ashudeep.sharma on 15/02/16.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
package io.vitess.jdbc;

import com.google.common.annotations.VisibleForTesting;
import org.apache.commons.lang.StringUtils;

import io.vitess.proto.Query;
import io.vitess.util.Constants;
import io.vitess.util.MysqlDefs;

import java.sql.Connection;
import java.sql.DatabaseMetaData;
import java.sql.ResultSet;
Expand All @@ -35,11 +41,6 @@
import java.util.StringTokenizer;
import java.util.TreeMap;
import java.util.logging.Logger;
import org.apache.commons.lang.StringUtils;

import io.vitess.proto.Query;
import io.vitess.util.Constants;
import io.vitess.util.MysqlDefs;

/**
* Created by ashudeep.sharma on 15/02/16.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,14 @@

package io.vitess.jdbc;

import io.vitess.client.Context;
import io.vitess.client.VTGateConnection;
import io.vitess.client.cursor.Cursor;
import io.vitess.client.cursor.CursorWithError;
import io.vitess.mysql.DateTime;
import io.vitess.util.Constants;
import io.vitess.util.StringUtils;

import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
Expand Down Expand Up @@ -48,15 +56,6 @@
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.logging.Logger;

import io.vitess.client.Context;
import io.vitess.client.VTGateConnection;
import io.vitess.client.cursor.Cursor;
import io.vitess.client.cursor.CursorWithError;
import io.vitess.mysql.DateTime;
import io.vitess.util.Constants;
import io.vitess.util.StringUtils;

/**
* Created by harshit.gangal on 25/01/16.
Expand All @@ -70,7 +69,6 @@
public class VitessPreparedStatement extends VitessStatement implements PreparedStatement {

/* Get actual class name to be printed on */
private static Logger logger = Logger.getLogger(VitessPreparedStatement.class.getName());
private final String sql;
private final Map<String, Object> bindVariables;
/**
Expand Down Expand Up @@ -394,7 +392,7 @@ public void addBatch() throws SQLException {
vtGateConn = this.vitessConnection.getVtGateConn();

this.retrieveGeneratedKeys = true; // mimicking mysql-connector-j
/**
/*
* Current api does not support single query and multiple bindVariables list.
* So, List of the query is created to match the bindVariables list.
*/
Expand Down Expand Up @@ -466,9 +464,6 @@ private int calculateParameterCount() throws SQLException {
continue; // inline quote escape
}

inQuotes = !inQuotes;
currentQuoteChar = 0;
} else if (((c == '\'') || (c == '"')) && c == currentQuoteChar) {
inQuotes = !inQuotes;
currentQuoteChar = 0;
}
Expand Down
23 changes: 10 additions & 13 deletions java/jdbc/src/main/java/io/vitess/jdbc/VitessResultSet.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@

import com.google.common.annotations.VisibleForTesting;
import com.google.protobuf.ByteString;

import io.vitess.client.cursor.Cursor;
import io.vitess.client.cursor.Row;
import io.vitess.client.cursor.SimpleCursor;
import io.vitess.proto.Query;
import io.vitess.util.Constants;
import io.vitess.util.StringUtils;

import javax.sql.rowset.serial.SerialClob;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.io.Reader;
Expand Down Expand Up @@ -46,24 +55,12 @@
import java.util.Calendar;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import javax.sql.rowset.serial.SerialClob;

import io.vitess.client.cursor.Cursor;
import io.vitess.client.cursor.Row;
import io.vitess.client.cursor.SimpleCursor;
import io.vitess.proto.Query;
import io.vitess.util.Constants;
import io.vitess.util.StringUtils;

/**
* Created by harshit.gangal on 23/01/16.
*/
public class VitessResultSet implements ResultSet {

/* Get actual class name to be printed on */
private static Logger logger = Logger.getLogger(VitessResultSet.class.getName());

private Cursor cursor;
private List<FieldWithMetadata> fields;
private VitessStatement vitessStatement;
Expand Down Expand Up @@ -765,7 +762,7 @@ public Timestamp getTimestamp(String columnLabel, Calendar cal) throws SQLExcept
return getTimestamp(columnIndex, cal);
}

public boolean isClosed() throws SQLException {
public boolean isClosed() {
return this.closed;
}

Expand Down
Loading

0 comments on commit a3143fe

Please sign in to comment.