Package org.hibernate.ogm.persister.impl

Examples of org.hibernate.ogm.persister.impl.OgmCollectionPersister


  private Map<AssociationKeyMetadata, Neo4jAssociationQueries> initializeAssociationQueries(SessionFactoryImplementor sessionFactoryImplementor) {
    Map<AssociationKeyMetadata, Neo4jAssociationQueries> queryMap = new HashMap<AssociationKeyMetadata, Neo4jAssociationQueries>();
    Collection<CollectionPersister> collectionPersisters = sessionFactoryImplementor.getCollectionPersisters().values();
    for ( CollectionPersister collectionPersister : collectionPersisters ) {
      if ( collectionPersister instanceof OgmCollectionPersister ) {
        OgmCollectionPersister ogmCollectionPersister = (OgmCollectionPersister) collectionPersister;
        EntityKeyMetadata ownerEntityKeyMetadata = ( (OgmEntityPersister) ( ogmCollectionPersister.getOwnerEntityPersister() ) ).getEntityKeyMetadata();
        AssociationKeyMetadata associationKeyMetadata = ogmCollectionPersister.getAssociationKeyMetadata();
        queryMap.put( associationKeyMetadata, new Neo4jAssociationQueries( ownerEntityKeyMetadata, associationKeyMetadata ) );
      }
    }
    return queryMap;
  }
