Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

zmiana projekty, wycyszczenie ze zbednych klas, implementacja managerów

  • Loading branch information...
commit 1b464ea4358cf8052989a9e700d5fc2d9d0baece 1 parent a778f7a
Kamui authored
Showing with 316 additions and 1,746 deletions.
  1. +0 −60 src/main/java/Main.java
  2. +1 −0  src/main/java/database/IManager.java
  3. +3 −0  src/main/java/database/ManagerBase.java
  4. +0 −28 src/main/java/database/builder/AuthorBuilder.java
  5. +21 −29 src/main/java/database/builder/BookBuilder.java
  6. +2 −1  src/main/java/database/builder/IEntityBuilder.java
  7. +0 −15 src/main/java/database/builder/MagazineBuilder.java
  8. +8 −0 src/main/java/database/managers/IAggregateManager.java
  9. +0 −13 src/main/java/database/managers/IAuthorManager.java
  10. +14 −12 src/main/java/database/managers/IBookManager.java
  11. +0 −9 src/main/java/database/managers/IEnumerationManager.java
  12. +0 −74 src/main/java/database/managers/impl/HibBookManager.java
  13. +0 −202 src/main/java/database/managers/impl/HsqlAuthorManager.java
  14. +0 −191 src/main/java/database/managers/impl/HsqlBookManager.java
  15. +0 −59 src/main/java/database/managers/impl/HsqlEnumerationManager.java
  16. +0 −118 src/main/java/database/managers/impl/HsqlMagazineManager.java
  17. +0 −70 src/main/java/database/managers/impl/MockBookManager.java
  18. +70 −0 src/main/java/database/managers/impl/MysqlAggregateManager.java
  19. +0 −180 src/main/java/database/managers/impl/MysqlAuthorManager.java
  20. +126 −256 src/main/java/database/managers/impl/MysqlBookManager.java
  21. +17 −1 src/main/java/database/managers/impl/MysqlManagerBase.java
  22. +0 −37 src/main/java/dto/AuthorSummaryDto.java
  23. +0 −20 src/main/java/dto/BookDto.java
  24. +0 −36 src/main/java/dto/BookSummaryDto.java
  25. +0 −6 src/main/java/enums/EnumNames.java
  26. +0 −20 src/main/java/enums/EnumerationProvider.java
  27. +0 −5 src/main/java/enums/MagazineType.java
  28. +39 −0 src/main/java/model/Aggregate.java
  29. +0 −56 src/main/java/model/Author.java
  30. +14 −42 src/main/java/model/Book.java
  31. +0 −10 src/main/java/model/EntityBase.java
  32. +0 −57 src/main/java/model/Enumeration.java
  33. +0 −35 src/main/java/model/Magazine.java
  34. +1 −1  src/main/resources/hibernate.cfg.xml
  35. +0 −103 src/test/java/database/managers/book/tests/BookManagerTests.java
