Skip to content

Commit

Permalink
skip null values for 'labels' and 'messages'
Browse files Browse the repository at this point in the history
  • Loading branch information
Oleg Smelov committed Jun 6, 2024
1 parent b6c168a commit 17244bf
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 17 deletions.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -38,14 +54,17 @@ public CompletableFuture<AsyncResultSet> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -30,7 +30,6 @@

import static com.exactpro.cradle.cassandra.dao.messages.MessageBatchEntity.*;


public class MessageBatchInserter {

private final CqlSession session;
Expand All @@ -56,14 +55,17 @@ public CompletableFuture<AsyncResultSet> 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();
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand All @@ -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;
Expand Down Expand Up @@ -58,17 +59,23 @@ public CompletableFuture<AsyncResultSet> 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();
}
}
}

0 comments on commit 17244bf

Please sign in to comment.