if ( id == null && ogmLoadingContext.hasResultSet() ) {
return ogmLoadingContext.getResultSet();
}
//TODO this if won't work when we will support collections inside the entity tuple but that will do for now
final TupleAsMapResultSet resultset = new TupleAsMapResultSet();
if ( getEntityPersisters().length > 0 ) {
OgmEntityPersister persister = getEntityPersisters()[0];
final EntityKey key = EntityKeyBuilder.fromPersister( persister, id, session );
Tuple entry = gridDialect.getTuple( key, persister.getTupleContext() );
if ( entry != null ) {
resultset.addTuple( entry );
}
}
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 ) {
for ( RowKey rowKey : assoc.getKeys() ) {
resultset.addTuple( assoc.get( rowKey ) );
}
}
}
return resultset;
}