當前位置: 首頁>>代碼示例>>Java>>正文


Java OneToOne類代碼示例

本文整理匯總了Java中javax.persistence.OneToOne的典型用法代碼示例。如果您正苦於以下問題:Java OneToOne類的具體用法?Java OneToOne怎麽用?Java OneToOne使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


OneToOne類屬於javax.persistence包,在下文中一共展示了OneToOne類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: isCascadeAll

import javax.persistence.OneToOne; //導入依賴的package包/類
private boolean isCascadeAll()
{
	OneToMany onetomany = getAnnotation(OneToMany.class);
	if( onetomany != null )
	{
		return hasCascadeAll(onetomany.cascade());
	}
	OneToOne onetoone = getAnnotation(OneToOne.class);
	if( onetoone != null )
	{
		return hasCascadeAll(onetoone.cascade());
	}
	ManyToOne manyToOne = getAnnotation(ManyToOne.class);
	if( manyToOne != null )
	{
		return hasCascadeAll(manyToOne.cascade());
	}
	// CollectionOfElements is a 'default' cascade all
	if( getAnnotation(CollectionOfElements.class) != null )
	{
		return true;
	}

	return false;
}
 
開發者ID:equella,項目名稱:Equella,代碼行數:26,代碼來源:Property.java

示例2: getMappedBy

import javax.persistence.OneToOne; //導入依賴的package包/類
private String getMappedBy(MetaAttribute attr) {
	ManyToMany manyManyAnnotation = attr.getAnnotation(ManyToMany.class);
	OneToMany oneManyAnnotation = attr.getAnnotation(OneToMany.class);
	OneToOne oneOneAnnotation = attr.getAnnotation(OneToOne.class);
	String mappedBy = null;
	if (manyManyAnnotation != null) {
		mappedBy = manyManyAnnotation.mappedBy();
	}
	if (oneManyAnnotation != null) {
		mappedBy = oneManyAnnotation.mappedBy();
	}
	if (oneOneAnnotation != null) {
		mappedBy = oneOneAnnotation.mappedBy();
	}

	if (mappedBy != null && mappedBy.length() == 0) {
		mappedBy = null;
	}
	return mappedBy;
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:21,代碼來源:JpaMetaFilter.java

示例3: getFieldType

import javax.persistence.OneToOne; //導入依賴的package包/類
@Override
public Optional<ResourceFieldType> getFieldType(BeanAttributeInformation attributeDesc) {
	Optional<OneToOne> oneToOne = attributeDesc.getAnnotation(OneToOne.class);
	Optional<OneToMany> oneToMany = attributeDesc.getAnnotation(OneToMany.class);
	Optional<ManyToOne> manyToOne = attributeDesc.getAnnotation(ManyToOne.class);
	Optional<ManyToMany> manyToMany = attributeDesc.getAnnotation(ManyToMany.class);
	if (oneToOne.isPresent() || oneToMany.isPresent() || manyToOne.isPresent() || manyToMany.isPresent()) {
		return Optional.of(ResourceFieldType.RELATIONSHIP);
	}

	Optional<Id> id = attributeDesc.getAnnotation(Id.class);
	Optional<EmbeddedId> embeddedId = attributeDesc.getAnnotation(EmbeddedId.class);
	if (id.isPresent() || embeddedId.isPresent()) {
		return Optional.of(ResourceFieldType.ID);
	}
	return Optional.empty();
}
 
開發者ID:crnk-project,項目名稱:crnk-framework,代碼行數:18,代碼來源:JpaResourceFieldInformationProvider.java

示例4: hasAnnotationsOnIdClass

import javax.persistence.OneToOne; //導入依賴的package包/類
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;
	}
 
開發者ID:lamsfoundation,項目名稱:lams,代碼行數:27,代碼來源:AnnotationBinder.java

示例5: nonInverseToOneAssociationsMustBeLazilyFetched

import javax.persistence.OneToOne; //導入依賴的package包/類
/**
 * In JPA, @ManyToOne and @OneToOne associations are fetched eagerly by
 * default. That will, in most situations, cause performance problems.
 * Because of that, the default behavior shall be changed to lazy fetching
 * which this test enforces. On some rare occasions, the developer may want
 * to apply eager fetching and for these cases @EagerFetch annotation is
 * available for indicating that the intention is purposeful and should be
 * passed by this test.
 */
