Commit 83e29ae5 authored by SR-Lut3t1um's avatar SR-Lut3t1um

Added Database support

parent 519deeda
Pipeline #89217 failed with stages
in 3 minutes and 49 seconds
......@@ -16,7 +16,7 @@ dependencies {
implementation enforcedPlatform("${quarkusPlatformGroupId}:${quarkusPlatformArtifactId}:${quarkusPlatformVersion}")
implementation 'io.quarkus:quarkus-resteasy'
implementation 'io.quarkus:quarkus-resteasy-qute'
implementation 'io.quarkus:quarkus-jdbc-postgresql'
implementation 'io.quarkus:quarkus-jdbc-mariadb'
testImplementation 'io.quarkus:quarkus-junit5'
testImplementation 'io.rest-assured:rest-assured'
......
......@@ -4,14 +4,29 @@ import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;
/** Class to model an Automaton */
@Entity
public class Automaton {
private String name;
private final ArrayList<State> states = new ArrayList<>();
private final User owner;
private final ArrayList<String> alphabet;
private List<State> states = new ArrayList<>();
private User owner;
private List<String> alphabet;
private State start;
private long id;
protected Automaton() {
alphabet = new ArrayList<>();
owner = new User("yikes");
}
public Automaton(String name, User owner) {
this.name = name;
......@@ -33,10 +48,14 @@ public class Automaton {
states.add(state);
}
public void setStart(int i) {
start = states.get(i);
public void setStart(State start) {
if (!states.contains(start)) {
states.add(start);
}
this.start = start;
}
@OneToOne
public State getStart() {
return start;
}
......@@ -45,19 +64,47 @@ public class Automaton {
states.remove(state);
}
@ManyToOne(fetch = FetchType.LAZY)
public User getOwner() {
return owner;
}
protected void setOwner(User owner) {
this.owner = owner;
}
public String getName() {
return name;
}
protected void setName(String name) {
this.name = name;
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
protected Long getId() {
return id;
}
protected void setId(Long id) {
this.id = id;
}
public void addPath(State from, int index, State to) {
from.addPath(alphabet.get(index), to);
}
@OneToMany
public List<State> getStates() {
return Collections.unmodifiableList(states);
}
protected void setStates(List<State> states) {
this.states = states;
}
protected void setAlphabet(List<String> alphabet) {
this.alphabet = alphabet;
}
}
......@@ -3,19 +3,27 @@ package org.un1qu3.models;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;
import javax.persistence.ElementCollection;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
/** This Class models a State from an {@link Automaton} */
@Entity
public class State {
/** is this State accepting? default: false */
private boolean isAccepting;
/** How do we want to name our state? */
private String name;
/** How do we want to identify our state? */
private int id;
private long id;
/** Where are we? */
private int x, y;
/** Where can we go from here? */
private final Map<String, ArrayList<State>> paths = new HashMap<>();
private Map<String, ArrayList<State>> paths = new HashMap<>();
protected State() {}
/**
* Let's assume this State is not accepting
......@@ -85,14 +93,25 @@ public class State {
paths.get(key).add(state);
}
@ElementCollection
public Map<String, ArrayList<State>> getPaths() {
return paths;
}
public int getId() {
public void setPaths(Map<String, ArrayList<State>> paths) {
this.paths = paths;
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
public long getId() {
return id;
}
protected void setId(long id) {
this.id = id;
}
@Override
public String toString() {
return "State{"
......
package org.un1qu3.models;
import java.util.List;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
@Entity
public class User {
private final String name;
private String name;
private long id;
private List<Automaton> automatons;
protected User() {}
public User(String name) {
this.name = name;
}
protected void setName(String name) {
this.name = name;
}
public String getName() {
return name;
}
@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
protected long getId() {
return id;
}
protected void setId(long id) {
this.id = id;
}
@OneToMany
protected List<Automaton> getAutomatons() {
return automatons;
}
protected void setAutomatons(List<Automaton> automatons) {
this.automatons = automatons;
}
}
# Configuration file
quarkus.datasource.url=jdbc:postgresql://localhost:5432/hibernate_db
quarkus.datasource.driver=org.postgresql.Driver
quarkus.datasource.url=jdbc:mariadb://localhost:3306/test
quarkus.datasource.driver=org.mariadb.jdbc.Driver
quarkus.datasource.username=root
quarkus.datasource.password=test123
# drop and create the database at startup (use `update` to only update the schema)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment