1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.caleigo.core.meta;
19
20 import org.caleigo.core.*;
21 import org.caleigo.core.exception.*;
22
23
24 /*** MetaEntityRelation is the descriptor for MetaEntityRelationEntity objects.
25 *
26 * @author dennis
27 * @version 1.0.0
28 *//*
29 * WHEN WHO WHY & WHAT
30 * ------------------------------------------------------------------------------
31 * 030627 dennis Creation
32 */
33 public class MetaEntityRelation extends AbstractMetaEntityDescriptor
34 {
35
36
37 /*** The singleton instance for the MetaEntityRelation entity descriptor.
38 * Access it as MetaEntityRelation.instance anywhere in the code.
39 */
40 public final static MetaEntityRelation instance;
41
42 /*** The SourceName field (index=0) has the data type STRING(100).
43 * SourceName is a required identity field.
44 */
45 public final static IFieldDescriptor SourceName;
46
47 /*** The CodeName field (index=1) has the data type STRING(100).
48 * CodeName is a required field.
49 */
50 public final static IFieldDescriptor CodeName;
51
52 /*** The ForwardName field (index=2) has the data type STRING(50).
53 * ForwardName is a required field.
54 */
55 public final static IFieldDescriptor ForwardName;
56
57 /*** The ReververseName field (index=3) has the data type STRING(50).
58 * ReververseName is a required field.
59 */
60 public final static IFieldDescriptor ReverseName;
61
62 /*** The ReferenceEntity field (index=4) has the data type STRING(50).
63 * ReferenceEntity is a required field.
64 */
65 public final static IFieldDescriptor ReferenceEntity;
66
67 /*** The TargetEntity field (index=5) has the data type STRING(50).
68 * TargetEntity is a required field.
69 */
70 public final static IFieldDescriptor TargetEntity;
71
72
73
74 static
75 {
76 String className = MetaEntityRelation.class.getName();
77
78
79 IFieldDescriptor[] fields = new IFieldDescriptor[6];
80
81 fields[0] = SourceName = createFieldDescriptor("SourceName", "SourceName", "Source Name", className, DataType.STRING, 100, IFieldDescriptor.IDENTITY_FIELD | IFieldDescriptor.REQUIRED | IFieldDescriptor.INDEXED, null);
82 fields[1] = CodeName = createFieldDescriptor("CodeName", "CodeName", "Code Name", className, DataType.STRING, 100, IFieldDescriptor.REQUIRED | IFieldDescriptor.NAME_FIELD, null);
83 fields[2] = ForwardName = createFieldDescriptor("ForwardName", "ForwardName", "Forward Name", className, DataType.STRING, 50, IFieldDescriptor.REQUIRED | IFieldDescriptor.OVERVIEW_FIELD, null);
84 fields[3] = ReverseName = createFieldDescriptor("ReverseName", "ReverseName", "Reverse Name", className, DataType.STRING, 50, IFieldDescriptor.REQUIRED | IFieldDescriptor.OVERVIEW_FIELD, null);
85 fields[4] = ReferenceEntity = createFieldDescriptor("ReferenceEntity", "ReferenceEntity", "Referens Entity", className, DataType.STRING, 50, IFieldDescriptor.REQUIRED | IFieldDescriptor.OVERVIEW_FIELD, null);
86 fields[5] = TargetEntity = createFieldDescriptor("TargetEntity", "TargetEntity", "Target Entity", className, DataType.STRING, 50, IFieldDescriptor.REQUIRED | IFieldDescriptor.OVERVIEW_FIELD, null);
87
88
89 IEntityRelation[] relations = new IEntityRelation[3];
90 IFieldRelation[] fieldRelations;
91
92 fieldRelations = new IFieldRelation[1];
93 fieldRelations[0] = createFieldRelation("org.caleigo.core.meta.MetaFieldRelation", "EntityRelation", "org.caleigo.core.meta.MetaEntityRelation", "SourceName");
94 relations[0] = createEntityRelation(fieldRelations, "MetaFieldRelationMetaEntityRelation", "Entity Relation", "Field Relations");
95
96 fieldRelations = new IFieldRelation[1];
97 fieldRelations[0] = createFieldRelation("org.caleigo.core.meta.MetaEntityRelation", "ReferenceEntity", "org.caleigo.core.meta.MetaEntityDescriptor", "SourceName");
98 relations[1] = createEntityRelation(fieldRelations, "MetaEntityRelationMetaEntityDescripto", "Reference Descriptor", "Foreign Relations");
99
100 fieldRelations = new IFieldRelation[1];
101 fieldRelations[0] = createFieldRelation("org.caleigo.core.meta.MetaEntityRelation", "TargetEntity", "org.caleigo.core.meta.MetaEntityDescriptor", "SourceName");
102 relations[2] = createEntityRelation(fieldRelations, "MetaEntityRelationMetaEntityDescriptor1", "Target Descriptor", "Target Relations");
103
104
105 instance = new MetaEntityRelation(fields, relations);
106 }
107
108 /*** Creates a new MetaEntityRelationEntity with default values set
109 */
110 public static MetaEntityRelationEntity create()
111 {
112 return (MetaEntityRelationEntity)instance.createEntity();
113 }
114
115 /*** Creates a new MetaEntityRelationEntity, setting any field values
116 * avaivlable from the provided IDataProvider.
117 */
118 public static MetaEntityRelationEntity create(IDataProvider propertySource)
119 {
120 return (MetaEntityRelationEntity)instance.createEntity(propertySource);
121 }
122
123 /*** Loads a single MetaEntityRelationEntity instance identified by
124 * by the provided identity field values from the default data source.
125 * Returns null if no entity could be identified by field values.
126 */
127 public static MetaEntityRelationEntity load(String aSourceName)
128 {
129 return load(Qualifier.create(SourceName, new String(aSourceName)));
130 }
131
132 /*** Loads a single MetaEntityRelationEntity instance identified by
133 * by the provided identity-qualifier from the default data source.
134 * Returns null if no entity could be identified by the provided qualifier.
135 */
136 public static MetaEntityRelationEntity load(Qualifier identityQualifier)
137 {
138 if(instance.getDataSourceDescriptor().getDefaultDataSource()==null)
139 throw new DataServiceNotFoundException("No default data source has been set for: " + instance.getDataSourceDescriptor().getCodeName());
140 return (MetaEntityRelationEntity)instance.getDataSourceDescriptor().getDefaultDataSource().loadEntity(instance, identityQualifier);
141 }
142
143
144
145 /*** Private access to avoid missuse.
146 */
147 private MetaEntityRelation(IFieldDescriptor[] fields, IEntityRelation[] relations)
148 {
149 super("MetaEntityRelation", "MetaEntityRelation", "Entity Relation", "org.caleigo.core.meta.MetaEntityRelationEntity", "org.caleigo.core.meta.Meta", SLAVE_ENTITY, fields, relations);
150 this.setFlags(LISTABLE | CREATABLE | EDITABLE | DELETABLE);
151 this.setCacheTime(72000);
152 }
153
154
155
156 protected IEntityAction createDeleteAction()
157 {
158 return new DeleteEntityAction(this)
159 {
160 public void prepareTransaction(IDataBundle data, IDataTransaction transaction)
161 {
162
163 ISelection slaveSelection = MetaFieldRelation.instance.loadSelection(Qualifier.create(MetaFieldRelation.EntityRelation, ((MetaEntityRelationEntity)data.getData(0)).getSourceName()));
164 for(int j=0; slaveSelection!=null && j<slaveSelection.size(); j++)
165 transaction.addDelete(slaveSelection.getEntity(j));
166
167
168 super.prepareTransaction(data, transaction);
169 }
170 };
171 }
172
173 }