https://github.com/mewebstudio/spring-boot-jpa-nested-set-kotlin
Spring Boot JPA Nested Set Kotlin - Maven package
https://github.com/mewebstudio/spring-boot-jpa-nested-set-kotlin
hibernate jpa kotlin maven nestedset spring-boot
Last synced: 5 months ago
JSON representation
Spring Boot JPA Nested Set Kotlin - Maven package
- Host: GitHub
- URL: https://github.com/mewebstudio/spring-boot-jpa-nested-set-kotlin
- Owner: mewebstudio
- License: mit
- Created: 2025-05-06T16:07:32.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2025-05-06T18:25:33.000Z (about 1 year ago)
- Last Synced: 2025-07-01T09:06:49.047Z (12 months ago)
- Topics: hibernate, jpa, kotlin, maven, nestedset, spring-boot
- Language: Kotlin
- Homepage:
- Size: 15.6 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Nested Set Tree Utilities for Spring Boot JPA (Kotlin Implementation)
[](https://opensource.org/licenses/MIT)
[](https://central.sonatype.com/artifact/com.mewebstudio/spring-boot-jpa-nested-set-kotlin)
[](https://javadoc.io/doc/com.mewebstudio/spring-boot-jpa-nested-set-kotlin)
This package provides a generic and reusable implementation of the [Nested Set Model](https://en.wikipedia.org/wiki/Nested_set_model) for managing hierarchical data using Spring Boot and JPA.
It is designed to be extended and adapted for any entity that implements the `INestedSetNode>` interface.
---
## 📦 Package Overview
**Package:** `com.mewebstudio.springboot.jpa.nestedset.kotlin`
### Core Components
- **`INestedSetNode>`**
Interface that defines the structure of a nested set node (left, right, parent).
- **`INestedSetNodeResponse`**
Interface for representing nodes with children, used for building hierarchical responses.
- **`JpaNestedSetRepository, ID> : JpaRepository`**
Base JPA repository interface with custom queries for nested set operations (e.g. find ancestors, descendants, siblings).
- **`AbstractNestedSetService, ID>`**
Abstract service class that implements common logic for creating, moving, and restructuring nodes in a nested set tree.
---
## ✅ Features
- Create new nodes in the correct position in the nested set.
- Move nodes up or down among siblings.
- Retrieve ancestors and descendants of a node.
- Rebuild the entire tree from an unordered list of nodes.
- Shift and close gaps in the tree on node deletion.
- Generic and type-safe structure, reusable across multiple domain entities.
---
## 📥 Installation
#### for maven users
Add the following dependency to your `pom.xml` file:
```xml
com.mewebstudio
spring-boot-jpa-nested-set-kotlin
0.1.5
```
#### for gradle users
Add the following dependency to your `build.gradle` file:
```groovy
implementation 'com.mewebstudio:spring-boot-jpa-nested-set-kotlin:0.1.5'
```
## 🚀 Usage
### 1. Example entity class `INestedSetNode>`
```kotlin
@Entity
class Category(
// implement getId, getLeft, getRight, getParent, etc.
) : AbstractBaseEntity(), INestedSetNode
```
### 2. Example repository interface `JpaNestedSetRepository, ID> : JpaRepository`
```kotlin
interface CategoryRepository : JpaNestedSetRepository
```
### 3. Example service class `AbstractNestedSetService, ID>`
```kotlin
@Service
class CategoryService(
private val categoryRepository: CategoryRepository
) : AbstractNestedSetService(categoryRepository) {
// Implement additional service methods as needed
}
```
## 🔁 Other Implementations
[Spring Boot JPA Nested Set (Java Maven Package)](https://github.com/mewebstudio/spring-boot-jpa-nested-set)
## 💡 Example Implementations
[Spring Boot JPA Nested Set - Kotlin Implementation](https://github.com/mewebstudio/spring-boot-jpa-nested-set-kotlin-impl)
[Spring Boot JPA Nested Set - Java Implementation](https://github.com/mewebstudio/spring-boot-jpa-nested-set-java-impl)