Skip to content

Commit

Permalink
[misc] Various change
Browse files Browse the repository at this point in the history
- Exception handling refactoring:
     * Sql is now only on first Exception of stracktrace
     * Always have thread id logged but for generic exception
     * ensure to log sql when on dumpQueriesOnException is enable
- ColumnDefinition renaming to follow protocol description
- Blob faster position() implementation
- unnamed Savepoint now generate unique internal identifier
  • Loading branch information
rusher committed Jan 31, 2020
1 parent 6a6e2c3 commit fcbcbc1
Show file tree
Hide file tree
Showing 65 changed files with 1,456 additions and 1,716 deletions.
4 changes: 2 additions & 2 deletions .travis/build/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ RUN apt-get update && apt-get install -y --no-install-recommends \
&& rm -rf /var/lib/apt/lists/*

RUN { \
echo "mariadb-server-10.4" mysql-server/root_password password 'unused'; \
echo "mariadb-server-10.4" mysql-server/root_password_again password 'unused'; \
echo "mariadb-server-10.5" mysql-server/root_password password 'unused'; \
echo "mariadb-server-10.5" mysql-server/root_password_again password 'unused'; \
} | debconf-set-selections

RUN apt-get update -y
Expand Down
8 changes: 4 additions & 4 deletions .travis/build/build.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@ echo "**************************************************************************
echo "* searching for last complete build"
echo "**************************************************************************"

wget -q -o /dev/null index.html http://hasky.askmonty.org/archive/10.4/
wget -q -o /dev/null index.html http://hasky.askmonty.org/archive/10.5/
grep -o ">build-[0-9]*" index.html | grep -o "[0-9]*" | tac | while read -r line ; do

curl -s --head http://hasky.askmonty.org/archive/10.4/build-$line/kvm-deb-bionic-amd64/md5sums.txt | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null
curl -s --head http://hasky.askmonty.org/archive/10.5/build-$line/kvm-deb-bionic-amd64/md5sums.txt | head -n 1 | grep "HTTP/1.[01] [23].." > /dev/null
if [ $? = "0" ]; then
echo "**************************************************************************"
echo "* Processing $line"
echo "**************************************************************************"
wget -q -o /dev/null -O $line.html http://hasky.askmonty.org/archive/10.4/build-$line/kvm-deb-bionic-amd64/debs/binary/
wget -q -o /dev/null -O $line.html http://hasky.askmonty.org/archive/10.5/build-$line/kvm-deb-bionic-amd64/debs/binary/
grep -o ">[^\"]*\.deb" $line.html | grep -o "[^>]*\.deb" | while read -r file ; do
if [[ "$file" =~ ^mariadb-plugin.* ]] ;
then
echo "skipped file: $file"
else
echo "download file: $file"
wget -q -o /dev/null -O .travis/build/$file http://hasky.askmonty.org/archive/10.4/build-$line/kvm-deb-bionic-amd64/debs/binary/$file
wget -q -o /dev/null -O .travis/build/$file http://hasky.askmonty.org/archive/10.5/build-$line/kvm-deb-bionic-amd64/debs/binary/$file
fi
done

Expand Down
17 changes: 17 additions & 0 deletions appveyor-download.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
@echo off
set archive=http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-%DB%/winx64-packages/mariadb-%DB%-winx64.msi
set last=http://mirror.i3d.net/pub/mariadb//mariadb-%DB%/winx64-packages/mariadb-%DB%-winx64.msi

curl -fsS -o server.msi %archive%

if %ERRORLEVEL% == 0 goto end


curl -fsS -o server.msi %last%
if %ERRORLEVEL% == 0 goto end

echo Failure Reason Given is %errorlevel%
exit /b %errorlevel%

:end
echo "File found".
8 changes: 6 additions & 2 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,11 @@ environment:
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
JAVA_HOME: C:\Program Files\Java\jdk1.8.0

- DB: '10.5.0'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
JAVA_HOME: C:\Program Files\Java\jdk1.8.0

- DB: '10.1.41'
APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
CMAKE_PARAM: 'Visual Studio 15 2017 Win64'
Expand All @@ -35,8 +40,7 @@ install:
[System.IO.Compression.ZipFile]::ExtractToDirectory("C:\maven-bin.zip", "C:\maven")
}
# Prepend Java entry, remove Ruby entry (C:\Ruby193\bin;) from PATH
- cmd: set FILE=http://ftp.hosteurope.de/mirror/archive.mariadb.org//mariadb-%DB%/winx64-packages/mariadb-%DB%-winx64.msi
- ps: Start-FileDownload $Env:FILE -FileName server.msi -Timeout 900000
- cmd: appveyor-download.bat
- cmd: msiexec /i server.msi INSTALLDIR=c:\projects\server SERVICENAME=mariadb ALLOWREMOTEROOTACCESS=true /qn
- cmd: "\"c:\\projects\\server\\bin\\mysql.exe\" -e \"create database testj\" --user=root"
- cmd: SET PATH=C:\maven\apache-maven-3.5.4\bin;%JAVA_HOME%\bin;%PATH:C:\Ruby193\bin;=%;
Expand Down
43 changes: 22 additions & 21 deletions src/main/java/org/mariadb/jdbc/BasePrepareStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.com.send.parameters.*;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory;

import java.io.InputStream;
import java.io.Reader;
Expand Down Expand Up @@ -112,13 +112,15 @@ public abstract class BasePrepareStatement extends MariaDbStatement implements P
* ResultSet.CONCUR_READ_ONLY</code> or <code>ResultSet.CONCUR_UPDATABLE</code>
* @param autoGeneratedKeys a flag indicating whether auto-generated keys should be returned; one
* of <code>Statement.RETURN_GENERATED_KEYS</code> or <code>Statement.NO_GENERATED_KEYS</code>
* @param exceptionFactory exception factory
*/
public BasePrepareStatement(
MariaDbConnection connection,
int resultSetScrollType,
int resultSetConcurrency,
int autoGeneratedKeys) {
super(connection, resultSetScrollType, resultSetConcurrency);
int autoGeneratedKeys,
ExceptionFactory exceptionFactory) {
super(connection, resultSetScrollType, resultSetConcurrency, exceptionFactory);
this.noBackslashEscapes = protocol.noBackslashEscapes();
this.useFractionalSeconds = options.useFractionalSeconds;
this.autoGeneratedKeys = autoGeneratedKeys;
Expand Down Expand Up @@ -242,7 +244,7 @@ public void setCharacterStream(final int parameterIndex, final Reader reader)
* PreparedStatement</code>
*/
public void setRef(final int parameterIndex, final Ref ref) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("REF not supported");
throw exceptionFactory.notSupported("REF parameter are not supported");
}

