Java Code Examples for javax.persistence.AccessType

The following examples show how to use javax.persistence.AccessType. These examples are extracted from open source projects. 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
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
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 Project: lams   Source File: PropertyAccessMixedImpl.java    License: 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
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
/**
 * 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 Project: lams   Source File: XMLContext.java    License: 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 7
Source Project: lams   Source File: PropertyAccessMixedImpl.java    License: 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 8
Source Project: lams   Source File: PropertyAccessMixedImpl.java    License: 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 9
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 10
Source Project: mycore   Source File: MCRCategoryImpl.java    License: 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 11
Source Project: cosmic   Source File: Zone.java    License: 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 12
@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 13
Source Project: find   Source File: SavedSearch.java    License: 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 14
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 15
Source Project: vaadinator   Source File: Address.java    License: 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 Project: vaadinator   Source File: Address.java    License: 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 Project: lams   Source File: XMLContext.java    License: GNU General Public License v2.0 4 votes vote down vote up
public AccessType getAccess() {
	return access;
}
 
Example 18
Source Project: lams   Source File: XMLContext.java    License: GNU General Public License v2.0 4 votes vote down vote up
protected void setAccess(AccessType access) {
	this.access = access;
}
 
Example 19
private static AccessType getAccessTypeOrNull(CtMember ctMember) {
	Access access = getAnnotationOrNull( ctMember, Access.class );
	return access == null ? null : access.value();
}
 
Example 20
Source Project: mycore   Source File: MCRCategoryImpl.java    License: GNU General Public License v3.0 4 votes vote down vote up
@ManyToOne(optional = true, targetEntity = MCRCategoryImpl.class)
@JoinColumn(name = "parentID")
@Access(AccessType.FIELD)
public MCRCategory getParent() {
    return super.getParent();
}
 
Example 21
Source Project: cosmic   Source File: Zone.java    License: Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "allocation_state")
@Enumerated(value = EnumType.STRING)
public AllocationState getAllocationState() {
    return super.getAllocationState();
}
 
Example 22
Source Project: cosmic   Source File: Zone.java    License: Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "description")
public String getDescription() {
    return super.getDescription();
}
 
Example 23
Source Project: cosmic   Source File: Zone.java    License: Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "dhcp_provider")
public String getDhcpProvider() {
    return super.getDhcpProvider();
}
 
Example 24
Source Project: cosmic   Source File: Zone.java    License: Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "dns1")
public String getDns1() {
    return super.getDns1();
}
 
Example 25
Source Project: cosmic   Source File: Zone.java    License: Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "dns2")
public String getDns2() {
    return super.getDns2();
}
 
Example 26
Source Project: cosmic   Source File: Zone.java    License: Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "dns_provider")
public String getDnsProvider() {
    return super.getDnsProvider();
}
 
Example 27
Source Project: cosmic   Source File: Zone.java    License: Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "domain_id")
public Long getDomainId() {
    return super.getDomainId();
}
 
Example 28
Source Project: cosmic   Source File: Zone.java    License: Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "domain")
public String getDomain() {
    return super.getDomain();
}
 
Example 29
Source Project: cosmic   Source File: Zone.java    License: Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "firewall_provider")
public String getFirewallProvider() {
    return super.getFirewallProvider();
}
 
Example 30
Source Project: cosmic   Source File: Zone.java    License: Apache License 2.0 4 votes vote down vote up
@Access(AccessType.PROPERTY)
@Column(name = "gateway_provider")
public String getGatewayProvider() {
    return super.getGatewayProvider();
}