Skip to content

Commit 514e1a2

Browse files
author
JARVIS SONG
committed
auditing
1 parent b3b561e commit 514e1a2

30 files changed

+529
-1655
lines changed

spring-data-mybatis-core/pom.xml

Lines changed: 49 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -1,50 +1,55 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22
<project xmlns="http://maven.apache.org/POM/4.0.0"
3-
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4-
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5-
<parent>
6-
<artifactId>spring-data-mybatis-parent</artifactId>
7-
<groupId>io.easybest</groupId>
8-
<version>${revision}</version>
9-
<relativePath>../spring-data-mybatis-parent</relativePath>
10-
</parent>
11-
<modelVersion>4.0.0</modelVersion>
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
<parent>
6+
<artifactId>spring-data-mybatis-parent</artifactId>
7+
<groupId>io.easybest</groupId>
8+
<version>${revision}</version>
9+
<relativePath>../spring-data-mybatis-parent</relativePath>
10+
</parent>
11+
<modelVersion>4.0.0</modelVersion>
1212

13-
<artifactId>spring-data-mybatis-core</artifactId>
13+
<artifactId>spring-data-mybatis-core</artifactId>
1414

15-
<name>Spring Data MyBatis Core</name>
16-
<description>Spring Data module for MyBatis repositories.</description>
17-
<url>https://github.com/easybest/spring-data-mybatis</url>
18-
<developers>
19-
<developer>
20-
<id>jarvis</id>
21-
<name>Jarvis Song</name>
22-
<email>[email protected]</email>
23-
</developer>
24-
</developers>
25-
<organization>
26-
<name>EasyBest</name>
27-
<url>https://easybest.io</url>
28-
</organization>
29-
<licenses>
30-
<license>
31-
<name>Apache License, Version 2.0</name>
32-
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
33-
</license>
34-
</licenses>
35-
<scm>
36-
<url>https://github.com/easybest/spring-data-mybatis</url>
37-
<connection>scm:git:git://github.com/easybest/spring-data-mybatis.git
38-
</connection>
39-
<developerConnection>
40-
scm:git:ssh://[email protected]/easybest/spring-data-mybatis.git
41-
</developerConnection>
42-
</scm>
15+
<name>Spring Data MyBatis Core</name>
16+
<description>Spring Data module for MyBatis repositories.</description>
17+
<url>https://github.com/easybest/spring-data-mybatis</url>
18+
<developers>
19+
<developer>
20+
<id>jarvis</id>
21+
<name>Jarvis Song</name>
22+
<email>[email protected]</email>
23+
</developer>
24+
</developers>
25+
<organization>
26+
<name>EasyBest</name>
27+
<url>https://easybest.io</url>
28+
</organization>
29+
<licenses>
30+
<license>
31+
<name>Apache License, Version 2.0</name>
32+
<url>https://www.apache.org/licenses/LICENSE-2.0.txt</url>
33+
</license>
34+
</licenses>
35+
<scm>
36+
<url>https://github.com/easybest/spring-data-mybatis</url>
37+
<connection>scm:git:git://github.com/easybest/spring-data-mybatis.git
38+
</connection>
39+
<developerConnection>
40+
scm:git:ssh://[email protected]/easybest/spring-data-mybatis.git
41+
</developerConnection>
42+
</scm>
4343

44-
<dependencies>
45-
<dependency>
46-
<groupId>javax.persistence</groupId>
47-
<artifactId>javax.persistence-api</artifactId>
48-
</dependency>
49-
</dependencies>
44+
<dependencies>
45+
<dependency>
46+
<groupId>javax.persistence</groupId>
47+
<artifactId>javax.persistence-api</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>org.springframework.data</groupId>
51+
<artifactId>spring-data-commons</artifactId>
52+
<optional>true</optional>
53+
</dependency>
54+
</dependencies>
5055
</project>

spring-data-mybatis-core/src/main/java/org/springframework/data/mybatis/annotation/CreatedBy.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

spring-data-mybatis-core/src/main/java/org/springframework/data/mybatis/annotation/LastModifiedBy.java

Lines changed: 0 additions & 34 deletions
This file was deleted.

spring-data-mybatis-core/src/main/java/org/springframework/data/mybatis/annotation/LastModifiedDate.java

Lines changed: 0 additions & 34 deletions
This file was deleted.
Lines changed: 99 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,99 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.springframework.data.mybatis.domain;
17+
18+
import java.io.Serializable;
19+
import java.time.LocalDateTime;
20+
import java.time.ZoneId;
21+
import java.util.Date;
22+
import java.util.Optional;
23+
24+
import javax.persistence.ManyToOne;
25+
import javax.persistence.MappedSuperclass;
26+
import javax.persistence.Temporal;
27+
import javax.persistence.TemporalType;
28+
29+
import org.springframework.data.domain.Auditable;
30+
import org.springframework.lang.Nullable;
31+
32+
/**
33+
* Abstract base class for auditable entities. Stores the audition values in persistent
34+
* fields.
35+
*
36+
* @author JARVIS SONG
37+
* @since 2.0.1
38+
*/
39+
@MappedSuperclass
40+
public class AbstractAuditable<U, PK extends Serializable> extends AbstractPersistable<PK>
41+
implements Auditable<U, PK, LocalDateTime> {
42+
43+
private static final long serialVersionUID = 779906810082104339L;
44+
45+
@ManyToOne
46+
private @Nullable U createdBy;
47+
48+
@Temporal(TemporalType.TIMESTAMP)
49+
private @Nullable Date createdDate;
50+
51+
@ManyToOne
52+
private @Nullable U lastModifiedBy;
53+
54+
@Temporal(TemporalType.TIMESTAMP)
55+
private @Nullable Date lastModifiedDate;
56+
57+
@Override
58+
public Optional<U> getCreatedBy() {
59+
return Optional.ofNullable(this.createdBy);
60+
}
61+
62+
@Override
63+
public void setCreatedBy(U createdBy) {
64+
this.createdBy = createdBy;
65+
}
66+
67+
@Override
68+
public Optional<LocalDateTime> getCreatedDate() {
69+
return null == this.createdDate ? Optional.empty()
70+
: Optional.of(LocalDateTime.ofInstant(this.createdDate.toInstant(), ZoneId.systemDefault()));
71+
}
72+
73+
@Override
74+
public void setCreatedDate(LocalDateTime createdDate) {
75+
this.createdDate = Date.from(createdDate.atZone(ZoneId.systemDefault()).toInstant());
76+
}
77+
78+
@Override
79+
public Optional<U> getLastModifiedBy() {
80+
return Optional.ofNullable(this.lastModifiedBy);
81+
}
82+
83+
@Override
84+
public void setLastModifiedBy(U lastModifiedBy) {
85+
this.lastModifiedBy = lastModifiedBy;
86+
}
87+
88+
@Override
89+
public Optional<LocalDateTime> getLastModifiedDate() {
90+
return null == this.lastModifiedDate ? Optional.empty()
91+
: Optional.of(LocalDateTime.ofInstant(this.lastModifiedDate.toInstant(), ZoneId.systemDefault()));
92+
}
93+
94+
@Override
95+
public void setLastModifiedDate(LocalDateTime lastModifiedDate) {
96+
this.lastModifiedDate = Date.from(lastModifiedDate.atZone(ZoneId.systemDefault()).toInstant());
97+
}
98+
99+
}

0 commit comments

Comments
 (0)