Assert.assertFalse(idAttribute.isOptional()); Assert.assertEquals(idAttribute.getName(), key); Assert.assertEquals(clazz, idAttribute.getJavaType()); Assert.assertFalse(idAttributeDeclared.isOptional()); Assert.assertEquals(idAttributeDeclared.getName(), key); Assert.assertEquals(clazz, idAttributeDeclared.getJavaType());
public static boolean isOptional(Attribute<?, ?> attribute) { if (attribute instanceof SingularAttribute<?, ?>) { return ((SingularAttribute<?, ?>) attribute).isOptional(); } return true; }
Assert.assertTrue(managedType.getSingularAttribute("name").isOptional()); Assert.assertEquals(String.class, managedType.getSingularAttribute("name").getJavaType()); Assert.assertFalse(managedType.getSingularAttribute("field").isOptional()); Assert.assertEquals(String.class, managedType.getSingularAttribute("field").getJavaType());
public static boolean isOptional(Attribute<?, ?> attribute) { if (attribute instanceof SingularAttribute<?, ?>) { return ((SingularAttribute<?, ?>) attribute).isOptional(); } return true; }
if (attribute instanceof SingularAttribute) optional = ((SingularAttribute) attribute).isOptional();
private static boolean isNullable(Attribute<?, ?> attr) { if (attr.isCollection()) { return true; } // !((SingularAttribute<?, ?>) attr).isId() is required as a workaround for Eclipselink return ((SingularAttribute<?, ?>) attr).isOptional() && !((SingularAttribute<?, ?>) attr).isId(); }
private JoinType getModelAwareType(JoinNode baseNode, Attribute<?, ?> attr) { if (baseNode.getJoinType() == JoinType.LEFT) { return JoinType.LEFT; } if ((attr.getPersistentAttributeType() == Attribute.PersistentAttributeType.MANY_TO_ONE || attr.getPersistentAttributeType() == Attribute.PersistentAttributeType.ONE_TO_ONE) && ((SingularAttribute<?, ?>) attr).isOptional() == false) { return JoinType.INNER; } else { return JoinType.LEFT; } }
private static boolean isLeftOrNonNullReferenceJoin(Join<?, ?> join, boolean dbSchemaStrict) { if (join.getAttribute().isCollection()) { return false; } if (join.getJoinType() == JoinType.LEFT) { return true; } if (!dbSchemaStrict) { return false; } SingularAttribute<?, ?> singularAttribute = (SingularAttribute<?, ?>)join.getAttribute(); return !singularAttribute.isOptional() && singularAttribute.getPersistentAttributeType() == PersistentAttributeType.MANY_TO_ONE; } }
ExtendedAttribute<?, ?> extendedAttribute = entry.getValue(); SingularAttribute<?, ?> attribute = (SingularAttribute<?, ?>) extendedAttribute.getAttribute(); if (!attribute.isVersion() && !attribute.isOptional()) { if (superAttribute.isOptional()) { continue OUTER; } else {
if (!((SingularAttribute<?, ?>) attribute).isOptional()) { context.addError("Illegal use of the remove strategy SET_NULL for non-nullable mapped by attribute '" + mappedBy + "' at " + getLocation() + " Use a different strategy via @MappingInverse(removeStrategy = InverseRemoveStrategy...)"); if (!((SingularAttribute<?, ?>) attribute).isOptional()) { context.addError("Illegal use of the remove strategy SET_NULL for non-nullable mapped by attribute '" + mappedBy + "' because writable mapping '" + value + "' is non-optional at " + getLocation() + " Use a different strategy via @MappingInverse(removeStrategy = InverseRemoveStrategy...)");
Column column = addColumn(mf, String.join("_", attrPath), TypeFacility.getDataTypeName(getJavaDataType(attr.getJavaType())), entityTable); if (((SingularAttribute)attr).isOptional()) { column.setDefaultValue(null); Column column = addColumn(mf, String.join("_", attrPath), DataTypeManager.DefaultDataTypes.STRING, entityTable); if (((SingularAttribute)attr).isOptional()) { column.setDefaultValue(null);
if (attribute instanceof SingularAttribute) optional = ((SingularAttribute) attribute).isOptional();
/** * Gets a single field's metadata from the property descriptor. * * @param persistableClass The class of the data object. * @param attr The singular attribute to process. * @param primaryKeyAttributes The list of primary key attribute names. * @return The DataObjectAttribute containing the metadata for the given attribute on the provided Class */ protected DataObjectAttribute getAttributeMetadata(Class<?> persistableClass, SingularAttribute<?, ?> attr, List<String> primaryKeyAttributes) { DataObjectAttributeImpl attribute = new DataObjectAttributeImpl(); attribute.setOwningType(persistableClass); attribute.setName(attr.getName()); Class<?> propertyType = attr.getJavaType(); attribute.setType(propertyType); DataType dataType = DataType.getDataTypeFromClass(propertyType); if (dataType == null) { dataType = DataType.STRING; } attribute.setDataType(dataType); attribute.setRequired(!attr.isOptional() && !attr.isId() && !primaryKeyAttributes.contains(attr.getName())); populateImplementationSpecificAttributeLevelMetadata(attribute, attr); return attribute; }
protected EdmProperty.Builder toEdmProperty(String modelNamespace, SingularAttribute<?, ?> sa) { String name = sa.getName(); EdmType type; if (sa.getPersistentAttributeType() == PersistentAttributeType.EMBEDDED) { String simpleName = sa.getJavaType().getSimpleName(); // this will map to an edm complex. If anyone ever implements this you // should not create an EdmComplexType. Instead, you should maintain // a cache of EdmComplexType.Builders and re-use instances with the same // namespace.name. (multiple Entity classes may have properties of this // type and we don't wan't lots of instances of EdmComplex type floating // around that are the same conceptual type) type = EdmComplexType.newBuilder().setNamespace(modelNamespace).setName(simpleName).build(); } else if (sa.getBindableJavaType().isEnum()) { // TODO assume string mapping for now, @Enumerated info not avail in metamodel? type = EdmSimpleType.STRING; } else { type = toEdmType(sa); } boolean nullable = sa.isOptional(); Integer maxLength = null; if (sa.getJavaMember() instanceof AnnotatedElement) { Column col = ((AnnotatedElement) sa.getJavaMember()).getAnnotation(Column.class); if (col != null) { if (Enumerable.<EdmType> create(EdmSimpleType.BINARY, EdmSimpleType.STRING).contains(type)) maxLength = col.length(); nullable &= col.nullable(); } } return EdmProperty.newBuilder(name).setType(type).setNullable(nullable).setMaxLength(maxLength); }