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