1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package org.caleigo.core.meta;
20
21 import org.caleigo.core.*;
22
23 /***
24 *
25 * @author Mattias Hagstrand
26 * @version 1.0
27 */
28
29
30
31
32
33
34 class CustomFieldRelation implements IFieldRelation
35 {
36
37 private IEntityRelation mEntityRelation;
38
39 private CustomDataSourceDescriptor mDataSourceDescriptor;
40 private String mReferenceEntitySourceName;
41 private String mReferenceFieldSourceName;
42 private String mTargetEntitySourceName;
43 private String mTargetFieldSourceName;
44
45 private transient IFieldDescriptor mReferenceField;
46 private transient IFieldDescriptor mTargetField;
47
48
49 CustomFieldRelation(CustomDataSourceDescriptor dataSourceDescriptor, String referenceEntitySourceName, String referenceFieldSourceName,
50 String targetEntitySourceName, String targetFieldSourceName)
51 {
52 mDataSourceDescriptor = dataSourceDescriptor;
53 mReferenceEntitySourceName = referenceEntitySourceName;
54 mReferenceFieldSourceName = referenceFieldSourceName;
55 mTargetEntitySourceName = targetEntitySourceName;
56 mTargetFieldSourceName = targetFieldSourceName;
57 }
58
59
60
61 /*** Access method that return the IEntityRelation that the called
62 * IFieldRelation is a part of.
63 */
64 public IEntityRelation getEntityRelation()
65 {
66 return mEntityRelation;
67 }
68
69 /*** Access method that return the IFieldDescriptor that is the
70 * source/reference field that addresses another field. In RDB terms the
71 * reference field is or should be defined as a foreign key.
72 */
73 public IFieldDescriptor getReferenceField()
74 {
75 if(mReferenceField == null)
76 {
77 IEntityDescriptor entityDescriptor = mDataSourceDescriptor.getEntityDescriptorBySourceName(mReferenceEntitySourceName);
78 for (int i = 0; i < entityDescriptor.getFieldCount() && mReferenceField == null; i++)
79 if (entityDescriptor.getFieldDescriptor(i).getSourceName().compareTo(mReferenceFieldSourceName) == 0)
80 mReferenceField = entityDescriptor.getFieldDescriptor(i);
81 }
82 return mReferenceField;
83 }
84
85 /*** Access method that return the IFieldDescriptor that is the
86 * target field that are addressed by the reference field. In RDB terms the
87 * target field is usually a primary-key field.
88 */
89 public IFieldDescriptor getTargetField()
90 {
91 if(mTargetField == null)
92 {
93 IEntityDescriptor entityDescriptor = mDataSourceDescriptor.getEntityDescriptorBySourceName(mTargetEntitySourceName);
94 for (int i = 0; i < entityDescriptor.getFieldCount() && mTargetField == null; i++)
95 if (entityDescriptor.getFieldDescriptor(i).getSourceName().compareTo(mTargetFieldSourceName) == 0)
96 mTargetField = entityDescriptor.getFieldDescriptor(i);
97 }
98 return mTargetField;
99 }
100
101
102
103 /*** Mutation method with restricted access to avoid missuse.
104 */
105 void setEntityRelation(IEntityRelation relation)
106 {
107 mEntityRelation = relation;
108 }
109 }