001: /**
002: * Objective Database Abstraction Layer (ODAL)
003: * Copyright (c) 2004, The ODAL Development Group
004: * All rights reserved.
005: * For definition of the ODAL Development Group please refer to LICENCE.txt file
006: *
007: * Distributable under LGPL license.
008: * See terms of license at gnu.org.
009: */package com.completex.objective.components.persistency.meta;
010:
011: import com.completex.objective.components.persistency.Link;
012: import com.completex.objective.components.persistency.Mappable;
013: import com.completex.objective.util.PropertyMap;
014:
015: import java.util.LinkedHashMap;
016: import java.util.Map;
017:
018: /**
019: * @author Gennady Krizhevsky
020: */
021: public class MetaComplexChild extends MetaChild implements Mappable {
022:
023: private String name;
024: private Link.RelationshipType relationshipType;
025: private boolean cascadeInsert;
026: private boolean cascadeUpdate;
027: private boolean cascadeDelete;
028: private MetaMultipleResultFactory multipleResultFactory;
029: private String factoryMethod;
030: private boolean lazy;
031: private String inlineMode;
032:
033: //
034: // calculated:
035: //
036: private boolean insertBeforeParent;
037: //
038: // Assigned:
039: //
040: private int index;
041: private String className;
042: //
043: // Tags:
044: //
045: public static final String TAG_RELATIONSHIP_TYPE = "relationshipType";
046: public static final String TAG_REF = "ref";
047: public static final String TAG_CASCADE_INSERT = "cascadeInsert";
048: public static final String TAG_CASCADE_UPDATE = "cascadeUpdate";
049: public static final String TAG_CASCADE_DELETE = "cascadeDelete";
050: public static final String TAG_MULTIPLE_RESULT_FACTORY = "multipleResultFactory";
051: public static final String TAG_FACTORY_METHOD = "factoryMethod";
052: public static final String TAG_LAZY = "lazy";
053: public static final String TAG_NAME = "name";
054: public static final String TAG_INLINE_MODE = "inlineMode";
055:
056: public MetaComplexChild() {
057: }
058:
059: public MetaComplexChild(Map map) {
060: fromMap(map);
061: }
062:
063: public MetaComplexChild(String name, Map map) {
064: fromMap(map);
065: this .name = name;
066: }
067:
068: public Map toMap() {
069: LinkedHashMap map = new LinkedHashMap();
070: map.put(TAG_RELATIONSHIP_TYPE, relationshipType);
071: map.put(TAG_REF, ref.toMap());
072: map.put(TAG_CASCADE_INSERT, Boolean.valueOf(cascadeInsert));
073: map.put(TAG_CASCADE_UPDATE, Boolean.valueOf(cascadeUpdate));
074: map.put(TAG_CASCADE_DELETE, Boolean.valueOf(cascadeDelete));
075: map.put(TAG_FACTORY_METHOD, factoryMethod);
076: map.put(TAG_LAZY, Boolean.valueOf(lazy));
077: map.put(TAG_NAME, name);
078: if (inlineMode != null) {
079: map.put(TAG_INLINE_MODE, inlineMode);
080: }
081: if (multipleResultFactory != null) {
082: map.put(TAG_MULTIPLE_RESULT_FACTORY, multipleResultFactory
083: .toMap());
084: }
085: return map;
086: }
087:
088: public void fromMap(Map map) {
089: PropertyMap propertyMap = PropertyMap.toPropertyMap(map);
090:
091: String relName = propertyMap.getProperty(TAG_RELATIONSHIP_TYPE,
092: true);
093: relationshipType = Link.RelationshipType.name2type(relName);
094: Map refMap = propertyMap.getPropertyMap(TAG_REF, true);
095: ref = new MetaRef(refMap);
096: cascadeInsert = propertyMap.getBoolean(TAG_CASCADE_INSERT);
097: cascadeUpdate = propertyMap.getBoolean(TAG_CASCADE_UPDATE);
098: cascadeDelete = propertyMap.getBoolean(TAG_CASCADE_DELETE);
099: Map multipleResultFactoryMap = propertyMap
100: .getPropertyMap(TAG_MULTIPLE_RESULT_FACTORY);
101: if (multipleResultFactoryMap != null) {
102: multipleResultFactory = new MetaMultipleResultFactory(
103: multipleResultFactoryMap);
104: }
105: factoryMethod = propertyMap.getProperty(TAG_FACTORY_METHOD);
106: lazy = propertyMap.getBoolean(TAG_LAZY);
107: name = propertyMap.getProperty(TAG_NAME);
108: inlineMode = propertyMap.getProperty(TAG_INLINE_MODE);
109:
110: //
111: // calculate insertBeforeParent:
112: //
113: if (relationshipType == Link.MANY_TO_ONE) {
114: insertBeforeParent = true;
115: }
116: }
117:
118: public boolean isCascadeInsert() {
119: return cascadeInsert;
120: }
121:
122: public void setCascadeInsert(boolean cascadeInsert) {
123: this .cascadeInsert = cascadeInsert;
124: }
125:
126: public boolean isCascadeUpdate() {
127: return cascadeUpdate;
128: }
129:
130: public void setCascadeUpdate(boolean cascadeUpdate) {
131: this .cascadeUpdate = cascadeUpdate;
132: }
133:
134: public boolean isCascadeDelete() {
135: return cascadeDelete;
136: }
137:
138: public void setCascadeDelete(boolean cascadeDelete) {
139: this .cascadeDelete = cascadeDelete;
140: }
141:
142: public MetaMultipleResultFactory getMultipleResultFactory() {
143: return multipleResultFactory;
144: }
145:
146: public void setMultipleResultFactory(
147: MetaMultipleResultFactory multipleResultFactory) {
148: this .multipleResultFactory = multipleResultFactory;
149: }
150:
151: public String getFactoryMethod() {
152: return factoryMethod;
153: }
154:
155: public void setFactoryMethod(String factoryMethod) {
156: this .factoryMethod = factoryMethod;
157: }
158:
159: public boolean isLazy() {
160: return lazy;
161: }
162:
163: public void setLazy(boolean lazy) {
164: this .lazy = lazy;
165: }
166:
167: public boolean isInsertBeforeParent() {
168: return insertBeforeParent;
169: }
170:
171: public void setInsertBeforeParent(boolean insertBeforeParent) {
172: this .insertBeforeParent = insertBeforeParent;
173: }
174:
175: public int getIndex() {
176: return index;
177: }
178:
179: public void setIndex(int index) {
180: this .index = index;
181: }
182:
183: public String getClassName() {
184: return className;
185: }
186:
187: public void setClassName(String className) {
188: this .className = className;
189: }
190:
191: public String getName() {
192: return name;
193: }
194:
195: public void setName(String name) {
196: this .name = name;
197: }
198:
199: public Link.RelationshipType getRelationshipType() {
200: return relationshipType;
201: }
202:
203: public void setRelationshipType(
204: Link.RelationshipType relationshipType) {
205: this .relationshipType = relationshipType;
206: }
207:
208: public String getInlineMode() {
209: return inlineMode;
210: }
211:
212: public void setInlineMode(String inlineMode) {
213: this .inlineMode = inlineMode;
214: }
215:
216: public String toString() {
217: return toMap().toString();
218: }
219: }
|