Skip to content

Commit

Permalink
[misc] code formating
Browse files Browse the repository at this point in the history
  • Loading branch information
rusher committed Sep 15, 2015
1 parent 7924c5d commit bb04ba9
Show file tree
Hide file tree
Showing 156 changed files with 7,732 additions and 7,680 deletions.
19 changes: 9 additions & 10 deletions src/main/java/org/mariadb/jdbc/AbstractMySQLPrepareStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,20 +61,19 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import java.net.URL;
import java.sql.*;
import java.util.Calendar;
import java.util.concurrent.locks.ReentrantLock;

public abstract class AbstractMySQLPrepareStatement extends MySQLStatement implements PreparedStatement {
private boolean useFractionalSeconds;
protected abstract boolean isNoBackslashEscapes();

protected abstract boolean useFractionalSeconds();

protected abstract Calendar cal();

public AbstractMySQLPrepareStatement(MySQLConnection connection) {
super(connection);
}

protected abstract boolean isNoBackslashEscapes();

protected abstract boolean useFractionalSeconds();

protected abstract Calendar cal();

/**
* Sets the designated parameter to the given <code>Reader</code> object, which is the given number of characters
Expand Down Expand Up @@ -276,7 +275,7 @@ public void setNull(final int parameterIndex, final int sqlType) throws SQLExcep
* <P><B>Note:</B> You must specify the parameter's SQL type.
*
* @param parameterIndex the first parameter is 1, the second is 2, ...
* @param mysqlType the type code defined in <code> org.mariadb.jdbc.internal.mysql.MySQLType</code>
* @param mysqlType the type code defined in <code> org.mariadb.jdbc.internal.mysql.MySQLType</code>
* @throws java.sql.SQLException if parameterIndex does not correspond to a parameter marker in the SQL statement;
* if a database access error occurs or this method is called on a closed
* <code>PreparedStatement</code>
Expand Down Expand Up @@ -1077,11 +1076,11 @@ public void setObject(final int parameterIndex, final Object x, final int target
setString(parameterIndex, s);
break;
case Types.TIMESTAMP:
if (x!= null && ((String) x).startsWith("0000-00-00")) setTimestamp(parameterIndex, null);
else setTimestamp(parameterIndex, Timestamp.valueOf((String) x));
if (x != null && ((String) x).startsWith("0000-00-00")) setTimestamp(parameterIndex, null);
else setTimestamp(parameterIndex, Timestamp.valueOf((String) x));
break;
case Types.TIME:
setTime(parameterIndex, Time.valueOf((String) x));
setTime(parameterIndex, Time.valueOf((String) x));
break;
default:
throw SQLExceptionMapper.getSQLException("Could not convert [" + s + "] to " + targetSqlType);
Expand Down
36 changes: 15 additions & 21 deletions src/main/java/org/mariadb/jdbc/Driver.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,19 +52,13 @@ WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWIS
import org.mariadb.jdbc.internal.SQLExceptionMapper;
import org.mariadb.jdbc.internal.common.QueryException;
import org.mariadb.jdbc.internal.common.Utils;
import org.mariadb.jdbc.internal.mysql.*;

import java.lang.reflect.Proxy;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.DriverPropertyInfo;
import java.sql.SQLException;
import java.sql.SQLFeatureNotSupportedException;
import org.mariadb.jdbc.internal.mysql.Protocol;

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



public final class Driver implements java.sql.Driver {

static {
Expand All @@ -75,12 +69,21 @@ public final class Driver implements java.sql.Driver {
}
}

/*
Provide a "cleanup" method that can be called after unloading driver, to fix Tomcat's obscure classpath handling.
See CONJ-61.
*/
public static void unloadDriver() {
MySQLStatement.unloadDriver();
}

/**
* Connect to the given connection string.
*
* <p/>
* the properties are currently ignored
*
* @param url the url to connect to
* @param url the url to connect to
* @return a connection
* @throws SQLException if it is not possible to connect
*/
Expand Down Expand Up @@ -113,7 +116,7 @@ public Connection connect(final String url, final Properties props) throws SQLEx
* @return true if the url is valid for this driver
*/
public boolean acceptsURL(String url) {
return JDBCUrl.acceptsURL(url);
return JDBCUrl.acceptsURL(url);
}

/**
Expand Down Expand Up @@ -161,13 +164,4 @@ public java.util.logging.Logger getParentLogger() throws SQLFeatureNotSupportedE
// TODO Auto-generated method stub
return null;
}

/*
Provide a "cleanup" method that can be called after unloading driver, to fix Tomcat's obscure classpath handling.
See CONJ-61.
*/
public static void unloadDriver() {
MySQLStatement.unloadDriver();
}
}
88 changes: 47 additions & 41 deletions src/main/java/org/mariadb/jdbc/HostAddress.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,68 +9,71 @@
public class HostAddress {
public String host;
public int port;
public String type=null;
public String type = null;


public HostAddress() {
}

public HostAddress(String host, int port) {
this.host = host;
this.port = port;
this.type = ParameterConstant.TYPE_MASTER;
}

public HostAddress(String host, int port, String type) {
this.host = host;
this.port = port;
this.type = type;
}

/**
* parse - parse server addresses from the URL fragment
* @param spec - list of endpoints in one of the forms
* 1 - host1,....,hostN:port (missing port default to MySQL default 3306
* 2 - host:port,...,host:port
*
* @param spec - list of endpoints in one of the forms
* 1 - host1,....,hostN:port (missing port default to MySQL default 3306
* 2 - host:port,...,host:port
* @param haMode High availability mode
* @return parsed endpoints
* @return parsed endpoints
*/
public static List<HostAddress> parse(String spec, UrlHAMode haMode) {
if (spec == null) throw new IllegalArgumentException("Invalid connection URL, host address must not be empty ");
String[] tokens = spec.trim().split(",");
List<HostAddress> arr = new ArrayList<>(tokens.length);

for (int i=0; i < tokens.length; i++) {
for (int i = 0; i < tokens.length; i++) {
if (tokens[i].startsWith("address=")) {
arr.add(parseParameterHostAddress(tokens[i]));
} else {
arr.add(parseSimpleHostAddress(tokens[i]));
}
}

int defaultPort = arr.get(arr.size()-1).port;
int defaultPort = arr.get(arr.size() - 1).port;
if (defaultPort == 0) {
defaultPort = 3306;
}

for (int i = 0; i < arr.size(); i++) {
if (haMode == UrlHAMode.REPLICATION) {
if (i==0 && arr.get(i).type == null) arr.get(i).type = ParameterConstant.TYPE_MASTER;
else if (i!=0 && arr.get(i).type == null) arr.get(i).type = ParameterConstant.TYPE_SLAVE;
if (i == 0 && arr.get(i).type == null) arr.get(i).type = ParameterConstant.TYPE_MASTER;
else if (i != 0 && arr.get(i).type == null) arr.get(i).type = ParameterConstant.TYPE_SLAVE;
}
if (arr.get(i).port == 0) {
arr.get(i).port = defaultPort;
}
}
return arr;
}
public HostAddress() {}

public HostAddress(String host, int port) {
this.host = host;
this.port = port;
this.type = ParameterConstant.TYPE_MASTER;
}

public HostAddress(String host, int port, String type) {
this.host = host;
this.port = port;
this.type = type;
}

static HostAddress parseSimpleHostAddress(String s) {
HostAddress result = new HostAddress();
if (s.startsWith("[")) {
/* IPv6 addresses in URLs are enclosed in square brackets */
/* IPv6 addresses in URLs are enclosed in square brackets */
int ind = s.indexOf(']');
result.host = s.substring(1,ind);
if (ind != (s.length() -1) && s.charAt(ind + 1) == ':') {
result.port = Integer.parseInt(s.substring(ind+2));
result.host = s.substring(1, ind);
if (ind != (s.length() - 1) && s.charAt(ind + 1) == ':') {
result.port = Integer.parseInt(s.substring(ind + 2));
}
} else if (s.contains(":")) {
/* Parse host:port */
Expand All @@ -83,51 +86,54 @@ static HostAddress parseSimpleHostAddress(String s) {
}
return result;
}

static HostAddress parseParameterHostAddress(String s) {
HostAddress result = new HostAddress();
String[] array = s.split("(?=\\()|(?<=\\))");
for (int i=1;i< array.length;i++) {
String[] token = array[i].replace("(","").replace(")","").trim().split("=");
if (token.length != 2) throw new IllegalArgumentException("Invalid connection URL, expected key=value pairs, found " + array[i]);
for (int i = 1; i < array.length; i++) {
String[] token = array[i].replace("(", "").replace(")", "").trim().split("=");
if (token.length != 2)
throw new IllegalArgumentException("Invalid connection URL, expected key=value pairs, found " + array[i]);
String key = token[0].toLowerCase();
String value = token[1].toLowerCase();
if (key.equals("host")) {
result.host=value.replace("[","").replace("]", "");
result.host = value.replace("[", "").replace("]", "");
} else if (key.equals("port")) {
result.port=Integer.parseInt(value);
result.port = Integer.parseInt(value);
} else if (key.equals("type")) {
if (value.equals(ParameterConstant.TYPE_MASTER) || value.equals(ParameterConstant.TYPE_SLAVE))result.type=value;
if (value.equals(ParameterConstant.TYPE_MASTER) || value.equals(ParameterConstant.TYPE_SLAVE))
result.type = value;
}
}
return result;
}

public static String toString(List<HostAddress> addrs) {
String s="";
for(int i=0; i < addrs.size(); i++) {
String s = "";
for (int i = 0; i < addrs.size(); i++) {
if (addrs.get(i).type != null) {
s+="address=(host="+addrs.get(i).host+")(port="+addrs.get(i).port+")(type="+addrs.get(i).type+")";
s += "address=(host=" + addrs.get(i).host + ")(port=" + addrs.get(i).port + ")(type=" + addrs.get(i).type + ")";
} else {
boolean isIPv6 = addrs.get(i).host != null && addrs.get(i).host.contains(":");
String host = (isIPv6) ? ("[" + addrs.get(i).host + "]") : addrs.get(i).host;
s += host + ":" + addrs.get(i).port;
}
if (i < addrs.size() -1) s += ",";
if (i < addrs.size() - 1) s += ",";
}
return s;
}

public static String toString(HostAddress[] addrs) {
String s="";
for(int i=0; i < addrs.length; i++) {
String s = "";
for (int i = 0; i < addrs.length; i++) {
if (addrs[i].type != null) {
s+="address=(host="+addrs[i].host+")(port="+addrs[i].port+")(type="+addrs[i].type+")";
s += "address=(host=" + addrs[i].host + ")(port=" + addrs[i].port + ")(type=" + addrs[i].type + ")";
} else {
boolean isIPv6 = addrs[i].host != null && addrs[i].host.contains(":");
String host = (isIPv6)?("[" + addrs[i].host + "]"):addrs[i].host;
String host = (isIPv6) ? ("[" + addrs[i].host + "]") : addrs[i].host;
s += host + ":" + addrs[i].port;
}
if (i < addrs.length -1) s += ",";
if (i < addrs.length - 1) s += ",";
}
return s;
}
Expand Down
Loading

0 comments on commit bb04ba9

Please sign in to comment.