Top Fields Constructors Methods
com.mysql.cj

public Class NativeCharsetSettings

extends CharsetMapping
implements CharsetSettings
Class Inheritance
All Implemented Interfaces
com.mysql.cj.CharsetSettings
Imports
java.io.IOException, java.nio.ByteBuffer, .CharBuffer, java.nio.charset.Charset, .CharsetEncoder, java.util.Collections, .HashMap, .HashSet, .List, .Locale, .Map, .Set, com.mysql.cj.conf.PropertyKey, .RuntimeProperty, com.mysql.cj.exceptions.ExceptionFactory, .WrongArgumentException, com.mysql.cj.protocol.Resultset, .Resultset.Type, .ServerCapabilities, .ServerSession, com.mysql.cj.protocol.a.NativeConstants, .NativeMessageBuilder, .NativePacketPayload, .ResultsetFactory, com.mysql.cj.result.IntegerValueFactory, .Row, .StringValueFactory, .ValueFactory, com.mysql.cj.telemetry.TelemetryAttribute, .TelemetryScope, .TelemetrySpan, .TelemetrySpanName, com.mysql.cj.util.StringUtils

Field Summary

Modifier and TypeField and Description
protected RuntimeProperty<Boolean>
protected RuntimeProperty<String>
protected RuntimeProperty<String>
public Map<String, Integer>
public Map<String, String>
public Map<String, Integer>
public Map<Integer, String>
public Map<Integer, String>
public Map<String, Integer>
private NativeMessageBuilder
protected RuntimeProperty<String>
private static final Map<String, Map<String, Integer>>
private static final Map<String, Map<String, String>>
private static final Map<String, Map<String, Integer>>
customCharsetNameToMblenByUrl

Actual mysql charset name to mblen map of user defined charsets for given server URLs.

private static final Map<String, Map<Integer, String>>
customCollationIndexToCharsetNameByUrl

Actual collation index to mysql charset name map of user defined charsets for given server URLs.

private static final Map<String, Map<Integer, String>>
private static final Map<String, Map<String, Integer>>
private static final Map<String, Map<String, String>>
private static final Map<String, Set<String>>
private String
errorMessageEncoding

The (Java) encoding used to interpret error messages received from the server.

public Map<String, String>
private int
private String
metadataEncoding

What character set is the metadata returned in?

public Set<String>
protected RuntimeProperty<String>
private boolean
platformDbCharsetMatches

Does the character set of this connection match the character set of the platform

private boolean
requiresEscapingEncoder

If a CharsetEncoder is required for escaping.

private ServerSession
private NativeSession
private Integer
Inherited from com.mysql.cj.CharsetMapping:
MAP_SIZEMYSQL_CHARSET_NAME_armscii8MYSQL_CHARSET_NAME_asciiMYSQL_CHARSET_NAME_big5MYSQL_CHARSET_NAME_binaryMYSQL_CHARSET_NAME_cp1250MYSQL_CHARSET_NAME_cp1251MYSQL_CHARSET_NAME_cp1256MYSQL_CHARSET_NAME_cp1257MYSQL_CHARSET_NAME_cp850MYSQL_CHARSET_NAME_cp852MYSQL_CHARSET_NAME_cp866MYSQL_CHARSET_NAME_cp932MYSQL_CHARSET_NAME_dec8MYSQL_CHARSET_NAME_eucjpmsMYSQL_CHARSET_NAME_euckrMYSQL_CHARSET_NAME_gb18030MYSQL_CHARSET_NAME_gb2312MYSQL_CHARSET_NAME_gbkMYSQL_CHARSET_NAME_geostd8MYSQL_CHARSET_NAME_greekMYSQL_CHARSET_NAME_hebrewMYSQL_CHARSET_NAME_hp8MYSQL_CHARSET_NAME_keybcs2MYSQL_CHARSET_NAME_koi8rMYSQL_CHARSET_NAME_koi8uMYSQL_CHARSET_NAME_latin1MYSQL_CHARSET_NAME_latin2MYSQL_CHARSET_NAME_latin5MYSQL_CHARSET_NAME_latin7MYSQL_CHARSET_NAME_macceMYSQL_CHARSET_NAME_macromanMYSQL_CHARSET_NAME_sjisMYSQL_CHARSET_NAME_swe7MYSQL_CHARSET_NAME_tis620MYSQL_CHARSET_NAME_ucs2MYSQL_CHARSET_NAME_ujisMYSQL_CHARSET_NAME_utf16MYSQL_CHARSET_NAME_utf16leMYSQL_CHARSET_NAME_utf32MYSQL_CHARSET_NAME_utf8MYSQL_CHARSET_NAME_utf8mb3MYSQL_CHARSET_NAME_utf8mb4MYSQL_COLLATION_INDEX_binaryMYSQL_COLLATION_INDEX_utf8mb4_0900_ai_ciMYSQL_COLLATION_INDEX_utf8mb4_general_ci

