Vorbereitung Release 0.2.0 #83
@@ -3,16 +3,23 @@ package de.thpeetz.kontor;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedList;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import de.thpeetz.kontor.infrastructure.AppHibernateConfig;
|
||||
import de.thpeetz.kontor.infrastructure.AppHibernateSessionFactory;
|
||||
import de.thpeetz.kontor.models.comics.Comic;
|
||||
import de.thpeetz.kontor.models.media.MediaFile;
|
||||
import io.javalin.Javalin;
|
||||
import jakarta.persistence.EntityManager;
|
||||
import io.javalin.config.Key;
|
||||
//import jakarta.persistence.EntityManager;
|
||||
|
||||
public class Main {
|
||||
private static Logger logger = LoggerFactory.getLogger(Main.class);
|
||||
private static short port = 8400;
|
||||
// private static Key<EntityManagerFactory> emf = new
|
||||
// Key<EntityManagerFactory>("entityManagerFactory");
|
||||
private static Key<SessionFactory> sf = new Key<>("SessionFactory");
|
||||
|
||||
public static void main(String[] args) {
|
||||
Javalin app = Javalin.create(config -> {
|
||||
@@ -22,6 +29,7 @@ public class Main {
|
||||
logger.info(ctx.path());
|
||||
}
|
||||
});
|
||||
config.appData(sf, AppHibernateSessionFactory.getSessionFactory());
|
||||
});
|
||||
app.get("/", ctx -> ctx.json("Ok"));
|
||||
app.get("/health", ctx -> {
|
||||
@@ -30,21 +38,49 @@ public class Main {
|
||||
ctx.json(status);
|
||||
});
|
||||
app.get("/api/v1/comics", ctx -> {
|
||||
var result = new LinkedList<>();
|
||||
var result = new LinkedList<Comic>();
|
||||
ctx.appData(sf).inStatelessTransaction(session -> {
|
||||
session.createSelectionQuery("from Comic", Comic.class).getResultList().forEach(comic -> {
|
||||
result.add(comic);
|
||||
});
|
||||
});
|
||||
// var em = ctx.appData(emf).createEntityManager();
|
||||
// logger.info(em.toString());
|
||||
// EntityManager entityManager = ctx.attribute("entityManager");
|
||||
// entityManager.createQuery("select * from Comic",
|
||||
// Comic.class).getResultList().forEach(comic -> {
|
||||
// result.add(comic);
|
||||
// });
|
||||
ctx.json(result);
|
||||
});
|
||||
app.get("/api/v1/media/files", ctx -> {
|
||||
var result = new LinkedList<>();
|
||||
// ctx.appData(sf).inStatelessTransaction(session -> {
|
||||
// var files = session.createSelectionQuery("from MediaFile",
|
||||
// MediaFile.class).getResultList();
|
||||
// result.addAll(files);
|
||||
// });
|
||||
var list = ctx.appData(sf).openStatelessSession().createSelectionQuery("from MediaFile", MediaFile.class)
|
||||
.getResultList();
|
||||
result.addAll(list);
|
||||
ctx.json(result);
|
||||
});
|
||||
app.before(ctx -> {
|
||||
ctx.attribute("configuration", AppHibernateConfig.configuration());
|
||||
});
|
||||
// app.before(ctx -> {
|
||||
// ctx.attribute("configuration", AppHibernateConfig.configuration());
|
||||
// ctx.attribute("sessionFactory",
|
||||
// AppHibernateSessionFactory.getSessionFactory());
|
||||
// });
|
||||
app.after(ctx -> {
|
||||
EntityManager entityManager = ctx.attribute("entityManager");
|
||||
if (entityManager != null) {
|
||||
entityManager.close();
|
||||
}
|
||||
// SessionFactory sessionFactory = ctx.attribute("sessionFactory");
|
||||
// if (sessionFactory != null) {
|
||||
// logger.info("close SessionFactory");
|
||||
// sessionFactory.close();
|
||||
// }
|
||||
// EntityManager entityManager = ctx.attribute("entityManager");
|
||||
// if (entityManager != null) {
|
||||
// logger.info("close EntityManager");
|
||||
// entityManager.close();
|
||||
// }
|
||||
});
|
||||
app.start(port);
|
||||
|
||||
|
||||
+1
-1
@@ -31,7 +31,7 @@ public class AppHibernateConfig {
|
||||
settings.put(AvailableSettings.JAKARTA_JDBC_USER, "kontor");
|
||||
settings.put(AvailableSettings.JAKARTA_JDBC_PASSWORD, "kontor");
|
||||
settings.put(AvailableSettings.HIGHLIGHT_SQL, true);
|
||||
settings.put(AvailableSettings.HBM2DDL_AUTO, Action.ACTION_CREATE);
|
||||
settings.put(AvailableSettings.HBM2DDL_AUTO, Action.ACTION_UPDATE);
|
||||
|
||||
configuration.setProperties(settings);
|
||||
configuration.addAnnotatedClass(MediaFile.class);
|
||||
|
||||
+8
-5
@@ -3,6 +3,7 @@ package de.thpeetz.kontor.infrastructure;
|
||||
import java.util.Objects;
|
||||
|
||||
import org.hibernate.SessionFactory;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistry;
|
||||
import org.hibernate.boot.registry.StandardServiceRegistryBuilder;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -15,14 +16,16 @@ public class AppHibernateSessionFactory {
|
||||
|
||||
public static SessionFactory getSessionFactory() {
|
||||
if (Objects.isNull(sessionFactory)) {
|
||||
var configuration = AppHibernateConfig.configuration();
|
||||
final StandardServiceRegistry registry = new StandardServiceRegistryBuilder()
|
||||
.applySettings(configuration.getProperties())
|
||||
.build();
|
||||
try {
|
||||
var configuration = AppHibernateConfig.configuration();
|
||||
var serviceRegistry = new StandardServiceRegistryBuilder()
|
||||
.applySettings(configuration.getProperties())
|
||||
.build();
|
||||
sessionFactory = configuration.buildSessionFactory(serviceRegistry);
|
||||
sessionFactory = configuration.buildSessionFactory(registry);
|
||||
logger.info("SessionFactory created");
|
||||
} catch (Throwable ex) {
|
||||
logger.error("Failed to create session factory", ex);
|
||||
StandardServiceRegistryBuilder.destroy(registry);
|
||||
}
|
||||
}
|
||||
return sessionFactory;
|
||||
|
||||
@@ -48,6 +48,7 @@ public class Comic {
|
||||
@JsonIgnoreProperties({ "comics" })
|
||||
private Publisher publisher;
|
||||
|
||||
@Column(name = "current_order")
|
||||
private Boolean currentOrder = false;
|
||||
|
||||
private Boolean completed = false;
|
||||
|
||||
@@ -13,7 +13,7 @@ import jakarta.persistence.Table;
|
||||
import jakarta.persistence.Version;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
@Table(name = "comic_work")
|
||||
public class ComicWork {
|
||||
|
||||
@Id
|
||||
@@ -38,7 +38,7 @@ public class ComicWork {
|
||||
private Artist artist;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "workType_id", nullable = false)
|
||||
@JoinColumn(name = "work_type_id", nullable = false)
|
||||
private Worktype workType;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -53,11 +53,11 @@ public class Issue {
|
||||
private Volume volume;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "storyArc_id", nullable = true)
|
||||
@JoinColumn(name = "story_arc_id", nullable = true)
|
||||
@JsonIgnoreProperties({ "issues" })
|
||||
private StoryArc storyArc;
|
||||
|
||||
@Column(nullable = false)
|
||||
@Column(name = "issue_number", nullable = false)
|
||||
private String issueNumber;
|
||||
|
||||
@Column(nullable = true)
|
||||
@@ -67,10 +67,10 @@ public class Issue {
|
||||
@Column(name = "published_on", columnDefinition = "date", nullable = true)
|
||||
private YearMonth publishedOn;
|
||||
|
||||
@Column
|
||||
@Column(name = "is_read")
|
||||
private Boolean isRead;
|
||||
|
||||
@Column
|
||||
@Column(name = "in_stock")
|
||||
private Boolean inStock;
|
||||
|
||||
@Column(nullable = true)
|
||||
|
||||
@@ -15,7 +15,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
@Table(name = "issue_work")
|
||||
@Getter
|
||||
@Setter
|
||||
public class IssueWork {
|
||||
@@ -42,7 +42,7 @@ public class IssueWork {
|
||||
private Artist artist;
|
||||
|
||||
@ManyToOne
|
||||
@JoinColumn(name = "workType_id", nullable = false)
|
||||
@JoinColumn(name = "work_type_id", nullable = false)
|
||||
private Worktype workType;
|
||||
|
||||
@Override
|
||||
|
||||
@@ -22,7 +22,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
@Table(name = "story_arc")
|
||||
@Getter
|
||||
@Setter
|
||||
public class StoryArc {
|
||||
|
||||
@@ -15,7 +15,7 @@ import lombok.Getter;
|
||||
import lombok.Setter;
|
||||
|
||||
@Entity
|
||||
@Table
|
||||
@Table(name = "trade_paperback")
|
||||
@Getter
|
||||
@Setter
|
||||
public class TradePaperback {
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.List;
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Entity
|
||||
@Table
|
||||
@Table(name = "media_actor")
|
||||
public class MediaActor {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -22,7 +22,7 @@ import lombok.Setter;
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Entity
|
||||
@Table(indexes = {
|
||||
@Table(name = "media_actor_file", indexes = {
|
||||
@Index(columnList = "media_file_id, media_actor_id") }, uniqueConstraints = @UniqueConstraint(columnNames = {
|
||||
"media_file_id", "media_actor_id" }))
|
||||
public class MediaActorFile {
|
||||
|
||||
@@ -18,7 +18,8 @@ import lombok.Setter;
|
||||
@Getter
|
||||
@Setter
|
||||
@Entity
|
||||
@Table(indexes = @Index(columnList = "url"), uniqueConstraints = @UniqueConstraint(columnNames = { "url" }))
|
||||
@Table(name = "media_article", indexes = @Index(columnList = "url"), uniqueConstraints = @UniqueConstraint(columnNames = {
|
||||
"url" }))
|
||||
public class MediaArticle {
|
||||
|
||||
@Id
|
||||
|
||||
@@ -22,7 +22,7 @@ import jakarta.persistence.Version;
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Entity
|
||||
@Table
|
||||
@Table(name = "media_file")
|
||||
public class MediaFile {
|
||||
|
||||
@Id
|
||||
@@ -44,16 +44,16 @@ public class MediaFile {
|
||||
@Column
|
||||
private boolean review;
|
||||
|
||||
@Column
|
||||
@Column(name = "should_download")
|
||||
private boolean shouldDownload;
|
||||
|
||||
@Column(nullable = true)
|
||||
private String title;
|
||||
|
||||
@Column(nullable = true)
|
||||
@Column(name = "cloud_link", nullable = true)
|
||||
private String cloudLink;
|
||||
|
||||
@Column(nullable = true)
|
||||
@Column(name = "file_name", nullable = true)
|
||||
private String fileName;
|
||||
|
||||
@Column(nullable = true)
|
||||
|
||||
@@ -18,7 +18,7 @@ import lombok.Setter;
|
||||
@Setter
|
||||
@EqualsAndHashCode(callSuper = false)
|
||||
@Entity
|
||||
@Table(uniqueConstraints = { @UniqueConstraint(columnNames = { "url" }) })
|
||||
@Table(name = "media_video", uniqueConstraints = { @UniqueConstraint(columnNames = { "url" }) })
|
||||
public class MediaVideo {
|
||||
|
||||
@Id
|
||||
@@ -40,16 +40,16 @@ public class MediaVideo {
|
||||
@Column
|
||||
private boolean review;
|
||||
|
||||
@Column
|
||||
@Column(name = "should_download")
|
||||
private boolean shouldDownload;
|
||||
|
||||
@Column(nullable = true)
|
||||
private String title;
|
||||
|
||||
@Column(nullable = true)
|
||||
@Column(name = "cloud_link", nullable = true)
|
||||
private String cloudLink;
|
||||
|
||||
@Column(nullable = true)
|
||||
@Column(name = "file_name", nullable = true)
|
||||
private String fileName;
|
||||
|
||||
@Column(nullable = true)
|
||||
|
||||
Reference in New Issue
Block a user