001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.amber.gen;
031:
032: import com.caucho.amber.type.*;
033: import com.caucho.java.JavaWriter;
034: import com.caucho.util.L10N;
035:
036: import java.io.IOException;
037: import java.util.HashSet;
038:
039: /**
040: * Generates the Java code for the wrapped object.
041: */
042: public class EntityComponent extends AmberMappedComponent {
043: private static final L10N L = new L10N(EntityComponent.class);
044:
045: public EntityComponent() {
046: }
047:
048: /**
049: * Gets the entity type.
050: */
051: public EntityType getEntityType() {
052: return (EntityType) _relatedType;
053: }
054:
055: /**
056: * Sets the bean info for the generator
057: */
058: public void setEntityType(EntityType entityType) {
059: setRelatedType(entityType);
060: }
061:
062: /**
063: * Starts generation of the Java code
064: */
065: public void generate(JavaWriter out) throws IOException {
066: try {
067: RelatedType parentType = getEntityType().getParentType();
068:
069: // jpa/0gg0
070: boolean isEntityParent = (parentType != null)
071: && (parentType instanceof EntityType)
072: && !parentType.getBeanClass().isAbstract();
073:
074: generateHeader(out, isEntityParent);
075:
076: generateIncrementVersion(out);
077:
078: generateInit(out, isEntityParent);
079:
080: HashSet<Object> completedSet = new HashSet<Object>();
081:
082: generatePrologue(out, completedSet);
083:
084: generateGetCacheEntity(out);
085:
086: generateGetEntityType(out);
087:
088: if (!isEntityParent)
089: generateGetEntityState(out);
090:
091: generateIsDirty(out);
092:
093: generateMatch(out);
094:
095: generateFields(out);
096:
097: generateMethods(out);
098:
099: generateDetach(out, isEntityParent);
100:
101: generateLoad(out, isEntityParent);
102:
103: int min = 0;
104: if (isEntityParent)
105: min = getEntityType().getParentType()
106: .getLoadGroupIndex() + 1;
107: int max = getEntityType().getLoadGroupIndex();
108:
109: for (int i = min; i <= max; i++)
110: generateLoadGroup(out, i);
111:
112: generateResultSetLoad(out, isEntityParent);
113:
114: generateSetQuery(out, isEntityParent);
115:
116: // generateLoadFromObject();
117:
118: // generateCopy();
119:
120: generateCopy(out);
121:
122: generateSetLoadMask(out);
123:
124: generateDumpRelationships(out);
125:
126: generateMakePersistent(out);
127:
128: generateCascadePersist(out);
129:
130: generateCascadeRemove(out);
131:
132: generateCreate(out);
133:
134: generateDelete(out);
135:
136: generateDeleteForeign(out);
137:
138: generateFlush(out);
139:
140: generateAfterCommit(out, isEntityParent);
141:
142: generateUpdateCacheItem(out, isEntityParent);
143:
144: generateAfterRollback(out);
145:
146: generateLoadKey(out);
147:
148: generateHome(out);
149:
150: generateInternals(out);
151:
152: // printDependList(out, _dependencies);
153: } catch (IOException e) {
154: throw e;
155: }
156: }
157: }
|