javax.persistence.AccessType Java Examples

The following examples show how to use javax.persistence.AccessType. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private boolean isProcessingId(XMLContext.Default defaults) {
	boolean isExplicit = defaults.getAccess() != null;
	boolean correctAccess =
			( PropertyType.PROPERTY.equals( propertyType ) && AccessType.PROPERTY.equals( defaults.getAccess() ) )
					|| ( PropertyType.FIELD.equals( propertyType ) && AccessType.FIELD
					.equals( defaults.getAccess() ) );
	boolean hasId = defaults.canUseJavaAnnotations()
			&& ( isPhysicalAnnotationPresent( Id.class ) || isPhysicalAnnotationPresent( EmbeddedId.class ) );
	//if ( properAccessOnMetadataComplete || properOverridingOnMetadataNonComplete ) {
	boolean mirrorAttributeIsId = defaults.canUseJavaAnnotations() &&
			( mirroredAttribute != null &&
					( mirroredAttribute.isAnnotationPresent( Id.class )
							|| mirroredAttribute.isAnnotationPresent( EmbeddedId.class ) ) );
	boolean propertyIsDefault = PropertyType.PROPERTY.equals( propertyType )
			&& !mirrorAttributeIsId;
	return correctAccess || ( !isExplicit && hasId ) || ( !isExplicit && propertyIsDefault );
}
 
Example #2
Source File: JPAOverriddenAnnotationReader.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
private void getAccessType(List<Annotation> annotationList, Element element) {
	if ( element == null ) {
		return;
	}
	String access = element.attributeValue( "access" );
	if ( access != null ) {
		AnnotationDescriptor ad = new AnnotationDescriptor( Access.class );
		AccessType type;
		try {
			type = AccessType.valueOf( access );
		}
		catch ( IllegalArgumentException e ) {
			throw new AnnotationException( access + " is not a valid access type. Check you xml confguration." );
		}

		if ( ( AccessType.PROPERTY.equals( type ) && this.element instanceof Method ) ||
				( AccessType.FIELD.equals( type ) && this.element instanceof Field ) ) {
			return;
		}

		ad.setValue( "value", type );
		annotationList.add( AnnotationFactory.create( ad ) );
	}
}
 
Example #3
Source File: PropertyAccessMixedImpl.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
protected static AccessType getAccessType(Class<?> containerJavaType, String propertyName) {
	Field field = fieldOrNull( containerJavaType, propertyName );
	AccessType fieldAccessType = getAccessTypeOrNull( field );
	if ( fieldAccessType != null ) {
		return fieldAccessType;
	}
	AccessType methodAccessType = getAccessTypeOrNull( getterMethodOrNull( containerJavaType, propertyName ) );
	if ( methodAccessType != null ) {
		return methodAccessType;
	}
	// No @Access on property or field; check to see if containerJavaType has an explicit @Access
	AccessType classAccessType = getAccessTypeOrNull( containerJavaType );
	if ( classAccessType != null ) {
		return classAccessType;
	}
	return field != null ? AccessType.FIELD : AccessType.PROPERTY;
}
 
Example #4
Source File: PersistentAttributesHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
public static <T extends Annotation> T getAnnotation(CtClass ctClass, String attributeName, Class<T> annotation) {
	AccessType classAccessType = getAccessTypeOrNull( ctClass );
	CtField field = findFieldOrNull( ctClass, attributeName );
	CtMethod getter = findGetterOrNull( ctClass, attributeName );

	if ( classAccessType == AccessType.FIELD || ( field != null && getAccessTypeOrNull( field ) == AccessType.FIELD ) ) {
		return field == null ? null : getAnnotationOrNull( field, annotation );
	}
	if ( classAccessType == AccessType.PROPERTY || ( getter != null && getAccessTypeOrNull( getter ) == AccessType.PROPERTY ) ) {
		return getter == null ? null : getAnnotationOrNull( getter, annotation );
	}

	T found = ( getter == null ? null : getAnnotationOrNull( getter, annotation ) );
	if ( found == null && field != null ) {
		return getAnnotationOrNull( field, annotation );
	}
	return found;
}
 
Example #5
Source File: PersistentAttributesHelper.java    From lams with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Consistent with hasAnnotation()
 */
