Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
[misc] java code cleaning
  • Loading branch information
rusher committed Aug 28, 2017
1 parent 8fb92e3 commit ff91ae0
Show file tree
Hide file tree
Showing 192 changed files with 2,437 additions and 3,081 deletions.
2 changes: 0 additions & 2 deletions .travis.yml
Expand Up @@ -16,15 +16,13 @@ install:
- .travis/gen-ssl.sh mariadb.example.com tmp
- export PROJ_PATH=`pwd`
- export SSLCERT=$PROJ_PATH/tmp
# - set SSLCERT=C:/projects/ssl
- export ENTRYPOINT=$PROJ_PATH/.travis/sql

cache:
directories:
- $HOME/.m2

jdk:
# - oraclejdk9
- oraclejdk8

env:
Expand Down
4 changes: 2 additions & 2 deletions .travis/maxscale/Dockerfile
Expand Up @@ -6,10 +6,10 @@ ENV MAXSCALE_VERSION ${MAXSCALE_VERSION:-2.1.4}
COPY maxscale/mariadb.repo /etc/yum.repos.d/

RUN rpm --import https://yum.mariadb.org/RPM-GPG-KEY-MariaDB \
&& yum -y install https://downloads.mariadb.com/MaxScale/$MAXSCALE_VERSION/centos/7/x86_64/maxscale-$MAXSCALE_VERSION-1.centos.7.x86_64.rpm \
&& yum -y install https://downloads.mariadb.com/MaxScale/${MAXSCALE_VERSION}/centos/7/x86_64/maxscale-${MAXSCALE_VERSION}-1.centos.7.x86_64.rpm \
&& yum -y update

