private static void appendRelationshipType(StringBuilder queryBuilder, AssociationKeyMetadata associationKeyMetadata) { escapeIdentifier( queryBuilder, associationKeyMetadata.getCollectionRole() ); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append( getClass().getSimpleName() ); sb.append( "[" ); sb.append( getEntityKey() ); sb.append( ", collectionRole=" ); sb.append( getAssociationKey().getMetadata().getCollectionRole() ); sb.append( "]" ); return sb.toString(); }
@Override public String toString() { StringBuilder sb = new StringBuilder(); sb.append( getClass().getSimpleName() ); sb.append( "[" ); sb.append( getEntityKey() ); sb.append( ", collectionRole=" ); sb.append( getAssociationKey().getMetadata().getCollectionRole() ); sb.append( "]" ); return sb.toString(); }
public String getFindAssociationQuery(String relationshipType, AssociationKeyMetadata associationKeyMetadata) { return findAssociationQueryCache.computeIfAbsent( associationKeyMetadata.getCollectionRole(), role -> completeFindAssociationQuery( relationshipType, associationKeyMetadata ) ); }
@Override public void setRows(Object rows) { EntityDocument entity = getEntity(); if ( isEmpty( rows ) ) { entity.unset( associationKeyMetadata.getCollectionRole() ); } else { entity.unset( associationKeyMetadata.getCollectionRole() ); if ( associationKeyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE && rows instanceof Collection ) { Object value = ( (Collection<?>) rows ).iterator().next(); entity.set( associationKeyMetadata.getCollectionRole(), value ); } else { entity.set( associationKeyMetadata.getCollectionRole(), rows ); } } }
private static Document getProjection(AssociationKey key, boolean embedded) { if ( embedded ) { return getProjection( Collections.singletonList( key.getMetadata().getCollectionRole() ) ); } else { return getProjection( ROWS_FIELDNAME_LIST ); } }
private static Document getProjection(AssociationKey key, boolean embedded) { if ( embedded ) { return getProjection( Collections.singletonList( key.getMetadata().getCollectionRole() ) ); } else { return getProjection( ROWS_FIELDNAME_LIST ); } }
public Association getAssociationOrNull() { if ( association == null ) { if ( hostingEntity != null ) { OgmEntityEntryState entryState = OgmEntityEntryState.getStateFor( session, hostingEntity ); if ( entryState.hasAssociation( associationKeyMetadata.getCollectionRole() ) ) { association = entryState.getAssociation( associationKeyMetadata.getCollectionRole() ); return association; } } if ( association == null ) { association = gridDialect.getAssociation( getAssociationKey(), getAssociationContext() ); if ( hostingEntity != null ) { OgmEntityEntryState.getStateFor( session, hostingEntity ) .setAssociation( associationKeyMetadata.getCollectionRole(), association ); } } } return association; }
private static Node findOwnerNode(Relationship relationship, AssociationKey associationKey) { if ( isEmbeddedCollection( associationKey ) ) { String collectionRole = associationKey.getMetadata().getCollectionRole(); return embeddedAssociationOwner( relationship, collectionRole ); } else { return ownerNodeFromAssociation( associationKey, relationship ); } }
@Override @SuppressWarnings("unchecked") public Object getRows() { Object rows; Object fieldValue = DotPatternMapHelpers.getValueOrNull( getEntity().getPropertiesAsHierarchy(), associationKeyMetadata.getCollectionRole() ); if ( fieldValue == null ) { rows = Collections.emptyList(); } else if ( associationKeyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE ) { rows = fieldValue; } else { rows = fieldValue; } return rows; }
private static Collection<?> getRows(Document document, AssociationKey associationKey, AssociationStorageStrategy storageStrategy) { Collection<?> rows = null; if ( associationKey.getMetadata().getAssociationType() == AssociationType.ONE_TO_ONE ) { Object oneToOneValue = getValueOrNull( document, associationKey.getMetadata().getCollectionRole(), Object.class ); if ( oneToOneValue != null ) { rows = Collections.singletonList( oneToOneValue ); } } else { Object toManyValue; if ( storageStrategy == AssociationStorageStrategy.IN_ENTITY ) { toManyValue = getValueOrNull( document, associationKey.getMetadata().getCollectionRole() ); } else { toManyValue = document.get( MongoDBDialect.ROWS_FIELDNAME ); } // list of rows if ( toManyValue instanceof Collection ) { rows = (Collection<?>) toManyValue; } // a map-typed association, rows are organized by row key else if ( toManyValue instanceof Document ) { rows = getRowsFromMapAssociation( associationKey, (Document) toManyValue ); } } return rows != null ? rows : Collections.emptyList(); }
private static Collection<?> getRows(Document document, AssociationKey associationKey, AssociationStorageStrategy storageStrategy) { Collection<?> rows = null; if ( associationKey.getMetadata().getAssociationType() == AssociationType.ONE_TO_ONE ) { Object oneToOneValue = getValueOrNull( document, associationKey.getMetadata().getCollectionRole(), Object.class ); if ( oneToOneValue != null ) { rows = Collections.singletonList( oneToOneValue ); } } else { Object toManyValue; if ( storageStrategy == AssociationStorageStrategy.IN_ENTITY ) { toManyValue = getValueOrNull( document, associationKey.getMetadata().getCollectionRole() ); } else { toManyValue = document.get( MongoDBDialect.ROWS_FIELDNAME ); } // list of rows if ( toManyValue instanceof Collection ) { rows = (Collection<?>) toManyValue; } // a map-typed association, rows are organized by row key else if ( toManyValue instanceof Document ) { rows = getRowsFromMapAssociation( associationKey, (Document) toManyValue ); } } return rows != null ? rows : Collections.emptyList(); }
protected String initCreateEmbeddedAssociationQuery(AssociationKey associationKey, EntityKey embeddedKey) { String collectionRole = associationKey.getMetadata().getCollectionRole(); String[] embeddedColumnNames = embeddedKey.getColumnNames(); Object[] embeddedColumnValues = embeddedKey.getColumnValues(); String[] columnNames = associationKey.getEntityKey().getMetadata().getColumnNames(); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append( matchOwnerEntityNode ); if ( isCollectionOfPrimitives( collectionRole, embeddedColumnNames ) ) { createRelationshipForCollectionOfPrimitivesOrMap( associationKey, collectionRole, columnNames, queryBuilder ); } else { createRelationshipforCollectionOfComponents( associationKey, collectionRole, embeddedColumnNames, embeddedColumnValues, queryBuilder ); } return queryBuilder.toString(); }
@Override protected String initCreateEmbeddedAssociationQuery(AssociationKey associationKey, EntityKey embeddedKey) { String collectionRole = associationKey.getMetadata().getCollectionRole(); String[] embeddedColumnNames = embeddedKey.getColumnNames(); Object[] embeddedColumnValues = embeddedKey.getColumnValues(); String[] columnNames = associationKey.getEntityKey().getMetadata().getColumnNames(); StringBuilder queryBuilder = new StringBuilder(); queryBuilder.append( matchOwnerEntityNode ); if ( isCollectionOfPrimitives( collectionRole, embeddedColumnNames ) ) { createRelationshipForCollectionOfPrimitivesOrMap( associationKey, collectionRole, columnNames, queryBuilder ); } else { createRelationshipforCollectionOfComponents( associationKey, collectionRole, embeddedColumnNames, embeddedColumnValues, queryBuilder ); } return queryBuilder.toString(); }
public AssociationTypeContextImpl build() { OptionsContext hostingPropertyOptions = serviceContext.getPropertyOptions( hostingEntityPersister.getMappedClass(), associationKeyMetadata.getCollectionRole() ); OptionsContext hostingEntityOptions = serviceContext.getEntityOptions( hostingEntityPersister.getEntityType().getReturnedClass() ); TupleTypeContext tupleTypeContext = hostingEntityPersister.getTupleTypeContext(); return new AssociationTypeContextImpl( hostingPropertyOptions, hostingEntityOptions, tupleTypeContext, associationKeyMetadata.getAssociatedEntityKeyMetadata(), mainSidePropertyName ); } }
private Relationship createRelationshipWithTargetNode(AssociationKey associationKey, Tuple associationRow, TupleTypeContext tupleTypeContext, Node targetNode) { EntityKey entityKey = associationKey.getEntityKey(); Node ownerNode = getEntityQueries( entityKey.getMetadata(), tupleTypeContext ).findEntity( dataBase, entityKey.getColumnValues() ); Relationship relationship = ownerNode.createRelationshipTo( targetNode, withName( associationKey.getMetadata().getCollectionRole() ) ); applyProperties( associationKey, associationRow, relationship ); return relationship; }
protected Object[] createRelationshipForEmbeddedQueryValues(AssociationKey associationKey, EntityKey embeddedKey) { String collectionRole = associationKey.getMetadata().getCollectionRole(); Object[] columnValues = associationKey.getEntityKey().getColumnValues(); if ( isCollectionOfPrimitives( collectionRole, embeddedKey.getColumnNames() ) ) { return ArrayHelper.concat( columnValues, embeddedKey.getColumnValues()[0] ); } else { return ArrayHelper.concat( columnValues, embeddedKey.getColumnValues() ); } }
public IgniteEmbeddedAssociationSnapshot(AssociationKey associationKey, Tuple tuple) { this.associationMetadata = associationKey.getMetadata(); this.tuple = tuple; BinaryObject obj = ( (IgniteTupleSnapshot) tuple.getSnapshot() ).getCacheValue(); Object objects[] = obj != null ? (Object[]) obj.field( StringHelper.realColumnName( associationMetadata.getCollectionRole() ) ) : null; rows = new HashMap<>(); if ( objects != null ) { String rowKeyColumnNames[] = new String[ associationMetadata.getRowKeyColumnNames().length ]; for ( int i = 0; i < rowKeyColumnNames.length; i++ ) { rowKeyColumnNames[i] = StringHelper.stringAfterPoint( associationMetadata.getRowKeyColumnNames()[i] ); } for ( int i = 0; i < objects.length; i++ ) { BinaryObject itemObject = (BinaryObject) objects[i]; Object rowKeyColumnValues[] = new Object[rowKeyColumnNames.length]; for ( int j = 0; j < rowKeyColumnNames.length; j++ ) { rowKeyColumnValues[j] = itemObject.field( rowKeyColumnNames[j] ); } RowKey rowKey = new RowKey( associationMetadata.getRowKeyColumnNames(), rowKeyColumnValues ); this.rows.put( rowKey, new IgniteTupleSnapshot( null, itemObject, associationMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata() ) ); } } }
/** * Writes out the changes gathered in the {@link Association} managed by this persister to the datastore. */ public void flushToDatastore() { if ( getAssociation().isEmpty() ) { gridDialect.removeAssociation( getAssociationKey(), getAssociationContext() ); association = null; OgmEntityEntryState.getStateFor( session, hostingEntity ).setAssociation( associationKeyMetadata.getCollectionRole(), null ); } else if ( !getAssociation().getOperations().isEmpty() ) { gridDialect.insertOrUpdateAssociation( getAssociationKey(), getAssociation(), getAssociationContext() ); } updateHostingEntityIfRequired(); }
private void addNavigationalInformationForInverseSide(int propertyIndex, AssociationKeyMetadata associationKeyMetadata, Object[] newColumnValue) { RowKey rowKey = getInverseRowKey( associationKeyMetadata, newColumnValue ); Tuple associationRow = new Tuple(); for ( String column : rowKey.getColumnNames() ) { associationRow.put( column, rowKey.getColumnValue( column ) ); } AssociationPersister associationPersister = createInverseAssociationPersister( propertyIndex, associationKeyMetadata, newColumnValue ); associationPersister.getAssociation().put( rowKey, associationRow ); if ( associationPersister.getAssociationContext().getEntityTuplePointer().getTuple() == null ) { throw log.entityTupleNotFound( associationKeyMetadata.getCollectionRole(), associationPersister.getAssociationKey().getEntityKey() ); } associationPersister.flushToDatastore(); }