Skip to content

Commit d329eb2

Browse files
committed
java docs
1 parent b846ad2 commit d329eb2

File tree

105 files changed

+7552
-5452
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+7552
-5452
lines changed

pom.xml

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111

1212
<groupId>io.github.hoangtien2k3</groupId>
1313
<artifactId>fw-commons</artifactId>
14-
<version>${version.lib}</version>
14+
<version>1.1.0</version>
1515
<packaging>jar</packaging>
1616
<name>fw-commons</name>
1717
<description>a commons java tool lib with spring boot framework</description>
@@ -49,7 +49,6 @@
4949

5050
<properties>
5151
<java.version>21</java.version>
52-
<version.lib>1.1.0</version.lib>
5352
<micrometer.tracing.version>1.3.1</micrometer.tracing.version>
5453
<micrometer.registry.version>1.13.1</micrometer.registry.version>
5554
<micrometer.core.version>1.13.1</micrometer.core.version>
@@ -66,13 +65,13 @@
6665
<spotless.version>2.43.0</spotless.version>
6766
<file.encoding>UTF-8</file.encoding>
6867
<!-- Plugins version -->
69-
<maven-compiler-plugin.version>3.11.0</maven-compiler-plugin.version>
70-
<maven-surefire-plugin.version>3.1.2</maven-surefire-plugin.version>
71-
<central-publishing-maven-plugin.version>0.3.0</central-publishing-maven-plugin.version>
72-
<nexus-staging-maven-plugin.version>1.6.7</nexus-staging-maven-plugin.version>
73-
<maven-gpg-plugin.version>1.5</maven-gpg-plugin.version>
74-
<maven-javadoc-plugin.version>2.9.1</maven-javadoc-plugin.version>
75-
<maven-source-plugin.version>2.2.1</maven-source-plugin.version>
68+
<maven-compiler-plugin.version>3.13.0</maven-compiler-plugin.version>
69+
<maven-surefire-plugin.version>3.4.0</maven-surefire-plugin.version>
70+
<central-publishing-maven-plugin.version>0.5.0</central-publishing-maven-plugin.version>
71+
<nexus-staging-maven-plugin.version>1.7.0</nexus-staging-maven-plugin.version>
72+
<maven-gpg-plugin.version>3.2.5</maven-gpg-plugin.version>
73+
<maven-javadoc-plugin.version>3.8.0</maven-javadoc-plugin.version>
74+
<maven-source-plugin.version>3.3.1</maven-source-plugin.version>
7675
</properties>
7776

