1 package org.hibernate.mapping; 3 4 import java.util.*; 5 import java.util.Map ; 6 7 import org.hibernate.AssertionFailure; 8 import org.hibernate.EntityMode; 9 import org.hibernate.util.JoinedIterator; 10 import org.hibernate.util.SingletonIterator; 11 12 16 public class Subclass extends PersistentClass { 17 18 private PersistentClass superclass; 19 private Class classPersisterClass; 20 private final int subclassId; 21 22 public Subclass(PersistentClass superclass) { 23 this.superclass = superclass; 24 this.subclassId = superclass.nextSubclassId(); 25 } 26 27 int nextSubclassId() { 28 return getSuperclass().nextSubclassId(); 29 } 30 31 public int getSubclassId() { 32 return subclassId; 33 } 34 35 public String getCacheConcurrencyStrategy() { 36 return getSuperclass().getCacheConcurrencyStrategy(); 37 } 38 39 public RootClass getRootClass() { 40 return getSuperclass().getRootClass(); 41 } 42 43 public PersistentClass getSuperclass() { 44 return superclass; 45 } 46 47 public Property getIdentifierProperty() { 48 return getSuperclass().getIdentifierProperty(); 49 } 50 public KeyValue getIdentifier() { 51 return getSuperclass().getIdentifier(); 52 } 53 public boolean hasIdentifierProperty() { 54 return getSuperclass().hasIdentifierProperty(); 55 } 56 public Value getDiscriminator() { 57 return getSuperclass().getDiscriminator(); 58 } 59 public boolean isMutable() { 60 return getSuperclass().isMutable(); 61 } 62 public boolean isInherited() { 63 return true; 64 } 65 public boolean isPolymorphic() { 66 return true; 67 } 68 69 public void addProperty(Property p) { 70 super.addProperty(p); 71 getSuperclass().addSubclassProperty(p); 72 } 73 public void addJoin(Join j) { 74 super.addJoin(j); 75 getSuperclass().addSubclassJoin(j); 76 } 77 78 public Iterator getPropertyClosureIterator() { 79 return new JoinedIterator( 80 getSuperclass().getPropertyClosureIterator(), 81 getPropertyIterator() 82 ); 83 } 84 public Iterator getTableClosureIterator() { 85 return new JoinedIterator( 86 getSuperclass().getTableClosureIterator(), 87 new SingletonIterator( getTable() ) 88 ); 89 } 90 public Iterator getKeyClosureIterator() { 91 return new JoinedIterator( 92 getSuperclass().getKeyClosureIterator(), 93 new SingletonIterator( getKey() ) 94 ); 95 } 96 protected void addSubclassProperty(Property p) { 97 super.addSubclassProperty(p); 98 getSuperclass().addSubclassProperty(p); 99 } 100 protected void addSubclassJoin(Join j) { 101 super.addSubclassJoin(j); 102 getSuperclass().addSubclassJoin(j); 103 } 104 105 protected void addSubclassTable(Table table) { 106 super.addSubclassTable(table); 107 getSuperclass().addSubclassTable(table); 108 } 109 110 public boolean isVersioned() { 111 return getSuperclass().isVersioned(); 112 } 113 public Property getVersion() { 114 return getSuperclass().getVersion(); 115 } 116 117 public boolean hasEmbeddedIdentifier() { 118 return getSuperclass().hasEmbeddedIdentifier(); 119 } 120 public Class getEntityPersisterClass() { 121 if (classPersisterClass==null) { 122 return getSuperclass().getEntityPersisterClass(); 123 } 124 else { 125 return classPersisterClass; 126 } 127 } 128 129 public Table getRootTable() { 130 return getSuperclass().getRootTable(); 131 } 132 133 public KeyValue getKey() { 134 return getSuperclass().getIdentifier(); 135 } 136 137 public boolean isExplicitPolymorphism() { 138 return getSuperclass().isExplicitPolymorphism(); 139 } 140 141 public void setSuperclass(PersistentClass superclass) { 142 this.superclass = superclass; 143 } 144 145 public String getWhere() { 146 return getSuperclass().getWhere(); 147 } 148 149 public boolean isJoinedSubclass() { 150 return getTable()!=getRootTable(); 151 } 152 153 public void createForeignKey() { 154 if ( !isJoinedSubclass() ) throw new AssertionFailure("not a joined-subclass"); 155 getKey().createForeignKeyOfEntity( getSuperclass().getEntityName() ); 156 } 157 158 public void setEntityPersisterClass(Class classPersisterClass) { 159 this.classPersisterClass = classPersisterClass; 160 } 161 162 public int getJoinClosureSpan() { 163 return getSuperclass().getJoinClosureSpan() + super.getJoinClosureSpan(); 164 } 165 166 public int getPropertyClosureSpan() { 167 return getSuperclass().getPropertyClosureSpan() + super.getPropertyClosureSpan(); 168 } 169 170 public Iterator getJoinClosureIterator() { 171 return new JoinedIterator( 172 getSuperclass().getJoinClosureIterator(), 173 super.getJoinClosureIterator() 174 ); 175 } 176 177 public boolean isClassOrSuperclassJoin(Join join) { 178 return super.isClassOrSuperclassJoin(join) || getSuperclass().isClassOrSuperclassJoin(join); 179 } 180 181 public boolean isClassOrSuperclassTable(Table table) { 182 return super.isClassOrSuperclassTable(table) || getSuperclass().isClassOrSuperclassTable(table); 183 } 184 185 public Table getTable() { 186 return getSuperclass().getTable(); 187 } 188 189 public boolean isForceDiscriminator() { 190 return getSuperclass().isForceDiscriminator(); 191 } 192 193 public boolean isDiscriminatorInsertable() { 194 return getSuperclass().isDiscriminatorInsertable(); 195 } 196 197 public java.util.Set getSynchronizedTables() { 198 HashSet result = new HashSet(); 199 result.addAll(synchronizedTables); 200 result.addAll( getSuperclass().getSynchronizedTables() ); 201 return result; 202 } 203 204 public Object accept(PersistentClassVisitor mv) { 205 return mv.accept(this); 206 } 207 208 public Map getFilterMap() { 209 return getSuperclass().getFilterMap(); 210 } 211 212 public boolean hasSubselectLoadableCollections() { 213 return super.hasSubselectLoadableCollections() || 214 getSuperclass().hasSubselectLoadableCollections(); 215 } 216 217 public String getTuplizerImplClassName(EntityMode mode) { 218 String impl = super.getTuplizerImplClassName( mode ); 219 if ( impl == null ) { 220 impl = getSuperclass().getTuplizerImplClassName( mode ); 221 } 222 return impl; 223 } 224 } 225 | Popular Tags |