~ POJOs done

+ Example Database Servlet

Signed-off-by: Johannes Theiner <j.theiner@live.de>
This commit is contained in:
Johannes Theiner 2019-04-05 19:54:03 +02:00
parent aab20c1c48
commit 7495f455e2
11 changed files with 224 additions and 8 deletions

View File

@ -137,6 +137,7 @@
<minimumTokens>100</minimumTokens>
<sourceEncoding>${project.build.sourceEncoding}</sourceEncoding>
<printFailingErrors>true</printFailingErrors>
<failOnViolation>false</failOnViolation>
</configuration>
<executions>
<execution>

View File

@ -3,11 +3,11 @@ package de.hsel.itech.db;
import de.hsel.itech.config.Configuration;
import org.jetbrains.annotations.Nullable;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.SQLException;
import java.sql.*;
/**
*
*
* @author Johannes Theiner
* @version 0.1
* @since 0.1
@ -15,11 +15,6 @@ import java.sql.SQLException;
public class Database {
public Database() {
try {
Class.forName("com.mariadb.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
}
@ -35,6 +30,26 @@ public class Database {
return null;
}
public String getHello() {
Connection connection = getConnection();
String hello = "";
try {
PreparedStatement statement = connection.prepareStatement("SELECT * FROM test WHERE id = 1");
ResultSet resultSet = statement.executeQuery();
resultSet.next();
hello = resultSet.getString("hello");
connection.close();
} catch (SQLException e) {
e.printStackTrace();
}
return hello;
}

View File

@ -0,0 +1,24 @@
package de.hsel.itech.db.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.time.LocalDate;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
@Data
@AllArgsConstructor
public class CreditCardPayment {
private long id;
private Customer customer;
private int number;
private String owner;
private LocalDate expiration;
private int checksum;
}

View File

@ -0,0 +1,21 @@
package de.hsel.itech.db.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
@Data
@AllArgsConstructor
public class DebitCardPayment {
private long id;
private Customer customer;
private String iban;
private String bic;
private String owner;
}

View File

@ -0,0 +1,18 @@
package de.hsel.itech.db.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
@Data
@AllArgsConstructor
public class InvoicePayment {
private long id;
private Customer customer;
}

View File

@ -0,0 +1,29 @@
package de.hsel.itech.db.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
import java.time.LocalDateTime;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
@Data
@AllArgsConstructor
public class Order {
private long id;
private LocalDateTime date;
private Book book;
/**
* price in cents
*/
private int price;
private PaymentType paymentType;
private Address address;
}

View File

@ -0,0 +1,20 @@
package de.hsel.itech.db.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
@Data
@AllArgsConstructor
public class PayPalPayment {
private long id;
private Customer customer;
private String email;
private String authCode;
}

View File

@ -0,0 +1,18 @@
package de.hsel.itech.db.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
@Data
@AllArgsConstructor
public class PaymentType {
private long id;
private String name;
}

View File

@ -0,0 +1,20 @@
package de.hsel.itech.db.pojo;
import lombok.AllArgsConstructor;
import lombok.Data;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
@Data
@AllArgsConstructor
public class ShoppingCart {
private long id;
private Customer customer;
private Book article;
private int count;
}

View File

@ -0,0 +1,40 @@
package de.hsel.itech.servlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.io.PrintWriter;
/**
* @author Johannes Theiner
* @version 0.1
* @since 0.1
**/
public class Database extends HttpServlet {
private static final long serialVersionUID = 15679036734L;
/**
* doGet.
*
* @param req Request
* @param resp Response
* @throws IOException failed
*/
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp)
throws IOException {
resp.setContentType("text/html");
final PrintWriter out = resp.getWriter();
out.println("<html>");
out.println("<head>");
out.println("<title>Hallo Welt!</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1>" + new de.hsel.itech.db.Database().getHello() + "</h1>");
out.println("</body>");
out.println("</html>");
}
}

View File

@ -10,8 +10,18 @@
<servlet-class>de.hsel.itech.HelloWorld</servlet-class>
</servlet>
<servlet>
<servlet-name>database</servlet-name>
<servlet-class>de.hsel.itech.servlet.Database</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>helloWorld</servlet-name>
<url-pattern>/index</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>database</servlet-name>
<url-pattern>/db</url-pattern>
</servlet-mapping>
</web-app>