-
-
Notifications
You must be signed in to change notification settings - Fork 263
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #3372 from ebean-orm/feature/1857-SlowQueryBindCap…
…ture #1857 Add bind values capture for SlowQueryEvent / SlowQueryListener
- Loading branch information
Showing
49 changed files
with
349 additions
and
156 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
29 changes: 29 additions & 0 deletions
29
ebean-core/src/main/java/io/ebeaninternal/api/SpiExpressionBind.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package io.ebeaninternal.api; | ||
|
||
import io.ebeaninternal.server.deploy.BeanDescriptor; | ||
|
||
/** | ||
* Expression bind values capture. | ||
*/ | ||
public interface SpiExpressionBind { | ||
|
||
/** | ||
* Return the bean descriptor for the root type. | ||
*/ | ||
BeanDescriptor<?> descriptor(); | ||
|
||
/** | ||
* Add an encryption key to bind to this request. | ||
*/ | ||
void addBindEncryptKey(Object encryptKey); | ||
|
||
/** | ||
* Add a bind value to this request. | ||
*/ | ||
void addBindValue(Object bindValue); | ||
|
||
/** | ||
* Escapes a string to use it as exact match in Like clause. | ||
*/ | ||
String escapeLikeString(String value); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
70 changes: 70 additions & 0 deletions
70
ebean-core/src/main/java/io/ebeaninternal/server/core/DSlowQueryEvent.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
package io.ebeaninternal.server.core; | ||
|
||
import io.ebean.ProfileLocation; | ||
import io.ebean.bean.ObjectGraphNode; | ||
import io.ebean.config.SlowQueryEvent; | ||
|
||
import java.util.List; | ||
|
||
/** | ||
* Slow query event. | ||
*/ | ||
final class DSlowQueryEvent implements SlowQueryEvent { | ||
|
||
private final String sql; | ||
private final long timeMillis; | ||
private final int rowCount; | ||
private final ObjectGraphNode originNode; | ||
private final List<Object> bindParams; | ||
private final String label; | ||
private final ProfileLocation profileLocation; | ||
|
||
/** | ||
* Construct with the SQL and execution time in millis. | ||
*/ | ||
DSlowQueryEvent(String sql, long timeMillis, int rowCount, ObjectGraphNode originNode, | ||
List<Object> bindParams, String label, ProfileLocation profileLocation) { | ||
this.sql = sql; | ||
this.timeMillis = timeMillis; | ||
this.rowCount = rowCount; | ||
this.originNode = originNode; | ||
this.bindParams = bindParams; | ||
this.profileLocation = profileLocation; | ||
this.label = label != null ? label : profileLocation == null ? null : profileLocation.label(); | ||
} | ||
|
||
@Override | ||
public String getSql() { | ||
return sql; | ||
} | ||
|
||
@Override | ||
public long getTimeMillis() { | ||
return timeMillis; | ||
} | ||
|
||
@Override | ||
public int getRowCount() { | ||
return rowCount; | ||
} | ||
|
||
@Override | ||
public ObjectGraphNode getOriginNode() { | ||
return originNode; | ||
} | ||
|
||
@Override | ||
public List<Object> getBindParams() { | ||
return bindParams; | ||
} | ||
|
||
@Override | ||
public String getLabel() { | ||
return label; | ||
} | ||
|
||
@Override | ||
public ProfileLocation getProfileLocation() { | ||
return profileLocation; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
ebean-core/src/main/java/io/ebeaninternal/server/core/SlowQueryBindCapture.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package io.ebeaninternal.server.core; | ||
|
||
import io.ebeaninternal.api.BindParams; | ||
import io.ebeaninternal.api.SpiExpressionBind; | ||
import io.ebeaninternal.api.SpiExpressionList; | ||
import io.ebeaninternal.api.SpiQuery; | ||
import io.ebeaninternal.server.deploy.BeanDescriptor; | ||
import io.ebeaninternal.server.persist.MultiValueWrapper; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
final class SlowQueryBindCapture implements SpiExpressionBind { | ||
|
||
private final SpiQuery<?> query; | ||
private final List<Object> bindParams = new ArrayList<>(); | ||
|
||
SlowQueryBindCapture(SpiQuery<?> query) { | ||
this.query = query; | ||
} | ||
|
||
List<Object> capture() { | ||
var params = query.bindParams(); | ||
if (params != null) { | ||
var positionedParameters = params.positionedParameters(); | ||
for (BindParams.Param param : positionedParameters) { | ||
if (param.isInParam()) { | ||
add(param.inValue()); | ||
} | ||
} | ||
} | ||
Object id = query.getId(); | ||
if (id != null) { | ||
add(id); | ||
} | ||
SpiExpressionList<?> spiExpressionList = query.whereExpressions(); | ||
if (spiExpressionList != null) { | ||
spiExpressionList.addBindValues(this); | ||
} | ||
return bindParams; | ||
} | ||
|
||
private void add(Object value) { | ||
if (value instanceof MultiValueWrapper) { | ||
var mvw = (MultiValueWrapper) value; | ||
bindParams.add(mvw.getValues()); | ||
} else { | ||
bindParams.add(value); | ||
} | ||
} | ||
|
||
@Override | ||
public BeanDescriptor<?> descriptor() { | ||
return query.descriptor(); | ||
} | ||
|
||
@Override | ||
public void addBindValue(Object bindValue) { | ||
add(bindValue); | ||
} | ||
|
||
@Override | ||
public void addBindEncryptKey(Object encryptKey) { | ||
bindParams.add("*"); | ||
} | ||
|
||
@Override | ||
public String escapeLikeString(String value) { | ||
return query.descriptor().ebeanServer().databasePlatform().escapeLikeString(value); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.