fetchType = manyToMany.fetch();
@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() ); }
@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() ); }
Relation relation = new Relation(relationField, targetEntity, relationField.getType(), m2mAnnotation.fetch(), Arrays.asList(m2mAnnotation.cascade()), Boolean.TRUE, m2mAnnotation.mappedBy(), Relation.ForeignKey.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) { throw new BeanNotRegisteredException(errorMsgMissingBeanTable(targetType, manyProp.getFullBeanName())); } manyProp.setManyToMany(); manyProp.setModifyListenMode(ModifyListenMode.ALL); manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.OUTER); }
@Override protected String getFetch(Field field) { return field.getAnnotation(ManyToMany.class).fetch().name(); } @Override
/** * INTERNAL: (Overridden in XMLManyToManyAccessor) */ public String getFetchType() { return m_manyToMany.fetch().name(); }
public static List<Field> getEntityLazyFields(final Class<?> clazz) { final Field[] fields = clazz.getDeclaredFields(); final List<Field> retList = new ArrayList<Field>(); for (final Field field : fields) { if (!Modifier.isPublic(field.getModifiers())) { field.setAccessible(true); } if (field.isAnnotationPresent(OneToMany.class) && FetchType.LAZY .equals(field.getAnnotation(OneToMany.class).fetch()) || field.isAnnotationPresent(ManyToOne.class) && FetchType.LAZY .equals(field.getAnnotation(ManyToOne.class) .fetch()) || field.isAnnotationPresent(ManyToMany.class) && FetchType.LAZY .equals(field.getAnnotation(ManyToMany.class) .fetch()) || field.isAnnotationPresent(OneToOne.class) && FetchType.LAZY .equals(field.getAnnotation(OneToOne.class).fetch())) { retList.add(field); } } return retList; }
fetchType = manyToMany.fetch();
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(); }
/** * @param member * the java member of attribute * @param name * the name of the attribute * @param manyToMany * the annotation * @param parsed * set of annotations parsed * * @since 2.0.0 */ public ManyToManyAttributeMetadataImpl(Member member, String name, ManyToMany manyToMany, Set<Class<? extends Annotation>> parsed) { super(member, name, parsed, manyToMany.targetEntity().getName(), manyToMany.fetch(), manyToMany.cascade()); parsed.add(ManyToMany.class); this.mappedBy = manyToMany.mappedBy(); this.mapKey = this.handleMapKey(member, parsed); this.mapKeyClassName = this.handleMapKeyClassName(member, parsed); this.mapKeyColumn = this.handleMapKeyColumn(member, parsed); this.mapKeyEnumType = this.handleMapKeyEnumType(member, parsed); this.mapKeyTemporalType = this.handleMapKeyTemporalType(member, parsed); this.orderBy = this.handleOrderBy(member, parsed); this.orderColumn = this.handleOrderColumn(member, parsed); }
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(); manyProp.setModifyListenMode(ModifyListenMode.ALL); manyProp.setBeanTable(assoc); manyProp.getTableJoin().setType(SqlJoinType.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) { 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); }
/** * sprawdza czy mapping ORM'owy jest ok */ private void analyzeNoAcceptChange(ChangeRequest cr, DataObject modPoint) { if (cr.getRecType().equals(RecType.REFERENCE_CHANGE)) { Method getter = cr.getterMethod(); boolean owner = ReflectionUtil.isPersistentGetterOwnerOfRelation(getter); if (owner && !modPoint.isTransient() && cr.getNewReference__() != null && cr.getNewReference__().isTransient()) { throw new UnsupportedMapping("Can't perform NoAccept reference change on owner side (usualy @ManyToOne). modPoint ["+modPoint.getGlobalId()+"] is persistent|detached but new reference ["+cr.getNewReference__().getGlobalId()+"] is transient."+ " Problematic getter: "+getterDesc(getter)); } } if (cr.getRecType().equals(RecType.CHILD_REMOVE)) { Method getter = cr.getterMethod(); if (getter.isAnnotationPresent(ManyToMany.class)){ ManyToMany manyToMany = getter.getAnnotation(ManyToMany.class); if (FetchType.EAGER == manyToMany.fetch()){ throw new UnsupportedMapping("Can't perform NoAccept child remove. @ManyToMany with FetchType.EAGER is not supported. Getter method: "+ getter); } } } }
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); }
/** * 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()); }
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); }
/** * 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); }
/** * 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() && !StringUtil.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); }