Github user kaspersorensen commented on a diff in the pull request: https://github.com/apache/metamodel/pull/190#discussion_r222490606 --- Diff: jdbc/src/main/java/org/apache/metamodel/jdbc/JdbcUpdateCallback.java --- @@ -42,18 +43,35 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.cache.CacheBuilder; +import com.google.common.cache.CacheLoader; +import com.google.common.cache.LoadingCache; +import javafx.util.Pair; + abstract class JdbcUpdateCallback extends AbstractUpdateCallback implements UpdateCallback { private static final Logger logger = LoggerFactory.getLogger(JdbcUpdateCallback.class); private Connection _connection; - private String _preparedStatementSql; - private PreparedStatement _preparedStatement; private final UpdateSummaryBuilder _updateSummaryBuilder; + private final LoadingCache<Pair<String, Boolean>, PreparedStatement> _preparedStatementCache; public JdbcUpdateCallback(JdbcDataContext dataContext) { super(dataContext); _updateSummaryBuilder = new UpdateSummaryBuilder(); + int maxCacheSize = JdbcDataContext.getSystemPropertyValue(JdbcDataContext.SYSTEM_PROPERTY_PREPARED_STATEMENT_CACHE_SIZE, 10); + _preparedStatementCache = CacheBuilder.newBuilder() + .maximumSize(maxCacheSize) + .initialCapacity(1) + .removalListener((removalNotification) -> { + closePreparedStatement((PreparedStatement) removalNotification.getValue()); --- End diff -- I'd implement the interface properly here instead of using a lambda. Then you don't have to do this cast which originates from the compiler not being able to infer the types I guess.
---