@Test public void testPathWrapperExample() throws Exception { EnvironmentKeySpace keySpace = new EnvironmentKeySpace("production"); final FDBDatabase database = FDBDatabaseFactory.instance().getDatabase(); final Tuple dataStoreTuple; final Tuple metadataStoreTuple; try (FDBRecordContext context = database.openContext()) { ApplicationPath application = keySpace.root().userid(123).application("myApplication"); dataStoreTuple = application.dataStore().toTuple(context); metadataStoreTuple = application.metadataStore().toTuple(context); context.commit(); } try (FDBRecordContext context = database.openContext()) { List<Long> entries = resolveBatch(context, keySpace.getRootName(), "myApplication"); assertEquals(Tuple.from(entries.get(0), 123L, entries.get(1), EnvironmentKeySpace.DATA_VALUE), dataStoreTuple); assertEquals(Tuple.from(entries.get(0), 123L, entries.get(1), EnvironmentKeySpace.METADATA_VALUE), metadataStoreTuple); ResolvedKeySpacePath path = keySpace.fromKey(context, dataStoreTuple); assertThat(path.toPath(), instanceOf(DataPath.class)); DataPath mainStorePath = (DataPath) path.toPath(); assertEquals(EnvironmentKeySpace.DATA_VALUE, mainStorePath.getValue()); assertEquals(EnvironmentKeySpace.DATA_VALUE, mainStorePath.resolveAsync(context).get().getResolvedValue()); assertEquals(entries.get(1), mainStorePath.parent().resolveAsync(context).get().getResolvedValue()); assertEquals("myApplication", mainStorePath.parent().getValue()); assertEquals(123L, mainStorePath.parent().parent().getValue()); assertEquals(entries.get(0), mainStorePath.parent().parent().parent().resolveAsync(context).get().getResolvedValue()); assertEquals("production", mainStorePath.parent().parent().parent().getValue()); assertEquals(null, mainStorePath.parent().parent().parent().parent()); assertThat(keySpace.fromKey(context, TupleHelpers.subTuple(dataStoreTuple, 0, 1)).toPath(), instanceOf(EnvironmentRoot.class)); assertThat(keySpace.fromKey(context, TupleHelpers.subTuple(dataStoreTuple, 0, 2)).toPath(), instanceOf(UserPath.class)); assertThat(keySpace.fromKey(context, TupleHelpers.subTuple(dataStoreTuple, 0, 3)).toPath(), instanceOf(ApplicationPath.class)); path = keySpace.fromKey(context, metadataStoreTuple); assertThat(path.toPath(), instanceOf(MetadataPath.class)); MetadataPath metadataPath = (MetadataPath) path.toPath(); assertEquals(EnvironmentKeySpace.METADATA_VALUE, metadataPath.getValue()); assertEquals(EnvironmentKeySpace.METADATA_VALUE, metadataPath.resolveAsync(context).get().getResolvedValue()); assertEquals(entries.get(1), metadataPath.parent().resolveAsync(context).get().getResolvedValue()); assertEquals("myApplication", metadataPath.parent().getValue()); assertEquals(123L, metadataPath.parent().parent().getValue()); assertEquals(entries.get(0), metadataPath.parent().parent().parent().resolveAsync(context).get().getResolvedValue()); assertEquals("production", metadataPath.parent().parent().parent().getValue()); assertEquals(null, metadataPath.parent().parent().parent().parent()); assertThat(keySpace.fromKey(context, TupleHelpers.subTuple(dataStoreTuple, 0, 1)).toPath(), instanceOf(EnvironmentRoot.class)); assertThat(keySpace.fromKey(context, TupleHelpers.subTuple(dataStoreTuple, 0, 2)).toPath(), instanceOf(UserPath.class)); assertThat(keySpace.fromKey(context, TupleHelpers.subTuple(dataStoreTuple, 0, 3)).toPath(), instanceOf(ApplicationPath.class)); Tuple recordTuple = dataStoreTuple.add(1L).add("someStr").add(0L); path = keySpace.fromKey(context, recordTuple); assertThat(path.toPath(), instanceOf(DataPath.class)); assertEquals(Tuple.from(1L, "someStr", 0L), path.getRemainder()); assertEquals(dataStoreTuple, path.toTuple()); } }
@Nullable public Object getValue() { return value; }
KeySpaceDirectory { @Nullable public Object getValue() { return value; } }
KeySpaceDirectory { @Nullable public Object getValue() { return value; } KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullable Object value,
                             @Nullable Function<KeySpacePath, KeySpacePath> wrapper);  KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullable Function<KeySpacePath, KeySpacePath> wrapper);  KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType);  KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullable Object value); }
KeySpaceDirectory { @Nullable public Object getValue() { return value; } KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullable Object value,
                             @Nullable Function<KeySpacePath, KeySpacePath> wrapper);  KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullable Function<KeySpacePath, KeySpacePath> wrapper);  KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType);  KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullable Object value); int depth(); @Nonnull CompletableFuture<ResolvedKeySpacePath> findChildForValue(@Nonnull FDBRecordContext context,
                                                                     @Nullable ResolvedKeySpacePath parent,
                                                                     @Nullable Object value); @Nonnull KeySpaceDirectory addSubdirectory(@Nonnull KeySpaceDirectory subdirectory); boolean isLeaf(); @Nonnull KeySpaceDirectory getSubdirectory(@Nonnull String name); @Nonnull List<KeySpaceDirectory> getSubdirectories(); @Nullable KeySpaceDirectory getParent(); @Nonnull String getName(); @Nonnull String getNameInTree(); @Nonnull KeyType getKeyType(); @Nullable Object getValue(); String toPathString(); @Override String toString(); void toTree(Writer out); }
KeySpaceDirectory { @Nullable public Object getValue() { return value; } KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullable Object value,
                             @Nullable Function<KeySpacePath, KeySpacePath> wrapper);  KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullable Function<KeySpacePath, KeySpacePath> wrapper);  KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType);  KeySpaceDirectory(@Nonnull String name, @Nonnull KeyType keyType, @Nullable Object value); int depth(); @Nonnull CompletableFuture<ResolvedKeySpacePath> findChildForValue(@Nonnull FDBRecordContext context,
                                                                     @Nullable ResolvedKeySpacePath parent,
                                                                     @Nullable Object value); @Nonnull KeySpaceDirectory addSubdirectory(@Nonnull KeySpaceDirectory subdirectory); boolean isLeaf(); @Nonnull KeySpaceDirectory getSubdirectory(@Nonnull String name); @Nonnull List<KeySpaceDirectory> getSubdirectories(); @Nullable KeySpaceDirectory getParent(); @Nonnull String getName(); @Nonnull String getNameInTree(); @Nonnull KeyType getKeyType(); @Nullable Object getValue(); String toPathString(); @Override String toString(); void toTree(Writer out); static final Object ANY_VALUE; }