7.10.2. InvoiceManager Class

The ru.ibase.fbjavaex.managers.InvoiceManager class is a kind of business layer that will be used to direct adding, editing and deleting invoices and their items, along with invoice payment. All operations in this layer will be performed in a SNAPSHOT transaction. We have chosen to have our application perform all of the invoice management options in this class by calling stored procedures. It is not mandatory to do it this way, of course. It is just one option.

  1. package ru.ibase.fbjavaex.managers;
  2. import java.sql.Timestamp;
  3. import org.jooq.DSLContext;
  4. import org.springframework.beans.factory.annotation.Autowired;
  5. import org.springframework.transaction.annotation.Transactional;
  6. import org.springframework.transaction.annotation.Propagation;
  7. import org.springframework.transaction.annotation.Isolation;
  8. import static ru.ibase.fbjavaex.exampledb.Sequences.GEN_INVOICE_ID;
  9. import static ru.ibase.fbjavaex.exampledb.Routines.spAddInvoice;
  10. import static ru.ibase.fbjavaex.exampledb.Routines.spEditInvoice;
  11. import static ru.ibase.fbjavaex.exampledb.Routines.spPayForInovice;
  12. import static ru.ibase.fbjavaex.exampledb.Routines.spDeleteInvoice;
  13. import static ru.ibase.fbjavaex.exampledb.Routines.spAddInvoiceLine;
  14. import static ru.ibase.fbjavaex.exampledb.Routines.spEditInvoiceLine;
  15. import static ru.ibase.fbjavaex.exampledb.Routines.spDeleteInvoiceLine;
  16. /**
  17. * Invoice manager
  18. *
  19. * @author Simonov Denis
  20. */
  21. public class InvoiceManager {
  22. @Autowired(required = true)
  23. private DSLContext dsl;
  24. /**
  25. * Add invoice
  26. *
  27. * @param customerId
  28. * @param invoiceDate
  29. */
  30. @Transactional(propagation = Propagation.REQUIRED,
  31. isolation = Isolation.REPEATABLE_READ)
  32. public void create(Integer customerId,
  33. Timestamp invoiceDate) {
  34. int invoiceId = this.dsl.nextval(GEN_INVOICE_ID).intValue();
  35. spAddInvoice(this.dsl.configuration(),
  36. invoiceId,
  37. customerId,
  38. invoiceDate);
  39. }
  40. /**
  41. * Edit invoice
  42. *
  43. * @param invoiceId
  44. * @param customerId
  45. * @param invoiceDate
  46. */
  47. @Transactional(propagation = Propagation.REQUIRED,
  48. isolation = Isolation.REPEATABLE_READ)
  49. public void edit(Integer invoiceId,
  50. Integer customerId,
  51. Timestamp invoiceDate) {
  52. spEditInvoice(this.dsl.configuration(),
  53. invoiceId,
  54. customerId,
  55. invoiceDate);
  56. }
  57. /**
  58. * Payment of invoices
  59. *
  60. * @param invoiceId
  61. */
  62. @Transactional(propagation = Propagation.REQUIRED,
  63. isolation = Isolation.REPEATABLE_READ)
  64. public void pay(Integer invoiceId) {
  65. spPayForInovice(this.dsl.configuration(),
  66. invoiceId);
  67. }
  68. /**
  69. * Delete invoice
  70. *
  71. * @param invoiceId
  72. */
  73. @Transactional(propagation = Propagation.REQUIRED,
  74. isolation = Isolation.REPEATABLE_READ)
  75. public void delete(Integer invoiceId) {
  76. spDeleteInvoice(this.dsl.configuration(),
  77. invoiceId);
  78. }
  79. /**
  80. * Add invoice item
  81. *
  82. * @param invoiceId
  83. * @param productId
  84. * @param quantity
  85. */
  86. @Transactional(propagation = Propagation.REQUIRED,
  87. isolation = Isolation.REPEATABLE_READ)
  88. public void addInvoiceLine(Integer invoiceId,
  89. Integer productId,
  90. Integer quantity) {
  91. spAddInvoiceLine(this.dsl.configuration(),
  92. invoiceId,
  93. productId,
  94. quantity);
  95. }
  96. /**
  97. * Edit invoice item
  98. *
  99. * @param invoiceLineId
  100. * @param quantity
  101. */
  102. @Transactional(propagation = Propagation.REQUIRED,
  103. isolation = Isolation.REPEATABLE_READ)
  104. public void editInvoiceLine(Integer invoiceLineId,
  105. Integer quantity) {
  106. spEditInvoiceLine(this.dsl.configuration(),
  107. invoiceLineId,
  108. quantity);
  109. }
  110. /**
  111. * Delete invoice item
  112. *
  113. * @param invoiceLineId
  114. */
  115. @Transactional(propagation = Propagation.REQUIRED,
  116. isolation = Isolation.REPEATABLE_READ)
  117. public void deleteInvoiceLine(Integer invoiceLineId) {
  118. spDeleteInvoiceLine(this.dsl.configuration(),
  119. invoiceLineId);
  120. }
  121. }