Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
version: "3.8"

services:
mysql:
image: mysql:8
container_name: car_rental_mysql
restart: always
environment:
MYSQL_ROOT_PASSWORD: root
MYSQL_DATABASE: car_rental
MYSQL_USER: car_user
MYSQL_PASSWORD: strong_password_here
ports:
- "3306:3306"
command: --default-authentication-plugin=mysql_native_password
53 changes: 53 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -60,3 +60,56 @@ Many-to-Many: Uppgifter ↔ Användare
One-to-Many: En restaurang → flera bord

Many-to-Many: Gäster ↔ Bokningar


---

## MySQL i Docker för detta projekt

Följ dessa steg för att köra MySQL lokalt i Docker och koppla upp applikationen.

### 1) Starta MySQL 8 med Docker Compose

Kräver Docker Desktop (eller docker + docker compose plugin).

Kör i projektroten:
```
docker compose up -d
```
Det startar en MySQL 8-container med:
- Databas: `car_rental`
- Användare: `car_user`
- Lösenord: `strong_password_here`
- Port: `3306` (exponerad på localhost)

### 2) JPA/Hibernate är konfigurerat för MySQL
`src/main/resources/META-INF/persistence.xml` pekar nu på:
```
jdbc:mysql://localhost:3306/car_rental
user=car_user, password=strong_password_here
```
Hibernate skapar/uppdaterar tabellerna vid start (`hibernate.hbm2ddl.auto=update`).

### 3) Verifiera och fyll på data
- Verifiera att containern är igång:
```
docker ps
```
- Logga in (om du har MySQL-klient):
```
mysql -h 127.0.0.1 -P 3306 -u car_user -p
USE car_rental;
SHOW TABLES;
```
- Lägg in seed-data (efter att applikationen skapat tabellerna) med filen `sql/seeds.sql`:
```
mysql -h 127.0.0.1 -P 3306 -u car_user -p car_rental < sql/seeds.sql
```

### 4) Starta applikationen
- Bygg och kör som vanligt (t.ex. via IntelliJ eller Maven). Vid start kommer Hibernate att skapa tabellerna i MySQL.

### 5) Felsökning
- Port 3306 upptagen → stoppa annan MySQL eller ändra port i `docker-compose.yml` och i `persistence.xml`.
- Access denied → kontrollera user/lösen i både compose och `persistence.xml`.
- No suitable driver → kör `mvn clean package` och säkerställ att `mysql-connector-j` finns i `pom.xml`.
7 changes: 7 additions & 0 deletions car-rental.iml
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
<?xml version="1.0" encoding="UTF-8"?>
<module version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
3 changes: 3 additions & 0 deletions faktura.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
FAKTURA - EVTA Rental
Kund: torsten
Att betala: 1100.0 kr
6,789 changes: 6,789 additions & 0 deletions maven_output.log

Large diffs are not rendered by default.

6,691 changes: 6,691 additions & 0 deletions maven_output_2.log

Large diffs are not rendered by default.

2,949 changes: 2,949 additions & 0 deletions maven_output_3.log

Large diffs are not rendered by default.

113 changes: 81 additions & 32 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -1,54 +1,103 @@
<?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/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>org.example</groupId>
<artifactId>JavaJPA</artifactId>
<artifactId>car-rental</artifactId>
<version>1.0-SNAPSHOT</version>

<properties>
<maven.compiler.release>25</maven.compiler.release>
<maven.compiler.source>25</maven.compiler.source>
<maven.compiler.target>25</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>

<javafx.version>22.0.2</javafx.version>
<hibernate.version>6.4.4.Final</hibernate.version>
<jakarta.persistence.version>3.1.0</jakarta.persistence.version>
</properties>

<dependencies>

<!-- JavaFX -->
<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-controls</artifactId>
<version>${javafx.version}</version>
</dependency>

<dependency>
<groupId>org.openjfx</groupId>
<artifactId>javafx-fxml</artifactId>
<version>${javafx.version}</version>
</dependency>

<!-- JPA API -->
<dependency>
<groupId>jakarta.persistence</groupId>
<artifactId>jakarta.persistence-api</artifactId>
<version>${jakarta.persistence.version}</version>
</dependency>

<!-- Hibernate ORM -->
<dependency>
<groupId>org.hibernate.orm</groupId>
<artifactId>hibernate-core</artifactId>
<version>${hibernate.version}</version>
</dependency>

<!-- MySQL Connector -->
<dependency>
<groupId>com.mysql</groupId>
<artifactId>mysql-connector-j</artifactId>
<version>8.3.0</version>
</dependency>

<!-- Logging -->
<dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
<version>2.0.12</version>
</dependency>

<!-- Email (Jakarta Mail) -->
<dependency>
<groupId>com.sun.mail</groupId>
<artifactId>jakarta.mail</artifactId>
<version>2.0.1</version>
</dependency>

<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.jupiter.version}</version>
<artifactId>junit-jupiter-api</artifactId>
<version>5.10.2</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>${assertj.core.version}</version>
<version>3.25.3</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-junit-jupiter</artifactId>
<version>${mockito.version}</version>
<scope>test</scope>
</dependency>
<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>

<build>
<plugins>

<!-- JavaFX Plugin -->
<plugin>
<groupId>org.openjfx</groupId>
<artifactId>javafx-maven-plugin</artifactId>
<version>0.0.8</version>
<configuration>
<mainClass>org.example.Main</mainClass>
</configuration>
</plugin>

</plugins>
</build>

</project>
12 changes: 12 additions & 0 deletions sql/seeds.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
USE car_rental;

INSERT INTO cars (brand, model, registrationNumber, pricePerHour, pricePerDay) VALUES
('Volvo', 'XC60', 'ABC 123', 120, 800),
('Tesla', 'Model 3', 'DEF 456', 150, 990),
('Toyota', 'Corolla', 'GHI 789', 90, 600);

INSERT INTO addons (name, price) VALUES
('Takbox', 150),
('Försäkring (Hel)', 200),
('Barnstol', 100),
('GPS', 50);
7 changes: 0 additions & 7 deletions src/main/java/org/example/App.java

This file was deleted.

23 changes: 23 additions & 0 deletions src/main/java/org/example/Main.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package org.example;

import javafx.application.Application;
import javafx.fxml.FXMLLoader;
import javafx.scene.Scene;
import javafx.stage.Stage;

public class Main extends Application {

@Override
public void start(Stage stage) throws Exception {
FXMLLoader loader = new FXMLLoader(
getClass().getResource("/fxml/main-view.fxml"));
Scene scene = new Scene(loader.load());
stage.setTitle("Car Rental");
stage.setScene(scene);
stage.show();
}

public static void main(String[] args) {
launch();
}
}
15 changes: 15 additions & 0 deletions src/main/java/org/example/config/JpaUtil.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package org.example.config;

import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;

public class JpaUtil {

private static final EntityManagerFactory emf =
Persistence.createEntityManagerFactory("car_rental_pu");

public static EntityManager getEntityManager() {
return emf.createEntityManager();
}
}
Loading