mirror of
https://github.com/mariadb-corporation/mariadb-connector-j.git
synced 2025-07-22 01:28:39 +00:00
[CONJ-1261] Provide an option to cache the results of loadCodecs
This commit is contained in:
@ -59,6 +59,7 @@ public class Configuration {
|
||||
private static final Set<String> SENSITIVE_FIELDS;
|
||||
private static final String CATALOG_TERM = "CATALOG";
|
||||
private static final String SCHEMA_TERM = "SCHEMA";
|
||||
private static Codec<?>[] cachedCodecs = null;
|
||||
|
||||
static {
|
||||
EXCLUDED_FIELDS = new HashSet<>();
|
||||
@ -79,6 +80,7 @@ public class Configuration {
|
||||
PROPERTIES_TO_SKIP.add("$jacocoData");
|
||||
PROPERTIES_TO_SKIP.add("CATALOG_TERM");
|
||||
PROPERTIES_TO_SKIP.add("SCHEMA_TERM");
|
||||
PROPERTIES_TO_SKIP.add("cachedCodecs");
|
||||
|
||||
SENSITIVE_FIELDS = new HashSet<>();
|
||||
SENSITIVE_FIELDS.add("password");
|
||||
@ -120,6 +122,7 @@ public class Configuration {
|
||||
private String initSql;
|
||||
private boolean pinGlobalTxToPhysicalConnection;
|
||||
private boolean permitNoResults;
|
||||
private boolean cacheCodecs;
|
||||
|
||||
// socket
|
||||
private String socketFactory;
|
||||
@ -391,6 +394,7 @@ public class Configuration {
|
||||
this.pinGlobalTxToPhysicalConnection =
|
||||
builder.pinGlobalTxToPhysicalConnection != null && builder.pinGlobalTxToPhysicalConnection;
|
||||
this.permitNoResults = builder.permitNoResults == null || builder.permitNoResults;
|
||||
this.cacheCodecs = builder.cacheCodecs != null && builder.cacheCodecs;
|
||||
this.blankTableNameMeta = builder.blankTableNameMeta != null && builder.blankTableNameMeta;
|
||||
this.disconnectOnExpiredPasswords =
|
||||
builder.disconnectOnExpiredPasswords == null || builder.disconnectOnExpiredPasswords;
|
||||
@ -561,6 +565,7 @@ public class Configuration {
|
||||
.permitRedirect(this.permitRedirect)
|
||||
.pinGlobalTxToPhysicalConnection(this.pinGlobalTxToPhysicalConnection)
|
||||
.permitNoResults(this.permitNoResults)
|
||||
.cacheCodecs(this.cacheCodecs)
|
||||
.transactionIsolation(
|
||||
transactionIsolation == null ? null : this.transactionIsolation.getValue())
|
||||
.defaultFetchSize(this.defaultFetchSize)
|
||||
@ -2277,11 +2282,24 @@ public class Configuration {
|
||||
|
||||
@SuppressWarnings("rawtypes")
|
||||
private void loadCodecs() {
|
||||
if (cacheCodecs && cachedCodecs != null) {
|
||||
codecs = cachedCodecs;
|
||||
return;
|
||||
}
|
||||
|
||||
ServiceLoader<Codec> loader =
|
||||
ServiceLoader.load(Codec.class, Configuration.class.getClassLoader());
|
||||
List<Codec<?>> result = new ArrayList<>();
|
||||
loader.iterator().forEachRemaining(result::add);
|
||||
codecs = result.toArray(new Codec<?>[0]);
|
||||
|
||||
if (cacheCodecs) {
|
||||
synchronized (Configuration.class) {
|
||||
if (cachedCodecs == null) {
|
||||
cachedCodecs = codecs;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -2319,6 +2337,7 @@ public class Configuration {
|
||||
private Boolean permitRedirect;
|
||||
private Boolean pinGlobalTxToPhysicalConnection;
|
||||
private Boolean permitNoResults;
|
||||
private Boolean cacheCodecs;
|
||||
private Integer defaultFetchSize;
|
||||
private Integer maxQuerySizeToLog;
|
||||
private Integer maxAllowedPacket;
|
||||
@ -3298,6 +3317,17 @@ public class Configuration {
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* Permit caching codecs
|
||||
*
|
||||
* @param cacheCodecs can codec load be cached
|
||||
* @return this {@link Builder}
|
||||
*/
|
||||
public Builder cacheCodecs(Boolean cacheCodecs) {
|
||||
this.cacheCodecs = cacheCodecs;
|
||||
return this;
|
||||
}
|
||||
|
||||
/**
|
||||
* On dead-lock exception must add innodb status in exception error message. If enabled, an
|
||||
* additional command will be done to retrieve innodb status when dead-lock occurs.
|
||||
|
@ -87,4 +87,5 @@ trustStore=File path of the trustStore file (similar to java System property \"j
|
||||
trustStorePassword=Password for the trusted root certificate file (similar to java System property \"javax.net.ssl.trustStorePassword\").(legacy alias trustCertificateKeyStorePassword).
|
||||
disconnectOnExpiredPasswords=On connection creation, indicate behavior when password is expired. When true (default) throw an expired password error. When false, connection succeed in "sandbox" mode, only queries related to password change are allowed.
|
||||
permitNoResults=Indicate if Statement/PreparedStatement.executeQuery for command that produce no result will return an exception or just an empty result-set. When enabled, command not returning no data will end returning an empty result-set, when disabled, command not returning no data will end throwing an exception
|
||||
oldModeNoPrecisionTimestamp=permit timestamp text micro-precision representation compatible with 2.7. This is a compatibility option only.
|
||||
oldModeNoPrecisionTimestamp=permit timestamp text micro-precision representation compatible with 2.7. This is a compatibility option only.
|
||||
cacheCodecs=permit to enable/disable caching of codecs (FIELD encoder/decoder)
|
||||
|
Reference in New Issue
Block a user