View Full Code Here


    else {
      //collection persister
      if ( getCollectionPersisters().length != 1 ) {
        throw new AssertionFailure( "Found an unexpected number of collection persisters: " + getCollectionPersisters().length );
      }
      final OgmCollectionPersister persister = (OgmCollectionPersister) getCollectionPersisters()[0];
      Object owner = session.getPersistenceContext().getCollectionOwner( id, persister );

      AssociationPersister associationPersister = new AssociationPersister(
          persister.getOwnerEntityPersister().getMappedClass()
        )
        .gridDialect( gridDialect )
        .key( id, persister.getKeyGridType() )
        .associationKeyMetadata( persister.getAssociationKeyMetadata() )
        .associationTypeContext( persister.getAssociationTypeContext() )
        .hostingEntity( owner )
        .session( session );

      Association assoc = associationPersister.getAssociationOrNull();
      if ( assoc != null ) {
View Full Code Here

*/
public class BiDirectionalAssociationHelperTest extends OgmTestCase {

  @Test
  public void inverseMetadataForUnidirectionalOneToManyShouldBeNull() {
    OgmCollectionPersister persister = (OgmCollectionPersister) sessions.getCollectionPersister( Cloud.class.getName() + ".producedSnowFlakes" );
    OgmCollectionPersister inversePersister = BiDirectionalAssociationHelper.getInverseCollectionPersister( persister );
    assertThat( inversePersister ).isNull();
  }
View Full Code Here

    assertThat( inverseAssociationKeyMetadata.getTable() ).isEqualTo( "SalesGuy" );
    assertThat( inverseAssociationKeyMetadata.getColumnNames() ).isEqualTo( new String[]{ "salesForce_id" } );
    assertThat( inverseAssociationKeyMetadata.getRowKeyColumnNames() ).isEqualTo( new String[]{ "salesForce_id", "id" } );

    // no persister on the main side
    OgmCollectionPersister collectionPersister = (OgmCollectionPersister) sessions.getCollectionPersister( SalesForce.class.getName() + ".salesGuys" );
    OgmCollectionPersister mainSidePersister = BiDirectionalAssociationHelper.getInverseCollectionPersister( collectionPersister );
    assertThat( mainSidePersister ).isNull();
  }
View Full Code Here

    assertThat( inverseAssociationKeyMetadata.getRowKeyColumnNames() ).isEqualTo( new String[]{ "id", "wife" } );
  }

  @Test
  public void canObtainMainSidePropertyNameForOneToMany() {
    OgmCollectionPersister persister = (OgmCollectionPersister) sessions.getCollectionPersister( SalesForce.class.getName() + ".salesGuys" );
    String mainSidePropertyName = BiDirectionalAssociationHelper.getMainSidePropertyName( persister );
    assertThat( mainSidePropertyName ).isEqualTo( "salesForce" );
  }
View Full Code Here

  }

  @Test
  public void canObtainMainSidePropertyNameForManyToMany() {
    // ask from main side
    OgmCollectionPersister persister = (OgmCollectionPersister) sessions.getCollectionPersister( AccountOwner.class.getName() + ".bankAccounts" );
    String mainSidePropertyName = BiDirectionalAssociationHelper.getMainSidePropertyName( persister );
    assertThat( mainSidePropertyName ).isEqualTo( "bankAccounts" );

    // ask from inverse side
    persister = (OgmCollectionPersister) sessions.getCollectionPersister( BankAccount.class.getName() + ".owners" );
View Full Code Here

    assertThat( mainSidePropertyName ).isEqualTo( "bankAccounts" );
  }

  @Test
  public void canObtainMainSidePropertyNameWithSeveralAssociationsOnInverseSide() {
    OgmCollectionPersister persister = (OgmCollectionPersister) sessions.getCollectionPersister( Eater.class.getName() + ".muffins" );
    String mainSidePropertyName = BiDirectionalAssociationHelper.getMainSidePropertyName( persister );
    assertThat( mainSidePropertyName ).isEqualTo( "eater" );

    persister = (OgmCollectionPersister) sessions.getCollectionPersister( Eater.class.getName() + ".muffinsEatenAsStandin" );
    mainSidePropertyName = BiDirectionalAssociationHelper.getMainSidePropertyName( persister );
View Full Code Here

  private Map<AssociationKeyMetadata, Neo4jAssociationQueries> initializeAssociationQueries(SessionFactoryImplementor sessionFactoryImplementor) {
    Map<AssociationKeyMetadata, Neo4jAssociationQueries> queryMap = new HashMap<AssociationKeyMetadata, Neo4jAssociationQueries>();
    Collection<CollectionPersister> collectionPersisters = sessionFactoryImplementor.getCollectionPersisters().values();
    for ( CollectionPersister collectionPersister : collectionPersisters ) {
      if ( collectionPersister instanceof OgmCollectionPersister ) {
        OgmCollectionPersister ogmCollectionPersister = (OgmCollectionPersister) collectionPersister;
        EntityKeyMetadata ownerEntityKeyMetadata = ( (OgmEntityPersister) ( ogmCollectionPersister.getOwnerEntityPersister() ) ).getEntityKeyMetadata();
        AssociationKeyMetadata associationKeyMetadata = ogmCollectionPersister.getAssociationKeyMetadata();
        queryMap.put( associationKeyMetadata, new Neo4jAssociationQueries( ownerEntityKeyMetadata, associationKeyMetadata ) );
      }
    }
    return queryMap;
  }
View Full Code Here

    else {
      //collection persister
      if ( getCollectionPersisters().length != 1 ) {
        throw new AssertionFailure( "Found an unexpected number of collection persisters: " + getCollectionPersisters().length );
      }
      final OgmCollectionPersister persister = (OgmCollectionPersister) getCollectionPersisters()[0];

      AssociationPersister associationPersister = new AssociationPersister(
          persister.getOwnerEntityPersister().getMappedClass()
        )
        .gridDialect( gridDialect )
        .key( id )
        .keyGridType( persister.getKeyGridType() )
        .associationKeyMetadata( persister.getAssociationKeyMetadata() )
        // we can be on the main or on the inverse side, so we cannot simply use the unqualified role
        .roleOnMainSide( persister.getMainSidePropertyName() )
        .session( session );

      Association assoc = associationPersister.getAssociationOrNull();
      if ( assoc != null ) {
        for ( RowKey rowKey : assoc.getKeys() ) {
View Full Code Here

TOP

Related Classes of org.hibernate.ogm.persister.impl.OgmCollectionPersister

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.