GeezerVison is showing github.com — Merge branch '21-string-list-properties' into dev · zhoupan/objectbox-java@cdc4174
File treeExpand file treeCollapse file tree Open diff view settings objectbox-java/src/main/java/io/objectbox tests/objectbox-java-test/src
Expand file treeCollapse file tree Open diff view settings Collapse file Copy file name to clipboardExpand all lines: objectbox-java/src/main/java/io/objectbox/Cursor.java +10-7Lines changed: 10 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 16 | 16 |
| 17 | 17 | package io.objectbox; | 18 | 18 |
| 19 | | -import java.io.Closeable; | 20 | | -import java.util.List; | 21 | | - | 22 | | -import javax.annotation.Nullable; | 23 | | -import javax.annotation.concurrent.NotThreadSafe; | 24 | | - | 25 | 19 | import io.objectbox.annotation.apihint.Beta; | 26 | 20 | import io.objectbox.annotation.apihint.Internal; | 27 | 21 | import io.objectbox.internal.CursorFactory; | 28 | 22 | import io.objectbox.relation.ToMany; | 29 | 23 |
| | 24 | +import javax.annotation.Nullable; | | 25 | +import javax.annotation.concurrent.NotThreadSafe; | | 26 | +import java.io.Closeable; | | 27 | +import java.util.List; | | 28 | + | 30 | 29 | @SuppressWarnings({"unchecked", "SameParameterValue", "unused", "WeakerAccess", "UnusedReturnValue"}) | 31 | 30 | @Beta | 32 | 31 | @Internal | @@ -107,7 +106,11 @@ protected static native long collect004000(long cursor, long keyIfComplete, int | 107 | 106 | ); | 108 | 107 |
| 109 | 108 | protected static native long collectStringArray(long cursor, long keyIfComplete, int flags, | 110 | | - int idStringArray, String[] stringArray | | 109 | + int idStringArray, @Nullable String[] stringArray | | 110 | + ); | | 111 | + | | 112 | + protected static native long collectStringList(long cursor, long keyIfComplete, int flags, | | 113 | + int idStringList, @Nullable List<String> stringList | 111 | 114 | ); | 112 | 115 |
| 113 | 116 | native int nativePropertyId(long cursor, String propertyValue); | |
Collapse file Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/main/java/io/objectbox/TestEntity.java +15-1Lines changed: 15 additions & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
| 17 | 17 | package io.objectbox; | 18 | 18 |
| 19 | 19 | import java.util.Arrays; | | 20 | +import java.util.List; | 20 | 21 |
| 21 | 22 | /** In "real" entity would be annotated with @Entity. */ | 22 | 23 | public class TestEntity { | @@ -42,6 +43,7 @@ public class TestEntity { | 42 | 43 | private byte[] simpleByteArray; | 43 | 44 | /** Not-null value. */ | 44 | 45 | private String[] simpleStringArray; | | 46 | + private List<String> simpleStringList; | 45 | 47 | /** In "real" entity would be annotated with @Unsigned. */ | 46 | 48 | private short simpleShortU; | 47 | 49 | /** In "real" entity would be annotated with @Unsigned. */ | @@ -59,7 +61,7 @@ public TestEntity(long id) { | 59 | 61 | this.id = id; | 60 | 62 | } | 61 | 63 |
| 62 | | - public TestEntity(long id, boolean simpleBoolean, byte simpleByte, short simpleShort, int simpleInt, long simpleLong, float simpleFloat, double simpleDouble, String simpleString, byte[] simpleByteArray, String[] simpleStringArray, short simpleShortU, int simpleIntU, long simpleLongU) { | | 64 | + public TestEntity(long id, boolean simpleBoolean, byte simpleByte, short simpleShort, int simpleInt, long simpleLong, float simpleFloat, double simpleDouble, String simpleString, byte[] simpleByteArray, String[] simpleStringArray, List<String> simpleStringList, short simpleShortU, int simpleIntU, long simpleLongU) { | 63 | 65 | this.id = id; | 64 | 66 | this.simpleBoolean = simpleBoolean; | 65 | 67 | this.simpleByte = simpleByte; | @@ -71,6 +73,7 @@ public TestEntity(long id, boolean simpleBoolean, byte simpleByte, short simpleS | 71 | 73 | this.simpleString = simpleString; | 72 | 74 | this.simpleByteArray = simpleByteArray; | 73 | 75 | this.simpleStringArray = simpleStringArray; | | 76 | + this.simpleStringList = simpleStringList; | 74 | 77 | this.simpleShortU = simpleShortU; | 75 | 78 | this.simpleIntU = simpleIntU; | 76 | 79 | this.simpleLongU = simpleLongU; | @@ -172,6 +175,16 @@ public String[] getSimpleStringArray() { | 172 | 175 | public void setSimpleStringArray(String[] simpleStringArray) { | 173 | 176 | this.simpleStringArray = simpleStringArray; | 174 | 177 | } | | 178 | + | | 179 | + public List<String> getSimpleStringList() { | | 180 | + return simpleStringList; | | 181 | + } | | 182 | + | | 183 | + public TestEntity setSimpleStringList(List<String> simpleStringList) { | | 184 | + this.simpleStringList = simpleStringList; | | 185 | + return this; | | 186 | + } | | 187 | + | 175 | 188 | public short getSimpleShortU() { | 176 | 189 | return simpleShortU; | 177 | 190 | } | @@ -213,6 +226,7 @@ public String toString() { | 213 | 226 | ", simpleString='" + simpleString + '\'' + | 214 | 227 | ", simpleByteArray=" + Arrays.toString(simpleByteArray) + | 215 | 228 | ", simpleStringArray=" + Arrays.toString(simpleStringArray) + | | 229 | + ", simpleStringList=" + simpleStringList + | 216 | 230 | ", simpleShortU=" + simpleShortU + | 217 | 231 | ", simpleIntU=" + simpleIntU + | 218 | 232 | ", simpleLongU=" + simpleLongU + | |
Collapse file Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/main/java/io/objectbox/TestEntityCursor.java +7Lines changed: 7 additions & 0 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -52,6 +52,7 @@ public Cursor<TestEntity> createCursor(io.objectbox.Transaction tx, long cursorH | 52 | 52 | private final static int __ID_simpleString = TestEntity_.simpleString.id; | 53 | 53 | private final static int __ID_simpleByteArray = TestEntity_.simpleByteArray.id; | 54 | 54 | private final static int __ID_simpleStringArray = TestEntity_.simpleStringArray.id; | | 55 | + private final static int __ID_simpleStringList = TestEntity_.simpleStringList.id; | 55 | 56 | private final static int __ID_simpleShortU = TestEntity_.simpleShortU.id; | 56 | 57 | private final static int __ID_simpleIntU = TestEntity_.simpleIntU.id; | 57 | 58 | private final static int __ID_simpleLongU = TestEntity_.simpleLongU.id; | @@ -78,6 +79,12 @@ public final long put(TestEntity entity) { | 78 | 79 | collectStringArray(cursor, 0, PUT_FLAG_FIRST, | 79 | 80 | __id10, simpleStringArray); | 80 | 81 |
| | 82 | + java.util.List<String> simpleStringList = entity.getSimpleStringList(); | | 83 | + int __id11 = simpleStringList != null ? __ID_simpleStringList : 0; | | 84 | + | | 85 | + collectStringList(cursor, 0, 0, | | 86 | + __id11, simpleStringList); | | 87 | + | 81 | 88 | String simpleString = entity.getSimpleString(); | 82 | 89 | int __id8 = simpleString != null ? __ID_simpleString : 0; | 83 | 90 | byte[] simpleByteArray = entity.getSimpleByteArray(); | |
Collapse file Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/main/java/io/objectbox/TestEntity_.java +7-3Lines changed: 7 additions & 3 deletions | Original file line number | Diff line number | Diff line change |
|---|
@@ -80,14 +80,17 @@ public final class TestEntity_ implements EntityInfo<TestEntity> { | 80 | 80 | public final static io.objectbox.Property<TestEntity> simpleStringArray = | 81 | 81 | new io.objectbox.Property<>(__INSTANCE, 10, 11, String[].class, "simpleStringArray", false, "simpleStringArray"); | 82 | 82 |
| | 83 | + public final static io.objectbox.Property<TestEntity> simpleStringList = | | 84 | + new io.objectbox.Property<>(__INSTANCE, 11, 15, java.util.List.class, "simpleStringList"); | | 85 | + | 83 | 86 | public final static io.objectbox.Property<TestEntity> simpleShortU = | 84 | | - new io.objectbox.Property<>(__INSTANCE, 11, 12, short.class, "simpleShortU"); | | 87 | + new io.objectbox.Property<>(__INSTANCE, 12, 12, short.class, "simpleShortU"); | 85 | 88 |
| 86 | 89 | public final static io.objectbox.Property<TestEntity> simpleIntU = | 87 | | - new io.objectbox.Property<>(__INSTANCE, 12, 13, int.class, "simpleIntU"); | | 90 | + new io.objectbox.Property<>(__INSTANCE, 13, 13, int.class, "simpleIntU"); | 88 | 91 |
| 89 | 92 | public final static io.objectbox.Property<TestEntity> simpleLongU = | 90 | | - new io.objectbox.Property<>(__INSTANCE, 13, 14, long.class, "simpleLongU"); | | 93 | + new io.objectbox.Property<>(__INSTANCE, 14, 14, long.class, "simpleLongU"); | 91 | 94 |
| 92 | 95 | @SuppressWarnings("unchecked") | 93 | 96 | public final static io.objectbox.Property<TestEntity>[] __ALL_PROPERTIES = new io.objectbox.Property[]{ | @@ -102,6 +105,7 @@ public final class TestEntity_ implements EntityInfo<TestEntity> { | 102 | 105 | simpleString, | 103 | 106 | simpleByteArray, | 104 | 107 | simpleStringArray, | | 108 | + simpleStringList, | 105 | 109 | simpleShortU, | 106 | 110 | simpleIntU, | 107 | 111 | simpleLongU | |
Collapse file Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/AbstractObjectBoxTest.java +8-2Lines changed: 8 additions & 2 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 23 | 23 | import java.io.File; | 24 | 24 | import java.io.IOException; | 25 | 25 | import java.util.ArrayList; | | 26 | +import java.util.Arrays; | 26 | 27 | import java.util.List; | 27 | 28 | import java.util.Random; | 28 | 29 | import java.util.concurrent.CountDownLatch; | @@ -240,6 +241,8 @@ private void addTestEntity(ModelBuilder modelBuilder, @Nullable IndexType simple | 240 | 241 | } | 241 | 242 | entityBuilder.property("simpleByteArray", PropertyType.ByteVector).id(TestEntity_.simpleByteArray.id, ++lastUid); | 242 | 243 | entityBuilder.property("simpleStringArray", PropertyType.StringVector).id(TestEntity_.simpleStringArray.id, ++lastUid); | | 244 | + entityBuilder.property("simpleStringList", PropertyType.StringVector).id(TestEntity_.simpleStringList.id, ++lastUid) | | 245 | + .flags(PropertyFlags.NON_PRIMITIVE_TYPE); | 243 | 246 |
| 244 | 247 | // Unsigned integers. | 245 | 248 | entityBuilder.property("simpleShortU", PropertyType.Short).id(TestEntity_.simpleShortU.id, ++lastUid) | @@ -284,7 +287,9 @@ protected TestEntity createTestEntity(@Nullable String simpleString, int nr) { | 284 | 287 | entity.setSimpleFloat(200 + nr / 10f); | 285 | 288 | entity.setSimpleDouble(2000 + nr / 100f); | 286 | 289 | entity.setSimpleByteArray(new byte[]{1, 2, (byte) nr}); | 287 | | - entity.setSimpleStringArray(new String[]{simpleString}); | | 290 | + String[] stringArray = {simpleString}; | | 291 | + entity.setSimpleStringArray(stringArray); | | 292 | + entity.setSimpleStringList(Arrays.asList(stringArray)); | 288 | 293 | entity.setSimpleShortU((short) (100 + nr)); | 289 | 294 | entity.setSimpleIntU(nr); | 290 | 295 | entity.setSimpleLongU(1000 + nr); | @@ -304,9 +309,10 @@ protected void assertTestEntity(TestEntity actual, @Nullable String simpleString | 304 | 309 | assertEquals(200 + nr / 10f, actual.getSimpleFloat(), 0); | 305 | 310 | assertEquals(2000 + nr / 100f, actual.getSimpleDouble(), 0); | 306 | 311 | assertArrayEquals(new byte[]{1, 2, (byte) nr}, actual.getSimpleByteArray()); | 307 | | - // null array items are ignored, so array will be empty | | 312 | + // null array items are ignored, so array/list will be empty | 308 | 313 | String[] expectedStringArray = simpleString == null ? new String[]{} : new String[]{simpleString}; | 309 | 314 | assertArrayEquals(expectedStringArray, actual.getSimpleStringArray()); | | 315 | + assertEquals(Arrays.asList(expectedStringArray), actual.getSimpleStringList()); | 310 | 316 | assertEquals((short) (100 + nr), actual.getSimpleShortU()); | 311 | 317 | assertEquals(nr, actual.getSimpleIntU()); | 312 | 318 | assertEquals(1000 + nr, actual.getSimpleLongU()); | |
Collapse file Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/BoxStoreTest.java +1-1Lines changed: 1 addition & 1 deletion | Original file line number | Diff line number | Diff line change |
|---|
@@ -234,7 +234,7 @@ public void validate() { | 234 | 234 |
| 235 | 235 | // No limit. | 236 | 236 | long validated = store.validate(0, true); | 237 | | - assertEquals(7, validated); | | 237 | + assertEquals(8, validated); | 238 | 238 |
| 239 | 239 | // With limit. | 240 | 240 | validated = store.validate(1, true); | |
Collapse file Copy file name to clipboardExpand all lines: tests/objectbox-java-test/src/test/java/io/objectbox/BoxTest.java +12-7Lines changed: 12 additions & 7 deletions | Original file line number | Diff line number | Diff line change |
|---|
| 20 | 20 | import org.junit.Test; | 21 | 21 |
| 22 | 22 | import java.util.ArrayList; | | 23 | +import java.util.Arrays; | 23 | 24 | import java.util.Collection; | 24 | 25 | import java.util.List; | 25 | 26 | import java.util.Map; | @@ -52,41 +53,45 @@ public void testPutAndGet() { | 52 | 53 | } | 53 | 54 |
| 54 | 55 | @Test | 55 | | - public void testPutStringArray_withNull_ignoresNull() { | | 56 | + public void testPutStrings_withNull_ignoresNull() { | 56 | 57 | final String[] stringArray = new String[]{"sunrise", null, "sunset"}; | 57 | 58 | final String[] expectedStringArray = new String[]{"sunrise", "sunset"}; | 58 | 59 |
| 59 | 60 | TestEntity entity = new TestEntity(); | 60 | 61 | entity.setSimpleStringArray(stringArray); | | 62 | + entity.setSimpleStringList(Arrays.asList(stringArray)); | 61 | 63 | box.put(entity); | 62 | 64 |
| 63 | 65 | TestEntity entityRead = box.get(entity.getId()); | 64 | 66 | assertNotNull(entityRead); | 65 | 67 | assertArrayEquals(expectedStringArray, entityRead.getSimpleStringArray()); | | 68 | + assertEquals(Arrays.asList(expectedStringArray), entityRead.getSimpleStringList()); | 66 | 69 | } | 67 | 70 |
| 68 | 71 | @Test | 69 | | - public void testPutStringArray_onlyNull_isEmpty() { | 70 | | - final String[] stringArray = new String[]{null}; | 71 | | - final String[] expectedStringArray = new String[]{}; | 72 | | - | | 72 | + public void testPutStrings_onlyNull_isEmpty() { | 73 | 73 | TestEntity entity = new TestEntity(); | | 74 | + final String[] stringArray = new String[]{null}; | 74 | 75 | entity.setSimpleStringArray(stringArray); | | 76 | + entity.setSimpleStringList(Arrays.asList(stringArray)); | 75 | 77 | box.put(entity); | 76 | 78 |
| 77 | 79 | TestEntity entityRead = box.get(entity.getId()); | 78 | 80 | assertNotNull(entityRead); | 79 | | - assertArrayEquals(expectedStringArray, entityRead.getSimpleStringArray()); | | 81 | + assertArrayEquals(new String[]{}, entityRead.getSimpleStringArray()); | | 82 | + assertEquals(new ArrayList<>(), entityRead.getSimpleStringList()); | 80 | 83 | } | 81 | 84 |
| 82 | 85 | @Test | 83 | | - public void testPutStringArray_null_isNull() { | | 86 | + public void testPutStrings_null_isNull() { | | 87 | + // Null String array and list. | 84 | 88 | TestEntity entity = new TestEntity(); | 85 | 89 | box.put(entity); | 86 | 90 |
| 87 | 91 | TestEntity entityRead = box.get(entity.getId()); | 88 | 92 | assertNotNull(entityRead); | 89 | 93 | assertNull(entityRead.getSimpleStringArray()); | | 94 | + assertNull(entityRead.getSimpleStringList()); | 90 | 95 | } | 91 | 96 |
| 92 | 97 | @Test | |
|