Merge "Flush persistent H2 cache if the existing entries are incompatible" into stable-2.5

This commit is contained in:
Shawn Pearce
2012-10-16 10:17:41 -07:00
committed by Gerrit Code Review

View File

@@ -13,10 +13,12 @@ import com.google.common.hash.Funnels;
import com.google.common.hash.PrimitiveSink; import com.google.common.hash.PrimitiveSink;
import com.google.inject.TypeLiteral; import com.google.inject.TypeLiteral;
import org.h2.jdbc.JdbcSQLException;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import java.io.IOException; import java.io.IOException;
import java.io.InvalidClassException;
import java.io.ObjectOutputStream; import java.io.ObjectOutputStream;
import java.io.OutputStream; import java.io.OutputStream;
import java.sql.Connection; import java.sql.Connection;
@@ -394,6 +396,15 @@ public class H2CacheImpl<K, V> extends AbstractLoadingCache<K, V> {
while (r.next()) { while (r.next()) {
b.put(keyType.get(r, 1)); b.put(keyType.get(r, 1));
} }
} catch (JdbcSQLException e) {
if (e.getCause() instanceof InvalidClassException) {
log.warn("Entries cached for " + url
+ " have an incompatible class and can't be deserialized. "
+ "Cache is flushed.");
invalidateAll();
} else {
throw e;
}
} finally { } finally {
r.close(); r.close();
} }