in adb3client/src/main/java/com/alibaba/cloud/analyticdb/adb3client/impl/Cache.java [169:212]
public V get(K key, FunctionWithSQLException<K, V> builder, final int mode) throws SQLException {
final FunctionWithSQLException<K, V> internalBuilder = builder == null ? this.builder : builder;
Item item = null;
if (mode == MODE_ONLY_CACHE) {
item = cache.get(key);
if (item != null && !item.isExpire()) {
item.setAccessed(true);
} else {
item = null;
}
} else {
try {
item = cache.compute(key, (k, old) -> {
if (MODE_NO_CACHE == mode || old == null || old.isExpire()) {
try {
V value = internalBuilder.apply(k);
if (value != null) {
return new Item(value);
} else {
return null;
}
} catch (SQLException throwables) {
throw new FunctionRuntimeException(throwables);
}
} else {
old.setAccessed(true);
return old;
}
});
} catch (FunctionRuntimeException e) {
Throwable cause = e.getCause();
if (cause instanceof SQLException) {
throw (SQLException) cause;
} else {
throw new SQLException(cause);
}
}
}
if (item == null) {
return null;
} else {
return item.get();
}
}