1616
1717package io .objectbox ;
1818
19+ import io .objectbox .annotation .IndexType ;
1920import org .junit .After ;
2021import org .junit .Before ;
2122
@@ -101,25 +102,25 @@ protected File prepareTempDir(String prefix) throws IOException {
101102 }
102103
103104 protected BoxStore createBoxStore () {
104- return createBoxStore (false );
105+ return createBoxStore (null );
105106 }
106107
107- protected BoxStore createBoxStore (boolean withIndex ) {
108- return createBoxStoreBuilder (withIndex ).build ();
108+ protected BoxStore createBoxStore (@ Nullable IndexType simpleStringIndexType ) {
109+ return createBoxStoreBuilder (simpleStringIndexType ).build ();
109110 }
110111
111- protected BoxStoreBuilder createBoxStoreBuilderWithTwoEntities ( boolean withIndex ) {
112- BoxStoreBuilder builder = new BoxStoreBuilder (createTestModelWithTwoEntities ( withIndex )).directory (boxStoreDir );
112+ protected BoxStoreBuilder createBoxStoreBuilder ( @ Nullable IndexType simpleStringIndexType ) {
113+ BoxStoreBuilder builder = new BoxStoreBuilder (createTestModel ( simpleStringIndexType )).directory (boxStoreDir );
113114 if (DEBUG_LOG ) builder .debugFlags (DebugFlags .LOG_TRANSACTIONS_READ | DebugFlags .LOG_TRANSACTIONS_WRITE );
114115 builder .entity (new TestEntity_ ());
115- builder .entity (new TestEntityMinimal_ ());
116116 return builder ;
117117 }
118118
119- protected BoxStoreBuilder createBoxStoreBuilder (boolean withIndex ) {
120- BoxStoreBuilder builder = new BoxStoreBuilder (createTestModel (withIndex )).directory (boxStoreDir );
119+ protected BoxStoreBuilder createBoxStoreBuilderWithTwoEntities (boolean withIndex ) {
120+ BoxStoreBuilder builder = new BoxStoreBuilder (createTestModelWithTwoEntities (withIndex )).directory (boxStoreDir );
121121 if (DEBUG_LOG ) builder .debugFlags (DebugFlags .LOG_TRANSACTIONS_READ | DebugFlags .LOG_TRANSACTIONS_WRITE );
122122 builder .entity (new TestEntity_ ());
123+ builder .entity (new TestEntityMinimal_ ());
123124 return builder ;
124125 }
125126
@@ -189,24 +190,24 @@ protected long time() {
189190 return System .currentTimeMillis ();
190191 }
191192
192- protected byte [] createTestModel (boolean withIndex ) {
193+ protected byte [] createTestModel (@ Nullable IndexType simpleStringIndexType ) {
193194 ModelBuilder modelBuilder = new ModelBuilder ();
194- addTestEntity (modelBuilder , withIndex );
195+ addTestEntity (modelBuilder , simpleStringIndexType );
195196 modelBuilder .lastEntityId (lastEntityId , lastEntityUid );
196197 modelBuilder .lastIndexId (lastIndexId , lastIndexUid );
197198 return modelBuilder .build ();
198199 }
199200
200201 byte [] createTestModelWithTwoEntities (boolean withIndex ) {
201202 ModelBuilder modelBuilder = new ModelBuilder ();
202- addTestEntity (modelBuilder , withIndex );
203+ addTestEntity (modelBuilder , withIndex ? IndexType . DEFAULT : null );
203204 addTestEntityMinimal (modelBuilder , withIndex );
204205 modelBuilder .lastEntityId (lastEntityId , lastEntityUid );
205206 modelBuilder .lastIndexId (lastIndexId , lastIndexUid );
206207 return modelBuilder .build ();
207208 }
208209
209- private void addTestEntity (ModelBuilder modelBuilder , boolean withIndex ) {
210+ private void addTestEntity (ModelBuilder modelBuilder , @ Nullable IndexType simpleStringIndexType ) {
210211 lastEntityUid = ++lastUid ;
211212 EntityBuilder entityBuilder = modelBuilder .entity ("TestEntity" ).id (++lastEntityId , lastEntityUid );
212213 entityBuilder .property ("id" , PropertyType .Long ).id (TestEntity_ .id .id , ++lastUid )
@@ -220,9 +221,19 @@ private void addTestEntity(ModelBuilder modelBuilder, boolean withIndex) {
220221 entityBuilder .property ("simpleDouble" , PropertyType .Double ).id (TestEntity_ .simpleDouble .id , ++lastUid );
221222 PropertyBuilder pb =
222223 entityBuilder .property ("simpleString" , PropertyType .String ).id (TestEntity_ .simpleString .id , ++lastUid );
223- if (withIndex ) {
224+ if (simpleStringIndexType != null ) {
224225 lastIndexUid = ++lastUid ;
225- pb .flags (PropertyFlags .INDEXED ).indexId (++lastIndexId , lastIndexUid );
226+ // Since 2.0: default for Strings has changed from INDEXED to INDEX_HASH.
227+ int indexFlag ;
228+ if (simpleStringIndexType == IndexType .VALUE ) {
229+ indexFlag = PropertyFlags .INDEXED ;
230+ } else if (simpleStringIndexType == IndexType .HASH64 ) {
231+ indexFlag = PropertyFlags .INDEX_HASH64 ;
232+ } else {
233+ indexFlag = PropertyFlags .INDEX_HASH ;
234+ }
235+ log (String .format ("Using %s index on TestEntity.simpleString" , simpleStringIndexType ));
236+ pb .flags (indexFlag ).indexId (++lastIndexId , lastIndexUid );
226237 }
227238 entityBuilder .property ("simpleByteArray" , PropertyType .ByteVector ).id (TestEntity_ .simpleByteArray .id , ++lastUid );
228239 entityBuilder .property ("simpleStringArray" , PropertyType .StringVector ).id (TestEntity_ .simpleStringArray .id , ++lastUid );
0 commit comments