Skip to content

Commit

Permalink
HOLY FUCKING SHIT, IT WORKS
Browse files Browse the repository at this point in the history
WOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO
  • Loading branch information
591291-hvl committed Apr 4, 2022
1 parent ff36707 commit c6eb681
Show file tree
Hide file tree
Showing 65 changed files with 377 additions and 52 deletions.
11 changes: 11 additions & 0 deletions .idea/artifacts/Yatzy_ear.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions .idea/artifacts/Yatzy_ear_exploded.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

13 changes: 13 additions & 0 deletions .idea/artifacts/Yatzy_war_exploded.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 10 additions & 0 deletions .idea/webContexts.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 2 additions & 0 deletions META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Manifest-Version: 1.0

13 changes: 13 additions & 0 deletions META-INF/application.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="UTF-8"?>
<application xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/application_9.xsd"
version="9">
<module id="JavaEEHelloWorld-Web">
<web>
<web-uri>JavaEEHelloWorld.war</web-uri>
<context-root>JavaEEHelloWorldWeb</context-root>
</web>
</module>

</application>
Binary file added lib/FastInoset.jar
Binary file not shown.
Binary file added lib/gmbal-api-only.jar
Binary file not shown.
Binary file added lib/ha-api.jar
Binary file not shown.
Binary file added lib/javax.annotation_2.jar
Binary file not shown.
Binary file added lib/jaxb-api.jar
Binary file not shown.
Binary file added lib/jaxb-impl.jar
Binary file not shown.
Binary file added lib/jaxb-xjc.jar
Binary file not shown.
Binary file added lib/jaxws-api.jar
Binary file not shown.
Binary file added lib/jaxws-rt.jar
Binary file not shown.
Binary file added lib/jaxws-tools.jar
Binary file not shown.
Binary file added lib/jsr181-api.jar
Binary file not shown.
Binary file added lib/mail.jar
Binary file not shown.
Binary file added lib/management-api.jar
Binary file not shown.
Binary file added lib/mimepull.jar
Binary file not shown.
Binary file added lib/policy.jar
Binary file not shown.
Binary file added lib/saaj-api.jar
Binary file not shown.
Binary file added lib/saaj-impl.jar
Binary file not shown.
Binary file added lib/stax-ex.jar
Binary file not shown.
Binary file added lib/stax2-api.jar
Binary file not shown.
Binary file added lib/streambuffer.jar
Binary file not shown.
Binary file added lib/woodstox-core-asl.jar
Binary file not shown.
5 changes: 5 additions & 0 deletions out/artifacts/Yatzy_war_exploded/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Manifest-Version: 1.0
Created-By: IntelliJ IDEA
Built-By: 47472
Build-Jdk: Oracle OpenJDK version 14.0.2

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Manifest-Version: 1.0
Main-Class: jpaMain

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<persistence xmlns="https://jakarta.ee/xml/ns/persistence"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/persistence https://jakarta.ee/xml/ns/persistence/persistence_3_0.xsd"
version="3.0">
<persistence-unit name="personUnit"
transaction-type="JTA">
<provider>org.eclipse.persistence.jpa.PersistenceProvider</provider>
<jta-data-source>myDataSource</jta-data-source>
<class>entity.PersonEntity</class>
<properties>
<property name="eclipselink.weaving" value="false" />
</properties>
</persistence-unit>

</persistence>
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?xml version="1.0" encoding="UTF-8" ?>
<resources>
<Resource id="myDataSource" name="myDataSource" type="javax.sql.DataSource">
jdbcDriver = org.postgresql.Driver
jdbcUrl = jdbc:postgresql://ider-database.westeurope.cloudapp.azure.com:5432/h591291
userName = h591291
password = pass
</Resource>
</resources>

Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
31 changes: 31 additions & 0 deletions out/artifacts/Yatzy_war_exploded/WEB-INF/personServlet.jsp
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<!-- Fra https://purecss.io/ -->
<link rel="stylesheet"
href="https://unpkg.com/purecss@1.0.0/build/pure-min.css">
<title>SpillerListe</title>
</head>
<body>
<h2>Spillerliste</h2>
<table class="pure-table">
<tr bgcolor="#cccccc">
<th align="left">Id</th>
<th align="left">Navn</th>

</tr>

<c:forEach items="${spillere}" var="s">


<td>${s.id}</td>
<td>${s.name}</td>

</c:forEach>
</table>
</body>
</html>
9 changes: 9 additions & 0 deletions out/artifacts/Yatzy_war_exploded/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_5_0.xsd"
version="5.0">
<welcome-file-list>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
21 changes: 21 additions & 0 deletions out/artifacts/Yatzy_war_exploded/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<!DOCTYPE html>
<html>

<head>
<meta charset="ISO-8859-1">
<title>
Yatzy
</title>
</head>