Constructor Summary

AccessConstructor and Description
public

Method Summary

Modifier and TypeMethod and Description
private void
buildCollationMapping()

Builds the map needed for 4.1.0 and newer servers that maps field-level charset/collation info to a java character encoding name.

private boolean
characterSetNamesMatches(String mysqlEncodingName)

private void
checkForCharsetMismatch()

Determines if the connection charset is the same as the platform charset

public void
configurePostHandshake(boolean
if true then send the SET NAMES query even if server charset already matches the new value; needed for changeUser call.
dontCheckServerMatch
)

Implements com.mysql.cj.CharsetSettings.configurePostHandshake.

Sets up client character set.

public int
configurePreHandshake(boolean
reset the charsets configuration; needed for changeUser and resetServerState call.
reset
)

Implements com.mysql.cj.CharsetSettings.configurePreHandshake.

Choose the MySQL collation index for the handshake packet and the corresponding Java encodings for the password and error messages.

public boolean
public Integer
public int
public int
public String
private NativeMessageBuilder
public String
public String
public String
getJavaEncodingForCollationIndex(Integer collationIndex, String fallBackJavaEncoding)

public String
public String
getJavaEncodingForMysqlCharset(String mysqlCharsetName, String javaEncoding)

public int
public int
public int
public String
public String
public String
public String
public boolean
public String

Returns:

MySQL charset name
getServerDefaultCharset
()

Get the server's default character set name according to collation index from server greeting, or value of 'character_set_server' variable if there is no mapping for that index

public boolean
isImpermissibleCollation(int collationIndex)

public boolean
private void
private void
tryAndFixEncoding(RuntimeProperty<String>
connection property containing the Java encoding to try
encodingProperty
,
boolean
The character_set_client system variable cannot be set to ucs2, utf16, utf16le, utf32 charsets. If "true" the corresponding connection property value will be replaced with "UTF-8"
replaceImpermissibleEncodings
)

Attempt to use the encoding, and bail out if it can't be used.

Inherited from com.mysql.cj.CharsetMapping:
getStaticCollationIndexForCollationNamegetStaticCollationIndexForJavaEncodinggetStaticCollationIndexForMysqlCharsetNamegetStaticCollationNameForCollationIndexgetStaticJavaEncodingForCollationIndexgetStaticJavaEncodingForCollationIndexgetStaticJavaEncodingForMysqlCharsetgetStaticJavaEncodingForMysqlCharsetgetStaticMblengetStaticMysqlCharsetAliasesByNamegetStaticMysqlCharsetByNamegetStaticMysqlCharsetForJavaEncodinggetStaticMysqlCharsetNameForCollationIndexisStaticImpermissibleCollationisStaticMultibyteCharset

Field Detail

cacheServerConfigurationback to summary
protected RuntimeProperty<Boolean> cacheServerConfiguration
characterEncodingback to summary
protected RuntimeProperty<String> characterEncoding
characterSetResultsback to summary
protected RuntimeProperty<String> characterSetResults
charsetNameToCollationIndexback to summary
public Map<String, Integer> charsetNameToCollationIndex
charsetNameToJavaEncodingback to summary
public Map<String, String> charsetNameToJavaEncoding
charsetNameToMblenback to summary
public Map<String, Integer> charsetNameToMblen
collationIndexToCharsetNameback to summary
public Map<Integer, String> collationIndexToCharsetName
collationIndexToCollationNameback to summary
public Map<Integer, String> collationIndexToCollationName
collationNameToCollationIndexback to summary
public Map<String, Integer> collationNameToCollationIndex
commandBuilderback to summary
private NativeMessageBuilder commandBuilder
connectionCollationback to summary
protected RuntimeProperty<String> connectionCollation
customCharsetNameToCollationIndexByUrlback to summary
private static final Map<String, Map<String, Integer>> customCharsetNameToCollationIndexByUrl
customCharsetNameToJavaEncodingByUrlback to summary
private static final Map<String, Map<String, String>> customCharsetNameToJavaEncodingByUrl
customCharsetNameToMblenByUrlback to summary
private static final Map<String, Map<String, Integer>> customCharsetNameToMblenByUrl

Actual mysql charset name to mblen map of user defined charsets for given server URLs.

customCollationIndexToCharsetNameByUrlback to summary
private static final Map<String, Map<Integer, String>> customCollationIndexToCharsetNameByUrl

Actual collation index to mysql charset name map of user defined charsets for given server URLs.