7877
<dependencyManagement>
@@ -192,7 +191,7 @@
192191
<dependency>
193192
<groupId>org.json</groupId>
194193
<artifactId>json</artifactId>
195-
<version>20231013</version>
194+
<version>20240303</version>
196195
</dependency>
197196
<dependency>
198197
<groupId>javax.xml.bind</groupId>
@@ -437,6 +436,13 @@
437436
<javadocExecutable>${java.home}/bin/javadoc</javadocExecutable>
438437
</configuration>
439438
<executions>
439+
<execution>
440+
<id>generate-javadocs</id>
441+
<phase>prepare-package</phase>
442+
<goals>
443+
<goal>javadoc</goal>
444+
</goals>
445+
</execution>
440446
<execution>
441447
<id>attach-javadocs</id>
442448
<goals>
@@ -507,6 +513,7 @@
507513
<spacesPerTab>2</spacesPerTab>
508514
</indent>
509515
<removeUnusedImports/>
516+
<palantirJavaFormat/>
510517
<licenseHeader>
511518
<content><![CDATA[
512519
/*
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2024 author - Hoàng Anh Tiến
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
12+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
13+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14+
*/
15+
package io.hoangtien2k3.commons;
16+
17+
import org.springframework.boot.SpringApplication;
18+
import org.springframework.boot.autoconfigure.SpringBootApplication;
19+
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
20+
import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
21+
import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
22+
import org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration;
23+
import org.springframework.context.annotation.ComponentScan;
24+
import org.springframework.context.annotation.ImportResource;
25+
26+
@SpringBootApplication(
27+
exclude = {
28+
DataSourceAutoConfiguration.class,
29+
DataSourceTransactionManagerAutoConfiguration.class,
30+
HibernateJpaAutoConfiguration.class,
31+
SecurityAutoConfiguration.class,
32+
})
33+
@ComponentScan(basePackages = {"io.hoangtien2k3.commons.*"})
34+
@ImportResource({"classpath*:applicationContext.xml"})
35+
// @EnableDiscoveryClient
36+
public class FwCommonsApplication {
37+
public static void main(String[] args) {
38+
SpringApplication.run(FwCommonsApplication.class, args);
39+
}
40+
}

src/main/java/io/hoangtien2k3/commons/annotations/LocalCache.java

Lines changed: 46 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,55 @@
1919
import java.lang.annotation.RetentionPolicy;
2020
import java.lang.annotation.Target;
2121

22+
/**
23+
* Annotation for specifying caching behavior on methods.
24+
*
25+
* <p>
26+
* This annotation allows methods to utilize caching by specifying cache
27+
* parameters. The caching behavior is controlled by the
28+
* {@code durationInMinute}, {@code maxRecord}, and {@code autoCache}
29+
* attributes.
30+
* </p>
31+
*
32+
* <ul>
33+
* <li><b>durationInMinute:</b> Specifies the duration (in minutes) for which
34+
* the cache entries should be retained. The default value is 120 minutes.</li>
35+
* <li><b>maxRecord:</b> Defines the maximum number of cache records to store.
36+
* The default value is 1000 records.</li>
37+
* <li><b>autoCache:</b> Indicates whether caching should be automatically
38+
* applied. If {@code true}, caching is enabled without additional
39+
* configuration. The default value is {@code false}.</li>
40+
* </ul>
41+
*
42+
* <p>
43+
* This annotation should be applied to methods where caching is desired. The
44+
* cache implementation will use the specified parameters to manage caching
45+
* behavior, including cache expiration and size limits.
46+
* </p>
47+
*/
2248
@Target(ElementType.METHOD)
2349
@Retention(RetentionPolicy.RUNTIME)
2450
public @interface LocalCache {
25-
int durationInMinute() default 120;
2651

27-
int maxRecord() default 1000;
52+
/**
53+
* The duration (in minutes) for which cache entries should be retained.
54+
*
55+
* @return the cache duration in minutes
56+
*/
57+
int durationInMinute() default 120;
58+
59+
/**
60+
* The maximum number of cache records to store.
61+
*
62+
* @return the maximum number of cache records
63+
*/
64+
int maxRecord() default 1000;
2865

29-
boolean autoCache() default false;
66+
/**
67+
* Whether caching should be automatically applied.
68+
*
69+
* @return {@code true} if caching should be automatically applied;
70+
* {@code false} otherwise
71+
*/
72+
boolean autoCache() default false;
3073
}

src/main/java/io/hoangtien2k3/commons/annotations/LogPerformance.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,13 @@
2222
@Target({ElementType.METHOD, ElementType.TYPE})
2323
@Retention(RetentionPolicy.RUNTIME)
2424
public @interface LogPerformance {
25-
String logType() default "";
25+
String logType() default "";
2626

27-
String actionType() default "";
27+
String actionType() default "";
2828

29-
boolean logOutput() default true;
29+
boolean logOutput() default true;
3030

31-
boolean logInput() default true;
31+
boolean logInput() default true;
3232

33-
String title() default "";
33+
String title() default "";
3434
}

src/main/java/io/hoangtien2k3/commons/annotations/cache/CacheAspect.java

Lines changed: 64 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@
1515
package io.hoangtien2k3.commons.annotations.cache;
1616

1717
import com.github.benmanes.caffeine.cache.Cache;
18+
import io.hoangtien2k3.commons.annotations.LocalCache;
19+
import java.util.Optional;
1820
import lombok.extern.slf4j.Slf4j;
1921
import org.aspectj.lang.ProceedingJoinPoint;
2022
import org.aspectj.lang.annotation.Around;
@@ -27,32 +29,72 @@
2729
import reactor.core.publisher.Mono;
2830
import reactor.core.publisher.Signal;
2931

30-
import java.util.Optional;
31-
32+
/**
33+
* Aspect for managing cache operations based on the {@link LocalCache}
34+
* annotation.
35+
*
36+
* <p>
37+
* This aspect intercepts method calls annotated with {@link LocalCache} and
38+
* handles caching of method results. It uses a cache store to retrieve results
39+
* if they are present, and if not, it proceeds with the method execution,
40+
* stores the result in the cache, and then returns it.
41+
* </p>
42+
*
43+
* <p>
44+
* The cache key is generated based on the method arguments, and the cache is
45+
* identified using the method name and class name of the target object.
46+
* </p>
47+
*
48+
* @see LocalCache
49+
* @see CacheStore
50+
* @see SimpleKeyGenerator
51+
* @see CacheMono
52+
* @see Signal
53+
*/
3254
@Aspect
3355
@Configuration
3456
@Slf4j
3557
public class CacheAspect {
36-
@Pointcut("@annotation(io.hoangtien2k3.commons.annotations.LocalCache)")
37-
private void processAnnotation() {
38-
}
3958

40-
@Around("processAnnotation()")
41-
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
42-
Object[] args = joinPoint.getArgs();
43-
Object key = SimpleKeyGenerator.generateKey(args);
44-
String name = ClassUtils.getUserClass(joinPoint.getTarget().getClass()).getSimpleName() + "."
45-
+ joinPoint.getSignature().getName();
46-
Cache cache = CacheStore.getCache(name);
59+
/**
60+
* Pointcut for methods annotated with {@link LocalCache}.
61+
*/
62+
@Pointcut("@annotation(io.hoangtien2k3.commons.annotations.LocalCache)")
63+
private void processAnnotation() {}
64+
65+
/**
66+
* Around advice for caching method results.
67+
*
68+
* <p>
69+
* This method intercepts the execution of a method annotated with
70+
* {@link LocalCache}, retrieves the result from the cache if available, or
71+
* proceeds with the method execution if the result is not cached. The result is
72+
* then stored in the cache for future use.
73+
* </p>
74+
*
75+
* @param joinPoint
76+
* the join point representing the intercepted method call
77+
* @return the result of the method call, either from the cache or from the
78+
* method execution
79+
* @throws Throwable
80+
* if the method call or caching operation fails
81+
*/
82+
@Around("processAnnotation()")
83+
public Object aroundAdvice(ProceedingJoinPoint joinPoint) throws Throwable {
84+
Object[] args = joinPoint.getArgs();
85+
Object key = SimpleKeyGenerator.generateKey(args);
86+
String name = ClassUtils.getUserClass(joinPoint.getTarget().getClass()).getSimpleName() + "."
87+
+ joinPoint.getSignature().getName();
88+
Cache cache = CacheStore.getCache(name);
4789

48-
return CacheMono.lookup(k -> Mono.justOrEmpty(cache.getIfPresent(key)).map(Signal::next), key)
49-
.onCacheMissResume((Mono<Object>) joinPoint.proceed(args))
50-
.andWriteWith((k, sig) -> Mono.fromRunnable(() -> {
51-
if (sig != null && sig.get() != null) {
52-
if (!(sig.get() instanceof Optional && ((Optional) sig.get()).isEmpty())) {
53-
cache.put(k, sig.get());
54-
}
55-
}
56-
}));
57-
}
90+
return CacheMono.lookup(k -> Mono.justOrEmpty(cache.getIfPresent(key)).map(Signal::next), key)
91+
.onCacheMissResume((Mono<Object>) joinPoint.proceed(args))
92+
.andWriteWith((k, sig) -> Mono.fromRunnable(() -> {
93+
if (sig != null && sig.get() != null) {
94+
if (!(sig.get() instanceof Optional && ((Optional) sig.get()).isEmpty())) {
95+
cache.put(k, sig.get());
96+
}
97+
}
98+
}));
99+
}
58100
}

0 commit comments

Comments
 (0)