/** * @param clazz Source class. * @param propertyName Property name. * @param accessType Expected access type. Legal values are <i>field</i> and <i>property</i>. * * @return Property object or {@code null} if none with expected name and access type has been found. */ public static XProperty getProperty(XClass clazz, String propertyName, String accessType) { for ( XProperty property : clazz.getDeclaredProperties( accessType ) ) { if ( propertyName.equals( property.getName() ) ) { return property; } } return null; }
final List<XProperty> fields = xClass.getDeclaredProperties( AccessType.FIELD.getType() ); final List<XProperty> getters = xClass.getDeclaredProperties( AccessType.PROPERTY.getType() );
/** * Recursively adds all audited properties of entity class and its superclasses. * * @param clazz Currently processed class. */ private void addPropertiesFromClass(XClass clazz) { final Audited allClassAudited = computeAuditConfiguration( clazz ); //look in the class addFromProperties( clazz.getDeclaredProperties( "field" ), it -> "field", fieldAccessedPersistentProperties, allClassAudited ); addFromProperties( clazz.getDeclaredProperties( "property" ), propertyAccessedPersistentProperties::get, propertyAccessedPersistentProperties.keySet(), allClassAudited ); if ( allClassAudited != null || !auditedPropertiesHolder.isEmpty() ) { final XClass superclazz = clazz.getSuperclass(); if ( !clazz.isInterface() && !"java.lang.Object".equals( superclazz.getName() ) ) { addPropertiesFromClass( superclazz ); } } }
private AccessType determineDefaultAccessType() { for (XClass xclass = clazz; xclass != null; xclass = xclass.getSuperclass()) { if ( ( xclass.getSuperclass() == null || Object.class.getName().equals( xclass.getSuperclass().getName() ) ) && ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) && xclass.isAnnotationPresent( Access.class ) ) { return AccessType.getAccessStrategy( xclass.getAnnotation( Access.class ).value() ); } } // Guess from identifier. // FIX: Shouldn't this be determined by the first attribute (i.e., field or property) with annotations, but without an // explicit Access annotation, according to JPA 2.0 spec 2.3.1: Default Access Type? for (XClass xclass = clazz; xclass != null && !Object.class.getName().equals(xclass.getName()); xclass = xclass.getSuperclass()) { if ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) { for ( XProperty prop : xclass.getDeclaredProperties( AccessType.PROPERTY.getType() ) ) { final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class ); if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) { return AccessType.PROPERTY; } } for ( XProperty prop : xclass.getDeclaredProperties( AccessType.FIELD.getType() ) ) { final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class ); if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) { return AccessType.FIELD; } } } } throw new AnnotationException( "No identifier specified for entity: " + clazz ); }
private static boolean hasAnnotationsOnIdClass(XClass idClass) { // if(idClass.getAnnotation(Embeddable.class) != null) // return true; List<XProperty> properties = idClass.getDeclaredProperties( XClass.ACCESS_FIELD ); for ( XProperty property : properties ) { if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent( OneToMany.class ) || property.isAnnotationPresent( ManyToOne.class ) || property.isAnnotationPresent( Id.class ) || property.isAnnotationPresent( GeneratedValue.class ) || property.isAnnotationPresent( OneToOne.class ) || property.isAnnotationPresent( ManyToMany.class ) ) { return true; } } List<XMethod> methods = idClass.getDeclaredMethods(); for ( XMethod method : methods ) { if ( method.isAnnotationPresent( Column.class ) || method.isAnnotationPresent( OneToMany.class ) || method.isAnnotationPresent( ManyToOne.class ) || method.isAnnotationPresent( Id.class ) || method.isAnnotationPresent( GeneratedValue.class ) || method.isAnnotationPresent( OneToOne.class ) || method.isAnnotationPresent( ManyToMany.class ) ) { return true; } } return false; }
if ( element.isAnnotationPresent( Id.class ) && element.isAnnotationPresent( Column.class ) ) { String columnName = element.getAnnotation( Column.class ).name(); for ( XProperty prop : declaringClass.getDeclaredProperties( AccessType.FIELD.getType() ) ) { if ( !prop.isAnnotationPresent( MapsId.class ) ) {
private TreeMap<String, XProperty> initProperties(AccessType access) { //order so that property are used in the same order when binding native query TreeMap<String, XProperty> propertiesMap = new TreeMap<String, XProperty>(); List<XProperty> properties = xClass.getDeclaredProperties( access.getType() ); for ( XProperty property : properties ) { if ( mustBeSkipped( property ) ) { continue; } propertiesMap.put( property.getName(), property ); } return propertiesMap; }
MutableBoolean modifiedEntityNamesFound, String accessType) { for ( XProperty property : clazz.getDeclaredProperties( accessType ) ) { final RevisionNumber revisionNumber = property.getAnnotation( RevisionNumber.class ); final RevisionTimestamp revisionTimestamp = property.getAnnotation( RevisionTimestamp.class );
String columnName = ""; for ( XProperty prop : inferredData.getDeclaringClass() .getDeclaredProperties( AccessType.FIELD.getType() ) ) { if ( prop.isAnnotationPresent( Id.class ) && prop.isAnnotationPresent( Column.class ) ) { columnName = prop.getAnnotation( Column.class ).name();
private AccessType determineDefaultAccessType() { XClass xclass = clazz; while ( xclass != null && !Object.class.getName().equals( xclass.getName() ) ) { if ( xclass.isAnnotationPresent( Entity.class ) || xclass.isAnnotationPresent( MappedSuperclass.class ) ) { for ( XProperty prop : xclass.getDeclaredProperties( AccessType.PROPERTY.getType() ) ) { final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class ); if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) { if (isEmbeddedId) { identifierType = prop.getClassOrElementClass(); } return AccessType.PROPERTY; } } for ( XProperty prop : xclass.getDeclaredProperties( AccessType.FIELD.getType() ) ) { final boolean isEmbeddedId = prop.isAnnotationPresent( EmbeddedId.class ); if ( prop.isAnnotationPresent( Id.class ) || isEmbeddedId ) { if ( isEmbeddedId ) { identifierType = prop.getClassOrElementClass(); } return AccessType.FIELD; } } } xclass = xclass.getSuperclass(); } throw new AnnotationException( "No identifier specified for entity: " + clazz.getName() ); }
Map<String, XProperty> getDeclaredFieldAccessXPropertiesByName(XClass xClass) { // TODO HSEARCH-3056 remove lambdas if possible return xClass.getDeclaredProperties( XClass.ACCESS_FIELD ).stream() .collect( xPropertiesByNameNoDuplicate() ); }
private static boolean hasAnnotationsOnIdClass(XClass idClass) { // if(idClass.getAnnotation(Embeddable.class) != null) // return true; List<XProperty> properties = idClass.getDeclaredProperties( XClass.ACCESS_FIELD ); for ( XProperty property : properties ) { if ( property.isAnnotationPresent( Column.class ) || property.isAnnotationPresent( OneToMany.class ) || property.isAnnotationPresent( ManyToOne.class ) || property.isAnnotationPresent( Id.class ) || property.isAnnotationPresent( GeneratedValue.class ) || property.isAnnotationPresent( OneToOne.class ) || property.isAnnotationPresent( ManyToMany.class ) ) { return true; } } List<XMethod> methods = idClass.getDeclaredMethods(); for ( XMethod method : methods ) { if ( method.isAnnotationPresent( Column.class ) || method.isAnnotationPresent( OneToMany.class ) || method.isAnnotationPresent( ManyToOne.class ) || method.isAnnotationPresent( Id.class ) || method.isAnnotationPresent( GeneratedValue.class ) || method.isAnnotationPresent( OneToOne.class ) || method.isAnnotationPresent( ManyToMany.class ) ) { return true; } } return false; }
@Override public List<XProperty> getDeclaredProperties(String arg0, Filter arg1) { List<XProperty> declaredProperties = delegate.getDeclaredProperties( arg0, arg1 ); Collections.reverse( declaredProperties ); return declaredProperties; }
@Override public List<XProperty> getDeclaredProperties(String arg0) { List<XProperty> declaredProperties = delegate.getDeclaredProperties( arg0 ); Collections.reverse( declaredProperties ); return declaredProperties; }
private void updateContainedInMetadata(ContainedInMetadataBuilder containedInMetadataBuilder, XProperty propertyWithContainedIn, String accessType) { XClass memberReturnedType = returnedType( propertyWithContainedIn ); String mappedBy = mappedBy( propertyWithContainedIn ); List<XProperty> returnedTypeProperties = memberReturnedType.getDeclaredProperties( accessType ); for ( XProperty property : returnedTypeProperties ) { if ( isCorrespondingIndexedEmbedded( propertyWithContainedIn, mappedBy, property ) ) { updateContainedInMetadataForProperty( containedInMetadataBuilder, property ); break; } } }
public void test2StepsGenerics() throws Exception { JavaReflectionManager factory = new JavaReflectionManager(); XClass container = factory.toXClass( Container.class ); XProperty contained = container.getDeclaredProperties( XClass.ACCESS_FIELD ).get( 0 ); assertTrue( contained.isTypeResolved() ); XProperty generic = contained.getType().getDeclaredProperties( XClass.ACCESS_FIELD ).get( 0 ); assertTrue( generic.isTypeResolved() ); }
public void testANN612IssueIsFixed() throws Exception { JavaReflectionManager factory = new JavaReflectionManager(); XClass clazz = factory.toXClass( C.class ); List<XProperty> properties = clazz.getDeclaredProperties( XClass.ACCESS_FIELD ); for( XProperty property : properties ) assertTrue( property.isTypeResolved() ); } }
public void testCanBeASimpleType() { List<XProperty> declaredProperties = dadAsSeenFromSon.getDeclaredProperties( "field" ); XProperty p = getPropertyNamed_from( "fieldProperty", declaredProperties ); assertTrue( factory.equals( p.getType(), String.class ) ); assertTrue( factory.equals( p.getElementClass(), String.class ) ); assertTrue( factory.equals( p.getClassOrElementClass(), String.class ) ); assertNull( p.getCollectionClass() ); assertFalse( p.isArray() ); assertFalse( p.isCollection() ); }
public void testResolveInterfaceType() { List<XProperty> declaredProperties = dadAsSeenFromSon.getDeclaredProperties( "property" ); XProperty p = getPropertyNamed_from( "language", declaredProperties ); assertTrue( factory.equals( p.getType(), String.class ) ); assertTrue( factory.equals( p.getElementClass(), String.class ) ); assertTrue( factory.equals( p.getClassOrElementClass(), String.class ) ); assertNull( p.getCollectionClass() ); assertNull( p.getMapKey() ); assertFalse( p.isArray() ); assertFalse( p.isCollection() ); }
public void testCanBeAnArray() { List<XProperty> declaredProperties = dadAsSeenFromSon.getDeclaredProperties( "property" ); XProperty p = getPropertyNamed_from( "arrayProperty", declaredProperties ); assertTrue( factory.equals( p.getType(), String[].class ) ); assertTrue( factory.equals( p.getElementClass(), String.class ) ); assertTrue( factory.equals( p.getClassOrElementClass(), String.class ) ); assertNull( p.getCollectionClass() ); assertNull( p.getMapKey() ); assertTrue( p.isArray() ); assertFalse( p.isCollection() ); }