Skip to content

Commit

Permalink
Add soft delete configuration (#141)
Browse files Browse the repository at this point in the history
  • Loading branch information
chanhyeong authored Apr 17, 2024
1 parent 1d64049 commit bfc1a91
Show file tree
Hide file tree
Showing 34 changed files with 2,480 additions and 145 deletions.
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;
}
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> {
}
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;
}
}
}
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> {
}
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);
}
}
}
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;
}
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;
}
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> {
}
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;
}
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;
}
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> {
}
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;
}
Loading

0 comments on commit bfc1a91

Please sign in to comment.