[#7474] Make number of seconds that are considered "slow" in jOOQ-meta configurable

This commit is contained in:
lukaseder 2018-05-11 10:54:07 +02:00
parent b3ff200fce
commit c0190dc488
3 changed files with 54 additions and 3 deletions

View File

@ -275,17 +275,18 @@ public abstract class AbstractDatabase implements Database {
@Override
public void executeEnd(ExecuteContext ctx) {
if (getLogSlowQueriesAfterSeconds() <= 0)
int s = getLogSlowQueriesAfterSeconds();
if (s <= 0)
return;
StopWatch watch = (StopWatch) ctx.data("org.jooq.meta.AbstractDatabase.watch");
if (watch.split() > TimeUnit.SECONDS.toNanos(getLogSlowQueriesAfterSeconds())) {
if (watch.split() > TimeUnit.SECONDS.toNanos(s)) {
watch.splitWarn("Slow SQL");
log.warn(
"Slow SQL",
"jOOQ Meta executed a slow query (slower than 5 seconds)"
"jOOQ Meta executed a slow query (slower than " + s + " seconds, configured by configuration/generator/database/logSlowQueriesAfterSeconds)"
+ "\n\n"
+ "Please report this bug here: https://github.com/jOOQ/jOOQ/issues/new\n\n```sql\n"
+ formatted(ctx.query())

View File

@ -127,6 +127,8 @@ public class Database implements Serializable
@XmlElement(defaultValue = "true")
protected Boolean forceIntegerTypesOnZeroScaleDecimals = true;
protected Boolean tableValuedFunctions;
@XmlElement(defaultValue = "5")
protected Integer logSlowQueriesAfterSeconds = 5;
@XmlElementWrapper(name = "properties")
@XmlElement(name = "property")
protected List<Property> properties;
@ -1190,6 +1192,30 @@ public class Database implements Serializable
this.tableValuedFunctions = value;
}
/**
* The number of seconds that are considered "slow" before a query is logged to indicate a bug, 0 for not logging.
*
* @return
* possible object is
* {@link Integer }
*
*/
public Integer getLogSlowQueriesAfterSeconds() {
return logSlowQueriesAfterSeconds;
}
/**
* Sets the value of the logSlowQueriesAfterSeconds property.
*
* @param value
* allowed object is
* {@link Integer }
*
*/
public void setLogSlowQueriesAfterSeconds(Integer value) {
this.logSlowQueriesAfterSeconds = value;
}
public List<Property> getProperties() {
if (properties == null) {
properties = new ArrayList<Property>();
@ -1452,6 +1478,11 @@ public class Database implements Serializable
return this;
}
public Database withLogSlowQueriesAfterSeconds(Integer value) {
setLogSlowQueriesAfterSeconds(value);
return this;
}
public Database withProperties(Property... values) {
if (values!= null) {
for (Property value: values) {
@ -1766,6 +1797,11 @@ public class Database implements Serializable
sb.append(tableValuedFunctions);
sb.append("</tableValuedFunctions>");
}
if (logSlowQueriesAfterSeconds!= null) {
sb.append("<logSlowQueriesAfterSeconds>");
sb.append(logSlowQueriesAfterSeconds);
sb.append("</logSlowQueriesAfterSeconds>");
}
if (properties!= null) {
sb.append("<properties>");
sb.append(properties);
@ -2144,6 +2180,15 @@ public class Database implements Serializable
return false;
}
}
if (logSlowQueriesAfterSeconds == null) {
if (other.logSlowQueriesAfterSeconds!= null) {
return false;
}
} else {
if (!logSlowQueriesAfterSeconds.equals(other.logSlowQueriesAfterSeconds)) {
return false;
}
}
if (properties == null) {
if (other.properties!= null) {
return false;
@ -2242,6 +2287,7 @@ public class Database implements Serializable
result = ((prime*result)+((orderProvider == null)? 0 :orderProvider.hashCode()));
result = ((prime*result)+((forceIntegerTypesOnZeroScaleDecimals == null)? 0 :forceIntegerTypesOnZeroScaleDecimals.hashCode()));
result = ((prime*result)+((tableValuedFunctions == null)? 0 :tableValuedFunctions.hashCode()));
result = ((prime*result)+((logSlowQueriesAfterSeconds == null)? 0 :logSlowQueriesAfterSeconds.hashCode()));
result = ((prime*result)+((properties == null)? 0 :properties.hashCode()));
result = ((prime*result)+((catalogs == null)? 0 :catalogs.hashCode()));
result = ((prime*result)+((schemata == null)? 0 :schemata.hashCode()));

View File

@ -714,6 +714,10 @@ and VARRAY types in Oracle.
While this flag defaults to true for most databases, it defaults to false
for Oracle.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
<element name="logSlowQueriesAfterSeconds" type="int" minOccurs="0" maxOccurs="1" default="5">
<annotation><appinfo><jxb:property><jxb:javadoc><![CDATA[The number of seconds that are considered "slow" before a query is logged to indicate a bug, 0 for not logging.]]></jxb:javadoc></jxb:property></appinfo></annotation>
</element>
</all>
</complexType>