customCollationIndexToCollationNameByUrlback to summary
private static final Map<String, Map<Integer, String>> customCollationIndexToCollationNameByUrl
customCollationNameToCollationIndexByUrlback to summary
private static final Map<String, Map<String, Integer>> customCollationNameToCollationIndexByUrl
customJavaEncodingUcToCharsetNameByUrlback to summary
private static final Map<String, Map<String, String>> customJavaEncodingUcToCharsetNameByUrl
customMultibyteEncodingsByUrlback to summary
private static final Map<String, Set<String>> customMultibyteEncodingsByUrl
errorMessageEncodingback to summary
private String errorMessageEncoding

The (Java) encoding used to interpret error messages received from the server. We use character_set_results (since MySQL 5.5) if it is not null or UTF-8 otherwise.

javaEncodingUcToCharsetNameback to summary
public Map<String, String> javaEncodingUcToCharsetName
metadataCollationIndexback to summary
private int metadataCollationIndex
metadataEncodingback to summary
private String metadataEncoding

What character set is the metadata returned in?

multibyteEncodingsback to summary
public Set<String> multibyteEncodings
passwordCharacterEncodingback to summary
protected RuntimeProperty<String> passwordCharacterEncoding
platformDbCharsetMatchesback to summary
private boolean platformDbCharsetMatches

Does the character set of this connection match the character set of the platform

requiresEscapingEncoderback to summary
private boolean requiresEscapingEncoder

If a CharsetEncoder is required for escaping. Needed for SJIS and related problems with ¥.

serverSessionback to summary
private ServerSession serverSession
sessionback to summary
private NativeSession session
sessionCollationIndexback to summary
private Integer sessionCollationIndex

Constructor Detail

NativeCharsetSettingsback to summary
public NativeCharsetSettings(NativeSession sess)

Method Detail

buildCollationMappingback to summary
private void buildCollationMapping()

Builds the map needed for 4.1.0 and newer servers that maps field-level charset/collation info to a java character encoding name.

characterSetNamesMatchesback to summary
private boolean characterSetNamesMatches(String mysqlEncodingName)
checkForCharsetMismatchback to summary
private void checkForCharsetMismatch()

Determines if the connection charset is the same as the platform charset

configurePostHandshakeback to summary
public void configurePostHandshake(boolean dontCheckServerMatch)

Implements com.mysql.cj.CharsetSettings.configurePostHandshake.

Doc from com.mysql.cj.CharsetSettings.configurePostHandshake.

Sets up client character set. This must be done before any further communication with the server! The 'collation_connection', 'character_set_client', 'character_set_connection' and 'character_set_results' server variables are set according to the collation index selected by configurePreHandshake(boolean) and sent in the Protocol::HandshakeV10 packet. Here Connector/J alters these server variables if needed.

Parameters
dontCheckServerMatch:boolean

if true then send the SET NAMES query even if server charset already matches the new value; needed for changeUser call.

Annotations
@Override
configurePreHandshakeback to summary
public int configurePreHandshake(boolean reset)

Implements com.mysql.cj.CharsetSettings.configurePreHandshake.

Doc from com.mysql.cj.CharsetSettings.configurePreHandshake.

Choose the MySQL collation index for the handshake packet and the corresponding Java encodings for the password and error messages.

This index will be sent with HandshakeResponse setting server variables 'character_set_connection', 'collation_connection', 'character_set_client' and 'character_set_results' which will be used by the server for decoding passwords during the authentication phase and later on, if no SET NAMES are issued by configurePostHandshake(boolean).

It also means that collation index should be set according to:

  1. 'passwordCharacterEncoding' if it's present, or
  2. 'connectionCollation' if it's present, or
  3. 'characterEncoding' if it's present
otherwise it will be set to utf8mb4_general_ci or utf8mb4_0900_ai_ci depending on server version.

Since Protocol::HandshakeV10 and Protocol::HandshakeResponse41 use only one byte for the collation it's not possible to use indexes > 255 during the handshake. Also, ucs2, utf16, utf16le and utf32 character sets are impermissible here. Connector/J will try to use utf8mb4 instead.

Parameters
reset:boolean

reset the charsets configuration; needed for changeUser and resetServerState call.

Returns:int

MySQL collation index to be used during the handshake.

Annotations
@Override
doesPlatformDbCharsetMatchesback to summary
public boolean doesPlatformDbCharsetMatches()

Implements com.mysql.cj.CharsetSettings.doesPlatformDbCharsetMatches.

Annotations
@Override
getCollationIndexForCollationNameback to summary
public Integer getCollationIndexForCollationName(String collationName)

Implements com.mysql.cj.CharsetSettings.getCollationIndexForCollationName.

