Skip to content

Commit 766fa44

Browse files
authored
Merge pull request #1 from bennu/feat/init
feat: base mapper and enum type handler
2 parents 0584169 + 8a74799 commit 766fa44

File tree

8 files changed

+275
-19
lines changed

8 files changed

+275
-19
lines changed
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Java CI with Maven and SonarCloud
2+
3+
on:
4+
push:
5+
branches: [ master ]
6+
pull_request:
7+
branches: [ master ]
8+
types: [opened, synchronize, reopened]
9+
10+
jobs:
11+
build-and-analyze:
12+
runs-on: ubuntu-latest
13+
14+
steps:
15+
- uses: actions/checkout@v3
16+
with:
17+
fetch-depth: 0 # Necessary for a comprehensive SonarCloud analysis
18+
19+
- name: Set up JDK 17
20+
uses: actions/setup-java@v3
21+
with:
22+
java-version: '17'
23+
distribution: 'zulu'
24+
25+
- name: Cache Maven and SonarCloud packages
26+
uses: actions/cache@v3
27+
with:
28+
path: |
29+
~/.m2
30+
~/.sonar/cache
31+
key: ${{ runner.os }}-m2-sonar-${{ hashFiles('**/pom.xml') }}
32+
33+
- name: Build and analyze with Maven
34+
env:
35+
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
36+
SONAR_TOKEN: ${{ secrets.SONAR_TOKEN }}
37+
run: mvn -B verify --file pom.xml org.sonarsource.scanner.maven:sonar-maven-plugin:sonar -PcoverageReport
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
name: Maven Library Publish
2+
3+
on:
4+
release:
5+
types: [ created ]
6+
7+
jobs:
8+
publish:
9+
10+
runs-on: ubuntu-latest
11+
12+
steps:
13+
- uses: actions/checkout@v3
14+
15+
- name: Set up JDK 17 for deploy to Sonatype
16+
uses: actions/setup-java@v3
17+
with:
18+
distribution: 'adopt'
19+
java-version: 17
20+
server-id: central
21+
server-username: MAVEN_USERNAME
22+
server-password: MAVEN_CENTRAL_TOKEN
23+
gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY }}
24+
gpg-passphrase: MAVEN_GPG_PASSPHRASE
25+
26+
- name: Build with Maven
27+
run: mvn -B package --file pom.xml
28+
29+
- name: Prepare Maven environnement with Java 17 for deployment to Sonatype
30+
run: export MAVEN_OPTS="--add-opens=java.base/java.util=ALL-UNNAMED --add-opens=java.base/java.lang.reflect=ALL-UNNAMED --add-opens=java.base/java.text=ALL-UNNAMED --add-opens=java.desktop/java.awt.font=ALL-UNNAMED"
31+
32+
- name: Publish to Apache Maven Central
33+
run: mvn deploy -PsonatypeDeploy
34+
env:
35+
MAVEN_USERNAME: ${{ secrets.NEXUS_USERNAME }}
36+
MAVEN_CENTRAL_TOKEN: ${{ secrets.NEXUS_PASSWORD }}
37+
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PASSPHRASE }}

.gitignore

Lines changed: 28 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,33 @@
1-
# Compiled class file
2-
*.class
1+
### IntelliJ IDEA ###
2+
out/
3+
!**/src/main/**/out/
4+
!**/src/test/**/out/
5+
.idea/
36

4-
# Log file
5-
*.log
7+
### Eclipse ###
8+
.apt_generated
9+
.classpath
10+
.factorypath
11+
.project
12+
.settings
13+
.springBeans
14+
.sts4-cache
15+
bin/
16+
!**/src/main/**/bin/
17+
!**/src/test/**/bin/
618

7-
# BlueJ files
8-
*.ctxt
19+
### NetBeans ###
20+
/nbproject/private/
21+
/nbbuild/
22+
/dist/
23+
/nbdist/
24+
/.nb-gradle/
925

10-
# Mobile Tools for Java (J2ME)
11-
.mtj.tmp/
26+
### VS Code ###
27+
.vscode/
1228

13-
# Package Files #
14-
*.jar
15-
*.war
16-
*.nar
17-
*.ear
18-
*.zip
19-
*.tar.gz
20-
*.rar
29+
### Mac OS ###
30+
.DS_Store
2131

22-
# virtual machine crash logs, see http://www.java.com/en/download/help/error_hotspot.xml
23-
hs_err_pid*
24-
replay_pid*
32+
### maven ??###
33+
target

README.md

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# Uso de librería bennu-commons
2+
3+
Para usar esta librería en los proyectos de Maven debes incluir el siguiente bloque:
4+
5+
```
6+
<dependency>
7+
<groupId>cl.bennu</groupId>
8+
<artifactId>mybatis-commons</artifactId>
9+
<version>0.0.1</version>
10+
</dependency>
11+
```
12+
13+
### Esta librería cuenta con las siguientes dependencias:
14+
15+
- lombok 1.18.36
16+
- jackson-core 2.18.2
17+
- jackson-annotations 2.18.2
18+
- commons-lang3 3.17.0
19+
- commons-io 2.18.0
20+
- java-jwt 4.4.0
21+
- commons-beanutils 1.10.0
22+
- commons-collections4 4.5.0-M3
23+
- slf4j-api 2.0.16

