public static boolean hasAnnotation(CtClass ctClass, String attributeName, Class<? extends Annotation> annotation) { return getAnnotation( ctClass, attributeName, annotation ) != null; }
public static boolean hasAnnotation(CtField attribute, Class<? extends Annotation> annotation) { return getAnnotation( attribute, annotation ) != null; }
private static String getMappedByFromAnnotation(CtField persistentField) { OneToOne oto = PersistentAttributesHelper.getAnnotation( persistentField, OneToOne.class ); if ( oto != null ) { return oto.mappedBy(); } OneToMany otm = PersistentAttributesHelper.getAnnotation( persistentField, OneToMany.class ); if ( otm != null ) { return otm.mappedBy(); } // For @ManyToOne associations, mappedBy must come from the @OneToMany side of the association ManyToMany mtm = PersistentAttributesHelper.getAnnotation( persistentField, ManyToMany.class ); return mtm == null ? "" : mtm.mappedBy(); }
public static <T extends Annotation> T getAnnotation(CtField attribute, Class<T> annotation) { return getAnnotation( attribute.getDeclaringClass(), attribute.getName(), annotation ); }
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 ); }
public static boolean hasAnnotation(CtClass ctClass, String attributeName, Class<? extends Annotation> annotation) { return getAnnotation( ctClass, attributeName, annotation ) != null; }
public static boolean hasAnnotation(CtField attribute, Class<? extends Annotation> annotation) { return getAnnotation( attribute, annotation ) != null; }
private static String getMappedByFromAnnotation(CtField persistentField) { OneToOne oto = PersistentAttributesHelper.getAnnotation( persistentField, OneToOne.class ); if ( oto != null ) { return oto.mappedBy(); } OneToMany otm = PersistentAttributesHelper.getAnnotation( persistentField, OneToMany.class ); if ( otm != null ) { return otm.mappedBy(); } // For @ManyToOne associations, mappedBy must come from the @OneToMany side of the association ManyToMany mtm = PersistentAttributesHelper.getAnnotation( persistentField, ManyToMany.class ); return mtm == null ? "" : mtm.mappedBy(); }
public static <T extends Annotation> T getAnnotation(CtField attribute, Class<T> annotation) { return getAnnotation( attribute.getDeclaringClass(), attribute.getName(), annotation ); }
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 ); }