Skip to content

Commit

Permalink
fix: Fixed unnecessary column type changes in H2DbWireRecordStoreImpl…
Browse files Browse the repository at this point in the history
… [backport release-5.4.0] (#5158)

* fix: Fixed unnecessary column type changes in H2DbWireRecordStoreImpl (#5157)

fix: Fixed unnecessary column type changes in H2DbWireRecordStore

Signed-off-by: Nicola Timeus <[email protected]>
(cherry picked from commit 9d11914)

* ore: Updated distrib reference to new core bundle

Signed-off-by: MMaiero <[email protected]>

---------

Signed-off-by: MMaiero <[email protected]>
Co-authored-by: nicolatimeus <[email protected]>
Co-authored-by: MMaiero <[email protected]>
  • Loading branch information
3 people authored Feb 29, 2024
1 parent cca8257 commit 443f471
Show file tree
Hide file tree
Showing 3 changed files with 142 additions and 2 deletions.
2 changes: 1 addition & 1 deletion kura/distrib/config/kura.build.properties
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ org.eclipse.kura.asset.helper.provider.version=1.4.0
org.eclipse.kura.broker.artemis.core.version=1.5.0
org.eclipse.kura.broker.artemis.simple.mqtt.version=1.4.0
org.eclipse.kura.broker.artemis.xml.version=1.4.0
org.eclipse.kura.core.version=1.4.0
org.eclipse.kura.core.version=1.4.1-SNAPSHOT
org.eclipse.kura.core.system.version=1.4.0
org.eclipse.kura.core.certificates.version=1.4.0
org.eclipse.kura.core.keystore.version=1.4.1-SNAPSHOT
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*******************************************************************************
* Copyright (c) 2023 Eurotech and/or its affiliates and others
* Copyright (c) 2023, 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
Expand All @@ -15,11 +15,13 @@
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;

import org.eclipse.kura.KuraStoreException;
import org.eclipse.kura.type.BooleanValue;
import org.eclipse.kura.type.ByteArrayValue;
import org.eclipse.kura.type.DataType;
import org.eclipse.kura.type.DoubleValue;
import org.eclipse.kura.type.FloatValue;
import org.eclipse.kura.type.IntegerValue;
Expand Down Expand Up @@ -81,4 +83,26 @@ private static Map<Class<? extends TypedValue<?>>, String> buildTypeMapping() {
return Collections.unmodifiableMap(result);
}

@Override
protected boolean isCorrectColumnType(final TypedValue<?> value, String mappedType, String actualType) {

final boolean mappedTypeEquals = Objects.equals(mappedType, actualType);

if (mappedTypeEquals) {
return true;
}

final DataType dataType = value.getType();

if (dataType == DataType.DOUBLE || dataType == DataType.FLOAT) {
return "DOUBLE PRECISION".equals(actualType) || actualType.startsWith("FLOAT");
} else if (dataType == DataType.STRING) {
return actualType.startsWith("CHARACTER VARYING");
} else if (dataType == DataType.BYTE_ARRAY) {
return "BINARY LARGE OBJECT".equals(actualType);
} else {
return false;
}
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,116 @@
/*******************************************************************************
* Copyright (c) 2024 Eurotech and/or its affiliates and others
*
* This program and the accompanying materials are made
* available under the terms of the Eclipse Public License 2.0
* which is available at https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Eurotech
*******************************************************************************/
package org.eclipse.kura.internal.wire.db.test;

import static org.eclipse.kura.type.TypedValues.newTypedValue;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;

import org.eclipse.kura.KuraException;
import org.eclipse.kura.type.TypedValue;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.junit.runners.Parameterized.Parameters;
import org.osgi.framework.InvalidSyntaxException;

@RunWith(Parameterized.class)
public class MultipleValueStoreTest extends DbComponentsTestBase {

@Test
public void shoudSupportStoringMultipleValuesOfSameType()
throws KuraException, InvalidSyntaxException, InterruptedException, ExecutionException, TimeoutException {
givenAnEnvelopeReceivedByStore("foo", insertedValue);
givenAnEnvelopeReceivedByStore("foo", insertedValue);
givenAnEnvelopeReceivedByStore("foo", insertedValue);

whenQueryIsPerformed("SELECT * FROM \"" + tableName + "\" ORDER BY ID ASC;");

thenEmittedRecordCountIs(3);
thenFilterEmitsEnvelopeWithProperty(0, 0, "foo", expectedValue);
thenFilterEmitsEnvelopeWithProperty(0, 1, "foo", expectedValue);
thenFilterEmitsEnvelopeWithProperty(0, 2, "foo", expectedValue);
}

private final TypedValue<?> insertedValue;
private final TypedValue<?> expectedValue;

public MultipleValueStoreTest(WireComponentTestTarget wireComponentTestTarget, StoreTestTarget storeTestTarget,
final TypedValue<?> insertedValue, final TypedValue<?> extractedValue)
throws InterruptedException, ExecutionException, TimeoutException, KuraException, InvalidSyntaxException {
super(wireComponentTestTarget, storeTestTarget);
this.insertedValue = insertedValue;
this.expectedValue = extractedValue;
}

@Parameters(name = "{0} with {1} : insert {2} expect {3}")
public static List<Object[]> parameters() {

final Boolean testBoolean = true;
final Integer testInteger = 12;
final Long testLong = 1235L;
final Double testDouble = 1d;
final Float testFloat = 1f;
final String testString = "foo";
final byte[] testBa = new byte[] { 1, 2, 3 };

final List<WireComponentTestTarget> wireComponentTestTargets = Arrays
.asList(WireComponentTestTarget.WIRE_RECORD_QUERY_AND_WIRE_RECORD_STORE);

final List<StoreTestTarget> storeTestTargets = Arrays.asList(StoreTestTarget.SQLITE, StoreTestTarget.H2);

final List<Object> insertedValues = Arrays.asList( //
testBoolean, //
testInteger, //
testLong, //
testDouble, //
testFloat, //
testString, //
testBa //
);

final List<Object> expectedValues = Arrays.asList( //
testBoolean, //
testInteger, //
testLong, //
testDouble, //
testDouble, // floats are returned as doubles
testString, //
testBa //
);

final List<Object[]> result = new ArrayList<>();

for (final WireComponentTestTarget wt : wireComponentTestTargets) {
for (final StoreTestTarget st : storeTestTargets) {

final Iterator<Object> insertedIter = insertedValues.iterator();
final Iterator<Object> expectedIter = expectedValues.iterator();

while (insertedIter.hasNext()) {
result.add(new Object[] { wt, st, newTypedValue(insertedIter.next()),
newTypedValue(expectedIter.next()) });
}
}
}

return result;

}

}

0 comments on commit 443f471

Please sign in to comment.