@Test public void testInvalidPath() throws Exception { KeySpace root = new KeySpace( new KeySpaceDirectory("root", KeyType.STRING, "production") .addSubdirectory(new KeySpaceDirectory("a", KeyType.STRING) .addSubdirectory(new KeySpaceDirectory("b", KeyType.STRING)))); final FDBDatabase database = FDBDatabaseFactory.instance().getDatabase(); try (FDBRecordContext context = database.openContext()) { Tuple tuple = root.path("root") .add("a", "foo") .add("b", "bar").toTuple(context); assertEquals(Tuple.from("production", "foo", "bar"), tuple); assertThrows(NoSuchDirectoryException.class, () -> root.path("foo").add("a", "bar").toTuple(context)); } }
@Nonnull public KeySpaceDirectory addSubdirectory(@Nonnull KeySpaceDirectory subdirectory) { for (KeySpaceDirectory existingSubdir : subdirsByName.values()) { if (existingSubdir.getName().equals(subdirectory.getName())) { throw new RecordCoreArgumentException("Subdirectory already exists", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, subdirectory.getName()); } if (existingSubdir.getKeyType() == subdirectory.getKeyType()) { if (existingSubdir.getValue() == ANY_VALUE || subdirectory.getValue() == ANY_VALUE) { throw new RecordCoreArgumentException("Cannot add directory due to overlapping type", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, existingSubdir.getName(), LogMessageKeys.DIR_TYPE, subdirectory.getKeyType()); } if (Objects.equals(subdirectory.getValue(), existingSubdir.getValue())) { throw new RecordCoreArgumentException("Cannot add directory due to overlapping constant value", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, existingSubdir.getName(), LogMessageKeys.DIR_TYPE, existingSubdir.getKeyType(), LogMessageKeys.DIR_VALUE, existingSubdir.getValue()); } if (!existingSubdir.isCompatible(this, subdirectory) || !subdirectory.isCompatible(this, existingSubdir)) { throw new RecordCoreArgumentException("Cannot add directory due to incompatibility with existing subdirectory", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_TYPE, existingSubdir.getKeyType(), LogMessageKeys.DIR_VALUE, existingSubdir.getValue()); } } } subdirectory.setParent(this); subdirsByName.put(subdirectory.getName(), subdirectory); subdirs.add(subdirectory); return this; }
KeySpaceDirectory { @Nonnull public KeySpaceDirectory addSubdirectory(@Nonnull KeySpaceDirectory subdirectory) { for (KeySpaceDirectory existingSubdir : subdirsByName.values()) { if (existingSubdir.getName().equals(subdirectory.getName())) { throw new RecordCoreArgumentException("Subdirectory already exists", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, subdirectory.getName()); } if (existingSubdir.getKeyType() == subdirectory.getKeyType()) { if (existingSubdir.getValue() == ANY_VALUE || subdirectory.getValue() == ANY_VALUE) { throw new RecordCoreArgumentException("Cannot add directory due to overlapping type", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, existingSubdir.getName(), LogMessageKeys.DIR_TYPE, subdirectory.getKeyType()); } if (Objects.equals(subdirectory.getValue(), existingSubdir.getValue())) { throw new RecordCoreArgumentException("Cannot add directory due to overlapping constant value", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, existingSubdir.getName(), LogMessageKeys.DIR_TYPE, existingSubdir.getKeyType(), LogMessageKeys.DIR_VALUE, existingSubdir.getValue()); } if (!existingSubdir.isCompatible(this, subdirectory) || !subdirectory.isCompatible(this, existingSubdir)) { throw new RecordCoreArgumentException("Cannot add directory due to incompatibility with existing subdirectory", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_TYPE, existingSubdir.getKeyType(), LogMessageKeys.DIR_VALUE, existingSubdir.getValue()); } } } subdirectory.setParent(this); subdirsByName.put(subdirectory.getName(), subdirectory); subdirs.add(subdirectory); return this; } }
KeySpaceDirectory { @Nonnull public KeySpaceDirectory addSubdirectory(@Nonnull KeySpaceDirectory subdirectory) { for (KeySpaceDirectory existingSubdir : subdirsByName.values()) { if (existingSubdir.getName().equals(subdirectory.getName())) { throw new RecordCoreArgumentException("Subdirectory already exists", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, subdirectory.getName()); } if (existingSubdir.getKeyType() == subdirectory.getKeyType()) { if (existingSubdir.getValue() == ANY_VALUE || subdirectory.getValue() == ANY_VALUE) { throw new RecordCoreArgumentException("Cannot add directory due to overlapping type", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, existingSubdir.getName(), LogMessageKeys.DIR_TYPE, subdirectory.getKeyType()); } if (Objects.equals(subdirectory.getValue(), existingSubdir.getValue())) { throw new RecordCoreArgumentException("Cannot add directory due to overlapping constant value", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, existingSubdir.getName(), LogMessageKeys.DIR_TYPE, existingSubdir.getKeyType(), LogMessageKeys.DIR_VALUE, existingSubdir.getValue()); } if (!existingSubdir.isCompatible(this, subdirectory) || !subdirectory.isCompatible(this, existingSubdir)) { throw new RecordCoreArgumentException("Cannot add directory due to incompatibility with existing subdirectory", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_TYPE, existingSubdir.getKeyType(), LogMessageKeys.DIR_VALUE, existingSubdir.getValue()); } } } subdirectory.setParent(this); subdirsByName.put(subdirectory.getName(), subdirectory); subdirs.add(subdirectory); return this; } 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 { @Nonnull public KeySpaceDirectory addSubdirectory(@Nonnull KeySpaceDirectory subdirectory) { for (KeySpaceDirectory existingSubdir : subdirsByName.values()) { if (existingSubdir.getName().equals(subdirectory.getName())) { throw new RecordCoreArgumentException("Subdirectory already exists", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, subdirectory.getName()); } if (existingSubdir.getKeyType() == subdirectory.getKeyType()) { if (existingSubdir.getValue() == ANY_VALUE || subdirectory.getValue() == ANY_VALUE) { throw new RecordCoreArgumentException("Cannot add directory due to overlapping type", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, existingSubdir.getName(), LogMessageKeys.DIR_TYPE, subdirectory.getKeyType()); } if (Objects.equals(subdirectory.getValue(), existingSubdir.getValue())) { throw new RecordCoreArgumentException("Cannot add directory due to overlapping constant value", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, existingSubdir.getName(), LogMessageKeys.DIR_TYPE, existingSubdir.getKeyType(), LogMessageKeys.DIR_VALUE, existingSubdir.getValue()); } if (!existingSubdir.isCompatible(this, subdirectory) || !subdirectory.isCompatible(this, existingSubdir)) { throw new RecordCoreArgumentException("Cannot add directory due to incompatibility with existing subdirectory", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_TYPE, existingSubdir.getKeyType(), LogMessageKeys.DIR_VALUE, existingSubdir.getValue()); } } } subdirectory.setParent(this); subdirsByName.put(subdirectory.getName(), subdirectory); subdirs.add(subdirectory); return this; } 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 { @Nonnull public KeySpaceDirectory addSubdirectory(@Nonnull KeySpaceDirectory subdirectory) { for (KeySpaceDirectory existingSubdir : subdirsByName.values()) { if (existingSubdir.getName().equals(subdirectory.getName())) { throw new RecordCoreArgumentException("Subdirectory already exists", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, subdirectory.getName()); } if (existingSubdir.getKeyType() == subdirectory.getKeyType()) { if (existingSubdir.getValue() == ANY_VALUE || subdirectory.getValue() == ANY_VALUE) { throw new RecordCoreArgumentException("Cannot add directory due to overlapping type", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, existingSubdir.getName(), LogMessageKeys.DIR_TYPE, subdirectory.getKeyType()); } if (Objects.equals(subdirectory.getValue(), existingSubdir.getValue())) { throw new RecordCoreArgumentException("Cannot add directory due to overlapping constant value", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_NAME, existingSubdir.getName(), LogMessageKeys.DIR_TYPE, existingSubdir.getKeyType(), LogMessageKeys.DIR_VALUE, existingSubdir.getValue()); } if (!existingSubdir.isCompatible(this, subdirectory) || !subdirectory.isCompatible(this, existingSubdir)) { throw new RecordCoreArgumentException("Cannot add directory due to incompatibility with existing subdirectory", LogMessageKeys.PARENT_DIR, getName(), LogMessageKeys.DIR_TYPE, existingSubdir.getKeyType(), LogMessageKeys.DIR_VALUE, existingSubdir.getValue()); } } } subdirectory.setParent(this); subdirsByName.put(subdirectory.getName(), subdirectory); subdirs.add(subdirectory); return this; } 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; }