pom.xml

Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
<?xml version="1.0"?>
2+
<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"
3+
xmlns="http://maven.apache.org/POM/4.0.0"
4+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
5+
6+
<modelVersion>4.0.0</modelVersion>
7+
8+
<groupId>cl.bennu</groupId>
9+
<artifactId>mybatis-commons</artifactId>
10+
<version>0.0.1</version>
11+
<name>bennu-mybatis-commons</name>
12+
<description>Utilitarios bennu para MyBatis</description>
13+
<url>https://github.com/bennu/mybatis-commons</url>
14+
15+
<licenses>
16+
<license>
17+
<name>MIT License</name>
18+
<url>http://www.opensource.org/licenses/mit-license.php</url>
19+
</license>
20+
</licenses>
21+
22+
<developers>
23+
<developer>
24+
<name>Bennu</name>
25+
<email>[email protected]</email>
26+
<url>https://bennu.cl/</url>
27+
<organization>Bennu SpA</organization>
28+
<organizationUrl>https://github.com/bennu</organizationUrl>
29+
</developer>
30+
</developers>
31+
32+
<scm>
33+
<connection>scm:git:[email protected]:bennu/mybatis-commons.git</connection>
34+
<developerConnection>scm:git:[email protected]:bennu/mybatis-commons.git</developerConnection>
35+
<url>[email protected]:bennu/mybatis-commons.git</url>
36+
</scm>
37+
38+
<properties>
39+
<java.version>17</java.version>
40+
<maven.compiler.release>17</maven.compiler.release>
41+
<maven.compiler.source>17</maven.compiler.source>
42+
<maven.compiler.target>17</maven.compiler.target>
43+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
44+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
45+
</properties>
46+
47+
<dependencies>
48+
<dependency>
49+
<groupId>cl.bennu</groupId>
50+
<artifactId>commons</artifactId>
51+
<version>0.1.0</version>
52+
</dependency>
53+
<dependency>
54+
<groupId>org.mybatis</groupId>
55+
<artifactId>mybatis</artifactId>
56+
<version>3.5.19</version>
57+
</dependency>
58+
</dependencies>
59+
60+
</project>
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
package cl.bennu.commons.enums.handler;
2+
3+
import cl.bennu.commons.enums.base.BaseEnum;
4+
import cl.bennu.commons.exception.NoDataException;
5+
import org.apache.ibatis.type.JdbcType;
6+
import org.apache.ibatis.type.MappedTypes;
7+
import org.apache.ibatis.type.TypeHandler;
8+
9+
import java.sql.*;
10+
11+
@MappedTypes(BaseEnum.class)
12+
public class EnumTypeHandler<T> implements TypeHandler<BaseEnum> {
13+
14+
private final Class<T> clazz;
15+
16+
public EnumTypeHandler(Class<T> clazz) throws NoDataException {
17+
if (clazz == null) throw new NoDataException("No class defined");
18+
this.clazz = clazz;
19+
}
20+
21+
public BaseEnum findEnum(Integer id) {
22+
BaseEnum[] enums = (BaseEnum[]) clazz.getEnumConstants();
23+
for (BaseEnum baseEnum : enums) {
24+
if (baseEnum.getId().equals(id)) {
25+
return baseEnum;
26+
}
27+
}
28+
return null;
29+
}
30+
31+
@Override
32+
public void setParameter(PreparedStatement ps, int i, BaseEnum parameter, JdbcType jdbcType) throws SQLException {
33+
if (parameter == null) {
34+
ps.setNull(i, Types.INTEGER);
35+
} else {
36+
ps.setInt(i, parameter.getId());
37+
}
38+
}
39+
40+
@Override
41+
public BaseEnum getResult(ResultSet rs, String columnName) throws SQLException {
42+
int value = rs.getInt(columnName);
43+
return value == 0 ? null : findEnum(value);
44+
}
45+
46+
@Override
47+
public BaseEnum getResult(ResultSet rs, int columnIndex) throws SQLException {
48+
int value = rs.getInt(columnIndex);
49+
return value == 0 ? null : findEnum(value);
50+
}
51+
52+
@Override
53+
public BaseEnum getResult(CallableStatement cs, int columnIndex) throws SQLException {
54+
int value = cs.getInt(columnIndex);
55+
return value == 0 ? null : findEnum(value);
56+
}
57+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package cl.bennu.commons.mapper;
2+
3+
import cl.bennu.commons.domain.base.BaseDomain;
4+
import cl.bennu.commons.mapper.base.BaseMapper;
5+
import org.apache.ibatis.annotations.Mapper;
6+
7+
@Mapper
8+
public interface ExampleMapper extends BaseMapper<BaseDomain> {
9+
10+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package cl.bennu.commons.mapper.base;
2+
3+
import cl.bennu.commons.domain.base.BaseDomain;
4+
5+
import java.util.List;
6+
7+
public interface BaseMapper<T extends BaseDomain> {
8+
9+
List<T> getAll();
10+
11+
List<T> find(T type);
12+
13+
T get(Long id);
14+
15+
T getByName(String name);
16+
17+
void insert(T type);
18+
19+
void update(T type);
20+
21+
void delete(Long id);
22+
23+
}

0 commit comments

Comments
 (0)