Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 12 additions & 7 deletions nitrite/src/main/java/org/dizitart/no2/Nitrite.java
Original file line number Diff line number Diff line change
Expand Up @@ -312,9 +312,11 @@ default <T> boolean hasRepository(Class<T> type) {
*/
default <T> boolean hasRepository(Class<T> type, String key) {
checkOpened();
Map<String, Set<String>> keyed = listKeyedRepositories();
Set<String> entities = keyed.get(key);
if (entities == null) return false;
String entityName = ObjectUtils.getEntityName(type);
return listKeyedRepositories().containsKey(key)
&& listKeyedRepositories().get(key).contains(entityName);
return entities.contains(entityName);
}

/**
Expand Down Expand Up @@ -343,8 +345,10 @@ default <T> boolean hasRepository(EntityDecorator<T> entityDecorator) {
*/
default <T> boolean hasRepository(EntityDecorator<T> entityDecorator, String key) {
checkOpened();
return listKeyedRepositories().containsKey(key)
&& listKeyedRepositories().get(key).contains(entityDecorator.getEntityName());
Map<String, Set<String>> keyed = listKeyedRepositories();
Set<String> entities = keyed.get(key);
if (entities == null) return false;
return entities.contains(entityDecorator.getEntityName());
}

/**
Expand All @@ -355,11 +359,12 @@ default <T> boolean hasRepository(EntityDecorator<T> entityDecorator, String key
* reserved names
*/
default void validateCollectionName(String name) {
notNull(name, "name cannot be null");
notEmpty(name, "name cannot be empty");
notNull(name, "name cannot be null");
String normalized = name.trim();
notEmpty(normalized, "name cannot be empty");

for (String reservedName : RESERVED_NAMES) {
if (name.contains(reservedName)) {
if (normalized.contains(reservedName)) {
throw new ValidationException("Name cannot contain " + reservedName);
}
}
Expand Down
Loading