Annotations
@Override
getCollationIndexForJavaEncodingback to summary
public int getCollationIndexForJavaEncoding(String javaEncoding, ServerVersion version)

Implements com.mysql.cj.CharsetSettings.getCollationIndexForJavaEncoding.

Annotations
@Override
getCollationIndexForMysqlCharsetNameback to summary
public int getCollationIndexForMysqlCharsetName(String charsetName)

Implements com.mysql.cj.CharsetSettings.getCollationIndexForMysqlCharsetName.

Annotations
@Override
getCollationNameForCollationIndexback to summary
public String getCollationNameForCollationIndex(Integer collationIndex)

Implements com.mysql.cj.CharsetSettings.getCollationNameForCollationIndex.

Annotations
@Override
getCommandBuilderback to summary
private NativeMessageBuilder getCommandBuilder()
getErrorMessageEncodingback to summary
public String getErrorMessageEncoding()

Implements com.mysql.cj.CharsetSettings.getErrorMessageEncoding.

Annotations
@Override
getJavaEncodingForCollationIndexback to summary
public String getJavaEncodingForCollationIndex(int collationIndex)

Implements com.mysql.cj.CharsetSettings.getJavaEncodingForCollationIndex.

Annotations
@Override
getJavaEncodingForCollationIndexback to summary
public String getJavaEncodingForCollationIndex(Integer collationIndex, String fallBackJavaEncoding)
getJavaEncodingForMysqlCharsetback to summary
public String getJavaEncodingForMysqlCharset(String mysqlCharsetName)

Implements com.mysql.cj.CharsetSettings.getJavaEncodingForMysqlCharset.

Annotations
@Override
getJavaEncodingForMysqlCharsetback to summary
public String getJavaEncodingForMysqlCharset(String mysqlCharsetName, String javaEncoding)
getMaxBytesPerCharback to summary
public int getMaxBytesPerChar(String javaCharsetName)

Implements com.mysql.cj.CharsetSettings.getMaxBytesPerChar.

Annotations
@Override
getMaxBytesPerCharback to summary
public int getMaxBytesPerChar(Integer charsetIndex, String javaCharsetName)

Implements com.mysql.cj.CharsetSettings.getMaxBytesPerChar.

Annotations
@Override
getMetadataCollationIndexback to summary
public int getMetadataCollationIndex()

Implements com.mysql.cj.CharsetSettings.getMetadataCollationIndex.

Annotations
@Override
getMetadataEncodingback to summary
public String getMetadataEncoding()

Implements com.mysql.cj.CharsetSettings.getMetadataEncoding.

Annotations
@Override
getMysqlCharsetForJavaEncodingback to summary
public String getMysqlCharsetForJavaEncoding(String javaEncoding, ServerVersion version)

Implements com.mysql.cj.CharsetSettings.getMysqlCharsetForJavaEncoding.

Annotations
@Override
getMysqlCharsetNameForCollationIndexback to summary
public String getMysqlCharsetNameForCollationIndex(Integer collationIndex)

Implements com.mysql.cj.CharsetSettings.getMysqlCharsetNameForCollationIndex.

Annotations
@Override
getPasswordCharacterEncodingback to summary
public String getPasswordCharacterEncoding()

Implements com.mysql.cj.CharsetSettings.getPasswordCharacterEncoding.

Annotations
@Override
getRequiresEscapingEncoderback to summary
public boolean getRequiresEscapingEncoder()

Implements com.mysql.cj.CharsetSettings.getRequiresEscapingEncoder.

Annotations
@Override
getServerDefaultCharsetback to summary
public String getServerDefaultCharset()

Get the server's default character set name according to collation index from server greeting, or value of 'character_set_server' variable if there is no mapping for that index

Returns:String

MySQL charset name

isImpermissibleCollationback to summary
public boolean isImpermissibleCollation(int collationIndex)
isMultibyteCharsetback to summary
public boolean isMultibyteCharset(String javaEncodingName)

Implements com.mysql.cj.CharsetSettings.isMultibyteCharset.

Annotations
@Override
telemetryWrapSendCommandback to summary
private void telemetryWrapSendCommand(Runnable command, TelemetrySpanName spanName, Object... args)
tryAndFixEncodingback to summary
private void tryAndFixEncoding(RuntimeProperty<String> encodingProperty, boolean replaceImpermissibleEncodings)

Attempt to use the encoding, and bail out if it can't be used.

Parameters
encodingProperty:RuntimeProperty<String>

connection property containing the Java encoding to try

replaceImpermissibleEncodings:boolean

The character_set_client system variable cannot be set to ucs2, utf16, utf16le, utf32 charsets. If "true" the corresponding connection property value will be replaced with "UTF-8"