From 388459b6a2a9f45abb5dba5f7329aab251000e70 Mon Sep 17 00:00:00 2001 From: joethei Date: Mon, 15 Apr 2019 18:36:03 +0200 Subject: [PATCH 01/14] + automatic inserts --- src/main/java/de/hsel/itech/db/Database.java | 28 ++++++++++++++++++- .../java/de/hsel/itech/servlet/Database.java | 2 +- src/main/resources/database.sql | 23 +++++++++++++++ 3 files changed, 51 insertions(+), 2 deletions(-) create mode 100644 src/main/resources/database.sql diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index f5267a1..3b9267e 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -4,6 +4,9 @@ import de.hsel.itech.config.Configuration; import org.jetbrains.annotations.Nullable; import org.mariadb.jdbc.MariaDbPoolDataSource; +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; @@ -18,15 +21,38 @@ import java.sql.SQLException; */ public class Database { + private static Database instance; + + public static Database getInstance() { + if(instance == null) + instance = new Database(); + return instance; + } + private MariaDbPoolDataSource dataSource; - public Database() { + private Database() { Configuration config = Configuration.get(); dataSource = new MariaDbPoolDataSource("jdbc:mysql://" + config.getDatabase().getHostname() + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase()); try { dataSource.setUser(config.getDatabase().getUsername()); dataSource.setPassword(config.getDatabase().getPassword()); dataSource.initialize(); + + Connection connection = getConnection(); + assert connection != null; + try(BufferedReader br = new BufferedReader(new FileReader(getClass().getClassLoader().getResource("database.sql").getFile()))) { + for (String line = br.readLine(); line != null; line = br.readLine()) { + PreparedStatement statement = connection.prepareStatement(line); + statement.executeUpdate(); + statement.close(); + } + } catch (IOException e) { + e.printStackTrace(); + } + finally { + connection.close(); + } } catch (SQLException e) { e.printStackTrace(); } diff --git a/src/main/java/de/hsel/itech/servlet/Database.java b/src/main/java/de/hsel/itech/servlet/Database.java index 7855d1f..a5c9a15 100644 --- a/src/main/java/de/hsel/itech/servlet/Database.java +++ b/src/main/java/de/hsel/itech/servlet/Database.java @@ -33,7 +33,7 @@ public class Database extends HttpServlet { out.println("Hallo Welt!"); out.println(""); out.println(""); - out.println("

" + new de.hsel.itech.db.Database().getHello() + "

"); + out.println("

" + de.hsel.itech.db.Database.getInstance().getHello() + "

"); out.println(""); out.println(""); } diff --git a/src/main/resources/database.sql b/src/main/resources/database.sql new file mode 100644 index 0000000..34fe222 --- /dev/null +++ b/src/main/resources/database.sql @@ -0,0 +1,23 @@ +CREATE TABLE IF NOT EXISTS test(id bigint, primary key auto_increment, hello varchar(25)); +INSERT IGNORE INTO test(hello) values ('Welt'); +CREATE TABLE IF NOT EXISTS book (id bigint primary key auto_increment, title varchar(50), description varchar(500) unique , price int, year year, publisher bigint, category bigint, image varchar(11) unique); +CREATE TABLE IF NOT EXISTS publisher(id bigint primary key auto_increment, name varchar(50) unique); +CREATE TABLE IF NOT EXISTS author(id bigint primary key auto_increment, name varchar(50) unique); +CREATE TABLE IF NOT EXISTS author_book(author bigint, book bigint, primary key(author, book), foreign key (author) REFERENCES author(id), foreign key (book) references book(id)); +CREATE TABLE IF NOT EXISTS category(id bigint primary key auto_increment, name varchar(25), image varchar(11)); +CREATE TABLE IF NOT EXISTS user(id bigint primary key auto_increment, name varchar(50), email varchar(255), password binary(40), type tinyint); +CREATE TABLE IF NOT EXISTS address(id bigint primary key auto_increment, street varchar(100), number smallint, zipCode smallint, city varchar(50)); +CREATE TABLE IF NOT EXISTS user_address(id bigint primary key auto_increment, user bigint, address bigint, foreign key (user) REFERENCES user(id), foreign key (address) references address(id)); +CREATE TABLE IF NOT EXISTS payment_type(id bigint primary key auto_increment, name varchar(25) unique); +INSERT IGNORE INTO payment_type (name) values ('CreditCard'); +INSERT IGNORE INTO payment_type (name) values ('DebitCard'); +INSERT IGNORE INTO payment_type (name) values ('Invoice'); +INSERT IGNORE INTO payment_type (name) values ('PayPal'); +CREATE TABLE IF NOT EXISTS payment_debit(id bigint primary key auto_increment, iban varchar(34), bic varchar(8), owner varchar(50)); +CREATE TABLE IF NOT EXISTS payment_credit(id bigint primary key auto_increment, number varchar(19), owner varchar(50), expiration DATE, checksum tinyint); +CREATE TABLE IF NOT EXISTS payment_invoice(id bigint primary key auto_increment); +CREATE TABLE IF NOT EXISTS payment_paypal(id bigint primary key auto_increment, mail varchar(255), auth varchar(255)); +CREATE TABLE IF NOT EXISTS `order`(id bigint primary key auto_increment, user bigint, price bigint); +CREATE TABLE IF NOT EXISTS order_book(`order` bigint, book bigint, count tinyint, primary key (`order`, book, count), foreign key (`order`) references `order`(id), foreign key (book) references `order`(id)); +CREATE TABLE IF NOT EXISTS shopping_cart(id bigint primary key auto_increment); +CREATE TABLE IF NOT EXISTS cart_books(user bigint, book bigint, count tinyint, primary key(book, user), foreign key (book) REFERENCES book(id), foreign key (user) REFERENCES user(id)); \ No newline at end of file From 07fa6d09a40e09c6d2cbb3680c4920a1222393df Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Tue, 16 Apr 2019 16:06:26 +0200 Subject: [PATCH 02/14] fixed database creation --- src/main/java/de/hsel/itech/db/Database.java | 1 + src/main/resources/database.sql | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 3b9267e..82c8e0c 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -43,6 +43,7 @@ public class Database { assert connection != null; try(BufferedReader br = new BufferedReader(new FileReader(getClass().getClassLoader().getResource("database.sql").getFile()))) { for (String line = br.readLine(); line != null; line = br.readLine()) { + System.out.println(line); PreparedStatement statement = connection.prepareStatement(line); statement.executeUpdate(); statement.close(); diff --git a/src/main/resources/database.sql b/src/main/resources/database.sql index 34fe222..61bd410 100644 --- a/src/main/resources/database.sql +++ b/src/main/resources/database.sql @@ -1,6 +1,6 @@ -CREATE TABLE IF NOT EXISTS test(id bigint, primary key auto_increment, hello varchar(25)); +CREATE TABLE IF NOT EXISTS test(id bigint primary key auto_increment, hello varchar(25)); INSERT IGNORE INTO test(hello) values ('Welt'); -CREATE TABLE IF NOT EXISTS book (id bigint primary key auto_increment, title varchar(50), description varchar(500) unique , price int, year year, publisher bigint, category bigint, image varchar(11) unique); +CREATE TABLE IF NOT EXISTS book (id bigint primary key auto_increment, title varchar(50), description varchar(500), price int, year year, publisher bigint, category bigint, image varchar(11) unique); CREATE TABLE IF NOT EXISTS publisher(id bigint primary key auto_increment, name varchar(50) unique); CREATE TABLE IF NOT EXISTS author(id bigint primary key auto_increment, name varchar(50) unique); CREATE TABLE IF NOT EXISTS author_book(author bigint, book bigint, primary key(author, book), foreign key (author) REFERENCES author(id), foreign key (book) references book(id)); From 18efa59177be1a7818ffc4c6b2d90ff97df1a3eb Mon Sep 17 00:00:00 2001 From: joethei Date: Wed, 17 Apr 2019 14:59:35 +0200 Subject: [PATCH 03/14] + get(Author/Publisher/Category/Book) --- src/main/java/de/hsel/itech/db/Database.java | 147 +++++++++++++++++- src/main/java/de/hsel/itech/db/pojo/Book.java | 5 +- .../java/de/hsel/itech/db/pojo/Category.java | 2 +- 3 files changed, 150 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 3b9267e..d6ba986 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -1,16 +1,26 @@ package de.hsel.itech.db; import de.hsel.itech.config.Configuration; +import de.hsel.itech.db.pojo.Author; +import de.hsel.itech.db.pojo.Book; +import de.hsel.itech.db.pojo.Category; +import de.hsel.itech.db.pojo.Publisher; import org.jetbrains.annotations.Nullable; import org.mariadb.jdbc.MariaDbPoolDataSource; import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; +import java.net.URL; import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.Year; +import java.util.AbstractMap; +import java.util.ArrayList; +import java.util.List; +import java.util.Map; /** * @@ -41,7 +51,9 @@ public class Database { Connection connection = getConnection(); assert connection != null; - try(BufferedReader br = new BufferedReader(new FileReader(getClass().getClassLoader().getResource("database.sql").getFile()))) { + URL file = getClass().getClassLoader().getResource("database.sql"); + assert file != null; + try(BufferedReader br = new BufferedReader(new FileReader(file.getFile()))) { for (String line = br.readLine(); line != null; line = br.readLine()) { PreparedStatement statement = connection.prepareStatement(line); statement.executeUpdate(); @@ -88,8 +100,141 @@ public class Database { } + @Nullable + private Map.Entry getResultSet(long id, String table) { + Connection connection = getConnection(); + try{ + assert connection != null; + PreparedStatement statement = connection.prepareStatement("SELECT * FROM ? WHERE ID = ?"); + statement.setString(1, table); + statement.setLong(2, id); + ResultSet resultSet = statement.executeQuery(); + if(resultSet.next()) { + return new AbstractMap.SimpleEntry<>(resultSet, connection); + } + return null; + + }catch (SQLException ex) { + ex.printStackTrace(); + } + return null; + } + + @Nullable + private Map.Entry, Connection> getResultSets(long id, String table, String column) { + Connection connection = getConnection(); + try { + assert connection != null; + PreparedStatement statement = connection.prepareStatement("SELECT * FROM ? WHERE ? = ?"); + statement.setString(1, table); + statement.setString(2, column); + statement.setLong(3, id); + + ResultSet resultSet = statement.executeQuery(); + + Map.Entry, Connection> entry = new AbstractMap.SimpleEntry<>(new ArrayList<>(), connection); + while(resultSet.next()) { + entry.getKey().add(resultSet); + } + return entry; + }catch (SQLException ex) { + ex.printStackTrace(); + } + return null; + } + @Nullable + public Author getAuthor(long id) { + Map.Entry entry = getResultSet(id, "author"); + assert entry != null; + + ResultSet rs = entry.getKey(); + Author author = null; + try { + author = new Author(rs.getLong("id"), rs.getString("name")); + entry.getValue().close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return author; + } + + @Nullable + public Category getCategory(long id) { + Map.Entry entry = getResultSet(id, "category"); + assert entry != null; + + ResultSet rs = entry.getKey(); + Category category = null; + try { + category = new Category(rs.getLong("id"), rs.getString("name"), rs.getString("image")); + entry.getValue().close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return category; + } + + @Nullable + public Publisher getPublisher(long id) { + Map.Entry entry = getResultSet(id, "category"); + assert entry != null; + + ResultSet rs = entry.getKey(); + Publisher publisher = null; + try { + publisher = new Publisher(rs.getLong("id"), rs.getString("name")); + entry.getValue().close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return publisher; + } + + @Nullable + private List getAuthors(long id) { + Map.Entry, Connection> entry = getResultSets(id, "author_book", "book"); + assert entry != null; + try { + List list = new ArrayList<>(); + for(ResultSet rs : entry.getKey()) { + list.add(rs.getInt("author")); + } + entry.getValue().close(); + return list; + } catch (SQLException e) { + e.printStackTrace(); + } + return null; + } + + @Nullable + public Book getBook(long id) { + Map.Entry entry = getResultSet(id, "book"); + assert entry != null; + + ResultSet rs = entry.getKey(); + Book book = null; + try { + Category category = getCategory(rs.getLong("category")); + Publisher publisher = getPublisher(rs.getLong("publisher")); + List authorIds = getAuthors(id); + assert authorIds != null; + List authors = new ArrayList<>(); + for(int i : authorIds) { + Author author = getAuthor(i); + assert author != null; + authors.add(author); + } + book = new Book(rs.getLong("id"), authors, publisher, category, rs.getString("title"), Year.of(rs.getInt("year")), rs.getInt("price"), rs.getString("description"), rs.getString("image")); + entry.getValue().close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return book; + } + } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/Book.java b/src/main/java/de/hsel/itech/db/pojo/Book.java index 79160e1..8599fb7 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Book.java +++ b/src/main/java/de/hsel/itech/db/pojo/Book.java @@ -4,6 +4,7 @@ import lombok.AllArgsConstructor; import lombok.Data; import java.time.Year; +import java.util.List; /** * @author Johannes Theiner @@ -15,8 +16,8 @@ import java.time.Year; @AllArgsConstructor public class Book { - private int isbn; - private Author author; + private long isbn; + private List authors; private Publisher publisher; private Category category; private String title; diff --git a/src/main/java/de/hsel/itech/db/pojo/Category.java b/src/main/java/de/hsel/itech/db/pojo/Category.java index 685ca42..6c6a166 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Category.java +++ b/src/main/java/de/hsel/itech/db/pojo/Category.java @@ -13,7 +13,7 @@ import lombok.Data; @AllArgsConstructor public class Category { - private int id; + private long id; private String name; private String image; } From 59ecac912cf933dedccfe3a822cce579478b3be3 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 17 Apr 2019 20:14:26 +0200 Subject: [PATCH 04/14] + insert(Book/Author/Publisher) + getBooks Signed-off-by: Johannes Theiner --- src/main/java/de/hsel/itech/db/Database.java | 270 ++++++++++++++---- .../java/de/hsel/itech/db/pojo/Address.java | 15 +- .../java/de/hsel/itech/db/pojo/Author.java | 5 +- src/main/java/de/hsel/itech/db/pojo/Book.java | 19 +- .../java/de/hsel/itech/db/pojo/Category.java | 7 +- .../hsel/itech/db/pojo/CreditCardPayment.java | 13 +- .../java/de/hsel/itech/db/pojo/Customer.java | 11 +- .../hsel/itech/db/pojo/DebitCardPayment.java | 11 +- .../de/hsel/itech/db/pojo/InvoicePayment.java | 5 +- .../java/de/hsel/itech/db/pojo/Order.java | 13 +- .../de/hsel/itech/db/pojo/PayPalPayment.java | 9 +- .../de/hsel/itech/db/pojo/PaymentType.java | 5 +- .../java/de/hsel/itech/db/pojo/Publisher.java | 5 +- .../de/hsel/itech/db/pojo/ShoppingCart.java | 9 +- .../servlet/{Database.java => DBTest.java} | 6 +- src/main/webapp/WEB-INF/web.xml | 2 +- 16 files changed, 302 insertions(+), 103 deletions(-) rename src/main/java/de/hsel/itech/servlet/{Database.java => DBTest.java} (86%) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index d6ba986..9243490 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -5,6 +5,7 @@ import de.hsel.itech.db.pojo.Author; import de.hsel.itech.db.pojo.Book; import de.hsel.itech.db.pojo.Category; import de.hsel.itech.db.pojo.Publisher; +import org.jetbrains.annotations.NotNull; import org.jetbrains.annotations.Nullable; import org.mariadb.jdbc.MariaDbPoolDataSource; @@ -23,8 +24,6 @@ import java.util.List; import java.util.Map; /** - * - * * @author Johannes Theiner * @version 0.1 * @since 0.1 @@ -34,7 +33,7 @@ public class Database { private static Database instance; public static Database getInstance() { - if(instance == null) + if (instance == null) instance = new Database(); return instance; } @@ -53,7 +52,7 @@ public class Database { assert connection != null; URL file = getClass().getClassLoader().getResource("database.sql"); assert file != null; - try(BufferedReader br = new BufferedReader(new FileReader(file.getFile()))) { + try (BufferedReader br = new BufferedReader(new FileReader(file.getFile()))) { for (String line = br.readLine(); line != null; line = br.readLine()) { PreparedStatement statement = connection.prepareStatement(line); statement.executeUpdate(); @@ -61,8 +60,7 @@ public class Database { } } catch (IOException e) { e.printStackTrace(); - } - finally { + } finally { connection.close(); } } catch (SQLException e) { @@ -100,52 +98,6 @@ public class Database { } - @Nullable - private Map.Entry getResultSet(long id, String table) { - Connection connection = getConnection(); - try{ - assert connection != null; - PreparedStatement statement = connection.prepareStatement("SELECT * FROM ? WHERE ID = ?"); - statement.setString(1, table); - statement.setLong(2, id); - ResultSet resultSet = statement.executeQuery(); - if(resultSet.next()) { - return new AbstractMap.SimpleEntry<>(resultSet, connection); - } - return null; - - }catch (SQLException ex) { - ex.printStackTrace(); - } - return null; - } - - @Nullable - private Map.Entry, Connection> getResultSets(long id, String table, String column) { - Connection connection = getConnection(); - try { - assert connection != null; - PreparedStatement statement = connection.prepareStatement("SELECT * FROM ? WHERE ? = ?"); - statement.setString(1, table); - statement.setString(2, column); - statement.setLong(3, id); - - ResultSet resultSet = statement.executeQuery(); - - Map.Entry, Connection> entry = new AbstractMap.SimpleEntry<>(new ArrayList<>(), connection); - while(resultSet.next()) { - entry.getKey().add(resultSet); - } - return entry; - - - }catch (SQLException ex) { - ex.printStackTrace(); - } - return null; - } - - @Nullable public Author getAuthor(long id) { Map.Entry entry = getResultSet(id, "author"); @@ -196,11 +148,11 @@ public class Database { @Nullable private List getAuthors(long id) { - Map.Entry, Connection> entry = getResultSets(id, "author_book", "book"); - assert entry != null; + Map.Entry, Connection> entry = getResultSets(id, "author_book", "book"); + assert entry != null; try { List list = new ArrayList<>(); - for(ResultSet rs : entry.getKey()) { + for (ResultSet rs : entry.getKey()) { list.add(rs.getInt("author")); } entry.getValue().close(); @@ -224,7 +176,7 @@ public class Database { List authorIds = getAuthors(id); assert authorIds != null; List authors = new ArrayList<>(); - for(int i : authorIds) { + for (int i : authorIds) { Author author = getAuthor(i); assert author != null; authors.add(author); @@ -237,4 +189,210 @@ public class Database { return book; } + @Nullable + public List getBooks() { + Map.Entry, Connection> entry = getResultSets("book", "id"); + assert entry != null; + + List ids = new ArrayList<>(); + try { + for (ResultSet resultSet : entry.getKey()) { + ids.add(resultSet.getLong("id")); + } + entry.getValue().close(); + } catch (SQLException ex) { + ex.printStackTrace(); + } + List books = new ArrayList<>(); + for(long id : ids) { + books.add(getBook(id)); + } + return books; + } + + @Nullable + public List getBooks(long category) { + Connection connection = getConnection(); + assert connection != null; + + List books = new ArrayList<>(); + try { + PreparedStatement statement = connection.prepareStatement("SELECT (id) FROM book WHERE category = ?"); + statement.setLong(1, category); + + ResultSet resultSet = statement.executeQuery(); + + while(resultSet.next()) { + books.add(getBook(resultSet.getLong("id"))); + } + + connection.close(); + } catch (SQLException e) { + e.printStackTrace(); + } + return books; + } + + @Nullable + public List getBooks(@NotNull Category category) { + return getBooks(category.getId()); + } + + + /** + * Inserts book into database + * + * authors, publishers, and category have to exist + * @param book Book + * @return insert count + */ + public int insert(@NotNull Book book) { + Connection connection = getConnection(); + assert connection != null; + + int insertCount = 0; + + try { + PreparedStatement statement = connection.prepareStatement("INSERT INTO book (title, description, price, year, publisher, category, image) VALUES (?, ?, ?, ?, ?, ?, ?)"); + statement.setString(1, book.getTitle()); + statement.setString(2, book.getDescription()); + statement.setInt(3, book.getPrice()); + statement.setInt(4, book.getYear().getValue()); + statement.setLong(5, book.getPublisher().getId()); + statement.setLong(6, book.getCategory().getId()); + statement.setString(7, book.getImage()); + insertCount += statement.executeUpdate(); + + for(Author author : book.getAuthors()) { + PreparedStatement authorStatement = connection.prepareStatement("INSERT INTO author_book (author, book) VALUES (?, ?)"); + statement.setLong(1, author.getId()); + statement.setLong(2, book.getIsbn()); + insertCount += authorStatement.executeUpdate(); + } + + connection.close(); + } catch (SQLException ex) { + ex.printStackTrace(); + } + return insertCount; + } + + /** + * inserts Category into database + * @param category Category + * @return insert count + */ + public int insert(@NotNull Category category) { + Connection connection = getConnection(); + assert connection != null; + + int insertCount = 0; + + try{ + PreparedStatement statement = connection.prepareStatement("INSERT INTO category (name, image) VALUES (?, ?)"); + statement.setString(1, category.getName()); + statement.setString(2, category.getImage()); + insertCount += statement.executeUpdate(); + + connection.close(); + }catch (SQLException ex) { + ex.printStackTrace(); + } + + return insertCount; + } + + /** + * inserts Author + * @param author Author + * @return insert count + */ + public int insert(@NotNull Author author) { + Connection connection = getConnection(); + assert connection != null; + + int insertCount = 0; + try{ + PreparedStatement statement = connection.prepareStatement("INSERT INTO author (name) VALUES (?)"); + statement.setString(1, author.getName()); + + insertCount += statement.executeUpdate(); + + connection.close(); + }catch (SQLException ex) { + ex.printStackTrace(); + } + + + return insertCount; + } + + + + + + @Nullable + private Map.Entry getResultSet(long id, String table) { + Connection connection = getConnection(); + try { + assert connection != null; + PreparedStatement statement = connection.prepareStatement("SELECT * FROM ? WHERE ID = ?"); + statement.setString(1, table); + statement.setLong(2, id); + ResultSet resultSet = statement.executeQuery(); + if (resultSet.next()) { + return new AbstractMap.SimpleEntry<>(resultSet, connection); + } + return null; + + } catch (SQLException ex) { + ex.printStackTrace(); + } + return null; + } + + @NotNull + private Map.Entry, Connection> getListConnectionEntry(Connection connection, PreparedStatement statement) throws SQLException { + ResultSet resultSet = statement.executeQuery(); + + Map.Entry, Connection> entry = new AbstractMap.SimpleEntry<>(new ArrayList<>(), connection); + while (resultSet.next()) { + entry.getKey().add(resultSet); + } + return entry; + } + + @Nullable + private Map.Entry, Connection> getResultSets(long id, String table, String column) { + Connection connection = getConnection(); + try { + assert connection != null; + PreparedStatement statement = connection.prepareStatement("SELECT * FROM ? WHERE ? = ?"); + statement.setString(1, table); + statement.setString(2, column); + statement.setLong(3, id); + + return getListConnectionEntry(connection, statement); + } catch (SQLException ex) { + ex.printStackTrace(); + } + return null; + } + + @Nullable + private Map.Entry, Connection> getResultSets(String table, String columns) { + Connection connection = getConnection(); + try { + assert connection != null; + PreparedStatement statement = connection.prepareStatement("SELECT (?) FROM ?"); + statement.setString(1, columns); + statement.setString(2, table); + + return getListConnectionEntry(connection, statement); + } catch (SQLException ex) { + ex.printStackTrace(); + } + return null; + } + } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/Address.java b/src/main/java/de/hsel/itech/db/pojo/Address.java index f986fbf..80f64a2 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Address.java +++ b/src/main/java/de/hsel/itech/db/pojo/Address.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; /** * @author Johannes Theiner @@ -11,13 +13,14 @@ import lombok.Data; @Data @AllArgsConstructor +@RequiredArgsConstructor public class Address { - private Customer customer; + @NonNull private Customer customer; private long id; - private String name; - private String street; - private String number; - private int zipCode; - private String city; + @NonNull private String name; + @NonNull private String street; + @NonNull private String number; + @NonNull private int zipCode; + @NonNull private String city; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/Author.java b/src/main/java/de/hsel/itech/db/pojo/Author.java index 507893e..a657c51 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Author.java +++ b/src/main/java/de/hsel/itech/db/pojo/Author.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; /** * @author Johannes Theiner @@ -11,9 +13,10 @@ import lombok.Data; @Data @AllArgsConstructor +@RequiredArgsConstructor public class Author { private long id; - private String name; + @NonNull private String name; } diff --git a/src/main/java/de/hsel/itech/db/pojo/Book.java b/src/main/java/de/hsel/itech/db/pojo/Book.java index 8599fb7..8adb3a7 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Book.java +++ b/src/main/java/de/hsel/itech/db/pojo/Book.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; import java.time.Year; import java.util.List; @@ -14,21 +16,22 @@ import java.util.List; @Data @AllArgsConstructor +@RequiredArgsConstructor public class Book { private long isbn; - private List authors; - private Publisher publisher; - private Category category; - private String title; - private Year year; + @NonNull private List authors; + @NonNull private Publisher publisher; + @NonNull private Category category; + @NonNull private String title; + @NonNull private Year year; /** * saved in cents */ - private int price; - private String description; - private String image; + @NonNull private int price; + @NonNull private String description; + @NonNull private String image; diff --git a/src/main/java/de/hsel/itech/db/pojo/Category.java b/src/main/java/de/hsel/itech/db/pojo/Category.java index 6c6a166..f2ebeb4 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Category.java +++ b/src/main/java/de/hsel/itech/db/pojo/Category.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; /** * @author Johannes Theiner @@ -11,9 +13,10 @@ import lombok.Data; @Data @AllArgsConstructor +@RequiredArgsConstructor public class Category { private long id; - private String name; - private String image; + @NonNull private String name; + @NonNull private String image; } diff --git a/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java b/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java index 0a19e81..bb7957f 100644 --- a/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java +++ b/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; import java.time.LocalDate; @@ -13,12 +15,13 @@ import java.time.LocalDate; @Data @AllArgsConstructor +@RequiredArgsConstructor public class CreditCardPayment { private long id; - private Customer customer; - private int number; - private String owner; - private LocalDate expiration; - private int checksum; + @NonNull private Customer customer; + @NonNull private int number; + @NonNull private String owner; + @NonNull private LocalDate expiration; + @NonNull private int checksum; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/Customer.java b/src/main/java/de/hsel/itech/db/pojo/Customer.java index b06ab30..61c0a2f 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Customer.java +++ b/src/main/java/de/hsel/itech/db/pojo/Customer.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; /** * @author Johannes Theiner @@ -11,11 +13,12 @@ import lombok.Data; @Data @AllArgsConstructor +@RequiredArgsConstructor public class Customer { private long id; - private String email; - private String name; - private String password; - private boolean admin; + @NonNull private String email; + @NonNull private String name; + @NonNull private String password; + @NonNull private boolean admin; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/DebitCardPayment.java b/src/main/java/de/hsel/itech/db/pojo/DebitCardPayment.java index 3741404..d4bfb78 100644 --- a/src/main/java/de/hsel/itech/db/pojo/DebitCardPayment.java +++ b/src/main/java/de/hsel/itech/db/pojo/DebitCardPayment.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; /** * @author Johannes Theiner @@ -11,11 +13,12 @@ import lombok.Data; @Data @AllArgsConstructor +@RequiredArgsConstructor public class DebitCardPayment { private long id; - private Customer customer; - private String iban; - private String bic; - private String owner; + @NonNull private Customer customer; + @NonNull private String iban; + @NonNull private String bic; + @NonNull private String owner; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/InvoicePayment.java b/src/main/java/de/hsel/itech/db/pojo/InvoicePayment.java index acf8a5a..4bf7d0e 100644 --- a/src/main/java/de/hsel/itech/db/pojo/InvoicePayment.java +++ b/src/main/java/de/hsel/itech/db/pojo/InvoicePayment.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; /** * @author Johannes Theiner @@ -11,8 +13,9 @@ import lombok.Data; @Data @AllArgsConstructor +@RequiredArgsConstructor public class InvoicePayment { private long id; - private Customer customer; + @NonNull private Customer customer; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/Order.java b/src/main/java/de/hsel/itech/db/pojo/Order.java index c0f8a14..e990112 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Order.java +++ b/src/main/java/de/hsel/itech/db/pojo/Order.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; import java.time.LocalDateTime; @@ -14,16 +16,17 @@ import java.time.LocalDateTime; @Data @AllArgsConstructor +@RequiredArgsConstructor public class Order { private long id; - private LocalDateTime date; - private Book book; + @NonNull private LocalDateTime date; + @NonNull private Book book; /** * price in cents */ - private int price; - private PaymentType paymentType; - private Address address; + @NonNull private int price; + @NonNull private PaymentType paymentType; + @NonNull private Address address; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java b/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java index e5804ac..6a5d4fe 100644 --- a/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java +++ b/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; /** * @author Johannes Theiner @@ -11,10 +13,11 @@ import lombok.Data; @Data @AllArgsConstructor +@RequiredArgsConstructor public class PayPalPayment { private long id; - private Customer customer; - private String email; - private String authCode; + @NonNull private Customer customer; + @NonNull private String email; + @NonNull private String authCode; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/PaymentType.java b/src/main/java/de/hsel/itech/db/pojo/PaymentType.java index 5f7e519..f191503 100644 --- a/src/main/java/de/hsel/itech/db/pojo/PaymentType.java +++ b/src/main/java/de/hsel/itech/db/pojo/PaymentType.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; /** * @author Johannes Theiner @@ -11,8 +13,9 @@ import lombok.Data; @Data @AllArgsConstructor +@RequiredArgsConstructor public class PaymentType { private long id; - private String name; + @NonNull private String name; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/Publisher.java b/src/main/java/de/hsel/itech/db/pojo/Publisher.java index c036d86..eee9d9e 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Publisher.java +++ b/src/main/java/de/hsel/itech/db/pojo/Publisher.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; /** * @author Johannes Theiner @@ -11,8 +13,9 @@ import lombok.Data; @Data @AllArgsConstructor +@RequiredArgsConstructor public class Publisher { private long id; - private String name; + @NonNull private String name; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/ShoppingCart.java b/src/main/java/de/hsel/itech/db/pojo/ShoppingCart.java index 375d01a..c56c4f3 100644 --- a/src/main/java/de/hsel/itech/db/pojo/ShoppingCart.java +++ b/src/main/java/de/hsel/itech/db/pojo/ShoppingCart.java @@ -2,6 +2,8 @@ package de.hsel.itech.db.pojo; import lombok.AllArgsConstructor; import lombok.Data; +import lombok.NonNull; +import lombok.RequiredArgsConstructor; /** * @author Johannes Theiner @@ -11,10 +13,11 @@ import lombok.Data; @Data @AllArgsConstructor +@RequiredArgsConstructor public class ShoppingCart { private long id; - private Customer customer; - private Book article; - private int count; + @NonNull private Customer customer; + @NonNull private Book article; + @NonNull private int count; } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/servlet/Database.java b/src/main/java/de/hsel/itech/servlet/DBTest.java similarity index 86% rename from src/main/java/de/hsel/itech/servlet/Database.java rename to src/main/java/de/hsel/itech/servlet/DBTest.java index a5c9a15..7f797c1 100644 --- a/src/main/java/de/hsel/itech/servlet/Database.java +++ b/src/main/java/de/hsel/itech/servlet/DBTest.java @@ -1,5 +1,7 @@ package de.hsel.itech.servlet; +import de.hsel.itech.db.Database; + import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -11,7 +13,7 @@ import java.io.PrintWriter; * @version 0.1 * @since 0.1 **/ -public class Database extends HttpServlet { +public class DBTest extends HttpServlet { private static final long serialVersionUID = 15679036734L; @@ -33,7 +35,7 @@ public class Database extends HttpServlet { out.println("Hallo Welt!"); out.println(""); out.println(""); - out.println("

" + de.hsel.itech.db.Database.getInstance().getHello() + "

"); + out.println("

" + Database.getInstance().getHello() + "

"); out.println(""); out.println(""); } diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 391a545..b4d113c 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -12,7 +12,7 @@ database - de.hsel.itech.servlet.Database + de.hsel.itech.servlet.DBTest From 2cf2646f76a887e661e4d1093f90d9dc17052b76 Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Thu, 18 Apr 2019 09:07:55 +0200 Subject: [PATCH 05/14] added booklist and addbook to edit books --- src/main/java/de/hsel/itech/db/Database.java | 50 ++++++- .../java/de/hsel/itech/servlet/AddBook.java | 43 ++++++ .../java/de/hsel/itech/servlet/BookList.java | 122 ++++++++++++++++++ .../java/de/hsel/itech/servlet/Utillity.java | 51 ++++++++ src/main/resources/template_footer.html | 81 ++++++++++++ src/main/resources/template_head.html | 65 ++++++++++ src/main/webapp/WEB-INF/web.xml | 20 +++ src/main/webapp/{preview => }/css/custom.css | 0 .../webapp/{preview => }/css/m-components.css | 0 .../{preview => }/css/m-dark.compiled.css | 0 src/main/webapp/{preview => }/css/m-dark.css | 0 src/main/webapp/{preview => }/css/m-debug.css | 0 .../webapp/{preview => }/css/m-doxygen.css | 0 src/main/webapp/{preview => }/css/m-grid.css | 0 .../webapp/{preview => }/css/m-layout.css | 0 .../{preview => }/css/m-light.compiled.css | 0 src/main/webapp/{preview => }/css/m-light.css | 0 .../webapp/{preview => }/css/m-theme-dark.css | 0 .../{preview => }/css/m-theme-light.css | 0 .../{preview => }/css/pygments-console.css | 0 .../{preview => }/css/pygments-dark.css | 0 .../webapp/{preview => }/css/slick-theme.css | 0 src/main/webapp/preview/book.html | 6 +- src/main/webapp/preview/catalog.html | 6 +- src/main/webapp/preview/confirmation.html | 6 +- src/main/webapp/preview/detailpage.html | 6 +- src/main/webapp/preview/login.html | 6 +- src/main/webapp/preview/orderinfo.html | 6 +- src/main/webapp/preview/register.html | 6 +- src/main/webapp/preview/shoppingcart.html | 6 +- src/main/webapp/preview/start.html | 6 +- src/main/webapp/preview/thanksForBuyin.html | 6 +- 32 files changed, 461 insertions(+), 31 deletions(-) create mode 100644 src/main/java/de/hsel/itech/servlet/AddBook.java create mode 100644 src/main/java/de/hsel/itech/servlet/BookList.java create mode 100644 src/main/java/de/hsel/itech/servlet/Utillity.java create mode 100644 src/main/resources/template_footer.html create mode 100644 src/main/resources/template_head.html rename src/main/webapp/{preview => }/css/custom.css (100%) rename src/main/webapp/{preview => }/css/m-components.css (100%) rename src/main/webapp/{preview => }/css/m-dark.compiled.css (100%) rename src/main/webapp/{preview => }/css/m-dark.css (100%) rename src/main/webapp/{preview => }/css/m-debug.css (100%) rename src/main/webapp/{preview => }/css/m-doxygen.css (100%) rename src/main/webapp/{preview => }/css/m-grid.css (100%) rename src/main/webapp/{preview => }/css/m-layout.css (100%) rename src/main/webapp/{preview => }/css/m-light.compiled.css (100%) rename src/main/webapp/{preview => }/css/m-light.css (100%) rename src/main/webapp/{preview => }/css/m-theme-dark.css (100%) rename src/main/webapp/{preview => }/css/m-theme-light.css (100%) rename src/main/webapp/{preview => }/css/pygments-console.css (100%) rename src/main/webapp/{preview => }/css/pygments-dark.css (100%) rename src/main/webapp/{preview => }/css/slick-theme.css (100%) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 82c8e0c..a8af043 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -1,6 +1,10 @@ package de.hsel.itech.db; import de.hsel.itech.config.Configuration; +import de.hsel.itech.db.pojo.Author; +import de.hsel.itech.db.pojo.Book; +import de.hsel.itech.db.pojo.Category; +import de.hsel.itech.db.pojo.Publisher; import org.jetbrains.annotations.Nullable; import org.mariadb.jdbc.MariaDbPoolDataSource; @@ -11,6 +15,8 @@ import java.sql.Connection; import java.sql.PreparedStatement; import java.sql.ResultSet; import java.sql.SQLException; +import java.time.Year; +import java.util.ArrayList; /** * @@ -43,7 +49,6 @@ public class Database { assert connection != null; try(BufferedReader br = new BufferedReader(new FileReader(getClass().getClassLoader().getResource("database.sql").getFile()))) { for (String line = br.readLine(); line != null; line = br.readLine()) { - System.out.println(line); PreparedStatement statement = connection.prepareStatement(line); statement.executeUpdate(); statement.close(); @@ -90,6 +95,49 @@ public class Database { } + private ArrayList books; + + public void addBook(Book book){ + if(books == null){ + books = new ArrayList(); + } + books.add(book); + } + + public void removeBook(long isbn){ + for(Book book : books){ + if(book.getIsbn() == isbn){ + books.remove(book); + break; + } + } + } + + public ArrayList getBooks(){ + if(books == null){ + books = new ArrayList(); + Book book = new Book( + 1234, + new Author(123123,"Julian Hinxlage"), + new Publisher(234231,"Verlag xy"), + new Category(23434,"Education", "DxAzOKSiPoE"), + "C++ for beginners", Year.of(2019),1500,"C++ book", "DxAzOKSiPoE" + ); + books.add(book); + + book = new Book( + 1235, + new Author(123123,"Julian Hinxlage"), + new Publisher(234231,"Verlag xy"), + new Category(23434,"Education", "DxAzOKSiPoE"), + "C++ for beginners vol 2", Year.of(2019),1499,"C++ book", "DxAzOKSiPoE" + ); + books.add(book); + } + + return books; + } + diff --git a/src/main/java/de/hsel/itech/servlet/AddBook.java b/src/main/java/de/hsel/itech/servlet/AddBook.java new file mode 100644 index 0000000..cabd6b3 --- /dev/null +++ b/src/main/java/de/hsel/itech/servlet/AddBook.java @@ -0,0 +1,43 @@ +package de.hsel.itech.servlet; + +import de.hsel.itech.db.pojo.Book; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.ArrayList; + +public class AddBook extends HttpServlet { + + + protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) + throws IOException { + + resp.setCharacterEncoding("utf-8"); + PrintWriter out = resp.getWriter(); + + Utillity.insertFile(out, "template_head.html"); + de.hsel.itech.db.Database db = de.hsel.itech.db.Database.getInstance(); + ArrayList books = db.getBooks(); + + out.println("
"); + Utillity.addInput(out,"ISBN", "isbn"); + Utillity.addInput(out,"Titel", "title"); + Utillity.addInput(out,"Author", "author"); + Utillity.addInput(out,"Preis", "price"); + Utillity.addInput(out,"Jahr", "year"); + Utillity.addInput(out,"Beschreibung", "description"); + Utillity.addInput(out,"Verlag", "publisher"); + Utillity.addTypeButton(out, "Hinzufügen", "submit"); + out.println("
"); + + + //Utillity.addButton(out,"Hinzufügen", "/itech/booklist"); + Utillity.addButton(out,"Zurück zur Buchliste", "booklist"); + + Utillity.insertFile(out, "template_footer.html"); + } + +} diff --git a/src/main/java/de/hsel/itech/servlet/BookList.java b/src/main/java/de/hsel/itech/servlet/BookList.java new file mode 100644 index 0000000..c2622b7 --- /dev/null +++ b/src/main/java/de/hsel/itech/servlet/BookList.java @@ -0,0 +1,122 @@ +package de.hsel.itech.servlet; + +import de.hsel.itech.db.pojo.Author; +import de.hsel.itech.db.pojo.Book; +import de.hsel.itech.db.pojo.Category; +import de.hsel.itech.db.pojo.Publisher; + +import javax.servlet.http.HttpServlet; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.IOException; +import java.io.PrintWriter; +import java.time.Year; +import java.util.ArrayList; +import java.util.Enumeration; + +public class BookList extends HttpServlet { + + protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) + throws IOException { + + //get database object + de.hsel.itech.db.Database db = de.hsel.itech.db.Database.getInstance(); + + //print parameter (debug) + Enumeration names = req.getParameterNames(); + while(names.hasMoreElements()){ + String name = names.nextElement(); + System.out.println(name + "=" + req.getParameter(name)); + } + + //remove book by id + String param = req.getParameter("removeid"); + if(param != null){ + long isbn = Long.parseLong(param); + //TODO remove book from Database + db.removeBook(isbn); + } + + param = req.getParameter("isbn"); + if(param != null){ + long isbn = Long.parseLong(param); + String title = req.getParameter("title"); + String author = req.getParameter("author"); + int price = Integer.parseInt(req.getParameter("price")); + int year = Integer.parseInt(req.getParameter("year")); + String category = req.getParameter("category"); + String description = req.getParameter("description"); + String publisher = req.getParameter("publisher"); + + Book book = new Book( + 0, + new Author(0,author), + new Publisher(0,publisher), + new Category(0,category, "DxAzOKSiPoE"), + title, Year.of(year),price,description, "DxAzOKSiPoE" + ); + //TODO add book + db.addBook(book); + + resp.sendRedirect("booklist"); + } + + resp.setCharacterEncoding("utf-8"); + PrintWriter out = resp.getWriter(); + + //header template + Utillity.insertFile(out, "template_head.html"); + + + ArrayList books = db.getBooks(); + + //book entries + out.println("
"); + for (Book book : books) { + + out.println("
"); + + out.println("
"); + out.println(" \"Buchcover\""); + out.println("
"); + + out.println("
"); + out.println("

" + book.getTitle() + "

"); + out.println("
"); + out.println("

" + book.getAuthor().getName() + "

"); + out.println("
"); + out.print("

" + book.getPrice() / 100 + ","); + if(book.getPrice() % 100 < 10){ + out.print("0"); + } + out.println(book.getPrice() % 100 +" €

"); + out.println("
"); + out.println("
"); + + out.println("
"); + out.println("
"); + + out.println(""); + out.println("Entfernen"); + out.println(""); + + out.println("
"); + out.println("
"); + out.println("
"); + } + out.println("
"); + + + //add book button + Utillity.addButton(out,"Neues Buch Hinzufügen", "addbook"); + + //footer template + Utillity.insertFile(out, "template_footer.html"); + } + + protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) + throws IOException { + doGet(req,resp); + } + +} diff --git a/src/main/java/de/hsel/itech/servlet/Utillity.java b/src/main/java/de/hsel/itech/servlet/Utillity.java new file mode 100644 index 0000000..74b998a --- /dev/null +++ b/src/main/java/de/hsel/itech/servlet/Utillity.java @@ -0,0 +1,51 @@ +package de.hsel.itech.servlet; + +import java.io.BufferedReader; +import java.io.FileReader; +import java.io.IOException; +import java.io.PrintWriter; + +public class Utillity { + + static public void insertFile(PrintWriter out, String fileName) { + try (BufferedReader br = new BufferedReader(new FileReader(Utillity.class.getClassLoader().getResource(fileName).getFile()))) { + for (String line = br.readLine(); line != null; line = br.readLine()) { + out.println(line); + } + } catch (IOException e) { + e.printStackTrace(); + } + } + + static public void addInput(PrintWriter out, String label, String name){ + out.println("
"); + out.println("
"); + out.println(label); + out.println(""); + out.println("
"); + out.println("
"); + } + + static public void addButton(PrintWriter out, String label, String url){ + out.println("
"); + out.println("
"); + out.println("
"); + out.println(""); + out.println(label); + out.println(""); + out.println("
"); + out.println("
"); + out.println("
"); + } + + static public void addTypeButton(PrintWriter out, String label, String type){ + out.println("
"); + out.println("
"); + //out.println("
"); + out.println(""); + //out.println(""); + //out.println("
"); + out.println("
"); + out.println("
"); + } +} diff --git a/src/main/resources/template_footer.html b/src/main/resources/template_footer.html new file mode 100644 index 0000000..c0a0803 --- /dev/null +++ b/src/main/resources/template_footer.html @@ -0,0 +1,81 @@ + + + + + + + + + + \ No newline at end of file diff --git a/src/main/resources/template_head.html b/src/main/resources/template_head.html new file mode 100644 index 0000000..d6dcbf2 --- /dev/null +++ b/src/main/resources/template_head.html @@ -0,0 +1,65 @@ + + + + Edit Book List + + + + + + + + + + + + + + + +
+ +
\ No newline at end of file diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index 391a545..4560e40 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -15,6 +15,16 @@ de.hsel.itech.servlet.Database + + booklist + de.hsel.itech.servlet.BookList + + + + addbook + de.hsel.itech.servlet.AddBook + + helloWorld /index @@ -24,4 +34,14 @@ database /db + + + booklist + /booklist + + + + addbook + /addbook + \ No newline at end of file diff --git a/src/main/webapp/preview/css/custom.css b/src/main/webapp/css/custom.css similarity index 100% rename from src/main/webapp/preview/css/custom.css rename to src/main/webapp/css/custom.css diff --git a/src/main/webapp/preview/css/m-components.css b/src/main/webapp/css/m-components.css similarity index 100% rename from src/main/webapp/preview/css/m-components.css rename to src/main/webapp/css/m-components.css diff --git a/src/main/webapp/preview/css/m-dark.compiled.css b/src/main/webapp/css/m-dark.compiled.css similarity index 100% rename from src/main/webapp/preview/css/m-dark.compiled.css rename to src/main/webapp/css/m-dark.compiled.css diff --git a/src/main/webapp/preview/css/m-dark.css b/src/main/webapp/css/m-dark.css similarity index 100% rename from src/main/webapp/preview/css/m-dark.css rename to src/main/webapp/css/m-dark.css diff --git a/src/main/webapp/preview/css/m-debug.css b/src/main/webapp/css/m-debug.css similarity index 100% rename from src/main/webapp/preview/css/m-debug.css rename to src/main/webapp/css/m-debug.css diff --git a/src/main/webapp/preview/css/m-doxygen.css b/src/main/webapp/css/m-doxygen.css similarity index 100% rename from src/main/webapp/preview/css/m-doxygen.css rename to src/main/webapp/css/m-doxygen.css diff --git a/src/main/webapp/preview/css/m-grid.css b/src/main/webapp/css/m-grid.css similarity index 100% rename from src/main/webapp/preview/css/m-grid.css rename to src/main/webapp/css/m-grid.css diff --git a/src/main/webapp/preview/css/m-layout.css b/src/main/webapp/css/m-layout.css similarity index 100% rename from src/main/webapp/preview/css/m-layout.css rename to src/main/webapp/css/m-layout.css diff --git a/src/main/webapp/preview/css/m-light.compiled.css b/src/main/webapp/css/m-light.compiled.css similarity index 100% rename from src/main/webapp/preview/css/m-light.compiled.css rename to src/main/webapp/css/m-light.compiled.css diff --git a/src/main/webapp/preview/css/m-light.css b/src/main/webapp/css/m-light.css similarity index 100% rename from src/main/webapp/preview/css/m-light.css rename to src/main/webapp/css/m-light.css diff --git a/src/main/webapp/preview/css/m-theme-dark.css b/src/main/webapp/css/m-theme-dark.css similarity index 100% rename from src/main/webapp/preview/css/m-theme-dark.css rename to src/main/webapp/css/m-theme-dark.css diff --git a/src/main/webapp/preview/css/m-theme-light.css b/src/main/webapp/css/m-theme-light.css similarity index 100% rename from src/main/webapp/preview/css/m-theme-light.css rename to src/main/webapp/css/m-theme-light.css diff --git a/src/main/webapp/preview/css/pygments-console.css b/src/main/webapp/css/pygments-console.css similarity index 100% rename from src/main/webapp/preview/css/pygments-console.css rename to src/main/webapp/css/pygments-console.css diff --git a/src/main/webapp/preview/css/pygments-dark.css b/src/main/webapp/css/pygments-dark.css similarity index 100% rename from src/main/webapp/preview/css/pygments-dark.css rename to src/main/webapp/css/pygments-dark.css diff --git a/src/main/webapp/preview/css/slick-theme.css b/src/main/webapp/css/slick-theme.css similarity index 100% rename from src/main/webapp/preview/css/slick-theme.css rename to src/main/webapp/css/slick-theme.css diff --git a/src/main/webapp/preview/book.html b/src/main/webapp/preview/book.html index eb30c83..caf6525 100644 --- a/src/main/webapp/preview/book.html +++ b/src/main/webapp/preview/book.html @@ -3,12 +3,12 @@ Amazon light - + - - + + diff --git a/src/main/webapp/preview/catalog.html b/src/main/webapp/preview/catalog.html index f4c13b7..8574887 100644 --- a/src/main/webapp/preview/catalog.html +++ b/src/main/webapp/preview/catalog.html @@ -3,12 +3,12 @@ Amazon light - + - - + + diff --git a/src/main/webapp/preview/confirmation.html b/src/main/webapp/preview/confirmation.html index 28545cd..44553c8 100644 --- a/src/main/webapp/preview/confirmation.html +++ b/src/main/webapp/preview/confirmation.html @@ -3,12 +3,12 @@ Amazon light - + - - + + diff --git a/src/main/webapp/preview/detailpage.html b/src/main/webapp/preview/detailpage.html index 283bb9a..e42fc41 100644 --- a/src/main/webapp/preview/detailpage.html +++ b/src/main/webapp/preview/detailpage.html @@ -3,12 +3,12 @@ Amazon light - + - - + + diff --git a/src/main/webapp/preview/login.html b/src/main/webapp/preview/login.html index 623393a..df2ed05 100644 --- a/src/main/webapp/preview/login.html +++ b/src/main/webapp/preview/login.html @@ -3,12 +3,12 @@ Amazon light - + - - + + diff --git a/src/main/webapp/preview/orderinfo.html b/src/main/webapp/preview/orderinfo.html index 2bc3057..ccfad5c 100644 --- a/src/main/webapp/preview/orderinfo.html +++ b/src/main/webapp/preview/orderinfo.html @@ -3,12 +3,12 @@ Amazon light - + - - + + diff --git a/src/main/webapp/preview/register.html b/src/main/webapp/preview/register.html index 8fb71cd..177913a 100644 --- a/src/main/webapp/preview/register.html +++ b/src/main/webapp/preview/register.html @@ -3,12 +3,12 @@ Amazon light - + - - + + diff --git a/src/main/webapp/preview/shoppingcart.html b/src/main/webapp/preview/shoppingcart.html index ccd201c..e1b058e 100644 --- a/src/main/webapp/preview/shoppingcart.html +++ b/src/main/webapp/preview/shoppingcart.html @@ -3,12 +3,12 @@ Amazon light - + - - + + diff --git a/src/main/webapp/preview/start.html b/src/main/webapp/preview/start.html index b8ba79f..caa74b3 100644 --- a/src/main/webapp/preview/start.html +++ b/src/main/webapp/preview/start.html @@ -3,12 +3,12 @@ Amazon light - + - - + + diff --git a/src/main/webapp/preview/thanksForBuyin.html b/src/main/webapp/preview/thanksForBuyin.html index 1a2f3c8..1dfa652 100644 --- a/src/main/webapp/preview/thanksForBuyin.html +++ b/src/main/webapp/preview/thanksForBuyin.html @@ -3,12 +3,12 @@ Amazon light - + - - + + From 8b9d81bfc15f440040f7bdf0e54cee165416861e Mon Sep 17 00:00:00 2001 From: joethei Date: Thu, 18 Apr 2019 09:10:13 +0200 Subject: [PATCH 06/14] + delete(Book/Author/Publisher/Category) --- src/main/java/de/hsel/itech/db/Database.java | 133 +++++++++++++++---- 1 file changed, 108 insertions(+), 25 deletions(-) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 9243490..4e3c60a 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -30,6 +30,12 @@ import java.util.Map; */ public class Database { + private final String BOOK = "book"; + private final String AUTHOR = "author"; + private final String AUTHOR_BOOK = "author_book"; + private final String PUBLISHER = "publisher"; + private final String CATEGORY = "category"; + private static Database instance; public static Database getInstance() { @@ -100,7 +106,7 @@ public class Database { @Nullable public Author getAuthor(long id) { - Map.Entry entry = getResultSet(id, "author"); + Map.Entry entry = getResultSet(id, AUTHOR); assert entry != null; ResultSet rs = entry.getKey(); @@ -116,7 +122,7 @@ public class Database { @Nullable public Category getCategory(long id) { - Map.Entry entry = getResultSet(id, "category"); + Map.Entry entry = getResultSet(id, CATEGORY); assert entry != null; ResultSet rs = entry.getKey(); @@ -132,7 +138,7 @@ public class Database { @Nullable public Publisher getPublisher(long id) { - Map.Entry entry = getResultSet(id, "category"); + Map.Entry entry = getResultSet(id, PUBLISHER); assert entry != null; ResultSet rs = entry.getKey(); @@ -148,12 +154,12 @@ public class Database { @Nullable private List getAuthors(long id) { - Map.Entry, Connection> entry = getResultSets(id, "author_book", "book"); + Map.Entry, Connection> entry = getResultSets(id, AUTHOR_BOOK, BOOK); assert entry != null; try { List list = new ArrayList<>(); for (ResultSet rs : entry.getKey()) { - list.add(rs.getInt("author")); + list.add(rs.getInt(AUTHOR)); } entry.getValue().close(); return list; @@ -165,14 +171,14 @@ public class Database { @Nullable public Book getBook(long id) { - Map.Entry entry = getResultSet(id, "book"); + Map.Entry entry = getResultSet(id, BOOK); assert entry != null; ResultSet rs = entry.getKey(); Book book = null; try { - Category category = getCategory(rs.getLong("category")); - Publisher publisher = getPublisher(rs.getLong("publisher")); + Category category = getCategory(rs.getLong(CATEGORY)); + Publisher publisher = getPublisher(rs.getLong(PUBLISHER)); List authorIds = getAuthors(id); assert authorIds != null; List authors = new ArrayList<>(); @@ -191,7 +197,7 @@ public class Database { @Nullable public List getBooks() { - Map.Entry, Connection> entry = getResultSets("book", "id"); + Map.Entry, Connection> entry = getResultSets(BOOK, "id"); assert entry != null; List ids = new ArrayList<>(); @@ -298,7 +304,6 @@ public class Database { }catch (SQLException ex) { ex.printStackTrace(); } - return insertCount; } @@ -322,11 +327,90 @@ public class Database { }catch (SQLException ex) { ex.printStackTrace(); } - - return insertCount; } + /** + * inserts Publisher + * @param publisher Publisher + * @return insert count + */ + public int insert(@NotNull Publisher publisher) { + Connection connection = getConnection(); + assert connection != null; + + int insertCount = 0; + try{ + PreparedStatement statement = connection.prepareStatement("INSERT INTO publisher (name) VALUES (?)"); + statement.setString(1, publisher.getName()); + + insertCount += statement.executeUpdate(); + + connection.close(); + }catch (SQLException ex) { + ex.printStackTrace(); + } + return insertCount; + } + + public int deleteBook(long id) { + int deleteCount = 0; + + try{ + Connection connection = getConnection(); + assert connection != null; + + PreparedStatement statement = connection.prepareStatement("DELETE FROM author_book WHERE book = ?"); + statement.setLong(1, id); + deleteCount =+ statement.executeUpdate(); + + connection.close(); + }catch (SQLException ex) { + ex.printStackTrace(); + } + + deleteCount += delete(id, BOOK); + + return deleteCount; + } + + public int deleteAuthor(long id) { + return delete(id, AUTHOR); + } + + public int deletePublisher(long id) { + return delete(id, PUBLISHER); + } + + public int deleteCategory(long id) { + return delete(id, CATEGORY); + } + + + + /** + * + * @param id + * @param table + * @return delete count + */ + private int delete(long id, String table) { + Connection connection = getConnection(); + assert connection != null; + + int deleteCount = 0; + try{ + PreparedStatement statement = connection.prepareStatement("DELETE FROM ? WHERE id=?"); + statement.setString(1, table); + statement.setLong(2, id); + + deleteCount =+ statement.executeUpdate(); + + }catch (SQLException ex) { + ex.printStackTrace(); + } + return deleteCount; + } @@ -351,19 +435,8 @@ public class Database { return null; } - @NotNull - private Map.Entry, Connection> getListConnectionEntry(Connection connection, PreparedStatement statement) throws SQLException { - ResultSet resultSet = statement.executeQuery(); - - Map.Entry, Connection> entry = new AbstractMap.SimpleEntry<>(new ArrayList<>(), connection); - while (resultSet.next()) { - entry.getKey().add(resultSet); - } - return entry; - } - @Nullable - private Map.Entry, Connection> getResultSets(long id, String table, String column) { + private Map.Entry, Connection> getResultSets(long id, @NotNull String table, @NotNull String column) { Connection connection = getConnection(); try { assert connection != null; @@ -380,7 +453,7 @@ public class Database { } @Nullable - private Map.Entry, Connection> getResultSets(String table, String columns) { + private Map.Entry, Connection> getResultSets(@NotNull String table, @NotNull String columns) { Connection connection = getConnection(); try { assert connection != null; @@ -395,4 +468,14 @@ public class Database { return null; } + @NotNull + private Map.Entry, Connection> getListConnectionEntry(@NotNull Connection connection, @NotNull PreparedStatement statement) throws SQLException { + ResultSet resultSet = statement.executeQuery(); + + Map.Entry, Connection> entry = new AbstractMap.SimpleEntry<>(new ArrayList<>(), connection); + while (resultSet.next()) { + entry.getKey().add(resultSet); + } + return entry; + } } \ No newline at end of file From 48606ee9537340efee1b6306952e66c8f00b7e47 Mon Sep 17 00:00:00 2001 From: joethei Date: Thu, 18 Apr 2019 12:31:04 +0200 Subject: [PATCH 07/14] + Documentation ~ made Checkstyle happy --- checkstyle.xml | 9 +- pom.xml | 4 + .../de/hsel/itech/config/Configuration.java | 7 +- .../java/de/hsel/itech/config/Database.java | 2 + src/main/java/de/hsel/itech/db/Database.java | 255 +++++++++++++----- .../java/de/hsel/itech/db/pojo/Address.java | 2 + .../java/de/hsel/itech/db/pojo/Author.java | 2 + src/main/java/de/hsel/itech/db/pojo/Book.java | 4 +- .../java/de/hsel/itech/db/pojo/Category.java | 2 + .../hsel/itech/db/pojo/CreditCardPayment.java | 2 + .../java/de/hsel/itech/db/pojo/Customer.java | 2 + .../hsel/itech/db/pojo/DebitCardPayment.java | 2 + .../de/hsel/itech/db/pojo/InvoicePayment.java | 2 + .../java/de/hsel/itech/db/pojo/Order.java | 4 +- .../de/hsel/itech/db/pojo/PayPalPayment.java | 2 + .../de/hsel/itech/db/pojo/PaymentType.java | 2 + .../java/de/hsel/itech/db/pojo/Publisher.java | 2 + .../de/hsel/itech/db/pojo/ShoppingCart.java | 2 + .../servlet/{DBTest.java => DbTest.java} | 4 +- src/main/webapp/WEB-INF/web.xml | 2 +- 20 files changed, 241 insertions(+), 72 deletions(-) rename src/main/java/de/hsel/itech/servlet/{DBTest.java => DbTest.java} (94%) diff --git a/checkstyle.xml b/checkstyle.xml index 1cec088..0c17f24 100644 --- a/checkstyle.xml +++ b/checkstyle.xml @@ -44,7 +44,7 @@ - + @@ -55,13 +55,14 @@ - + + + + value="LITERAL_TRY, LITERAL_CATCH, LITERAL_FINALLY, LITERAL_DO, LITERAL_IF, LITERAL_ELSE"/> diff --git a/pom.xml b/pom.xml index 2418572..188835c 100644 --- a/pom.xml +++ b/pom.xml @@ -212,6 +212,10 @@ spotbugs-maven-plugin 3.1.9 + + org.apache.maven.plugins + maven-javadoc-plugin + diff --git a/src/main/java/de/hsel/itech/config/Configuration.java b/src/main/java/de/hsel/itech/config/Configuration.java index 3c2b440..3412c35 100644 --- a/src/main/java/de/hsel/itech/config/Configuration.java +++ b/src/main/java/de/hsel/itech/config/Configuration.java @@ -10,6 +10,8 @@ import java.io.FileNotFoundException; import java.io.FileReader; /** + * config object. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 @@ -25,7 +27,10 @@ public class Configuration { private Database database; - + /** + * gets Configuration object from file. + * @return {@link de.hsel.itech.config.Configuration} + */ public static Configuration get() { Gson gson = new Gson(); diff --git a/src/main/java/de/hsel/itech/config/Database.java b/src/main/java/de/hsel/itech/config/Database.java index 2e78599..3eb5138 100644 --- a/src/main/java/de/hsel/itech/config/Database.java +++ b/src/main/java/de/hsel/itech/config/Database.java @@ -5,6 +5,8 @@ import lombok.Getter; import lombok.ToString; /** + * POJO for gson. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 4e3c60a..35af2eb 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -24,20 +24,27 @@ import java.util.List; import java.util.Map; /** + * base class for everything regarding the database. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 */ public class Database { - private final String BOOK = "book"; - private final String AUTHOR = "author"; - private final String AUTHOR_BOOK = "author_book"; - private final String PUBLISHER = "publisher"; - private final String CATEGORY = "category"; + private final String book = "book"; + private final String author = "author"; + private final String authorBook = "author_book"; + private final String publisher = "publisher"; + private final String category = "category"; private static Database instance; + /** + * Singleton for database access. + * + * @return {@link Database} + */ public static Database getInstance() { if (instance == null) instance = new Database(); @@ -46,9 +53,13 @@ public class Database { private MariaDbPoolDataSource dataSource; + /** + * initializes connection pool and executes database setup. + */ private Database() { Configuration config = Configuration.get(); - dataSource = new MariaDbPoolDataSource("jdbc:mysql://" + config.getDatabase().getHostname() + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase()); + dataSource = new MariaDbPoolDataSource("jdbc:mysql://" + config.getDatabase().getHostname() + + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase()); try { dataSource.setUser(config.getDatabase().getUsername()); dataSource.setPassword(config.getDatabase().getPassword()); @@ -74,6 +85,11 @@ public class Database { } } + /** + * gets connection from connection pool. + * + * @return {@link java.sql.Connection} + */ @Nullable private Connection getConnection() { try { @@ -84,6 +100,12 @@ public class Database { return null; } + /** + * testing method. + * + * @return String + */ + @Deprecated public String getHello() { Connection connection = getConnection(); @@ -92,21 +114,25 @@ public class Database { assert connection != null; PreparedStatement statement = connection.prepareStatement("SELECT * FROM test WHERE id = 1"); ResultSet resultSet = statement.executeQuery(); - resultSet.next(); - hello = resultSet.getString("hello"); + if (resultSet.next()) + hello = resultSet.getString("hello"); connection.close(); } catch (SQLException e) { e.printStackTrace(); } - return hello; - } + /** + * gets author by id. + * + * @param id ID from database + * @return {@link de.hsel.itech.db.pojo.Author} + */ @Nullable public Author getAuthor(long id) { - Map.Entry entry = getResultSet(id, AUTHOR); + Map.Entry entry = getResultSet(id, author); assert entry != null; ResultSet rs = entry.getKey(); @@ -120,9 +146,15 @@ public class Database { return author; } + /** + * gets category by id. + * + * @param id ID from database + * @return {@link de.hsel.itech.db.pojo.Category} + */ @Nullable public Category getCategory(long id) { - Map.Entry entry = getResultSet(id, CATEGORY); + Map.Entry entry = getResultSet(id, category); assert entry != null; ResultSet rs = entry.getKey(); @@ -136,9 +168,15 @@ public class Database { return category; } + /** + * gets publisher by id. + * + * @param id ID from database + * @return {@link de.hsel.itech.db.pojo.Publisher} + */ @Nullable public Publisher getPublisher(long id) { - Map.Entry entry = getResultSet(id, PUBLISHER); + Map.Entry entry = getResultSet(id, publisher); assert entry != null; ResultSet rs = entry.getKey(); @@ -152,14 +190,20 @@ public class Database { return publisher; } + /** + * gets list of author ids from database. + * + * @param id book id from database + * @return {@link java.util.List} + */ @Nullable private List getAuthors(long id) { - Map.Entry, Connection> entry = getResultSets(id, AUTHOR_BOOK, BOOK); + Map.Entry, Connection> entry = getResultSets(id, authorBook, book); assert entry != null; try { List list = new ArrayList<>(); for (ResultSet rs : entry.getKey()) { - list.add(rs.getInt(AUTHOR)); + list.add(rs.getInt(author)); } entry.getValue().close(); return list; @@ -169,16 +213,22 @@ public class Database { return null; } + /** + * gets book by id. + * + * @param id ID from database + * @return {@link de.hsel.itech.db.pojo.Book} + */ @Nullable public Book getBook(long id) { - Map.Entry entry = getResultSet(id, BOOK); + Map.Entry entry = getResultSet(id, book); assert entry != null; ResultSet rs = entry.getKey(); Book book = null; try { - Category category = getCategory(rs.getLong(CATEGORY)); - Publisher publisher = getPublisher(rs.getLong(PUBLISHER)); + Category category = getCategory(rs.getLong(this.category)); + Publisher publisher = getPublisher(rs.getLong(this.publisher)); List authorIds = getAuthors(id); assert authorIds != null; List authors = new ArrayList<>(); @@ -187,7 +237,9 @@ public class Database { assert author != null; authors.add(author); } - book = new Book(rs.getLong("id"), authors, publisher, category, rs.getString("title"), Year.of(rs.getInt("year")), rs.getInt("price"), rs.getString("description"), rs.getString("image")); + book = new Book(rs.getLong("id"), authors, publisher, category, rs.getString("title"), + Year.of(rs.getInt("year")), rs.getInt("price"), rs.getString("description"), + rs.getString("image")); entry.getValue().close(); } catch (SQLException e) { e.printStackTrace(); @@ -195,9 +247,14 @@ public class Database { return book; } + /** + * gets all books. + * + * @return {@link java.util.List} + */ @Nullable public List getBooks() { - Map.Entry, Connection> entry = getResultSets(BOOK, "id"); + Map.Entry, Connection> entry = getResultSets(book, "id"); assert entry != null; List ids = new ArrayList<>(); @@ -210,12 +267,18 @@ public class Database { ex.printStackTrace(); } List books = new ArrayList<>(); - for(long id : ids) { + for (long id : ids) { books.add(getBook(id)); } return books; } + /** + * gets books by category. + * + * @param category category id + * @return {@link java.util.List} + */ @Nullable public List getBooks(long category) { Connection connection = getConnection(); @@ -228,7 +291,7 @@ public class Database { ResultSet resultSet = statement.executeQuery(); - while(resultSet.next()) { + while (resultSet.next()) { books.add(getBook(resultSet.getLong("id"))); } @@ -239,6 +302,12 @@ public class Database { return books; } + /** + * get books by category. + * + * @param category Category object + * @return {@link java.util.List} + */ @Nullable public List getBooks(@NotNull Category category) { return getBooks(category.getId()); @@ -246,9 +315,9 @@ public class Database { /** - * Inserts book into database + * Inserts book into database. + * authors, publishers, and category have to exist. * - * authors, publishers, and category have to exist * @param book Book * @return insert count */ @@ -259,7 +328,8 @@ public class Database { int insertCount = 0; try { - PreparedStatement statement = connection.prepareStatement("INSERT INTO book (title, description, price, year, publisher, category, image) VALUES (?, ?, ?, ?, ?, ?, ?)"); + PreparedStatement statement = connection.prepareStatement("INSERT INTO book(title, description, " + + "price, year, publisher, category, image) VALUES (?, ?, ?, ?, ?, ?, ?)"); statement.setString(1, book.getTitle()); statement.setString(2, book.getDescription()); statement.setInt(3, book.getPrice()); @@ -269,7 +339,7 @@ public class Database { statement.setString(7, book.getImage()); insertCount += statement.executeUpdate(); - for(Author author : book.getAuthors()) { + for (Author author : book.getAuthors()) { PreparedStatement authorStatement = connection.prepareStatement("INSERT INTO author_book (author, book) VALUES (?, ?)"); statement.setLong(1, author.getId()); statement.setLong(2, book.getIsbn()); @@ -284,7 +354,8 @@ public class Database { } /** - * inserts Category into database + * inserts Category into database. + * * @param category Category * @return insert count */ @@ -294,44 +365,46 @@ public class Database { int insertCount = 0; - try{ + try { PreparedStatement statement = connection.prepareStatement("INSERT INTO category (name, image) VALUES (?, ?)"); statement.setString(1, category.getName()); statement.setString(2, category.getImage()); insertCount += statement.executeUpdate(); connection.close(); - }catch (SQLException ex) { + } catch (SQLException ex) { ex.printStackTrace(); } return insertCount; } /** - * inserts Author + * inserts Author. + * * @param author Author * @return insert count */ public int insert(@NotNull Author author) { Connection connection = getConnection(); - assert connection != null; + assert connection != null; int insertCount = 0; - try{ + try { PreparedStatement statement = connection.prepareStatement("INSERT INTO author (name) VALUES (?)"); statement.setString(1, author.getName()); insertCount += statement.executeUpdate(); connection.close(); - }catch (SQLException ex) { + } catch (SQLException ex) { ex.printStackTrace(); } return insertCount; } /** - * inserts Publisher + * inserts Publisher. + * * @param publisher Publisher * @return insert count */ @@ -340,81 +413,110 @@ public class Database { assert connection != null; int insertCount = 0; - try{ + try { PreparedStatement statement = connection.prepareStatement("INSERT INTO publisher (name) VALUES (?)"); statement.setString(1, publisher.getName()); insertCount += statement.executeUpdate(); connection.close(); - }catch (SQLException ex) { + } catch (SQLException ex) { ex.printStackTrace(); } return insertCount; } + /** + * deletes book from database. + * + * @param id book id + * @return deletion count + */ public int deleteBook(long id) { int deleteCount = 0; - try{ + try { Connection connection = getConnection(); assert connection != null; PreparedStatement statement = connection.prepareStatement("DELETE FROM author_book WHERE book = ?"); statement.setLong(1, id); - deleteCount =+ statement.executeUpdate(); + deleteCount = +statement.executeUpdate(); connection.close(); - }catch (SQLException ex) { + } catch (SQLException ex) { ex.printStackTrace(); } - deleteCount += delete(id, BOOK); + deleteCount += delete(id, book); return deleteCount; } + /** + * deletes author from database. + * + * @param id author id + * @return deletion count + */ public int deleteAuthor(long id) { - return delete(id, AUTHOR); + return delete(id, author); } + /** + * deletes publisher from database. + * + * @param id publisher id + * @return deletion count + */ public int deletePublisher(long id) { - return delete(id, PUBLISHER); + return delete(id, publisher); } + /** + * deletes category from database. + * + * @param id category count + * @return deletion count + */ public int deleteCategory(long id) { - return delete(id, CATEGORY); + return delete(id, category); } - /** + * deletes id from table. * - * @param id - * @param table - * @return delete count + * @param id database id + * @param table table name + * @return deletion count */ private int delete(long id, String table) { Connection connection = getConnection(); assert connection != null; int deleteCount = 0; - try{ + try { PreparedStatement statement = connection.prepareStatement("DELETE FROM ? WHERE id=?"); statement.setString(1, table); statement.setLong(2, id); - deleteCount =+ statement.executeUpdate(); + deleteCount = +statement.executeUpdate(); - }catch (SQLException ex) { + } catch (SQLException ex) { ex.printStackTrace(); } return deleteCount; } - - + /** + * gets specific entry from database. + * + * @param id id from database + * @param table table name + * @return {@link java.util.Map.Entry} + */ @Nullable private Map.Entry getResultSet(long id, String table) { Connection connection = getConnection(); @@ -435,6 +537,14 @@ public class Database { return null; } + /** + * gets specific entries from table. + * + * @param id id all entries should reference + * @param table table name + * @param column column to match + * @return {@link java.util.Map.Entry} + */ @Nullable private Map.Entry, Connection> getResultSets(long id, @NotNull String table, @NotNull String column) { Connection connection = getConnection(); @@ -445,37 +555,56 @@ public class Database { statement.setString(2, column); statement.setLong(3, id); - return getListConnectionEntry(connection, statement); + return getAllEntries(connection, statement); } catch (SQLException ex) { ex.printStackTrace(); } return null; } + /** + * gets all specified columns from table. + * + * @param table table name + * @param columns columns as String array + * @return {@link java.util.Map.Entry} + */ @Nullable - private Map.Entry, Connection> getResultSets(@NotNull String table, @NotNull String columns) { + private Map.Entry, Connection> getResultSets(@NotNull String table, @NotNull String... columns) { Connection connection = getConnection(); try { assert connection != null; PreparedStatement statement = connection.prepareStatement("SELECT (?) FROM ?"); - statement.setString(1, columns); + statement.setString(1, String.join(",", columns)); statement.setString(2, table); - return getListConnectionEntry(connection, statement); + return getAllEntries(connection, statement); } catch (SQLException ex) { ex.printStackTrace(); } return null; } - @NotNull - private Map.Entry, Connection> getListConnectionEntry(@NotNull Connection connection, @NotNull PreparedStatement statement) throws SQLException { - ResultSet resultSet = statement.executeQuery(); + /** + * gets all entries contained in result set. + * + * @param connection Connection + * @param statement query statement + * @return {@link java.util.Map.Entry} + */ + @Nullable + private Map.Entry, Connection> getAllEntries(@NotNull Connection connection, @NotNull PreparedStatement statement) { + try { + ResultSet resultSet = statement.executeQuery(); - Map.Entry, Connection> entry = new AbstractMap.SimpleEntry<>(new ArrayList<>(), connection); - while (resultSet.next()) { - entry.getKey().add(resultSet); + Map.Entry, Connection> entry = new AbstractMap.SimpleEntry<>(new ArrayList<>(), connection); + while (resultSet.next()) { + entry.getKey().add(resultSet); + } + return entry; + } catch (SQLException ex) { + ex.printStackTrace(); } - return entry; + return null; } } \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/db/pojo/Address.java b/src/main/java/de/hsel/itech/db/pojo/Address.java index 80f64a2..030e0be 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Address.java +++ b/src/main/java/de/hsel/itech/db/pojo/Address.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** + * POJO for Address. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/pojo/Author.java b/src/main/java/de/hsel/itech/db/pojo/Author.java index a657c51..ce43d7d 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Author.java +++ b/src/main/java/de/hsel/itech/db/pojo/Author.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** + * POJO for Author. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/pojo/Book.java b/src/main/java/de/hsel/itech/db/pojo/Book.java index 8adb3a7..c0fc7aa 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Book.java +++ b/src/main/java/de/hsel/itech/db/pojo/Book.java @@ -9,6 +9,8 @@ import java.time.Year; import java.util.List; /** + * POJO for Book. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 @@ -27,7 +29,7 @@ public class Book { @NonNull private Year year; /** - * saved in cents + * saved in cents. */ @NonNull private int price; @NonNull private String description; diff --git a/src/main/java/de/hsel/itech/db/pojo/Category.java b/src/main/java/de/hsel/itech/db/pojo/Category.java index f2ebeb4..28eb94e 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Category.java +++ b/src/main/java/de/hsel/itech/db/pojo/Category.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** + * POJO for Category. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java b/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java index bb7957f..0145e55 100644 --- a/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java +++ b/src/main/java/de/hsel/itech/db/pojo/CreditCardPayment.java @@ -8,6 +8,8 @@ import lombok.RequiredArgsConstructor; import java.time.LocalDate; /** + * POJO for CreditCard Payment. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/pojo/Customer.java b/src/main/java/de/hsel/itech/db/pojo/Customer.java index 61c0a2f..566afd3 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Customer.java +++ b/src/main/java/de/hsel/itech/db/pojo/Customer.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** + * POJO for Customer. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/pojo/DebitCardPayment.java b/src/main/java/de/hsel/itech/db/pojo/DebitCardPayment.java index d4bfb78..5e7afdd 100644 --- a/src/main/java/de/hsel/itech/db/pojo/DebitCardPayment.java +++ b/src/main/java/de/hsel/itech/db/pojo/DebitCardPayment.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** + * POJO for DebitCard Payment. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/pojo/InvoicePayment.java b/src/main/java/de/hsel/itech/db/pojo/InvoicePayment.java index 4bf7d0e..b250a97 100644 --- a/src/main/java/de/hsel/itech/db/pojo/InvoicePayment.java +++ b/src/main/java/de/hsel/itech/db/pojo/InvoicePayment.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** + * POJO for Invoice Payment. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/pojo/Order.java b/src/main/java/de/hsel/itech/db/pojo/Order.java index e990112..203a8eb 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Order.java +++ b/src/main/java/de/hsel/itech/db/pojo/Order.java @@ -9,6 +9,8 @@ import java.time.LocalDateTime; /** + * POJO for Orders. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 @@ -24,7 +26,7 @@ public class Order { @NonNull private Book book; /** - * price in cents + * price in cents. */ @NonNull private int price; @NonNull private PaymentType paymentType; diff --git a/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java b/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java index 6a5d4fe..be55830 100644 --- a/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java +++ b/src/main/java/de/hsel/itech/db/pojo/PayPalPayment.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** + * POJO for PayPal Payment. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/pojo/PaymentType.java b/src/main/java/de/hsel/itech/db/pojo/PaymentType.java index f191503..dad8e43 100644 --- a/src/main/java/de/hsel/itech/db/pojo/PaymentType.java +++ b/src/main/java/de/hsel/itech/db/pojo/PaymentType.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** + * POJO for PaymentType. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/pojo/Publisher.java b/src/main/java/de/hsel/itech/db/pojo/Publisher.java index eee9d9e..3d34f23 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Publisher.java +++ b/src/main/java/de/hsel/itech/db/pojo/Publisher.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** + * POJO for Publisher. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/db/pojo/ShoppingCart.java b/src/main/java/de/hsel/itech/db/pojo/ShoppingCart.java index c56c4f3..547743a 100644 --- a/src/main/java/de/hsel/itech/db/pojo/ShoppingCart.java +++ b/src/main/java/de/hsel/itech/db/pojo/ShoppingCart.java @@ -6,6 +6,8 @@ import lombok.NonNull; import lombok.RequiredArgsConstructor; /** + * POJO for Shopping Cart. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 diff --git a/src/main/java/de/hsel/itech/servlet/DBTest.java b/src/main/java/de/hsel/itech/servlet/DbTest.java similarity index 94% rename from src/main/java/de/hsel/itech/servlet/DBTest.java rename to src/main/java/de/hsel/itech/servlet/DbTest.java index 7f797c1..db86770 100644 --- a/src/main/java/de/hsel/itech/servlet/DBTest.java +++ b/src/main/java/de/hsel/itech/servlet/DbTest.java @@ -9,11 +9,13 @@ import java.io.IOException; import java.io.PrintWriter; /** + * Database test. + * * @author Johannes Theiner * @version 0.1 * @since 0.1 **/ -public class DBTest extends HttpServlet { +public class DbTest extends HttpServlet { private static final long serialVersionUID = 15679036734L; diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml index b4d113c..a40a730 100644 --- a/src/main/webapp/WEB-INF/web.xml +++ b/src/main/webapp/WEB-INF/web.xml @@ -12,7 +12,7 @@ database - de.hsel.itech.servlet.DBTest + de.hsel.itech.servlet.DbTest From d3dff89b4e16f559dba196cd95c62dd59a52cc8e Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Thu, 18 Apr 2019 13:25:22 +0200 Subject: [PATCH 08/14] removed isbn field from addbook page set default values for year and price in addbook form --- .../java/de/hsel/itech/servlet/AddBook.java | 6 ++--- .../java/de/hsel/itech/servlet/BookList.java | 13 +++++----- .../java/de/hsel/itech/servlet/Utillity.java | 24 +++++++++++++++---- 3 files changed, 28 insertions(+), 15 deletions(-) diff --git a/src/main/java/de/hsel/itech/servlet/AddBook.java b/src/main/java/de/hsel/itech/servlet/AddBook.java index cabd6b3..77477a3 100644 --- a/src/main/java/de/hsel/itech/servlet/AddBook.java +++ b/src/main/java/de/hsel/itech/servlet/AddBook.java @@ -23,13 +23,13 @@ public class AddBook extends HttpServlet { ArrayList books = db.getBooks(); out.println("
"); - Utillity.addInput(out,"ISBN", "isbn"); Utillity.addInput(out,"Titel", "title"); Utillity.addInput(out,"Author", "author"); - Utillity.addInput(out,"Preis", "price"); - Utillity.addInput(out,"Jahr", "year"); + Utillity.addInput(out,"Preis", "price", "0"); + Utillity.addInput(out,"Jahr", "year", "2019"); Utillity.addInput(out,"Beschreibung", "description"); Utillity.addInput(out,"Verlag", "publisher"); + Utillity.addInput(out,"Bild", "image", "DxAzOKSiPoE"); Utillity.addTypeButton(out, "Hinzufügen", "submit"); out.println("
"); diff --git a/src/main/java/de/hsel/itech/servlet/BookList.java b/src/main/java/de/hsel/itech/servlet/BookList.java index c2622b7..99a29ec 100644 --- a/src/main/java/de/hsel/itech/servlet/BookList.java +++ b/src/main/java/de/hsel/itech/servlet/BookList.java @@ -13,6 +13,7 @@ import java.io.PrintWriter; import java.time.Year; import java.util.ArrayList; import java.util.Enumeration; +import java.util.Random; public class BookList extends HttpServlet { @@ -33,13 +34,11 @@ public class BookList extends HttpServlet { String param = req.getParameter("removeid"); if(param != null){ long isbn = Long.parseLong(param); - //TODO remove book from Database db.removeBook(isbn); + resp.sendRedirect("booklist"); } - param = req.getParameter("isbn"); - if(param != null){ - long isbn = Long.parseLong(param); + if(req.getParameter("title") != null){ String title = req.getParameter("title"); String author = req.getParameter("author"); int price = Integer.parseInt(req.getParameter("price")); @@ -47,15 +46,15 @@ public class BookList extends HttpServlet { String category = req.getParameter("category"); String description = req.getParameter("description"); String publisher = req.getParameter("publisher"); + String image = req.getParameter("image"); Book book = new Book( - 0, + new Random().nextInt(), new Author(0,author), new Publisher(0,publisher), new Category(0,category, "DxAzOKSiPoE"), - title, Year.of(year),price,description, "DxAzOKSiPoE" + title, Year.of(year),price,description, image ); - //TODO add book db.addBook(book); resp.sendRedirect("booklist"); diff --git a/src/main/java/de/hsel/itech/servlet/Utillity.java b/src/main/java/de/hsel/itech/servlet/Utillity.java index 74b998a..dddceac 100644 --- a/src/main/java/de/hsel/itech/servlet/Utillity.java +++ b/src/main/java/de/hsel/itech/servlet/Utillity.java @@ -18,10 +18,14 @@ public class Utillity { } static public void addInput(PrintWriter out, String label, String name){ + addInput(out,label,name,""); + } + + static public void addInput(PrintWriter out, String label, String name, String value){ out.println("
"); out.println("
"); out.println(label); - out.println(""); + out.println(""); out.println("
"); out.println("
"); } @@ -39,13 +43,23 @@ public class Utillity { } static public void addTypeButton(PrintWriter out, String label, String type){ + /* out.println("
"); out.println("
"); - //out.println("
"); - out.println(""); - //out.println(""); - //out.println("
"); + out.println(" "); out.println("
"); out.println("
"); + */ + + out.println("
"); + out.println("
"); + out.println(" "); + out.println("
"); + out.println("
"); } } From c57fe0491634f22791de04e315ece0876f77812f Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Tue, 23 Apr 2019 15:32:52 +0200 Subject: [PATCH 09/14] edit book servlet now interacts with database --- src/main/java/de/hsel/itech/db/Database.java | 48 ++++++++++ .../java/de/hsel/itech/servlet/AddBook.java | 6 +- .../java/de/hsel/itech/servlet/BookList.java | 94 +++++++++++-------- 3 files changed, 104 insertions(+), 44 deletions(-) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 35af2eb..2faa88e 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -146,6 +146,28 @@ public class Database { return author; } + @Nullable + public Author getAuthor(String name) { + Author author = null; + + Map.Entry, Connection> set = getResultSets(this.author, "name", name); + + if(set == null){ + return null; + } + + if (set.getKey().size() > 0) { + try { + author = new Author(set.getKey().get(0).getLong("id"), set.getKey().get(0).getString("name")); + } catch (SQLException e) { + e.printStackTrace(); + } + } + + + return author; + } + /** * gets category by id. * @@ -562,6 +584,32 @@ public class Database { return null; } + /** + * gets specific entries from table. + * + * @param table table name + * @param column column to match + * @return {@link java.util.Map.Entry} + */ + @Nullable + private Map.Entry, Connection> getResultSets(@NotNull String table, @NotNull String column, @NotNull String value) { + Connection connection = getConnection(); + try { + assert connection != null; + PreparedStatement statement = connection.prepareStatement("SELECT * FROM ? WHERE ? = ?"); + statement.setString(1, table); + statement.setString(2, column); + statement.setString(3, value); + + System.out.println(statement); + + return getAllEntries(connection, statement); + } catch (SQLException ex) { + ex.printStackTrace(); + } + return null; + } + /** * gets all specified columns from table. * diff --git a/src/main/java/de/hsel/itech/servlet/AddBook.java b/src/main/java/de/hsel/itech/servlet/AddBook.java index 77477a3..3a5a4de 100644 --- a/src/main/java/de/hsel/itech/servlet/AddBook.java +++ b/src/main/java/de/hsel/itech/servlet/AddBook.java @@ -1,13 +1,10 @@ package de.hsel.itech.servlet; -import de.hsel.itech.db.pojo.Book; - import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; -import java.util.ArrayList; public class AddBook extends HttpServlet { @@ -20,7 +17,7 @@ public class AddBook extends HttpServlet { Utillity.insertFile(out, "template_head.html"); de.hsel.itech.db.Database db = de.hsel.itech.db.Database.getInstance(); - ArrayList books = db.getBooks(); + //List books = db.getBooks(); out.println("
"); Utillity.addInput(out,"Titel", "title"); @@ -29,6 +26,7 @@ public class AddBook extends HttpServlet { Utillity.addInput(out,"Jahr", "year", "2019"); Utillity.addInput(out,"Beschreibung", "description"); Utillity.addInput(out,"Verlag", "publisher"); + Utillity.addInput(out,"Kategorie", "category"); Utillity.addInput(out,"Bild", "image", "DxAzOKSiPoE"); Utillity.addTypeButton(out, "Hinzufügen", "submit"); out.println("
"); diff --git a/src/main/java/de/hsel/itech/servlet/BookList.java b/src/main/java/de/hsel/itech/servlet/BookList.java index 99a29ec..0ff4a15 100644 --- a/src/main/java/de/hsel/itech/servlet/BookList.java +++ b/src/main/java/de/hsel/itech/servlet/BookList.java @@ -13,7 +13,7 @@ import java.io.PrintWriter; import java.time.Year; import java.util.ArrayList; import java.util.Enumeration; -import java.util.Random; +import java.util.List; public class BookList extends HttpServlet { @@ -34,13 +34,13 @@ public class BookList extends HttpServlet { String param = req.getParameter("removeid"); if(param != null){ long isbn = Long.parseLong(param); - db.removeBook(isbn); + db.deleteBook(isbn); resp.sendRedirect("booklist"); } if(req.getParameter("title") != null){ String title = req.getParameter("title"); - String author = req.getParameter("author"); + String authorName = req.getParameter("author"); int price = Integer.parseInt(req.getParameter("price")); int year = Integer.parseInt(req.getParameter("year")); String category = req.getParameter("category"); @@ -48,14 +48,24 @@ public class BookList extends HttpServlet { String publisher = req.getParameter("publisher"); String image = req.getParameter("image"); + + ArrayList authors = new ArrayList(); + Author author = null; + + author = db.getAuthor(authorName); + + if(author == null){ + author = new Author(authorName); + db.insert(author); + } + authors.add(author); Book book = new Book( - new Random().nextInt(), - new Author(0,author), - new Publisher(0,publisher), - new Category(0,category, "DxAzOKSiPoE"), + authors, + new Publisher(publisher), + new Category(category, "DxAzOKSiPoE"), title, Year.of(year),price,description, image ); - db.addBook(book); + db.insert(book); resp.sendRedirect("booklist"); } @@ -67,44 +77,48 @@ public class BookList extends HttpServlet { Utillity.insertFile(out, "template_head.html"); - ArrayList books = db.getBooks(); + List books = db.getBooks(); - //book entries - out.println("
"); - for (Book book : books) { + if(books != null) { - out.println("
"); + //book entries + out.println("
"); + for (Book book : books) { - out.println("
"); - out.println(" \"Buchcover\""); - out.println("
"); + out.println("
"); - out.println("
"); - out.println("

" + book.getTitle() + "

"); - out.println("
"); - out.println("

" + book.getAuthor().getName() + "

"); - out.println("
"); - out.print("

" + book.getPrice() / 100 + ","); - if(book.getPrice() % 100 < 10){ - out.print("0"); + out.println("
"); + out.println(" \"Buchcover\""); + out.println("
"); + + out.println("
"); + out.println("

" + book.getTitle() + "

"); + out.println("
"); + for (int i = 0; i < book.getAuthors().size(); i++) { + out.println("

" + book.getAuthors().get(0).getName() + "

"); + } + out.println("
"); + out.print("

" + book.getPrice() / 100 + ","); + if (book.getPrice() % 100 < 10) { + out.print("0"); + } + out.println(book.getPrice() % 100 + " €

"); + out.println("
"); + out.println("
"); + + out.println("
"); + out.println("
"); + + out.println(""); + out.println("Entfernen"); + out.println(""); + + out.println("
"); + out.println("
"); + out.println("

"); } - out.println(book.getPrice() % 100 +" €"); - out.println("
"); - out.println("
"); - - out.println("
"); - out.println("
"); - - out.println(""); - out.println("Entfernen"); - out.println(""); - - out.println("
"); - out.println("
"); - out.println("
"); + out.println("
"); } - out.println("
"); - //add book button Utillity.addButton(out,"Neues Buch Hinzufügen", "addbook"); From c9ae2db7e19922ed9d4f5f3c4a0767e5531b2eb3 Mon Sep 17 00:00:00 2001 From: joethei Date: Wed, 24 Apr 2019 16:15:15 +0200 Subject: [PATCH 10/14] Meisten Bugs gefixt --- src/main/java/de/hsel/itech/db/Database.java | 208 +++++++++++++----- .../java/de/hsel/itech/db/pojo/Category.java | 13 +- .../java/de/hsel/itech/servlet/BookList.java | 22 +- 3 files changed, 171 insertions(+), 72 deletions(-) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 2faa88e..687a647 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -59,7 +59,7 @@ public class Database { private Database() { Configuration config = Configuration.get(); dataSource = new MariaDbPoolDataSource("jdbc:mysql://" + config.getDatabase().getHostname() - + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase()); + + ":" + config.getDatabase().getPort() + "/" + config.getDatabase().getDatabase() + "?useUnicode=true&characterEncoding=UTF-8"); try { dataSource.setUser(config.getDatabase().getUsername()); dataSource.setPassword(config.getDatabase().getPassword()); @@ -146,25 +146,34 @@ public class Database { return author; } + /** + * gets author by name. + * + * @param name author name + * @return {@link de.hsel.itech.db.pojo.Author} + */ @Nullable public Author getAuthor(String name) { + Map.Entry entry = getResultSets(author, "name", name); + assert entry != null; + assert entry.getKey() != null; + Author author = null; - - Map.Entry, Connection> set = getResultSets(this.author, "name", name); - - if(set == null){ - return null; - } - - if (set.getKey().size() > 0) { - try { - author = new Author(set.getKey().get(0).getLong("id"), set.getKey().get(0).getString("name")); - } catch (SQLException e) { - e.printStackTrace(); + ResultSet rs = entry.getKey(); + try { + while(rs.next()) { + System.out.println(rs.getString("name")); } + rs.beforeFirst(); + if(!rs.next()) { + System.out.println("test"); + }else + author = new Author(rs.getLong("id"), rs.getString("name")); + entry.getValue().close(); + } catch (SQLException e) { + e.printStackTrace(); } - return author; } @@ -178,15 +187,47 @@ public class Database { public Category getCategory(long id) { Map.Entry entry = getResultSet(id, category); assert entry != null; - ResultSet rs = entry.getKey(); - Category category = null; + try { - category = new Category(rs.getLong("id"), rs.getString("name"), rs.getString("image")); - entry.getValue().close(); + while(rs.next()) { + System.out.println(rs.getLong("id")); + } + + rs.beforeFirst(); } catch (SQLException e) { e.printStackTrace(); } + return getCategory(entry); + } + + /** + * get category by name. + * + * @param name category name + * @return {@link de.hsel.itech.db.pojo.Category} + */ + @Nullable + public Category getCategory(String name) { + Map.Entry entry = getResultSets(category, "name", name); + assert entry != null; + + return getCategory(entry); + } + + @Nullable + private Category getCategory(@NotNull Map.Entry entry) { + ResultSet rs = entry.getKey(); + Category category = null; + try{ + System.out.println(rs.getStatement()); + while(rs.next()) { + category = new Category(rs.getLong("id"), rs.getString("name"), rs.getString("image")); + } + entry.getValue().close(); + }catch (SQLException ex) { + ex.printStackTrace(); + } return category; } @@ -212,6 +253,32 @@ public class Database { return publisher; } + /** + * get publisher by name. + * + * @param name publisher name + * @return {@link de.hsel.itech.db.pojo.Publisher} + */ + @Nullable + public Publisher getPublisher(String name) { + Map.Entry entry = getResultSets(publisher, "name", name); + assert entry != null; + assert entry.getKey() != null; + + Publisher publisher = null; + ResultSet rs = entry.getKey(); + try { + while(rs.next()) { + publisher = new Publisher(rs.getLong("id"), rs.getString("name")); + } + entry.getValue().close(); + } catch (SQLException e) { + e.printStackTrace(); + } + + return publisher; + } + /** * gets list of author ids from database. * @@ -220,11 +287,12 @@ public class Database { */ @Nullable private List getAuthors(long id) { - Map.Entry, Connection> entry = getResultSets(id, authorBook, book); + Map.Entry entry = getResultSets(id, authorBook, book); assert entry != null; try { List list = new ArrayList<>(); - for (ResultSet rs : entry.getKey()) { + ResultSet rs = entry.getKey(); + while (rs.next()) { list.add(rs.getInt(author)); } entry.getValue().close(); @@ -252,7 +320,10 @@ public class Database { Category category = getCategory(rs.getLong(this.category)); Publisher publisher = getPublisher(rs.getLong(this.publisher)); List authorIds = getAuthors(id); + assert category != null; + assert publisher != null; assert authorIds != null; + List authors = new ArrayList<>(); for (int i : authorIds) { Author author = getAuthor(i); @@ -276,13 +347,14 @@ public class Database { */ @Nullable public List getBooks() { - Map.Entry, Connection> entry = getResultSets(book, "id"); + Map.Entry entry = getResultSets(book, "id"); assert entry != null; List ids = new ArrayList<>(); try { - for (ResultSet resultSet : entry.getKey()) { - ids.add(resultSet.getLong("id")); + ResultSet rs = entry.getKey(); + while (rs.next()) { + ids.add(rs.getLong("id")); } entry.getValue().close(); } catch (SQLException ex) { @@ -349,6 +421,47 @@ public class Database { int insertCount = 0; + //author exists ? + List authors = new ArrayList<>(); + for (Author author : book.getAuthors()) { + if (author.getId() == 0) { + Author dbAuthor = getAuthor(author.getName()); + System.out.println(dbAuthor); + if (dbAuthor == null) { + insertCount += insert(author); + dbAuthor = getAuthor(author.getName()); + } + authors.add(dbAuthor); + }else authors.add(author); + } + + //publisher exists ? + Publisher publisher; + if(book.getPublisher().getId() == 0) { + Publisher dbPublisher = getPublisher(book.getPublisher().getName()); + if(dbPublisher != null) + publisher = dbPublisher; + else { + insertCount += insert(new Publisher(book.getPublisher().getName())); + publisher = getPublisher(book.getPublisher().getName()); + } + }else publisher = book.getPublisher(); + + //category exists ? + Category category; + if(book.getCategory().getId() == 0) { + Category dbCategory = getCategory(book.getCategory().getName()); + if(dbCategory != null) + category = dbCategory; + else { + insertCount += insert(new Category(book.getCategory().getName(), book.getCategory().getImage())); + category = getCategory(book.getCategory().getName()); + } + }else category = book.getCategory(); + + assert publisher != null; + assert category != null; + try { PreparedStatement statement = connection.prepareStatement("INSERT INTO book(title, description, " + "price, year, publisher, category, image) VALUES (?, ?, ?, ?, ?, ?, ?)"); @@ -356,12 +469,12 @@ public class Database { statement.setString(2, book.getDescription()); statement.setInt(3, book.getPrice()); statement.setInt(4, book.getYear().getValue()); - statement.setLong(5, book.getPublisher().getId()); - statement.setLong(6, book.getCategory().getId()); + statement.setLong(5, publisher.getId()); + statement.setLong(6, category.getId()); statement.setString(7, book.getImage()); insertCount += statement.executeUpdate(); - for (Author author : book.getAuthors()) { + for (Author author : authors) { PreparedStatement authorStatement = connection.prepareStatement("INSERT INTO author_book (author, book) VALUES (?, ?)"); statement.setLong(1, author.getId()); statement.setLong(2, book.getIsbn()); @@ -519,9 +632,8 @@ public class Database { int deleteCount = 0; try { - PreparedStatement statement = connection.prepareStatement("DELETE FROM ? WHERE id=?"); - statement.setString(1, table); - statement.setLong(2, id); + PreparedStatement statement = connection.prepareStatement("DELETE FROM " + table + " WHERE id=?"); + statement.setLong(1, id); deleteCount = +statement.executeUpdate(); @@ -544,9 +656,8 @@ public class Database { Connection connection = getConnection(); try { assert connection != null; - PreparedStatement statement = connection.prepareStatement("SELECT * FROM ? WHERE ID = ?"); - statement.setString(1, table); - statement.setLong(2, id); + PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + table + " WHERE id = ?"); + statement.setLong(1, id); ResultSet resultSet = statement.executeQuery(); if (resultSet.next()) { return new AbstractMap.SimpleEntry<>(resultSet, connection); @@ -568,14 +679,12 @@ public class Database { * @return {@link java.util.Map.Entry} */ @Nullable - private Map.Entry, Connection> getResultSets(long id, @NotNull String table, @NotNull String column) { + private Map.Entry getResultSets(long id, @NotNull String table, @NotNull String column) { Connection connection = getConnection(); try { assert connection != null; - PreparedStatement statement = connection.prepareStatement("SELECT * FROM ? WHERE ? = ?"); - statement.setString(1, table); - statement.setString(2, column); - statement.setLong(3, id); + PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + table + " WHERE " + column + " = ?"); + statement.setLong(1, id); return getAllEntries(connection, statement); } catch (SQLException ex) { @@ -592,16 +701,12 @@ public class Database { * @return {@link java.util.Map.Entry} */ @Nullable - private Map.Entry, Connection> getResultSets(@NotNull String table, @NotNull String column, @NotNull String value) { + private Map.Entry getResultSets(@NotNull String table, @NotNull String column, @NotNull String value) { Connection connection = getConnection(); try { assert connection != null; - PreparedStatement statement = connection.prepareStatement("SELECT * FROM ? WHERE ? = ?"); - statement.setString(1, table); - statement.setString(2, column); - statement.setString(3, value); - - System.out.println(statement); + PreparedStatement statement = connection.prepareStatement("SELECT * FROM " + table + " WHERE " + column + " = ?"); + statement.setString(1, value); return getAllEntries(connection, statement); } catch (SQLException ex) { @@ -618,13 +723,11 @@ public class Database { * @return {@link java.util.Map.Entry} */ @Nullable - private Map.Entry, Connection> getResultSets(@NotNull String table, @NotNull String... columns) { + private Map.Entry getResultSets(@NotNull String table, @NotNull String... columns) { Connection connection = getConnection(); try { assert connection != null; - PreparedStatement statement = connection.prepareStatement("SELECT (?) FROM ?"); - statement.setString(1, String.join(",", columns)); - statement.setString(2, table); + PreparedStatement statement = connection.prepareStatement("SELECT (" + String.join(",", columns) + ") FROM " + table); return getAllEntries(connection, statement); } catch (SQLException ex) { @@ -641,15 +744,10 @@ public class Database { * @return {@link java.util.Map.Entry} */ @Nullable - private Map.Entry, Connection> getAllEntries(@NotNull Connection connection, @NotNull PreparedStatement statement) { + private Map.Entry getAllEntries(@NotNull Connection connection, @NotNull PreparedStatement statement) { try { ResultSet resultSet = statement.executeQuery(); - - Map.Entry, Connection> entry = new AbstractMap.SimpleEntry<>(new ArrayList<>(), connection); - while (resultSet.next()) { - entry.getKey().add(resultSet); - } - return entry; + return new AbstractMap.SimpleEntry<>(resultSet, connection); } catch (SQLException ex) { ex.printStackTrace(); } diff --git a/src/main/java/de/hsel/itech/db/pojo/Category.java b/src/main/java/de/hsel/itech/db/pojo/Category.java index 28eb94e..b3099ed 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Category.java +++ b/src/main/java/de/hsel/itech/db/pojo/Category.java @@ -1,9 +1,6 @@ package de.hsel.itech.db.pojo; -import lombok.AllArgsConstructor; -import lombok.Data; -import lombok.NonNull; -import lombok.RequiredArgsConstructor; +import lombok.*; /** * POJO for Category. @@ -16,9 +13,15 @@ import lombok.RequiredArgsConstructor; @Data @AllArgsConstructor @RequiredArgsConstructor +@NoArgsConstructor public class Category { private long id; @NonNull private String name; - @NonNull private String image; + private String image; + + public Category(String name, String image) { + this.name = name; + this.image = image; + } } diff --git a/src/main/java/de/hsel/itech/servlet/BookList.java b/src/main/java/de/hsel/itech/servlet/BookList.java index 0ff4a15..3c5c252 100644 --- a/src/main/java/de/hsel/itech/servlet/BookList.java +++ b/src/main/java/de/hsel/itech/servlet/BookList.java @@ -1,5 +1,6 @@ package de.hsel.itech.servlet; +import de.hsel.itech.db.Database; import de.hsel.itech.db.pojo.Author; import de.hsel.itech.db.pojo.Book; import de.hsel.itech.db.pojo.Category; @@ -21,7 +22,7 @@ public class BookList extends HttpServlet { throws IOException { //get database object - de.hsel.itech.db.Database db = de.hsel.itech.db.Database.getInstance(); + Database db = Database.getInstance(); //print parameter (debug) Enumeration names = req.getParameterNames(); @@ -43,26 +44,23 @@ public class BookList extends HttpServlet { String authorName = req.getParameter("author"); int price = Integer.parseInt(req.getParameter("price")); int year = Integer.parseInt(req.getParameter("year")); - String category = req.getParameter("category"); + String categoryName = req.getParameter("category"); String description = req.getParameter("description"); String publisher = req.getParameter("publisher"); String image = req.getParameter("image"); - ArrayList authors = new ArrayList(); - Author author = null; - - author = db.getAuthor(authorName); - - if(author == null){ - author = new Author(authorName); - db.insert(author); + ArrayList authors = new ArrayList<>(); + String[] authorNames = authorName.split(","); + for(String name : authorNames) { + authors.add(new Author(name)); } - authors.add(author); + Category category = new Category(); + category.setName(categoryName); Book book = new Book( authors, new Publisher(publisher), - new Category(category, "DxAzOKSiPoE"), + category, title, Year.of(year),price,description, image ); db.insert(book); From d91e4ad5f1d7fa2b158fa6308a9bb88016f96fe9 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Wed, 24 Apr 2019 21:59:23 +0200 Subject: [PATCH 11/14] + Fixed all insert bugs ~ found a weird one in PreparedStatement Signed-off-by: Johannes Theiner --- src/main/java/de/hsel/itech/db/Database.java | 57 +++++++++---------- src/main/java/de/hsel/itech/db/pojo/Book.java | 3 +- .../java/de/hsel/itech/servlet/AddBook.java | 3 +- .../java/de/hsel/itech/servlet/BookList.java | 30 +++++----- src/main/resources/database.sql | 2 +- 5 files changed, 47 insertions(+), 48 deletions(-) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 687a647..0e7bea2 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -13,10 +13,7 @@ import java.io.BufferedReader; import java.io.FileReader; import java.io.IOException; import java.net.URL; -import java.sql.Connection; -import java.sql.PreparedStatement; -import java.sql.ResultSet; -import java.sql.SQLException; +import java.sql.*; import java.time.Year; import java.util.AbstractMap; import java.util.ArrayList; @@ -161,13 +158,7 @@ public class Database { Author author = null; ResultSet rs = entry.getKey(); try { - while(rs.next()) { - System.out.println(rs.getString("name")); - } - rs.beforeFirst(); - if(!rs.next()) { - System.out.println("test"); - }else + if(rs.next()) author = new Author(rs.getLong("id"), rs.getString("name")); entry.getValue().close(); } catch (SQLException e) { @@ -190,10 +181,6 @@ public class Database { ResultSet rs = entry.getKey(); try { - while(rs.next()) { - System.out.println(rs.getLong("id")); - } - rs.beforeFirst(); } catch (SQLException e) { e.printStackTrace(); @@ -220,7 +207,6 @@ public class Database { ResultSet rs = entry.getKey(); Category category = null; try{ - System.out.println(rs.getStatement()); while(rs.next()) { category = new Category(rs.getLong("id"), rs.getString("name"), rs.getString("image")); } @@ -330,7 +316,7 @@ public class Database { assert author != null; authors.add(author); } - book = new Book(rs.getLong("id"), authors, publisher, category, rs.getString("title"), + book = new Book(rs.getLong("id"), rs.getLong("isbn"), authors, publisher, category, rs.getString("title"), Year.of(rs.getInt("year")), rs.getInt("price"), rs.getString("description"), rs.getString("image")); entry.getValue().close(); @@ -426,7 +412,6 @@ public class Database { for (Author author : book.getAuthors()) { if (author.getId() == 0) { Author dbAuthor = getAuthor(author.getName()); - System.out.println(dbAuthor); if (dbAuthor == null) { insertCount += insert(author); dbAuthor = getAuthor(author.getName()); @@ -463,21 +448,33 @@ public class Database { assert category != null; try { - PreparedStatement statement = connection.prepareStatement("INSERT INTO book(title, description, " - + "price, year, publisher, category, image) VALUES (?, ?, ?, ?, ?, ?, ?)"); - statement.setString(1, book.getTitle()); - statement.setString(2, book.getDescription()); - statement.setInt(3, book.getPrice()); - statement.setInt(4, book.getYear().getValue()); - statement.setLong(5, publisher.getId()); - statement.setLong(6, category.getId()); - statement.setString(7, book.getImage()); + PreparedStatement statement = connection.prepareStatement("INSERT INTO " + book + "(isbn, title, description, " + + "price, year, publisher, category, image) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); + statement.setLong(1, book.getIsbn()); + statement.setString(2, book.getTitle()); + statement.setString(3, book.getDescription()); + statement.setInt(4, book.getPrice()); + statement.setInt(5, book.getYear().getValue()); + statement.setLong(6, publisher.getId()); + statement.setLong(7, category.getId()); + statement.setString(8, book.getImage()); insertCount += statement.executeUpdate(); + ResultSet resultSet = statement.getGeneratedKeys(); + long lastId = -1; + while(resultSet.next()) { + lastId = resultSet.getLong("id"); + } for (Author author : authors) { - PreparedStatement authorStatement = connection.prepareStatement("INSERT INTO author_book (author, book) VALUES (?, ?)"); - statement.setLong(1, author.getId()); - statement.setLong(2, book.getIsbn()); + //FIXME: Prepared Statement is broken, parameters are null, but they are not + String query = "INSERT INTO " + authorBook + " (author, book) VALUES (?, ?);"; + String workingQuery = "INSERT INTO " + authorBook + " (author, book) VALUES (" + author.getId() + ", "+ lastId + ")"; + PreparedStatement authorStatement = connection.prepareStatement(workingQuery); + //statement.setLong(1, author.getId()); + //statement.setLong(2, lastId); + System.out.println(authorStatement); + System.out.println(author.getId()); + System.out.println(lastId); insertCount += authorStatement.executeUpdate(); } diff --git a/src/main/java/de/hsel/itech/db/pojo/Book.java b/src/main/java/de/hsel/itech/db/pojo/Book.java index c0fc7aa..e110d87 100644 --- a/src/main/java/de/hsel/itech/db/pojo/Book.java +++ b/src/main/java/de/hsel/itech/db/pojo/Book.java @@ -21,7 +21,8 @@ import java.util.List; @RequiredArgsConstructor public class Book { - private long isbn; + private long id; + @NonNull private long isbn; @NonNull private List authors; @NonNull private Publisher publisher; @NonNull private Category category; diff --git a/src/main/java/de/hsel/itech/servlet/AddBook.java b/src/main/java/de/hsel/itech/servlet/AddBook.java index 3a5a4de..e50e7c0 100644 --- a/src/main/java/de/hsel/itech/servlet/AddBook.java +++ b/src/main/java/de/hsel/itech/servlet/AddBook.java @@ -16,10 +16,9 @@ public class AddBook extends HttpServlet { PrintWriter out = resp.getWriter(); Utillity.insertFile(out, "template_head.html"); - de.hsel.itech.db.Database db = de.hsel.itech.db.Database.getInstance(); - //List books = db.getBooks(); out.println("
"); + Utillity.addInput(out, "ISBN", "isbn"); Utillity.addInput(out,"Titel", "title"); Utillity.addInput(out,"Author", "author"); Utillity.addInput(out,"Preis", "price", "0"); diff --git a/src/main/java/de/hsel/itech/servlet/BookList.java b/src/main/java/de/hsel/itech/servlet/BookList.java index 3c5c252..c7ef4f7 100644 --- a/src/main/java/de/hsel/itech/servlet/BookList.java +++ b/src/main/java/de/hsel/itech/servlet/BookList.java @@ -11,35 +11,37 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; +import java.nio.charset.StandardCharsets; import java.time.Year; import java.util.ArrayList; -import java.util.Enumeration; import java.util.List; public class BookList extends HttpServlet { protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { + req.setCharacterEncoding(StandardCharsets.UTF_8.name()); //get database object Database db = Database.getInstance(); - //print parameter (debug) - Enumeration names = req.getParameterNames(); - while(names.hasMoreElements()){ + //print parameters (debug) + /*Enumeration names = req.getParameterNames(); + while (names.hasMoreElements()) { String name = names.nextElement(); System.out.println(name + "=" + req.getParameter(name)); - } + }*/ //remove book by id String param = req.getParameter("removeid"); - if(param != null){ + if (param != null && Long.parseLong(param) != 0) { long isbn = Long.parseLong(param); db.deleteBook(isbn); resp.sendRedirect("booklist"); } - if(req.getParameter("title") != null){ + if (req.getParameter("title") != null) { + long isbn = Long.parseLong(req.getParameter("isbn")); String title = req.getParameter("title"); String authorName = req.getParameter("author"); int price = Integer.parseInt(req.getParameter("price")); @@ -52,16 +54,16 @@ public class BookList extends HttpServlet { ArrayList authors = new ArrayList<>(); String[] authorNames = authorName.split(","); - for(String name : authorNames) { + for (String name : authorNames) { authors.add(new Author(name)); } Category category = new Category(); category.setName(categoryName); - Book book = new Book( + Book book = new Book(isbn, authors, new Publisher(publisher), category, - title, Year.of(year),price,description, image + title, Year.of(year), price, description, image ); db.insert(book); @@ -77,7 +79,7 @@ public class BookList extends HttpServlet { List books = db.getBooks(); - if(books != null) { + if (books != null) { //book entries out.println("
"); @@ -107,7 +109,7 @@ public class BookList extends HttpServlet { out.println("
"); out.println("
"); - out.println(""); + out.println(""); out.println("Entfernen"); out.println(""); @@ -119,7 +121,7 @@ public class BookList extends HttpServlet { } //add book button - Utillity.addButton(out,"Neues Buch Hinzufügen", "addbook"); + Utillity.addButton(out, "Neues Buch Hinzufügen", "addbook"); //footer template Utillity.insertFile(out, "template_footer.html"); @@ -127,7 +129,7 @@ public class BookList extends HttpServlet { protected void doPost(final HttpServletRequest req, final HttpServletResponse resp) throws IOException { - doGet(req,resp); + doGet(req, resp); } } diff --git a/src/main/resources/database.sql b/src/main/resources/database.sql index 61bd410..ecde032 100644 --- a/src/main/resources/database.sql +++ b/src/main/resources/database.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS test(id bigint primary key auto_increment, hello varchar(25)); INSERT IGNORE INTO test(hello) values ('Welt'); -CREATE TABLE IF NOT EXISTS book (id bigint primary key auto_increment, title varchar(50), description varchar(500), price int, year year, publisher bigint, category bigint, image varchar(11) unique); +CREATE TABLE IF NOT EXISTS book (id bigint primary key auto_increment, isbn bigint unique, title varchar(50), description varchar(500), price int, year year, publisher bigint, category bigint, image varchar(11) unique); CREATE TABLE IF NOT EXISTS publisher(id bigint primary key auto_increment, name varchar(50) unique); CREATE TABLE IF NOT EXISTS author(id bigint primary key auto_increment, name varchar(50) unique); CREATE TABLE IF NOT EXISTS author_book(author bigint, book bigint, primary key(author, book), foreign key (author) REFERENCES author(id), foreign key (book) references book(id)); From 61e9b4df54919c5366065e1ae7a8fbf08216b733 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Thu, 25 Apr 2019 07:00:50 +0200 Subject: [PATCH 12/14] ~weird bug fixed: head->desk Signed-off-by: Johannes Theiner --- src/main/java/de/hsel/itech/db/Database.java | 14 ++++---------- 1 file changed, 4 insertions(+), 10 deletions(-) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 0e7bea2..146d2a6 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -448,7 +448,7 @@ public class Database { assert category != null; try { - PreparedStatement statement = connection.prepareStatement("INSERT INTO " + book + "(isbn, title, description, " + + PreparedStatement statement = connection.prepareStatement("INSERT INTO book(isbn, title, description, " + "price, year, publisher, category, image) VALUES (?, ?, ?, ?, ?, ?, ?, ?)", Statement.RETURN_GENERATED_KEYS); statement.setLong(1, book.getIsbn()); statement.setString(2, book.getTitle()); @@ -466,15 +466,9 @@ public class Database { } for (Author author : authors) { - //FIXME: Prepared Statement is broken, parameters are null, but they are not - String query = "INSERT INTO " + authorBook + " (author, book) VALUES (?, ?);"; - String workingQuery = "INSERT INTO " + authorBook + " (author, book) VALUES (" + author.getId() + ", "+ lastId + ")"; - PreparedStatement authorStatement = connection.prepareStatement(workingQuery); - //statement.setLong(1, author.getId()); - //statement.setLong(2, lastId); - System.out.println(authorStatement); - System.out.println(author.getId()); - System.out.println(lastId); + PreparedStatement authorStatement = connection.prepareStatement("INSERT INTO " + authorBook + " (author, book) VALUES (?, ?);"); + authorStatement.setLong(1, author.getId()); + authorStatement.setLong(2, lastId); insertCount += authorStatement.executeUpdate(); } From 5849812afd649c1fe198620ddd72087ba12337f0 Mon Sep 17 00:00:00 2001 From: Julian Hinxlage Date: Thu, 25 Apr 2019 11:31:47 +0200 Subject: [PATCH 13/14] changed booklist entries added value validation to addbook form added simple Error massages --- src/main/java/de/hsel/itech/db/Database.java | 1 + .../java/de/hsel/itech/servlet/AddBook.java | 17 ++- .../java/de/hsel/itech/servlet/BookList.java | 136 ++++++++++++------ .../java/de/hsel/itech/servlet/Utillity.java | 26 ++-- src/main/resources/database.sql | 2 +- 5 files changed, 116 insertions(+), 66 deletions(-) diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 146d2a6..9ea4650 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -300,6 +300,7 @@ public class Database { Map.Entry entry = getResultSet(id, book); assert entry != null; + ResultSet rs = entry.getKey(); Book book = null; try { diff --git a/src/main/java/de/hsel/itech/servlet/AddBook.java b/src/main/java/de/hsel/itech/servlet/AddBook.java index e50e7c0..a53e4d5 100644 --- a/src/main/java/de/hsel/itech/servlet/AddBook.java +++ b/src/main/java/de/hsel/itech/servlet/AddBook.java @@ -6,6 +6,14 @@ import javax.servlet.http.HttpServletResponse; import java.io.IOException; import java.io.PrintWriter; +/** + * Servlet: form to add a book to the database + * + * + * @author Julian Hinxlage + * @version 0.1 + * @since 0.1 + */ public class AddBook extends HttpServlet { @@ -18,20 +26,19 @@ public class AddBook extends HttpServlet { Utillity.insertFile(out, "template_head.html"); out.println(""); - Utillity.addInput(out, "ISBN", "isbn"); + Utillity.addValidationInput(out, "ISBN", "isbn", "text", "0", "[0-9]*"); Utillity.addInput(out,"Titel", "title"); Utillity.addInput(out,"Author", "author"); - Utillity.addInput(out,"Preis", "price", "0"); - Utillity.addInput(out,"Jahr", "year", "2019"); + Utillity.addValidationInput(out,"Preis", "price", "text", "0", "[0-9]*(,[0-9]{1,2})?"); + Utillity.addValidationInput(out,"Jahr", "year", "text", "2019", "[0-9]*"); Utillity.addInput(out,"Beschreibung", "description"); Utillity.addInput(out,"Verlag", "publisher"); Utillity.addInput(out,"Kategorie", "category"); Utillity.addInput(out,"Bild", "image", "DxAzOKSiPoE"); - Utillity.addTypeButton(out, "Hinzufügen", "submit"); + Utillity.addSubmitButton(out, "Hinzufügen"); out.println(""); - //Utillity.addButton(out,"Hinzufügen", "/itech/booklist"); Utillity.addButton(out,"Zurück zur Buchliste", "booklist"); Utillity.insertFile(out, "template_footer.html"); diff --git a/src/main/java/de/hsel/itech/servlet/BookList.java b/src/main/java/de/hsel/itech/servlet/BookList.java index c7ef4f7..bacbf33 100644 --- a/src/main/java/de/hsel/itech/servlet/BookList.java +++ b/src/main/java/de/hsel/itech/servlet/BookList.java @@ -16,6 +16,14 @@ import java.time.Year; import java.util.ArrayList; import java.util.List; +/** + * Servlet: list of all books and remove function + * + * + * @author Julian Hinxlage + * @version 0.1 + * @since 0.1 + */ public class BookList extends HttpServlet { protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) @@ -25,12 +33,11 @@ public class BookList extends HttpServlet { //get database object Database db = Database.getInstance(); - //print parameters (debug) - /*Enumeration names = req.getParameterNames(); - while (names.hasMoreElements()) { - String name = names.nextElement(); - System.out.println(name + "=" + req.getParameter(name)); - }*/ + resp.setCharacterEncoding("utf-8"); + PrintWriter out = resp.getWriter(); + + //header template + Utillity.insertFile(out, "template_head.html"); //remove book by id String param = req.getParameter("removeid"); @@ -40,45 +47,76 @@ public class BookList extends HttpServlet { resp.sendRedirect("booklist"); } + //add book to database if (req.getParameter("title") != null) { - long isbn = Long.parseLong(req.getParameter("isbn")); - String title = req.getParameter("title"); - String authorName = req.getParameter("author"); - int price = Integer.parseInt(req.getParameter("price")); - int year = Integer.parseInt(req.getParameter("year")); - String categoryName = req.getParameter("category"); - String description = req.getParameter("description"); - String publisher = req.getParameter("publisher"); - String image = req.getParameter("image"); + try { + long isbn = Long.parseLong(req.getParameter("isbn")); + String title = req.getParameter("title"); + String authorName = req.getParameter("author"); + String priceString = req.getParameter("price"); + String[] priceParts = priceString.split(","); + int price = Integer.parseInt(priceParts[0]) * 100; + if (priceParts.length >= 2) { + if (priceParts[1].length() == 1) { + price += Integer.parseInt(priceParts[1]) * 10; + } else { + price += Integer.parseInt(priceParts[1]); + } + } + int year = Integer.parseInt(req.getParameter("year")); + String categoryName = req.getParameter("category"); + String description = req.getParameter("description"); + String publisher = req.getParameter("publisher"); + String image = req.getParameter("image"); - ArrayList authors = new ArrayList<>(); - String[] authorNames = authorName.split(","); - for (String name : authorNames) { - authors.add(new Author(name)); + //check isbn + List books = db.getBooks(); + boolean found = false; + if (books != null) { + for(Book b : books){ + if(b.getIsbn() == isbn){ + found = true; + break; + } + } + } + + if (found) { + out.println(""); + } else { + ArrayList authors = new ArrayList<>(); + String[] authorNames = authorName.split(","); + for (String name : authorNames) { + authors.add(new Author(name)); + } + Category category = new Category(); + category.setName(categoryName); + Book book = new Book(isbn, + authors, + new Publisher(publisher), + category, + title, Year.of(year), price, description, image + ); + db.insert(book); + resp.sendRedirect("booklist"); + } + } + catch (Exception e){ + e.printStackTrace(); + out.println(""); } - Category category = new Category(); - category.setName(categoryName); - Book book = new Book(isbn, - authors, - new Publisher(publisher), - category, - title, Year.of(year), price, description, image - ); - db.insert(book); - resp.sendRedirect("booklist"); } - resp.setCharacterEncoding("utf-8"); - PrintWriter out = resp.getWriter(); - - //header template - Utillity.insertFile(out, "template_head.html"); + //list all books List books = db.getBooks(); - if (books != null) { //book entries @@ -92,18 +130,16 @@ public class BookList extends HttpServlet { out.println("
"); out.println("
"); - out.println("

" + book.getTitle() + "

"); - out.println("
"); + out.println("

" + book.getTitle() + "

"); + out.println("ISBN: " + book.getIsbn() + "
"); + for (int i = 0; i < book.getAuthors().size(); i++) { - out.println("

" + book.getAuthors().get(0).getName() + "

"); + out.println("von " + book.getAuthors().get(0).getName()); } - out.println("
"); - out.print("

" + book.getPrice() / 100 + ","); - if (book.getPrice() % 100 < 10) { - out.print("0"); - } - out.println(book.getPrice() % 100 + " €

"); - out.println("
"); + + out.println("
Veröffentlicht von " + book.getPublisher().getName() + ""); + out.println("

" + book.getDescription() + ""); + out.println("
"); out.println("
"); @@ -113,6 +149,16 @@ public class BookList extends HttpServlet { out.println("Entfernen"); out.println(""); + out.println("
"); + out.println("
"); + + out.print("

" + book.getPrice() / 100 + ","); + if (book.getPrice() % 100 < 10) { + out.print("0"); + } + + out.println(book.getPrice() % 100 + " €

"); + out.println("
"); out.println("
"); out.println("
"); diff --git a/src/main/java/de/hsel/itech/servlet/Utillity.java b/src/main/java/de/hsel/itech/servlet/Utillity.java index dddceac..9521525 100644 --- a/src/main/java/de/hsel/itech/servlet/Utillity.java +++ b/src/main/java/de/hsel/itech/servlet/Utillity.java @@ -30,6 +30,15 @@ public class Utillity { out.println(""); } + static public void addValidationInput(PrintWriter out, String label, String name, String type, String value, String pattern){ + out.println("
"); + out.println("
"); + out.println(label); + out.println(""); + out.println("
"); + out.println("
"); + } + static public void addButton(PrintWriter out, String label, String url){ out.println("
"); out.println("
"); @@ -42,23 +51,10 @@ public class Utillity { out.println("
"); } - static public void addTypeButton(PrintWriter out, String label, String type){ - /* - out.println("
"); - out.println("
"); - out.println(" "); - out.println("
"); - out.println("
"); - */ - + static public void addSubmitButton(PrintWriter out, String label){ out.println("
"); out.println("
"); - out.println(" "); + out.println(" "); out.println("
"); out.println("
"); } diff --git a/src/main/resources/database.sql b/src/main/resources/database.sql index ecde032..9da8296 100644 --- a/src/main/resources/database.sql +++ b/src/main/resources/database.sql @@ -1,6 +1,6 @@ CREATE TABLE IF NOT EXISTS test(id bigint primary key auto_increment, hello varchar(25)); INSERT IGNORE INTO test(hello) values ('Welt'); -CREATE TABLE IF NOT EXISTS book (id bigint primary key auto_increment, isbn bigint unique, title varchar(50), description varchar(500), price int, year year, publisher bigint, category bigint, image varchar(11) unique); +CREATE TABLE IF NOT EXISTS book (id bigint primary key auto_increment, isbn bigint unique, title varchar(50), description varchar(500), price int, year year, publisher bigint, category bigint, image varchar(11)); CREATE TABLE IF NOT EXISTS publisher(id bigint primary key auto_increment, name varchar(50) unique); CREATE TABLE IF NOT EXISTS author(id bigint primary key auto_increment, name varchar(50) unique); CREATE TABLE IF NOT EXISTS author_book(author bigint, book bigint, primary key(author, book), foreign key (author) REFERENCES author(id), foreign key (book) references book(id)); From 027ebd2a461b7091b66eb3a9b752ef3fad64a420 Mon Sep 17 00:00:00 2001 From: Johannes Theiner Date: Sat, 27 Apr 2019 11:37:05 +0200 Subject: [PATCH 14/14] + Index ~ small fixes - db, hello - web.xml Signed-off-by: Johannes Theiner --- src/main/java/de/hsel/itech/db/Database.java | 24 ---------- .../java/de/hsel/itech/servlet/AddBook.java | 3 ++ .../java/de/hsel/itech/servlet/BookList.java | 13 +++-- .../java/de/hsel/itech/servlet/DbTest.java | 44 ----------------- .../de/hsel/itech/servlet/HelloWorld.java | 46 ------------------ src/main/resources/template_footer.html | 4 +- src/main/webapp/WEB-INF/web.xml | 47 ------------------- src/main/webapp/index.html | 12 +++++ 8 files changed, 26 insertions(+), 167 deletions(-) delete mode 100644 src/main/java/de/hsel/itech/servlet/DbTest.java delete mode 100644 src/main/java/de/hsel/itech/servlet/HelloWorld.java delete mode 100644 src/main/webapp/WEB-INF/web.xml create mode 100644 src/main/webapp/index.html diff --git a/src/main/java/de/hsel/itech/db/Database.java b/src/main/java/de/hsel/itech/db/Database.java index 9ea4650..2e4e927 100644 --- a/src/main/java/de/hsel/itech/db/Database.java +++ b/src/main/java/de/hsel/itech/db/Database.java @@ -97,30 +97,6 @@ public class Database { return null; } - /** - * testing method. - * - * @return String - */ - @Deprecated - public String getHello() { - Connection connection = getConnection(); - - String hello = ""; - try { - assert connection != null; - PreparedStatement statement = connection.prepareStatement("SELECT * FROM test WHERE id = 1"); - ResultSet resultSet = statement.executeQuery(); - if (resultSet.next()) - hello = resultSet.getString("hello"); - - connection.close(); - } catch (SQLException e) { - e.printStackTrace(); - } - return hello; - } - /** * gets author by id. * diff --git a/src/main/java/de/hsel/itech/servlet/AddBook.java b/src/main/java/de/hsel/itech/servlet/AddBook.java index a53e4d5..32f8e36 100644 --- a/src/main/java/de/hsel/itech/servlet/AddBook.java +++ b/src/main/java/de/hsel/itech/servlet/AddBook.java @@ -1,5 +1,6 @@ package de.hsel.itech.servlet; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -14,6 +15,8 @@ import java.io.PrintWriter; * @version 0.1 * @since 0.1 */ + +@WebServlet("/addbook") public class AddBook extends HttpServlet { diff --git a/src/main/java/de/hsel/itech/servlet/BookList.java b/src/main/java/de/hsel/itech/servlet/BookList.java index bacbf33..2e94022 100644 --- a/src/main/java/de/hsel/itech/servlet/BookList.java +++ b/src/main/java/de/hsel/itech/servlet/BookList.java @@ -6,6 +6,7 @@ import de.hsel.itech.db.pojo.Book; import de.hsel.itech.db.pojo.Category; import de.hsel.itech.db.pojo.Publisher; +import javax.servlet.annotation.WebServlet; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; @@ -24,6 +25,8 @@ import java.util.List; * @version 0.1 * @since 0.1 */ + +@WebServlet("/booklist") public class BookList extends HttpServlet { protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) @@ -92,8 +95,7 @@ public class BookList extends HttpServlet { for (String name : authorNames) { authors.add(new Author(name)); } - Category category = new Category(); - category.setName(categoryName); + Category category = new Category(categoryName); Book book = new Book(isbn, authors, new Publisher(publisher), @@ -133,10 +135,13 @@ public class BookList extends HttpServlet { out.println("

" + book.getTitle() + "

"); out.println("ISBN: " + book.getIsbn() + "
"); - for (int i = 0; i < book.getAuthors().size(); i++) { - out.println("von " + book.getAuthors().get(0).getName()); + List authors = new ArrayList<>(); + for(Author author : book.getAuthors()) { + authors.add(author.getName()); } + out.println("von: " + String.join(", ", authors)); + out.println("
Veröffentlicht von " + book.getPublisher().getName() + ""); out.println("

" + book.getDescription() + ""); diff --git a/src/main/java/de/hsel/itech/servlet/DbTest.java b/src/main/java/de/hsel/itech/servlet/DbTest.java deleted file mode 100644 index db86770..0000000 --- a/src/main/java/de/hsel/itech/servlet/DbTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package de.hsel.itech.servlet; - -import de.hsel.itech.db.Database; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.IOException; -import java.io.PrintWriter; - -/** - * Database test. - * - * @author Johannes Theiner - * @version 0.1 - * @since 0.1 - **/ -public class DbTest 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(""); - out.println(""); - out.println("Hallo Welt!"); - out.println(""); - out.println(""); - out.println("

" + Database.getInstance().getHello() + "

"); - out.println(""); - out.println(""); - } -} \ No newline at end of file diff --git a/src/main/java/de/hsel/itech/servlet/HelloWorld.java b/src/main/java/de/hsel/itech/servlet/HelloWorld.java deleted file mode 100644 index 9aa5a44..0000000 --- a/src/main/java/de/hsel/itech/servlet/HelloWorld.java +++ /dev/null @@ -1,46 +0,0 @@ -package de.hsel.itech.servlet; - -import javax.servlet.http.HttpServlet; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; -import java.io.File; -import java.io.IOException; -import java.io.PrintWriter; - -/** - * Hello World. - * - * @author Johannes Theiner - * @version 0.1 - * @since 0.1 - **/ -public class HelloWorld extends HttpServlet { - - private static final long serialVersionUID = 15679036735L; - - /** - * 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(""); - out.println(""); - out.println(""); - out.println("Hallo Welt!"); - out.println(""); - out.println(""); - out.println("

Hallo Ostfriesland!


"); - out.println("

" + System.getProperty("catalina.base") + "


"); - out.println("

" + new File("").getAbsolutePath() + "

"); - out.println(""); - out.println(""); - } -} diff --git a/src/main/resources/template_footer.html b/src/main/resources/template_footer.html index c0a0803..79088c3 100644 --- a/src/main/resources/template_footer.html +++ b/src/main/resources/template_footer.html @@ -28,9 +28,9 @@
-

Rechtliches

+

Rechtliches

diff --git a/src/main/webapp/WEB-INF/web.xml b/src/main/webapp/WEB-INF/web.xml deleted file mode 100644 index 760482f..0000000 --- a/src/main/webapp/WEB-INF/web.xml +++ /dev/null @@ -1,47 +0,0 @@ - - - - - - - helloWorld - de.hsel.itech.servlet.HelloWorld - - - - database - de.hsel.itech.servlet.DbTest - - - - booklist - de.hsel.itech.servlet.BookList - - - - addbook - de.hsel.itech.servlet.AddBook - - - - helloWorld - /index - - - - database - /db - - - - booklist - /booklist - - - - addbook - /addbook - - \ No newline at end of file diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html new file mode 100644 index 0000000..ef273a3 --- /dev/null +++ b/src/main/webapp/index.html @@ -0,0 +1,12 @@ + + + + Internet Technologien + + + + + \ No newline at end of file