From e276fe0f810b221e245e665798b60fd0807d9450 Mon Sep 17 00:00:00 2001 From: Ohjun Kwon Date: Mon, 29 Jul 2024 15:07:55 +0900 Subject: [PATCH] [#noissue] Validate SqlUidMetaDataBo --- .../collector/service/HbaseSqlUidMetaDataService.java | 5 ++++- .../collector/service/SqlUidMetaDataService.java | 3 ++- .../pinpoint/common/server/bo/SqlUidMetaDataBo.java | 10 ++++++---- 3 files changed, 12 insertions(+), 6 deletions(-) diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/HbaseSqlUidMetaDataService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/HbaseSqlUidMetaDataService.java index 4cdcd08b8c1c..c4fc3b9c2239 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/HbaseSqlUidMetaDataService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/HbaseSqlUidMetaDataService.java @@ -4,11 +4,14 @@ import com.navercorp.pinpoint.collector.dao.SqlUidMetaDataDao; import com.navercorp.pinpoint.common.server.bo.SqlUidMetaDataBo; import com.navercorp.pinpoint.common.util.StringUtils; +import jakarta.validation.Valid; import org.springframework.stereotype.Service; +import org.springframework.validation.annotation.Validated; import java.util.Objects; @Service +@Validated public class HbaseSqlUidMetaDataService implements SqlUidMetaDataService { private final SqlUidMetaDataDao sqlUidMetaDataDao; @@ -21,7 +24,7 @@ public HbaseSqlUidMetaDataService(SqlUidMetaDataDao sqlUidMetaDataDao, Collector } @Override - public void insert(SqlUidMetaDataBo sqlUidMetaDataBo) { + public void insert(@Valid SqlUidMetaDataBo sqlUidMetaDataBo) { if (sqlUidMetaDataBo.getSql().length() > maxSqlLength) { String sql = StringUtils.abbreviate(sqlUidMetaDataBo.getSql(), maxSqlLength); sqlUidMetaDataBo = new SqlUidMetaDataBo(sqlUidMetaDataBo.getAgentId(), sqlUidMetaDataBo.getAgentStartTime(), sqlUidMetaDataBo.getApplicationName(), sqlUidMetaDataBo.getUid(), sql); diff --git a/collector/src/main/java/com/navercorp/pinpoint/collector/service/SqlUidMetaDataService.java b/collector/src/main/java/com/navercorp/pinpoint/collector/service/SqlUidMetaDataService.java index 0e3419d7f6aa..a77cff501c0b 100644 --- a/collector/src/main/java/com/navercorp/pinpoint/collector/service/SqlUidMetaDataService.java +++ b/collector/src/main/java/com/navercorp/pinpoint/collector/service/SqlUidMetaDataService.java @@ -1,7 +1,8 @@ package com.navercorp.pinpoint.collector.service; import com.navercorp.pinpoint.common.server.bo.SqlUidMetaDataBo; +import jakarta.validation.Valid; public interface SqlUidMetaDataService { - void insert(SqlUidMetaDataBo sqlUidMetaDataBo); + void insert(@Valid SqlUidMetaDataBo sqlUidMetaDataBo); } diff --git a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SqlUidMetaDataBo.java b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SqlUidMetaDataBo.java index 634530d1a241..52f0ba605f0d 100644 --- a/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SqlUidMetaDataBo.java +++ b/commons-server/src/main/java/com/navercorp/pinpoint/common/server/bo/SqlUidMetaDataBo.java @@ -1,17 +1,19 @@ package com.navercorp.pinpoint.common.server.bo; import com.navercorp.pinpoint.common.server.bo.serializer.metadata.uid.UidMetaDataRowKey; +import jakarta.validation.constraints.NotBlank; +import jakarta.validation.constraints.PositiveOrZero; import java.util.Arrays; import java.util.Objects; public class SqlUidMetaDataBo implements UidMetaDataRowKey { - private final String agentId; - private final long startTime; - private final String applicationName; + @NotBlank private final String agentId; + @PositiveOrZero private final long startTime; + @NotBlank private final String applicationName; private final byte[] sqlUid; - private final String sql; + @NotBlank private final String sql; public SqlUidMetaDataBo(String agentId, long startTime, byte[] sqlUid, String sql) { this.agentId = Objects.requireNonNull(agentId, "agentId");