javax.persistence.OneToOne#optional ( )源码实例Demo

下面列出了javax.persistence.OneToOne#optional ( ) 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。

源代码1 项目: cuba   文件: EntityInspectorEditor.java
protected boolean isRequired(MetaProperty metaProperty) {
    if (metaProperty.isMandatory())
        return true;

    ManyToOne many2One = metaProperty.getAnnotatedElement().getAnnotation(ManyToOne.class);
    if (many2One != null && !many2One.optional())
        return true;

    OneToOne one2one = metaProperty.getAnnotatedElement().getAnnotation(OneToOne.class);
    return one2one != null && !one2one.optional();
}
 
@Override
protected void initAttribute(MetaAttribute attr) {
	ManyToMany manyManyAnnotation = attr.getAnnotation(ManyToMany.class);
	ManyToOne manyOneAnnotation = attr.getAnnotation(ManyToOne.class);
	OneToMany oneManyAnnotation = attr.getAnnotation(OneToMany.class);
	OneToOne oneOneAnnotation = attr.getAnnotation(OneToOne.class);
	Version versionAnnotation = attr.getAnnotation(Version.class);
	Lob lobAnnotation = attr.getAnnotation(Lob.class);
	Column columnAnnotation = attr.getAnnotation(Column.class);

	boolean idAttr = attr.getAnnotation(Id.class) != null || attr.getAnnotation(EmbeddedId.class) != null;
	boolean attrGenerated = attr.getAnnotation(GeneratedValue.class) != null;

	attr.setVersion(versionAnnotation != null);
	attr.setAssociation(
			manyManyAnnotation != null || manyOneAnnotation != null || oneManyAnnotation != null || oneOneAnnotation !=
					null);

	attr.setLazy(isJpaLazy(attr.getAnnotations(), attr.isAssociation()));
	attr.setLob(lobAnnotation != null);
	attr.setFilterable(lobAnnotation == null);
	attr.setSortable(lobAnnotation == null);

	attr.setCascaded(getCascade(manyManyAnnotation, manyOneAnnotation, oneManyAnnotation, oneOneAnnotation));

	if (attr.getReadMethod() == null) {
		throw new IllegalStateException("no getter found for " + attr.getParent().getName() + "." + attr.getName());
	}
	Class<?> attributeType = attr.getReadMethod().getReturnType();
	boolean isPrimitiveType = ClassUtils.isPrimitiveType(attributeType);
	boolean columnNullable = (columnAnnotation == null || columnAnnotation.nullable()) &&
			(manyOneAnnotation == null || manyOneAnnotation.optional()) &&
			(oneOneAnnotation == null || oneOneAnnotation.optional());
	attr.setNullable(!isPrimitiveType && columnNullable);

	boolean hasSetter = attr.getWriteMethod() != null;
	attr.setInsertable(hasSetter && (columnAnnotation == null || columnAnnotation.insertable()) && !attrGenerated
			&& versionAnnotation == null);
	attr.setUpdatable(
			hasSetter && (columnAnnotation == null || columnAnnotation.updatable()) && !idAttr && versionAnnotation == null);

}
 
源代码3 项目: oval   文件: JPAAnnotationsConfigurer.java
protected void initializeChecks(final OneToOne annotation, final Collection<Check> checks) {
   if (!annotation.optional() && !containsCheckOfType(checks, NotNullCheck.class)) {
      checks.add(new NotNullCheck());
   }
}