public CompiledArgumentResolver(SqlBuilder builder) { this.compiledSql = builder.getSqlString(); this.sqlArgs = builder.getBoundArguments(); this.compileContext = builder.compileContext; this.needsValidation = builder.needsValidation(); if (compiledSql.contains(SqlStatement.REPLACEABLE_ARRAY_PARAMETER)) { collectionArgs = new ArrayList<>(); findCollectionArgs(); compiledSqlCache = new SimpleLruCache<>(CACHE_SIZE); argArrayCache = new SimpleLruCache<>(CACHE_SIZE); } }
private String resolveSqlString(String cacheKey, boolean largeArgMode) { if (hasCollectionArgs()) { if (!largeArgMode) { String cachedResult = compiledSqlCache.get(cacheKey); if (cachedResult != null) { return cachedResult; compiledSqlCache.put(cacheKey, resultSql); } else { Logger.w(Logger.LOG_TAG,
private String resolveSqlString(String cacheKey, boolean largeArgMode) { if (hasCollectionArgs()) { if (!largeArgMode) { String cachedResult = compiledSqlCache.get(cacheKey); if (cachedResult != null) { return cachedResult; compiledSqlCache.put(cacheKey, resultSql); } else { Logger.w(Logger.LOG_TAG,
private Object[] resolveSqlArguments(String cacheKey, int totalArgSize, boolean largeArgMode) { if (hasCollectionArgs()) { Object[] cachedResult = argArrayCache.get(cacheKey); if (cachedResult == null) { int size = largeArgMode ? calculateArgsSizeWithoutCollectionArgs() : totalArgSize; if (compiledArgs == null || compiledArgs.length != size) { cachedResult = new Object[size]; } else { cachedResult = compiledArgs; } argArrayCache.put(cacheKey, cachedResult); } compiledArgs = cachedResult; populateCompiledArgs(largeArgMode); } else { if (compiledArgs == null) { compiledArgs = sqlArgs.toArray(new Object[sqlArgs.size()]); } } return applyArgumentResolver(compiledArgs); }
public CompiledArgumentResolver(SqlBuilder builder) { this.compiledSql = builder.getSqlString(); this.sqlArgs = builder.getBoundArguments(); this.compileContext = builder.compileContext; this.needsValidation = builder.needsValidation(); if (compiledSql.contains(SqlStatement.REPLACEABLE_ARRAY_PARAMETER)) { collectionArgs = new ArrayList<>(); findCollectionArgs(); compiledSqlCache = new SimpleLruCache<>(CACHE_SIZE); argArrayCache = new SimpleLruCache<>(CACHE_SIZE); } }
@Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > maxCapacity; } }
private SimpleLruCache<String, String> cacheWithCapacity(int capacity) { return new SimpleLruCache<>(capacity); }
private void testCapacity(int capacity) { SimpleLruCache<String, String> cache = cacheWithCapacity(capacity); populateCache(cache, capacity + 2); String cap1 = Integer.toString(capacity + 1); String cap2 = Integer.toString(capacity + 2); if (capacity > 1) { assertEquals(cap1, cache.get(cap1)); } assertEquals(cap2, cache.get(cap2)); assertNull(cache.get("1")); assertNull(cache.get("2")); } }
private void populateCache(SimpleLruCache<String, String> cache, int times) { for (int i = 1; i <= times; i++) { cache.put(Integer.toString(i), Integer.toString(i)); } }
private Object[] resolveSqlArguments(String cacheKey, int totalArgSize, boolean largeArgMode) { if (hasCollectionArgs()) { Object[] cachedResult = argArrayCache.get(cacheKey); if (cachedResult == null) { int size = largeArgMode ? calculateArgsSizeWithoutCollectionArgs() : totalArgSize; if (compiledArgs == null || compiledArgs.length != size) { cachedResult = new Object[size]; } else { cachedResult = compiledArgs; } argArrayCache.put(cacheKey, cachedResult); } compiledArgs = cachedResult; populateCompiledArgs(largeArgMode); } else { if (compiledArgs == null) { compiledArgs = sqlArgs.toArray(new Object[sqlArgs.size()]); } } return applyArgumentResolver(compiledArgs); }
@Override protected boolean removeEldestEntry(Map.Entry<K, V> eldest) { return size() > maxCapacity; } }