Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import java.lang.ref.WeakReference;
import java.lang.reflect.Method;
import java.sql.Statement;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
Expand All @@ -40,11 +41,13 @@ public class StatementFinalizer extends AbstractCreateStatementInterceptor {
protected List<StatementEntry> statements = new LinkedList<>();

private boolean logCreationStack = false;
private int createStatementCount=0;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unnecessary to initialize instance variables, since they're being initialized with their default value. In this case: 0


@Override
public Object createStatement(Object proxy, Method method, Object[] args, Object statement, long time) {
try {
if (statement instanceof Statement) {
clearEntry();
statements.add(new StatementEntry((Statement)statement));
}
}catch (ClassCastException x) {
Expand Down Expand Up @@ -93,6 +96,22 @@ public void reset(ConnectionPool parent, PooledConnection con) {
super.reset(parent, con);
}

public void clearEntry() {
if(createStatementCount%10!=0) {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why don't you want to check every add?

createStatementCount++;
return;
}else {
createStatementCount=0;
Iterator<StatementEntry> iterator = statements.iterator();
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be done with List.removeIf()

while (iterator.hasNext()) {
StatementEntry st = iterator.next();
if(st.getStatement()==null || st.getStatement().isClosed()) {
iterator.remove();
}
}
}
}

protected class StatementEntry {
private WeakReference<Statement> statement;
private Throwable allocationStack;
Expand Down