RUN yum -y install maxscale-$MAXSCALE_VERSION MariaDB-client \
RUN yum -y install maxscale-${MAXSCALE_VERSION} MariaDB-client \
&& yum clean all \
&& rm -rf /tmp/*

Expand Down
14 changes: 7 additions & 7 deletions .travis/script.sh
Expand Up @@ -52,7 +52,7 @@ then
mv src/test/resources/logback-test-travis.xml src/test/resources/logback-test.xml
fi

cmd=( mvn clean test $ADDITIONNAL_VARIABLES -DjobId=$TRAVIS_JOB_ID \
cmd=( mvn clean test $ADDITIONNAL_VARIABLES -DjobId=${TRAVIS_JOB_ID} \
-DkeystorePath="$SSLCERT/client-keystore.jks" \
-DkeystorePassword="kspass" \
-DserverCertificatePath="$SSLCERT/server.crt" \
Expand All @@ -65,7 +65,7 @@ if [ -n "$AURORA" ]
then
if [ -n "$AURORA_STRING_URL" ]
then
urlString=$AURORA_STRING_URL
urlString=${AURORA_STRING_URL}
testSingleHost=true
else
testSingleHost=false
Expand All @@ -77,9 +77,9 @@ else
###################################################################################################################
# launch docker server and maxscale
###################################################################################################################
export INNODB_LOG_FILE_SIZE=$(echo $PACKET| cut -d'M' -f 1)0M
docker-compose -f $COMPOSE_FILE build
docker-compose -f $COMPOSE_FILE up -d
export INNODB_LOG_FILE_SIZE=$(echo ${PACKET}| cut -d'M' -f 1)0M
docker-compose -f ${COMPOSE_FILE} build
docker-compose -f ${COMPOSE_FILE} up -d

###################################################################################################################
# launch 3 galera servers
Expand All @@ -104,7 +104,7 @@ else
sleep 1
done

docker-compose -f $COMPOSE_FILE logs
docker-compose -f ${COMPOSE_FILE} logs

if [ "$i" = 0 ]; then
echo 'SELECT 1' | "${mysql[@]}"
Expand All @@ -121,7 +121,7 @@ fi
echo "Running coveralls for JDK version: $TRAVIS_JDK_VERSION"
cmd+=( -DdbUrl="$urlString" )
cmd+=( -DtestSingleHost="$testSingleHost" )
echo $cmd
echo ${cmd}

"${cmd[@]}"
if [ -n "$PROFILE" ]
Expand Down
1 change: 1 addition & 0 deletions README.md
Expand Up @@ -16,6 +16,7 @@ Tracker link <a href="https://jira.mariadb.org/projects/CONJ/issues/">https://ji
[![Maven Central](https://maven-badges.herokuapp.com/maven-central/org.mariadb.jdbc/mariadb-java-client/badge.svg)](https://maven-badges.herokuapp.com/maven-central/org.mariadb.jdbc/mariadb-java-client)
[![License (LGPL version 2.1)](https://img.shields.io/badge/license-GNU%20LGPL%20version%202.1-green.svg?style=flat-square)](http://opensource.org/licenses/LGPL-2.1)
[![Known Vulnerabilities](https://snyk.io/test/github/mariadb/mariadb-connector-j/badge.svg)](https://snyk.io/test/github/mariadb/mariadb-connector-j)
[![Codacy Badge](https://api.codacy.com/project/badge/Grade/be7f4c89d63e496d824e8f365478e8c8)](https://www.codacy.com/app/diego-dupin/mariadb-connector-j?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=MariaDB/mariadb-connector-j&amp;utm_campaign=Badge_Grade)

## Obtaining the driver

Expand Down
1 change: 1 addition & 0 deletions build.xml
Expand Up @@ -56,6 +56,7 @@
<!-- Ant build file (http://ant.apache.org/) for Ant 1.6.2 or above. -->
<!-- ====================================================================== -->

<!--suppress XmlUnboundNsPrefix -->
<project name="mariadb-java-client" default="package" basedir=".">

<!-- ====================================================================== -->
Expand Down
1 change: 1 addition & 0 deletions maven-build.properties
@@ -1,3 +1,4 @@
# suppress inspection "UnusedProperty" for whole file
#
# /*
# MariaDB Client for Java
Expand Down
18 changes: 5 additions & 13 deletions src/main/java/org/mariadb/jdbc/BasePrepareStatement.java
Expand Up @@ -56,7 +56,6 @@
import org.mariadb.jdbc.internal.com.send.parameters.*;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;

import java.io.IOException;
import java.io.InputStream;
import java.io.Reader;
import java.math.BigDecimal;
Expand Down Expand Up @@ -97,7 +96,7 @@ public abstract class BasePrepareStatement extends MariaDbStatement implements P
.appendLiteral(']')
.toFormatter();

protected boolean useFractionalSeconds;
private boolean useFractionalSeconds;
protected int autoGeneratedKeys;
protected boolean hasLongData = false;
private boolean noBackslashEscapes;
Expand Down Expand Up @@ -940,13 +939,8 @@ public void setObject(final int parameterIndex, final Object obj) throws SQLExce
setTime(parameterIndex, Time.valueOf(LocalTime.class.cast(obj)));
} else {
//fallback to sending serialized object
try {
setParameter(parameterIndex, new SerializableParameter(obj, noBackslashEscapes));
hasLongData = true;
} catch (IOException e) {
throw ExceptionMapper.getSqlException(
"Could not set parameter in setObject, Object class is not handled (Class : " + obj.getClass() + ")");
}
setParameter(parameterIndex, new SerializableParameter(obj, noBackslashEscapes));
hasLongData = true;
}
}

Expand All @@ -960,8 +954,8 @@ public void setObject(int parameterIndex, Object obj, SQLType targetSqlType) thr
setObject(parameterIndex, obj, targetSqlType.getVendorTypeNumber());
}

protected void setInternalObject(final int parameterIndex, final Object obj, final int targetSqlType,
final long scaleOrLength) throws SQLException {
private void setInternalObject(final int parameterIndex, final Object obj, final int targetSqlType,
final long scaleOrLength) throws SQLException {
switch (targetSqlType) {
case Types.ARRAY:
case Types.DATALINK:
Expand Down Expand Up @@ -1123,8 +1117,6 @@ protected void setInternalObject(final int parameterIndex, final Object obj, fin
setBoolean(parameterIndex, (Boolean) obj);
} else if (obj instanceof Blob) {
setBlob(parameterIndex, (Blob) obj);
} else if (obj instanceof BigInteger) {
setString(parameterIndex, obj.toString());
} else if (obj instanceof Clob) {
setClob(parameterIndex, (Clob) obj);
} else if (obj instanceof InputStream) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/mariadb/jdbc/BlobOutputStream.java
Expand Up @@ -60,8 +60,8 @@
*/
class BlobOutputStream extends OutputStream {

int pos;
MariaDbBlob blob;
private int pos;
private final MariaDbBlob blob;

public BlobOutputStream(MariaDbBlob blob, int pos) {
this.blob = blob;
Expand Down
111 changes: 100 additions & 11 deletions src/main/java/org/mariadb/jdbc/CallParameter.java
Expand Up @@ -58,20 +58,109 @@
* Info about in/out parameters.
*/
class CallParameter {
boolean isInput;
boolean isOutput;
int sqlType;
int outputSqlType;
int scale;
String typeName;
boolean isSigned;
int isNullable;
int precision;
String className;
String name;

private boolean isInput;
private boolean isOutput;
private int sqlType;
private int outputSqlType;
private int scale;
private String typeName;
private boolean isSigned;
private int canBeNull;
private int precision;
private String className;
private String name;

public CallParameter() {
sqlType = Types.OTHER;
outputSqlType = Types.OTHER;
}

public boolean isInput() {
return isInput;
}

public void setInput(boolean input) {
isInput = input;
}

public boolean isOutput() {
return isOutput;
}

public void setOutput(boolean output) {
isOutput = output;
}

public int getSqlType() {
return sqlType;
}

public void setSqlType(int sqlType) {
this.sqlType = sqlType;
}

public int getOutputSqlType() {
return outputSqlType;
}

public void setOutputSqlType(int outputSqlType) {
this.outputSqlType = outputSqlType;
}

public int getScale() {
return scale;
}

public void setScale(int scale) {
this.scale = scale;
}

public String getTypeName() {
return typeName;
}

public void setTypeName(String typeName) {
this.typeName = typeName;
}

public boolean isSigned() {
return isSigned;
}

public void setSigned(boolean signed) {
isSigned = signed;
}

public int getCanBeNull() {
return canBeNull;
}

public void setCanBeNull(int canBeNull) {
this.canBeNull = canBeNull;
}

public int getPrecision() {
return precision;
}

public void setPrecision(int precision) {
this.precision = precision;
}

public String getClassName() {
return className;
}

public void setClassName(String className) {
this.className = className;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}
}
29 changes: 14 additions & 15 deletions src/main/java/org/mariadb/jdbc/CallableFunctionStatement.java
Expand Up @@ -69,7 +69,7 @@ public abstract class CallableFunctionStatement extends MariaDbPreparedStatement
/**
* Information about parameters, merely from registerOutputParameter() and setXXX() calls.
*/
protected CallParameter[] params;
private CallParameter[] params;
protected CallableParameterMetaData parameterMetadata;

/**
Expand Down Expand Up @@ -115,11 +115,11 @@ public void initFunctionData(int parametersCount) {
for (int i = 0; i < parametersCount; i++) {
params[i] = new CallParameter();
if (i > 0) {
params[i].isInput = true;
params[i].setInput(true);
}
}
// the query was in the form {?=call function()}, so the first parameter is always output
params[0].isOutput = true;
params[0].setOutput(true);
}

protected abstract SelectResultSet getResult() throws SQLException;
Expand All @@ -136,7 +136,7 @@ public ParameterMetaData getParameterMetaData() throws SQLException {
* @return index
* @throws SQLException exception
*/
protected int nameToIndex(String parameterName) throws SQLException {
private int nameToIndex(String parameterName) throws SQLException {
parameterMetadata.readMetadataFromDbIfRequired();
for (int i = 1; i <= parameterMetadata.getParameterCount(); i++) {
String name = parameterMetadata.getName(i);
Expand Down Expand Up @@ -170,9 +170,8 @@ private int nameToOutputIndex(String parameterName) throws SQLException {
*
* @param parameterIndex index
* @return index
* @throws SQLException exception
*/
private int indexToOutputIndex(int parameterIndex) throws SQLException {
private int indexToOutputIndex(int parameterIndex) {
return parameterIndex;
}

Expand Down Expand Up @@ -351,7 +350,7 @@ public Timestamp getTimestamp(String parameterName, Calendar cal) throws SQLExce

@Override
public Object getObject(int parameterIndex) throws SQLException {
Class<?> classType = ColumnType.classFromJavaType(getParameter(parameterIndex).outputSqlType);
Class<?> classType = ColumnType.classFromJavaType(getParameter(parameterIndex).getOutputSqlType());
if (classType != null) {
return getResult().getObject(indexToOutputIndex(parameterIndex), classType);
}
Expand All @@ -362,7 +361,7 @@ public Object getObject(int parameterIndex) throws SQLException {
@Override
public Object getObject(String parameterName) throws SQLException {
int index = nameToIndex(parameterName);
Class<?> classType = ColumnType.classFromJavaType(getParameter(index).outputSqlType);
Class<?> classType = ColumnType.classFromJavaType(getParameter(index).getOutputSqlType());
if (classType != null) {
return getResult().getObject(indexToOutputIndex(index), classType);
}
Expand Down Expand Up @@ -541,9 +540,9 @@ public Reader getCharacterStream(String parameterName) throws SQLException {
*/
public void registerOutParameter(int parameterIndex, int sqlType, String typeName) throws SQLException {
CallParameter callParameter = getParameter(parameterIndex);
callParameter.outputSqlType = sqlType;
callParameter.typeName = typeName;
callParameter.isOutput = true;
callParameter.setOutputSqlType(sqlType);
callParameter.setTypeName(typeName);
callParameter.setOutput(true);
}

@Override
Expand Down Expand Up @@ -583,9 +582,9 @@ public void registerOutParameter(int parameterIndex, int sqlType) throws SQLExce
@Override
public void registerOutParameter(int parameterIndex, int sqlType, int scale) throws SQLException {
CallParameter callParameter = getParameter(parameterIndex);
callParameter.isOutput = true;
callParameter.outputSqlType = sqlType;
callParameter.scale = scale;
callParameter.setOutput(true);
callParameter.setOutputSqlType(sqlType);
callParameter.setScale(scale);
}

@Override
Expand Down Expand Up @@ -634,7 +633,7 @@ public void registerOutParameter(String parameterName, SQLType sqlType, String t
registerOutParameter(parameterName, sqlType.getVendorTypeNumber(), typeName);
}

CallParameter getParameter(int index) throws SQLException {
private CallParameter getParameter(int index) throws SQLException {
if (index > params.length || index <= 0) {
throw new SQLException("No parameter with index " + (index));
}
Expand Down

0 comments on commit ff91ae0

Please sign in to comment.