public static AssociationStorageStrategy getInstance(AssociationKeyMetadata keyMetadata, AssociationStorageType associationStorage, AssociationDocumentStorageType associationDocumentStorage) { if ( keyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE || keyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION || associationStorage == AssociationStorageType.IN_ENTITY ) { return IN_ENTITY; } else if ( associationDocumentStorage == AssociationDocumentStorageType.COLLECTION_PER_ASSOCIATION ) { return COLLECTION_PER_ASSOCIATION; } else { return GLOBAL_COLLECTION; } } }
public static AssociationStorageStrategy getInstance(AssociationKeyMetadata keyMetadata, AssociationStorageType associationStorage, AssociationDocumentStorageType associationDocumentStorage) { if ( keyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE || keyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION || associationStorage == AssociationStorageType.IN_ENTITY ) { return IN_ENTITY; } else if ( associationDocumentStorage == AssociationDocumentStorageType.COLLECTION_PER_ASSOCIATION ) { return COLLECTION_PER_ASSOCIATION; } else { return GLOBAL_COLLECTION; } } }
private static boolean isEmbeddedAssociation(AssociationKey key) { return AssociationKind.EMBEDDED_COLLECTION == key.getMetadata().getAssociationKind(); }
private static boolean isEmbeddedAssociation(AssociationKey key) { return AssociationKind.EMBEDDED_COLLECTION == key.getMetadata().getAssociationKind(); }
private static boolean isEmbeddedCollection(AssociationKey associationKey) { return associationKey.getMetadata().getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION; }
private static String initRemoveAssociationQuery(EntityKeyMetadata ownerEntityKeyMetadata, AssociationKeyMetadata associationKeyMetadata) { StringBuilder queryBuilder = new StringBuilder( "MATCH " ); queryBuilder.append( "(n:" ); queryBuilder.append( ENTITY ); queryBuilder.append( ":" ); appendLabel( ownerEntityKeyMetadata, queryBuilder ); appendProperties( ownerEntityKeyMetadata, queryBuilder ); queryBuilder.append( ") - " ); queryBuilder.append( "[a" ); queryBuilder.append( ":" ); appendRelationshipType( queryBuilder, associationKeyMetadata ); queryBuilder.append( "]" ); if ( associationKeyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION ) { queryBuilder.append( " - (e:" ); queryBuilder.append( EMBEDDED ); queryBuilder.append( ")" ); queryBuilder.append( " WITH a,e" ); queryBuilder.append( " MATCH path=(e) -[*0..]-> (:EMBEDDED) " ); queryBuilder.append( " FOREACH ( r IN relationships(path) | DELETE r )" ); queryBuilder.append( " FOREACH ( e IN nodes(path) | DELETE e )" ); queryBuilder.append( " DELETE a" ); } else { queryBuilder.append( " - () DELETE a" ); } return queryBuilder.toString(); }
@Override public boolean isStoredInEntityStructure(AssociationKeyMetadata associationKeyMetadata, AssociationTypeContext associationTypeContext) { AssociationStorageType associationStorage = associationTypeContext .getOptionsContext() .getUnique( AssociationStorageOption.class ); return associationKeyMetadata.getAssociationType() == AssociationType.ONE_TO_ONE || associationKeyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION || associationStorage == AssociationStorageType.IN_ENTITY; }
/** * When dealing with some scenarios like, for example, a bidirectional association, OGM calls this method twice: * <p> * the first time with the information related to the owner of the association and the {@link RowKey}, * the second time using the same {@link RowKey} but with the {@link AssociationKey} referring to the other side of the association. * @param associatedEntityKeyMetadata * @param action */ private void putAssociationOperation(AssociationKey associationKey, AssociationOperation action, AssociationContext associationContext) { switch ( associationKey.getMetadata().getAssociationKind() ) { case EMBEDDED_COLLECTION: createRelationshipWithEmbeddedNode( associationKey, associationContext, action ); break; case ASSOCIATION: findOrCreateRelationshipWithEntityNode( associationKey, associationContext, action ); break; default: throw new AssertionFailure( "Unrecognized associationKind: " + associationKey.getMetadata().getAssociationKind() ); } }
@Override public Association createAssociation(AssociationKey key, AssociationContext associationContext) { if ( key.getMetadata().getAssociationKind() == AssociationKind.ASSOCIATION ) { return new Association( new IgniteAssociationSnapshot( key ) ); } else if ( key.getMetadata().getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION ) { return new Association( new IgniteEmbeddedAssociationSnapshot( key, associationContext.getEntityTuplePointer().getTuple() ) ); } else { throw new UnsupportedOperationException( "Unknown association kind " + key.getMetadata().getAssociationKind() ); } }
if ( associationKeyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION ) { queryBuilder.append( ":" ); queryBuilder.append( EMBEDDED ); if ( associationKeyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION ) { queryBuilder.append( ", e" );
/** * When dealing with some scenarios like, for example, a bidirectional association, OGM calls this method twice: * <p> * the first time with the information related to the owner of the association and the {@link RowKey}, * the second time using the same {@link RowKey} but with the {@link AssociationKey} referring to the other side of the association. * @param associatedEntityKeyMetadata * @param associationContext */ private Relationship createRelationship(AssociationKey associationKey, Tuple associationRow, AssociatedEntityKeyMetadata associatedEntityKeyMetadata, AssociationContext associationContext) { switch ( associationKey.getMetadata().getAssociationKind() ) { case EMBEDDED_COLLECTION: return createRelationshipWithEmbeddedNode( associationKey, associationRow, associatedEntityKeyMetadata ); case ASSOCIATION: return findOrCreateRelationshipWithEntityNode( associationKey, associationRow, associatedEntityKeyMetadata, associationContext.getTupleTypeContext() ); default: throw new AssertionFailure( "Unrecognized associationKind: " + associationKey.getMetadata().getAssociationKind() ); } }
/** * When dealing with some scenarios like, for example, a bidirectional association, OGM calls this method twice: * <p> * the first time with the information related to the owner of the association and the {@link RowKey}, * the second time using the same {@link RowKey} but with the {@link AssociationKey} referring to the other side of the association. * @param associationKey * @param action * @param associationContext */ private void putAssociationOperation(AssociationKey associationKey, AssociationOperation action, AssociationContext associationContext) { switch ( associationKey.getMetadata().getAssociationKind() ) { case EMBEDDED_COLLECTION: createRelationshipWithEmbeddedNode( associationKey, associationContext, action ); break; case ASSOCIATION: findOrCreateRelationshipWithEntityNode( associationKey, associationContext, action ); break; default: throw new AssertionFailure( "Unrecognized associationKind: " + associationKey.getMetadata().getAssociationKind() ); } }
appendRelationshipType( queryBuilder, relationshipType ); queryBuilder.append( associationKeyMetadata.isInverse() ? "]- " : "]-> " ); if ( associationKeyMetadata.getAssociationKind() == AssociationKind.ASSOCIATION ) { EntityKeyMetadata associatedEntityMetadata = associationKeyMetadata.getAssociatedEntityKeyMetadata().getEntityKeyMetadata(); appendEntityNode( "target", associatedEntityMetadata, queryBuilder, 0, false );
public IgniteCache<Object, BinaryObject> getAssociationCache(AssociationKeyMetadata keyMetadata) { return keyMetadata.getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION ? getEntityCache( keyMetadata.getEntityKeyMetadata() ) : getEntityCache( keyMetadata.getTable() ); }
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() ); }
private static boolean associationStoredWithinEntityEntry(AssociationKey key, AssociationContext associationContext) { final String cacheName = cacheName( key ); final String entityTableName = associationContext.getAssociationTypeContext().getAssociatedEntityKeyMetadata().getEntityKeyMetadata().getTable(); // in the case of embedded collections, the entityTableName and the cacheName are equal but they reference the name of a // join table so the association is not stored in the entity entry. return cacheName.equals( entityTableName ) && ! key.getMetadata().getAssociationKind().equals( AssociationKind.EMBEDDED_COLLECTION ); }
if ( key.getMetadata().getAssociationKind() == AssociationKind.ASSOCIATION ) { QueryHints.Builder hintsBuilder = new QueryHints.Builder(); Boolean isCollocated = associationContext.getAssociationTypeContext().getOptionsContext().getUnique( CollocatedAssociationOption.class ); else if ( key.getMetadata().getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION ) { result = new Association( new IgniteEmbeddedAssociationSnapshot( key, associationContext.getEntityTuplePointer().getTuple() ) ); throw new UnsupportedOperationException( "Unknown association kind " + key.getMetadata().getAssociationKind() );
private void initializeAssociations(SchemaDefinitionContext context, IgniteDatastoreProvider igniteDatastoreProvider) { for ( AssociationKeyMetadata associationKeyMetadata : context.getAllAssociationKeyMetadata() ) { log.debugf( "initializeAssociations. associationKeyMetadata: %s", associationKeyMetadata ); if ( associationKeyMetadata.getAssociationKind() != AssociationKind.EMBEDDED_COLLECTION && IgniteAssociationSnapshot.isThirdTableAssociation( associationKeyMetadata ) ) { try { try { igniteDatastoreProvider.getAssociationCache( associationKeyMetadata ); } catch (HibernateException ex) { CacheConfiguration config = createCacheConfiguration( associationKeyMetadata, context ); if ( config != null ) { igniteDatastoreProvider.initializeCache( config ); } } } catch (Exception ex) { // just write error to log throw log.unableToInitializeCache( associationKeyMetadata.getTable(), ex ); } } } }
if ( key.getMetadata().getAssociationKind() == AssociationKind.ASSOCIATION ) { QueryHints.Builder hintsBuilder = new QueryHints.Builder(); Boolean isCollocated = associationContext.getAssociationTypeContext().getOptionsContext().getUnique( CollocatedAssociationOption.class ); else if ( key.getMetadata().getAssociationKind() == AssociationKind.EMBEDDED_COLLECTION ) { Object id = ( (IgniteTupleSnapshot) associationContext.getEntityTuplePointer().getTuple().getSnapshot() ).getCacheKey(); BinaryObject binaryObject = associationCache.get( id );
private CacheConfiguration<?,?> createEntityCacheConfiguration(EntityKeyMetadata entityKeyMetadata, SchemaDefinitionContext context) { CacheConfiguration<?,?> cacheConfiguration = new CacheConfiguration<>(); cacheConfiguration.setStoreKeepBinary( true ); cacheConfiguration.setSqlSchema( QueryUtils.DFLT_SCHEMA ); cacheConfiguration.setBackups( 1 ); cacheConfiguration.setName( StringHelper.stringBeforePoint( entityKeyMetadata.getTable() ) ); cacheConfiguration.setAtomicityMode( CacheAtomicityMode.TRANSACTIONAL ); QueryEntity queryEntity = new QueryEntity(); queryEntity.setTableName( entityKeyMetadata.getTable() ); queryEntity.setKeyType( getEntityIdClassName( entityKeyMetadata.getTable(), context ).getSimpleName() ); queryEntity.setValueType( StringHelper.stringAfterPoint( entityKeyMetadata.getTable() ) ); addTableInfo( queryEntity, context, entityKeyMetadata.getTable() ); for ( AssociationKeyMetadata associationKeyMetadata : context.getAllAssociationKeyMetadata() ) { if ( associationKeyMetadata.getAssociationKind() != AssociationKind.EMBEDDED_COLLECTION && associationKeyMetadata.getTable().equals( entityKeyMetadata.getTable() ) && !IgniteAssociationSnapshot.isThirdTableAssociation( associationKeyMetadata ) ) { appendIndex( queryEntity, associationKeyMetadata, context ); } } addUserIndexes( queryEntity, context, entityKeyMetadata.getTable() ); log.debugf( "queryEntity: %s", queryEntity ); cacheConfiguration.setQueryEntities( Arrays.asList( queryEntity ) ); return cacheConfiguration; }