Skip to content

Instantly share code, notes, and snippets.

@Repository
public interface PostRepository extends ReactiveCrudRepository<Post, Long>, SoftDeleteRepository<Post, Long> {
Flux<PostWithDeleteStamp> findByDeletedDateIsNotNull();
@Query("select * FROM posts")
Flux<PostWithDeleteStamp> findAllEntries();
// delete (hard-delete) all posts from the database
@Query("delete from posts")
Mono<Void> flush();
@Configuration
@EnableR2dbcRepositories(
basePackages = "io.github.jelilio.feed.repository",
repositoryBaseClass = SoftDeleteRepositoryImpl.class
)
public class DatabaseConfig {
}
@Repository
public interface PostRepository extends SoftDeleteRepository<Post, Long>, ReactiveCrudRepository<Post, Long> {
@NonNull
default Mono<Post> findById(@NonNull Long id) {
return findById(id, Post.class);
}
@NonNull
default Flux<Post> findAll() {
return findAll(Post.class);
public interface SoftDeleteRepository<T, ID> {
@NonNull
Mono<Long> count(Class<T> entityClass);
@NonNull
Mono<Boolean> existsById(@NonNull ID id, Class<T> entityClass);
@NonNull
Mono<T> findById(@NonNull ID id, Class<T> entityClass);
public class SoftDeleteRepositoryImpl<T extends AbstractSoftDeletableEntity, ID> implements SoftDeleteRepository<T, ID> {
private final R2dbcEntityOperations entityOperations;
private final R2dbcConverter converter;
public SoftDeleteRepositoryImpl(R2dbcEntityOperations entityOperations, R2dbcConverter converter) {
this.entityOperations = entityOperations;
this.converter = converter;
}
@NonNull
@jelilio
jelilio / Post.java
Last active November 10, 2024 02:41
@Table("posts")
public class Post extends AbstractSoftDeletableEntity {
@Id
private Long id;
@Column("title")
public String title;
@Column("body")
public String body;
public abstract class AbstractSoftDeletableEntity extends AbstractAuditingEntity {
@JsonIgnore
@Column("deleted_date")
public Instant deletedDate;
}
@jelilio
jelilio / isValidEmailAddress.java
Last active March 20, 2024 09:41
isValidEmailAddress
private boolean isValidEmailAddress(String email) {
String ePattern = "^[a-zA-Z0-9.!#$%&'*+/=?^_`{|}~-]+@((\\[[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\])|(([a-zA-Z\\-0-9]+\\.)+[a-zA-Z]{2,}))$";
Pattern p = Pattern.compile(ePattern);
Matcher m = p.matcher(email);
return m.matches();
}
@jelilio
jelilio / loading_button_final.kt
Created November 24, 2023 17:53 — forked from fvilarino/loading_button_final.kt
Loading Button Final
enum class AnimationType {
Bounce,
LazyBounce,
Fade,
}
private const val NumIndicators = 3
private const val IndicatorSize = 12
private const val BounceAnimationDurationMillis = 300
private const val FadeAnimationDurationMillis = 600