/** * @param associationMetadata * @return true - is association through third table */ public static boolean isThirdTableAssociation(AssociationKeyMetadata associationMetadata) { return !associationMetadata.getTable().equals( associationMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata().getTable() ); } }
private static String initFindRelationshipQuery(EntityKeyMetadata ownerEntityKeyMetadata, AssociationKeyMetadata associationKeyMetadata) { int offset = 0; StringBuilder queryBuilder = new StringBuilder( "MATCH " ); queryBuilder.append( "(n:" ); queryBuilder.append( ENTITY ); queryBuilder.append( ":" ); appendLabel( ownerEntityKeyMetadata, queryBuilder ); appendProperties( ownerEntityKeyMetadata, queryBuilder ); queryBuilder.append( ") - " ); queryBuilder.append( "[r" ); queryBuilder.append( ":" ); appendRelationshipType( queryBuilder, associationKeyMetadata ); offset = ownerEntityKeyMetadata.getColumnNames().length; if ( associationKeyMetadata.getRowKeyIndexColumnNames().length > 0 ) { appendProperties( queryBuilder, associationKeyMetadata.getRowKeyIndexColumnNames(), offset ); queryBuilder.append( "] - (t" ); } else { queryBuilder.append( "] - (t" ); appendProperties( queryBuilder, associationKeyMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata().getColumnNames(), offset ); } queryBuilder.append( ")" ); queryBuilder.append( " RETURN r" ); return queryBuilder.toString(); }
queryBuilder.append( associationKeyMetadata.isInverse() ? "]- " : "]-> " ); if ( associationKeyMetadata.getAssociationKind() == AssociationKind.ASSOCIATION ) { EntityKeyMetadata associatedEntityMetadata = associationKeyMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata(); appendEntityNode( "target", associatedEntityMetadata, queryBuilder, 0, false );
public IgniteAssociationRowSnapshot(Object id, BinaryObject binaryObject, AssociationKeyMetadata associationMetadata) { this.id = id; this.binaryObject = binaryObject; this.associationMetadata = associationMetadata; this.thirdTableLink = IgniteAssociationSnapshot.isThirdTableAssociation( associationMetadata ); if ( this.thirdTableLink ) { Set<String> cn = new HashSet<>(); Collections.addAll( cn, associationMetadata.getRowKeyColumnNames() ); Collections.addAll( cn, associationMetadata.getAssociatedEntityKeyMetadata().getAssociationKeyColumns() ); this.columnNames = Collections.unmodifiableSet( cn ); this.isSimpleId = true; //vk: not used in this case } else { Set<String> idColumnNames = new HashSet<>(); EntityKeyMetadata entityKeyMetadata = associationMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata(); for ( String columnName : entityKeyMetadata.getColumnNames() ) { if ( entityKeyMetadata.isKeyColumn( columnName ) ) { idColumnNames.add( columnName ); } } if ( idColumnNames.isEmpty() ) { throw new UnsupportedOperationException( "There is no id column in entity " + entityKeyMetadata.getTable() + ". Hmm..." ); } this.columnNames = CollectionHelper.asSet( entityKeyMetadata.getColumnNames() ); this.isSimpleId = idColumnNames.size() == 1; } }
/** * Returns the entity key on the other side of association row represented by the given row key. * <p> * <b>Note:</b> May only be invoked if the row key actually contains all the columns making up that entity key. * Specifically, it may <b>not</b> be invoked if the association has index columns (maps, ordered collections), as * the entity key columns will not be part of the row key in this case. */ private EntityKey getEntityKey(AssociationKey associationKey, RowKey rowKey) { String[] associationKeyColumns = associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns(); Object[] columnValues = new Object[associationKeyColumns.length]; int i = 0; for ( String associationKeyColumn : associationKeyColumns ) { columnValues[i] = rowKey.getColumnValue( associationKeyColumn ); i++; } EntityKeyMetadata entityKeyMetadata = associationKey.getMetadata().getAssociatedEntityKeyMetadata().getEntityKeyMetadata(); return new EntityKey( entityKeyMetadata, columnValues ); }
/** * Returns the shared prefix with a trailing dot (.) of the association columns or {@literal null} if there is no shared prefix. * * @param associationKey the association key * * @return the shared prefix with a trailing dot (.) of the association columns or {@literal null} */ public static String getColumnSharedPrefixOfAssociatedEntityLink(AssociationKey associationKey) { String[] associationKeyColumns = associationKey.getMetadata() .getAssociatedEntityKeyMetadata() .getAssociationKeyColumns(); // we used to check that columns are the same (in an ordered fashion) // but to handle List and Map and store indexes / keys at the same level as the id columns // this check is removed String prefix = DocumentHelpers.getColumnSharedPrefix( associationKeyColumns ); return prefix == null ? "" : prefix + "."; } }
/** * Returns the entity key on the other side of association row represented by the given row key. * <p> * <b>Note:</b> May only be invoked if the row key actually contains all the columns making up that entity key. * Specifically, it may <b>not</b> be invoked if the association has index columns (maps, ordered collections), as * the entity key columns will not be part of the row key in this case. */ private EntityKey getEntityKey(AssociationKey associationKey, RowKey rowKey) { String[] associationKeyColumns = associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns(); Object[] columnValues = new Object[associationKeyColumns.length]; int i = 0; for ( String associationKeyColumn : associationKeyColumns ) { columnValues[i] = rowKey.getColumnValue( associationKeyColumn ); i++; } EntityKeyMetadata entityKeyMetadata = associationKey.getMetadata().getAssociatedEntityKeyMetadata().getEntityKeyMetadata(); return new EntityKey( entityKeyMetadata, columnValues ); }
appendProperties( queryBuilder, associationKeyMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata().getColumnNames(), offset );
private static String initCreateRelationshipQuery(EntityKeyMetadata ownerEntityKeyMetadata, AssociationKeyMetadata associationKeyMetadata) { EntityKeyMetadata targetEntityKeyMetadata = associationKeyMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata(); int offset = 0; StringBuilder queryBuilder = new StringBuilder( "MATCH " ); appendEntityNode( "n", ownerEntityKeyMetadata, queryBuilder ); queryBuilder.append( ", " ); offset += ownerEntityKeyMetadata.getColumnNames().length; appendEntityNode( "t", targetEntityKeyMetadata, queryBuilder, offset ); queryBuilder.append( " MERGE (n)" ); queryBuilder.append( " -[r" ); queryBuilder.append( ":" ); appendRelationshipType( queryBuilder, associationKeyMetadata ); offset = ownerEntityKeyMetadata.getColumnNames().length; if ( associationKeyMetadata.getRowKeyIndexColumnNames().length > 0 ) { offset += targetEntityKeyMetadata.getColumnNames().length; appendProperties( queryBuilder, associationKeyMetadata.getRowKeyIndexColumnNames(), offset ); } queryBuilder.append( "]-> (t)" ); queryBuilder.append( " RETURN r" ); return queryBuilder.toString(); }
private boolean isAJoinColumn(AssociationKey key) { AssociationKeyMetadata metadata = key.getMetadata(); if ( AssociationKind.EMBEDDED_COLLECTION.equals( metadata.getAssociationKind() ) ) { return false; } AssociatedEntityKeyMetadata entityKeyMetadata = metadata.getAssociatedEntityKeyMetadata(); return metadata.getTable().equals( entityKeyMetadata.getEntityKeyMetadata().getTable() ); }
.getAssociatedEntityKeyMetadata() .getAssociationKeyColumns(); .getAssociatedEntityKeyMetadata() .getAssociationKeyColumns() ) { associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns()[0], mapRow );
public Object createAssociationKeyObject( RowKey rowKey, AssociationKeyMetadata keyMetadata ) { Object result = null; if ( IgniteAssociationSnapshot.isThirdTableAssociation( keyMetadata ) ) { result = UUID.randomUUID().toString(); } else { String associationKeyColumns[] = keyMetadata.getAssociatedEntityKeyMetadata().getAssociationKeyColumns(); if ( associationKeyColumns.length == 1 ) { result = rowKey.getColumnValue( associationKeyColumns[0] ); } else { BinaryObjectBuilder builder = createBinaryObjectBuilder( findKeyType( keyMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata() ) ); for ( int i = 0; i < associationKeyColumns.length; i++ ) { builder.setField( StringHelper.stringAfterPoint( associationKeyColumns[i] ), rowKey.getColumnValue( associationKeyColumns[i] ) ); } result = builder.build(); } } return result; }
queryBuilder.append( EMBEDDED ); queryBuilder.append( ":" ); escapeIdentifier( queryBuilder, associationKey.getMetadata().getAssociatedEntityKeyMetadata().getEntityKeyMetadata().getTable() ); int index = 0; int embeddedNumber = 0;
.getAssociatedEntityKeyMetadata() .getAssociationKeyColumns(); for ( String column : associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns() ) { row.put( associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns()[0], mapRow );
.getAssociatedEntityKeyMetadata() .getAssociationKeyColumns(); for ( String column : associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns() ) { row.put( associationKey.getMetadata().getAssociatedEntityKeyMetadata().getAssociationKeyColumns()[0], mapRow );
queryBuilder.append( EMBEDDED ); queryBuilder.append( ":" ); escapeIdentifier( queryBuilder, associationKey.getMetadata().getAssociatedEntityKeyMetadata().getEntityKeyMetadata().getTable() );
@Override public Object get(String column) { Object result = null; if ( !isEmpty() ) { if ( !thirdTableLink && associationMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata().isKeyColumn( column ) ) { result = isSimpleId ? id : ( (BinaryObject) id ).field( StringHelper.stringAfterPoint( column ) ); } else { result = binaryObject.field( StringHelper.realColumnName( column ) ); } } return result; }
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 ); } }
@Override @SuppressWarnings("unchecked") public AssociationRow<?> createAssociationRow(AssociationKey associationKey, Object row) { R rowObject = null; AssociationRowAccessor<R> accessor; if ( associationRowType.isInstance( row ) ) { // if the columns are only made of the embedded id columns, add back the embedded id property prefix // { id1: "foo", id2: "bar" } becomes { embeddedid.id1: "foo", "embeddedid.id2: "bar" } String[] associationKeyColumns = associationKey.getMetadata() .getAssociatedEntityKeyMetadata() .getAssociationKeyColumns(); String prefix = DocumentHelpers.getColumnSharedPrefix( associationKeyColumns ); // pass the columns that are not prefixed and the prefix accessor = getAssociationRowAccessor( associationKeyColumns, prefix ); rowObject = (R) row; } else { accessor = getAssociationRowAccessor( null, null ); String columnName = associationKey.getMetadata().getSingleRowKeyColumnNotContainedInAssociationKey(); Contracts.assertNotNull( columnName, "columnName" ); rowObject = getSingleColumnRow( columnName, row ); } return new AssociationRow<R>( associationKey, accessor, rowObject ); }
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() ) ); } } }