Skip to content

Commit 5119def

Browse files
authored
Merge pull request #2 from microsphere-projects/main
Introduce microsphere-hibernate core, tests, and CI integration
2 parents d685e2e + 33807be commit 5119def

33 files changed

Lines changed: 4123 additions & 2 deletions

.github/workflows/maven-build.yml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ jobs:
2525
java: [ '17' , '21' , '25' ]
2626
maven-profile-spring-cloud: [ 'spring-cloud-2022' , 'spring-cloud-2023' , 'spring-cloud-2024' ,
2727
'spring-cloud-2025' ]
28+
maven-hibernate: [ 'hibernate-7.3' , 'hibernate-7.2' , 'hibernate-7.1' , 'hibernate-7.0' ,
29+
'hibernate-6.6' , 'hibernate-6.5' , 'hibernate-6.4' , 'hibernate-6.3' ,
30+
'hibernate-6.2'
31+
]
32+
2833
steps:
2934
- name: Checkout Source
3035
uses: actions/checkout@v5

README.md

Lines changed: 106 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,106 @@
1-
# microsphere-hibernate
2-
The microsphere projects for Hibernate ORM
1+
# Microsphere Hibernate
2+
3+
> Microsphere Projects for [Hibernate](https://hibernate.org/)
4+
5+
[![Ask DeepWiki](https://deepwiki.com/badge.svg)](https://deepwiki.com/microsphere-projects/microsphere-hibernate)
6+
[![Maven Build](https://github.com/microsphere-projects/microsphere-hibernate/actions/workflows/maven-build.yml/badge.svg)](https://github.com/microsphere-projects/microsphere-hibernate/actions/workflows/maven-build.yml)
7+
[![Codecov](https://codecov.io/gh/microsphere-projects/microsphere-hibernate/branch/main/graph/badge.svg)](https://app.codecov.io/gh/microsphere-projects/microsphere-hibernate)
8+
![Maven](https://img.shields.io/maven-central/v/io.github.microsphere-projects/microsphere-hibernate.svg)
9+
![License](https://img.shields.io/github/license/microsphere-projects/microsphere-hibernate.svg)
10+
11+
## Modules
12+
13+
| **Module** | **Purpose** |
14+
|----------------------------------------|------------------------------------------------------------------------|
15+
| **microsphere-hibernate-parent** | Defines the parent POM with dependency management and version profiles |
16+
| **microsphere-hibernate-dependencies** | Centralizes dependency management for all project modules |
17+
| **microsphere-hibernate-core** | Core featurues of Hibernate ORM extension |
18+
| **microsphere-hibernate-test** | Testing framework for Hibernate ORM |
19+
20+
## Getting Started
21+
22+
The easiest way to get started is by adding the Microsphere Hibernate BOM (Bill of Materials) to your project's
23+
pom.xml:
24+
25+
```xml
26+
27+
<dependencyManagement>
28+
<dependencies>
29+
...
30+
<!-- Microsphere Hibernate Dependencies -->
31+
<dependency>
32+
<groupId>io.github.microsphere-projects</groupId>
33+
<artifactId>microsphere-hibernate-dependencies</artifactId>
34+
<version>${microsphere-hibernate.version}</version>
35+
<type>pom</type>
36+
<scope>import</scope>
37+
</dependency>
38+
...
39+
</dependencies>
40+
</dependencyManagement>
41+
```
42+
43+
`${microsphere-hibernate.version}` has two branches:
44+
45+
| **Branches** | **Purpose** | **Latest Version** |
46+
|--------------|--------------------------------------------------|--------------------|
47+
| **0.2.x** | Compatible with Spring Cloud 2022.0.x - 2025.0.x | 0.2.0 |
48+
| **0.1.x** | Compatible with Spring Cloud Hoxton - 2021.0.x | 0.1.0 |
49+
50+
## Building from Source
51+
52+
You don't need to build from source unless you want to try out the latest code or contribute to the project.
53+
54+
To build the project, follow these steps:
55+
56+
1. Clone the repository:
57+
58+
```bash
59+
git clone https://github.com/microsphere-projects/microsphere-hibernate.git
60+
```
61+
62+
2. Build the source:
63+
64+
- Linux/MacOS:
65+
66+
```bash
67+
./mvnw package
68+
```
69+
70+
- Windows:
71+
72+
```powershell
73+
mvnw.cmd package
74+
```
75+
76+
## Contributing
77+
78+
We welcome your contributions! Please read [Code of Conduct](./CODE_OF_CONDUCT.md) before submitting a pull request.
79+
80+
## Reporting Issues
81+
82+
* Before you log a bug, please search
83+
the [issues](https://github.com/microsphere-projects/microsphere-hibernate/issues)
84+
to see if someone has already reported the problem.
85+
* If the issue doesn't already
86+
exist, [create a new issue](https://github.com/microsphere-projects/microsphere-hibernate/issues/new).
87+
* Please provide as much information as possible with the issue report.
88+
89+
## Documentation
90+
91+
### User Guide
92+
93+
[DeepWiki Host](https://deepwiki.com/microsphere-projects/microsphere-hibernate)
94+
95+
### Wiki
96+
97+
[Github Host](https://github.com/microsphere-projects/microsphere-hibernate/wiki)
98+
99+
### JavaDoc
100+
101+
- [microsphere-hibernate-core](https://javadoc.io/doc/io.github.microsphere-projects/microsphere-hibernate-core)
102+
- [microsphere-hibernate-test](https://javadoc.io/doc/io.github.microsphere-projects/microsphere-hibernate-test)
103+
104+
## License
105+
106+
The Microsphere Spring is released under the [Apache License 2.0](https://www.apache.org/licenses/LICENSE-2.0).

microsphere-hibernate-core/pom.xml

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,5 +18,70 @@
1818
<name>Microsphere :: Hibernate :: Core</name>
1919
<description>Microsphere Hibernate Core</description>
2020

21+
<dependencies>
22+
23+
<!-- Microsphere Java Core -->
24+
<dependency>
25+
<groupId>io.github.microsphere-projects</groupId>
26+
<artifactId>microsphere-java-core</artifactId>
27+
</dependency>
28+
29+
<!-- Microsphere Annotation Processor -->
30+
<dependency>
31+
<groupId>io.github.microsphere-projects</groupId>
32+
<artifactId>microsphere-annotation-processor</artifactId>
33+
<optional>true</optional>
34+
</dependency>
35+
36+
<!-- Hibernate -->
37+
<dependency>
38+
<groupId>org.hibernate.orm</groupId>
39+
<artifactId>hibernate-core</artifactId>
40+
<optional>true</optional>
41+
</dependency>
42+
43+
<!-- Testing -->
44+
<dependency>
45+
<groupId>org.junit.jupiter</groupId>
46+
<artifactId>junit-jupiter</artifactId>
47+
<scope>test</scope>
48+
</dependency>
49+
50+
<!-- Mockito -->
51+
<dependency>
52+
<groupId>org.mockito</groupId>
53+
<artifactId>mockito-core</artifactId>
54+
<scope>test</scope>
55+
</dependency>
56+
57+
<dependency>
58+
<groupId>org.mockito</groupId>
59+
<artifactId>mockito-junit-jupiter</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
63+
<!-- Microsphere Hibernate Test -->
64+
<dependency>
65+
<groupId>io.github.microsphere-projects</groupId>
66+
<artifactId>microsphere-hibernate-test</artifactId>
67+
<version>${revision}</version>
68+
<scope>test</scope>
69+
</dependency>
70+
71+
<!-- H2 -->
72+
<dependency>
73+
<groupId>com.h2database</groupId>
74+
<artifactId>h2</artifactId>
75+
<scope>test</scope>
76+
</dependency>
77+
78+
<!-- Logback -->
79+
<dependency>
80+
<groupId>ch.qos.logback</groupId>
81+
<artifactId>logback-classic</artifactId>
82+
<scope>test</scope>
83+
</dependency>
84+
85+
</dependencies>
2186

2287
</project>
Lines changed: 203 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,203 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
package io.microsphere.hibernate;
19+
20+
import org.hibernate.CallbackException;
21+
import org.hibernate.Interceptor;
22+
import org.hibernate.Transaction;
23+
import org.hibernate.metamodel.RepresentationMode;
24+
import org.hibernate.metamodel.spi.EntityRepresentationStrategy;
25+
import org.hibernate.type.Type;
26+
27+
import java.io.Serializable;
28+
import java.util.Iterator;
29+
30+
/**
31+
* Composite {@link Interceptor}
32+
*
33+
* @author <a href="mailto:mercyblitz@gmail.com">Mercy</a>
34+
* @see Interceptor
35+
* @since 1.0.0
36+
*/
37+
public class CompositeInterceptor implements Interceptor {
38+
39+
private final Iterable<Interceptor> interceptors;
40+
41+
public CompositeInterceptor(Iterable<Interceptor> interceptors) {
42+
this.interceptors = interceptors;
43+
}
44+
45+
@Override
46+
public boolean onLoad(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
47+
for (Interceptor interceptor : interceptors) {
48+
interceptor.onLoad(entity, id, state, propertyNames, types);
49+
}
50+
return Interceptor.super.onLoad(entity, id, state, propertyNames, types);
51+
}
52+
53+
public boolean onLoad(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
54+
return Interceptor.super.onLoad(entity, id, state, propertyNames, types);
55+
}
56+
57+
@Override
58+
public boolean onPersist(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
59+
return Interceptor.super.onPersist(entity, id, state, propertyNames, types);
60+
}
61+
62+
@Override
63+
public void onRemove(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
64+
Interceptor.super.onRemove(entity, id, state, propertyNames, types);
65+
}
66+
67+
@Override
68+
public boolean onFlushDirty(Object entity, Object id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) throws CallbackException {
69+
return Interceptor.super.onFlushDirty(entity, id, currentState, previousState, propertyNames, types);
70+
}
71+
72+
public boolean onFlushDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) throws CallbackException {
73+
return Interceptor.super.onFlushDirty(entity, id, currentState, previousState, propertyNames, types);
74+
}
75+
76+
public boolean onSave(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
77+
return Interceptor.super.onSave(entity, id, state, propertyNames, types);
78+
}
79+
80+
@Override
81+
public boolean onSave(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
82+
return Interceptor.super.onSave(entity, id, state, propertyNames, types);
83+
}
84+
85+
public void onDelete(Object entity, Serializable id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
86+
Interceptor.super.onDelete(entity, id, state, propertyNames, types);
87+
}
88+
89+
@Override
90+
public void onDelete(Object entity, Object id, Object[] state, String[] propertyNames, Type[] types) throws CallbackException {
91+
Interceptor.super.onDelete(entity, id, state, propertyNames, types);
92+
}
93+
94+
public void onCollectionRecreate(Object collection, Serializable key) throws CallbackException {
95+
Interceptor.super.onCollectionRecreate(collection, key);
96+
}
97+
98+
@Override
99+
public void onCollectionRecreate(Object collection, Object key) throws CallbackException {
100+
Interceptor.super.onCollectionRecreate(collection, key);
101+
}
102+
103+
public void onCollectionRemove(Object collection, Serializable key) throws CallbackException {
104+
Interceptor.super.onCollectionRemove(collection, key);
105+
}
106+
107+
@Override
108+
public void onCollectionRemove(Object collection, Object key) throws CallbackException {
109+
Interceptor.super.onCollectionRemove(collection, key);
110+
}
111+
112+
public void onCollectionUpdate(Object collection, Serializable key) throws CallbackException {
113+
Interceptor.super.onCollectionUpdate(collection, key);
114+
}
115+
116+
@Override
117+
public void onCollectionUpdate(Object collection, Object key) throws CallbackException {
118+
Interceptor.super.onCollectionUpdate(collection, key);
119+
}
120+
121+
@Override
122+
public void preFlush(Iterator<Object> entities) throws CallbackException {
123+
Interceptor.super.preFlush(entities);
124+
}
125+
126+
@Override
127+
public void postFlush(Iterator<Object> entities) throws CallbackException {
128+
Interceptor.super.postFlush(entities);
129+
}
130+
131+
@Override
132+
public Boolean isTransient(Object entity) {
133+
return Interceptor.super.isTransient(entity);
134+
}
135+
136+
public int[] findDirty(Object entity, Serializable id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
137+
return Interceptor.super.findDirty(entity, id, currentState, previousState, propertyNames, types);
138+
}
139+
140+
@Override
141+
public int[] findDirty(Object entity, Object id, Object[] currentState, Object[] previousState, String[] propertyNames, Type[] types) {
142+
return Interceptor.super.findDirty(entity, id, currentState, previousState, propertyNames, types);
143+
}
144+
145+
@Override
146+
public Object instantiate(String entityName, EntityRepresentationStrategy representationStrategy, Object id) throws CallbackException {
147+
return Interceptor.super.instantiate(entityName, representationStrategy, id);
148+
}
149+
150+
@Override
151+
public Object instantiate(String entityName, RepresentationMode representationMode, Object id) throws CallbackException {
152+
return Interceptor.super.instantiate(entityName, representationMode, id);
153+
}
154+
155+
@Override
156+
public String getEntityName(Object object) throws CallbackException {
157+
return Interceptor.super.getEntityName(object);
158+
}
159+
160+
public Object getEntity(String entityName, Serializable id) throws CallbackException {
161+
return Interceptor.super.getEntity(entityName, id);
162+
}
163+
164+
@Override
165+
public Object getEntity(String entityName, Object id) throws CallbackException {
166+
return Interceptor.super.getEntity(entityName, id);
167+
}
168+
169+
@Override
170+
public void afterTransactionBegin(Transaction tx) {
171+
Interceptor.super.afterTransactionBegin(tx);
172+
}
173+
174+
@Override
175+
public void beforeTransactionCompletion(Transaction tx) {
176+
Interceptor.super.beforeTransactionCompletion(tx);
177+
}
178+
179+
@Override
180+
public void afterTransactionCompletion(Transaction tx) {
181+
Interceptor.super.afterTransactionCompletion(tx);
182+
}
183+
184+
@Override
185+
public void onInsert(Object entity, Object id, Object[] state, String[] propertyNames, Type[] propertyTypes) {
186+
Interceptor.super.onInsert(entity, id, state, propertyNames, propertyTypes);
187+
}
188+
189+
@Override
190+
public void onUpdate(Object entity, Object id, Object[] state, String[] propertyNames, Type[] propertyTypes) {
191+
Interceptor.super.onUpdate(entity, id, state, propertyNames, propertyTypes);
192+
}
193+
194+
@Override
195+
public void onUpsert(Object entity, Object id, Object[] state, String[] propertyNames, Type[] propertyTypes) {
196+
Interceptor.super.onUpsert(entity, id, state, propertyNames, propertyTypes);
197+
}
198+
199+
@Override
200+
public void onDelete(Object entity, Object id, String[] propertyNames, Type[] propertyTypes) {
201+
Interceptor.super.onDelete(entity, id, propertyNames, propertyTypes);
202+
}
203+
}

0 commit comments

Comments
 (0)