private String tryFindSingularIdAttributeNameOrUseFallback(Class<? extends Object> idPropertyValueType, String fallbackIdTypePropertyName) { ManagedType<? extends Object> idPropertyType = metamodel.managedType(idPropertyValueType); for (SingularAttribute<?, ?> sa : idPropertyType.getSingularAttributes()) { if (sa.isId()) { return sa.getName(); } } return fallbackIdTypePropertyName; }
/** * On id. * * @param key * the key * @param attribute * the attribute * @param fieldValue * the field value * @return the object */ private Object onId(Object key, Attribute attribute, Object fieldValue) { if (SingularAttribute.class.isAssignableFrom(attribute.getClass()) && ((SingularAttribute) attribute).isId()) { key = fieldValue; } return key; }
if (!column.isCollection() && !((SingularAttribute) column).isId())
if (!column.isCollection() && !((SingularAttribute) column).isId())
/** * On id attribute. * * @param builder * the builder * @param entityMetadata * the entity metadata * @param clazz * the clazz * @param f * the f */ private void onIdAttribute(final MetaModelBuilder builder, EntityMetadata entityMetadata, final Class clazz, Field f) { EntityType entity = (EntityType) builder.getManagedTypes().get(clazz); Attribute attrib = entity.getAttribute(f.getName()); if (!attrib.isCollection() && ((SingularAttribute) attrib).isId()) { entityMetadata.setIdAttribute((SingularAttribute) attrib); populateIdAccessorMethods(entityMetadata, clazz, f); } }
.getDeclaredSingularAttribute(id); Assert.assertNotNull(rowId); Assert.assertTrue(rowId.isId()); Assert.assertEquals(String.class, rowId.getBindableJavaType()); .getDeclaredAttribute(otherAttribute); Assert.assertNotNull(byteAttribute); Assert.assertFalse(byteAttribute.isId()); Assert.assertEquals(byte[].class, byteAttribute.getBindableJavaType());
Assert.assertTrue(((SingularAttribute) idAttribute).isId());
Assert.assertTrue(((SingularAttribute) idAttribute).isId());
public static boolean isId(Attribute<?,?> a) { if (a instanceof SingularAttribute) return ((SingularAttribute<?,?>)a).isId(); return false; }
String columnName = ((AbstractAttribute) attribute).getJPAColumnName(); if (metaModel.isEmbeddable(relMetadata.getIdAttribute().getBindableJavaType()) && ((SingularAttribute) attribute).isId())
private Object onId(Object key, Attribute attribute, Object fieldValue) { if (SingularAttribute.class.isAssignableFrom(attribute.getClass()) && ((SingularAttribute) attribute).isId()) { key = fieldValue; } return key; }
/** * Populates Node properties from Entity object * * @param entity * @param m * @param node */ private void populateNodeProperties(Object entity, EntityMetadata m, Node node) { MetamodelImpl metaModel = (MetamodelImpl) kunderaMetadata.getApplicationMetadata().getMetamodel( m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); // Iterate over entity attributes Set<Attribute> attributes = entityType.getSingularAttributes(); for (Attribute attribute : attributes) { Field field = (Field) attribute.getJavaMember(); // Set Node level properties if (!attribute.isCollection() && !attribute.isAssociation() && !((SingularAttribute) attribute).isId()) { String columnName = ((AbstractAttribute) attribute).getJPAColumnName(); Object value = PropertyAccessorHelper.getObject(entity, field); if (value != null) { node.setProperty(columnName, toNeo4JProperty(value)); } } } }
@SuppressWarnings({"rawtypes", "unchecked"}) private SingularAttribute<?,?> getIdProperty(EntityType entity) { final Set<SingularAttribute> singularAttributes = entity.getSingularAttributes(); for (final SingularAttribute singularAttribute : singularAttributes) { if (singularAttribute.isId()) { return singularAttribute; } } return null; }
private static Set<SingularAttribute<?, ?>> collectIdAttributes(IdentifiableType<?> entityType) { Set<SingularAttribute<?, ?>> idTypes = new TreeSet<>(ATTRIBUTE_NAME_COMPARATOR); for (SingularAttribute<?, ?> attribute : entityType.getSingularAttributes()) { if (attribute.isId()) { idTypes.add(attribute); } } return idTypes; }
else if (!attr.isCollection() && !((SingularAttribute) attr).isId())
@Override public <Y> void addAttribute(Attribute<X, Y> attribute) { if (attribute instanceof SingularAttribute) { SingularAttribute<? super X, ?> sa = (SingularAttribute<? super X, ?>) attribute; if (sa.isId()) id = sa; if (sa.isVersion()) version = sa; } super.addAttribute(attribute); }
private boolean isId(Type<?> type, Expression idExpression) { AttributeHolder maybeSingularAssociationIdJoinResult = JpaUtils.getAttributeForJoining(metamodel, type, idExpression, null); Attribute<?, ?> maybeSingularAssociationId = maybeSingularAssociationIdJoinResult.getAttribute(); if (!(maybeSingularAssociationId instanceof SingularAttribute<?, ?>)) { return false; } if (!((SingularAttribute<?, ?>) maybeSingularAssociationId).isId()) { return false; } return true; }
private boolean isEmbeddedIdPart(JoinNode baseNode, String field, SingularAttribute<?, ?> attr) { if (attr.getDeclaringType() instanceof EmbeddableType<?>) { ManagedType<?> managedType = baseNode.getManagedType(); if (managedType instanceof EntityType<?>) { int dotIndex = field.indexOf('.'); EntityType<?> entityType = (EntityType<?>) managedType; SingularAttribute<?, ?> potentialIdAttribute = entityType.getSingularAttribute(field.substring(0, dotIndex)); return potentialIdAttribute.isId(); } } return false; }
private String tryFindSingularIdAttributeNameOrUseFallback(Class<? extends Object> idPropertyValueType, String fallbackIdTypePropertyName) { ManagedType<? extends Object> idPropertyType = metamodel.managedType(idPropertyValueType); for (SingularAttribute<?, ?> sa : idPropertyType.getSingularAttributes()) { if (sa.isId()) { return sa.getName(); } } return fallbackIdTypePropertyName; }