| 1 |
|
|
| 2 |
|
|
| 3 |
|
|
| 4 |
|
|
| 5 |
|
|
| 6 |
|
|
| 7 |
|
|
| 8 |
|
|
| 9 |
|
|
| 10 |
|
|
| 11 |
|
|
| 12 |
|
package org.trails.hibernate; |
| 13 |
|
|
| 14 |
|
import java.beans.IntrospectionException; |
| 15 |
|
import java.beans.Introspector; |
| 16 |
|
import java.beans.PropertyDescriptor; |
| 17 |
|
import java.lang.reflect.Field; |
| 18 |
|
import java.lang.reflect.Method; |
| 19 |
|
import java.util.ArrayList; |
| 20 |
|
import java.util.Collection; |
| 21 |
|
import java.util.HashMap; |
| 22 |
|
import java.util.Iterator; |
| 23 |
|
import java.util.List; |
| 24 |
|
|
| 25 |
|
import ognl.Ognl; |
| 26 |
|
import ognl.OgnlException; |
| 27 |
|
|
| 28 |
|
import org.apache.commons.logging.Log; |
| 29 |
|
import org.apache.commons.logging.LogFactory; |
| 30 |
|
import org.hibernate.HibernateException; |
| 31 |
|
import org.hibernate.SessionFactory; |
| 32 |
|
import org.hibernate.cfg.Configuration; |
| 33 |
|
import org.hibernate.mapping.Column; |
| 34 |
|
import org.hibernate.mapping.Component; |
| 35 |
|
import org.hibernate.mapping.PersistentClass; |
| 36 |
|
import org.hibernate.mapping.Property; |
| 37 |
|
import org.hibernate.mapping.Selectable; |
| 38 |
|
import org.hibernate.mapping.SimpleValue; |
| 39 |
|
import org.hibernate.metadata.ClassMetadata; |
| 40 |
|
import org.hibernate.metadata.CollectionMetadata; |
| 41 |
|
import org.hibernate.type.ComponentType; |
| 42 |
|
import org.hibernate.type.Type; |
| 43 |
|
import org.springframework.orm.hibernate3.LocalSessionFactoryBean; |
| 44 |
|
import org.trails.TrailsRuntimeException; |
| 45 |
|
import org.trails.descriptor.CollectionDescriptor; |
| 46 |
|
import org.trails.descriptor.DescriptorDecorator; |
| 47 |
|
import org.trails.descriptor.DescriptorFactory; |
| 48 |
|
import org.trails.descriptor.EmbeddedDescriptor; |
| 49 |
|
import org.trails.descriptor.EnumReferenceDescriptor; |
| 50 |
|
import org.trails.descriptor.IClassDescriptor; |
| 51 |
|
import org.trails.descriptor.IPropertyDescriptor; |
| 52 |
|
import org.trails.descriptor.IdentifierDescriptor; |
| 53 |
|
import org.trails.descriptor.ObjectReferenceDescriptor; |
| 54 |
|
import org.trails.descriptor.OwningObjectReferenceDescriptor; |
| 55 |
|
import org.trails.descriptor.TrailsPropertyDescriptor; |
| 56 |
|
|
| 57 |
|
|
| 58 |
|
|
| 59 |
|
|
| 60 |
|
|
| 61 |
|
|
| 62 |
|
|
| 63 |
|
|
| 64 |
|
|
| 65 |
|
|
| 66 |
|
|
| 67 |
|
|
| 68 |
|
|
| 69 |
|
|
| 70 |
|
|
| 71 |
|
|
| 72 |
|
|
| 73 |
|
|
| 74 |
|
|
| 75 |
|
|
| 76 |
|
|
| 77 |
25 |
public class HibernateDescriptorDecorator implements DescriptorDecorator |
| 78 |
|
{ |
| 79 |
1 |
protected static final Log LOG = LogFactory.getLog(HibernateDescriptorDecorator.class); |
| 80 |
|
|
| 81 |
|
private LocalSessionFactoryBean localSessionFactoryBean; |
| 82 |
|
|
| 83 |
|
private List types; |
| 84 |
|
|
| 85 |
|
private DescriptorFactory descriptorFactory; |
| 86 |
|
|
| 87 |
12 |
private HashMap<Class, IClassDescriptor> descriptors = new HashMap<Class, IClassDescriptor>(); |
| 88 |
|
|
| 89 |
12 |
private int largeColumnLength = 100; |
| 90 |
|
|
| 91 |
|
public IClassDescriptor decorate(IClassDescriptor descriptor) |
| 92 |
|
{ |
| 93 |
145 |
ArrayList<IPropertyDescriptor> decoratedPropertyDescriptors = new ArrayList<IPropertyDescriptor>(); |
| 94 |
923 |
for (IPropertyDescriptor propertyDescriptor : descriptor.getPropertyDescriptors()) |
| 95 |
|
{ |
| 96 |
633 |
Class type = descriptor.getType(); |
| 97 |
|
|
| 98 |
|
IPropertyDescriptor descriptorReference; |
| 99 |
|
try |
| 100 |
|
{ |
| 101 |
633 |
ClassMetadata classMetaData = findMetadata(type); |
| 102 |
633 |
if (propertyDescriptor.getName().equals(getIdentifierProperty(type))) |
| 103 |
|
{ |
| 104 |
143 |
descriptorReference = createIdentifierDescriptor(type, propertyDescriptor); |
| 105 |
490 |
} else if (notAHibernateProperty(classMetaData, propertyDescriptor)) |
| 106 |
|
{ |
| 107 |
|
|
| 108 |
|
|
| 109 |
|
|
| 110 |
25 |
propertyDescriptor.setSearchable(false); |
| 111 |
25 |
descriptorReference = propertyDescriptor; |
| 112 |
|
} else |
| 113 |
|
{ |
| 114 |
465 |
Property mappingProperty = getMapping(type).getProperty(propertyDescriptor.getName()); |
| 115 |
930 |
descriptorReference = decoratePropertyDescriptor(type, mappingProperty, propertyDescriptor, |
| 116 |
465 |
descriptor); |
| 117 |
|
} |
| 118 |
|
|
| 119 |
0 |
} catch (HibernateException e) |
| 120 |
|
{ |
| 121 |
0 |
throw new TrailsRuntimeException(e); |
| 122 |
|
} |
| 123 |
633 |
decoratedPropertyDescriptors.add(descriptorReference); |
| 124 |
|
} |
| 125 |
145 |
descriptor.setPropertyDescriptors(decoratedPropertyDescriptors); |
| 126 |
145 |
return descriptor; |
| 127 |
|
} |
| 128 |
|
|
| 129 |
|
protected IPropertyDescriptor decoratePropertyDescriptor(Class type, Property mappingProperty, |
| 130 |
|
IPropertyDescriptor descriptor, IClassDescriptor parentClassDescriptor) |
| 131 |
|
{ |
| 132 |
491 |
if (isFormula(mappingProperty)) |
| 133 |
|
{ |
| 134 |
22 |
descriptor.setReadOnly(true); |
| 135 |
22 |
return descriptor; |
| 136 |
|
} |
| 137 |
469 |
descriptor.setLength(findColumnLength(mappingProperty)); |
| 138 |
469 |
descriptor.setLarge(isLarge(mappingProperty)); |
| 139 |
469 |
if (!mappingProperty.isOptional()) |
| 140 |
|
{ |
| 141 |
34 |
descriptor.setRequired(true); |
| 142 |
|
} |
| 143 |
|
|
| 144 |
469 |
if (!mappingProperty.isInsertable() && !mappingProperty.isUpdateable()) |
| 145 |
|
{ |
| 146 |
0 |
descriptor.setReadOnly(true); |
| 147 |
|
} |
| 148 |
|
|
| 149 |
469 |
IPropertyDescriptor descriptorReference = descriptor; |
| 150 |
469 |
Type hibernateType = mappingProperty.getType(); |
| 151 |
469 |
if (mappingProperty.getType() instanceof ComponentType) |
| 152 |
|
{ |
| 153 |
26 |
EmbeddedDescriptor embeddedDescriptor = buildEmbeddedDescriptor(type, mappingProperty, descriptor, |
| 154 |
13 |
parentClassDescriptor); |
| 155 |
13 |
descriptorReference = embeddedDescriptor; |
| 156 |
456 |
} else if (Collection.class.isAssignableFrom(descriptor.getPropertyType())) |
| 157 |
|
{ |
| 158 |
81 |
descriptorReference = decorateCollectionDescriptor(type, descriptor, parentClassDescriptor); |
| 159 |
375 |
} else if (hibernateType.isAssociationType()) |
| 160 |
|
{ |
| 161 |
92 |
descriptorReference = decorateAssociationDescriptor(type, mappingProperty, descriptor, |
| 162 |
46 |
parentClassDescriptor); |
| 163 |
329 |
} else if (hibernateType.getReturnedClass().isEnum()) |
| 164 |
|
{ |
| 165 |
0 |
descriptor.addExtension(EnumReferenceDescriptor.class.getName(), new EnumReferenceDescriptor(hibernateType |
| 166 |
0 |
.getReturnedClass())); |
| 167 |
|
} |
| 168 |
|
|
| 169 |
469 |
return descriptorReference; |
| 170 |
|
} |
| 171 |
|
|
| 172 |
|
private EmbeddedDescriptor buildEmbeddedDescriptor(Class type, Property mappingProperty, |
| 173 |
|
IPropertyDescriptor descriptor, IClassDescriptor parentClassDescriptor) |
| 174 |
|
{ |
| 175 |
13 |
Component componentMapping = (Component) mappingProperty.getValue(); |
| 176 |
13 |
IClassDescriptor baseDescriptor = getDescriptorFactory().buildClassDescriptor(descriptor.getPropertyType()); |
| 177 |
|
|
| 178 |
13 |
EmbeddedDescriptor embeddedDescriptor = new EmbeddedDescriptor(type, baseDescriptor); |
| 179 |
|
|
| 180 |
13 |
embeddedDescriptor.copyFrom(descriptor); |
| 181 |
13 |
ArrayList<IPropertyDescriptor> decoratedProperties = new ArrayList<IPropertyDescriptor>(); |
| 182 |
|
|
| 183 |
65 |
for (IPropertyDescriptor propertyDescriptor : embeddedDescriptor.getPropertyDescriptors()) |
| 184 |
|
{ |
| 185 |
39 |
if (notAHibernateProperty(componentMapping, propertyDescriptor)) |
| 186 |
|
{ |
| 187 |
13 |
decoratedProperties.add(propertyDescriptor); |
| 188 |
|
} else |
| 189 |
|
{ |
| 190 |
26 |
Property property = componentMapping.getProperty(propertyDescriptor.getName()); |
| 191 |
52 |
IPropertyDescriptor iPropertyDescriptor = decoratePropertyDescriptor(embeddedDescriptor.getBeanType(), |
| 192 |
26 |
property, propertyDescriptor, parentClassDescriptor); |
| 193 |
26 |
decoratedProperties.add(iPropertyDescriptor); |
| 194 |
|
} |
| 195 |
|
} |
| 196 |
13 |
embeddedDescriptor.setPropertyDescriptors(decoratedProperties); |
| 197 |
13 |
return embeddedDescriptor; |
| 198 |
|
} |
| 199 |
|
|
| 200 |
|
|
| 201 |
|
|
| 202 |
|
|
| 203 |
|
|
| 204 |
|
|
| 205 |
|
|
| 206 |
|
|
| 207 |
|
|
| 208 |
|
protected List sortPropertyDescriptors(Class type, List propertyDescriptors) |
| 209 |
|
{ |
| 210 |
0 |
ArrayList sortedPropertyDescriptors = new ArrayList(); |
| 211 |
|
|
| 212 |
|
try |
| 213 |
|
{ |
| 214 |
0 |
sortedPropertyDescriptors.add(Ognl.getValue("#this.{? identifier == true}[0]", propertyDescriptors)); |
| 215 |
0 |
for (Iterator iter = getMapping(type).getPropertyIterator(); iter.hasNext();) |
| 216 |
|
{ |
| 217 |
0 |
Property mapping = (Property) iter.next(); |
| 218 |
0 |
sortedPropertyDescriptors.addAll((List) Ognl.getValue("#this.{ ? name == \"" + mapping.getName() |
| 219 |
0 |
+ "\"}", propertyDescriptors)); |
| 220 |
|
} |
| 221 |
0 |
} catch (Exception ex) |
| 222 |
|
{ |
| 223 |
0 |
throw new TrailsRuntimeException(ex); |
| 224 |
|
} |
| 225 |
0 |
return sortedPropertyDescriptors; |
| 226 |
|
} |
| 227 |
|
|
| 228 |
|
|
| 229 |
|
|
| 230 |
|
|
| 231 |
|
|
| 232 |
|
|
| 233 |
|
|
| 234 |
|
|
| 235 |
|
protected ClassMetadata findMetadata(Class type) throws MetadataNotFoundException |
| 236 |
|
{ |
| 237 |
633 |
ClassMetadata metaData = getSessionFactory().getClassMetadata(type); |
| 238 |
633 |
if (metaData != null) |
| 239 |
|
{ |
| 240 |
633 |
return metaData; |
| 241 |
|
} |
| 242 |
0 |
if (!type.equals(Object.class)) |
| 243 |
|
{ |
| 244 |
0 |
return findMetadata(type.getSuperclass()); |
| 245 |
|
} else |
| 246 |
|
{ |
| 247 |
0 |
throw new MetadataNotFoundException("Failed to find metadata."); |
| 248 |
|
} |
| 249 |
|
} |
| 250 |
|
|
| 251 |
|
private boolean isFormula(Property mappingProperty) |
| 252 |
|
{ |
| 253 |
1383 |
for (Iterator iter = mappingProperty.getColumnIterator(); iter.hasNext();) |
| 254 |
|
{ |
| 255 |
423 |
Selectable selectable = (Selectable) iter.next(); |
| 256 |
423 |
if (selectable.isFormula()) |
| 257 |
|
{ |
| 258 |
22 |
return true; |
| 259 |
|
} |
| 260 |
|
} |
| 261 |
469 |
return false; |
| 262 |
|
} |
| 263 |
|
|
| 264 |
|
|
| 265 |
|
|
| 266 |
|
|
| 267 |
|
|
| 268 |
|
|
| 269 |
|
|
| 270 |
|
|
| 271 |
|
protected boolean notAHibernateProperty(Component componentMapping, IPropertyDescriptor propertyDescriptor) |
| 272 |
|
{ |
| 273 |
117 |
for (Iterator iter = componentMapping.getPropertyIterator(); iter.hasNext();) |
| 274 |
|
{ |
| 275 |
65 |
Property property = (Property) iter.next(); |
| 276 |
65 |
if (property.getName().equals(propertyDescriptor.getName())) |
| 277 |
|
{ |
| 278 |
26 |
return false; |
| 279 |
|
} |
| 280 |
|
} |
| 281 |
13 |
return true; |
| 282 |
|
} |
| 283 |
|
|
| 284 |
|
private boolean isLarge(Property mappingProperty) |
| 285 |
|
{ |
| 286 |
|
|
| 287 |
|
|
| 288 |
903 |
return findColumnLength(mappingProperty) != Column.DEFAULT_LENGTH |
| 289 |
128 |
&& findColumnLength(mappingProperty) > getLargeColumnLength(); |
| 290 |
|
} |
| 291 |
|
|
| 292 |
|
private int findColumnLength(Property mappingProperty) |
| 293 |
|
{ |
| 294 |
1066 |
int length = 0; |
| 295 |
2994 |
for (Iterator iter = mappingProperty.getColumnIterator(); iter.hasNext();) |
| 296 |
|
{ |
| 297 |
862 |
Column column = (Column) iter.next(); |
| 298 |
862 |
length += column.getLength(); |
| 299 |
|
} |
| 300 |
1066 |
return length; |
| 301 |
|
} |
| 302 |
|
|
| 303 |
|
|
| 304 |
|
|
| 305 |
|
|
| 306 |
|
|
| 307 |
|
|
| 308 |
|
protected boolean notAHibernateProperty(ClassMetadata classMetaData, IPropertyDescriptor descriptor) |
| 309 |
|
{ |
| 310 |
|
try |
| 311 |
|
{ |
| 312 |
980 |
return (Boolean) Ognl.getValue("propertyNames.{ ? #this == \"" + descriptor.getName() + "\"}.size() == 0", |
| 313 |
490 |
classMetaData); |
| 314 |
0 |
} catch (OgnlException oe) |
| 315 |
|
{ |
| 316 |
0 |
throw new TrailsRuntimeException(oe); |
| 317 |
|
} |
| 318 |
|
} |
| 319 |
|
|
| 320 |
|
|
| 321 |
|
|
| 322 |
|
|
| 323 |
|
|
| 324 |
|
|
| 325 |
|
|
| 326 |
|
private IdentifierDescriptor createIdentifierDescriptor(Class type, IPropertyDescriptor descriptor) |
| 327 |
|
{ |
| 328 |
143 |
IdentifierDescriptor identifierDescriptor = new IdentifierDescriptor(type, descriptor); |
| 329 |
143 |
PersistentClass mapping = getMapping(type); |
| 330 |
|
|
| 331 |
143 |
if (((SimpleValue) mapping.getIdentifier()).getIdentifierGeneratorStrategy().equals("assigned")) |
| 332 |
|
{ |
| 333 |
22 |
identifierDescriptor.setGenerated(false); |
| 334 |
|
} |
| 335 |
|
|
| 336 |
143 |
return identifierDescriptor; |
| 337 |
|
} |
| 338 |
|
|
| 339 |
|
|
| 340 |
|
|
| 341 |
|
|
| 342 |
|
|
| 343 |
|
protected PersistentClass getMapping(Class type) |
| 344 |
|
{ |
| 345 |
608 |
Configuration cfg = getLocalSessionFactoryBean().getConfiguration(); |
| 346 |
|
|
| 347 |
608 |
return cfg.getClassMapping(type.getName()); |
| 348 |
|
} |
| 349 |
|
|
| 350 |
|
|
| 351 |
|
|
| 352 |
|
|
| 353 |
|
|
| 354 |
|
private CollectionDescriptor decorateCollectionDescriptor(Class type, IPropertyDescriptor descriptor, |
| 355 |
|
IClassDescriptor parentClassDescriptor) |
| 356 |
|
{ |
| 357 |
|
try |
| 358 |
|
{ |
| 359 |
81 |
CollectionDescriptor collectionDescriptor = new CollectionDescriptor(type, descriptor); |
| 360 |
81 |
org.hibernate.mapping.Collection collectionMapping = findCollectionMapping(type, descriptor.getName()); |
| 361 |
|
|
| 362 |
|
|
| 363 |
81 |
collectionDescriptor.setChildRelationship(collectionMapping.hasOrphanDelete()); |
| 364 |
162 |
CollectionMetadata collectionMetaData = getSessionFactory().getCollectionMetadata( |
| 365 |
81 |
collectionMapping.getRole()); |
| 366 |
|
|
| 367 |
81 |
collectionDescriptor.setElementType(collectionMetaData.getElementType().getReturnedClass()); |
| 368 |
|
|
| 369 |
81 |
collectionDescriptor.setOneToMany(collectionMapping.isOneToMany()); |
| 370 |
|
|
| 371 |
81 |
decorateOneToManyCollection(parentClassDescriptor, collectionDescriptor, collectionMapping); |
| 372 |
|
|
| 373 |
81 |
return collectionDescriptor; |
| 374 |
|
|
| 375 |
0 |
} catch (HibernateException e) |
| 376 |
|
{ |
| 377 |
0 |
throw new TrailsRuntimeException(e); |
| 378 |
|
} |
| 379 |
|
} |
| 380 |
|
|
| 381 |
|
public IPropertyDescriptor decorateAssociationDescriptor(Class type, Property mappingProperty, |
| 382 |
|
IPropertyDescriptor descriptor, IClassDescriptor parentClassDescriptor) |
| 383 |
|
{ |
| 384 |
46 |
Type hibernateType = mappingProperty.getType(); |
| 385 |
46 |
Class parentClassType = parentClassDescriptor.getType(); |
| 386 |
92 |
ObjectReferenceDescriptor descriptorReference = new ObjectReferenceDescriptor(type, descriptor, hibernateType |
| 387 |
46 |
.getReturnedClass()); |
| 388 |
|
|
| 389 |
|
try |
| 390 |
|
{ |
| 391 |
46 |
Field propertyField = parentClassType.getDeclaredField(descriptor.getName()); |
| 392 |
46 |
PropertyDescriptor beanPropDescriptor = (PropertyDescriptor) Ognl.getValue( |
| 393 |
46 |
"propertyDescriptors.{? name == '" + descriptor.getName() + "'}[0]", Introspector |
| 394 |
46 |
.getBeanInfo(parentClassType)); |
| 395 |
46 |
Method readMethod = beanPropDescriptor.getReadMethod(); |
| 396 |
|
|
| 397 |
|
|
| 398 |
|
|
| 399 |
46 |
String inverseProperty = ""; |
| 400 |
46 |
if (readMethod.isAnnotationPresent(javax.persistence.OneToOne.class)) |
| 401 |
|
{ |
| 402 |
0 |
inverseProperty = readMethod.getAnnotation(javax.persistence.OneToOne.class).mappedBy(); |
| 403 |
46 |
} else if (propertyField.isAnnotationPresent(javax.persistence.OneToOne.class)) |
| 404 |
|
{ |
| 405 |
0 |
inverseProperty = propertyField.getAnnotation(javax.persistence.OneToOne.class).mappedBy(); |
| 406 |
|
} else |
| 407 |
|
{ |
| 408 |
|
|
| 409 |
|
|
| 410 |
46 |
return descriptorReference; |
| 411 |
|
} |
| 412 |
|
|
| 413 |
0 |
if ("".equals(inverseProperty)) |
| 414 |
|
{ |
| 415 |
|
|
| 416 |
|
|
| 417 |
|
|
| 418 |
0 |
Class returnType = readMethod.getReturnType(); |
| 419 |
0 |
for (int i = 0; i < returnType.getDeclaredMethods().length; i++) |
| 420 |
|
{ |
| 421 |
0 |
if (returnType.getDeclaredMethods()[i].getReturnType().equals(propertyField.getDeclaringClass())) |
| 422 |
|
{ |
| 423 |
0 |
Method theProperty = returnType.getDeclaredMethods()[i]; |
| 424 |
|
|
| 425 |
0 |
inverseProperty = theProperty.getName().substring(3).toLowerCase(); |
| 426 |
0 |
break; |
| 427 |
|
} |
| 428 |
|
} |
| 429 |
|
} |
| 430 |
|
|
| 431 |
0 |
} catch (SecurityException e) |
| 432 |
|
{ |
| 433 |
0 |
LOG.error(e.getMessage()); |
| 434 |
0 |
} catch (NoSuchFieldException e) |
| 435 |
|
{ |
| 436 |
0 |
LOG.error(e.getMessage()); |
| 437 |
0 |
} catch (OgnlException e) |
| 438 |
|
{ |
| 439 |
0 |
LOG.error(e.getMessage()); |
| 440 |
0 |
} catch (IntrospectionException e) |
| 441 |
|
{ |
| 442 |
0 |
LOG.error(e.getMessage()); |
| 443 |
|
} |
| 444 |
0 |
return descriptorReference; |
| 445 |
|
} |
| 446 |
|
|
| 447 |
|
|
| 448 |
|
|
| 449 |
|
|
| 450 |
|
|
| 451 |
|
private void decorateOneToManyCollection(IClassDescriptor parentClassDescriptor, |
| 452 |
|
CollectionDescriptor collectionDescriptor, org.hibernate.mapping.Collection collectionMapping) |
| 453 |
|
{ |
| 454 |
81 |
Class type = parentClassDescriptor.getType(); |
| 455 |
81 |
if (collectionDescriptor.isOneToMany() && collectionMapping.isInverse()) |
| 456 |
|
{ |
| 457 |
|
try |
| 458 |
|
{ |
| 459 |
|
|
| 460 |
22 |
Field propertyField = type.getDeclaredField(collectionDescriptor.getName()); |
| 461 |
22 |
PropertyDescriptor beanPropDescriptor = (PropertyDescriptor) Ognl.getValue( |
| 462 |
22 |
"propertyDescriptors.{? name == '" + collectionDescriptor.getName() + "'}[0]", Introspector |
| 463 |
22 |
.getBeanInfo(type)); |
| 464 |
22 |
Method readMethod = beanPropDescriptor.getReadMethod(); |
| 465 |
22 |
String mappedBy = ""; |
| 466 |
22 |
if (readMethod.isAnnotationPresent(javax.persistence.OneToMany.class)) |
| 467 |
|
{ |
| 468 |
22 |
mappedBy = readMethod.getAnnotation(javax.persistence.OneToMany.class).mappedBy(); |
| 469 |
0 |
} else if (propertyField.isAnnotationPresent(javax.persistence.OneToMany.class)) |
| 470 |
|
{ |
| 471 |
0 |
mappedBy = propertyField.getAnnotation(javax.persistence.OneToMany.class).mappedBy(); |
| 472 |
|
} |
| 473 |
|
|
| 474 |
22 |
if (!"".equals(mappedBy)) |
| 475 |
|
{ |
| 476 |
22 |
collectionDescriptor.setInverseProperty(mappedBy); |
| 477 |
|
} |
| 478 |
|
|
| 479 |
22 |
parentClassDescriptor.setHasCyclicRelationships(true); |
| 480 |
|
|
| 481 |
0 |
} catch (SecurityException e) |
| 482 |
|
{ |
| 483 |
0 |
LOG.error(e.getMessage()); |
| 484 |
0 |
} catch (NoSuchFieldException e) |
| 485 |
|
{ |
| 486 |
0 |
LOG.error(e.getMessage()); |
| 487 |
0 |
} catch (OgnlException e) |
| 488 |
|
{ |
| 489 |
0 |
LOG.error(e.getMessage()); |
| 490 |
0 |
} catch (IntrospectionException e) |
| 491 |
|
{ |
| 492 |
0 |
LOG.error(e.getMessage()); |
| 493 |
|
} |
| 494 |
|
} |
| 495 |
81 |
} |
| 496 |
|
|
| 497 |
|
protected org.hibernate.mapping.Collection findCollectionMapping(Class type, String name) |
| 498 |
|
{ |
| 499 |
94 |
String roleName = type.getName() + "." + name; |
| 500 |
188 |
org.hibernate.mapping.Collection collectionMapping = getLocalSessionFactoryBean().getConfiguration() |
| 501 |
94 |
.getCollectionMapping(roleName); |
| 502 |
94 |
if (collectionMapping != null) |
| 503 |
|
{ |
| 504 |
81 |
return collectionMapping; |
| 505 |
13 |
} else if (!type.equals(Object.class)) |
| 506 |
|
{ |
| 507 |
13 |
return findCollectionMapping(type.getSuperclass(), name); |
| 508 |
|
} else |
| 509 |
|
{ |
| 510 |
0 |
throw new MetadataNotFoundException("Metadata not found."); |
| 511 |
|
} |
| 512 |
|
|
| 513 |
|
} |
| 514 |
|
|
| 515 |
|
|
| 516 |
|
|
| 517 |
|
|
| 518 |
|
|
| 519 |
|
|
| 520 |
|
public String getIdentifierProperty(Class type) |
| 521 |
|
{ |
| 522 |
|
try |
| 523 |
|
{ |
| 524 |
633 |
return getSessionFactory().getClassMetadata(type).getIdentifierPropertyName(); |
| 525 |
0 |
} catch (HibernateException e) |
| 526 |
|
{ |
| 527 |
0 |
throw new TrailsRuntimeException(e); |
| 528 |
|
} |
| 529 |
|
} |
| 530 |
|
|
| 531 |
|
|
| 532 |
|
|
| 533 |
|
|
| 534 |
|
public SessionFactory getSessionFactory() |
| 535 |
|
{ |
| 536 |
1347 |
return (SessionFactory) getLocalSessionFactoryBean().getObject(); |
| 537 |
|
} |
| 538 |
|
|
| 539 |
|
public IClassDescriptor getClassDescriptor(Class type) |
| 540 |
|
{ |
| 541 |
0 |
return descriptors.get(type); |
| 542 |
|
} |
| 543 |
|
|
| 544 |
|
|
| 545 |
|
|
| 546 |
|
|
| 547 |
|
public LocalSessionFactoryBean getLocalSessionFactoryBean() |
| 548 |
|
{ |
| 549 |
2049 |
return localSessionFactoryBean; |
| 550 |
|
} |
| 551 |
|
|
| 552 |
|
|
| 553 |
|
|
| 554 |
|
|
| 555 |
|
|
| 556 |
|
public void setLocalSessionFactoryBean(LocalSessionFactoryBean localSessionFactoryBean) |
| 557 |
|
{ |
| 558 |
12 |
this.localSessionFactoryBean = localSessionFactoryBean; |
| 559 |
12 |
} |
| 560 |
|
|
| 561 |
|
|
| 562 |
|
|
| 563 |
|
|
| 564 |
|
|
| 565 |
|
|
| 566 |
|
public List<IClassDescriptor> getAllDescriptors() |
| 567 |
|
{ |
| 568 |
0 |
return new ArrayList<IClassDescriptor>(descriptors.values()); |
| 569 |
|
} |
| 570 |
|
|
| 571 |
|
public List getTypes() |
| 572 |
|
{ |
| 573 |
0 |
return types; |
| 574 |
|
} |
| 575 |
|
|
| 576 |
|
public void setTypes(List types) |
| 577 |
|
{ |
| 578 |
0 |
this.types = types; |
| 579 |
0 |
} |
| 580 |
|
|
| 581 |
|
public int getLargeColumnLength() |
| 582 |
|
{ |
| 583 |
128 |
return largeColumnLength; |
| 584 |
|
} |
| 585 |
|
|
| 586 |
|
|
| 587 |
|
|
| 588 |
|
|
| 589 |
|
|
| 590 |
|
|
| 591 |
|
public void setLargeColumnLength(int largeColumnLength) |
| 592 |
|
{ |
| 593 |
0 |
this.largeColumnLength = largeColumnLength; |
| 594 |
0 |
} |
| 595 |
|
|
| 596 |
|
public DescriptorFactory getDescriptorFactory() |
| 597 |
|
{ |
| 598 |
13 |
return descriptorFactory; |
| 599 |
|
} |
| 600 |
|
|
| 601 |
|
public void setDescriptorFactory(DescriptorFactory descriptorFactory) |
| 602 |
|
{ |
| 603 |
12 |
this.descriptorFactory = descriptorFactory; |
| 604 |
12 |
} |
| 605 |
|
|
| 606 |
|
} |