
Inline adoc files when they are included exactly once. Also fix language tags because this inlining gives us better information on what language the code is written in.
39 lines
975 B
Plaintext
39 lines
975 B
Plaintext
== Why is this an issue?
|
|
|
|
Some implementations of ``++java.sql.ResultSet#getMetaData()++`` suffer from performance issue and should not be called in a loop. Instead, multiple calls in a row should be replaced by a single cached call.
|
|
|
|
|
|
=== Noncompliant code example
|
|
|
|
[source,java]
|
|
----
|
|
ResultSetMetaData rsmd = rs.getMetaData();
|
|
for (int i=1; i<rsmd.getColumnCount(); i++) {
|
|
System.out.println(rs.getMetaData().getAutoIncrement()); // Noncompliant; "rs.getMetaData()" will be called for each columns
|
|
}
|
|
----
|
|
|
|
|
|
=== Compliant solution
|
|
|
|
[source,java]
|
|
----
|
|
ResultSetMetaData rsmd = rs.getMetaData(); // Compliant; result of "rs.getMetaData()" is cached
|
|
for (int i=1; i<rsmd.getColumnCount(); i++) {
|
|
System.out.println(rsmd.getAutoIncrement());
|
|
}
|
|
----
|
|
|
|
ifdef::env-github,rspecator-view[]
|
|
|
|
'''
|
|
== Implementation Specification
|
|
(visible only on this page)
|
|
|
|
=== Message
|
|
|
|
Cache the result of "java.sql.ResultSet#getMetaData()" out of this loop.
|
|
|
|
|
|
endif::env-github,rspecator-view[]
|