remove SessionFactory and prepare for creating an EntityManagerFactory
This commit is contained in:
@@ -19,13 +19,18 @@ dependencies {
|
|||||||
implementation libs.hypersistence
|
implementation libs.hypersistence
|
||||||
implementation libs.validation.api
|
implementation libs.validation.api
|
||||||
annotationProcessor libs.hibernate.jpamodelgen
|
annotationProcessor libs.hibernate.jpamodelgen
|
||||||
|
implementation libs.el
|
||||||
|
annotationProcessor libs.openapi.annotation
|
||||||
|
implementation libs.javalin.openapi
|
||||||
|
implementation libs.javalin.swagger
|
||||||
|
implementation libs.javalin.redoc
|
||||||
testImplementation(platform(libs.junit.bom))
|
testImplementation(platform(libs.junit.bom))
|
||||||
testImplementation "org.junit.jupiter:junit-jupiter"
|
testImplementation "org.junit.jupiter:junit-jupiter"
|
||||||
}
|
}
|
||||||
|
|
||||||
task fatJar(type: Jar) {
|
task fatJar(type: Jar) {
|
||||||
manifest {
|
manifest {
|
||||||
attributes 'Main-Class': 'de.thpeetz.kontor.api.Main'
|
attributes 'Main-Class': 'de.thpeetz.kontor.Main'
|
||||||
}
|
}
|
||||||
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
duplicatesStrategy = DuplicatesStrategy.EXCLUDE
|
||||||
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
|
from { configurations.runtimeClasspath.collect { it.isDirectory() ? it : zipTree(it) } }
|
||||||
|
|||||||
@@ -14,6 +14,8 @@ postgresql = "42.7.3"
|
|||||||
hibernate = "7.0.5.Final"
|
hibernate = "7.0.5.Final"
|
||||||
validation = "2.0.1.Final"
|
validation = "2.0.1.Final"
|
||||||
hypersistence = "3.14.1"
|
hypersistence = "3.14.1"
|
||||||
|
el = "4.0.1"
|
||||||
|
openapi = "6.7.0-3"
|
||||||
|
|
||||||
[libraries]
|
[libraries]
|
||||||
junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
|
junit = { module = "org.junit.jupiter:junit-jupiter", version.ref = "junit" }
|
||||||
@@ -30,4 +32,9 @@ hibernate = { module = "org.hibernate.orm:hibernate-core", version.ref = "hibern
|
|||||||
hibernate-jpamodelgen = { module = "org.hibernate.orm:hibernate-jpamodelgen", version.ref = "hibernate" }
|
hibernate-jpamodelgen = { module = "org.hibernate.orm:hibernate-jpamodelgen", version.ref = "hibernate" }
|
||||||
hibernate-validator = { module = "org.hibernate:hibernate-validator", version.ref = "hibernate" }
|
hibernate-validator = { module = "org.hibernate:hibernate-validator", version.ref = "hibernate" }
|
||||||
validation-api = { module = "javax.validation:validation-api", version.ref = "validation" }
|
validation-api = { module = "javax.validation:validation-api", version.ref = "validation" }
|
||||||
|
el = { module = "org.glassfish:jakarta.el", version.ref = "el" }
|
||||||
hypersistence = { module = "io.hypersistence:hypersistence-utils-hibernate-70", version.ref = "hypersistence" }
|
hypersistence = { module = "io.hypersistence:hypersistence-utils-hibernate-70", version.ref = "hypersistence" }
|
||||||
|
javalin-openapi = { module = "io.javalin.community.openapi:javalin-openapi-plugin", version.ref = "openapi" }
|
||||||
|
javalin-swagger = { module = "io.javalin.community.openapi:javalin-swagger-plugin", version.ref = "openapi" }
|
||||||
|
javalin-redoc = { module = "io.javalin.community.openapi:javalin-redoc-plugin", version.ref = "openapi" }
|
||||||
|
openapi-annotation = { module = "io.javalin.community.openapi:openapi-annotation-processor", version.ref = "openapi" }
|
||||||
@@ -1,33 +0,0 @@
|
|||||||
package de.thpeetz.kontor;
|
|
||||||
|
|
||||||
import io.javalin.Javalin;
|
|
||||||
|
|
||||||
import static io.javalin.apibuilder.ApiBuilder.get;
|
|
||||||
import static io.javalin.apibuilder.ApiBuilder.path;
|
|
||||||
import static io.javalin.apibuilder.ApiBuilder.post;
|
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import de.thpeetz.kontor.web.ComicHandler;
|
|
||||||
import de.thpeetz.kontor.web.MediaFileHandler;
|
|
||||||
|
|
||||||
public class JavalinApp {
|
|
||||||
|
|
||||||
public static Javalin create() {
|
|
||||||
return Javalin.create((var config) -> config.router.apiBuilder(() -> {
|
|
||||||
path("/", () -> get(ctx -> ctx.json("Ok")));
|
|
||||||
path("health", () -> get(ctx -> {
|
|
||||||
HashMap<String, String> status = new HashMap<>();
|
|
||||||
status.put("status", "ok");
|
|
||||||
ctx.json(status);
|
|
||||||
}));
|
|
||||||
path("/api/v1/comics", () -> {
|
|
||||||
get(ComicHandler.listAll);
|
|
||||||
});
|
|
||||||
path("/api/v1/media/files", () -> {
|
|
||||||
get(MediaFileHandler.listAll);
|
|
||||||
post(MediaFileHandler.save);
|
|
||||||
});
|
|
||||||
}));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -1,14 +1,52 @@
|
|||||||
package de.thpeetz.kontor;
|
package de.thpeetz.kontor;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.LinkedList;
|
||||||
|
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
|
import de.thpeetz.kontor.infrastructure.AppHibernateConfig;
|
||||||
|
import io.javalin.Javalin;
|
||||||
|
import jakarta.persistence.EntityManager;
|
||||||
|
|
||||||
public class Main {
|
public class Main {
|
||||||
private static Logger logger = LoggerFactory.getLogger(Main.class);
|
private static Logger logger = LoggerFactory.getLogger(Main.class);
|
||||||
private static short port = 8400;
|
private static short port = 8400;
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
JavalinApp.create().start(port);
|
Javalin app = Javalin.create(config -> {
|
||||||
|
config.requestLogger.http((ctx, ms) -> {
|
||||||
|
var path = ctx.path();
|
||||||
|
if (!path.equals("/health")) {
|
||||||
|
logger.info(ctx.path());
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
|
app.get("/", ctx -> ctx.json("Ok"));
|
||||||
|
app.get("/health", ctx -> {
|
||||||
|
HashMap<String, String> status = new HashMap<>();
|
||||||
|
status.put("status", "ok");
|
||||||
|
ctx.json(status);
|
||||||
|
});
|
||||||
|
app.get("/api/v1/comics", ctx -> {
|
||||||
|
var result = new LinkedList<>();
|
||||||
|
ctx.json(result);
|
||||||
|
});
|
||||||
|
app.get("/api/v1/media/files", ctx -> {
|
||||||
|
var result = new LinkedList<>();
|
||||||
|
ctx.json(result);
|
||||||
|
});
|
||||||
|
app.before(ctx -> {
|
||||||
|
ctx.attribute("configuration", AppHibernateConfig.configuration());
|
||||||
|
});
|
||||||
|
app.after(ctx -> {
|
||||||
|
EntityManager entityManager = ctx.attribute("entityManager");
|
||||||
|
if (entityManager != null) {
|
||||||
|
entityManager.close();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
app.start(port);
|
||||||
|
|
||||||
logger.info("API's alive for real :-)");
|
logger.info("API's alive for real :-)");
|
||||||
}
|
}
|
||||||
|
|||||||
+2
-2
@@ -22,8 +22,8 @@ import de.thpeetz.kontor.models.media.MediaArticle;
|
|||||||
import de.thpeetz.kontor.models.media.MediaFile;
|
import de.thpeetz.kontor.models.media.MediaFile;
|
||||||
import de.thpeetz.kontor.models.media.MediaVideo;
|
import de.thpeetz.kontor.models.media.MediaVideo;
|
||||||
|
|
||||||
class AppHibernateConfig {
|
public class AppHibernateConfig {
|
||||||
static Configuration configuration() {
|
public static Configuration configuration() {
|
||||||
var configuration = new Configuration();
|
var configuration = new Configuration();
|
||||||
var settings = new Properties();
|
var settings = new Properties();
|
||||||
settings.put(AvailableSettings.JAKARTA_JDBC_DRIVER, "org.postgresql.Driver");
|
settings.put(AvailableSettings.JAKARTA_JDBC_DRIVER, "org.postgresql.Driver");
|
||||||
|
|||||||
+2
-2
@@ -7,13 +7,13 @@ import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
|||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
class AppHibernateSessionFactory {
|
public class AppHibernateSessionFactory {
|
||||||
|
|
||||||
private static final Logger logger = LoggerFactory.getLogger(AppHibernateSessionFactory.class);
|
private static final Logger logger = LoggerFactory.getLogger(AppHibernateSessionFactory.class);
|
||||||
|
|
||||||
private static SessionFactory sessionFactory;
|
private static SessionFactory sessionFactory;
|
||||||
|
|
||||||
static SessionFactory getSessionFactory() {
|
public static SessionFactory getSessionFactory() {
|
||||||
if (Objects.isNull(sessionFactory)) {
|
if (Objects.isNull(sessionFactory)) {
|
||||||
try {
|
try {
|
||||||
var configuration = AppHibernateConfig.configuration();
|
var configuration = AppHibernateConfig.configuration();
|
||||||
|
|||||||
@@ -43,16 +43,13 @@ public class Comic {
|
|||||||
@Column(unique = true, nullable = false)
|
@Column(unique = true, nullable = false)
|
||||||
private String title;
|
private String title;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "publisher_id")
|
@JoinColumn(name = "publisher_id", nullable = false)
|
||||||
@JsonIgnoreProperties({ "comics" })
|
@JsonIgnoreProperties({ "comics" })
|
||||||
private Publisher publisher;
|
private Publisher publisher;
|
||||||
|
|
||||||
@Column
|
|
||||||
private Boolean currentOrder = false;
|
private Boolean currentOrder = false;
|
||||||
|
|
||||||
@Column
|
|
||||||
private Boolean completed = false;
|
private Boolean completed = false;
|
||||||
|
|
||||||
@Column(nullable = true)
|
@Column(nullable = true)
|
||||||
|
|||||||
@@ -29,19 +29,16 @@ public class ComicWork {
|
|||||||
@Column(name = "last_modified_date")
|
@Column(name = "last_modified_date")
|
||||||
private Date lastModifiedDate;
|
private Date lastModifiedDate;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "comic_id")
|
@JoinColumn(name = "comic_id", nullable = false)
|
||||||
private Comic comic;
|
private Comic comic;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "artist_id")
|
@JoinColumn(name = "artist_id", nullable = false)
|
||||||
private Artist artist;
|
private Artist artist;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "workType_id")
|
@JoinColumn(name = "workType_id", nullable = false)
|
||||||
private Worktype workType;
|
private Worktype workType;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -42,21 +42,18 @@ public class Issue {
|
|||||||
@Column(name = "last_modified_date")
|
@Column(name = "last_modified_date")
|
||||||
private Date lastModifiedDate;
|
private Date lastModifiedDate;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "comic_id")
|
@JoinColumn(name = "comic_id", nullable = false)
|
||||||
@JsonIgnoreProperties({ "issues" })
|
@JsonIgnoreProperties({ "issues" })
|
||||||
private Comic comic;
|
private Comic comic;
|
||||||
|
|
||||||
@Column(nullable = true)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "volume_id")
|
@JoinColumn(name = "volume_id", nullable = true)
|
||||||
@JsonIgnoreProperties({ "issues" })
|
@JsonIgnoreProperties({ "issues" })
|
||||||
private Volume volume;
|
private Volume volume;
|
||||||
|
|
||||||
@Column(nullable = true)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "storyArc_id")
|
@JoinColumn(name = "storyArc_id", nullable = true)
|
||||||
@JsonIgnoreProperties({ "issues" })
|
@JsonIgnoreProperties({ "issues" })
|
||||||
private StoryArc storyArc;
|
private StoryArc storyArc;
|
||||||
|
|
||||||
|
|||||||
@@ -33,19 +33,16 @@ public class IssueWork {
|
|||||||
@Column(name = "last_modified_date")
|
@Column(name = "last_modified_date")
|
||||||
private Date lastModifiedDate;
|
private Date lastModifiedDate;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "issue_id")
|
@JoinColumn(name = "issue_id", nullable = false)
|
||||||
private Issue issue;
|
private Issue issue;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "artist_id")
|
@JoinColumn(name = "artist_id", nullable = false)
|
||||||
private Artist artist;
|
private Artist artist;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "workType_id")
|
@JoinColumn(name = "workType_id", nullable = false)
|
||||||
private Worktype workType;
|
private Worktype workType;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|||||||
@@ -44,13 +44,11 @@ public class Publisher {
|
|||||||
@Column(unique = true, nullable = false)
|
@Column(unique = true, nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column
|
|
||||||
private String weblink;
|
private String weblink;
|
||||||
|
|
||||||
@Column(nullable = true)
|
|
||||||
@JsonBackReference
|
@JsonBackReference
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "parent_publisher_id")
|
@JoinColumn(name = "parent_publisher_id", nullable = true)
|
||||||
@JsonIgnoreProperties({ "comics" })
|
@JsonIgnoreProperties({ "comics" })
|
||||||
private Publisher parentCompany;
|
private Publisher parentCompany;
|
||||||
|
|
||||||
|
|||||||
@@ -43,15 +43,13 @@ public class StoryArc {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "comic_id")
|
@JoinColumn(name = "comic_id", nullable = false)
|
||||||
@JsonIgnoreProperties({ "storyArcs" })
|
@JsonIgnoreProperties({ "storyArcs" })
|
||||||
private Comic comic;
|
private Comic comic;
|
||||||
|
|
||||||
@Column(nullable = true)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "volume_id")
|
@JoinColumn(name = "volume_id", nullable = true)
|
||||||
@JsonIgnoreProperties({ "storyArcs" })
|
@JsonIgnoreProperties({ "storyArcs" })
|
||||||
private Volume volume;
|
private Volume volume;
|
||||||
|
|
||||||
|
|||||||
@@ -36,13 +36,13 @@ public class TradePaperback {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "comic_id")
|
@JoinColumn(name = "comic_id", nullable = false)
|
||||||
private Comic comic;
|
private Comic comic;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
private Integer issueStart;
|
private Integer issueStart;
|
||||||
|
|
||||||
@Column
|
@Column
|
||||||
private Integer issueEnd;}
|
private Integer issueEnd;
|
||||||
|
}
|
||||||
|
|||||||
@@ -43,9 +43,8 @@ public class Volume {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String name;
|
private String name;
|
||||||
|
|
||||||
@Column(nullable = false)
|
|
||||||
@ManyToOne
|
@ManyToOne
|
||||||
@JoinColumn(name = "comic_id")
|
@JoinColumn(name = "comic_id", nullable = false)
|
||||||
@JsonIgnoreProperties({ "volumes" })
|
@JsonIgnoreProperties({ "volumes" })
|
||||||
private Comic comic;
|
private Comic comic;
|
||||||
|
|
||||||
|
|||||||
@@ -1,20 +1,19 @@
|
|||||||
package de.thpeetz.kontor.web;
|
package de.thpeetz.kontor.web;
|
||||||
|
|
||||||
|
import java.util.LinkedList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import de.thpeetz.kontor.infrastructure.AppHibernate;
|
import de.thpeetz.kontor.infrastructure.AppHibernate;
|
||||||
import io.javalin.http.Handler;
|
import io.javalin.http.Handler;
|
||||||
import io.javalin.http.HttpStatus;
|
import io.javalin.http.HttpStatus;
|
||||||
import de.thpeetz.kontor.models.media.MediaFile;
|
import de.thpeetz.kontor.models.media.MediaFile;
|
||||||
import de.thpeetz.kontor.models.media.MediaFileQueries;
|
|
||||||
import de.thpeetz.kontor.models.media.MediaFileQueries_;
|
|
||||||
import de.thpeetz.kontor.web.model.NewMediaFile;
|
import de.thpeetz.kontor.web.model.NewMediaFile;
|
||||||
import de.thpeetz.kontor.web.model.ResultMediaFile;
|
import de.thpeetz.kontor.web.model.ResultMediaFile;
|
||||||
|
|
||||||
public class MediaFileHandler {
|
public class MediaFileHandler {
|
||||||
|
|
||||||
public static Handler listAll = (context) -> {
|
public static Handler listAll = (context) -> {
|
||||||
List<MediaFile> result = AppHibernate.fromTransaction(MediaFileQueries_::getAllMediaFiles);
|
List<MediaFile> result = new LinkedList<>();
|
||||||
context.json(new ResultMediaFile(result));
|
context.json(new ResultMediaFile(result));
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user