@ NotNull protected final JpaStream findStream ( @ NotNull final StreamId streamId ) { Contract . requireArgNotNull ( "streamId" , streamId ) ; verifyStreamEntityExists ( streamId ) ; final String sql = createJpqlStreamSelect ( streamId ) ; final TypedQuery < JpaStream > query = getEm ( ) . createQuery ( sql , JpaStream . class ) ; setJpqlParameters ( query , streamId ) ; final List < JpaStream > streams = query . getResultList ( ) ; if ( streams . size ( ) == 0 ) { throw new StreamNotFoundException ( streamId ) ; } final JpaStream stream = streams . get ( 0 ) ; if ( stream . getState ( ) == StreamState . SOFT_DELETED ) { // TODO Remove after event store has a way to distinguish between // never-existing and soft deleted // streams throw new StreamNotFoundException ( streamId ) ; } return stream ; }
Reads the stream with the given identifier from the DB and returns it .