/**
Expand Down Expand Up @@ -399,7 +401,7 @@ public void setClob(final int parameterIndex, final Reader reader) throws SQLExc
* PreparedStatement</code>
*/
public void setArray(final int parameterIndex, final Array array) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("Arrays not supported");
throw exceptionFactory.notSupported("Arrays not supported");
}

/**
Expand Down Expand Up @@ -645,7 +647,7 @@ public void setURL(final int parameterIndex, final URL url) throws SQLException
* PreparedStatement</code>
*/
public void setRowId(final int parameterIndex, final RowId rowid) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("RowIDs not supported");
throw exceptionFactory.notSupported("RowIDs not supported");
}

/**
Expand Down Expand Up @@ -780,7 +782,7 @@ public void setNClob(final int parameterIndex, final Reader reader) throws SQLEx
*/
@Override
public void setSQLXML(final int parameterIndex, final SQLXML xmlObject) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("SQlXML not supported");
throw exceptionFactory.notSupported("SQlXML not supported");
}

/**
Expand Down Expand Up @@ -957,7 +959,7 @@ private void setInternalObject(
case Types.ROWID:
case Types.SQLXML:
case Types.STRUCT:
throw ExceptionMapper.getFeatureNotSupportedException("Type not supported");
throw exceptionFactory.notSupported("Type not supported");
default:
break;
}
Expand All @@ -966,7 +968,7 @@ private void setInternalObject(
setNull(parameterIndex, Types.INTEGER);
} else if (obj instanceof String) {
if (targetSqlType == Types.BLOB) {
throw ExceptionMapper.getSqlException("Cannot convert a String to a Blob");
throw exceptionFactory.create("Cannot convert a String to a Blob");
}
String str = (String) obj;
try {
Expand Down Expand Up @@ -1037,12 +1039,12 @@ private void setInternalObject(
options));
break;
default:
throw ExceptionMapper.getSqlException(
"Could not convert [" + str + "] to " + targetSqlType);
throw exceptionFactory.create(
String.format("Could not convert [%s] to %s", str, targetSqlType));
}
} catch (IllegalArgumentException e) {
throw ExceptionMapper.getSqlException(
"Could not convert [" + str + "] to " + targetSqlType, e);
throw exceptionFactory.create(
String.format("Could not convert [%s] to %s", str, targetSqlType), e);
}
} else if (obj instanceof Number) {
Number bd = (Number) obj;
Expand Down Expand Up @@ -1084,16 +1086,16 @@ private void setInternalObject(
setString(parameterIndex, bd.toString());
break;
default:
throw ExceptionMapper.getSqlException(
"Could not convert [" + bd + "] to " + targetSqlType);
throw exceptionFactory.create(
String.format("Could not convert [%s] to %s", bd, targetSqlType));
}
} else if (obj instanceof byte[]) {
if (targetSqlType == Types.BINARY
|| targetSqlType == Types.VARBINARY
|| targetSqlType == Types.LONGVARBINARY) {
setBytes(parameterIndex, (byte[]) obj);
} else {
throw ExceptionMapper.getSqlException(
throw exceptionFactory.create(
"Can only convert a byte[] to BINARY, VARBINARY or LONGVARBINARY");
}

Expand Down Expand Up @@ -1152,11 +1154,10 @@ private void setInternalObject(
} else if (obj instanceof LocalTime) {
setParameter(parameterIndex, new LocalTimeParameter((LocalTime) obj, useFractionalSeconds));
} else {
throw ExceptionMapper.getSqlException(
"Could not set parameter in setObject, could not convert: "
+ obj.getClass()
+ " to "
+ targetSqlType);
throw exceptionFactory.create(
String.format(
"Could not set parameter in setObject, could not convert: %s to %s",
obj.getClass(), targetSqlType));
}
}

Expand Down
35 changes: 23 additions & 12 deletions src/main/java/org/mariadb/jdbc/CallableFunctionStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory;

import java.io.InputStream;
import java.io.Reader;
Expand All @@ -80,12 +80,23 @@ public abstract class CallableFunctionStatement extends ClientSidePreparedStatem
* ResultSet.TYPE_SCROLL_INSENSITIVE</code>, or <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code>
* or <code>ResultSet.CONCUR_UPDATABLE</code>
* @param exceptionFactory Exception factory
* @throws SQLException if clientPrepareStatement creation throw an exception
*/
public CallableFunctionStatement(
MariaDbConnection connection, String sql, int resultSetType, final int resultSetConcurrency)
MariaDbConnection connection,
String sql,
int resultSetType,
final int resultSetConcurrency,
ExceptionFactory exceptionFactory)
throws SQLException {
super(connection, sql, resultSetType, resultSetConcurrency, Statement.NO_GENERATED_KEYS);
super(
connection,
sql,
resultSetType,
resultSetConcurrency,
Statement.NO_GENERATED_KEYS,
exceptionFactory);
}

