/src/classes/com/sapienter/jbilling/server/order/db/OrderPeriodDTO.java

https://github.com/bibulous/SkyrackJbill2.2 · Java · 167 lines · 123 code · 24 blank · 20 comment · 0 complexity · ec5cd98efa45e8d74c4ac6ac5eea598a MD5 · raw file

  1. /*
  2. jBilling - The Enterprise Open Source Billing System
  3. Copyright (C) 2003-2009 Enterprise jBilling Software Ltd. and Emiliano Conde
  4. This file is part of jbilling.
  5. jbilling is free software: you can redistribute it and/or modify
  6. it under the terms of the GNU Affero General Public License as published by
  7. the Free Software Foundation, either version 3 of the License, or
  8. (at your option) any later version.
  9. jbilling is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU Affero General Public License for more details.
  13. You should have received a copy of the GNU Affero General Public License
  14. along with jbilling. If not, see <http://www.gnu.org/licenses/>.
  15. */
  16. package com.sapienter.jbilling.server.order.db;
  17. import java.util.HashSet;
  18. import java.util.Set;
  19. import javax.persistence.CascadeType;
  20. import javax.persistence.Column;
  21. import javax.persistence.Entity;
  22. import javax.persistence.FetchType;
  23. import javax.persistence.GeneratedValue;
  24. import javax.persistence.GenerationType;
  25. import javax.persistence.Id;
  26. import javax.persistence.JoinColumn;
  27. import javax.persistence.ManyToOne;
  28. import javax.persistence.OneToMany;
  29. import javax.persistence.Table;
  30. import javax.persistence.TableGenerator;
  31. import javax.persistence.Transient;
  32. import javax.persistence.Version;
  33. import org.hibernate.annotations.Cache;
  34. import org.hibernate.annotations.CacheConcurrencyStrategy;
  35. import com.sapienter.jbilling.server.process.db.PeriodUnitDTO;
  36. import com.sapienter.jbilling.server.user.db.CompanyDTO;
  37. import com.sapienter.jbilling.server.util.Constants;
  38. import com.sapienter.jbilling.server.util.db.AbstractDescription;
  39. @Entity
  40. @TableGenerator(
  41. name="order_period_GEN",
  42. table="jbilling_seqs",
  43. pkColumnName = "name",
  44. valueColumnName = "next_id",
  45. pkColumnValue="order_period",
  46. allocationSize = 100
  47. )
  48. @Table(name="order_period")
  49. @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
  50. public class OrderPeriodDTO extends AbstractDescription implements java.io.Serializable {
  51. private int id;
  52. private CompanyDTO company;
  53. private PeriodUnitDTO periodUnitDTO;
  54. private Integer value;
  55. private Set<OrderDTO> orderDTOs = new HashSet<OrderDTO>(0);
  56. private Integer versionNum;
  57. public OrderPeriodDTO() {
  58. }
  59. public OrderPeriodDTO(int id) {
  60. this.id = id;
  61. }
  62. public OrderPeriodDTO(int id, CompanyDTO entity, PeriodUnitDTO periodUnitDTO, Integer value, Set<OrderDTO> orderDTOs) {
  63. this.id = id;
  64. this.company = entity;
  65. this.periodUnitDTO = periodUnitDTO;
  66. this.value = value;
  67. this.orderDTOs = orderDTOs;
  68. }
  69. @Transient
  70. protected String getTable() {
  71. return Constants.TABLE_ORDER_PERIOD;
  72. }
  73. @Id @GeneratedValue(strategy=GenerationType.TABLE, generator="order_period_GEN")
  74. @Column(name="id", unique=true, nullable=false)
  75. public int getId() {
  76. return this.id;
  77. }
  78. public void setId(int id) {
  79. this.id = id;
  80. }
  81. @ManyToOne(fetch=FetchType.LAZY)
  82. @JoinColumn(name="entity_id")
  83. public CompanyDTO getCompany() {
  84. return this.company;
  85. }
  86. public void setCompany(CompanyDTO entity) {
  87. this.company = entity;
  88. }
  89. @ManyToOne(fetch=FetchType.LAZY)
  90. @JoinColumn(name="unit_id")
  91. public PeriodUnitDTO getPeriodUnit() {
  92. return this.periodUnitDTO;
  93. }
  94. public void setPeriodUnit(PeriodUnitDTO periodUnitDTO) {
  95. this.periodUnitDTO = periodUnitDTO;
  96. }
  97. @Column(name="value")
  98. public Integer getValue() {
  99. return this.value;
  100. }
  101. public void setValue(Integer value) {
  102. this.value = value;
  103. }
  104. @OneToMany(cascade=CascadeType.ALL, fetch=FetchType.LAZY, mappedBy="orderPeriod")
  105. public Set<OrderDTO> getPurchaseOrders() {
  106. return this.orderDTOs;
  107. }
  108. public void setPurchaseOrders(Set<OrderDTO> orderDTOs) {
  109. this.orderDTOs = orderDTOs;
  110. }
  111. @Version
  112. @Column(name="OPTLOCK")
  113. public Integer getVersionNum() {
  114. return versionNum;
  115. }
  116. protected void setVersionNum(Integer versionNum) {
  117. this.versionNum = versionNum;
  118. }
  119. public String toString() {
  120. return "OrderPeriodDTO:[" +
  121. " id=" + id +
  122. " company=" + company +
  123. " periodUnitDTO=" + periodUnitDTO +
  124. " value=" + value +
  125. " versionNum=" + versionNum + "]";
  126. }
  127. // convenient methods for migration from entity beans
  128. @Transient
  129. public Integer getUnitId() {
  130. return getPeriodUnit().getId();
  131. }
  132. public void setUnitId(int id) {
  133. PeriodUnitDTO period = new PeriodUnitDTO(id);
  134. setPeriodUnit(period);
  135. }
  136. public void touch() {
  137. getUnitId();
  138. }
  139. }