BrightSide Workbench Full Report + Source Code
bsfinancials-core/src/main/java/org/turro/financials/entity/DocumentDefinition.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 java.util.HashSet;
21 import java.util.Set;
22 import java.util.TreeSet;
23 import javax.persistence.CascadeType;
24 import javax.persistence.Column;
25 import javax.persistence.Entity;
26 import javax.persistence.FetchType;
27 import javax.persistence.GeneratedValue;
28 import javax.persistence.GenerationType;
29 import javax.persistence.Id;
30 import javax.persistence.OneToMany;
31 import javax.persistence.OrderBy;
32 import org.turro.financials.db.FinancialsPU;
33 import org.turro.jpa.Dao;
34 import org.turro.jpa.entity.IDaoEntity;
35 
40 @Entity
41 public class DocumentDefinition implements java.io.Serializable, IDaoEntity {
42 
43  @Id
44  @GeneratedValue(strategy=GenerationType.IDENTITY)
45  @Column(name="IDENTIFIER")
46  private long id;
47 
48  @Column(name="DOCDEF_NAME")
49  private String name;
50 
51  private boolean autoNumbered;
52 
53  @OneToMany(mappedBy = "documentDefinition", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval=true)
54  @OrderBy("columnOrder")
55  private Set<RelatedColumn> documentColumns = new TreeSet<RelatedColumn>();
56 
57  @OneToMany(mappedBy = "documentDefinition", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval=true)
58  private Set<RelatedStoreDefinition> relatedStoreDefinitions = new HashSet<RelatedStoreDefinition>();
59 
60  @OneToMany(mappedBy = "documentDefinition", fetch = FetchType.LAZY, cascade = CascadeType.ALL, orphanRemoval=true)
61  private Set<RelatedLineType> relatedLineTypes = new HashSet<RelatedLineType>();
62 
63  public boolean isAutoNumbered() {
64  return autoNumbered;
65  }
66 
67  public void setAutoNumbered(boolean autoNumbered) {
68  this.autoNumbered = autoNumbered;
69  }
70 
71  public Set<RelatedColumn> getDocumentColumns() {
72  Dao dao = new FinancialsPU();
73  if(id > 0 && dao.isNotLoaded(documentColumns)) {
74  documentColumns = dao.lazyLoader(DocumentDefinition.class, this, "documentColumns").documentColumns;
75  }
76  return documentColumns;
77  }
78 
79  public void setDocumentColumns(Set<RelatedColumn> documentColumns) {
80  this.documentColumns = documentColumns;
81  }
82 
83  public long getId() {
84  return id;
85  }
86 
87  public void setId(long id) {
88  this.id = id;
89  }
90 
91  public String getName() {
92  return name;
93  }
94 
95  public void setName(String name) {
96  this.name = name;
97  }
98 
99  public Set<RelatedLineType> getRelatedLineTypes() {
100  Dao dao = new FinancialsPU();
101  if(id > 0 && dao.isNotLoaded(relatedLineTypes)) {
102  relatedLineTypes = dao.lazyLoader(DocumentDefinition.class, this, "relatedLineTypes").relatedLineTypes;
103  }
104  return relatedLineTypes;
105  }
106 
107  public void setRelatedLineTypes(Set<RelatedLineType> relatedLineTypes) {
108  this.relatedLineTypes = relatedLineTypes;
109  }
110 
111  public Set<RelatedStoreDefinition> getRelatedStoreDefinitions() {
112  Dao dao = new FinancialsPU();
113  if(id > 0 && dao.isNotLoaded(relatedStoreDefinitions)) {
114  relatedStoreDefinitions = dao.lazyLoader(DocumentDefinition.class, this, "relatedStoreDefinitions").relatedStoreDefinitions;
115  }
116  return relatedStoreDefinitions;
117  }
118 
119  public void setRelatedStoreDefinitions(Set<RelatedStoreDefinition> relatedStoreDefinitions) {
120  this.relatedStoreDefinitions = relatedStoreDefinitions;
121  }
122 
123  /* IDaoEntity */
124 
125  @Override
126  public Object entityId() {
127  return id;
128  }
129 
130  @Override
131  public boolean isEmpty() {
132  return id > 0;
133  }
134 
135  /* Helpers */
136 
137  public boolean hasColumn(DocumentColumn documentColumn) {
138  for(RelatedColumn dc : getDocumentColumns()) {
139  if(documentColumn.equals(dc.getDocumentColumn())) {
140  return true;
141  }
142  }
143  return false;
144  }
145 
146  public boolean hasDetail() {
148  }
149 
151  return new FinancialsPU().find(DocumentDefinition.class, 2L);
152  }
153 
154 }
boolean isNotLoaded(Object o, String attribute)
Definition: Dao.java:216