/**
Expand Down Expand Up @@ -144,7 +155,7 @@ private int nameToIndex(String parameterName) throws SQLException {
return i;
}
}
throw new SQLException("there is no parameter with the name " + parameterName);
throw exceptionFactory.create("there is no parameter with the name " + parameterName);
}

/**
Expand All @@ -161,7 +172,7 @@ private int nameToOutputIndex(String parameterName) throws SQLException {
return i;
}
}
throw new SQLException("there is no parameter with the name " + parameterName);
throw exceptionFactory.create("there is no parameter with the name " + parameterName);
}

/**
Expand Down Expand Up @@ -438,12 +449,12 @@ public URL getURL(String parameterName) throws SQLException {

@Override
public RowId getRowId(int parameterIndex) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("RowIDs not supported");
throw exceptionFactory.notSupported("RowIDs not supported");
}

@Override
public RowId getRowId(String parameterName) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("RowIDs not supported");
throw exceptionFactory.notSupported("RowIDs not supported");
}

@Override
Expand All @@ -458,12 +469,12 @@ public NClob getNClob(String parameterName) throws SQLException {

@Override
public SQLXML getSQLXML(int parameterIndex) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("SQLXML not supported");
throw exceptionFactory.notSupported("SQLXML not supported");
}

@Override
public SQLXML getSQLXML(String parameterName) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("SQLXML not supported");
throw exceptionFactory.notSupported("SQLXML not supported");
}

@Override
Expand Down Expand Up @@ -617,19 +628,19 @@ public void registerOutParameter(String parameterName, SQLType sqlType, String t

private CallParameter getParameter(int index) throws SQLException {
if (index > params.length || index <= 0) {
throw new SQLException("No parameter with index " + (index));
throw exceptionFactory.create("No parameter with index " + (index));
}
return params[index - 1];
}

@Override
public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("SQLXML not supported");
throw exceptionFactory.notSupported("SQLXML not supported");
}

@Override
public void setRowId(String parameterName, RowId rowid) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("RowIDs not supported");
throw exceptionFactory.notSupported("RowIDs not supported");
}

@Override
Expand Down
29 changes: 20 additions & 9 deletions src/main/java/org/mariadb/jdbc/CallableProcedureStatement.java
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

import org.mariadb.jdbc.internal.ColumnType;
import org.mariadb.jdbc.internal.com.read.resultset.SelectResultSet;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
import org.mariadb.jdbc.internal.util.exceptions.ExceptionFactory;

import java.io.InputStream;
import java.io.Reader;
Expand Down Expand Up @@ -85,12 +85,23 @@ public abstract class CallableProcedureStatement extends ServerSidePreparedState
* <code>ResultSet.TYPE_SCROLL_SENSITIVE</code>
* @param resultSetConcurrency a concurrency type; one of <code>ResultSet.CONCUR_READ_ONLY</code>
* or <code>ResultSet.CONCUR_UPDATABLE</code>
* @param exceptionFactory Exception factory
* @throws SQLException is prepareStatement connection throw any error
*/
public CallableProcedureStatement(
MariaDbConnection connection, String sql, int resultSetScrollType, int resultSetConcurrency)
MariaDbConnection connection,
String sql,
int resultSetScrollType,
int resultSetConcurrency,
ExceptionFactory exceptionFactory)
throws SQLException {
super(connection, sql, resultSetScrollType, resultSetConcurrency, Statement.NO_GENERATED_KEYS);
super(
connection,
sql,
resultSetScrollType,
resultSetConcurrency,
Statement.NO_GENERATED_KEYS,
exceptionFactory);
}