private static String inferTypeName(CtClass ctClass, String attributeName ) {
	AccessType classAccessType = getAccessTypeOrNull( ctClass );
	CtField field = findFieldOrNull( ctClass, attributeName );
	CtMethod getter = findGetterOrNull( ctClass, attributeName );

	if ( classAccessType == AccessType.FIELD || ( field != null && getAccessTypeOrNull( field ) == AccessType.FIELD ) ) {
		return field == null ? null : inferFieldTypeName( field );
	}
	if ( classAccessType == AccessType.PROPERTY || ( getter != null && getAccessTypeOrNull( getter ) == AccessType.PROPERTY ) ) {
		return getter == null ? null : inferMethodTypeName( getter );
	}

	String found = ( getter == null ? null : inferMethodTypeName( getter ) );
	if ( found == null && field != null ) {
		return inferFieldTypeName( field );
	}
	return found;
}
 
Example #6
Source File: MCRCategoryImpl.java    From mycore with GNU General Public License v3.0 5 votes vote down vote up
@Override
@OneToMany(targetEntity = MCRCategoryImpl.class,
    cascade = {
        CascadeType.ALL },
    mappedBy = "parent")
@OrderColumn(name = "positionInParent")
@Access(AccessType.FIELD)
public List<MCRCategory> getChildren() {
    return super.getChildren();
}
 
Example #7
Source File: MybatisPersistentPropertyImpl.java    From spring-data-mybatis with Apache License 2.0 5 votes vote down vote up
@Nullable
private Boolean detectPropertyAccess() {

	org.springframework.data.annotation.AccessType accessType = findAnnotation(
			org.springframework.data.annotation.AccessType.class);

	if (accessType != null) {
		return Type.PROPERTY.equals(accessType.value());
	}

	Access access = findAnnotation(Access.class);

	if (access != null) {
		return AccessType.PROPERTY.equals(access.value());
	}

	accessType = findPropertyOrOwnerAnnotation(
			org.springframework.data.annotation.AccessType.class);

	if (accessType != null) {
		return Type.PROPERTY.equals(accessType.value());
	}

	access = findPropertyOrOwnerAnnotation(Access.class);

	if (access != null) {
		return AccessType.PROPERTY.equals(access.value());
	}

	return null;
}
 
Example #8
Source File: XMLContext.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void setAccess( String access, Default defaultType) {
	AccessType type;
	if ( access != null ) {
		try {
			type = AccessType.valueOf( access );
		}
		catch ( IllegalArgumentException e ) {
			throw new AnnotationException( "Invalid access type " + access + " (check your xml configuration)" );
		}
		defaultType.setAccess( type );
	}
}
 
Example #9
Source File: SavedSearch.java    From find with MIT License 5 votes vote down vote up
@SuppressWarnings("unused")
@Access(AccessType.PROPERTY)
@Column(name = Table.Column.DATE_RANGE_TYPE)
@JsonIgnore
public Integer getDateRangeInt() {
    return dateRange == null ? null : dateRange.getId();
}
 
Example #10
Source File: Zone.java    From cosmic with Apache License 2.0 5 votes vote down vote up
@Access(AccessType.PROPERTY)
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "id")
public long getId() {
    return super.getId();
}
 
Example #11
Source File: CreateXAnnotations.java    From hyperjaxb3 with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public XAnnotation<javax.persistence.Access> createAccess(String access) {
	return access == null ? null
			: new XAnnotation<javax.persistence.Access>(
					javax.persistence.Access.class, AnnotationUtils.create(
							"value", AccessType.valueOf(access)));

}
 
Example #12
Source File: BiDirectionalAssociationHandler.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static TypeDescription.Generic target(FieldDescription persistentField) {
	AnnotationDescription.Loadable<Access> access = persistentField.getDeclaringType().asErasure().getDeclaredAnnotations().ofType( Access.class );
	if ( access != null && access.loadSilent().value() == AccessType.FIELD ) {
		return persistentField.getType();
	}
	else {
		MethodDescription getter = EnhancerImpl.getterOf( persistentField );
		if ( getter == null ) {
			return persistentField.getType();
		}
		else {
			return getter.getReturnType();
		}
	}
}
 
Example #13
Source File: PropertyAccessMixedImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private static AccessType getAccessTypeOrNull(AnnotatedElement element) {
	if ( element == null ) {
		return null;
	}
	Access elementAccess = element.getAnnotation( Access.class );
	return elementAccess == null ? null : elementAccess.value();
}
 
