if ((relationValue != null && relation.isUnary()) || (relation.isJoinedByPrimaryKey())) Object relationEntity = pd.getClient(targetEntityMetadata).find(relation.getTargetEntity(), relationValue != null ? relationValue : entityId); if (relationEntity != null) else if (!relation.isUnary()) relation.getProperty().getDeclaringClass(), entityId, targetEntityMetadata.getEntityClazz(), associatedClient); relationalEntities = associatedClient.findByRelation(relation.getJoinColumnName(kunderaMetadata), entityId, relation.getTargetEntity());
FetchType fetchType = relation.getFetchType(); if (relation.isUnary() && relation.getTargetEntity().isAssignableFrom(originalEntity.getClass())) relation.getProperty()); if (relation.getType().equals(ForeignKey.ONE_TO_ONE)) PropertyAccessorHelper.set(relationEntity, relation.getProperty(), originalEntity); && relationsMap.containsKey(relation.getJoinColumnName(kunderaMetadata))) PropertyAccessorHelper.set(relationEntity, relation.getProperty(), originalEntity); .getJoinColumnName(kunderaMetadata)) : null; final EntityMetadata targetEntityMetadata = KunderaMetadataManager.getEntityMetadata( kunderaMetadata, relation.getTargetEntity()); List immediateRelations = fetchRelations(relation, metadata, pd, entityId, relationValue, targetEntityMetadata);
relation.getTargetEntity()); if (((relation.getType().equals(ForeignKey.ONE_TO_ONE) && !relation.isJoinedByPrimaryKey()) || relation .getType().equals(ForeignKey.MANY_TO_MANY)) && relation.getMappedBy() == null) else if (relation.getType().equals(ForeignKey.ONE_TO_MANY) && relation.getMappedBy() == null)
/** * * @param metadata * Entity metadata of the parent node * @param relation * @return */ private Map<LinkProperty, Object> getLinkProperties(EntityMetadata metadata, Relation relation, final KunderaMetadata kunderaMetadata) { Map<LinkProperty, Object> linkProperties = new HashMap<NodeLink.LinkProperty, Object>(); linkProperties.put(LinkProperty.LINK_NAME, MetadataUtils.getMappedName(metadata, relation, kunderaMetadata)); linkProperties.put(LinkProperty.IS_SHARED_BY_PRIMARY_KEY, relation.isJoinedByPrimaryKey()); linkProperties.put(LinkProperty.IS_BIDIRECTIONAL, !relation.isUnary()); linkProperties.put(LinkProperty.IS_RELATED_VIA_JOIN_TABLE, relation.isRelatedViaJoinTable()); linkProperties.put(LinkProperty.PROPERTY, relation.getProperty()); linkProperties.put(LinkProperty.CASCADE, relation.getCascades()); if (relation.isRelatedViaJoinTable()) { linkProperties.put(LinkProperty.JOIN_TABLE_METADATA, relation.getJoinTableMetadata()); } return linkProperties; }
/** * Method to add specific relation name for given relational field. * * @param rField * relation object. */ private void addRelationName(Relation rField) { if (rField != null && !rField.isRelatedViaJoinTable()) { String relationName = getJoinColumnName(rField.getProperty()); if (rField.getProperty().isAnnotationPresent(PrimaryKeyJoinColumn.class)) { relationName = this.getIdAttribute().getName(); } addToRelationNameCollection(relationName); } }
/** * Adds the join table. * * @param relations * the relations */ private void addJoinTable(List<Relation> relations) { for (Relation relation : relations) { if (relation.getType().equals(ForeignKey.MANY_TO_MANY) && relation.isRelatedViaJoinTable()) { String joinTableName = relation.getJoinTableMetadata().getJoinTableName(); String hTableName = HBaseUtils.getHTableName(databaseName, joinTableName); HTableDescriptor tableDescriptor = new HTableDescriptor(TableName.valueOf(hTableName)); tableDescriptor.addFamily(new HColumnDescriptor(joinTableName)); createOrUpdateTable(hTableName, tableDescriptor); } } }
AbstractAttribute attribute = (AbstractAttribute) entityType.getAttribute(relation.getProperty().getName()); boolean optional = false; if (attribute instanceof SingularAttribute) EntityMetadata associatedMetadata = metaModel.getEntityMetadata(relation.getTargetEntity()); EntityType associatedEntityType = metaModel.entity(associatedMetadata.getEntityClazz()); String joinColumn = relation.getJoinColumnName(kunderaMetadata); String localField = metadata.getFieldName(joinColumn); String foreignField = associatedMetadata.getFieldName(joinColumn); .contains(relation.getType()))
Class<?> targetEntityClass = relation.getTargetEntity(); EntityMetadata targetEntityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, targetEntityClass); Field property = relation.getProperty(); if (relation.getPropertyType().isAssignableFrom(Map.class)) DynamicRelationshipType.withName(relation.getJoinColumnName(kunderaMetadata)))) Field bidirectionalField = relation.getBiDirectionalField(); Map<Object, Object> sourceEntitiesMap = new HashMap<Object, Object>(); if (bidirectionalField != null) DynamicRelationshipType.withName(relation.getJoinColumnName(kunderaMetadata)))) Class<?> relationshipClass = relation.getMapKeyJoinClass(); for (Field f : relationshipClass.getDeclaredFields()) DynamicRelationshipType.withName(relation.getJoinColumnName(kunderaMetadata)))) relationMap.put(relation.getJoinColumnName(kunderaMetadata), targetEntitiesMap);
for (Relation rel : relationsMap.values()) if (rel.getMapKeyJoinClass() != null) builder.append(" --- via ").append(rel.getMapKeyJoinClass().getSimpleName()).append(" ---\n"); builder.append("\t\t" + rel.getTargetEntity().getName() + "#" + rel.getProperty().getName()); builder.append(" (" + rel.getCascades()); builder.append(", " + rel.getType()); builder.append(", " + rel.getFetchType()); builder.append(")\n");
if ((relation.getType().equals(ForeignKey.ONE_TO_ONE) || relation.getType().equals(ForeignKey.MANY_TO_ONE))) Field biDirectionalField = relation.getBiDirectionalField(); boolean isBidirectionalRelation = (biDirectionalField != null); if (isBidirectionalRelation && (relationValue == null && !relation.isJoinedByPrimaryKey())) relation.getTargetEntity()); Object owner = null; + relation.getProperty().getName(); + relation.getProperty().getName() + "_" + relationValue); Object proxy = getLazyEntity(entityName, relation.getTargetEntity(), parentEntityMetadata.getReadIdentifierMethod(), parentEntityMetadata.getWriteIdentifierMethod(), relationValue, pd); PropertyAccessorHelper.set(entity, relation.getProperty(), proxy); + relation.getProperty().getName() + "_" + relationValue); + relation.getProperty().getName(); Object proxy = getLazyEntity(entityName, relation.getTargetEntity(), m.getReadIdentifierMethod(), m.getWriteIdentifierMethod(), relationValue, pd); PropertyAccessorHelper.set(entity, relation.getProperty(), proxy); else if (relation.isJoinedByPrimaryKey()) + relation.getProperty().getName() + "_" + relationValue);
Class entityClass = relation.getTargetEntity(); EntityMetadata targetEntityMetadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, entityClass); ForeignKey relationType = relation.getType(); && relation.getJoinColumnName(kunderaMetadata) != null) tableInfo.addColumnInfo(getJoinColumn(tableInfo, relation.getJoinColumnName(kunderaMetadata), entityMetadata.getIdAttribute().getJavaType())); addJoinColumnToInfo(relation.getJoinColumnName(kunderaMetadata), targetTableInfo, targetTableInfos, entityMetadata); addJoinColumnToInfo(relation.getJoinColumnName(kunderaMetadata), targetTableInfo, tableInfos, entityMetadata); else if (relation.isUnary() && relation.getJoinColumnName(kunderaMetadata) != null) if (!relation.isJoinedByPrimaryKey()) tableInfo.addColumnInfo(getJoinColumn(tableInfo, relation.getJoinColumnName(kunderaMetadata), targetEntityMetadata.getIdAttribute().getJavaType())); JoinTableMetadata joinTableMetadata = relation.getJoinTableMetadata(); String joinTableName = joinTableMetadata != null ? joinTableMetadata.getJoinTableName() : null; String joinColumnName = joinTableMetadata != null
f = relation.getProperty(); .entity(relation.getTargetEntity()).getAttribute(embeddableAttributeAsStr); String targetColumnName = targetAttribute.getJPAColumnName(); && ((DefaultSingularAttribute) targetAttribute).isId()) property = relation.getJoinColumnName(kunderaMetadata);
/** * Returns mapped relational name, in case of bi directional mapping, it * will return back pKey name of associated entity. * * @param relation * holding relation. * @return mapped/join column name. */ public static String getMappedName(EntityMetadata parentMetadata, Relation relation, final KunderaMetadata kunderaMetadata) { if (relation != null) { String joinColumn = relation.getJoinColumnName(kunderaMetadata); if (joinColumn == null) { Class clazz = relation.getTargetEntity(); EntityMetadata metadata = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, clazz); joinColumn = relation.getType().equals(ForeignKey.ONE_TO_MANY) ? ((AbstractAttribute) parentMetadata .getIdAttribute()).getJPAColumnName() : ((AbstractAttribute) metadata.getIdAttribute()) .getJPAColumnName(); } return joinColumn; } return null; }
PersistenceDelegator delegator, Relation relation) JoinTableMetadata jtMetadata = relation.getJoinTableMetadata(); Client pClient = delegator.getClient(entityMetadata); relation.getTargetEntity()); Class columnJavaType = owningEntityMetadata.getIdAttribute().getJavaType(); if (jtMetadata == null) Relation owningEntityMetadataRelation = owningEntityMetadata.getRelation(relation.getMappedBy()); jtMetadata = owningEntityMetadataRelation.getJoinTableMetadata(); pClient = delegator.getClient(owningEntityMetadata); schema = owningEntityMetadata.getSchema(); relation.getTargetEntity()); Object child = delegator.find(relation.getTargetEntity(), foreignKey); Object obj = child instanceof EnhanceEntity && child != null ? ((EnhanceEntity) child).getEntity() : child; Field biDirectionalField = relation.getBiDirectionalField(); boolean isBidirectionalRelation = (biDirectionalField != null); Field childField = relation.getProperty();
r != null ? r : relation) && rel != null && !rel.getProperty().isAnnotationPresent(ManyToMany.class) && !rel.getProperty().isAnnotationPresent(OneToMany.class) && (rel.getProperty().isAnnotationPresent(OneToOne.class) && StringUtils.isBlank(rel.getMappedBy()) || rel.getProperty().isAnnotationPresent( ManyToOne.class))) if (!r.getType().equals(ForeignKey.MANY_TO_MANY) && (r.getProperty().isAnnotationPresent(OneToOne.class) && StringUtils.isBlank(r.getMappedBy()) || r .getProperty().isAnnotationPresent(ManyToOne.class))) queryBuilder.append(r.getJoinColumnName());
List<Relation> relations = metadata.getRelations(); for (Relation relation : relations) { if (relation.getType().equals(ForeignKey.MANY_TO_ONE) || relation.getType().equals(ForeignKey.ONE_TO_ONE)) { String propertyName = relation.getJoinColumnName(null); if (propertyName != null && columnsNameToBeIndexed.contains(propertyName)) { java.lang.reflect.Field property = relation.getProperty(); Object obj = PropertyAccessorHelper.getObject(entity, property); if (obj != null) {
name != null ? name : r) && rel != null && !rel.getProperty().isAnnotationPresent(ManyToMany.class) && !rel.getProperty().isAnnotationPresent(OneToMany.class) && (rel.getProperty().isAnnotationPresent(OneToOne.class) && StringUtils.isBlank(rel.getMappedBy()) || rel.getProperty().isAnnotationPresent( ManyToOne.class)))
/** * After successfully parsing set relational entity object within entity * object. * * @param entity * @param relationEntity * @param relation */ private void setRelationToEntity(Object entity, Object relationEntity, Relation relation) { if (relation.getTargetEntity().isAssignableFrom(getEntity(relationEntity).getClass())) { if (relation.isUnary()) { PropertyAccessorHelper.set(entity, relation.getProperty(), getEntity(relationEntity)); } else { Object associationObject = PropertyAccessorHelper.getObject(entity, relation.getProperty()); if (associationObject == null || ProxyHelper.isProxyOrCollection(associationObject)) { associationObject = PropertyAccessorHelper.getCollectionInstance(relation.getProperty()); PropertyAccessorHelper.set(entity, relation.getProperty(), associationObject); } ((Collection) associationObject).add(getEntity(relationEntity)); } } }
@Test public void testMetamodel() { EntityMetadata m1 = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, Actor.class); Assert.assertNotNull(m1); Assert.assertEquals(Actor.class, m1.getEntityClazz()); Assert.assertEquals(Role.class, m1.getRelation("movies").getMapKeyJoinClass()); Assert.assertEquals(Movie.class, m1.getRelation("movies").getTargetEntity()); Assert.assertEquals("ACTS_IN", m1.getRelation("movies").getJoinColumnName(kunderaMetadata)); EntityMetadata m2 = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, Movie.class); Assert.assertNotNull(m2); Assert.assertEquals(Movie.class, m2.getEntityClazz()); Assert.assertEquals(Role.class, m2.getRelation("actors").getMapKeyJoinClass()); Assert.assertEquals(Actor.class, m2.getRelation("actors").getTargetEntity()); Assert.assertNotNull(m2.getRelation("actors").getJoinColumnName(kunderaMetadata)); Assert.assertEquals(m2.getRelation("actors").getJoinColumnName(kunderaMetadata),"actors"); EntityMetadata m3 = KunderaMetadataManager.getEntityMetadata(kunderaMetadata, Role.class); Assert.assertNotNull(m3); Assert.assertEquals(Role.class, m3.getEntityClazz()); Metamodel mm = KunderaMetadataManager.getMetamodel(kunderaMetadata, "imdb"); Assert.assertNotNull(mm); }
relation.getTargetEntity()); Class<?> relationshipClass = relation.getMapKeyJoinClass(); for (Field f : relationshipClass.getDeclaredFields()) PropertyAccessorHelper.set(entity, relation.getProperty(), relObject);