protected FieldInfo buildFieldInfo(Field field) { FieldInfo info = new FieldInfo(); info.setName(field.getName()); info.setGenericType(field.getGenericType()); ManyToMany manyToMany = field.getAnnotation(ManyToMany.class); if (manyToMany != null) { info.setManyToManyMappedBy(manyToMany.mappedBy()); info.setManyToManyTargetEntity(manyToMany.targetEntity().getName()); } OneToMany oneToMany = field.getAnnotation(OneToMany.class); if (oneToMany != null) { info.setOneToManyMappedBy(oneToMany.mappedBy()); info.setOneToManyTargetEntity(oneToMany.targetEntity().getName()); } return info; }
protected FieldInfo buildFieldInfo(Field field) { FieldInfo info = new FieldInfo(); info.setName(field.getName()); info.setGenericType(field.getGenericType()); ManyToMany manyToMany = field.getAnnotation(ManyToMany.class); if (manyToMany != null) { info.setManyToManyMappedBy(manyToMany.mappedBy()); info.setManyToManyTargetEntity(manyToMany.targetEntity().getName()); } OneToMany oneToMany = field.getAnnotation(OneToMany.class); if (oneToMany != null) { info.setOneToManyMappedBy(oneToMany.mappedBy()); info.setOneToManyTargetEntity(oneToMany.targetEntity().getName()); } MapKey mapKey = field.getAnnotation(MapKey.class); if (mapKey != null) { info.setMapKey(mapKey.name()); } return info; }
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;
@Test public void testNoChildren() throws Exception { reader = getReader( Entity2.class, "field1", "many-to-many.orm1.xml" ); assertAnnotationPresent( ManyToMany.class ); assertAnnotationNotPresent( OrderBy.class ); assertAnnotationNotPresent( OrderColumn.class ); assertAnnotationNotPresent( MapKey.class ); assertAnnotationNotPresent( MapKeyClass.class ); assertAnnotationNotPresent( MapKeyTemporal.class ); assertAnnotationNotPresent( MapKeyEnumerated.class ); assertAnnotationNotPresent( MapKeyColumn.class ); assertAnnotationNotPresent( MapKeyJoinColumns.class ); assertAnnotationNotPresent( MapKeyJoinColumn.class ); assertAnnotationNotPresent( JoinTable.class ); assertAnnotationNotPresent( Access.class ); ManyToMany relAnno = reader.getAnnotation( ManyToMany.class ); assertEquals( 0, relAnno.cascade().length ); assertEquals( FetchType.LAZY, relAnno.fetch() ); assertEquals( "", relAnno.mappedBy() ); assertEquals( void.class, relAnno.targetEntity() ); }
if (targetEntity == null && null != m2mAnnotation.targetEntity() && !m2mAnnotation.targetEntity().getSimpleName().equals("void")) targetEntity = m2mAnnotation.targetEntity();
@Test public void testAllAttributes() throws Exception { reader = getReader( Entity2.class, "field1", "many-to-many.orm21.xml" ); assertAnnotationPresent( ManyToMany.class ); assertAnnotationNotPresent( OrderBy.class ); assertAnnotationNotPresent( OrderColumn.class ); assertAnnotationNotPresent( MapKey.class ); assertAnnotationNotPresent( MapKeyClass.class ); assertAnnotationNotPresent( MapKeyTemporal.class ); assertAnnotationNotPresent( MapKeyEnumerated.class ); assertAnnotationNotPresent( MapKeyColumn.class ); assertAnnotationNotPresent( MapKeyJoinColumns.class ); assertAnnotationNotPresent( MapKeyJoinColumn.class ); assertAnnotationNotPresent( JoinTable.class ); assertAnnotationPresent( Access.class ); ManyToMany relAnno = reader.getAnnotation( ManyToMany.class ); assertEquals( 0, relAnno.cascade().length ); assertEquals( FetchType.EAGER, relAnno.fetch() ); assertEquals( "field2", relAnno.mappedBy() ); assertEquals( Entity3.class, relAnno.targetEntity() ); assertEquals( AccessType.PROPERTY, reader.getAnnotation( Access.class ) .value() ); }
if (targetEntity == null && null != m2mAnnotation.targetEntity() && !m2mAnnotation.targetEntity().getSimpleName().equals("void")) targetEntity = m2mAnnotation.targetEntity();
/** * INTERNAL: (Overridden in XMLManyToManyAccessor) */ public Class getTargetEntity() { return m_manyToMany.targetEntity(); }
.targetEntity() .equals( void.class ) ) { return true;
private void readToMany(ManyToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } // find the other many table (not intersection) BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName())); } manyProp.setManyToMany(); manyProp.setModifyListenMode(ModifyListenMode.ALL); manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.OUTER); }
mappedBy = manyToManyAnn.mappedBy(); collectionBinder.setTargetEntity( context.getBootstrapContext().getReflectionManager().toXClass( manyToManyAnn.targetEntity() ) ); collectionBinder.setCascadeStrategy(
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 void introspectManyToMany(ManyToMany manyToMany) { Class targetClass = manyToMany.targetEntity(); if (! void.class.equals(targetClass)) setTargetEntity(targetClass); setCascadeTypes(manyToMany.cascade()); setFetch(manyToMany.fetch()); _mappedBy = manyToMany.mappedBy(); }
/** * Parse @ManyToMany. */ private void parseManyToMany(FieldMetaData fmd, ManyToMany anno) { switch (fmd.getDeclaredTypeCode()) { case JavaTypes.ARRAY: case JavaTypes.COLLECTION: case JavaTypes.MAP: if (JavaTypes.maybePC(fmd.getElement())) break; // no break default: throw new MetaDataException(_loc.get("bad-meta-anno", fmd, "OneToMany")); } fmd.setInDefaultFetchGroup(anno.fetch() == FetchType.EAGER); if (isMappingOverrideMode() && !StringUtils.isEmpty(anno.mappedBy())) fmd.setMappedBy(anno.mappedBy()); if (anno.targetEntity() != void.class) fmd.getElement().setDeclaredType(anno.targetEntity()); setCascades(fmd.getElement(), anno.cascade()); }
/** * Parse @ManyToMany. */ private void parseManyToMany(FieldMetaData fmd, ManyToMany anno) { switch (fmd.getDeclaredTypeCode()) { case JavaTypes.ARRAY: case JavaTypes.COLLECTION: case JavaTypes.MAP: if (fmd.getDeclaredType() == Properties.class || JavaTypes.maybePC(fmd.getElement())) break; // no break default: throw new MetaDataException(_loc.get("bad-meta-anno", fmd, "ManyToMany")); } fmd.setInDefaultFetchGroup(anno.fetch() == FetchType.EAGER); if (isMappingOverrideMode() && !StringUtils.isEmpty(anno.mappedBy())) fmd.setMappedBy(anno.mappedBy()); if (anno.targetEntity() != void.class) fmd.getElement().setDeclaredType(anno.targetEntity()); setCascades(fmd.getElement(), anno.cascade()); fmd.setAssociationType(FieldMetaData.MANY_TO_MANY); }
/** * Parse @ManyToMany. */ private void parseManyToMany(FieldMetaData fmd, ManyToMany anno) { switch (fmd.getDeclaredTypeCode()) { case JavaTypes.ARRAY: case JavaTypes.COLLECTION: case JavaTypes.MAP: if (fmd.getDeclaredType() == Properties.class || JavaTypes.maybePC(fmd.getElement())) break; // no break default: throw new MetaDataException(_loc.get("bad-meta-anno", fmd, "ManyToMany")); } fmd.setInDefaultFetchGroup(anno.fetch() == FetchType.EAGER); if (isMappingOverrideMode() && !StringUtils.isEmpty(anno.mappedBy())) fmd.setMappedBy(anno.mappedBy()); if (anno.targetEntity() != void.class) fmd.getElement().setDeclaredType(anno.targetEntity()); setCascades(fmd.getElement(), anno.cascade()); fmd.setAssociationType(FieldMetaData.MANY_TO_MANY); }
private void readToMany(ManyToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } // find the other many table (not intersection) BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { String msg = errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName()); throw new RuntimeException(msg); } manyProp.setManyToMany(true); manyProp.setModifyListenMode(ModifyListenMode.ALL); manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(TableJoin.LEFT_OUTER); }
private void readToMany(ManyToMany propAnn, DeployBeanPropertyAssocMany<?> manyProp) { manyProp.setMappedBy(propAnn.mappedBy()); manyProp.setFetchType(propAnn.fetch()); setCascadeTypes(propAnn.cascade(), manyProp.getCascadeInfo()); Class<?> targetType = propAnn.targetEntity(); if (targetType.equals(void.class)) { // via reflection of generics type targetType = manyProp.getTargetType(); } else { manyProp.setTargetType(targetType); } // find the other many table (not intersection) BeanTable assoc = factory.getBeanTable(targetType); if (assoc == null) { throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName())); } manyProp.setManyToMany(); manyProp.setModifyListenMode(ModifyListenMode.ALL); manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.OUTER); }
mappedBy = manyToManyAnn.mappedBy(); collectionBinder.setTargetEntity( mappings.getReflectionManager().toXClass( manyToManyAnn.targetEntity() ) ); collectionBinder.setCascadeStrategy(