-
Notifications
You must be signed in to change notification settings - Fork 35
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add soft delete configuration (#141)
- Loading branch information
1 parent
1d64049
commit bfc1a91
Showing
34 changed files
with
2,480 additions
and
145 deletions.
There are no files selected for viewing
29 changes: 29 additions & 0 deletions
29
...ava/com/navercorp/spring/data/jdbc/plus/repository/guide/article/BooleanStateArticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.navercorp.spring.data.jdbc.plus.repository.guide.article; | ||
|
||
import java.time.Instant; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import com.navercorp.spring.jdbc.plus.commons.annotations.SoftDeleteColumn; | ||
|
||
@Table("boolean_state_articles") | ||
@Getter | ||
@Builder(toBuilder = true) | ||
@AllArgsConstructor | ||
public class BooleanStateArticle { | ||
|
||
@Id | ||
private final Long id; | ||
private final String writerId; | ||
private final String contents; | ||
private final Instant createdAt; | ||
private final Instant lastModifiedAt; | ||
|
||
@SoftDeleteColumn.Boolean(valueAsDeleted = "false") | ||
private final boolean visible; | ||
} |
28 changes: 28 additions & 0 deletions
28
...vercorp/spring/data/jdbc/plus/repository/guide/article/BooleanStateArticleRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Spring JDBC Plus | ||
* | ||
* Copyright 2020-2024 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.spring.data.jdbc.plus.repository.guide.article; | ||
|
||
import com.navercorp.spring.data.jdbc.plus.repository.JdbcRepository; | ||
import com.navercorp.spring.data.jdbc.plus.repository.guide.order.Order; | ||
|
||
/** | ||
* @author Chanhyeong Cho | ||
*/ | ||
public interface BooleanStateArticleRepository extends JdbcRepository<BooleanStateArticle, Long> { | ||
} |
50 changes: 50 additions & 0 deletions
50
...n/java/com/navercorp/spring/data/jdbc/plus/repository/guide/article/EnumStateArticle.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
package com.navercorp.spring.data.jdbc.plus.repository.guide.article; | ||
|
||
import java.time.Instant; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.annotation.Version; | ||
import org.springframework.data.relational.core.mapping.Column; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import com.navercorp.spring.jdbc.plus.commons.annotations.SoftDeleteColumn; | ||
|
||
@Table("enum_state_articles") | ||
@Getter | ||
@Builder(toBuilder = true) | ||
@AllArgsConstructor | ||
public class EnumStateArticle { | ||
|
||
@Id | ||
private final Long id; | ||
private final String writerId; | ||
private final String contents; | ||
private final Instant createdAt; | ||
private final Instant lastModifiedAt; | ||
|
||
@Version | ||
private final int version; | ||
|
||
@SoftDeleteColumn.String(valueAsDeleted = "CLOSE") | ||
@Column("article_state") | ||
private final State state; | ||
|
||
public boolean closed() { | ||
return state == State.CLOSE; | ||
} | ||
|
||
@Getter | ||
public enum State { | ||
OPEN("op"), CLOSE("cl"); | ||
|
||
private final String code; | ||
|
||
State(String code) { | ||
this.code = code; | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
.../navercorp/spring/data/jdbc/plus/repository/guide/article/EnumStateArticleRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Spring JDBC Plus | ||
* | ||
* Copyright 2020-2024 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.spring.data.jdbc.plus.repository.guide.article; | ||
|
||
import com.navercorp.spring.data.jdbc.plus.repository.JdbcRepository; | ||
|
||
/** | ||
* @author Chanhyeong Cho | ||
*/ | ||
public interface EnumStateArticleRepository extends JdbcRepository<EnumStateArticle, Long> { | ||
} |
44 changes: 44 additions & 0 deletions
44
...n/java/com/navercorp/spring/data/jdbc/plus/repository/guide/config/JdbcConfiguration.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package com.navercorp.spring.data.jdbc.plus.repository.guide.config; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.convert.converter.Converter; | ||
import org.springframework.data.convert.ReadingConverter; | ||
import org.springframework.data.convert.WritingConverter; | ||
|
||
import com.navercorp.spring.data.jdbc.plus.repository.config.AbstractJdbcPlusConfiguration; | ||
import com.navercorp.spring.data.jdbc.plus.repository.guide.article.EnumStateArticle; | ||
import com.navercorp.spring.data.jdbc.plus.repository.guide.article.EnumStateArticle.State; | ||
|
||
@Configuration | ||
public class JdbcConfiguration extends AbstractJdbcPlusConfiguration { | ||
|
||
@Override | ||
protected List<?> userConverters() { | ||
return List.of( | ||
new ArticleStateReadingConverter(), | ||
new ArticleStateWritingConverter() | ||
); | ||
} | ||
|
||
@WritingConverter | ||
private static class ArticleStateWritingConverter implements Converter<EnumStateArticle.State, String> { | ||
@Override | ||
public String convert(EnumStateArticle.State source) { | ||
return source.getCode(); | ||
} | ||
} | ||
|
||
@ReadingConverter | ||
private static class ArticleStateReadingConverter implements Converter<String, EnumStateArticle.State> { | ||
@Override | ||
public State convert(String source) { | ||
return Arrays.stream(EnumStateArticle.State.values()) | ||
.filter(it -> it.getCode().equals(source)) | ||
.findFirst() | ||
.orElse(null); | ||
} | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../main/java/com/navercorp/spring/data/jdbc/plus/repository/guide/product/PlainProduct.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.navercorp.spring.data.jdbc.plus.repository.guide.product; | ||
|
||
import java.time.Instant; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Table("plain_products") | ||
@Getter | ||
@Builder(toBuilder = true) | ||
@AllArgsConstructor | ||
public class PlainProduct { | ||
|
||
@Id | ||
private final Long id; | ||
private final String productName; | ||
private final Instant createdAt; | ||
private final Instant lastModifiedAt; | ||
} |
28 changes: 28 additions & 0 deletions
28
...corp/spring/data/jdbc/plus/repository/guide/product/PlainProductWithSoftDeleteReview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.navercorp.spring.data.jdbc.plus.repository.guide.product; | ||
|
||
import java.time.Instant; | ||
import java.util.Set; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.relational.core.mapping.MappedCollection; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Table("plain_products") | ||
@Getter | ||
@Builder(toBuilder = true) | ||
@AllArgsConstructor | ||
public class PlainProductWithSoftDeleteReview { | ||
|
||
@Id | ||
private final Long id; | ||
private final String productName; | ||
private final Instant createdAt; | ||
private final Instant lastModifiedAt; | ||
|
||
@MappedCollection(idColumn = "product_id") | ||
private final Set<SoftDeleteReview> reviews; | ||
} |
28 changes: 28 additions & 0 deletions
28
...g/data/jdbc/plus/repository/guide/product/PlainProductWithSoftDeleteReviewRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
/* | ||
* Spring JDBC Plus | ||
* | ||
* Copyright 2020-2024 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.spring.data.jdbc.plus.repository.guide.product; | ||
|
||
import com.navercorp.spring.data.jdbc.plus.repository.JdbcRepository; | ||
|
||
/** | ||
* @author Chanhyeong Cho | ||
*/ | ||
public interface PlainProductWithSoftDeleteReviewRepository | ||
extends JdbcRepository<PlainProductWithSoftDeleteReview, Long> { | ||
} |
24 changes: 24 additions & 0 deletions
24
...c/main/java/com/navercorp/spring/data/jdbc/plus/repository/guide/product/PlainReview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.navercorp.spring.data.jdbc.plus.repository.guide.product; | ||
|
||
import java.time.Instant; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Table("plain_reviews") | ||
@Getter | ||
@Builder(toBuilder = true) | ||
@AllArgsConstructor | ||
public class PlainReview { | ||
|
||
@Id | ||
private final Long id; | ||
private final Long productId; | ||
private final String contents; | ||
private final Instant createdAt; | ||
private final Instant lastModifiedAt; | ||
} |
33 changes: 33 additions & 0 deletions
33
.../java/com/navercorp/spring/data/jdbc/plus/repository/guide/product/SoftDeleteProduct.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.navercorp.spring.data.jdbc.plus.repository.guide.product; | ||
|
||
import java.time.Instant; | ||
import java.util.Set; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.relational.core.mapping.MappedCollection; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import com.navercorp.spring.jdbc.plus.commons.annotations.SoftDeleteColumn; | ||
|
||
@Table("soft_delete_products") | ||
@Getter | ||
@Builder(toBuilder = true) | ||
@AllArgsConstructor | ||
public class SoftDeleteProduct { | ||
|
||
@Id | ||
private final Long id; | ||
private final String productName; | ||
private final Instant createdAt; | ||
private final Instant lastModifiedAt; | ||
|
||
@MappedCollection(idColumn = "product_id") | ||
private final Set<SoftDeleteReview> reviews; | ||
|
||
@SoftDeleteColumn.Boolean(valueAsDeleted = "false") | ||
private final boolean visible; | ||
} |
27 changes: 27 additions & 0 deletions
27
...navercorp/spring/data/jdbc/plus/repository/guide/product/SoftDeleteProductRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
/* | ||
* Spring JDBC Plus | ||
* | ||
* Copyright 2020-2024 NAVER Corp. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.navercorp.spring.data.jdbc.plus.repository.guide.product; | ||
|
||
import com.navercorp.spring.data.jdbc.plus.repository.JdbcRepository; | ||
|
||
/** | ||
* @author Chanhyeong Cho | ||
*/ | ||
public interface SoftDeleteProductRepository extends JdbcRepository<SoftDeleteProduct, Long> { | ||
} |
33 changes: 33 additions & 0 deletions
33
...corp/spring/data/jdbc/plus/repository/guide/product/SoftDeleteProductWithPlainReview.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.navercorp.spring.data.jdbc.plus.repository.guide.product; | ||
|
||
import java.time.Instant; | ||
import java.util.Set; | ||
|
||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.relational.core.mapping.MappedCollection; | ||
import org.springframework.data.relational.core.mapping.Table; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
import com.navercorp.spring.jdbc.plus.commons.annotations.SoftDeleteColumn; | ||
|
||
@Table("soft_delete_products") | ||
@Getter | ||
@Builder(toBuilder = true) | ||
@AllArgsConstructor | ||
public class SoftDeleteProductWithPlainReview { | ||
|
||
@Id | ||
private final Long id; | ||
private final String productName; | ||
private final Instant createdAt; | ||
private final Instant lastModifiedAt; | ||
|
||
@MappedCollection(idColumn = "product_id") | ||
private final Set<PlainReview> reviews; | ||
|
||
@SoftDeleteColumn.Boolean(valueAsDeleted = "false") | ||
private final boolean visible; | ||
} |
Oops, something went wrong.