@Test
public void nonInverseToOneAssociationsMustBeLazilyFetched() {
    final Stream<Field> failedFields = filterFieldsOfManagedJpaTypes(field -> {
        final OneToOne oneToOne = field.getAnnotation(OneToOne.class);
        final ManyToOne manyToOne = field.getAnnotation(ManyToOne.class);

        return !isIdField(field) && !field.isAnnotationPresent(EagerFetch.class) &&
                (manyToOne != null && manyToOne.fetch() == FetchType.EAGER ||
                        oneToOne != null && "".equals(oneToOne.mappedBy()) && oneToOne.fetch() == FetchType.EAGER);
    });

    assertNoFields(failedFields,
            "These entity fields should either have \"fetch = FetchType.LAZY\" parameter set on @ManyToOne/" +
                    "@OneToOne annotation or alternatively be annotated with @EagerFetch: ");
}
 
開發者ID:suomenriistakeskus,項目名稱:oma-riista-web,代碼行數:25,代碼來源:JpaModelTest.java

示例6: appendEntityAttributeName

import javax.persistence.OneToOne; //導入依賴的package包/類
/**
 * 
 * Append the entity attribute name to the JPQL query statement.
 * 
 * @param jpqlStatement
 * @param jpaEntity
 * @param attribute
 * @throws java.lang.SecurityException 
 * @throws NoSuchFieldException 
 * @throws ClassNotFoundException 
 */
private void appendEntityAttributeName(StringBuilder jpqlStatement, JpaEntity jpaEntity, EntityAttribute attribute, AtomicInteger aliasUnicityKey, AtomicInteger joinAdditionsOffset) throws NoSuchFieldException, java.lang.SecurityException, ClassNotFoundException {
	Class<?> entityClass = Class.forName(jpaEntity.getClassName());
	Field field = entityClass.getDeclaredField(attribute.getAttributeName());
	boolean isJointRelationship = 
			field.getAnnotation(OneToOne.class) != null
			|| field.getAnnotation(OneToMany.class) != null
			|| field.getAnnotation(ManyToOne.class) != null
			|| field.getAnnotation(ManyToMany.class) != null;
	if(isJointRelationship) {
		StringBuilder joinFragment = new StringBuilder();
		Queue<String> objectTreePath = extractDotSeparatedPathFragments(attribute.getPossibleValueLabelAttributePath());
		completeJoinFragment(joinFragment, entityClass, objectTreePath, aliasUnicityKey);
		jpqlStatement.insert(joinAdditionsOffset.get(), joinFragment);
		joinAdditionsOffset.set(joinAdditionsOffset.get() + joinFragment.length());
		jpqlStatement.append(" x").append(aliasUnicityKey.get()).append('.').append(attribute.getPossibleValueLabelAttribute());
	} else {
		jpqlStatement.append(" x.").append(attribute.getAttributeName());
	}
}
 
開發者ID:infiniquery,項目名稱:infiniquery-core,代碼行數:31,代碼來源:DefaultQueryModelService.java

示例7: getValueType

import javax.persistence.OneToOne; //導入依賴的package包/類
protected Class<?> getValueType(PopulateValueRequest populateValueRequest, Class<?> startingValueType) {
    Class<?> valueType = startingValueType;
    if (!StringUtils.isEmpty(populateValueRequest.getMetadata().getToOneTargetProperty())) {
        Field nestedField = FieldManager.getSingleField(valueType, populateValueRequest.getMetadata()
                .getToOneTargetProperty());
        ManyToOne manyToOne = nestedField.getAnnotation(ManyToOne.class);
        if (manyToOne != null && !manyToOne.targetEntity().getName().equals(void.class.getName())) {
            valueType = manyToOne.targetEntity();
        } else {
            OneToOne oneToOne = nestedField.getAnnotation(OneToOne.class);
            if (oneToOne != null && !oneToOne.targetEntity().getName().equals(void.class.getName())) {
                valueType = oneToOne.targetEntity();
            }
        }
    }
    return valueType;
}
 
