-
Notifications
You must be signed in to change notification settings - Fork 19
Johan branch #14
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Johan branch #14
Changes from all commits
dc26f2f
f8ab006
1681333
40de36a
2cdebb1
d65b884
043ddc9
101a2c1
e478e3b
014a203
6b91ab2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,2 +1,56 @@ | ||
| # Maven | ||
| target/ | ||
| /.idea/ | ||
| pom.xml.tag | ||
| pom.xml.releaseBackup | ||
| pom.xml.versionsBackup | ||
| pom.xml.next | ||
| release.properties | ||
| dependency-reduced-pom.xml | ||
| buildNumber.properties | ||
| .mvn/timing.properties | ||
| .mvn/wrapper/maven-wrapper.jar | ||
|
|
||
| # IntelliJ IDEA | ||
| .idea/ | ||
| *.iml | ||
| *.iws | ||
| *.ipr | ||
| out/ | ||
|
|
||
| # VS Code | ||
| .vscode/ | ||
|
|
||
| # OS | ||
| .DS_Store | ||
| Thumbs.db | ||
| desktop.ini | ||
|
|
||
| # Logs | ||
| *.log | ||
| logs/ | ||
|
|
||
| # Database files | ||
| *.db | ||
| *.mv.db | ||
| *.trace.db | ||
|
|
||
| # Docker override | ||
| docker-compose.override.yml | ||
|
|
||
| # Environment files | ||
| .env | ||
| .env.local | ||
| .env.*.local | ||
|
|
||
| # Configuration files - VIKTIGAST! | ||
| src/main/resources/META-INF/persistence.xml | ||
| src/main/resources/application.properties | ||
| src/main/resources/application.yml | ||
| src/main/resources/application.yaml | ||
|
|
||
| # Temp files | ||
| *.tmp | ||
| *.temp | ||
| *.bak | ||
| *.swp | ||
| *~ | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| FROM maven:3.8-openjdk-17 AS builder | ||
| WORKDIR /app | ||
| COPY pom.xml . | ||
| COPY src ./src | ||
| RUN mvn clean package -DskipTests | ||
|
|
||
| FROM openjdk:17-jdk-slim | ||
| COPY --from=builder /app/target/*.jar app.jar | ||
| ENTRYPOINT ["java", "-jar", "app.jar"] |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,36 @@ | ||
| version: '3.8' | ||
|
|
||
| services: | ||
| mysql-db: | ||
| image: mysql:8.0 | ||
| container_name: music-mysql | ||
| restart: always | ||
| environment: | ||
| MYSQL_ROOT_PASSWORD: rootpassword | ||
| MYSQL_DATABASE: musicdb | ||
| MYSQL_USER: music_app | ||
| MYSQL_PASSWORD: music_app_pass | ||
| ports: | ||
| - "3306:3306" | ||
| volumes: | ||
| - mysql-data:/var/lib/mysql | ||
| command: | ||
| - --default-authentication-plugin=mysql_native_password | ||
| - --character-set-server=utf8mb4 | ||
| - --collation-server=utf8mb4_unicode_ci | ||
|
|
||
| phpmyadmin: | ||
| image: phpmyadmin/phpmyadmin | ||
| container_name: music-phpmyadmin | ||
| restart: always | ||
| environment: | ||
| PMA_HOST: mysql-db | ||
| PMA_PORT: 3306 | ||
| ports: | ||
| - "8080:80" | ||
| depends_on: | ||
| - mysql-db | ||
|
|
||
| volumes: | ||
| mysql-data: | ||
| driver: local |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,9 @@ | ||
| 2025-12-16 15:54:24.333089+01:00 jdbc[3]: exception | ||
| org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "create table Album (id bigint generated by default as identity, title varchar(255), [*]year integer not null, artist_id bigint, primary key (id))"; expected "identifier"; SQL statement: | ||
| create table Album (id bigint generated by default as identity, title varchar(255), year integer not null, artist_id bigint, primary key (id)) [42001-224] | ||
| 2025-12-16 15:54:24.344107+01:00 jdbc[3]: exception | ||
| org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "ALBUM" not found; SQL statement: | ||
| alter table Album add constraint FKeornxb63o72l560qifpvd6ty foreign key (artist_id) references Artist [42102-224] | ||
| 2025-12-16 15:54:24.345111+01:00 jdbc[3]: exception | ||
| org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "ALBUM" not found; SQL statement: | ||
| alter table Song add constraint FK5i04cpyv4w83t78ui446eelht foreign key (album_id) references Album [42102-224] |
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,7 @@ | ||||||||||
| CREATE DATABASE IF NOT EXISTS musicdb; | ||||||||||
| USE musicdb; | ||||||||||
|
|
||||||||||
|
|
||||||||||
| CREATE USER IF NOT EXISTS 'musicuser'@'%' IDENTIFIED BY 'musicpass'; | ||||||||||
| GRANT ALL PRIVILEGES ON musicdb.* TO 'musicuser'@'%'; | ||||||||||
|
Comment on lines
+5
to
+6
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Credential mismatch will cause connection failures. The init script creates user
The application won't be able to connect to the database with these mismatched credentials. 🐛 Proposed fix to align credentials-CREATE USER IF NOT EXISTS 'musicuser'@'%' IDENTIFIED BY 'musicpass';
-GRANT ALL PRIVILEGES ON musicdb.* TO 'musicuser'@'%';
+CREATE USER IF NOT EXISTS 'music_app'@'%' IDENTIFIED BY 'music_app_pass';
+GRANT ALL PRIVILEGES ON musicdb.* TO 'music_app'@'%';Alternatively, this script may be unnecessary since 📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||
| FLUSH PRIVILEGES; | ||||||||||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,24 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <persistence version="2.2" xmlns="http://xmlns.jcp.org/xml/ns/persistence"> | ||
| <persistence-unit name="musicPU" transaction-type="RESOURCE_LOCAL"> | ||
| <provider>org.hibernate.jpa.HibernatePersistenceProvider</provider> | ||
|
|
||
| <class>org.example.model.Artist</class> | ||
| <class>org.example.model.Album</class> | ||
| <class>org.example.model.Song</class> | ||
| <class>org.example.model.Playlist</class> | ||
| <class>org.example.model.PlaylistSong</class> | ||
|
|
||
| <properties> | ||
| <property name="javax.persistence.jdbc.driver" value="com.mysql.cj.jdbc.Driver"/> | ||
| <property name="javax.persistence.jdbc.url" value="jdbc:mysql://localhost:3306/musicdb"/> | ||
| <property name="javax.persistence.jdbc.user" value="music_app"/> | ||
| <property name="javax.persistence.jdbc.password" value="music_app_pass"/> | ||
|
|
||
| <property name="hibernate.dialect" value="org.hibernate.dialect.MySQL8Dialect"/> | ||
| <property name="hibernate.hbm2ddl.auto" value="update"/> | ||
| <property name="hibernate.show_sql" value="true"/> | ||
| <property name="hibernate.format_sql" value="true"/> | ||
| </properties> | ||
| </persistence-unit> | ||
| </persistence> |
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| @@ -1,54 +1,36 @@ | ||||||||||||||||||||||||||||||
| <?xml version="1.0" encoding="UTF-8"?> | ||||||||||||||||||||||||||||||
| <project xmlns="http://maven.apache.org/POM/4.0.0" | ||||||||||||||||||||||||||||||
| xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | ||||||||||||||||||||||||||||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||||||||||||||||||||||||||||
| xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 | ||||||||||||||||||||||||||||||
| http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||||||||||||||||||||||||||||||
| <modelVersion>4.0.0</modelVersion> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <groupId>org.example</groupId> | ||||||||||||||||||||||||||||||
| <artifactId>JavaJPA</artifactId> | ||||||||||||||||||||||||||||||
| <version>1.0-SNAPSHOT</version> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <properties> | ||||||||||||||||||||||||||||||
| <maven.compiler.release>25</maven.compiler.release> | ||||||||||||||||||||||||||||||
| <maven.compiler.source>17</maven.compiler.source> | ||||||||||||||||||||||||||||||
| <maven.compiler.target>17</maven.compiler.target> | ||||||||||||||||||||||||||||||
| <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> | ||||||||||||||||||||||||||||||
| <junit.jupiter.version>6.0.1</junit.jupiter.version> | ||||||||||||||||||||||||||||||
| <assertj.core.version>3.27.6</assertj.core.version> | ||||||||||||||||||||||||||||||
| <mockito.version>5.21.0</mockito.version> | ||||||||||||||||||||||||||||||
| <hibernate.version>5.6.15.Final</hibernate.version> | ||||||||||||||||||||||||||||||
| <mysql.version>8.0.33</mysql.version> | ||||||||||||||||||||||||||||||
| </properties> | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| <dependencies> | ||||||||||||||||||||||||||||||
| <dependency> | ||||||||||||||||||||||||||||||
| <groupId>org.junit.jupiter</groupId> | ||||||||||||||||||||||||||||||
| <artifactId>junit-jupiter</artifactId> | ||||||||||||||||||||||||||||||
| <version>${junit.jupiter.version}</version> | ||||||||||||||||||||||||||||||
| <scope>test</scope> | ||||||||||||||||||||||||||||||
| <groupId>org.hibernate</groupId> | ||||||||||||||||||||||||||||||
| <artifactId>hibernate-core</artifactId> | ||||||||||||||||||||||||||||||
| <version>${hibernate.version}</version> | ||||||||||||||||||||||||||||||
| </dependency> | ||||||||||||||||||||||||||||||
| <dependency> | ||||||||||||||||||||||||||||||
| <groupId>org.assertj</groupId> | ||||||||||||||||||||||||||||||
| <artifactId>assertj-core</artifactId> | ||||||||||||||||||||||||||||||
| <version>${assertj.core.version}</version> | ||||||||||||||||||||||||||||||
| <scope>test</scope> | ||||||||||||||||||||||||||||||
| <groupId>javax.persistence</groupId> | ||||||||||||||||||||||||||||||
| <artifactId>javax.persistence-api</artifactId> | ||||||||||||||||||||||||||||||
| <version>2.2</version> | ||||||||||||||||||||||||||||||
| </dependency> | ||||||||||||||||||||||||||||||
| <dependency> | ||||||||||||||||||||||||||||||
| <groupId>org.mockito</groupId> | ||||||||||||||||||||||||||||||
| <artifactId>mockito-junit-jupiter</artifactId> | ||||||||||||||||||||||||||||||
| <version>${mockito.version}</version> | ||||||||||||||||||||||||||||||
| <scope>test</scope> | ||||||||||||||||||||||||||||||
| <groupId>mysql</groupId> | ||||||||||||||||||||||||||||||
| <artifactId>mysql-connector-java</artifactId> | ||||||||||||||||||||||||||||||
| <version>${mysql.version}</version> | ||||||||||||||||||||||||||||||
| </dependency> | ||||||||||||||||||||||||||||||
|
Comment on lines
30
to
34
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fix deprecated MySQL connector artifact per pipeline warning. The pipeline reports that 🐛 Proposed fix <dependency>
- <groupId>mysql</groupId>
- <artifactId>mysql-connector-java</artifactId>
+ <groupId>com.mysql</groupId>
+ <artifactId>mysql-connector-j</artifactId>
<version>${mysql.version}</version>
</dependency>📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| <dependency> | ||||||||||||||||||||||||||||||
| <groupId>org.hibernate.orm</groupId> | ||||||||||||||||||||||||||||||
| <artifactId>hibernate-core</artifactId> | ||||||||||||||||||||||||||||||
| <version>7.2.0.Final</version> | ||||||||||||||||||||||||||||||
| </dependency> | ||||||||||||||||||||||||||||||
| <dependency> | ||||||||||||||||||||||||||||||
| <groupId>com.mysql</groupId> | ||||||||||||||||||||||||||||||
| <artifactId>mysql-connector-j</artifactId> | ||||||||||||||||||||||||||||||
| <version>9.5.0</version> | ||||||||||||||||||||||||||||||
| <scope>runtime</scope> | ||||||||||||||||||||||||||||||
| </dependency> | ||||||||||||||||||||||||||||||
| <dependency> | ||||||||||||||||||||||||||||||
| <groupId>io.github.classgraph</groupId> | ||||||||||||||||||||||||||||||
| <artifactId>classgraph</artifactId> | ||||||||||||||||||||||||||||||
| <version>4.8.184</version> | ||||||||||||||||||||||||||||||
| </dependency> | ||||||||||||||||||||||||||||||
| </dependencies> | ||||||||||||||||||||||||||||||
|
Comment on lines
19
to
35
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🧩 Analysis chain🏁 Script executed: #!/bin/bash
# First, check if src/test directory exists and what test files are present
find . -path "*/src/test/*" -name "*.java" 2>/dev/null | head -20Repository: ithsjava25/ithsjava25-java-project-jpa-maven-java-template Length of output: 181 🏁 Script executed: #!/bin/bash
# Check the complete pom.xml file to see all dependencies and their scopes
cat pom.xmlRepository: ithsjava25/ithsjava25-java-project-jpa-maven-java-template Length of output: 1467 🏁 Script executed: #!/bin/bash
# Also check for any test configuration or profile sections in pom.xml
grep -n "test\|scope" pom.xml 2>/dev/null | head -20Repository: ithsjava25/ithsjava25-java-project-jpa-maven-java-template Length of output: 84 🏁 Script executed: #!/bin/bash
# Check what test frameworks the test files are trying to use
head -30 ./src/test/java/org/example/AppIT.java ./src/test/java/org/example/AppTest.javaRepository: ithsjava25/ithsjava25-java-project-jpa-maven-java-template Length of output: 615 Add missing test dependencies. Test files exist in
Without these, the tests will fail to compile and run. 🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||
| </project> | ||||||||||||||||||||||||||||||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,50 @@ | ||
| package org.example; | ||
|
|
||
| import persistence.repository.ArtistRepository; | ||
| import persistence.repository.AlbumRepository; | ||
| import persistence.repository.SongRepository; | ||
| import persistence.repository.PlaylistRepository; | ||
| import org.example.ui.MenuManager; | ||
| import javax.persistence.*; | ||
| import java.util.Scanner; | ||
|
|
||
| public class Main { | ||
| public static void main(String[] args) { | ||
| System.out.println("🎵 Startar Musikappen..."); | ||
|
|
||
| try { | ||
| // Skapa EntityManagerFactory | ||
| EntityManagerFactory emf = Persistence.createEntityManagerFactory("musicPU"); | ||
| System.out.println("✅ Ansluten till databasen"); | ||
|
|
||
| // Skapa EntityManager | ||
| EntityManager em = emf.createEntityManager(); | ||
|
|
||
| // Skapa Scanner för användarinput | ||
| Scanner scanner = new Scanner(System.in); | ||
|
|
||
| // Skapa alla repositories | ||
| System.out.println("🔄 Skapar repositories..."); | ||
| ArtistRepository artistRepo = new ArtistRepository(em); | ||
| AlbumRepository albumRepo = new AlbumRepository(em); | ||
| SongRepository songRepo = new SongRepository(em); | ||
| PlaylistRepository playlistRepo = new PlaylistRepository(em); | ||
|
|
||
| // Skapa MenuManager och starta huvudmenyn | ||
| MenuManager menuManager = new MenuManager(scanner, artistRepo, albumRepo, songRepo, playlistRepo); | ||
|
|
||
| // Starta applikationen | ||
| menuManager.start(); | ||
|
|
||
| // Stäng alla resurser | ||
| System.out.println("👋 Stänger applikationen..."); | ||
| scanner.close(); | ||
| em.close(); | ||
| emf.close(); | ||
|
|
||
| } catch (Exception e) { | ||
| System.err.println("❌ Ett fel uppstod vid start: " + e.getMessage()); | ||
| e.printStackTrace(); | ||
| } | ||
|
Comment on lines
+15
to
+48
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Resource cleanup should use try-finally or try-with-resources. If an exception occurs after creating 🛠️ Suggested refactor using try-finally public static void main(String[] args) {
System.out.println("🎵 Startar Musikappen...");
+ EntityManagerFactory emf = null;
+ EntityManager em = null;
+ Scanner scanner = null;
+
try {
- // Skapa EntityManagerFactory
- EntityManagerFactory emf = Persistence.createEntityManagerFactory("musicPU");
+ emf = Persistence.createEntityManagerFactory("musicPU");
System.out.println("✅ Ansluten till databasen");
- // Skapa EntityManager
- EntityManager em = emf.createEntityManager();
-
- // Skapa Scanner för användarinput
- Scanner scanner = new Scanner(System.in);
+ em = emf.createEntityManager();
+ scanner = new Scanner(System.in);
// ... repository and menu code ...
- // Stäng alla resurser
- System.out.println("👋 Stänger applikationen...");
- scanner.close();
- em.close();
- emf.close();
-
} catch (Exception e) {
System.err.println("❌ Ett fel uppstod vid start: " + e.getMessage());
e.printStackTrace();
+ } finally {
+ System.out.println("👋 Stänger applikationen...");
+ if (em != null && em.isOpen()) em.close();
+ if (emf != null && emf.isOpen()) emf.close();
+ // Note: Avoid closing Scanner(System.in) as it closes the underlying stream
}
}🤖 Prompt for AI Agents |
||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| package org.example.model; | ||
|
|
||
| import javax.persistence.*; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
|
|
||
| @Entity | ||
| @Table(name = "album") | ||
| public class Album { | ||
| @Id | ||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| private Long id; | ||
|
|
||
| private String title; | ||
|
|
||
| @Column(name = "release_year") | ||
| private int releaseYear; | ||
|
|
||
| @ManyToOne | ||
| @JoinColumn(name = "artist_id") | ||
| private Artist artist; | ||
|
|
||
| @OneToMany(mappedBy = "album", cascade = CascadeType.ALL, orphanRemoval = true) | ||
| private List<Song> songs = new ArrayList<>(); | ||
|
|
||
| // Konstruktorer | ||
| public Album() { | ||
| } | ||
|
|
||
| public Album(String title, int releaseYear) { | ||
| this.title = title; | ||
| this.releaseYear = releaseYear; | ||
| } | ||
|
|
||
| public Album(String title, int releaseYear, Artist artist) { | ||
| this.title = title; | ||
| this.releaseYear = releaseYear; | ||
| this.artist = artist; | ||
| } | ||
|
|
||
| // Getters och Setters | ||
| public Long getId() { | ||
| return id; | ||
| } | ||
|
|
||
| public void setId(Long id) { | ||
| this.id = id; | ||
| } | ||
|
|
||
| public String getTitle() { | ||
| return title; | ||
| } | ||
|
|
||
| public void setTitle(String title) { | ||
| this.title = title; | ||
| } | ||
|
|
||
| public int getReleaseYear() { | ||
| return releaseYear; | ||
| } | ||
|
|
||
| public void setReleaseYear(int releaseYear) { | ||
| this.releaseYear = releaseYear; | ||
| } | ||
|
|
||
| public Artist getArtist() { | ||
| return artist; | ||
| } | ||
|
|
||
| public void setArtist(Artist artist) { | ||
| this.artist = artist; | ||
| } | ||
|
|
||
| public List<Song> getSongs() { | ||
| return songs; | ||
| } | ||
|
|
||
| public void setSongs(List<Song> songs) { | ||
| this.songs = songs; | ||
| } | ||
|
|
||
| // Hjälpmetod för att lägga till låt | ||
| public void addSong(Song song) { | ||
| songs.add(song); | ||
| song.setAlbum(this); | ||
| } | ||
|
|
||
| // Hjälpmetod för att ta bort låt | ||
| public void removeSong(Song song) { | ||
| songs.remove(song); | ||
| song.setAlbum(null); | ||
| } | ||
|
|
||
| @Override | ||
| public String toString() { | ||
| return "Album{" + | ||
| "id=" + id + | ||
| ", title='" + title + '\'' + | ||
| ", releaseYear=" + releaseYear + | ||
| ", artist=" + (artist != null ? artist.getName() : "null") + | ||
| ", songs=" + songs.size() + | ||
| '}'; | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
UTF-8 BOM character detected at start of file.
There's a hidden UTF-8 BOM (
) at the beginning of line 1. While most tools handle this gracefully, some may not recognize the first line as a comment or could have parsing issues. Consider removing it.🤖 Prompt for AI Agents