BrightSide Workbench Full Report + Source Code
BookRegister.java
Go to the documentation of this file.
1 /*
2  * TurrĂ³ i Cutiller Foundation. License notice.
3  * Copyright (C) 2011 Lluis TurrĂ³ Cutiller <http://www.turro.org/>
4  *
5  * This program 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  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU Affero General Public License for more details.
14  *
15  * You should have received a copy of the GNU Affero General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package org.turro.financials.entity;
19 
20 import javax.persistence.*;
21 import org.amic.util.date.CheckDate;
22 import org.turro.elephant.db.IdUtils;
23 import org.turro.financials.db.FinancialsPU;
24 import org.turro.jpa.entity.IDaoEntity;
25 
30 @Entity
31 public class BookRegister implements java.io.Serializable, IDaoEntity {
32 
33  @Id
34  @GeneratedValue(strategy=GenerationType.IDENTITY)
35  @Column(name="IDENTIFIER")
36  private long id;
37 
38  @ManyToOne
39  private BookDefinition bookDefinition;
40 
41  @ManyToOne
42  private Register register;
43 
44  private long bookOrder;
45 
47  return bookDefinition;
48  }
49 
50  public void setBookDefinition(BookDefinition bookDefinition) {
51  this.bookDefinition = bookDefinition;
52  }
53 
54  public long getBookOrder() {
55  return bookOrder;
56  }
57 
58  public void setBookOrder(long bookOrder) {
59  this.bookOrder = bookOrder;
60  }
61 
62  public long getId() {
63  return id;
64  }
65 
66  public void setId(long id) {
67  this.id = id;
68  }
69 
70  public Register getRegister() {
71  return register;
72  }
73 
74  public void setRegister(Register register) {
75  this.register = register;
76  }
77 
78  @Override
79  public Object entityId() {
80  return id;
81  }
82 
83  @Override
84  public boolean isEmpty() {
85  return bookDefinition == null || register == null;
86  }
87 
88  @Override
89  public void prepareSave() {
90  IDaoEntity.super.prepareSave();
91  if(bookOrder == 0) {
92  bookOrder = IdUtils.getMaxLongIdFromLong(
93  new FinancialsPU(), "BookRegister", "bookOrder",
94  new String[] {
95  "year(register.registerDate) = " + new CheckDate(register.getRegisterDate()).getYear(),
96  "bookDefinition.id = " + bookDefinition.getId(),
97  "register.view.id = " + register.getView().getId()
98  });
99  }
100  }
101 
102 }
static long getMaxLongIdFromLong(Dao dao, String table, String field)
Definition: IdUtils.java:91
void setBookDefinition(BookDefinition bookDefinition)