From 17244bf56b51f51b75834e0e7040212e413652e4 Mon Sep 17 00:00:00 2001 From: Oleg Smelov Date: Thu, 6 Jun 2024 10:02:02 +0400 Subject: [PATCH] skip null values for 'labels' and 'messages' --- .../messages/GroupedMessageBatchInserter.java | 27 ++++++++++++++++--- .../dao/messages/MessageBatchInserter.java | 14 +++++----- .../dao/testevents/TestEvenInserter.java | 21 ++++++++++----- 3 files changed, 45 insertions(+), 17 deletions(-) diff --git a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/GroupedMessageBatchInserter.java b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/GroupedMessageBatchInserter.java index 8770df6c..0b82e692 100644 --- a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/GroupedMessageBatchInserter.java +++ b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/GroupedMessageBatchInserter.java @@ -1,3 +1,19 @@ +/* + * Copyright 2022-2024 Exactpro (Exactpro Systems Limited) + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + package com.exactpro.cradle.cassandra.dao.messages; import com.datastax.oss.driver.api.core.CqlSession; @@ -38,14 +54,17 @@ public CompletableFuture insert(GroupedMessageBatchEntity groupe .setLocalDate(FIELD_LAST_MESSAGE_DATE, groupedMessageBatch.getLastMessageDate()) .setLocalTime(FIELD_LAST_MESSAGE_TIME, groupedMessageBatch.getLastMessageTime()) .setInt(FIELD_MESSAGE_COUNT, groupedMessageBatch.getMessageCount()) - .setBoolean(FIELD_COMPRESSED, groupedMessageBatch.isCompressed()) - .setSet(FIELD_LABELS, groupedMessageBatch.getLabels(), String.class) - .setByteBuffer(FIELD_CONTENT, groupedMessageBatch.getContent()) + .setBoolean(FIELD_COMPRESSED, groupedMessageBatch.isCompressed()); + + if (groupedMessageBatch.getLabels() != null) { + builder = builder.setSet(FIELD_LABELS, groupedMessageBatch.getLabels(), String.class); + } + + builder = builder.setByteBuffer(FIELD_CONTENT, groupedMessageBatch.getContent()) .setInstant(FIELD_REC_DATE, Instant.now()) .setInt(FIELD_CONTENT_SIZE, groupedMessageBatch.getContentSize()) .setInt(FIELD_UNCOMPRESSED_CONTENT_SIZE, groupedMessageBatch.getUncompressedContentSize()); - attributes.apply(builder); BoundStatement statement = builder.build(); return session.executeAsync(statement).toCompletableFuture(); diff --git a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessageBatchInserter.java b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessageBatchInserter.java index 6382184a..e7092f44 100644 --- a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessageBatchInserter.java +++ b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/messages/MessageBatchInserter.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -30,7 +30,6 @@ import static com.exactpro.cradle.cassandra.dao.messages.MessageBatchEntity.*; - public class MessageBatchInserter { private final CqlSession session; @@ -56,14 +55,17 @@ public CompletableFuture insert(MessageBatchEntity messageBatch, .setLocalTime(FIELD_LAST_MESSAGE_TIME, messageBatch.getLastMessageTime()) .setLong(FIELD_LAST_SEQUENCE, messageBatch.getLastSequence()) .setInt(FIELD_MESSAGE_COUNT, messageBatch.getMessageCount()) - .setBoolean(FIELD_COMPRESSED, messageBatch.isCompressed()) - .setSet(FIELD_LABELS, messageBatch.getLabels(), String.class) - .setByteBuffer(FIELD_CONTENT, messageBatch.getContent()) + .setBoolean(FIELD_COMPRESSED, messageBatch.isCompressed()); + + if (messageBatch.getLabels() != null) { + builder = builder.setSet(FIELD_LABELS, messageBatch.getLabels(), String.class); + } + + builder = builder.setByteBuffer(FIELD_CONTENT, messageBatch.getContent()) .setInstant(FIELD_REC_DATE, Instant.now()) .setInt(FIELD_CONTENT_SIZE, messageBatch.getContentSize()) .setInt(FIELD_UNCOMPRESSED_CONTENT_SIZE, messageBatch.getUncompressedContentSize()); - attributes.apply(builder); BoundStatement statement = builder.build(); return session.executeAsync(statement).toCompletableFuture(); diff --git a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/testevents/TestEvenInserter.java b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/testevents/TestEvenInserter.java index 03cae338..8c426d6e 100644 --- a/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/testevents/TestEvenInserter.java +++ b/cradle-cassandra/src/main/java/com/exactpro/cradle/cassandra/dao/testevents/TestEvenInserter.java @@ -1,5 +1,5 @@ /* - * Copyright 2021-2022 Exactpro (Exactpro Systems Limited) + * Copyright 2021-2024 Exactpro (Exactpro Systems Limited) * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -13,6 +13,7 @@ * See the License for the specific language governing permissions and * limitations under the License. */ + package com.exactpro.cradle.cassandra.dao.testevents; import com.datastax.oss.driver.api.core.CqlSession; @@ -58,17 +59,23 @@ public CompletableFuture insert(TestEventEntity testEvent, Funct .setInt(FIELD_EVENT_COUNT, testEvent.getEventCount()) .setLocalDate(FIELD_END_DATE, testEvent.getEndDate()) .setLocalTime(FIELD_END_TIME, testEvent.getEndTime()) - .setBoolean(FIELD_COMPRESSED, testEvent.isCompressed()) - .setByteBuffer(FIELD_MESSAGES, testEvent.getMessages()) - .setSet(FIELD_LABELS, testEvent.getLabels(), String.class) - .setByteBuffer(FIELD_CONTENT, testEvent.getContent()) + .setBoolean(FIELD_COMPRESSED, testEvent.isCompressed()); + + if (testEvent.getMessages() != null) { + builder = builder.setByteBuffer(FIELD_MESSAGES, testEvent.getMessages()); + } + + if (testEvent.getLabels() != null) { + builder = builder.setSet(FIELD_LABELS, testEvent.getLabels(), String.class); + } + + builder = builder.setByteBuffer(FIELD_CONTENT, testEvent.getContent()) .setInstant(FIELD_REC_DATE, Instant.now()) .setInt(FIELD_CONTENT_SIZE, testEvent.getContentSize()) .setInt(FIELD_UNCOMPRESSED_CONTENT_SIZE, testEvent.getUncompressedContentSize()); - attributes.apply(builder); BoundStatement statement = builder.build(); return session.executeAsync(statement).toCompletableFuture(); } -} +} \ No newline at end of file