<body>
<h1>
Yatzy
</h1>
<h2>
<a href="PersonServlet">Se personer</a>
</h2>

</body>

</html>
25 changes: 22 additions & 3 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@

<!-- https://mvnrepository.com/artifact/junit/junit -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.13.2</version>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<version>5.8.2</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -33,6 +33,25 @@
<artifactId>postgresql</artifactId>
<version>42.3.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/org.actframework/act-eclipselink -->
<dependency>
<groupId>org.eclipse.persistence</groupId>
<artifactId>eclipselink</artifactId>
<version>2.6.3</version>
</dependency>
<!-- https://mvnrepository.com/artifact/javax.servlet/jstl -->
<dependency>
<groupId>javax.servlet</groupId>
<artifactId>jstl</artifactId>
<version>1.2</version>
</dependency>
<dependency>
<groupId>org.apache.tomcat</groupId>
<artifactId>tomcat-catalina</artifactId>
<version>9.0.52</version>
<scope>provided</scope>
</dependency>



</dependencies>
Expand Down
32 changes: 13 additions & 19 deletions src/main/java/dao/PersonDAO.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
package dao;

import entity.PersonEntity;
import jakarta.persistence.EntityManager;
import jakarta.persistence.EntityManagerFactory;
import jakarta.persistence.Persistence;
import jakarta.persistence.TypedQuery;

import java.beans.JavaBean;
import java.util.List;
import javax.ejb.Stateless;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Stateless
@JavaBean
public class PersonDAO {
private EntityManagerFactory emf;

public PersonDAO() {
emf = Persistence.createEntityManagerFactory("PersonUnit");
}
@PersistenceContext(name = "personUnit")
private EntityManager em;

public synchronized List<PersonEntity> getAllPersons() {
return em.createQuery("SELECT p FROM PersonEntity p", PersonEntity.class).getResultList();
}

public List<PersonEntity> getAllPersons() {
EntityManager em = emf.createEntityManager();
List<PersonEntity> persons = null;
try {
TypedQuery<PersonEntity> query = em.createQuery("Select p from PersonEntity p", PersonEntity.class);
persons = query.getResultList();
} finally {
em.close();
}
return persons;
public void savePerson(PersonEntity person) {
em.persist(person);
}
}

22 changes: 21 additions & 1 deletion src/main/java/entity/PersonEntity.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import jakarta.persistence.*;

@Entity
@Table(name = "Person", schema = "public", catalog = "h591291")
@Table(name = "person", schema = "public")
public class PersonEntity {
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
Expand All @@ -13,6 +13,18 @@ public class PersonEntity {
@Column(name = "name")
private String name;

public PersonEntity(){

}

public PersonEntity(String id, String name){
this.id = id;
this.name = name;
}




public String getId() {
return id;
}
Expand All @@ -29,6 +41,14 @@ public void setName(String name) {
this.name = name;
}

@Override
public String toString() {
return "PersonEntity{" +
"id='" + id + '\'' +
", name='" + name + '\'' +
'}';
}

@Override
public boolean equals(Object o) {
if (this == o) return true;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/jpaMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ public static void main(String[] args){

PersonDAO pDAO = new PersonDAO();

PersonEntity p1 = new PersonEntity("003", "Petter");
pDAO.savePerson(p1);

List<PersonEntity> persons = pDAO.getAllPersons();

for(PersonEntity p : persons){
Expand Down
48 changes: 48 additions & 0 deletions src/main/java/servlet/PersonServlet.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package servlet;

import dao.PersonDAO;
import entity.PersonEntity;
import jakarta.servlet.*;
import jakarta.servlet.http.*;
import jakarta.servlet.annotation.*;

import javax.ejb.EJB;
import java.io.IOException;
import java.util.List;

@WebServlet(name = "PersonServlet", value = "/PersonServlet")
public class PersonServlet extends HttpServlet {
private static final long serialVersionUID = 1L;


@EJB
private PersonDAO pDAO;

protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


// Henter alle deltagerene sortert etter navn
List<PersonEntity> spillere = pDAO.getAllPersons();

// Setter deltagerene som atributt i requesten, hentes ut i jsp siden...
request.setAttribute("spillere", spillere);

// G� til deltagerlisten
request.getRequestDispatcher("WEB-INF/personServlet.jsp").forward(request, response);


}

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


// Henter alle deltagerene sortert etter navn
List<PersonEntity> spillere = pDAO.getAllPersons();

// Setter deltagerene som atributt i requesten, hentes ut i jsp siden...
request.setAttribute("spillere", spillere);

// G� til deltagerlisten
request.getRequestDispatcher("WEB-INF/personServlet.jsp").forward(request, response);
}
}
Loading

0 comments on commit c6eb681

Please sign in to comment.