Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[misc] code cleaning : small constructor simplification
  • Loading branch information
rusher committed Sep 14, 2017
1 parent 8e08437 commit 4d3e53a
Show file tree
Hide file tree
Showing 29 changed files with 149 additions and 155 deletions.
8 changes: 1 addition & 7 deletions src/main/java/org/mariadb/jdbc/Driver.java
Expand Up @@ -52,14 +52,10 @@

package org.mariadb.jdbc;

import org.mariadb.jdbc.internal.protocol.Protocol;
import org.mariadb.jdbc.internal.util.Utils;
import org.mariadb.jdbc.internal.util.constant.Version;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;

import java.sql.*;
import java.util.Properties;
import java.util.concurrent.locks.ReentrantLock;


public final class Driver implements java.sql.Driver {
Expand Down Expand Up @@ -91,9 +87,7 @@ public Connection connect(final String url, final Properties props) throws SQLEx
//log.info("MariaDB connector : missing Host address");
return null;
} else {
ReentrantLock lock = new ReentrantLock();
Protocol protocol = Utils.retrieveProxy(urlParser, lock);
return MariaDbConnection.newConnection(url, protocol, lock);
return MariaDbConnection.newConnection(urlParser);
}

}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/org/mariadb/jdbc/MariaDbBlob.java
Expand Up @@ -100,7 +100,7 @@ private void writeObject(ObjectOutputStream out)
}

private void readObject(ObjectInputStream in)
throws IOException, ClassNotFoundException {
throws IOException {
actualSize = in.readInt();
blobContent = new byte[actualSize];
if (actualSize > 0) {
Expand Down
18 changes: 9 additions & 9 deletions src/main/java/org/mariadb/jdbc/MariaDbConnection.java
Expand Up @@ -98,7 +98,6 @@ public class MariaDbConnection implements Connection {
* the protocol to communicate with.
*/
private final Protocol protocol;
private final String initialUrl;
private final ClientPrepareStatementCache clientPrepareStatementCache;
public MariaDbPooledConnection pooledConnection;
private CallableStatementCache callableStatementCache;
Expand All @@ -121,21 +120,18 @@ public class MariaDbConnection implements Connection {
/**
* Creates a new connection with a given protocol and query factory.
*
* @param initialUrl initial url
* @param protocol the protocol to use.
* @param lock lock
*/
private MariaDbConnection(String initialUrl, Protocol protocol, ReentrantLock lock) {
public MariaDbConnection(Protocol protocol) {
this.protocol = protocol;
this.initialUrl = initialUrl;
options = protocol.getOptions();
canUseServerTimeout = protocol.versionGreaterOrEqual(10, 1, 2);
sessionStateAware = protocol.sessionStateAware();
nullCatalogMeansCurrent = options.nullCatalogMeansCurrent;
if (options.cacheCallableStmts) {
callableStatementCache = CallableStatementCache.newInstance(options.callableStmtCacheSize);
}
this.lock = lock;
this.lock = protocol.getLock();

if (options.cachePrepStmts) {
this.clientPrepareStatementCache = ClientPrepareStatementCache.newInstance(options.prepStmtCacheSize);
Expand All @@ -144,8 +140,9 @@ private MariaDbConnection(String initialUrl, Protocol protocol, ReentrantLock lo
}
}

public static MariaDbConnection newConnection(String initialUrl, Protocol protocol, ReentrantLock lock) {
return new MariaDbConnection(initialUrl, protocol, lock);
public static MariaDbConnection newConnection(UrlParser urlParser) throws SQLException {
Protocol protocol = Utils.retrieveProxy(urlParser);
return new MariaDbConnection(protocol);
}

public static String quoteIdentifier(String string) {
Expand Down Expand Up @@ -775,7 +772,10 @@ public boolean isClosed() throws SQLException {
* @throws SQLException if there is a problem creating the meta data.
*/
public DatabaseMetaData getMetaData() throws SQLException {
return new MariaDbDatabaseMetaData(this, protocol.getUsername(), initialUrl);
return new MariaDbDatabaseMetaData(
this,
protocol.getUsername(),
protocol.getUrlParser().getInitialUrl());
}

/**
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/org/mariadb/jdbc/MariaDbDataSource.java
Expand Up @@ -254,9 +254,7 @@ public void setServerName(String serverName) {
*/
public Connection getConnection() throws SQLException {
try {
ReentrantLock lock = new ReentrantLock();
Protocol proxyfiedProtocol = Utils.retrieveProxy(urlParser, lock);
return MariaDbConnection.newConnection(urlParser.getInitialUrl(), proxyfiedProtocol, lock);
return MariaDbConnection.newConnection(urlParser);
} catch (SQLException e) {
ExceptionMapper.throwException(e, null, null);
return null;
Expand Down
Expand Up @@ -229,7 +229,7 @@ public static ColumnInformation create(String name, ColumnType type) {
arr[pos++] = 0; /* decimals */

arr[pos++] = 0; /* 2 bytes filler */
arr[pos++] = 0;
arr[pos] = 0;

return new ColumnInformation(new Buffer(arr));
}
Expand Down
Expand Up @@ -172,10 +172,8 @@ public boolean verify(String host, SSLSession session, long serverThreadId) {
* @throws SSLException exception
*/
public void verify(String host, X509Certificate cert, long serverThreadId) throws SSLException {
if (host == null) return; //no validation if no host (possible for name pipe)
String lowerCaseHost = host.toLowerCase(Locale.ROOT);

if (lowerCaseHost == null) return; //no validation if no host (possible for name pipe)

try {
//***********************************************************
// RFC 6125 : check Subject Alternative Name (SAN)
Expand Down
Expand Up @@ -641,7 +641,7 @@ private static Options parse(HaMode haMode, Properties properties, Options param
*
* @param optionName current option name
* @param properties list of properties
* @return properties or alias value if existant
* @return properties or alias value if existant
*/
private static String handleAlias(String optionName, Properties properties) {
String propertyValue = properties.getProperty(optionName);
Expand Down

0 comments on commit 4d3e53a

Please sign in to comment.