@Override @SuppressWarnings({"unchecked"}) public <X, K, V> MapJoin<X, K, V> joinMap(String attributeName, JoinType jt) { final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( !attribute.isCollection() ) { throw new IllegalArgumentException( "Requested attribute was not a map" ); } final PluralAttribute pluralAttribute = (PluralAttribute) attribute; if ( !PluralAttribute.CollectionType.MAP.equals( pluralAttribute.getCollectionType() ) ) { throw new IllegalArgumentException( "Requested attribute was not a map" ); } return (MapJoin<X, K, V>) join( (MapAttribute) attribute, jt ); }
@Override @SuppressWarnings({"unchecked"}) public <X, Y> SetJoin<X, Y> joinSet(String attributeName, JoinType jt) { final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( !attribute.isCollection() ) { throw new IllegalArgumentException( "Requested attribute was not a set" ); } final PluralAttribute pluralAttribute = (PluralAttribute) attribute; if ( !PluralAttribute.CollectionType.SET.equals( pluralAttribute.getCollectionType() ) ) { throw new IllegalArgumentException( "Requested attribute was not a set" ); } return (SetJoin<X, Y>) join( (SetAttribute) attribute, jt ); }
@Override @SuppressWarnings({"unchecked"}) public <X, Y> CollectionJoin<X, Y> joinCollection(String attributeName, JoinType jt) { final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( !attribute.isCollection() ) { throw new IllegalArgumentException( "Requested attribute was not a collection" ); } final PluralAttribute pluralAttribute = (PluralAttribute) attribute; if ( !PluralAttribute.CollectionType.COLLECTION.equals( pluralAttribute.getCollectionType() ) ) { throw new IllegalArgumentException( "Requested attribute was not a collection" ); } return (CollectionJoin<X, Y>) join( (CollectionAttribute) attribute, jt ); }
@Override @SuppressWarnings({"unchecked"}) public <X, Y> ListJoin<X, Y> joinList(String attributeName, JoinType jt) { final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( !attribute.isCollection() ) { throw new IllegalArgumentException( "Requested attribute was not a list" ); } final PluralAttribute pluralAttribute = (PluralAttribute) attribute; if ( !PluralAttribute.CollectionType.LIST.equals( pluralAttribute.getCollectionType() ) ) { throw new IllegalArgumentException( "Requested attribute was not a list" ); } return (ListJoin<X, Y>) join( (ListAttribute) attribute, jt ); }
if (isLeafProperty && !isForSelection && !attribute.isCollection()) { return false;
@Override @SuppressWarnings({"unchecked"}) public <X, Y> Fetch<X, Y> fetch(String attributeName, JoinType jt) { if ( !canBeFetchSource() ) { throw illegalFetch(); } Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( attribute.isCollection() ) { return (Fetch<X, Y>) fetch( (PluralAttribute) attribute, jt ); } else { return (Fetch<X, Y>) fetch( (SingularAttribute) attribute, jt ); } } }
@Override @SuppressWarnings({ "unchecked" }) public <Y> Path<Y> get(String attributeName) { if ( ! canBeDereferenced() ) { throw illegalDereference(); } final Attribute attribute = locateAttribute( attributeName ); if ( attribute.isCollection() ) { final PluralAttribute<X,Y,?> pluralAttribute = (PluralAttribute<X,Y,?>) attribute; if ( PluralAttribute.CollectionType.MAP.equals( pluralAttribute.getCollectionType() ) ) { return (PluralAttributePath<Y>) this.<Object,Object,Map<Object, Object>>get( (MapAttribute) pluralAttribute ); } else { return (PluralAttributePath<Y>) this.get( (PluralAttribute) pluralAttribute ); } } else { return get( (SingularAttribute<X,Y>) attribute ); } }
@Override @SuppressWarnings({"unchecked"}) public <X, Y> Join<X, Y> join(String attributeName, JoinType jt) { if ( !canBeJoinSource() ) { throw illegalJoin(); } if ( jt.equals( JoinType.RIGHT ) ) { throw new UnsupportedOperationException( "RIGHT JOIN not supported" ); } final Attribute<X, ?> attribute = (Attribute<X, ?>) locateAttribute( attributeName ); if ( attribute.isCollection() ) { final PluralAttribute pluralAttribute = (PluralAttribute) attribute; if ( PluralAttribute.CollectionType.COLLECTION.equals( pluralAttribute.getCollectionType() ) ) { return (Join<X, Y>) join( (CollectionAttribute) attribute, jt ); } else if ( PluralAttribute.CollectionType.LIST.equals( pluralAttribute.getCollectionType() ) ) { return (Join<X, Y>) join( (ListAttribute) attribute, jt ); } else if ( PluralAttribute.CollectionType.SET.equals( pluralAttribute.getCollectionType() ) ) { return (Join<X, Y>) join( (SetAttribute) attribute, jt ); } else { return (Join<X, Y>) join( (MapAttribute) attribute, jt ); } } else { return (Join<X, Y>) join( (SingularAttribute) attribute, jt ); } }
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); } }
private <Y> Path<Y> getPath(Attribute attribute,EntityType<Y> entityType,Attribute embeddedAttribute) { Path<Y> path = null; if (attribute.isCollection()) { path = new DefaultPath<Y>(PathType.PLURAL, attribute.getDeclaringType(), attribute, entityType,embeddedAttribute); } else { path = new DefaultPath<Y>(PathType.SINGULAR, attribute.getDeclaringType(), attribute,entityType,embeddedAttribute); } return path; }
/** * On via embeddable. * * @param entityType * the entity type * @param column * the column * @param m * the m * @param entity * the entity * @param embeddable * the embeddable * @param jsonObj * the json obj */ private static void onViaEmbeddable(EntityType entityType, Attribute column, EntityMetadata m, Object entity, EmbeddableType embeddable, JsonObject jsonObj) { Field embeddedField = (Field) column.getJavaMember(); JsonElement embeddedDocumentObject = jsonObj.get(((AbstractAttribute) column).getJPAColumnName()); if (!column.isCollection()) { PropertyAccessorHelper.set( entity, embeddedField, getObjectFromJson(embeddedDocumentObject.getAsJsonObject(), ((AbstractAttribute) column).getBindableJavaType(), embeddable.getAttributes())); } }
/** * Checks whether an entity with given metadata contains a collection field * * @param m * @return */ public static boolean containsBasicElementCollectionField(final EntityMetadata m, final KunderaMetadata kunderaMetadata) { Metamodel metaModel = kunderaMetadata.getApplicationMetadata().getMetamodel(m.getPersistenceUnit()); EntityType entityType = metaModel.entity(m.getEntityClazz()); Iterator<Attribute> iter = entityType.getAttributes().iterator(); while (iter.hasNext()) { Attribute attr = iter.next(); if (attr.isCollection() && !attr.isAssociation() && isBasicElementCollectionField((Field) attr.getJavaMember())) { return true; } } return false; }
for (Attribute attr : attributes) if (!attr.isCollection() && !attr.getName().equalsIgnoreCase(m.getIdAttribute().getName())) else if (attr.isCollection())
if (!attribute.isCollection() && !attribute.isAssociation() && entityMetadata.getIndexProperties().keySet().contains(field.getName()))
if (!attribute.isCollection() && !attribute.isAssociation() && entityMetadata.getIndexProperties().keySet().contains(field.getName()))
if (!attribute.isCollection() && !attribute.isAssociation())
if (column.isCollection())
if (attribute.isCollection())
/** * 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)); } } } }