/**
Expand Down Expand Up @@ -461,12 +472,12 @@ public URL getURL(String parameterName) throws SQLException {

@Override
public RowId getRowId(int parameterIndex) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("RowIDs not supported");
throw exceptionFactory.notSupported("RowIDs not supported");
}

@Override
public RowId getRowId(String parameterName) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("RowIDs not supported");
throw exceptionFactory.notSupported("RowIDs not supported");
}

@Override
Expand All @@ -481,12 +492,12 @@ public NClob getNClob(String parameterName) throws SQLException {

@Override
public SQLXML getSQLXML(int parameterIndex) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("SQLXML not supported");
throw exceptionFactory.notSupported("SQLXML not supported");
}

@Override
public SQLXML getSQLXML(String parameterName) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("SQLXML not supported");
throw exceptionFactory.notSupported("SQLXML not supported");
}

@Override
Expand Down Expand Up @@ -647,12 +658,12 @@ private CallParameter getParameter(int index) throws SQLException {

@Override
public void setSQLXML(String parameterName, SQLXML xmlObject) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("SQLXML not supported");
throw exceptionFactory.notSupported("SQLXML not supported");
}

@Override
public void setRowId(String parameterName, RowId rowid) throws SQLException {
throw ExceptionMapper.getFeatureNotSupportedException("RowIDs not supported");
throw exceptionFactory.notSupported("RowIDs not supported");
}

@Override
Expand Down
Loading

0 comments on commit fcbcbc1

Please sign in to comment.