CompositeKeyFactory implements KeyFactory { @Override public Set<Key> createMultivalueKeys(IndexableItem indexableItem) throws JasDBStorageException { KeyNameMapper nameMapper = multiKeyloader.getKeyNameMapper(); Set<Key> currentKeys = new HashSet<>(); currentKeys.add(new CompositeKey()); for(KeyFactory keyFactory : multiKeyloader.getKeyFactories()) { Set<Key> subKeys = keyFactory.createMultivalueKeys(indexableItem); Set<Key> productSet = new HashSet<>(); for(Key currentKey : currentKeys) { for(Key subKey : subKeys) { Key key = currentKey.cloneKey(true); key.addKey(nameMapper, keyFactory.getFieldName(), subKey.cloneKey(false)); productSet.add(key); } } currentKeys = productSet; } return currentKeys; } CompositeKeyFactory(MultiKeyloader multiKeyloader); @Override Key loadKey(int curPosition, ByteBuffer byteBuffer); @Override void writeKey(Key key, int curPosition, ByteBuffer byteBuffer); @Override Key createKey(IndexableItem indexableItem); @Override Key createEmptyKey(); @Override KeyLoadResult loadKey(int offset, DataBlock dataBlock); @Override DataBlock writeKey(Key key, DataBlock dataBlock); @Override Set<Key> createMultivalueKeys(IndexableItem indexableItem); @Override boolean isMultiValueKey(IndexableItem indexableItem); @Override Key convertKey(Key key); MultiKeyloader getMultiKeyloader(); @Override boolean supportsKey(Key key); @Override String asHeader(); @Override KeyType getKeyType(); @Override int getKeySize(); @Override int getMemorySize(); @Override String getKeyId(); @Override String getFieldName();  }
@Test public void testCreateMultiValueKeys() throws JasDBStorageException { KeyNameMapper nameMapper = new KeyNameMapperImpl(); nameMapper.addMappedField("city"); nameMapper.addMappedField("__ID"); nameMapper.setValueMarker(2); KeyFactory cityKeyFactory = new StringKeyFactory("city", "1000"); KeyFactory idKeyFactory = new UUIDKeyFactory("__ID"); MultiKeyloader multiKeyloader = new MultiKeyLoaderImpl(nameMapper, new KeyFactory[]{cityKeyFactory, idKeyFactory}); CompositeKeyFactory compositeKeyFactory = new CompositeKeyFactory(multiKeyloader); String randomId = UUID.randomUUID().toString(); Map<String, List<String>> properties = Maps.newHashMap(); properties.put("city", Lists.newArrayList("Amsterdam", "Rotterdam")); properties.put("__ID", Lists.newArrayList(randomId)); Set<Key> keys = compositeKeyFactory.createMultivalueKeys(new MockedIndexableItem(properties)); assertEquals(2, keys.size()); Key expectedCompositeKey1 = new CompositeKey(); expectedCompositeKey1.addKey(nameMapper, "city", new StringKey("Amsterdam")); expectedCompositeKey1.addKey(nameMapper, "__ID", new UUIDKey(randomId)); Key expectedCompositeKey2 = new CompositeKey(); expectedCompositeKey2.addKey(nameMapper, "city", new StringKey("Rotterdam")); expectedCompositeKey2.addKey(nameMapper, "__ID", new UUIDKey(randomId)); assertThat(keys, hasItems(expectedCompositeKey1, expectedCompositeKey2)); }