-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #42 from LinuxCounter/41_jpa_layer
[#41] basic JPA layer
- Loading branch information
Showing
19 changed files
with
251 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
8 changes: 8 additions & 0 deletions
8
...pi/src/main/java/io/github/linuxcounter/repository/api/AnonymousReportDataRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package io.github.linuxcounter.repository.api; | ||
|
||
import io.github.linuxcounter.common.value.AnonymousReportData; | ||
|
||
public interface AnonymousReportDataRepository { | ||
|
||
void countAnonymous(AnonymousReportData reportData); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
module linuxcounter.repository.api { | ||
exports io.github.linuxcounter.repository.api; | ||
|
||
requires linuxcounter.common.value; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
17 changes: 17 additions & 0 deletions
17
...ain/java/io/github/linuxcounter/repository/impl/jpa/AnonymousReportDataJpaRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package io.github.linuxcounter.repository.impl.jpa; | ||
|
||
import io.github.linuxcounter.common.value.AnonymousReportData; | ||
import io.github.linuxcounter.repository.api.AnonymousReportDataRepository; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.persistence.EntityManager; | ||
|
||
@ApplicationScoped | ||
public class AnonymousReportDataJpaRepository extends JpaBaseRepository implements AnonymousReportDataRepository { | ||
|
||
@Override | ||
public void countAnonymous(AnonymousReportData reportData) { | ||
final EntityManager em = getEntityManager(); | ||
throw new UnsupportedOperationException( | ||
"not yet implemented: [io.github.linuxcounter.repository.impl.jpa.AnonymousReportDataJpaRepository::countAnonymous]."); | ||
} | ||
} |
25 changes: 25 additions & 0 deletions
25
.../impl/jpa/src/main/java/io/github/linuxcounter/repository/impl/jpa/JpaBaseRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.github.linuxcounter.repository.impl.jpa; | ||
|
||
import javax.persistence.EntityManager; | ||
import javax.persistence.PersistenceContext; | ||
|
||
public class JpaBaseRepository { | ||
|
||
@PersistenceContext(unitName = "unixcounter") | ||
private EntityManager entityManager; | ||
|
||
public JpaBaseRepository() { | ||
} | ||
|
||
public JpaBaseRepository(EntityManager entityManager) { | ||
this.entityManager = entityManager; | ||
} | ||
|
||
public EntityManager getEntityManager() { | ||
return entityManager; | ||
} | ||
|
||
public void setEntityManager(EntityManager entityManager) { | ||
this.entityManager = entityManager; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
module linuxcounter.repository.impl.jpa { | ||
exports io.github.linuxcounter.repository.impl.jpa; | ||
|
||
requires jakarta.enterprise.cdi.api; | ||
requires linuxcounter.common.value; | ||
requires linuxcounter.repository.api; | ||
requires java.persistence; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<beans> | ||
<trim /> | ||
</beans> |
20 changes: 20 additions & 0 deletions
20
repository/impl/jpa/src/main/resources/META-INF/persistence.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<persistence xmlns="http://xmlns.jcp.org/xml/ns/persistence" | ||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/persistence http://xmlns.jcp.org/xml/ns/persistence/persistence_2_2.xsd" | ||
version="2.2"> | ||
<persistence-unit name="unixcounter" | ||
transaction-type="JTA"> | ||
<description> | ||
Persistence unit for the JPA tutorial of the Hibernate Getting Started Guide | ||
</description> | ||
|
||
<exclude-unlisted-classes>false</exclude-unlisted-classes> | ||
|
||
<properties> | ||
<property name="javax.persistence.schema-generation.database.action" | ||
value="none" /> | ||
</properties> | ||
|
||
</persistence-unit> | ||
|
||
</persistence> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
12 changes: 9 additions & 3 deletions
12
services/impl/src/main/java/io/github/linuxcounter/services/impl/CounterServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,22 @@ | ||
package io.github.linuxcounter.services.impl; | ||
|
||
import io.github.linuxcounter.common.value.AnonymousReportData; | ||
import io.github.linuxcounter.repository.api.AnonymousReportDataRepository; | ||
import io.github.linuxcounter.services.api.CounterService; | ||
import javax.enterprise.context.ApplicationScoped; | ||
import javax.inject.Inject; | ||
import javax.transaction.Transactional; | ||
|
||
|
||
@ApplicationScoped | ||
public class CounterServiceImpl implements CounterService { | ||
|
||
@Inject | ||
AnonymousReportDataRepository anonymousReportDataRepository; | ||
|
||
@Override | ||
@Transactional | ||
public void countAnonymous(AnonymousReportData reportData) { | ||
// TODO: implement | ||
throw new UnsupportedOperationException( | ||
"not yet implemented: [io.github.linuxcounter.services.impl.CounterServiceImpl::countAnonymous]."); | ||
anonymousReportDataRepository.countAnonymous(reportData); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
9 changes: 8 additions & 1 deletion
9
web/rest-v1/src/main/java/io/github/linuxcounter/web/rest/v1/config/JsonbConfigurator.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 25 additions & 0 deletions
25
...main/java/io/github/linuxcounter/web/rest/v1/err/UnsupportedOperationExceptionMapper.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package io.github.linuxcounter.web.rest.v1.err; | ||
|
||
import java.util.Map; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
import javax.ws.rs.core.Response.Status; | ||
import javax.ws.rs.ext.ExceptionMapper; | ||
import javax.ws.rs.ext.Provider; | ||
|
||
@Provider | ||
@Produces(MediaType.APPLICATION_JSON) | ||
public class UnsupportedOperationExceptionMapper implements ExceptionMapper<UnsupportedOperationException> { | ||
|
||
@Override | ||
public Response toResponse(UnsupportedOperationException exception) { | ||
Map<String, Object> responseEntity = Map.of( | ||
"message", exception.getMessage() | ||
); | ||
|
||
return Response.status(Status.NOT_IMPLEMENTED) | ||
.entity(responseEntity) | ||
.build(); | ||
} | ||
} |
34 changes: 34 additions & 0 deletions
34
...rest-v1/src/main/java/io/github/linuxcounter/web/rest/v1/json/AnonymousRecordAdapter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
package io.github.linuxcounter.web.rest.v1.json; | ||
|
||
import io.github.linuxcounter.common.value.AnonymousReportData; | ||
import io.github.linuxcounter.common.value.HardwareId; | ||
import javax.json.Json; | ||
import javax.json.JsonObject; | ||
import javax.json.bind.adapter.JsonbAdapter; | ||
|
||
public class AnonymousRecordAdapter implements JsonbAdapter<AnonymousReportData, JsonObject> { | ||
|
||
@Override | ||
public JsonObject adaptToJson(AnonymousReportData obj) throws Exception { | ||
return Json.createObjectBuilder() | ||
.add("kernel_name", obj.kernelName()) | ||
.add("kernel_version", obj.kernelVersion()) | ||
.add("distribution_name", obj.distributionName()) | ||
.add("distribution_version", obj.distributionVersion()) | ||
.add("timezone", obj.timezone()) | ||
.add("hardware_id", obj.hardwareId().value()) | ||
.build(); | ||
} | ||
|
||
@Override | ||
public AnonymousReportData adaptFromJson(JsonObject obj) throws Exception { | ||
return new AnonymousReportData( | ||
obj.getString("kernel_name"), | ||
obj.getString("kernel_version"), | ||
obj.getString("distribution_name"), | ||
obj.getString("distribution_version"), | ||
obj.getString("timezone"), | ||
new HardwareId(obj.getString("hardware_id")) | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.