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", manyToOne.targetEntity() ); ad.setValue( "fetch", manyToOne.fetch() ); ad.setValue( "optional", manyToOne.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 ); }
.targetEntity() .equals( void.class ) ) { return true;
if (manyToOne != null && !manyToOne.targetEntity().getName().equals(void.class.getName())) { valueClassName = manyToOne.targetEntity().getName(); } else { OneToOne oneToOne = nestedField.getAnnotation(OneToOne.class);
checkCeiling: if (manyToOne != null && manyToOne.targetEntity() != void.class) { ceiling = manyToOne.targetEntity().getName(); break checkCeiling;
@Test public void testNoJoins() throws Exception { reader = getReader( Entity1.class, "field1", "many-to-one.orm1.xml" ); assertAnnotationPresent( ManyToOne.class ); assertAnnotationNotPresent( JoinColumn.class ); assertAnnotationNotPresent( JoinColumns.class ); assertAnnotationNotPresent( JoinTable.class ); assertAnnotationNotPresent( Id.class ); assertAnnotationNotPresent( MapsId.class ); assertAnnotationNotPresent( Access.class ); ManyToOne relAnno = reader.getAnnotation( ManyToOne.class ); assertEquals( 0, relAnno.cascade().length ); assertEquals( FetchType.EAGER, relAnno.fetch() ); assertTrue( relAnno.optional() ); assertEquals( void.class, relAnno.targetEntity() ); }
@Test public void testAllAttributes() throws Exception { reader = getReader( Entity1.class, "field1", "many-to-one.orm6.xml" ); assertAnnotationPresent( ManyToOne.class ); assertAnnotationNotPresent( JoinColumn.class ); assertAnnotationNotPresent( JoinColumns.class ); assertAnnotationNotPresent( JoinTable.class ); assertAnnotationPresent( Id.class ); assertAnnotationPresent( MapsId.class ); assertAnnotationPresent( Access.class ); ManyToOne relAnno = reader.getAnnotation( ManyToOne.class ); assertEquals( 0, relAnno.cascade().length ); assertEquals( FetchType.LAZY, relAnno.fetch() ); assertFalse( relAnno.optional() ); assertEquals( Entity3.class, relAnno.targetEntity() ); assertEquals( "col1", reader.getAnnotation( MapsId.class ).value() ); assertEquals( AccessType.PROPERTY, reader.getAnnotation( Access.class ) .value() ); }
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() ); } }
Class<?> tt = manyToOne.targetEntity(); if (!tt.equals(void.class)) { propertyType = tt;
/** * INTERNAL: (Overridden in XMLManyToOneAccessor) */ public Class getTargetEntity() { return m_manyToOne.targetEntity(); }
.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 void introspectManyToOne(ManyToOne manyToOne) { Class targetClass = manyToOne.targetEntity(); if (void.class.equals(targetClass)) targetClass = _fieldType; setTargetEntity(targetClass); setCascadeTypes(manyToOne.cascade()); setFetch(manyToOne.fetch()); _isOptional = manyToOne.optional(); }
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 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 @ManyToOne. */ private void parseManyToOne(FieldMetaData fmd, ManyToOne anno) { if (!JavaTypes.maybePC(fmd.getValue())) throw new MetaDataException(_loc.get("bad-meta-anno", fmd, "ManyToOne")); // 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 (anno.targetEntity() != void.class) fmd.setTypeOverride(anno.targetEntity()); setCascades(fmd, anno.cascade()); }