Skip to content

Commit

Permalink
feat: Added query type (static, prep, call) to search index
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Ruaux committed Apr 19, 2023
1 parent 6e2b828 commit c98d3b4
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,19 @@

public class SmartCallableStatement extends SmartPreparedStatement implements CallableStatement {

private static final String TYPE = "proc";

private final Map<String, Object> parameters = new HashMap<>();

public SmartCallableStatement(SmartConnection connection, CallableStatement statement, String sql) {
super(connection, statement, sql);
}

@Override
protected String statementType() {
return TYPE;
}

@Override
protected Collection<Object> parameters() {
return parameters.entrySet().stream().map(Parameter::new).collect(Collectors.toList());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@

public class SmartPreparedStatement extends SmartStatement implements PreparedStatement {

private static final String TYPE = "prep";

private static final String METHOD_CANNOT_BE_USED = "Cannot use query methods that take a query string on a PreparedStatement";
protected static final String PARAMETER_SEPARATOR = ",";

Expand All @@ -42,6 +44,11 @@ public SmartPreparedStatement(SmartConnection connection, PreparedStatement stat
this.sql = sql;
}

@Override
protected String statementType() {
return TYPE;
}

@Override
protected String key(Query query) {
KeyBuilder keyBuilder = connection.getKeyBuilder();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,8 @@ public class SmartStatement implements Statement {
public static final String TAG_ID = "id";
public static final String TAG_TABLE = "table";
public static final String TAG_SQL = "sql";
public static final String TAG_TYPE = "type";
private static final String TYPE = "static";

protected final SmartConnection connection;
protected final Statement statement;
Expand All @@ -58,7 +60,12 @@ private Timer createTimer(String name, Query query) {
}

private Tags tags(Query query) {
return Tags.of(TAG_ID, query.getId(), TAG_SQL, query.getSql(), TAG_TABLE, csv(query.getTables()));
return Tags.of(TAG_ID, query.getId(), TAG_TYPE, statementType(), TAG_SQL, query.getSql(), TAG_TABLE,
csv(query.getTables()));
}

protected String statementType() {
return TYPE;
}

private String csv(Collection<String> tables) {
Expand Down

0 comments on commit c98d3b4

Please sign in to comment.