예제 #1
0
 public int setPrice(int price) throws PriceLessThanZeroException {
   if (price < 0) {
     throw new PriceLessThanZeroException("Price cannot be equal or lower than zero");
   } else {
     logger.info("New manga: " + title + "added to list" + " Price:" + price);
     return this.price = price;
   }
 }
예제 #2
0
@NamedNativeQueries({
  @NamedNativeQuery(
      name = "findStockByStockCodeNativeSQL",
      query = "select * from manga",
      resultClass = Manga.class)
})
@Entity
public class Manga {

  @Id @GeneratedValue public int ID;

  @OneToOne
  @JoinColumn(name = "Manga_ID")
  private Manga manga;

  @ManyToOne
  @NotFound(action = NotFoundAction.IGNORE)
  private Customer owner;

  public String title;
  public int price;
  public MangaType mangatype;

  private static Logger logger = Logger.getLogger(Manga.class);

  public Customer getOwner() {
    return owner;
  }

  public void setOwner(Customer owner) {
    this.owner = owner;
  }

  public Manga getManga() {
    return manga;
  }

  public void setManga(Manga manga) {
    this.manga = manga;
  }

  public int getId() {
    return ID;
  }

  public void setId(int ID) {
    this.ID = ID;
  }

  public Manga(String title, int price, MangaType mangatype) {
    this.title = title;
    this.price = price;
    this.mangatype = mangatype;
  }

  public String printMangas() {
    String tempStorePrintMangas =
        "\t" + title + " | Price: " + price + "ZL" + " | MangaType: " + mangatype;
    System.out.println(tempStorePrintMangas);
    return tempStorePrintMangas;
  }

  public String getTitle() {
    return title;
  }

  public void setTitle(String title) {
    this.title = title;
  }

  public MangaType getMangaType() {
    return mangatype;
  }

  public void setMangaType(MangaType mangatype) {
    this.mangatype = mangatype;
  }

  public int getPrice() {
    return price;
  }

  public int setPrice(int price) throws PriceLessThanZeroException {
    if (price < 0) {
      throw new PriceLessThanZeroException("Price cannot be equal or lower than zero");
    } else {
      logger.info("New manga: " + title + "added to list" + " Price:" + price);
      return this.price = price;
    }
  }
}
예제 #3
0
  public static void main(String[] args) throws Cena_mniej_niz_zero {

    PropertyConfigurator.configure("log4j.properties");
    logger.debug("Sample debug message");
    logger.info("Sample info message");
    logger.warn("Sample warn message");
    logger.error("Sample error message");
    logger.fatal("Sample fatal message");
    SampleReport obj = new SampleReport();
    obj.generateReport();

    List<Product> products = new ArrayList<Product>();

    Client customer1 = new Client("Waldek", "Kiepski", products);
    try {
      customer1.addProduct(new Product("plyta CD", -1));
      customer1.addProduct(new Product("plyta DVD", 2));
      customer1.addProduct(new Product("kabel USB", 8));
      customer1.addProduct(new Product("slon", 10000));

    } catch (Cena_mniej_niz_zero e) {
      logger.error(e);
    }

    customer1.printCustomers();
    customer1.printMangas();
    System.out.println("Ilosc produktow " + products.size());
    System.out.println("\n");

    // HIBERNATE

    List<Client> owners = new ArrayList<Client>();

    SessionFactory sessionFactory = new Configuration().configure().buildSessionFactory();
    Session session = sessionFactory.openSession();
    session.beginTransaction();

    /*session.save(p);
    for(Car car :cars)
    {
    	session.save(car);
    }*/
    session.persist(customer1);

    List<Client> clients = session.getNamedQuery("Client.all").list();

    // session.save(garage2);
    // session.save(garage);
    session.get(Client.class, 1000);
    session.getTransaction().commit();
    int i = 1;
    do {
      owners.add((Client) session.get(Client.class, i));
      i++;
    } while (session.get(Client.class, i) != null);

    session.close();
    System.out.println(owners.size());

    for (Client client : clients) {
      System.out.print(client.getName());
    }
  }