protected Class<?> getValueType(PopulateValueRequest populateValueRequest, Class<?> startingValueType) { Class<?> valueType = startingValueType; if (!StringUtils.isEmpty(populateValueRequest.getMetadata().getToOneTargetProperty())) { Field nestedField = FieldManager.getSingleField(valueType, populateValueRequest.getMetadata() .getToOneTargetProperty()); ManyToOne manyToOne = nestedField.getAnnotation(ManyToOne.class); if (manyToOne != null && !manyToOne.targetEntity().getName().equals(void.class.getName())) { valueType = manyToOne.targetEntity(); } else { OneToOne oneToOne = nestedField.getAnnotation(OneToOne.class); if (oneToOne != null && !oneToOne.targetEntity().getName().equals(void.class.getName())) { valueType = oneToOne.targetEntity(); } } } return valueType; }
private static Class<?> getTargetEntityClass(XProperty property) { final ManyToOne mTo = property.getAnnotation( ManyToOne.class ); if (mTo != null) { return mTo.targetEntity(); } final OneToOne oTo = property.getAnnotation( OneToOne.class ); if (oTo != null) { return oTo.targetEntity(); } throw new AssertionFailure("Unexpected discovery of a targetEntity: " + property.getName() ); } }
ad.setValue( "targetEntity", oneToOne.targetEntity() ); ad.setValue( "fetch", oneToOne.fetch() ); ad.setValue( "optional", oneToOne.optional() );
public static CtClass getTargetEntityClass(CtClass managedCtClass, CtField persistentField) throws NotFoundException { // get targetEntity defined in the annotation try { OneToOne oto = PersistentAttributesHelper.getAnnotation( persistentField, OneToOne.class ); OneToMany otm = PersistentAttributesHelper.getAnnotation( persistentField, OneToMany.class ); ManyToOne mto = PersistentAttributesHelper.getAnnotation( persistentField, ManyToOne.class ); ManyToMany mtm = PersistentAttributesHelper.getAnnotation( persistentField, ManyToMany.class ); Class<?> targetClass = null; if ( oto != null ) { targetClass = oto.targetEntity(); } if ( otm != null ) { targetClass = otm.targetEntity(); } if ( mto != null ) { targetClass = mto.targetEntity(); } if ( mtm != null ) { targetClass = mtm.targetEntity(); } if ( targetClass != null && targetClass != void.class ) { return managedCtClass.getClassPool().get( targetClass.getName() ); } } catch (NotFoundException ignore) { } // infer targetEntity from generic type signature String inferredTypeName = inferTypeName( managedCtClass, persistentField.getName() ); return inferredTypeName == null ? null : managedCtClass.getClassPool().get( inferredTypeName ); }
private static boolean discoverTypeWithoutReflection(XProperty p) { if ( p.isAnnotationPresent( OneToOne.class ) && !p.getAnnotation( OneToOne.class ) .targetEntity() .equals( void.class ) ) { return true;
} else { OneToOne oneToOne = nestedField.getAnnotation(OneToOne.class); if (oneToOne != null && !oneToOne.targetEntity().getName().equals(void.class.getName())) { valueClassName = oneToOne.targetEntity().getName();
private static Class<?> getTargetEntityClass(XProperty property) { final ManyToOne mTo = property.getAnnotation( ManyToOne.class ); if (mTo != null) { return mTo.targetEntity(); } final OneToOne oTo = property.getAnnotation( OneToOne.class ); if (oTo != null) { return oTo.targetEntity(); } throw new AssertionFailure("Unexpected discovery of a targetEntity: " + property.getName() ); } }
/** * INTERNAL: (Overridden in XMLOneToOneAccessor) */ public Class getTargetEntity() { return (m_oneToOne == null) ? void.class : m_oneToOne.targetEntity(); }
private static boolean discoverTypeWithoutReflection(XProperty p) { if ( p.isAnnotationPresent( OneToOne.class ) && !p.getAnnotation( OneToOne.class ) .targetEntity() .equals( void.class ) ) { return true;
protected Class getFieldTypeAccordingAnnotations(Field field) { OneToOne oneToOneAnnotation = field.getAnnotation(OneToOne.class); OneToMany oneToManyAnnotation = field.getAnnotation(OneToMany.class); ManyToOne manyToOneAnnotation = field.getAnnotation(ManyToOne.class); ManyToMany manyToManyAnnotation = field.getAnnotation(ManyToMany.class); Class result = null; if (oneToOneAnnotation != null) { result = oneToOneAnnotation.targetEntity(); } else if (oneToManyAnnotation != null) { result = oneToManyAnnotation.targetEntity(); } else if (manyToOneAnnotation != null) { result = manyToOneAnnotation.targetEntity(); } else if (manyToManyAnnotation != null) { result = manyToManyAnnotation.targetEntity(); } return result; }
private Class<?> getTargetEntity() { if ( oneToOne != null ) { return oneToOne.targetEntity(); } if ( oneToMany != null ) { return oneToMany.targetEntity(); } if ( manyToOne != null ) { return manyToOne.targetEntity(); } return null; } }
private static Class<?> getTargetEntityClass(XProperty property) { final ManyToOne mTo = property.getAnnotation( ManyToOne.class ); if (mTo != null) { return mTo.targetEntity(); } final OneToOne oTo = property.getAnnotation( OneToOne.class ); if (oTo != null) { return oTo.targetEntity(); } throw new AssertionFailure("Unexpected discovery of a targetEntity: " + property.getName() ); } }
private static Class<?> getTargetEntityClass(XProperty property) { final ManyToOne mTo = property.getAnnotation( ManyToOne.class ); if (mTo != null) { return mTo.targetEntity(); } final OneToOne oTo = property.getAnnotation( OneToOne.class ); if (oTo != null) { return oTo.targetEntity(); } throw new AssertionFailure("Unexpected discovery of a targetEntity: " + property.getName() ); } }
private void introspectOneToOne(OneToOne oneToOne) { Class targetClass = oneToOne.targetEntity(); if (void.class.equals(targetClass)) targetClass = _fieldType; setTargetEntity(targetClass); setCascadeTypes(oneToOne.cascade()); setFetch(oneToOne.fetch()); _isOptional = oneToOne.optional(); _mappedBy = oneToOne.mappedBy(); }
private static Class<?> getTargetEntityClass(XProperty property) { final ManyToOne mTo = property.getAnnotation( ManyToOne.class ); if (mTo != null) { return mTo.targetEntity(); } final OneToOne oTo = property.getAnnotation( OneToOne.class ); if (oTo != null) { return oTo.targetEntity(); } throw new AssertionFailure("Unexpected discovery of a targetEntity: " + property.getName() ); } }
/** * Parse @OneToOne. */ private void parseOneToOne(FieldMetaData fmd, OneToOne anno) { if (!JavaTypes.maybePC(fmd.getValue())) throw new MetaDataException(_loc.get("bad-meta-anno", fmd, "OneToOne")); // don't specifically exclude relation from DFG b/c that will prevent // us from even reading the fk when reading from the primary table, // which is not what most users will want if (anno.fetch() == FetchType.EAGER) fmd.setInDefaultFetchGroup(true); if (!anno.optional()) fmd.setNullValue(FieldMetaData.NULL_EXCEPTION); if (isMappingOverrideMode() && !StringUtils.isEmpty(anno.mappedBy())) fmd.setMappedBy(anno.mappedBy()); if (anno.targetEntity() != void.class) fmd.setTypeOverride(anno.targetEntity()); setCascades(fmd, anno.cascade()); }
/** * Parse @OneToOne. */ private void parseOneToOne(FieldMetaData fmd, OneToOne anno) { if (!JavaTypes.maybePC(fmd.getValue())) throw new MetaDataException(_loc.get("bad-meta-anno", fmd, "OneToOne")); // don't specifically exclude relation from DFG b/c that will prevent // us from even reading the fk when reading from the primary table, // which is not what most users will want if (anno.fetch() == FetchType.EAGER) fmd.setInDefaultFetchGroup(true); if (!anno.optional()) fmd.setNullValue(FieldMetaData.NULL_EXCEPTION); if (isMappingOverrideMode() && !StringUtils.isEmpty(anno.mappedBy())) fmd.setMappedBy(anno.mappedBy()); if (anno.targetEntity() != void.class) fmd.setTypeOverride(anno.targetEntity()); setCascades(fmd, anno.cascade()); setOrphanRemoval(fmd, anno.orphanRemoval()); fmd.setAssociationType(FieldMetaData.ONE_TO_ONE); }
/** * Parse @OneToOne. */ private void parseOneToOne(FieldMetaData fmd, OneToOne anno) { if (!JavaTypes.maybePC(fmd.getValue())) throw new MetaDataException(_loc.get("bad-meta-anno", fmd, "OneToOne")); // don't specifically exclude relation from DFG b/c that will prevent // us from even reading the fk when reading from the primary table, // which is not what most users will want if (anno.fetch() == FetchType.EAGER) fmd.setInDefaultFetchGroup(true); if (!anno.optional()) fmd.setNullValue(FieldMetaData.NULL_EXCEPTION); if (isMappingOverrideMode() && !StringUtil.isEmpty(anno.mappedBy())) fmd.setMappedBy(anno.mappedBy()); if (anno.targetEntity() != void.class) fmd.setTypeOverride(anno.targetEntity()); setCascades(fmd, anno.cascade()); setOrphanRemoval(fmd, anno.orphanRemoval()); fmd.setAssociationType(FieldMetaData.ONE_TO_ONE); }
/** * Parse @OneToOne. */ private void parseOneToOne(FieldMetaData fmd, OneToOne anno) { if (!JavaTypes.maybePC(fmd.getValue())) throw new MetaDataException(_loc.get("bad-meta-anno", fmd, "OneToOne")); // don't specifically exclude relation from DFG b/c that will prevent // us from even reading the fk when reading from the primary table, // which is not what most users will want if (anno.fetch() == FetchType.EAGER) fmd.setInDefaultFetchGroup(true); if (!anno.optional()) fmd.setNullValue(FieldMetaData.NULL_EXCEPTION); if (isMappingOverrideMode() && !StringUtil.isEmpty(anno.mappedBy())) fmd.setMappedBy(anno.mappedBy()); if (anno.targetEntity() != void.class) fmd.setTypeOverride(anno.targetEntity()); setCascades(fmd, anno.cascade()); setOrphanRemoval(fmd, anno.orphanRemoval()); fmd.setAssociationType(FieldMetaData.ONE_TO_ONE); }
/** * Return the value of the targetEntity for the accessor if it has a {@link OneToOne}, {@link OneToMany}, * {@link ManyToOne}, {@link OneToOne}, or {@link ManyToMany} annotation. This will return null if the accessor * is not an {@link AccessibleObject} or if it does not have one of the aforementioned annotations, or if the * targetEntity is not set for the annotation * @param theAccessor the accessor * @return the targetEntity for the accessor, or null if not specified. */ public static Class<?> getTargetEntity(Object theAccessor) { Class<?> aClass = null; if (theAccessor instanceof AccessibleObject) { AccessibleObject aObject = (AccessibleObject) theAccessor; if (aObject.getAnnotation(OneToMany.class) != null) { aClass = aObject.getAnnotation(OneToMany.class).targetEntity(); } else if (aObject.getAnnotation(OneToOne.class) != null) { aClass = aObject.getAnnotation(OneToOne.class).targetEntity(); } else if (aObject.getAnnotation(ManyToOne.class) != null) { aClass = aObject.getAnnotation(ManyToOne.class).targetEntity(); } else if (aObject.getAnnotation(ManyToMany.class) != null) { aClass = aObject.getAnnotation(ManyToMany.class).targetEntity(); } } return aClass; }