Skip to content
Permalink
Browse files

[CONJ-722] add option blankTableNameMeta that force result-set metada…

…ta getTableName method to empty value.

This is mainly for Oracle compatibility.
  • Loading branch information...
rusher committed Jul 30, 2019
1 parent c7074aa commit f22fe19bcce6ce9814b2ecae7f11554da1195665
@@ -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 @@ private ResultSet executeQuery(String sql) throws SQLException {
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.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 boolean isCurrency(final int column) {
* 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 int getColumnDisplaySize(final int column) throws SQLException {

/**
* 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 String getColumnLabel(final int column) throws SQLException {
*/
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 String getCatalogName(int column) throws SQLException {

/**
* 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 int getScale(final int column) throws SQLException {
* @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 int getColumnType(final int column) throws SQLException {
default:
return ci.getColumnType().getSqlType();
}

}

/**
@@ -326,9 +294,8 @@ public int getColumnType(final int column) throws SQLException {
*/
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,23 +330,20 @@ public boolean isDefinitelyWritable(final int column) {

/**
* 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
* used by the method <code>ResultSet.getObject</code> to retrieve the value in the specified
* 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 @@ private ColumnInformation getColumnInformation(int column) throws SQLException {

/**
* 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 @@ private ColumnInformation getColumnInformation(int column) throws SQLException {
/**
* 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 @@
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 ServerSidePreparedStatement(MariaDbConnection connection, String sql,
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 @@ private void prepare(String sql) throws SQLException {
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());
}

0 comments on commit f22fe19

Please sign in to comment.
You can’t perform that action at this time.