-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
290 additions
and
87 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 0 additions & 30 deletions
30
bsm-desk-app/src/main/java/main/backend/list/AuthorList.java
This file was deleted.
Oops, something went wrong.
35 changes: 0 additions & 35 deletions
35
bsm-desk-app/src/main/java/main/backend/list/BookList.java
This file was deleted.
Oops, something went wrong.
49 changes: 49 additions & 0 deletions
49
bsm-desk-app/src/main/java/main/backend/lists/AuthorList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
package main.backend.lists; | ||
|
||
import java.sql.ResultSet; | ||
import java.util.ArrayList; | ||
|
||
import main.backend.objects.Author; | ||
import main.backend.utils.DBconnect; | ||
|
||
public class AuthorList { | ||
private ArrayList<Author> authors; | ||
|
||
public AuthorList() { authors = new ArrayList<>(); } | ||
public AuthorList(AuthorList other) { authors = new ArrayList<>(other.authors); } | ||
|
||
public void add(Author author) { authors.add(author); } | ||
public void clear() { authors.clear(); } | ||
public Author getAuthorByID(int id) { | ||
for (Author author : authors) | ||
if (author.getId() == id) return author; | ||
return null; | ||
} | ||
|
||
public boolean loadAuthors_fromDatabase(String name) { | ||
String condition = name == null ? null : ("WHERE Name = " + name); | ||
try ( | ||
DBconnect db = new DBconnect(); | ||
ResultSet rs = db.view("AUTHOR", condition); | ||
) { | ||
authors.clear(); | ||
while (rs.next()) | ||
authors.add(new Author(rs.getInt(0), rs.getString(1), rs.getString(2))); | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String str = "There are " + authors.size() + " authors in the list.\n\n"; | ||
|
||
for (Author author : authors) | ||
str += author.toString() + "\n"; | ||
|
||
return str; | ||
} | ||
} |
72 changes: 72 additions & 0 deletions
72
bsm-desk-app/src/main/java/main/backend/lists/BookList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
package main.backend.lists; | ||
|
||
import java.sql.ResultSet; | ||
import java.util.ArrayList; | ||
|
||
import main.backend.objects.Book; | ||
import main.backend.utils.DBconnect; | ||
|
||
public class BookList { | ||
private ArrayList<Book> books; | ||
|
||
public BookList() { books = new ArrayList<>(); } | ||
public BookList(BookList other) { books = new ArrayList<>(other.books); } | ||
|
||
public void add(Book book) { books.add(book); } | ||
public void clear() { books.clear(); } | ||
public Book getBookById(int id) { | ||
for (Book book : books) | ||
if (book.getId() == id) return book; | ||
return null; | ||
} | ||
|
||
public boolean loadBooks_fromDatabase(String name, PublisherList pl, AuthorList au, CategoryList ca) { | ||
String condition = name == null ? null : ("WHERE Name = " + name); | ||
try ( | ||
DBconnect db = new DBconnect(); | ||
ResultSet rs = db.view("AUTHOR", condition); | ||
) { | ||
books.clear(); | ||
while (rs.next()) { | ||
int id = rs.getInt(0); | ||
String title = rs.getString(1); | ||
String isbn = rs.getString(2); | ||
String language = rs.getString(3); | ||
int numberOfPages = rs.getInt(4); | ||
int publisherID = rs.getInt(5); | ||
int authorID = rs.getInt(6); | ||
boolean enabled = rs.getBoolean(8); | ||
|
||
CategoryList categories = new CategoryList(); | ||
String condition1 = "WHERE BookID = " + String.valueOf(id); | ||
try (ResultSet rs1 = db.view("CATEGORY_BOOK", condition1);) { | ||
while (rs1.next()) | ||
categories.add(ca.getCategoryByID(rs1.getInt(0))); | ||
} catch (Exception e) { | ||
System.err.println("Categories"); | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
|
||
Book book = new Book(id, title, isbn, language, numberOfPages, pl.getPublisherByID(publisherID), au.getAuthorByID(authorID), categories, enabled); | ||
books.add(book); | ||
} | ||
} catch (Exception e) { | ||
e.printStackTrace(); | ||
return false; | ||
} | ||
|
||
return true; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
String str = "There are " + books.size() + " books in the list.\n\n"; | ||
|
||
for (Book book : books) | ||
str += book.toString() + "\n"; | ||
|
||
return str; | ||
} | ||
|
||
} |
25 changes: 22 additions & 3 deletions
25
.../java/main/backend/list/CategoryList.java → ...java/main/backend/lists/CategoryList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
25 changes: 22 additions & 3 deletions
25
...java/main/backend/list/PublisherList.java → ...ava/main/backend/lists/PublisherList.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.