From bdead7f2a0a652935c1246815352c6431b2daded Mon Sep 17 00:00:00 2001 From: Johno Crawford Date: Mon, 6 Nov 2017 11:48:19 +0100 Subject: [PATCH] Add generics to LRUCache to avoid typed exceptions. --- src/com/mysql/jdbc/ConnectionImpl.java | 20 ++++++++++---------- src/com/mysql/jdbc/PerConnectionLRUFactory.java | 6 +++--- src/com/mysql/jdbc/util/LRUCache.java | 4 ++-- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/com/mysql/jdbc/ConnectionImpl.java b/src/com/mysql/jdbc/ConnectionImpl.java index e0fe1441..4f706bc7 100644 --- a/src/com/mysql/jdbc/ConnectionImpl.java +++ b/src/com/mysql/jdbc/ConnectionImpl.java @@ -546,7 +546,7 @@ public class ConnectionImpl extends ConnectionPropertiesImpl implements MySQLCon */ private final CopyOnWriteArrayList openStatements = new CopyOnWriteArrayList(); - private LRUCache parsedCallableStatementCache; + private LRUCache parsedCallableStatementCache; private boolean parserKnowsUnicode = false; @@ -573,7 +573,7 @@ public class ConnectionImpl extends ConnectionPropertiesImpl implements MySQLCon private boolean readOnly = false; /** Cache of ResultSet metadata */ - protected LRUCache resultSetMetadataCache; + protected LRUCache resultSetMetadataCache; /** The timezone of the server */ private TimeZone serverTimezoneTZ = null; @@ -606,8 +606,8 @@ public class ConnectionImpl extends ConnectionPropertiesImpl implements MySQLCon */ private boolean useServerPreparedStmts = false; - private LRUCache serverSideStatementCheckCache; - private LRUCache serverSideStatementCache; + private LRUCache serverSideStatementCheckCache; + private LRUCache serverSideStatementCache; private Calendar sessionCalendar; private Calendar utcCalendar; @@ -2304,14 +2304,14 @@ public class ConnectionImpl extends ConnectionPropertiesImpl implements MySQLCon } if (getUseServerPreparedStmts()) { - this.serverSideStatementCheckCache = new LRUCache(cacheSize); + this.serverSideStatementCheckCache = new LRUCache(cacheSize); - this.serverSideStatementCache = new LRUCache(cacheSize) { + this.serverSideStatementCache = new LRUCache(cacheSize) { private static final long serialVersionUID = 7692318650375988114L; @Override - protected boolean removeEldestEntry(java.util.Map.Entry eldest) { + protected boolean removeEldestEntry(java.util.Map.Entry eldest) { if (this.maxElements <= 1) { return false; } @@ -2319,7 +2319,7 @@ public class ConnectionImpl extends ConnectionPropertiesImpl implements MySQLCon boolean removeIt = super.removeEldestEntry(eldest); if (removeIt) { - ServerPreparedStatement ps = (ServerPreparedStatement) eldest.getValue(); + ServerPreparedStatement ps = eldest.getValue(); ps.isCached = false; ps.setClosed(false); @@ -3155,7 +3155,7 @@ public class ConnectionImpl extends ConnectionPropertiesImpl implements MySQLCon } if (getCacheCallableStatements()) { - this.parsedCallableStatementCache = new LRUCache(getCallableStatementCacheSize()); + this.parsedCallableStatementCache = new LRUCache(getCallableStatementCacheSize()); } if (getAllowMultiQueries()) { @@ -3163,7 +3163,7 @@ public class ConnectionImpl extends ConnectionPropertiesImpl implements MySQLCon } if (getCacheResultSetMetadata()) { - this.resultSetMetadataCache = new LRUCache(getMetadataCacheSize()); + this.resultSetMetadataCache = new LRUCache(getMetadataCacheSize()); } if (getSocksProxyHost() != null) { diff --git a/src/com/mysql/jdbc/PerConnectionLRUFactory.java b/src/com/mysql/jdbc/PerConnectionLRUFactory.java index 5885e8c9..764aa4cd 100644 --- a/src/com/mysql/jdbc/PerConnectionLRUFactory.java +++ b/src/com/mysql/jdbc/PerConnectionLRUFactory.java @@ -40,13 +40,13 @@ public class PerConnectionLRUFactory implements CacheAdapterFactory { private final int cacheSqlLimit; - private final LRUCache cache; + private final LRUCache cache; private final Connection conn; protected PerConnectionLRU(Connection forConnection, int cacheMaxSize, int maxKeySize) { final int cacheSize = cacheMaxSize; this.cacheSqlLimit = maxKeySize; - this.cache = new LRUCache(cacheSize); + this.cache = new LRUCache(cacheSize); this.conn = forConnection; } @@ -56,7 +56,7 @@ public class PerConnectionLRUFactory implements CacheAdapterFactory { +public class LRUCache extends LinkedHashMap { private static final long serialVersionUID = 1L; protected int maxElements; @@ -41,7 +41,7 @@ public class LRUCache extends LinkedHashMap { * @see java.util.LinkedHashMap#removeEldestEntry(java.util.Map.Entry) */ @Override - protected boolean removeEldestEntry(Entry eldest) { + protected boolean removeEldestEntry(Entry eldest) { return (size() > this.maxElements); } } -- 2.13.6