開發者ID:takbani,項目名稱:blcdemo,代碼行數:18,代碼來源:MapFieldPersistenceProvider.java

示例8: anyAnnotation

import javax.persistence.OneToOne; //導入依賴的package包/類
private Annotation anyAnnotation(Field field) {
    Annotation annotation = null;

    annotation = field.getAnnotation(ManyToMany.class);
    if (annotation != null) {
        return annotation;
    }

    annotation = field.getAnnotation(OneToOne.class);
    if (annotation != null) {
        return annotation;
    }

    annotation = field.getAnnotation(OneToMany.class);
    if (annotation != null) {
        return annotation;
    }

    annotation = field.getAnnotation(ManyToOne.class);
    if (annotation != null) {
        return annotation;
    }

    return null;
}
 
開發者ID:jurgendl,項目名稱:hql-builder,代碼行數:26,代碼來源:EntityRelationHelper.java

示例9: mappedByAnything

import javax.persistence.OneToOne; //導入依賴的package包/類
private Annotation mappedByAnything(String property) {
    Field field = findField(property);
    Annotation relationAnnotation = null;

    relationAnnotation = field.getAnnotation(ManyToMany.class);
    if (relationAnnotation != null) {
        return relationAnnotation;
    }

    relationAnnotation = field.getAnnotation(OneToOne.class);
    if (relationAnnotation != null) {
        return relationAnnotation;
    }

    relationAnnotation = field.getAnnotation(OneToMany.class);
    if (relationAnnotation != null) {
        return relationAnnotation;
    }

    relationAnnotation = field.getAnnotation(ManyToOne.class);
    if (relationAnnotation != null) {
        return relationAnnotation;
    }

    return null;
}
 
開發者ID:jurgendl,項目名稱:hql-builder,代碼行數:27,代碼來源:EntityRelationHelper.java

示例10: targetEntity

import javax.persistence.OneToOne; //導入依賴的package包/類
private Class<?> targetEntity(Annotation relationAnnotation) {
    if (relationAnnotation instanceof ManyToMany) {
        return ManyToMany.class.cast(relationAnnotation).targetEntity();
    }

    if (relationAnnotation instanceof OneToOne) {
        return OneToOne.class.cast(relationAnnotation).targetEntity();
    }

    if (relationAnnotation instanceof OneToMany) {
        return OneToMany.class.cast(relationAnnotation).targetEntity();
    }

    if (relationAnnotation instanceof ManyToOne) {
        return ManyToOne.class.cast(relationAnnotation).targetEntity();
    }

    return null;
}
 
開發者ID:jurgendl,項目名稱:hql-builder,代碼行數:20,代碼來源:EntityRelationHelper.java

示例11: configureExample

import javax.persistence.OneToOne; //導入依賴的package包/類
/**
 * Metodo que agrega relaciones
 * 
 * @param criteria
 * @param example
 * @return
 */
@Nonnull
private Criteria configureExample(@Nonnull final Criteria criteria,
		final T example) {

	if (example == null) {
		return criteria;
	}
	try {
		for (final Field f : example.getClass().getDeclaredFields()) {
			f.setAccessible(true);
			if (f.getAnnotation(OneToOne.class) == null
					&& f.getAnnotation(ManyToOne.class) == null
					|| f.get(example) == null) {
				continue;
			}
			criteria.add(Restrictions.eq(f.getName(), f.get(example)));
		}
	} catch (final Exception e) {
		this.log.error("Error al agregar la relación", e);
	}
	return criteria;
}
 
開發者ID:fpuna-cia,項目名稱:karaku,代碼行數:30,代碼來源:BaseDAOImpl.java

示例12: buildUniqueProperty

