[CONJ-722] add option blankTableNameMeta that force result-set metadata getTableName method to empty value.
This is mainly for Oracle compatibility.
This commit is contained in:
Родитель
c7074aad69
Коммит
f22fe19bcc
|
@ -187,6 +187,7 @@ See [[use-mariadb-connector-j-driver.creole#using-pooling|using pooling]] for mo
|
|||
|=useAffectedRows|default correspond to the JDBC standard, reporting real affected rows. if enable, will report "affected" rows. example : if enable, an update command that doesn't change a row value will still be "affected", then report.\\//Default: false. Since 2.2.6//
|
||||
|=includeInnodbStatusInDeadlockExceptions|add "SHOW ENGINE INNODB STATUS" result to exception trace when having a deadlock exception\\//Default: false. Since 2.3.0//
|
||||
|=includeThreadDumpInDeadlockExceptions|add thread dump to exception trace when having a deadlock exception\\//Default: false. Since 2.3.0//
|
||||
|=blankTableNameMeta|Result-set metadata getTableName always return blank. This option is mainly for ORACLE db compatibility\\//Default: false. Since 2.4.3//
|
||||
|
||||
\\\\
|
||||
== Failover/High availability URL parameters
|
||||
|
|
|
@ -472,7 +472,7 @@ public class MariaDbDatabaseMetaData implements DatabaseMetaData {
|
|||
ResultSet.CONCUR_READ_ONLY);
|
||||
SelectResultSet rs = (SelectResultSet) stmt.executeQuery(sql);
|
||||
rs.setStatement(null); // bypass Hibernate statement tracking (CONJ-49)
|
||||
rs.setReturnTableAlias(true);
|
||||
rs.setForceTableAlias();
|
||||
return rs;
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* MariaDB Client for Java
|
||||
*
|
||||
* Copyright (c) 2012-2014 Monty Program Ab.
|
||||
* Copyright (c) 2015-2017 MariaDB Ab.
|
||||
* Copyright (c) 2015-2019 MariaDB Ab.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
|
@ -18,36 +18,6 @@
|
|||
* You should have received a copy of the GNU Lesser General Public License along
|
||||
* with this library; if not, write to Monty Program Ab info@montyprogram.com.
|
||||
*
|
||||
* This particular MariaDB Client for Java file is work
|
||||
* derived from a Drizzle-JDBC. Drizzle-JDBC file which is covered by subject to
|
||||
* the following copyright and notice provisions:
|
||||
*
|
||||
* Copyright (c) 2009-2011, Marcus Eriksson
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the driver nor the names of its contributors may not be
|
||||
* used to endorse or promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mariadb.jdbc;
|
||||
|
@ -61,25 +31,24 @@ import org.mariadb.jdbc.internal.util.Options;
|
|||
import org.mariadb.jdbc.internal.util.constant.ColumnFlags;
|
||||
import org.mariadb.jdbc.internal.util.exceptions.ExceptionMapper;
|
||||
|
||||
|
||||
public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
||||
|
||||
private final ColumnInformation[] fieldPackets;
|
||||
private final Options options;
|
||||
private final boolean returnTableAlias;
|
||||
private final boolean forceAlias;
|
||||
|
||||
/**
|
||||
* Constructor.
|
||||
*
|
||||
* @param fieldPackets column informations
|
||||
* @param options connection options
|
||||
* @param returnTableAlias must return table alias or real table name
|
||||
* @param fieldPackets column informations
|
||||
* @param options connection options
|
||||
* @param forceAlias force table and column name alias as original data
|
||||
*/
|
||||
public MariaDbResultSetMetaData(ColumnInformation[] fieldPackets, Options options,
|
||||
boolean returnTableAlias) {
|
||||
public MariaDbResultSetMetaData(
|
||||
final ColumnInformation[] fieldPackets, final Options options, final boolean forceAlias) {
|
||||
this.fieldPackets = fieldPackets;
|
||||
this.options = options;
|
||||
this.returnTableAlias = returnTableAlias;
|
||||
this.forceAlias = forceAlias;
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -137,8 +106,8 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
* Indicates the nullability of values in the designated column.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, ...
|
||||
* @return the nullability status of the given column; one of <code>columnNoNulls</code>,
|
||||
* <code>columnNullable</code> or <code>columnNullableUnknown</code>
|
||||
* @return the nullability status of the given column; one of <code>columnNoNulls</code>, <code>
|
||||
* columnNullable</code> or <code>columnNullableUnknown</code>
|
||||
* @throws SQLException if a database access error occurs
|
||||
*/
|
||||
public int isNullable(final int column) throws SQLException {
|
||||
|
@ -173,10 +142,9 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
|
||||
/**
|
||||
* Gets the designated column's suggested title for use in printouts and displays. The suggested
|
||||
* title is usually specified by the SQL <code>AS</code> clause. If a SQL <code>AS</code> is not
|
||||
* specified, the value returned from
|
||||
* <code>getColumnLabel</code> will be the same as the value returned by the
|
||||
* <code>getColumnName</code> method.
|
||||
* title is usually specified by the SQL <code>AS</code> clause. If a SQL <code>AS</code> is not
|
||||
* specified, the value returned from <code>getColumnLabel</code> will be the same as the value
|
||||
* returned by the <code>getColumnName</code> method.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, ...
|
||||
* @return the suggested column title
|
||||
|
@ -195,13 +163,8 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
*/
|
||||
public String getColumnName(final int column) throws SQLException {
|
||||
String columnName = getColumnInformation(column).getOriginalName();
|
||||
if (returnTableAlias) {
|
||||
columnName = getColumnInformation(column).getName(); //for old mysql compatibility
|
||||
}
|
||||
|
||||
if ("".equals(columnName)) {
|
||||
// odd things that are no columns, e.g count(*)
|
||||
columnName = getColumnLabel(column);
|
||||
if ("".equals(columnName) || options.useOldAliasMetadataBehavior || forceAlias) {
|
||||
return getColumnLabel(column);
|
||||
}
|
||||
return columnName;
|
||||
}
|
||||
|
@ -219,7 +182,7 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
|
||||
/**
|
||||
* Get the designated column's specified column size. For numeric data, this is the maximum
|
||||
* precision. For character data, this is the length in characters. For datetime datatypes, this
|
||||
* precision. For character data, this is the length in characters. For datetime datatypes, this
|
||||
* is the length in characters of the String representation (assuming the maximum allowed
|
||||
* precision of the fractional seconds component). For binary data, this is the length in bytes.
|
||||
* For the ROWID datatype, this is the length in bytes. 0 is returned for data types where the
|
||||
|
@ -253,13 +216,19 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
* @throws SQLException if a database access error occurs
|
||||
*/
|
||||
public String getTableName(final int column) throws SQLException {
|
||||
if (returnTableAlias) {
|
||||
if (forceAlias) {
|
||||
return getColumnInformation(column).getTable();
|
||||
} else {
|
||||
return getColumnInformation(column).getOriginalTable();
|
||||
}
|
||||
}
|
||||
|
||||
if (options.blankTableNameMeta) {
|
||||
return "";
|
||||
}
|
||||
|
||||
if (options.useOldAliasMetadataBehavior) {
|
||||
return getColumnInformation(column).getTable();
|
||||
}
|
||||
return getColumnInformation(column).getOriginalTable();
|
||||
}
|
||||
|
||||
public String getSchemaName(int column) {
|
||||
return "";
|
||||
|
@ -313,7 +282,6 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
default:
|
||||
return ci.getColumnType().getSqlType();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -326,9 +294,8 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
*/
|
||||
public String getColumnTypeName(final int column) throws SQLException {
|
||||
ColumnInformation ci = getColumnInformation(column);
|
||||
return ColumnType
|
||||
.getColumnTypeName(ci.getColumnType(), ci.getLength(), ci.isSigned(), ci.isBinary());
|
||||
|
||||
return ColumnType.getColumnTypeName(
|
||||
ci.getColumnType(), ci.getLength(), ci.isSigned(), ci.isBinary());
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -363,10 +330,8 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
|
||||
/**
|
||||
* Returns the fully-qualified name of the Java class whose instances are manufactured if the
|
||||
* method
|
||||
* <code>ResultSet.getObject</code> is called to retrieve a value from the column.
|
||||
* <code>ResultSet.getObject</code>
|
||||
* may return a subclass of the class returned by this method.
|
||||
* method <code>ResultSet.getObject</code> is called to retrieve a value from the column. <code>
|
||||
* ResultSet.getObject</code> may return a subclass of the class returned by this method.
|
||||
*
|
||||
* @param column the first column is 1, the second is 2, ...
|
||||
* @return the fully-qualified name of the class in the Java programming language that would be
|
||||
|
@ -374,12 +339,11 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
* column. This is the class name used for custom mapping.
|
||||
* @throws SQLException if a database access error occurs
|
||||
*/
|
||||
|
||||
public String getColumnClassName(int column) throws SQLException {
|
||||
ColumnInformation ci = getColumnInformation(column);
|
||||
ColumnType type = ci.getColumnType();
|
||||
return ColumnType
|
||||
.getClassName(type, (int) ci.getLength(), ci.isSigned(), ci.isBinary(), options);
|
||||
return ColumnType.getClassName(
|
||||
type, (int) ci.getLength(), ci.isSigned(), ci.isBinary(), options);
|
||||
}
|
||||
|
||||
private ColumnInformation getColumnInformation(int column) throws SQLException {
|
||||
|
@ -391,14 +355,13 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
|
||||
/**
|
||||
* Returns an object that implements the given interface to allow access to non-standard methods,
|
||||
* or standard methods not exposed by the proxy.
|
||||
* <br>
|
||||
* or standard methods not exposed by the proxy. <br>
|
||||
* If the receiver implements the interface then the result is the receiver or a proxy for the
|
||||
* receiver. If the receiver is a wrapper and the wrapped object implements the interface then the
|
||||
* result is the wrapped object or a proxy for the wrapped object. Otherwise return the the result
|
||||
* of calling <code>unwrap</code> recursively on the wrapped object or a proxy for that result. If
|
||||
* the receiver is not a wrapper and does not implement the interface, then an
|
||||
* <code>SQLException</code> is thrown.
|
||||
* the receiver is not a wrapper and does not implement the interface, then an <code>SQLException
|
||||
* </code> is thrown.
|
||||
*
|
||||
* @param iface A Class defining an interface that the result must implement.
|
||||
* @return an object that implements the interface. May be a proxy for the actual implementing
|
||||
|
@ -420,18 +383,18 @@ public class MariaDbResultSetMetaData implements ResultSetMetaData {
|
|||
/**
|
||||
* Returns true if this either implements the interface argument or is directly or indirectly a
|
||||
* wrapper for an object that does. Returns false otherwise. If this implements the interface then
|
||||
* return true, else if this is a wrapper then return the result of recursively calling
|
||||
* <code>isWrapperFor</code> on the wrapped object. If this does not implement the interface and
|
||||
* is not a wrapper, return false. This method should be implemented as a low-cost operation
|
||||
* compared to <code>unwrap</code> so that callers can use this method to avoid expensive
|
||||
* <code>unwrap</code> calls that may fail. If this method returns true then calling
|
||||
* <code>unwrap</code> with the same argument should succeed.
|
||||
* return true, else if this is a wrapper then return the result of recursively calling <code>
|
||||
* isWrapperFor</code> on the wrapped object. If this does not implement the interface and is not
|
||||
* a wrapper, return false. This method should be implemented as a low-cost operation compared to
|
||||
* <code>unwrap</code> so that callers can use this method to avoid expensive <code>unwrap</code>
|
||||
* calls that may fail. If this method returns true then calling <code>unwrap</code> with the same
|
||||
* argument should succeed.
|
||||
*
|
||||
* @param iface a Class defining an interface.
|
||||
* @return true if this implements the interface or directly or indirectly wraps an object that
|
||||
* does.
|
||||
* @throws SQLException if an error occurs while determining whether this is a wrapper for an
|
||||
* object with the given interface.
|
||||
* object with the given interface.
|
||||
*/
|
||||
public boolean isWrapperFor(final Class<?> iface) throws SQLException {
|
||||
return iface.isInstance(this);
|
||||
|
|
|
@ -18,36 +18,6 @@
|
|||
* You should have received a copy of the GNU Lesser General Public License along
|
||||
* with this library; if not, write to Monty Program Ab info@montyprogram.com.
|
||||
*
|
||||
* This particular MariaDB Client for Java file is work
|
||||
* derived from a Drizzle-JDBC. Drizzle-JDBC file which is covered by subject to
|
||||
* the following copyright and notice provisions:
|
||||
*
|
||||
* Copyright (c) 2009-2011, Marcus Eriksson
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the driver nor the names of its contributors may not be
|
||||
* used to endorse or promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mariadb.jdbc;
|
||||
|
@ -79,7 +49,6 @@ public class ServerSidePreparedStatement extends BasePrepareStatement implements
|
|||
protected int parameterCount = -1;
|
||||
private String sql;
|
||||
private ServerPrepareResult serverPrepareResult = null;
|
||||
private boolean returnTableAlias = false;
|
||||
private MariaDbResultSetMetaData metadata;
|
||||
private MariaDbParameterMetaData parameterMetaData;
|
||||
private Map<Integer, ParameterHolder> currentParameterHolder;
|
||||
|
@ -110,7 +79,6 @@ public class ServerSidePreparedStatement extends BasePrepareStatement implements
|
|||
throws SQLException {
|
||||
super(connection, resultSetScrollType, resultSetConcurrency, autoGeneratedKeys);
|
||||
this.sql = sql;
|
||||
returnTableAlias = options.useOldAliasMetadataBehavior;
|
||||
currentParameterHolder = Collections.synchronizedMap(new TreeMap<Integer, ParameterHolder>());
|
||||
mustExecuteOnMaster = protocol.isMasterConnection();
|
||||
prepare(this.sql);
|
||||
|
@ -157,7 +125,7 @@ public class ServerSidePreparedStatement extends BasePrepareStatement implements
|
|||
private void setMetaFromResult() {
|
||||
parameterCount = serverPrepareResult.getParameters().length;
|
||||
metadata = new MariaDbResultSetMetaData(serverPrepareResult.getColumns(),
|
||||
protocol.getUrlParser().getOptions(), returnTableAlias);
|
||||
protocol.getUrlParser().getOptions(), false);
|
||||
parameterMetaData = new MariaDbParameterMetaData(serverPrepareResult.getParameters());
|
||||
}
|
||||
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
* MariaDB Client for Java
|
||||
*
|
||||
* Copyright (c) 2012-2014 Monty Program Ab.
|
||||
* Copyright (c) 2015-2017 MariaDB Ab.
|
||||
* Copyright (c) 2015-2019 MariaDB Ab.
|
||||
*
|
||||
* This library is free software; you can redistribute it and/or modify it under
|
||||
* the terms of the GNU Lesser General Public License as published by the Free
|
||||
|
@ -18,36 +18,6 @@
|
|||
* You should have received a copy of the GNU Lesser General Public License along
|
||||
* with this library; if not, write to Monty Program Ab info@montyprogram.com.
|
||||
*
|
||||
* This particular MariaDB Client for Java file is work
|
||||
* derived from a Drizzle-JDBC. Drizzle-JDBC file which is covered by subject to
|
||||
* the following copyright and notice provisions:
|
||||
*
|
||||
* Copyright (c) 2009-2011, Marcus Eriksson
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the driver nor the names of its contributors may not be
|
||||
* used to endorse or promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
|
||||
|
@ -152,11 +122,10 @@ public class SelectResultSet implements ResultSet {
|
|||
private int rowPointer;
|
||||
private ColumnNameMap columnNameMap;
|
||||
private int lastRowPointer = -1;
|
||||
private int dataTypeMappingFlags;
|
||||
private boolean returnTableAlias;
|
||||
private boolean isClosed;
|
||||
private boolean eofDeprecated;
|
||||
private ReentrantLock lock;
|
||||
private boolean forceAlias;
|
||||
|
||||
/**
|
||||
* Create Streaming resultSet.
|
||||
|
@ -178,7 +147,6 @@ public class SelectResultSet implements ResultSet {
|
|||
this.protocol = protocol;
|
||||
this.options = protocol.getOptions();
|
||||
this.noBackslashEscapes = protocol.noBackslashEscapes();
|
||||
this.returnTableAlias = this.options.useOldAliasMetadataBehavior;
|
||||
this.columnsInformation = columnInformation;
|
||||
this.columnNameMap = new ColumnNameMap(columnsInformation);
|
||||
|
||||
|
@ -234,11 +202,9 @@ public class SelectResultSet implements ResultSet {
|
|||
if (protocol != null) {
|
||||
this.options = protocol.getOptions();
|
||||
this.timeZone = protocol.getTimeZone();
|
||||
this.returnTableAlias = this.options.useOldAliasMetadataBehavior;
|
||||
} else {
|
||||
this.options = new Options();
|
||||
this.timeZone = TimeZone.getDefault();
|
||||
this.returnTableAlias = false;
|
||||
}
|
||||
this.row = new TextRowProtocol(0, this.options);
|
||||
this.protocol = null;
|
||||
|
@ -1282,7 +1248,7 @@ public class SelectResultSet implements ResultSet {
|
|||
* {inheritDoc}.
|
||||
*/
|
||||
public ResultSetMetaData getMetaData() {
|
||||
return new MariaDbResultSetMetaData(columnsInformation, options, returnTableAlias);
|
||||
return new MariaDbResultSetMetaData(columnsInformation, options, forceAlias);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -2395,8 +2361,11 @@ public class SelectResultSet implements ResultSet {
|
|||
return iface.isInstance(this);
|
||||
}
|
||||
|
||||
public void setReturnTableAlias(boolean returnTableAlias) {
|
||||
this.returnTableAlias = returnTableAlias;
|
||||
/**
|
||||
* Force metadata getTableName to return table alias, not original table name.
|
||||
*/
|
||||
public void setForceTableAlias() {
|
||||
this.forceAlias = true;
|
||||
}
|
||||
|
||||
private void rangeCheck(Object className, long minValue, long maxValue, long value,
|
||||
|
|
Разница между файлами не показана из-за своего большого размера
Загрузить разницу
|
@ -18,53 +18,24 @@
|
|||
* You should have received a copy of the GNU Lesser General Public License along
|
||||
* with this library; if not, write to Monty Program Ab info@montyprogram.com.
|
||||
*
|
||||
* This particular MariaDB Client for Java file is work
|
||||
* derived from a Drizzle-JDBC. Drizzle-JDBC file which is covered by subject to
|
||||
* the following copyright and notice provisions:
|
||||
*
|
||||
* Copyright (c) 2009-2011, Marcus Eriksson
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the driver nor the names of its contributors may not be
|
||||
* used to endorse or promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mariadb.jdbc.internal.util;
|
||||
|
||||
import java.lang.reflect.Field;
|
||||
import java.sql.DriverManager;
|
||||
import java.util.Objects;
|
||||
|
||||
@SuppressWarnings("ConstantConditions")
|
||||
public class Options implements Cloneable {
|
||||
|
||||
public static final int MIN_VALUE__MAX_IDLE_TIME = 60;
|
||||
|
||||
//standard options
|
||||
// standard options
|
||||
public String user;
|
||||
public String password;
|
||||
|
||||
//divers
|
||||
// divers
|
||||
public boolean trustServerCertificate;
|
||||
public String serverSslCert;
|
||||
public String trustStore;
|
||||
|
@ -95,6 +66,7 @@ public class Options implements Cloneable {
|
|||
public boolean useCompression;
|
||||
public boolean interactiveClient;
|
||||
public String passwordCharacterEncoding;
|
||||
public boolean blankTableNameMeta;
|
||||
|
||||
public boolean useSsl;
|
||||
public String enabledSslCipherSuites;
|
||||
|
@ -132,13 +104,13 @@ public class Options implements Cloneable {
|
|||
public String servicePrincipalName;
|
||||
public int defaultFetchSize;
|
||||
|
||||
//logging options
|
||||
// logging options
|
||||
public boolean log;
|
||||
public boolean profileSql;
|
||||
public int maxQuerySizeToLog = 1024;
|
||||
public Long slowQueryThresholdNanos;
|
||||
|
||||
//HA options
|
||||
// HA options
|
||||
public boolean assureReadOnly;
|
||||
public boolean autoReconnect;
|
||||
public boolean failOnReadOnly;
|
||||
|
@ -149,7 +121,7 @@ public class Options implements Cloneable {
|
|||
public boolean allowMasterDownConnection;
|
||||
public String galeraAllowedState;
|
||||
|
||||
//Pool options
|
||||
// Pool options
|
||||
public boolean pool;
|
||||
public String poolName;
|
||||
public int maxPoolSize = 8;
|
||||
|
@ -175,10 +147,10 @@ public class Options implements Cloneable {
|
|||
try {
|
||||
result.append(field.getName());
|
||||
result.append(": ");
|
||||
//requires access to private field:
|
||||
// requires access to private field:
|
||||
result.append(field.get(this));
|
||||
} catch (IllegalAccessException ex) {
|
||||
//ignore error
|
||||
// ignore error
|
||||
}
|
||||
result.append(newLine);
|
||||
}
|
||||
|
@ -216,6 +188,9 @@ public class Options implements Cloneable {
|
|||
if (tcpAbortiveClose != opt.tcpAbortiveClose) {
|
||||
return false;
|
||||
}
|
||||
if (blankTableNameMeta != opt.blankTableNameMeta) {
|
||||
return false;
|
||||
}
|
||||
if (allowMultiQueries != opt.allowMultiQueries) {
|
||||
return false;
|
||||
}
|
||||
|
@ -351,31 +326,28 @@ public class Options implements Cloneable {
|
|||
if (poolValidMinDelay != opt.poolValidMinDelay) {
|
||||
return false;
|
||||
}
|
||||
if (user != null ? !user.equals(opt.user) : opt.user != null) {
|
||||
if (!Objects.equals(user, opt.user)) {
|
||||
return false;
|
||||
}
|
||||
if (password != null ? !password.equals(opt.password) : opt.password != null) {
|
||||
if (!Objects.equals(password, opt.password)) {
|
||||
return false;
|
||||
}
|
||||
if (serverSslCert != null ? !serverSslCert.equals(opt.serverSslCert)
|
||||
: opt.serverSslCert != null) {
|
||||
if (!Objects.equals(serverSslCert, opt.serverSslCert)) {
|
||||
return false;
|
||||
}
|
||||
if (trustStore != null ? !trustStore.equals(opt.trustStore) : opt.trustStore != null) {
|
||||
if (!Objects.equals(trustStore, opt.trustStore)) {
|
||||
return false;
|
||||
}
|
||||
if (trustStorePassword != null ? !trustStorePassword.equals(opt.trustStorePassword)
|
||||
: opt.trustStorePassword != null) {
|
||||
if (!Objects.equals(trustStorePassword, opt.trustStorePassword)) {
|
||||
return false;
|
||||
}
|
||||
if (keyStore != null ? !keyStore.equals(opt.keyStore) : opt.keyStore != null) {
|
||||
if (!Objects.equals(keyStore, opt.keyStore)) {
|
||||
return false;
|
||||
}
|
||||
if (keyStorePassword != null ? !keyStorePassword.equals(opt.keyStorePassword)
|
||||
: opt.keyStorePassword != null) {
|
||||
if (!Objects.equals(keyStorePassword, opt.keyStorePassword)) {
|
||||
return false;
|
||||
}
|
||||
if (keyPassword != null ? !keyPassword.equals(opt.keyPassword) : opt.keyPassword != null) {
|
||||
if (!Objects.equals(keyPassword, opt.keyPassword)) {
|
||||
return false;
|
||||
}
|
||||
if (enabledSslProtocolSuites != null) {
|
||||
|
@ -385,34 +357,31 @@ public class Options implements Cloneable {
|
|||
} else if (opt.enabledSslProtocolSuites != null) {
|
||||
return false;
|
||||
}
|
||||
if (socketFactory != null ? !socketFactory.equals(opt.socketFactory)
|
||||
: opt.socketFactory != null) {
|
||||
if (!Objects.equals(socketFactory, opt.socketFactory)) {
|
||||
return false;
|
||||
}
|
||||
if (connectTimeout != opt.connectTimeout) {
|
||||
return false;
|
||||
}
|
||||
if (pipe != null ? !pipe.equals(opt.pipe) : opt.pipe != null) {
|
||||
if (!Objects.equals(pipe, opt.pipe)) {
|
||||
return false;
|
||||
}
|
||||
if (localSocket != null ? !localSocket.equals(opt.localSocket) : opt.localSocket != null) {
|
||||
if (!Objects.equals(localSocket, opt.localSocket)) {
|
||||
return false;
|
||||
}
|
||||
if (sharedMemory != null ? !sharedMemory.equals(opt.sharedMemory) : opt.sharedMemory != null) {
|
||||
if (!Objects.equals(sharedMemory, opt.sharedMemory)) {
|
||||
return false;
|
||||
}
|
||||
if (tcpRcvBuf != null ? !tcpRcvBuf.equals(opt.tcpRcvBuf) : opt.tcpRcvBuf != null) {
|
||||
if (!Objects.equals(tcpRcvBuf, opt.tcpRcvBuf)) {
|
||||
return false;
|
||||
}
|
||||
if (tcpSndBuf != null ? !tcpSndBuf.equals(opt.tcpSndBuf) : opt.tcpSndBuf != null) {
|
||||
if (!Objects.equals(tcpSndBuf, opt.tcpSndBuf)) {
|
||||
return false;
|
||||
}
|
||||
if (localSocketAddress != null ? !localSocketAddress.equals(opt.localSocketAddress)
|
||||
: opt.localSocketAddress != null) {
|
||||
if (!Objects.equals(localSocketAddress, opt.localSocketAddress)) {
|
||||
return false;
|
||||
}
|
||||
if (socketTimeout != null ? !socketTimeout.equals(opt.socketTimeout)
|
||||
: opt.socketTimeout != null) {
|
||||
if (!Objects.equals(socketTimeout, opt.socketTimeout)) {
|
||||
return false;
|
||||
}
|
||||
if (passwordCharacterEncoding != null) {
|
||||
|
@ -423,16 +392,13 @@ public class Options implements Cloneable {
|
|||
return false;
|
||||
}
|
||||
|
||||
if (enabledSslCipherSuites != null ? !enabledSslCipherSuites.equals(opt.enabledSslCipherSuites)
|
||||
: opt.enabledSslCipherSuites != null) {
|
||||
if (!Objects.equals(enabledSslCipherSuites, opt.enabledSslCipherSuites)) {
|
||||
return false;
|
||||
}
|
||||
if (sessionVariables != null ? !sessionVariables.equals(opt.sessionVariables)
|
||||
: opt.sessionVariables != null) {
|
||||
if (!Objects.equals(sessionVariables, opt.sessionVariables)) {
|
||||
return false;
|
||||
}
|
||||
if (serverTimezone != null ? !serverTimezone.equals(opt.serverTimezone)
|
||||
: opt.serverTimezone != null) {
|
||||
if (!Objects.equals(serverTimezone, opt.serverTimezone)) {
|
||||
return false;
|
||||
}
|
||||
if (prepStmtCacheSize != opt.prepStmtCacheSize) {
|
||||
|
@ -444,36 +410,31 @@ public class Options implements Cloneable {
|
|||
if (callableStmtCacheSize != opt.callableStmtCacheSize) {
|
||||
return false;
|
||||
}
|
||||
if (connectionAttributes != null ? !connectionAttributes.equals(opt.connectionAttributes)
|
||||
: opt.connectionAttributes != null) {
|
||||
if (!Objects.equals(connectionAttributes, opt.connectionAttributes)) {
|
||||
return false;
|
||||
}
|
||||
if (useBatchMultiSend != null ? !useBatchMultiSend.equals(opt.useBatchMultiSend)
|
||||
: opt.useBatchMultiSend != null) {
|
||||
if (!Objects.equals(useBatchMultiSend, opt.useBatchMultiSend)) {
|
||||
return false;
|
||||
}
|
||||
if (usePipelineAuth != null ? !usePipelineAuth.equals(opt.usePipelineAuth)
|
||||
: opt.usePipelineAuth != null) {
|
||||
if (!Objects.equals(usePipelineAuth, opt.usePipelineAuth)) {
|
||||
return false;
|
||||
}
|
||||
if (maxQuerySizeToLog != opt.maxQuerySizeToLog) {
|
||||
return false;
|
||||
}
|
||||
if (slowQueryThresholdNanos != null ? !slowQueryThresholdNanos
|
||||
.equals(opt.slowQueryThresholdNanos) : opt.slowQueryThresholdNanos != null) {
|
||||
if (!Objects.equals(slowQueryThresholdNanos, opt.slowQueryThresholdNanos)) {
|
||||
return false;
|
||||
}
|
||||
if (autocommit != opt.autocommit) {
|
||||
return false;
|
||||
}
|
||||
if (poolName != null ? !poolName.equals(opt.poolName) : opt.poolName != null) {
|
||||
if (!Objects.equals(poolName, opt.poolName)) {
|
||||
return false;
|
||||
}
|
||||
if (galeraAllowedState != null ? !galeraAllowedState.equals(opt.galeraAllowedState)
|
||||
: opt.galeraAllowedState != null) {
|
||||
if (!Objects.equals(galeraAllowedState, opt.galeraAllowedState)) {
|
||||
return false;
|
||||
}
|
||||
return minPoolSize != null ? minPoolSize.equals(opt.minPoolSize) : opt.minPoolSize == null;
|
||||
return Objects.equals(minPoolSize, opt.minPoolSize);
|
||||
}
|
||||
|
||||
@SuppressWarnings("SimplifiableIfStatement")
|
||||
|
@ -508,8 +469,9 @@ public class Options implements Cloneable {
|
|||
result = 31 * result + (rewriteBatchedStatements ? 1 : 0);
|
||||
result = 31 * result + (useCompression ? 1 : 0);
|
||||
result = 31 * result + (interactiveClient ? 1 : 0);
|
||||
result = 31 * result + (passwordCharacterEncoding != null ? passwordCharacterEncoding.hashCode()
|
||||
: 0);
|
||||
result =
|
||||
31 * result
|
||||
+ (passwordCharacterEncoding != null ? passwordCharacterEncoding.hashCode() : 0);
|
||||
result = 31 * result + (useSsl ? 1 : 0);
|
||||
result = 31 * result + (enabledSslCipherSuites != null ? enabledSslCipherSuites.hashCode() : 0);
|
||||
result = 31 * result + (sessionVariables != null ? sessionVariables.hashCode() : 0);
|
||||
|
|
|
@ -18,36 +18,6 @@
|
|||
* You should have received a copy of the GNU Lesser General Public License along
|
||||
* with this library; if not, write to Monty Program Ab info@montyprogram.com.
|
||||
*
|
||||
* This particular MariaDB Client for Java file is work
|
||||
* derived from a Drizzle-JDBC. Drizzle-JDBC file which is covered by subject to
|
||||
* the following copyright and notice provisions:
|
||||
*
|
||||
* Copyright (c) 2009-2011, Marcus Eriksson
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* Redistributions of source code must retain the above copyright notice, this list
|
||||
* of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice, this
|
||||
* list of conditions and the following disclaimer in the documentation and/or
|
||||
* other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of the driver nor the names of its contributors may not be
|
||||
* used to endorse or promote products derived from this software without specific
|
||||
* prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
||||
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
||||
* IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
||||
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
||||
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
||||
* PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
||||
* WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
||||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
*/
|
||||
|
||||
package org.mariadb.jdbc;
|
||||
|
@ -224,17 +194,36 @@ public class ResultSetMetaDataTest extends BaseTest {
|
|||
|
||||
// add useOldAliasMetadataBehavior to get the alias instead of the real
|
||||
// table name
|
||||
try (Connection connection = setConnection("&useOldAliasMetadataBehavior=true")) {
|
||||
try (Connection connection = setConnection("&useOldAliasMetadataBehavior")) {
|
||||
rs = connection.createStatement().executeQuery(
|
||||
"SELECT id AS id_alias FROM t3 AS t1_alias");
|
||||
rsmd = rs.getMetaData();
|
||||
|
||||
// this should return the alias name of the table, i.e. old behavior
|
||||
logInfo(rsmd.getTableName(1));
|
||||
assertEquals(rsmd.getTableName(1), "t1_alias");
|
||||
assertEquals(rsmd.getColumnLabel(1), "id_alias");
|
||||
assertEquals(rsmd.getColumnName(1), "id_alias");
|
||||
}
|
||||
|
||||
try (Connection connection = setConnection("&blankTableNameMeta")) {
|
||||
rs = connection.createStatement().executeQuery(
|
||||
"SELECT id AS id_alias FROM t3 AS t1_alias");
|
||||
rsmd = rs.getMetaData();
|
||||
|
||||
assertEquals(rsmd.getTableName(1), "");
|
||||
assertEquals(rsmd.getColumnLabel(1), "id_alias");
|
||||
assertEquals(rsmd.getColumnName(1), "id");
|
||||
}
|
||||
|
||||
try (Connection connection = setConnection("&blankTableNameMeta&useOldAliasMetadataBehavior")) {
|
||||
rs = connection.createStatement().executeQuery(
|
||||
"SELECT id AS id_alias FROM t3 AS t1_alias");
|
||||
rsmd = rs.getMetaData();
|
||||
|
||||
assertEquals(rsmd.getTableName(1), "");
|
||||
assertEquals(rsmd.getColumnLabel(1), "id_alias");
|
||||
assertEquals(rsmd.getColumnName(1), "id_alias");
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче