-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[#8072] Fix bind.pinpoint api to return json
- Loading branch information
Showing
12 changed files
with
198 additions
and
59 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
31 changes: 31 additions & 0 deletions
31
web/src/main/java/com/navercorp/pinpoint/web/query/BindType.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,31 @@ | ||
package com.navercorp.pinpoint.web.query; | ||
|
||
import java.util.EnumSet; | ||
import java.util.Objects; | ||
import java.util.Set; | ||
|
||
public enum BindType { | ||
SQL("sql"), | ||
MONGO_JSON("mongoJson"); | ||
|
||
private static final Set<BindType> BIND_TYPE = EnumSet.allOf(BindType.class); | ||
|
||
private final String typeName; | ||
|
||
BindType(String typeName) { | ||
this.typeName = Objects.requireNonNull(typeName, "typeName"); | ||
} | ||
|
||
public String getTypeName() { | ||
return typeName; | ||
} | ||
|
||
public static BindType of(String typeName) { | ||
for (BindType bindType : BIND_TYPE) { | ||
if (bindType.getTypeName().equalsIgnoreCase(typeName)) { | ||
return bindType; | ||
} | ||
} | ||
return null; | ||
} | ||
} |
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
24 changes: 24 additions & 0 deletions
24
web/src/main/java/com/navercorp/pinpoint/web/query/EscapeJsonFilter.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,24 @@ | ||
package com.navercorp.pinpoint.web.query; | ||
|
||
import org.apache.commons.text.StringEscapeUtils; | ||
|
||
import java.util.Objects; | ||
|
||
public class EscapeJsonFilter implements QueryService { | ||
private final QueryService delegate; | ||
|
||
public EscapeJsonFilter(QueryService delegate) { | ||
this.delegate = Objects.requireNonNull(delegate, "delegate"); | ||
} | ||
|
||
@Override | ||
public String bind(String metaData, String bind) { | ||
String bindedQuery = delegate.bind(metaData, bind); | ||
return StringEscapeUtils.escapeJson(bindedQuery); | ||
} | ||
|
||
@Override | ||
public BindType getBindType() { | ||
return delegate.getBindType(); | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
web/src/main/java/com/navercorp/pinpoint/web/query/MongoQueryService.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,24 @@ | ||
package com.navercorp.pinpoint.web.query; | ||
|
||
import com.navercorp.pinpoint.web.util.MongoJsonParser; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
public class MongoQueryService implements QueryService { | ||
|
||
private final MongoJsonParser mongoJsonParser = new DefaultMongoJsonParser(); | ||
private final OutputParameterMongoJsonParser parameterJsonParser = new OutputParameterMongoJsonParser(); | ||
|
||
@Override | ||
public String bind(String metaData, String bind) { | ||
List<String> bindValues = parameterJsonParser.parseOutputParameter(bind); | ||
return mongoJsonParser.combineBindValues(metaData, bindValues); | ||
} | ||
|
||
@Override | ||
public BindType getBindType() { | ||
return BindType.MONGO_JSON; | ||
} | ||
} |
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
6 changes: 6 additions & 0 deletions
6
web/src/main/java/com/navercorp/pinpoint/web/query/QueryService.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,6 @@ | ||
package com.navercorp.pinpoint.web.query; | ||
|
||
public interface QueryService { | ||
BindType getBindType(); | ||
String bind(String metaData, String bind); | ||
} |
35 changes: 35 additions & 0 deletions
35
web/src/main/java/com/navercorp/pinpoint/web/query/QueryServiceFactory.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,35 @@ | ||
package com.navercorp.pinpoint.web.query; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.Objects; | ||
import java.util.stream.Stream; | ||
|
||
@Component | ||
public class QueryServiceFactory { | ||
|
||
private final QueryService[] queryServices; | ||
|
||
public QueryServiceFactory(QueryService[] services) { | ||
Objects.requireNonNull(services, "services"); | ||
|
||
this.queryServices = Stream.of(services) | ||
.map(this::wrapFilter) | ||
.toArray(QueryService[]::new); | ||
} | ||
|
||
private QueryService wrapFilter(QueryService service) { | ||
return new EscapeJsonFilter(service); | ||
} | ||
|
||
public QueryService getService(BindType bindType) { | ||
Objects.requireNonNull(bindType, "bindType"); | ||
|
||
for (QueryService queryService : queryServices) { | ||
if (queryService.getBindType().equals(bindType)) { | ||
return queryService; | ||
} | ||
} | ||
throw new IllegalArgumentException("Unknown BindType" + bindType); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
web/src/main/java/com/navercorp/pinpoint/web/query/SqlQueryService.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,26 @@ | ||
package com.navercorp.pinpoint.web.query; | ||
|
||
import com.navercorp.pinpoint.common.profiler.sql.DefaultSqlParser; | ||
import com.navercorp.pinpoint.common.profiler.sql.OutputParameterParser; | ||
import com.navercorp.pinpoint.common.profiler.sql.SqlParser; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
public class SqlQueryService implements QueryService { | ||
|
||
private final SqlParser sqlParser = new DefaultSqlParser(); | ||
private final OutputParameterParser parameterParser = new OutputParameterParser(); | ||
|
||
@Override | ||
public String bind(String metaData, String bind) { | ||
List<String> bindValues = parameterParser.parseOutputParameter(bind); | ||
return sqlParser.combineBindValues(metaData, bindValues); | ||
} | ||
|
||
@Override | ||
public BindType getBindType() { | ||
return BindType.SQL; | ||
} | ||
} |
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.