001: /**
002: * Copyright (C) 2001-2005 France Telecom R&D
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the Free Software
016: * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
017: */package org.objectweb.speedo.metadata.jdo;
018:
019: import java.util.ArrayList;
020: import java.util.HashMap;
021:
022: import org.objectweb.speedo.api.SpeedoRuntimeException;
023: import org.objectweb.speedo.lib.Personality;
024: import org.objectweb.speedo.metadata.SpeedoCallback;
025: import org.objectweb.speedo.metadata.SpeedoClass;
026: import org.objectweb.speedo.metadata.SpeedoCollection;
027: import org.objectweb.speedo.metadata.SpeedoColumn;
028: import org.objectweb.speedo.metadata.SpeedoDefaults;
029: import org.objectweb.speedo.metadata.SpeedoDiscriminator;
030: import org.objectweb.speedo.metadata.SpeedoElement;
031: import org.objectweb.speedo.metadata.SpeedoField;
032: import org.objectweb.speedo.metadata.SpeedoIdentity;
033: import org.objectweb.speedo.metadata.SpeedoInheritance;
034: import org.objectweb.speedo.metadata.SpeedoInheritedField;
035: import org.objectweb.speedo.metadata.SpeedoJoin;
036: import org.objectweb.speedo.metadata.SpeedoJoinColumn;
037: import org.objectweb.speedo.metadata.SpeedoMap;
038: import org.objectweb.speedo.metadata.SpeedoNoFieldColumn;
039: import org.objectweb.speedo.metadata.SpeedoNullValue;
040: import org.objectweb.speedo.metadata.SpeedoPackage;
041: import org.objectweb.speedo.metadata.SpeedoTable;
042:
043: /**
044: * This class is in charge of the initialization of Speedo Meta Objects with
045: * the default value corresponding to the JDO personality.
046: *
047: * @author S.Chassande-Barrioz, P. Dechamboux
048: */
049: public class JDODefaults extends SpeedoDefaults {
050:
051: public void assignDefaults(Object se) throws SpeedoRuntimeException {
052: ((SpeedoElement) se).personality = Personality.JDO;
053: if (se instanceof SpeedoPackage) {
054: SpeedoPackage sp = (SpeedoPackage) se;
055: //sp.classes = ?;
056: //sp.jdoExtension = ?;
057: //sp.name = ?;
058: //sp.sequences = ?;
059: //sp.xmlDescriptor = ?;
060: } else if (se instanceof SpeedoClass) {
061: SpeedoClass sc = (SpeedoClass) se;
062: //sc.enhancementStatus = ?;
063: sc.fetchGroups = new HashMap();
064: sc.fields = new HashMap();
065: sc.identity = new SpeedoIdentity();
066: sc.versionField = null;
067: sc.inheritance = null;
068: sc.isAbstract = false;
069: sc.isDetachable = false;
070: sc.isInstanceCallbacks = false;
071: sc.isSerializable = false;
072: //sc.jdoExtension = ?;
073: //sc.joinToExtTables = ?;
074: //sc.jormclass = ?;
075: sc.callBacks = null;
076: //sc.mainTable = ?;
077: //sc.moPackage = ?;
078: //sc.name = ?;
079: sc.name2query = new HashMap();
080: //sc.noArgConstructorStatus = ?;
081: //sc.version = ?;
082: } else if (se instanceof SpeedoField) {
083: SpeedoField sf = (SpeedoField) se;
084: sf.name = null;
085: //sf.visibility = ?;
086: sf.propagate = SpeedoField.PROPAG_ALL;
087: sf.type = null;
088: sf.number = -1;
089: sf.persistenceStatus = SpeedoField.UNKNOWN;
090: sf.primaryKey = false;
091: sf.nullValue = SpeedoNullValue.NONE;
092: sf.defaultFetchGroup = true;
093: sf.depth = 0;
094: //sf.fetchGroup = ?;
095: sf.embedded = true;
096: //sf.valueStrategy = ?;
097: //sf.sequence = ?;
098: sf.relationType = SpeedoField.NO_BI_RELATION;
099: sf.reverseField = null;
100: sf.isCoherentReverseField = false;
101: sf.jdoTuple = null;
102: sf.moClass = null;
103: if (sf.columns != null) {
104: System.out.println("forget existing columns");
105: throw new RuntimeException("forget existing columns");
106: }
107: sf.columns = null;
108: sf.join = null;
109: sf.mappedByReversefield = false;
110: } else if (se instanceof SpeedoTable) {
111: SpeedoTable st = (SpeedoTable) se;
112: st.catalog = null;
113: st.name = null;
114: st.schema = null;
115: st.join = null;
116: } else if (se instanceof SpeedoJoin) {
117: SpeedoJoin sj = (SpeedoJoin) se;
118: sj.extTable = null;
119: sj.mainTable = null;
120: sj.columns = new ArrayList();
121: sj.deleteAction = SpeedoJoin.ACTION_NONE;
122: } else if (se instanceof SpeedoColumn) {
123: SpeedoColumn sc = (SpeedoColumn) se;
124: sc.allowNull = true;
125: sc.defaultValue = null;
126: sc.jdbcType = null;
127: sc.length = -1;
128: sc.name = null;
129: sc.targetColumn = null;
130: sc.targetField = null;
131: sc.scale = -1;
132: sc.sqlType = null;
133: sc.table = null;
134: sc.insertable = true;
135: sc.updatable = true;
136: } else if (se instanceof SpeedoIdentity) {
137: SpeedoIdentity si = (SpeedoIdentity) se;
138: si.objectidClass = null;
139: si.objectidJClass = null;
140: si.sequenceName = null;
141: si.strategy = SpeedoIdentity.DATASTORE_LONG;
142: si.columns = null;
143: } else if (se instanceof SpeedoJoinColumn) {
144: SpeedoJoinColumn sjc = (SpeedoJoinColumn) se;
145: sjc.column = null;
146: sjc.targetColumn = null;
147: sjc.targetField = null;
148: } else if (se instanceof SpeedoInheritance) {
149: SpeedoInheritance si = (SpeedoInheritance) se;
150: si.clazz = null;
151: si.discriminator = null;
152: si.discriminatorValues = null;
153: si.join = null;
154: si.remappedInheritedFields = null;
155: si.strategy = SpeedoInheritance.STRATEGY_UNKOWN;
156: si.super ClassName = null;
157: } else if (se instanceof SpeedoDiscriminator) {
158: SpeedoDiscriminator sd = (SpeedoDiscriminator) se;
159: sd.elements = new ArrayList();
160: sd.strategy = SpeedoDiscriminator.STRATEGY_NONE;
161: } else if (se instanceof SpeedoNoFieldColumn) {
162: SpeedoNoFieldColumn sc = (SpeedoNoFieldColumn) se;
163: // In EJB3, type may be one of {"Ljava.lang.String;", "", ""}.
164: //sc.type = ;
165: //sc.column = ;
166: } else if (se instanceof SpeedoInheritedField) {
167: SpeedoInheritedField shf = (SpeedoInheritedField) se;
168: shf.name = null;
169: shf.columns = null;
170: shf.inheritedField = null;
171: shf.join = null;
172: shf.moClass = null;
173: } else if (se instanceof SpeedoCollection) {
174: SpeedoCollection sc = (SpeedoCollection) se;
175: sc.elementType = null;
176: sc.embeddedElement = false;
177: sc.indexColumns = null;
178: sc.moField = null;
179: } else if (se instanceof SpeedoMap) {
180: SpeedoMap sm = (SpeedoMap) se;
181: sm.embeddedKey = false;
182: sm.embeddedValue = false;
183: sm.keyColumns = null;
184: sm.keyType = null;
185: sm.moField = null;
186: } else if (se instanceof SpeedoCallback) {
187: SpeedoCallback sc = (SpeedoCallback) se;
188: sc.listenerClassName = null;
189: sc.callbackName = null;
190: sc.methodByteCodeSignature = null;
191: sc.callbackType = -1;
192: } else {
193: /*throw new SpeedoException("Unknown element to initialize: " +
194: se.getClass().getName());*/
195: }
196: }
197: }
|