import javax.persistence.OneToOne; //導入依賴的package包/類
private void buildUniqueProperty(final SingularProperty<E, ?> property) {
	if (this.context.getMaxUniqueProperties() > 0) {
		final boolean unique;
		final Column column = property.getAttribute().getAnnotation(Column.class);
		if (column != null && column.unique()) {
			unique = true;
		} else {
			final OneToOne oneToOne = property.getAttribute().getAnnotation(OneToOne.class);
			if (oneToOne != null) {
				unique = StringUtils.isEmpty(oneToOne.mappedBy());
			} else {
				final JoinColumn joinColumn = property.getAttribute().getAnnotation(JoinColumn.class);
				unique = joinColumn != null && joinColumn.unique();
			}
		}
		if (unique) {
			final UniquePropertyQuality propertyQuality = UniquePropertyQuality.getMatchingQuality(property);
			if (propertyQuality != null && isBetterUniquePropertyQuality(propertyQuality)) {
				this.uniquePropertiesQuality = propertyQuality;
				this.uniqueProperties = Collections
						.<SingularProperty<E, ?>> singletonList((SingularProperty<E, ?>) property);
			}
		}
	}
}
 
開發者ID:liefke,項目名稱:org.fastnate,代碼行數:26,代碼來源:EntityClass.java

示例13: isLazy

import javax.persistence.OneToOne; //導入依賴的package包/類
/**
 * Find if a OneToOne or OneToMany annotation exits and if it's the case, verify if the fetch is LAZY.
 * @param field the field
 * @return true if eager, false otherwise
 */
public static boolean isLazy(final Field field) {
    final OneToOne oneOne = field.getAnnotation(OneToOne.class);
    if (oneOne != null) {
        // By Default Eager
        return oneOne.fetch().equals(FetchType.LAZY);
    }
    final ManyToOne manyOne = field.getAnnotation(ManyToOne.class);
    if (manyOne != null) {
        // By Default Eager
        return manyOne.fetch().equals(FetchType.LAZY);
    }
    final OneToMany oneMany = field.getAnnotation(OneToMany.class);
    if (oneMany != null) {
        // By Default Lazy
        return oneMany.fetch().equals(FetchType.LAZY);
    }
    final ManyToMany manyMany = field.getAnnotation(ManyToMany.class);
    if (manyMany != null) {
        // By Default Lazy
        return manyMany.fetch().equals(FetchType.LAZY);
    }
    // Other case, no problem
    return true;
}
 
開發者ID:qjafcunuas,項目名稱:jbromo,代碼行數:30,代碼來源:EntityUtil.java

示例14: getTargetEntityFromAnnotation

import javax.persistence.OneToOne; //導入依賴的package包/類
/**
 * @param field
 * @return
 */
private static Class<?> getTargetEntityFromAnnotation(final Field field)
{
	for (final Annotation annotation : field.getAnnotations())
	{
		if (instanceOf(annotation, OneToMany.class))
		{
			return ((OneToMany) annotation).targetEntity();
		}
		else if (instanceOf(annotation, OneToOne.class))
		{
			return ((OneToOne) annotation).targetEntity();
		}
	}
	return null;
}
 
開發者ID:openfurther,項目名稱:further-open-core,代碼行數:20,代碼來源:JpaAnnotationUtil.java

示例15: extractPropertyMetadata

import javax.persistence.OneToOne; //導入依賴的package包/類
/**
 * Get the property metadata
 * for the supplied property
 * @param property
 * @param builder
 */
@SuppressWarnings("unchecked")
private void extractPropertyMetadata(PropertyDescriptor property, ResourceMetadataBuilder builder) {
	// Get the field for the property
	Method accessor = property.getReadMethod();
	
	// Get the property name
	String name = property.getName();

	// Is it an identity field?
	if (AnnotationHelper.fieldOrPropertyAnnotated(property, Id.class)) {
		builder.identityProperty(name, accessor);
	}

	// Is it a relation field (and therefore embedded)?
	else if (AnnotationHelper.fieldOrPropertyAnnotated(property, ManyToOne.class, OneToOne.class, OneToMany.class, ManyToMany.class)) {
		builder.embeddedResource(name, accessor);
	}

	// None of the above, must be @Basic or unadorned.
	else {
		builder.simpleProperty(name, accessor);
	}
}
 
開發者ID:patrickvankann,項目名稱:bjug-querydsl,代碼行數:30,代碼來源:JpaEntityResourceMetadataExtractor.java


注:本文中的javax.persistence.OneToOne類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。