1 package com.atlassian.jira.referentiel.entities;
2
3 import java.util.Map;
4
5 import org.ofbiz.core.entity.EntityUtil;
6 import org.ofbiz.core.entity.GenericDelegator;
7 import org.ofbiz.core.entity.GenericEntityException;
8 import org.ofbiz.core.entity.GenericValue;
9 import org.ofbiz.core.util.UtilMisc;
10
11 import com.atlassian.core.ofbiz.CoreFactory;
12 import com.atlassian.core.ofbiz.util.EntityUtils;
13
14 public abstract class AInternalEntity extends AExternalEntity {
15
16 public AInternalEntity(GenericValue genericValue) {
17 super(genericValue);
18 init(genericValue);
19 }
20
21 public static final String ID = "id";
22
23 private Long id = null;
24
25 public Map getEntityKeys() {
26 return UtilMisc.toMap(ID,id);
27 }
28
29
30
31
32 public abstract Map getEntityCandidateKeys();
33
34
35
36
37 protected void addKeys(Map _fields) {
38 try {
39 if (id==null) {
40 id = new Long(EntityUtils.getNextStringId(getEntityName()));
41 }
42 _fields.putAll(getEntityKeys());
43 } catch (Exception e) {
44 }
45 }
46
47
48
49
50
51 public void load() throws GenericEntityException {
52 super.load();
53 if (genericValue == null) {
54 GenericDelegator gd = CoreFactory.getGenericDelegator();
55 genericValue = EntityUtil.getOnly(gd.findByAnd(getEntityName(), getEntityCandidateKeys()));
56 }
57 }
58
59
60
61
62 public boolean isCreated() {
63 boolean isCreated = false;
64 try {
65 load();
66 isCreated = (getGenericValue() != null);
67
68
69
70 } catch (Exception e) {
71 }
72
73
74
75
76
77
78
79 return isCreated;
80 }
81
82 public Long getId() { return id; }
83
84 public void setId(Long i) { id = i; }
85
86 }