/** * Resolve an externalized name to the AccessType enum value it names. * * @param externalName The external name * * @return The matching AccessType; {@link #DEFAULT} is returned rather than {@code null} */ public static AccessType getAccessStrategy(String externalName) { if ( externalName == null ) { return DEFAULT; } else if ( FIELD.getType().equals( externalName ) ) { return FIELD; } else if ( PROPERTY.getType().equals( externalName ) ) { return PROPERTY; } else { // TODO historically if the externalName string could not be matched default access was used. Maybe this should be an exception though!? return DEFAULT; } }
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 ); }
parameters.put( DynamicParameterizedType.XPROPERTY, xproperty ); parameters.put( DynamicParameterizedType.PROPERTY, xproperty.getName() ); parameters.put( DynamicParameterizedType.ACCESS_TYPE, accessType.getType() ); simpleValue.setTypeParameters( parameters );
public static AccessType getAccessStrategy(String type) { if ( type == null ) { return DEFAULT; } else if ( FIELD.getType().equals( type ) ) { return FIELD; } else if ( PROPERTY.getType().equals( type ) ) { return PROPERTY; } else { // TODO historically if the type string could not be matched default access was used. Maybe this should be an exception though!? return DEFAULT; } }
declaringClass, property, propertyContainer.getClassLevelAccessType().getType(), context.getBootstrapContext().getReflectionManager() ); 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 ) ) { propertyContainer.getClassLevelAccessType().getType(),
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; }
prop.setLazyGroup( lazyGroup ); prop.setCascade( cascade ); prop.setPropertyAccessorName( accessType.getType() );
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() ); }
/** * @param elements List of {@code ProperyData} instances * @param defaultAccessType The default value access strategy which has to be used in case no explicit local access * strategy is used * @param propertyContainer Metadata about a class and its properties * @param mappings Mapping meta data * * @return the number of id properties found while iterating the elements of {@code annotatedClass} using * the determined access strategy, {@code false} otherwise. */ static int addElementsOfClass( List<PropertyData> elements, AccessType defaultAccessType, PropertyContainer propertyContainer, ExtendedMappings mappings ) { int idPropertyCounter = 0; AccessType accessType = defaultAccessType; if ( propertyContainer.hasExplicitAccessStrategy() ) { accessType = propertyContainer.getExplicitAccessStrategy(); } propertyContainer.assertTypesAreResolvable( accessType ); Collection<XProperty> properties = propertyContainer.getProperties( accessType ); for ( XProperty p : properties ) { final int currentIdPropertyCounter = addProperty( propertyContainer, p, elements, accessType.getType(), mappings ); idPropertyCounter += currentIdPropertyCounter; } return idPropertyCounter; }
public static AccessType getAccessStrategy(String type) { if ( type == null ) { return DEFAULT; } else if ( FIELD.getType().equals( type ) ) { return FIELD; } else if ( PROPERTY.getType().equals( type ) ) { return PROPERTY; } else { // TODO historically if the type string could not be matched default access was used. Maybe this should be an exception though!? return DEFAULT; } }
public static AccessType getAccessStrategy(String type) { if ( type == null ) { return DEFAULT; } else if ( FIELD.getType().equals( type ) ) { return FIELD; } else if ( PROPERTY.getType().equals( type ) ) { return PROPERTY; } else { // TODO historically if the type string could not be matched default access was used. Maybe this should be an exception though!? return DEFAULT; } }
/** * Resolve an externalized name to the AccessType enum value it names. * * @param externalName The external name * * @return The matching AccessType; {@link #DEFAULT} is returned rather than {@code null} */ public static AccessType getAccessStrategy(String externalName) { if ( externalName == null ) { return DEFAULT; } else if ( FIELD.getType().equals( externalName ) ) { return FIELD; } else if ( PROPERTY.getType().equals( externalName ) ) { return PROPERTY; } else { // TODO historically if the externalName string could not be matched default access was used. Maybe this should be an exception though!? return DEFAULT; } }
prop.setLazy( lazy ); prop.setCascade( cascade ); prop.setPropertyAccessorName( accessType.getType() ); Generated ann = property != null ? property.getAnnotation( Generated.class ) :
/** * Retrieves all properties from the {@code xClass} with the specified access type. This method does not take * any jpa access rules/annotations into account yet. * * @param access The access type - {@code AccessType.FIELD} or {@code AccessType.Property} * * @return A maps of the properties with the given access type keyed against their property name */ private TreeMap<String, XProperty> initProperties(AccessType access) { if ( !( AccessType.PROPERTY.equals( access ) || AccessType.FIELD.equals( access ) ) ) { throw new IllegalArgumentException( "Access type has to be AccessType.FIELD or AccessType.Property" ); } //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; }
/** * Retrieves all properties from the {@code xClass} with the specified access type. This method does not take * any jpa access rules/annotations into account yet. * * @param access The access type - {@code AccessType.FIELD} or {@code AccessType.Property} * * @return A maps of the properties with the given access type keyed against their property name */ private TreeMap<String, XProperty> initProperties(AccessType access) { if ( !( AccessType.PROPERTY.equals( access ) || AccessType.FIELD.equals( access ) ) ) { throw new IllegalArgumentException( "Access type has to be AccessType.FIELD or AccessType.Property" ); } //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; }
/** * @param elements List of {@code ProperyData} instances * @param defaultAccessType The default value access strategy which has to be used in case no explicit local access * strategy is used * @param propertyContainer Metadata about a class and its properties * @param mappings Mapping meta data * * @return the number of id properties found while iterating the elements of {@code annotatedClass} using * the determined access strategy, {@code false} otherwise. */ static int addElementsOfClass( List<PropertyData> elements, AccessType defaultAccessType, PropertyContainer propertyContainer, Mappings mappings) { int idPropertyCounter = 0; AccessType accessType = defaultAccessType; if ( propertyContainer.hasExplicitAccessStrategy() ) { accessType = propertyContainer.getExplicitAccessStrategy(); } Collection<XProperty> properties = propertyContainer.getProperties( accessType ); for ( XProperty p : properties ) { final int currentIdPropertyCounter = addProperty( propertyContainer, p, elements, accessType.getType(), mappings ); idPropertyCounter += currentIdPropertyCounter; } return idPropertyCounter; }
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 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 ); }