Example #14
Source File: PropertyAccessMixedImpl.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public PropertyAccessMixedImpl(
		PropertyAccessStrategy strategy,
		Class containerJavaType,
		String propertyName) {
	this.strategy = strategy;

	AccessType propertyAccessType = getAccessType( containerJavaType, propertyName );

	switch ( propertyAccessType ) {
		case FIELD: {
			Field field = fieldOrNull( containerJavaType, propertyName );
			if ( field == null ) {
				throw new PropertyAccessBuildingException(
					"Could not locate field for property named [" + containerJavaType.getName() + "#" + propertyName + "]"
				);
			}
			this.getter = fieldGetter( containerJavaType, propertyName, field );
			this.setter = fieldSetter( containerJavaType, propertyName, field );
			break;
		}
		case PROPERTY: {
			Method getterMethod = getterMethodOrNull( containerJavaType, propertyName );
			if ( getterMethod == null ) {
				throw new PropertyAccessBuildingException(
					"Could not locate getter for property named [" + containerJavaType.getName() + "#" + propertyName + "]"
				);
			}
			Method setterMethod = setterMethodOrNull( containerJavaType, propertyName, getterMethod.getReturnType() );

			this.getter = propertyGetter( containerJavaType, propertyName, getterMethod );
			this.setter = propertySetter( containerJavaType, propertyName, setterMethod );
			break;
		}
		default: {
			throw new PropertyAccessBuildingException(
				"Invalid access type " + propertyAccessType + " for property named [" + containerJavaType.getName() + "#" + propertyName + "]"
			);
		}
	}
}
 
Example #15
Source File: Address.java    From vaadinator with Apache License 2.0 5 votes vote down vote up
@Column(length = 1024)
@Access(AccessType.PROPERTY)
public String getMagFilmeAsString() {
	StringBuffer res = new StringBuffer();
	Set<Filme> set = getMagFilme();
	if (set != null) {
		for (Filme f : set) {
			if (res.length() > 0) {
				res.append(",");
			}
			res.append(f.name());
		}
	}
	return res.toString();
}
 
Example #16
Source File: Address.java    From vaadinator with Apache License 2.0 5 votes vote down vote up
@Column(length = 1024)
@Access(AccessType.PROPERTY)
public String getMagFilmeAsString() {
	StringBuffer res = new StringBuffer();
	Set<Filme> set = getMagFilme();
	if (set != null) {
		for (Filme f : set) {
			if (res.length() > 0) {
				res.append(",");
			}
			res.append(f.name());
		}
	}
	return res.toString();
}
 
Example #17
Source File: Zone.java    From cosmic with Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "networktype")
@Enumerated(EnumType.STRING)
public NetworkType getNetworkType() {
    return super.getNetworkType();
}
 
Example #18
Source File: Zone.java    From cosmic with Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "internal_dns1")
public String getInternalDns1() {
    return super.getInternalDns1();
}
 
Example #19
Source File: Zone.java    From cosmic with Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "removed")
public Date getRemoved() {
    return super.getRemoved();
}
 
Example #20
Source File: Zone.java    From cosmic with Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "router_mac_address", updatable = false, nullable = false)
public String getRouterMacAddress() {
    return super.getRouterMacAddress();
}
 
Example #21
Source File: Zone.java    From cosmic with Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "userdata_provider")
public String getUserDataProvider() {
    return super.getUserDataProvider();
}
 
Example #22
Source File: Zone.java    From cosmic with Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "uuid")
public String getUuid() {
    return super.getUuid();
}
 
Example #23
Source File: Zone.java    From cosmic with Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "vpn_provider")
public String getVpnProvider() {
    return super.getVpnProvider();
}
 
Example #24
Source File: Zone.java    From cosmic with Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "zone_token")
public String getZoneToken() {
    return super.getZoneToken();
}
 
Example #25
Source File: ContactResource.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
@javax.persistence.Id
@Access(AccessType.PROPERTY)
public String getRepoId() {
  return super.getRepoId();
}
 
Example #26
Source File: HostResource.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
@javax.persistence.Id
@Access(AccessType.PROPERTY) // to tell it to use the non-default property-as-ID
public String getRepoId() {
  return super.getRepoId();
}
 
Example #27
Source File: DomainBase.java    From nomulus with Apache License 2.0 4 votes vote down vote up
@Override
@javax.persistence.Id
@Access(AccessType.PROPERTY)
public String getRepoId() {
  return super.getRepoId();
}
 
Example #28
Source File: AbstractJpaBaseEntity.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@Access(AccessType.PROPERTY)
@Column(name = "created_at", insertable = true, updatable = false, nullable = false)
public long getCreatedAt() {
    return createdAt;
}
 
Example #29
Source File: AbstractJpaBaseEntity.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@Access(AccessType.PROPERTY)
@Column(name = "created_by", insertable = true, updatable = false, nullable = false, length = 64)
public String getCreatedBy() {
    return createdBy;
}
 
Example #30
Source File: AbstractJpaBaseEntity.java    From hawkbit with Eclipse Public License 1.0 4 votes vote down vote up
@Override
@Access(AccessType.PROPERTY)
@Column(name = "last_modified_at", insertable = true, updatable = true, nullable = false)
public long getLastModifiedAt() {
    return lastModifiedAt;
}