60 src/main/java/Main.java
View
@@ -1,60 +0,0 @@
-
-
-import org.hibernate.Session;
-import org.hibernate.SessionFactory;
-import org.hibernate.cfg.Configuration;
-
-import model.Author;
-import model.Book;
-import database.HibUnitOfWork;
-import database.MysqlUnitOfWork;
-import database.UnitOfWork;
-import database.builder.AuthorBuilder;
-import database.builder.BookBuilder;
-import database.builder.IEntityBuilder;
-import database.managers.IBookManager;
-import database.managers.impl.HibBookManager;
-import database.managers.impl.HsqlAuthorManager;
-import database.managers.impl.HsqlBookManager;
-import database.managers.impl.MysqlBookManager;
-import database.unitofwork.IUnitOfWork;
-import dto.BookDto;
-import enums.EnumerationProvider;
-import enums.MagazineType;
-
-
-public class Main {
-
- public static void main(String[] args) {
-
- Book b = new Book();
- b.setPublisher("Helion");
- b.setTitle("Java");
- b.setYear(2013);
- Book b2 =new Book();
-
- b2.setPublisher("Helion");
- b2.setTitle("Java2");
- b2.setYear(2013);
- Author a = new Author();
- a.setName("Adam");
- a.setSurname("Urbanowicz");
-
- a.getBooks().add(b);
- b.getAuthors().add(a);
- a.getBooks().add(b2);
- b2.getAuthors().add(a);
- IUnitOfWork uow = new MysqlUnitOfWork();
- IBookManager mgr = new MysqlBookManager((MysqlUnitOfWork)uow,new BookBuilder());
-
- mgr.save(b);
- mgr.save(b2);
- uow.commit();
-
- Book b3=mgr.get(1);
-
- System.out.println(b3.getTitle());
- uow.close();
- }
-
-}
1  src/main/java/database/IManager.java
View
@@ -11,5 +11,6 @@
public void update(T obj);
public T get(int id);
public List<T> getAll(PageInfo request);
+ public int count();
public void saveChanges();
}
3  src/main/java/database/ManagerBase.java
View
@@ -48,6 +48,9 @@ public final void saveChanges()
public abstract List<E> getAll(PageInfo request);
@Override
+ public abstract int count();
+
+ @Override
public abstract void persistAdd(EntityBase ent);
@Override
28 src/main/java/database/builder/AuthorBuilder.java
View
@@ -1,28 +0,0 @@
-package database.builder;
-
-import java.sql.ResultSet;
-
-import javax.enterprise.context.RequestScoped;
-
-import model.Author;
-//@RequestScoped
-public class AuthorBuilder implements IEntityBuilder<Author>{
-
- @Override
- public Author build(ResultSet rs) {
- Author a = null;
- try
- {
- a = new Author();
- a.setId(rs.getInt("id"));
- a.setName(rs.getString("name"));
- a.setSurname(rs.getString("surname"));
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- }
- return a;
- }
-
-}
50 src/main/java/database/builder/BookBuilder.java
View
@@ -1,29 +1,21 @@
-package database.builder;
-
-import java.sql.ResultSet;
-
-import javax.enterprise.context.RequestScoped;
-
-import model.Book;
-//@RequestScoped
-public class BookBuilder implements IEntityBuilder<Book>{
-
- @Override
- public Book build(ResultSet rs) {
- Book result = null;
- try{
-
- result = new Book();
- result.setId(rs.getInt("id"));
- result.setPublisher(rs.getString("publisher"));
- result.setTitle(rs.getString("title"));
- result.setYear(rs.getInt("year"));
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- }
- return result;
- }
-
-}
+package database.builder;
+
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.Date;
+
+import model.Book;
+
+public class BookBuilder implements IEntityBuilder<Book> {
+
+ @Override
+ public Book build(ResultSet rs) throws SQLException {
+ Book result = new Book();
+ result.setTitle(rs.getString("Title"));
+ result.setPrice(rs.getDouble("Price"));
+ result.setId(rs.getInt("Id"));
+ result.setDateOfAggregation(new Date(rs.getDate("DateOfAggregation").getTime()));
+ return result;
+ }
+
+}
3  src/main/java/database/builder/IEntityBuilder.java
View
@@ -1,11 +1,12 @@
package database.builder;
import java.sql.ResultSet;
+import java.sql.SQLException;
import model.EntityBase;
public interface IEntityBuilder<E extends EntityBase> {
- public E build(ResultSet rs);
+ public E build(ResultSet rs) throws SQLException;
}
15 src/main/java/database/builder/MagazineBuilder.java
View
@@ -1,15 +0,0 @@
-package database.builder;
-
-import java.sql.ResultSet;
-
-import model.Magazine;
-
-public class MagazineBuilder implements IEntityBuilder<Magazine> {
-
- @Override
- public Magazine build(ResultSet rs) {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
8 src/main/java/database/managers/IAggregateManager.java
View
@@ -0,0 +1,8 @@
+package database.managers;
+
+import model.Aggregate;
+import database.IManager;
+
+public interface IAggregateManager extends IManager<Aggregate>{
+
+}
13 src/main/java/database/managers/IAuthorManager.java
View
@@ -1,13 +0,0 @@
-package database.managers;
-
-import java.util.List;
-
-import database.IManager;
-import model.Author;
-import model.Book;
-
-public interface IAuthorManager
- extends IManager<Author>{
-
- public void setAuthorsOfBook(Book b);
-}
26 src/main/java/database/managers/IBookManager.java
View
@@ -1,12 +1,14 @@
-package database.managers;
-
-import model.Author;
-import model.Book;
-
-import java.util.List;
-
-import database.IManager;
-public interface IBookManager extends IManager<Book>{
-
- public void setAuthors(Book b);
-}
+package database.managers;
+
+import java.util.List;
+
+import model.Aggregate;
+import model.Book;
+import database.IManager;
+import database.PageInfo;
+
+public interface IBookManager extends IManager<Book>{
+
+ public List<Book> getBooksByAggregate(Aggregate aggregate, PageInfo pageInfo);
+ public int countBooksByAggregate(Aggregate aggregate);
+}
9 src/main/java/database/managers/IEnumerationManager.java
View
@@ -1,9 +0,0 @@
-package database.managers;
-
-import model.Enumeration;
-import database.IManager;
-
-public interface IEnumerationManager extends IManager<Enumeration>{
-
- public Object getEnumKey(int key,String stringKey);
-}
74 src/main/java/database/managers/impl/HibBookManager.java
View
@@ -1,74 +0,0 @@
-package database.managers.impl;
-
-import java.util.List;
-
-import org.hibernate.Query;
-import org.hibernate.Session;
-
-import model.Author;
-import model.Book;
-import model.EntityBase;
-import database.HibUnitOfWork;
-import database.ManagerBase;
-import database.PageInfo;
-import database.managers.IBookManager;
-import database.unitofwork.IUnitOfWork;
-
-public class HibBookManager extends ManagerBase<Book> implements IBookManager {
-
- Session session;
-
- public HibBookManager(HibUnitOfWork uow) {
- super(uow);
- this.session=uow.getSession();
- }
-
- @Override
- public void setAuthors(Book b) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public Book get(int id) {
- boolean openedNewSesson=false;
- if(!session.isOpen())
- {
- session = ((HibUnitOfWork)uow).getSession();
- openedNewSesson=true;
- }try{
- return (Book)session.get(Book.class, id);
- }finally
- {
- if(openedNewSesson)
- session.close();
- }
- }
-
- @Override
- public List<Book> getAll(PageInfo request) {
- Query query = session.createQuery("from Books");
- query.setFirstResult(request.getPageIndex() * request.getPageSize());
- query.setMaxResults(request.getPageSize());
- return (List<Book>)query.list();
- }
-
- @Override
- public void persistAdd(EntityBase ent) {
- Book b = (Book)ent;
- session.save(b);
- }
-
- @Override
- public void persistDeleted(EntityBase ent) {
- session.delete((Book)ent);
-
- }
-
- @Override
- public void persistUpdated(EntityBase ent) {
- session.update((Book)ent);
-
- }
-
-}
202 src/main/java/database/managers/impl/HsqlAuthorManager.java
View
@@ -1,202 +0,0 @@
-package database.managers.impl;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-
-import model.Author;
-import model.Book;
-import model.EntityBase;
-import database.ManagerBase;
-import database.PageInfo;
-import database.builder.IEntityBuilder;
-import database.managers.IAuthorManager;
-import database.unitofwork.IUnitOfWork;
-
-public class HsqlAuthorManager
- extends ManagerBase<Author>
- implements IAuthorManager
-{
-
- private IEntityBuilder<Author> builder;
- private Connection connection;
- private String url = "jdbc:hsqldb:hsql://localhost/workdb";
-
- private PreparedStatement getAuthorForBook;
- private PreparedStatement getAuthorById;
- private PreparedStatement getAllAuthors;
- private PreparedStatement update;
- private PreparedStatement delete;
- private PreparedStatement insert;
-
- private PreparedStatement getAuthors;
-
- private Statement stmt;
-
-
- //@Inject
- public HsqlAuthorManager(IUnitOfWork uow, IEntityBuilder<Author> builder) {
- super(uow);
-
- this.builder=builder;
-
- try {
- connection = DriverManager.getConnection(url);
- stmt =connection.createStatement();
-
- ResultSet rs = connection.getMetaData()
- .getTables(null,null,null,null);
-
- boolean exist = false;
- while(rs.next())
- {
- if("Author".equalsIgnoreCase(rs.getString("TABLE_NAME")))
- {
- exist=true;
- break;
- }
- }
-
- if(!exist)
- {
- stmt.executeUpdate(""
- + "CREATE TABLE Author("
- + "id bigint GENERATED BY DEFAULT AS IDENTITY,"
- + "name VARCHAR(50),"
- + "surname VARCHAR(50),"
- + "bookId bigint"
- + ")"
- + "");
- }
-
- getAuthorById = connection.prepareStatement(""
- + "SELECT * FROM Author WHERE id=?");
- getAllAuthors = connection.prepareStatement(
- "SELECT * FROM Author LIMIT ? ?");
- insert = connection.prepareStatement(""
- + "INSERT INTO Author(name,surname)"
- + "VALUES (?,?)");
- delete = connection.prepareStatement(""
- + "DELETE FROM Author WHERE id=?");
- update = connection.prepareStatement("UPDATE Author SET "
- + "name=? "
- + "WHERE id=?");
- getAuthorForBook = connection.prepareStatement(
- "SELECT * FROM Author WHERE bookId=?");
- //getAuthors=connection.prepareStatement(
- // "SELECT * FROM Author WHERE bookId =?");
-
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void setAuthorsOfBook(Book b) {
-
- try
- {
- getAuthorForBook.setInt(1, b.getId());
- ResultSet rs = getAuthorForBook.executeQuery();
- while(rs.next())
- {
- Author a = builder.build(rs);
- b.getAuthors().add(a);
-
- }
- }
- catch(Exception ex){
- ex.printStackTrace();
- }
-
- }
-
- @Override
- public Author get(int id) {
- Author a = null;
- try
- {
- getAuthorById.setInt(1, id);
- ResultSet rs = getAuthorById.executeQuery();
- while(rs.next())
- {
- a = builder.build(rs);
- }
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- }
-
- return a;
- }
-
- @Override
- public List<Author> getAll(PageInfo request) {
-
- List<Author> authors = new ArrayList<Author>();
-
- try
- {
- getAllAuthors.setInt(1, request.getPageIndex()*request.getPageSize());
- getAllAuthors.setInt(2, request.getPageSize());
- ResultSet rs = getAllAuthors.executeQuery();
- while(rs.next())
- {
-
- Author a = builder.build(rs);
- }
-
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
-
- return null;
- }
-
- @Override
- public void persistAdd(EntityBase ent) {
-
- Author a = (Author)ent;
- try{
- insert.setString(1, a.getName());
- insert.setString(2, a.getSurname());
- insert.executeUpdate();
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- }
-
- }
-
- @Override
- public void persistDeleted(EntityBase ent) {
-
- try{
- delete.setInt(1, ent.getId());
- delete.executeUpdate();
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
- @Override
- public void persistUpdated(EntityBase ent) {
- // TODO Auto-generated method stub
-
- }
-
-}
191 src/main/java/database/managers/impl/HsqlBookManager.java
View
@@ -1,191 +0,0 @@
-package database.managers.impl;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-
-import model.Author;
-import model.Book;
-import model.EntityBase;
-import database.ManagerBase;
-import database.PageInfo;
-import database.builder.AuthorBuilder;
-import database.builder.IEntityBuilder;
-import database.managers.IAuthorManager;
-import database.managers.IBookManager;
-import database.unitofwork.IUnitOfWork;
-
-public class HsqlBookManager
- extends ManagerBase<Book>
- implements IBookManager {
-
- private IAuthorManager authorMgr;
- private Connection connection;
- private String url = "jdbc:hsqldb:hsql://localhost/workdb";
-
- private PreparedStatement getBooksById;
- private PreparedStatement getAllBooks;
- private PreparedStatement update;
- private PreparedStatement delete;
- private PreparedStatement insert;
- private IEntityBuilder<Book> builder;
- private PreparedStatement getAuthors;
-
- private Statement stmt;
-
- public HsqlBookManager(IUnitOfWork uow,
- IEntityBuilder<Book> builder,
- IAuthorManager authorMgr) {
- super(uow);
-
- this.builder=builder;
- this.authorMgr=authorMgr;
-
- try {
- connection = DriverManager.getConnection(url);
- stmt =connection.createStatement();
-
- ResultSet rs = connection.getMetaData()
- .getTables(null,null,null,null);
-
- boolean exist = false;
- while(rs.next())
- {
- if("Book".equalsIgnoreCase(rs.getString("TABLE_NAME")))
- {
- exist=true;
- break;
- }
- }
-
- if(!exist)
- {
- stmt.executeUpdate(""
- + "CREATE TABLE Book("
- + "id bigint GENERATED BY DEFAULT AS IDENTITY,"
- + "publisher VARCHAR(50),"
- + "title VARCHAR(50),"
- + "year integer"
- + ")"
- + "");
- }
-
- getBooksById = connection.prepareStatement(""
- + "SELECT * FROM Book WHERE id=?");
- getAllBooks = connection.prepareStatement("SELECT * FROM Book LIMIT ? ?");
- insert = connection.prepareStatement(""
- + "INSERT INTO Book(publisher,title,year)"
- + "VALUES (?,?,?)");
- delete = connection.prepareStatement(""
- + "DELETE FROM Book WHERE id=?");
- update = connection.prepareStatement("UPDATE Book SET "
- + "(publisher,title,year)=(?,?,?) "
- + "WHERE id=?");
-
- //getAuthors=connection.prepareStatement(
- // "SELECT * FROM Author WHERE bookId =?");
-
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
- }
-
- @Override
- public void setAuthors(Book b) {
- authorMgr.setAuthorsOfBook(b);
- }
-
- @Override
- public Book get(int id) {
- Book result = null;
- try{
-
- getBooksById.setInt(1, id);
- ResultSet rs = getBooksById.executeQuery();
- while(rs.next())
- {
- result = builder.build(rs);
- }
-
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
- return result;
- }
-
- @Override
- public List<Book> getAll(PageInfo request) {
- List<Book> books = new ArrayList<Book>();
-
- try{
- int n = request.getPageIndex()*request.getPageSize();
- getAllBooks.setInt(1, n);
- getAllBooks.setInt(2, request.getPageSize());
- ResultSet rs = getAllBooks.executeQuery();
- while(rs.next())
- {
- Book result = builder.build(rs);
-
- books.add(result);
- }
-
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
- return books;
- }
-
- @Override
- public void persistAdd(EntityBase ent) {
-
- Book b = (Book)ent;
- try {
-
- insert.setString(1, b.getPublisher());
- insert.setString(2, b.getTitle());
- insert.setInt(3, b.getYear());
- insert.executeUpdate();
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void persistDeleted(EntityBase ent) {
-
- try {
- delete.setInt(1, ent.getId());
- delete.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Override
- public void persistUpdated(EntityBase ent) {
- Book b = (Book)ent;
- try{
- update.setString(1, b.getPublisher());
- update.setString(2, b.getTitle());
- update.setInt(3, b.getYear());
- update.setInt(4, ent.getId());
- update.executeUpdate();
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
-}
59 src/main/java/database/managers/impl/HsqlEnumerationManager.java
View
@@ -1,59 +0,0 @@
-package database.managers.impl;
-
-import java.util.List;
-
-import model.EntityBase;
-import model.Enumeration;
-import database.ManagerBase;
-import database.PageInfo;
-import database.managers.IEnumerationManager;
-import database.unitofwork.IUnitOfWork;
-
-public class HsqlEnumerationManager
- extends ManagerBase<Enumeration>
- implements IEnumerationManager
-{
-
- public HsqlEnumerationManager(IUnitOfWork uow) {
- super(uow);
- // TODO Auto-generated constructor stub
- }
-
-
- @Override
- public Enumeration get(int id) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List<Enumeration> getAll(PageInfo request) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void persistAdd(EntityBase ent) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void persistDeleted(EntityBase ent) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void persistUpdated(EntityBase ent) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public Object getEnumKey(int key, String stringKey) {
- // TODO Auto-generated method stub
- return null;
- }
-
-}
118 src/main/java/database/managers/impl/HsqlMagazineManager.java
View
@@ -1,118 +0,0 @@
-package database.managers.impl;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.Statement;
-import java.util.List;
-
-import model.Book;
-import model.EntityBase;
-import model.Magazine;
-import database.ManagerBase;
-import database.PageInfo;
-import database.builder.IEntityBuilder;
-import database.unitofwork.IUnitOfWork;
-
-public class HsqlMagazineManager extends ManagerBase<Magazine> {
-
- private Connection connection;
- private String url = "jdbc:hsqldb:hsql://localhost/workdb";
-
- private PreparedStatement getById;
- private PreparedStatement getAll;
- private PreparedStatement update;
- private PreparedStatement delete;
- private PreparedStatement insert;
-
- private Statement stmt;
-
-
- public HsqlMagazineManager(IUnitOfWork uow) {
- super(uow);
- try {
- connection = DriverManager.getConnection(url);
- stmt =connection.createStatement();
-
- ResultSet rs = connection.getMetaData()
- .getTables(null,null,null,null);
-
- boolean exist = false;
- while(rs.next())
- {
- if("Book".equalsIgnoreCase(rs.getString("TABLE_NAME")))
- {
- exist=true;
- break;
- }
- }
-
- if(!exist)
- {
- stmt.executeUpdate(""
- + "CREATE TABLE Magazine("
- + "id bigint GENERATED BY DEFAULT AS IDENTITY,"
- + "number integer,"
- + "title VARCHAR(50),"
- + "year integer,"
- + "typeId integer"
- + ")"
- + "");
- }
-
- getById = connection.prepareStatement(""
- + "SELECT * FROM Magazine WHERE id=?");
-
- getAll = connection.prepareStatement(
- "SELECT * FROM Magazine LIMIT ? ?");
-
- insert = connection.prepareStatement(""
- + "INSERT INTO Magazine(number,title,year,typeId)"
- + "VALUES (?,?,?,?)");
-
- delete = connection.prepareStatement(
- "DELETE FROM Magazine WHERE id=?");
-
- update = connection.prepareStatement("UPDATE Book SET "
- + "(number,title,year,typeId)=(?,?,?,?) "
- + "WHERE id=?");
-
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
-
- }
-
- @Override
- public Magazine get(int id) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public List<Magazine> getAll(PageInfo request) {
- // TODO Auto-generated method stub
- return null;
- }
-
- @Override
- public void persistAdd(EntityBase ent) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void persistDeleted(EntityBase ent) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public void persistUpdated(EntityBase ent) {
- // TODO Auto-generated method stub
-
- }
-
-}
70 src/main/java/database/managers/impl/MockBookManager.java
View
@@ -1,70 +0,0 @@
-package database.managers.impl;
-
-import java.util.List;
-
-import model.Author;
-import model.Book;
-import model.EntityBase;
-import database.ManagerBase;
-import database.MockDb;
-import database.PageInfo;
-import database.managers.IBookManager;
-import database.unitofwork.IUnitOfWork;
-
-public class MockBookManager
- extends ManagerBase<Book>
- implements IBookManager {
-
- private MockDb db;
-
- public MockBookManager(IUnitOfWork uow, MockDb db)
- {
- this(uow);
- this.db=db;
- }
-
- private MockBookManager(IUnitOfWork uow) {
- super(uow);
- }
-
- @Override
- public void setAuthors(Book b) {
-
- }
-
- @Override
- public Book get(int id) {
- Book book = new Book();
- Book b = (Book)db.get(id-1);
- book.setId(b.getId());
- book.setPublisher(b.getPublisher());
- book.setTitle(b.getTitle());
- book.setYear(b.getYear());
- return book;
- }
-
- @Override
- public List<Book> getAll(PageInfo request) {
- // TODO Auto-generated method stub
- return db.getItemsByType(Book.class);
- }
-
- @Override
- public void persistAdd(EntityBase ent) {
- db.save(ent);
-
- }
-
- @Override
- public void persistDeleted(EntityBase ent) {
- db.delete(ent);
-
- }
-
- @Override
- public void persistUpdated(EntityBase ent) {
- // tu nie trzeba nic implementować póki co
-
- }
-
-}
70 src/main/java/database/managers/impl/MysqlAggregateManager.java
View
@@ -0,0 +1,70 @@
+package database.managers.impl;
+
+import java.sql.SQLException;
+
+import database.MysqlUnitOfWork;
+import database.builder.IEntityBuilder;
+import database.managers.IAggregateManager;
+import model.Aggregate;
+import model.EntityBase;
+
+public class MysqlAggregateManager extends MysqlManagerBase<Aggregate> implements IAggregateManager {
+
+ public MysqlAggregateManager(MysqlUnitOfWork uow,
+ IEntityBuilder<Aggregate> builder) {
+ super(uow, builder);
+ }
+
+ @Override
+ protected void setUpdateQuery(EntityBase ent) throws SQLException {
+ Aggregate a =(Aggregate) ent;
+ update.setString(1, a.getName());
+
+ if(a.getParent()!=null)
+ update.setInt(2, a.getParent().getId());
+ else
+ update.setNull(2, java.sql.Types.INTEGER);
+
+ update.setInt(3, a.getId());
+ }
+
+ @Override
+ protected void setInsertQuery(EntityBase ent) throws SQLException {
+ Aggregate a = (Aggregate)ent;
+ insert.setString(1, a.getName());
+ if(a.getParent()!=null)
+ insert.setInt(2, a.getParent().getId());
+ else
+ insert.setNull(2, java.sql.Types.INTEGER);
+ }
+
+ @Override
+ protected String getUpdateQuery() {
+ return "UPDATE aggregates SET (Name,Aggregate_Id)=(?,?) where Id=?";
+ }
+
+ @Override
+ protected String getInsertQuery() {
+
+ return "INSERT INTO aggregates(Name,Aggregate_Id) VALUES(?,?)";
+ }
+
+ @Override
+ protected String getCreateQuery() {
+ return "CREATE TABLE `aggregates` ("
+ +"`Id` int(11) NOT NULL AUTO_INCREMENT,"
+ +"`Name` longtext,"
+ +"`Aggregate_Id` int(11) DEFAULT NULL,"
+ +"PRIMARY KEY (`Id`),"
+ +"UNIQUE KEY `Id` (`Id`),"
+ +"KEY `Aggregate_Id` (`Aggregate_Id`),"
+ +"CONSTRAINT `Aggregate_Aggregates` FOREIGN KEY (`Aggregate_Id`) REFERENCES `aggregates` (`Id`) ON DELETE NO ACTION ON UPDATE NO ACTION"
+ +")";
+ }
+
+ @Override
+ protected String getTableName() {
+ return "aggregates";
+ }
+
+}
180 src/main/java/database/managers/impl/MysqlAuthorManager.java
View
@@ -1,180 +0,0 @@
-package database.managers.impl;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-
-import model.Author;
-import model.Book;
-import model.EntityBase;
-import database.ManagerBase;
-import database.PageInfo;
-import database.builder.IEntityBuilder;
-import database.managers.IAuthorManager;
-import database.unitofwork.IUnitOfWork;
-
-//@RequestScoped
-public class MysqlAuthorManager extends ManagerBase<Author> implements IAuthorManager{
-
- private IAuthorManager authorMgr;
- private Connection connection;
- private String url = "jdbc:mysql://localhost/library?user=newuser&password=1qaz@WSX";
-
- private PreparedStatement getAuthorById;
- private PreparedStatement getAllAuthors;
- private PreparedStatement update;
- private PreparedStatement delete;
- private PreparedStatement insert;
- private IEntityBuilder<Author> builder;
-
- private Statement stmt;
- //@Inject
- public MysqlAuthorManager(IUnitOfWork uow, IEntityBuilder<Author> builder) {
- super(uow);
-
- this.builder=builder;
-
- try {
-
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- connection = DriverManager.getConnection(url);
- stmt =connection.createStatement();
-
- ResultSet rs = connection.getMetaData()
- .getTables(null,null,null,null);
-
- boolean exist = false;
- while(rs.next())
- {
- if("Book".equalsIgnoreCase(rs.getString("TABLE_NAME")))
- {
- exist=true;
- break;
- }
- }
-
- if(!exist)
- {
-
- }
-
- getAuthorById = connection.prepareStatement(""
- + "SELECT * FROM author WHERE id=?");
- getAllAuthors = connection.prepareStatement("SELECT * FROM author LIMIT ? ?");
- insert = connection.prepareStatement(""
- + "INSERT INTO author(name,surname)"
- + "VALUES (?,?)");
- delete = connection.prepareStatement(""
- + "DELETE FROM author WHERE id=?");
- update = connection.prepareStatement("UPDATE author SET "
- + "(name,surname)=(?,?) "
- + "WHERE id=?");
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
- @Override
- public void setAuthorsOfBook(Book b) {
- // TODO Auto-generated method stub
-
- }
-
- @Override
- public Author get(int id) {
- Author result = null;
- try{
-
- getAuthorById.setInt(1, id);
- ResultSet rs = getAuthorById.executeQuery();
- while(rs.next())
- {
- result = builder.build(rs);
- }
-
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
- return result;
- }
-
- @Override
- public List<Author> getAll(PageInfo request) {
- List<Author> books = new ArrayList<Author>();
-
- try{
- int n = request.getPageIndex()*request.getPageSize();
- getAllAuthors.setInt(1, n);
- getAllAuthors.setInt(2, request.getPageSize());
- ResultSet rs = getAllAuthors.executeQuery();
- while(rs.next())
- {
- Author result = builder.build(rs);
-
- books.add(result);
- }
-
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
- return books;
- }
-
- @Override
- public void persistAdd(EntityBase ent) {
-
- Author b = (Author)ent;
- try {
-
- insert.setString(1, b.getName());
- insert.setString(2, b.getSurname());
- insert.executeUpdate();
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
-
- }
-
- @Override
- public void persistDeleted(EntityBase ent) {
-
- try {
- delete.setInt(1, ent.getId());
- delete.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
-
- }
-
- @Override
- public void persistUpdated(EntityBase ent) {
- Author b = (Author)ent;
- try{
- update.setString(1, b.getName());
- update.setString(2, b.getSurname());
- update.setInt(4, ent.getId());
- update.executeUpdate();
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- }
-
- }
-
-}
382 src/main/java/database/managers/impl/MysqlBookManager.java
View
@@ -1,256 +1,126 @@
-package database.managers.impl;
-
-import java.sql.Connection;
-import java.sql.DriverManager;
-import java.sql.PreparedStatement;
-import java.sql.ResultSet;
-import java.sql.SQLException;
-import java.sql.Statement;
-import java.util.ArrayList;
-import java.util.List;
-
-import javax.enterprise.context.RequestScoped;
-import javax.inject.Inject;
-
-import model.Book;
-import model.EntityBase;
-import database.ManagerBase;
-import database.MysqlUnitOfWork;
-import database.PageInfo;
-import database.builder.IEntityBuilder;
-import database.managers.IAuthorManager;
-import database.managers.IBookManager;
-import database.unitofwork.IUnitOfWork;
-
-//@RequestScoped
-public class MysqlBookManager extends MysqlManagerBase<Book> implements IBookManager{
-
- public MysqlBookManager(MysqlUnitOfWork uow, IEntityBuilder<Book> builder) {
- super(uow, builder);
- }
-
- @Override
- public void setAuthors(Book b) {
- }
-
- @Override
- protected void setUpdateQuery(EntityBase ent) throws SQLException {
- Book b = (Book)ent;
- update.setString(1, b.getPublisher());
- update.setString(2, b.getTitle());
- update.setInt(3, b.getYear());
- update.setInt(4, ent.getId());
-
- }
-
- @Override
- protected void setInsertQuery(EntityBase ent) throws SQLException {
-
- Book b = (Book)ent;
- insert.setString(1, b.getPublisher());
- insert.setString(2, b.getTitle());
- insert.setInt(3, b.getYear());
-
- }
-
- @Override
- protected String getUpdateQuery() {
- return "UPDATE Book SET "
- + "(publisher,title,year)=(?,?,?) "
- + "WHERE id=?";
- }
-
- @Override
- protected String getInsertQuery() {
- return "INSERT INTO Book(publisher,title,year)"
- + "VALUES (?,?,?)";
- }
-
- @Override
- protected String getCreateQuery() {
- return "CREATE TABLE Book("
- + "id int ,"
- + "publisher VARCHAR(50),"
- + "title VARCHAR(50),"
- + "year integer"
- + ")"
- + "";
- }
-
- @Override
- protected String getTableName() {
- return "Book";
- }
-
-
- /*
- private IAuthorManager authorMgr;
- private Connection connection;
- private String url = "jdbc:mysql://localhost/library?user=newuser&password=1qaz@WSX";
-
- private PreparedStatement getBooksById;
- private PreparedStatement getAllBooks;
- private PreparedStatement update;
- private PreparedStatement delete;
- private PreparedStatement insert;
- private IEntityBuilder<Book> builder;
- private PreparedStatement getAuthors;
-
- private Statement stmt;
-
-
- @Inject
- public MysqlBookManager(IUnitOfWork uow,
- IEntityBuilder<Book> builder,
- IAuthorManager authorMgr) {
- super(uow);
-
- this.builder=builder;
- this.authorMgr=authorMgr;
-
- try {
-
- Class.forName("com.mysql.jdbc.Driver").newInstance();
- connection = DriverManager.getConnection(url);
- stmt =connection.createStatement();
-
- ResultSet rs = connection.getMetaData()
- .getTables(null,null,null,null);
-
- boolean exist = false;
- while(rs.next())
- {
- if("Book".equalsIgnoreCase(rs.getString("TABLE_NAME")))
- {
- exist=true;
- break;
- }
- }
-
- if(!exist)
- {
- stmt.executeUpdate(""
- + "CREATE TABLE Book("
- + "id int ,"
- + "publisher VARCHAR(50),"
- + "title VARCHAR(50),"
- + "year integer"
- + ")"
- + "");
- }
-
- getBooksById = connection.prepareStatement(""
- + "SELECT * FROM Book WHERE id=?");
- getAllBooks = connection.prepareStatement("SELECT * FROM Book LIMIT ? ?");
- insert = connection.prepareStatement(""
- + "INSERT INTO Book(publisher,title,year)"
- + "VALUES (?,?,?)");
- delete = connection.prepareStatement(""
- + "DELETE FROM Book WHERE id=?");
- update = connection.prepareStatement("UPDATE Book SET "
- + "(publisher,title,year)=(?,?,?) "
- + "WHERE id=?");
-
- //getAuthors=connection.prepareStatement(
- // "SELECT * FROM Author WHERE bookId =?");
-
-
- } catch (Exception e) {
- e.printStackTrace();
- }
-
- }
-
- @Override
- public void setAuthors(Book b) {
- authorMgr.setAuthorsOfBook(b);
- }
-
- @Override
- public Book get(int id) {
- Book result = null;
- try{
-
- getBooksById.setInt(1, id);
- ResultSet rs = getBooksById.executeQuery();
- while(rs.next())
- {
- result = builder.build(rs);
- }
-
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
- return result;
- }
-
- @Override
- public List<Book> getAll(PageInfo request) {
- List<Book> books = new ArrayList<Book>();
-
- try{
- int n = request.getPageIndex()*request.getPageSize();
- getAllBooks.setInt(1, n);
- getAllBooks.setInt(2, request.getPageSize());
- ResultSet rs = getAllBooks.executeQuery();
- while(rs.next())
- {
- Book result = builder.build(rs);
-
- books.add(result);
- }
-
- }catch(Exception ex)
- {
- ex.printStackTrace();
- }
- return books;
- }
-
- @Override
- public void persistAdd(EntityBase ent) {
-
- Book b = (Book)ent;
- try {
-
- insert.setString(1, b.getPublisher());
- insert.setString(2, b.getTitle());
- insert.setInt(3, b.getYear());
- insert.executeUpdate();
-
- } catch (SQLException e) {
- e.printStackTrace();
- }
- }
-
- @Override
- public void persistDeleted(EntityBase ent) {
-
- try {
- delete.setInt(1, ent.getId());
- delete.executeUpdate();
- } catch (SQLException e) {
- // TODO Auto-generated catch block
- e.printStackTrace();
- }
- }
-
- @Override
- public void persistUpdated(EntityBase ent) {
- Book b = (Book)ent;
- try{
- update.setString(1, b.getPublisher());
- update.setString(2, b.getTitle());
- update.setInt(3, b.getYear());
- update.setInt(4, ent.getId());
- update.executeUpdate();
- }
- catch(Exception ex)
- {
- ex.printStackTrace();
- }
- }
-*/
-}
-
+package database.managers.impl;
+
+import java.sql.Date;
+import java.sql.PreparedStatement;
+import java.sql.ResultSet;
+import java.sql.SQLException;
+import java.util.ArrayList;
+import java.util.List;
+
+import database.MysqlUnitOfWork;
+import database.PageInfo;
+import database.builder.IEntityBuilder;
+import database.managers.IBookManager;
+import model.Aggregate;
+import model.Book;
+import model.EntityBase;
+
+public class MysqlBookManager extends MysqlManagerBase<Book> implements IBookManager{
+
+
+ private PreparedStatement getBookByAggregate;
+ private PreparedStatement countBookByAggregate;
+
+ public MysqlBookManager(MysqlUnitOfWork uow, IEntityBuilder<Book> builder) {
+ super(uow, builder);
+
+ try {
+ getBookByAggregate = uow.getConnection().prepareStatement(
+ "SELECT * FROM book,book_aggregate "
+ + "where Aggregate_Id=? "
+ + "AND Book_Id=book.Id "
+ + "LIMIT ?,?");
+ countBookByAggregate = uow.getConnection().prepareStatement(
+ "SELECT count(*) FROM book,book_aggregate "
+ + "where Aggregate_Id=? "
+ + "AND Book_Id=book.Id "
+ );
+
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ }
+
+ @Override
+ protected void setUpdateQuery(EntityBase ent) throws SQLException {
+ Book b = (Book)ent;
+ update.setString(1, b.getTitle());
+ update.setDouble(2, b.getPrice());
+ update.setDate(3,new Date(b.getDateOfAggregation().getTime()));
+ update.setInt(4, b.getId());
+ }
+
+ @Override
+ protected void setInsertQuery(EntityBase ent) throws SQLException {
+ Book b = (Book)ent;
+ insert.setString(1, b.getTitle());
+ insert.setDouble(2, b.getPrice());
+ insert.setDate(3,new Date(b.getDateOfAggregation().getTime()));
+ }
+
+ @Override
+ protected String getUpdateQuery() {
+ return "UPDATE book SET (title,price,dateofaggregation)=(?,?,?) WHERE id=?";
+ }
+
+ @Override
+ protected String getInsertQuery() {
+
+ return "INSERT INTO book(title,price,dateofaggregation) VALUES (?,?,?)";
+ }
+
+ @Override
+ protected String getCreateQuery() {
+ // TODO Auto-generated method stub
+ return "CREATE TABLE `book` ("
+ + "`Id` int(11) NOT NULL AUTO_INCREMENT,"
+ + "`Title` longtext,"
+ + "`Price` double NOT NULL,"
+ +"`DateOFAggregation` datetime NOT NULL,"
+ + "PRIMARY KEY (`Id`),"
+ + "UNIQUE KEY `Id` (`Id`)"
+ +")";
+ }
+
+ @Override
+ protected String getTableName() {
+ return "book";
+ }
+
+ @Override
+ public List<Book> getBooksByAggregate(Aggregate aggregate, PageInfo pageInfo) {
+ List<Book> result = new ArrayList<Book>();
+
+ try {
+ getBookByAggregate.setInt(1, aggregate.getId());
+ getBookByAggregate.setInt(2, pageInfo.getPageIndex()*pageInfo.getPageSize());
+ getBookByAggregate.setInt(3, pageInfo.getPageSize());
+ ResultSet rs = getBookByAggregate.executeQuery();
+ while(rs.next())
+ {
+ Book b = builder.build(rs);
+ b.getAggregates().add(aggregate);
+ aggregate.getBooks().add(b);
+ result.add(b);
+ }
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return result;
+ }
+
+ @Override
+ public int countBooksByAggregate(Aggregate aggregate) {
+
+ try {
+ countBookByAggregate.setInt(1, aggregate.getId());
+ ResultSet rs = countBookByAggregate.executeQuery();
+ while(rs.next())
+ return rs.getInt(1);
+ } catch (SQLException e) {
+ e.printStackTrace();
+ }
+ return 0;
+ }
+
+}
18 src/main/java/database/managers/impl/MysqlManagerBase.java
View
@@ -21,6 +21,7 @@
protected PreparedStatement update;
protected PreparedStatement delete;
protected PreparedStatement insert;
+ protected PreparedStatement count;
protected IEntityBuilder<E> builder;
protected Statement stmt;
@@ -70,7 +71,8 @@ public MysqlManagerBase(MysqlUnitOfWork uow, IEntityBuilder<E> builder) {
getAll = getConnection().prepareStatement("SELECT * FROM "
+ getTableName()
+ " LIMIT ? ?");
-
+ count = getConnection().prepareStatement("Select count(*) from " + getTableName());
+
update = getConnection().prepareStatement(getUpdateQuery());
} catch (Exception e) {
e.printStackTrace();
@@ -121,6 +123,20 @@ public E get(int id) {
}
@Override
+ public int count()
+ {
+ try {
+ ResultSet rs = count.executeQuery();
+ while(rs.next())
+ return rs.getInt(1);
+ } catch (SQLException e) {
+ // TODO Auto-generated catch block
+ e.printStackTrace();
+ }
+ return 0;
+ }
+
+ @Override
public void persistAdd(EntityBase ent) {
try {
37 src/main/java/dto/AuthorSummaryDto.java
View
@@ -1,37 +0,0 @@
-package dto;
-
-public class AuthorSummaryDto {
-
- private int id;
-
- private String name;
- private String surname;
-
-
-
- public String getName() {
- return name;
- }
-
- public void setName(String name) {
- this.name = name;
- }
-
- public String getSurname() {
- return surname;
- }
-
- public void setSurname(String surname) {
- this.surname = surname;
- }
-
- public int getId() {
- return id;
- }
-
- public void setId(int id) {
- this.id = id;
- }
-
-
-}
20 src/main/java/dto/BookDto.java
View
@@ -1,20 +0,0 @@
-package dto;
-
-import java.util.List;
-
-import javax.xml.bind.annotation.XmlRootElement;
-@XmlRootElement
-public class BookDto extends BookSummaryDto{
-
- private List<AuthorSummaryDto> authors;
-
- public List<AuthorSummaryDto> getAuthors() {
- return authors;
- }
-
- public void setAuthors(List<AuthorSummaryDto> authors) {
- this.authors = authors;
- }
-
-
-}
36 src/main/java/dto/BookSummaryDto.java
View
@@ -1,36 +0,0 @@
-package dto;
-
-public class BookSummaryDto {
-
- private String title;
- private String publisher;
- private int year;
- private int id;
-
- public String getTitle() {
- return title;
- }
- public void setTitle(String title) {
- this.title = title;
- }
- public String getPublisher() {
- return publisher;
- }
- public void setPublisher(String publisher) {
- this.publisher = publisher;
- }
- public int getYear() {
- return year;
- }
- public void setYear(int year) {
- this.year = year;
- }
- public int getId() {
- return id;
- }
- public void setId(int id) {
- this.id = id;
- }
-
-
-}
6 src/main/java/enums/EnumNames.java
View
@@ -1,6 +0,0 @@
-package enums;
-
-public enum EnumNames {
-
- MagazineType
-}
20 src/main/java/enums/EnumerationProvider.java
View
@@ -1,20 +0,0 @@
-package enums;
-
-
-public class EnumerationProvider {
-
- public static Object Provide(int intKey, String enumName)
- {
- EnumNames name = EnumNames.valueOf(enumName);
- switch(name)
- {
- case MagazineType:
- {
- return MagazineType.values()[intKey];
- }
- default:
- break;
- }
- return null;
- }
-}
5 src/main/java/enums/MagazineType.java
View
@@ -1,5 +0,0 @@
-package enums;
-
-public enum MagazineType {
- miesiecznik, kwartalnik, tygodnik, dziennik
-}
39 src/main/java/model/Aggregate.java
View
@@ -0,0 +1,39 @@
+package model;
+
+import java.util.ArrayList;
+import java.util.Collection;
+
+public class Aggregate extends EntityBase {
+
+ private String name;
+ private Aggregate parent;
+
+ private Collection<Aggregate> children = new ArrayList<Aggregate>();
+ private Collection<Book> books = new ArrayList<Book>();
+
+ public String getName() {
+ return name;
+ }
+
+ public void setName(String name) {
+ this.name = name;
+ }
+
+ public Collection<Book> getBooks() {
+ return books;
+ }
+
+ public Aggregate getParent() {
+ return parent;
+ }
+
+ public void setParent(Aggregate parent) {
+ this.parent = parent;
+ }
+
+ public Collection<Aggregate> getChildren() {
+ return children;
+ }
+
+
+}
56 src/main/java/model/Author.java
View
@@ -1,56 +0,0 @@
-package model;
-
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
-
-import javax.persistence.Entity;
-import javax.persistence.FetchType;
-import javax.persistence.ManyToMany;
-import javax.persistence.Table;
-
-@Entity
-@Table(name="authors")
-public class Author extends EntityBase {
-
- private String name;
- private String surname;
- @ManyToMany(mappedBy="authors")
- private Collection<Book> books = new ArrayList<Book>();
-
-
- public Collection<Book> getBooks() {
- return books;
- }
-
- public void setBooks(Collection<Book> books) {
- this.books = books;
- }
-
- public String toString()
- {
- return "Imie: "+this.name+"\n" +
- "Nazwisko: " +this.surname;
- }
-
- public String getName() {
- return name;
- }
- public void setName(String name) {
- this.name = name;
- }
- public String getSurname() {
- return surname;
- }
- public void setSurname(String surname) {
- this.surname = surname;
- }
-
- @Override
- protected String showDetails() {
- // TODO Auto-generated method stub
- return this.toString();
- }
-
-
-}
56 src/main/java/model/Book.java
View
@@ -9,63 +9,35 @@
import javax.persistence.Transient;
@Entity
-@Table(name = "books")
+@Table(name = "book")
public class Book extends EntityBase {
-
- @ManyToMany(cascade=javax.persistence.CascadeType.ALL, fetch=FetchType.EAGER)
- private Collection<Author> authors = new ArrayList<Author>();
-
-
-
- private String publisher;
private String title;
- private int year;
+ private double price;
+ private Date dateOfAggregation;
+ private Collection<Aggregate> aggregates = new ArrayList<Aggregate>();
public String getTitle() {
return title;
}
-
public void setTitle(String title) {
this.title = title;
}
-
- public int getYear() {
- return year;
- }
-
- public void setYear(int year) {
- this.year = year;
+ public double getPrice() {
+ return price;
}
-
- @Override
- protected String showDetails() {
-
- String details;
- details="\nAutorzy:";
- for(Author a : authors)
- {
- details+="\nb"+a;
- }
- details+="Wydawca: "+this.publisher;
- return details;
+ public void setPrice(double price) {
+ this.price = price;
}
-
- public Collection<Author> getAuthors() {
- return authors;
+ public Date getDateOfAggregation() {
+ return dateOfAggregation;
}
-
- public void setAuthors(Collection<Author> arrayList) {
- this.authors = arrayList;
+ public void setDateOfAggregation(Date dateOfAggregation) {
+ this.dateOfAggregation = dateOfAggregation;
}
-
- public String getPublisher() {
- return publisher;
- }
-
- public void setPublisher(String publisher) {
- this.publisher = publisher;
+ public Collection<Aggregate> getAggregates() {
+ return aggregates;
}
10 src/main/java/model/EntityBase.java
View
@@ -15,16 +15,6 @@
@GeneratedValue(strategy=GenerationType.TABLE)
protected int id;
- public final String show()
- {
- String details = null;
-
- return details;
- }
-
- protected abstract String showDetails();
-
-
public int getId() {
return id;
}
57 src/main/java/model/Enumeration.java
View
@@ -1,57 +0,0 @@
-package model;
-
-public class Enumeration extends EntityBase {
-
- private int intKey;
- private String stringKey;
- private String value;
- private String enumName;
-
- public Enumeration()
- {}
-
- public Enumeration(int intKey, String stringKey, String value,
- String enumName) {
- super();
- this.intKey = intKey;
- this.stringKey = stringKey;
- this.value = value;
- this.enumName = enumName;
- }
-
- public int getIntKey() {
- return intKey;
- }
-
- public void setIntKey(int intKey) {
- this.intKey = intKey;
- }
-
- public String getStringKey() {
- return stringKey;
- }
-
- public void setStringKey(String stringKey) {
- this.stringKey = stringKey;
- }
- public String getValue() {
- return value;
- }
-
- public void setValue(String value) {
- this.value = value;
- }
- public String getEnumName() {
- return enumName;
- }
- public void setEnumName(String enumName) {
- this.enumName = enumName;
- }
-
- @Override
- protected String showDetails() {
- // TODO Auto-generated method stub
- return toString();
- }
-
-}
35 src/main/java/model/Magazine.java
View
@@ -1,35 +0,0 @@
-package model;
-
-import enums.MagazineType;
-
-public class Magazine extends EntityBase{
-
- private int number;
- private MagazineType typeOfMagazine;
-
- @Override
- protected String showDetails() {
- String details;
- details="\nNumer magazynu: "+this.number+"\n";
- details+="Typ: "+ typeOfMagazine;
- return details;
- }
-
- public int getNumber() {
- return number;
- }
-
- public void setNumber(int number) {
- this.number = number;
- }
-
- public MagazineType getTypeOfMagazine() {
- return typeOfMagazine;
- }
-
- public void setTypeOfMagazine(MagazineType typeOfMagazine) {
- this.typeOfMagazine = typeOfMagazine;
- }
-
-
-}
2  src/main/resources/hibernate.cfg.xml
View
@@ -19,7 +19,7 @@
<property name="show_sql">true</property>
- <property name="hbm2ddl.auto">create</property>
+ <property name="hbm2ddl.auto">update</property>
<mapping class="model.Book" />
<mapping class="model.EntityBase"/>
103 src/test/java/database/managers/book/tests/BookManagerTests.java
View
@@ -1,103 +0,0 @@
-package database.managers.book.tests;
-
-import static org.junit.Assert.*;
-import model.Book;
-
-import org.junit.After;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-import database.MockDb;
-import database.UnitOfWork;
-import database.managers.IBookManager;
-import database.managers.impl.MockBookManager;
-import database.unitofwork.IUnitOfWork;
-
-public class BookManagerTests {
-
- private MockDb db;
- private IUnitOfWork uow;
- @BeforeClass
- public static void setUpBeforeClass() throws Exception {
-
- }
-
- @AfterClass
- public static void tearDownAfterClass() throws Exception {
- }
-
- @Before
- public void setUp() throws Exception {
- db = new MockDb();
- Book b1 = new Book();
- Book b2 = new Book();
- Book b3 = new Book();
- Book b4 = new Book();
- b1.setPublisher("Helion");
- b1.setTitle("Java");
- b1.setYear(2010);
-
- b2.setPublisher("Helion");
- b2.setTitle("Java2");
- b2.setYear(2011);
-
- b3.setPublisher("Helion");
- b3.setTitle("Java3");
- b3.setYear(2012);
-
- b4.setPublisher("Helion");
- b4.setTitle("Java4");
- b4.setYear(2013);
- db.save(b1);
- db.save(b2);
- db.save(b3);
- db.save(b4);
- uow = new UnitOfWork();
-
- }
-
- @After
- public void tearDown() throws Exception {
- db.getAllItems().clear();
- }
-
- @Test
- public void testPersistAdd() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testPersistDeleted() {
- fail("Not yet implemented");
- }
-
- @Test
- public void testPersistUpdated() {
- fail("Not yet implemented");
- }
-
- @Test
- public void test_sprawdza_poprawnosc_wyciagania_ksiazki_z_bazy() {
- IBookManager mgr = new MockBookManager(uow,db);
- Book book = mgr.get(1);
- Book book2 = mgr.get(1);
- assertNotNull("nie udało się wybrać książki z bazy"
- ,book);
- assertTrue("problem z pobraniem wydawcy"
- ,book.getPublisher().equals("Helion"));
- assertEquals("problem z pobraniem wydawcy",
- book.getPublisher(),"Helion");
- assertEquals("problem z tytułem",
- book.getTitle(),"Java");
- assertNotSame("obiekty wskazują na tą samą przestrzeń w pamieci"
- ,book,book2);
- }
-
- @Test
- public void testGetAll() {
- fail("Not yet implemented");
- }
-
-}
Please sign in to comment.
Something went wrong with that request. Please try again.