Skip to content

Commit

Permalink
HSEARCH-3610 Rename Search.getSearchSession() to Search.session()
Browse files Browse the repository at this point in the history
  • Loading branch information
yrodiere committed Jun 21, 2019
1 parent 7676a5a commit 4ef444b
Show file tree
Hide file tree
Showing 33 changed files with 122 additions and 98 deletions.
Expand Up @@ -76,7 +76,7 @@ public void test() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::searching[]
// Not shown: get the entity manager and open a transaction
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

SearchResult<Book> result = searchSession.search( Book.class )
.predicate( factory -> factory.match()
Expand All @@ -93,7 +93,7 @@ public void test() {

// Also test the other terms mentioned in the getting started guide
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

for ( String term : new String[] { "Refactor", "refactors", "refactored", "refactoring" } ) {
SearchResult<Book> result = searchSession.search( Book.class )
Expand Down
Expand Up @@ -84,7 +84,7 @@ public void test() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
try {
// tag::manual-index[]
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>

MassIndexer indexer = searchSession.massIndexer( Book.class ) // <2>
.threadsToLoadObjects( 7 ); // <3>
Expand All @@ -100,7 +100,7 @@ public void test() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::searching-objects[]
// Not shown: get the entity manager and open a transaction
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>

SearchScope<Book> scope = searchSession.scope( Book.class ); // <2>

Expand Down Expand Up @@ -139,7 +139,7 @@ public void test() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::searching-lambdas[]
// Not shown: get the entity manager and open a transaction
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>

SearchResult<Book> result = searchSession.search( Book.class ) // <2>
.predicate( f -> f.match() // <3>
Expand Down Expand Up @@ -174,7 +174,7 @@ public void test() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::counting[]
// Not shown: get the entity manager and open a transaction
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

long totalHitCount = searchSession.search( Book.class )
.predicate( f -> f.match()
Expand Down
Expand Up @@ -70,7 +70,7 @@ public void setup() {
@Test
public void sort() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

List<Book> result = searchSession.search( Book.class ) // <1>
.predicate( f -> f.matchAll() )
Expand All @@ -88,7 +88,7 @@ public void sort() {
@Test
public void projection_simple() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

List<String> result = searchSession.search( Book.class ) // <1>
.asProjection( f -> f.field( "title", String.class ) ) // <2>
Expand Down
Expand Up @@ -63,7 +63,7 @@ public void setup() {
@Test
public void search_separateQueries() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

List<Author> authorResult = searchSession.search( Author.class )
.predicate( f -> f.matchAll() )
Expand All @@ -81,7 +81,7 @@ public void search_separateQueries() {
public void search_singleQuery() {
SubTest.expectException(
() -> OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

// tag::cross-backend-search[]
// This will fail because Author and User are indexed in different backends
Expand Down
Expand Up @@ -61,7 +61,7 @@ public void synchronizationStrategyOverride() {

OrmUtils.withinEntityManager( entityManagerFactory, entityManager -> {
// tag::automatic-indexing-synchronization-strategy-override[]
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>
searchSession.setAutomaticIndexingSynchronizationStrategy(
AutomaticIndexingSynchronizationStrategy.searchable()
); // <2>
Expand Down
Expand Up @@ -85,7 +85,7 @@ public void persist_automaticIndexing_periodicProcess() {
assertBookCount( entityManager, 0 );

// tag::persist-automatic-indexing-periodic-process[]
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>
SearchSessionWritePlan searchWritePlan = searchSession.writePlan(); // <2>

entityManager.getTransaction().begin();
Expand Down Expand Up @@ -119,7 +119,7 @@ public void persist_automaticIndexing_periodicExecute() {
assertBookCount( entityManager, 0 );

// tag::persist-automatic-indexing-periodic-execute[]
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>
SearchSessionWritePlan searchWritePlan = searchSession.writePlan(); // <2>

entityManager.getTransaction().begin();
Expand Down Expand Up @@ -184,7 +184,7 @@ public void addOrUpdate() {
assertBookCount( entityManager, 0 );

// tag::write-plan-addOrUpdate[]
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>
SearchSessionWritePlan searchWritePlan = searchSession.writePlan(); // <2>

entityManager.getTransaction().begin();
Expand Down Expand Up @@ -214,7 +214,7 @@ public void delete() {
assertBookCount( entityManager, numberOfBooks );

// tag::write-plan-delete[]
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>
SearchSessionWritePlan searchWritePlan = searchSession.writePlan(); // <2>

entityManager.getTransaction().begin();
Expand Down Expand Up @@ -242,7 +242,7 @@ public void writer() {

OrmUtils.withinEntityManager( entityManagerFactory, entityManager -> {
// tag::writer-retrieval[]
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>
SearchWriter writer1 = searchSession.writer(); // <2>
SearchWriter writer2 = searchSession.writer( Book.class ); // <3>
SearchWriter writer3 = searchSession.writer( Book.class, Author.class ); // <4>
Expand All @@ -254,7 +254,7 @@ public void writer() {
assertAuthorCount( entityManager, numberOfBooks );

// tag::writer-purge[]
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>
SearchWriter writer = searchSession.writer( Book.class, Author.class ); // <2>
writer.purge(); // <3>
// end::writer-purge[]
Expand Down Expand Up @@ -306,7 +306,7 @@ private Author newAuthor(int id) {
}

private void assertBookCount(EntityManager entityManager, int expectedCount) {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );
// Ensure every committed work is searchable: flush also executes a refresh on Elasticsearch
searchSession.writer().flush();
assertThat(
Expand All @@ -318,7 +318,7 @@ private void assertBookCount(EntityManager entityManager, int expectedCount) {
}

private void assertAuthorCount(EntityManager entityManager, int expectedCount) {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );
// Ensure every committed work is searchable: flush also executes a refresh on Elasticsearch
searchSession.writer().flush();
assertThat(
Expand Down
Expand Up @@ -68,7 +68,7 @@ public void setup() {
@Test
public void dslConverterEnabled() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

// tag::dsl-converter-enabled[]
List<AuthenticationEvent> result = searchSession.search( AuthenticationEvent.class )
Expand All @@ -86,7 +86,7 @@ public void dslConverterEnabled() {
@Test
public void dslConverterDisabled() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

// tag::dsl-converter-disabled[]
List<AuthenticationEvent> result = searchSession.search( AuthenticationEvent.class )
Expand Down
Expand Up @@ -68,7 +68,7 @@ public void setup() {
@Test
public void projectionConverterEnabled() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

// tag::projection-converter-enabled[]
List<OrderStatus> result = searchSession.search( Order.class )
Expand All @@ -85,7 +85,7 @@ public void projectionConverterEnabled() {
@Test
public void projectionConverterDisabled() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

// tag::projection-converter-disabled[]
List<String> result = searchSession.search( Order.class )
Expand Down
Expand Up @@ -81,7 +81,7 @@ public void setup() {
public void entryPoint() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::entryPoint-lambdas[]
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

List<Book> result = searchSession.search( Book.class ) // <1>
.predicate( f -> f.match().onField( "title" ) // <2>
Expand All @@ -95,7 +95,7 @@ public void entryPoint() {

OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::entryPoint-objects[]
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

SearchScope<Book> scope = searchSession.scope( Book.class );

Expand Down Expand Up @@ -734,7 +734,7 @@ public Integer getPageCountMaxFilter() {

private void withinSearchSession(Consumer<SearchSession> action) {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );
action.accept( searchSession );
} );
}
Expand Down
Expand Up @@ -87,7 +87,7 @@ public void setup() {
public void entryPoint() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::entryPoint-lambdas[]
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

List<String> result = searchSession.search( Book.class ) // <1>
.asProjection( f -> f.field( "title", String.class ) ) // <2>
Expand All @@ -104,7 +104,7 @@ public void entryPoint() {

OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::entryPoint-objects[]
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

SearchScope<Book> scope = searchSession.scope( Book.class );

Expand Down Expand Up @@ -406,7 +406,7 @@ public void elasticsearch() {

private void withinSearchSession(Consumer<SearchSession> action) {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );
action.accept( searchSession );
} );
}
Expand Down
Expand Up @@ -66,7 +66,7 @@ public void entryPoint() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::entryPoint[]
// Not shown: get the entity manager and open a transaction
SearchSession searchSession = Search.getSearchSession( entityManager ); // <1>
SearchSession searchSession = Search.session( entityManager ); // <1>

SearchResult<Book> result = searchSession.search( Book.class ) // <2>
.predicate( f -> f.match() // <3>
Expand Down
Expand Up @@ -78,7 +78,7 @@ public void setup() {
public void entryPoint() {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::entryPoint-lambdas[]
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

List<Book> result = searchSession.search( Book.class ) // <1>
.predicate( f -> f.matchAll() )
Expand All @@ -93,7 +93,7 @@ public void entryPoint() {

OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
// tag::entryPoint-objects[]
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );

SearchScope<Book> scope = searchSession.scope( Book.class );

Expand Down Expand Up @@ -343,7 +343,7 @@ public List<MySort> getSorts() {

private void withinSearchSession(Consumer<SearchSession> action) {
OrmUtils.withinJPATransaction( entityManagerFactory, entityManager -> {
SearchSession searchSession = Search.getSearchSession( entityManager );
SearchSession searchSession = Search.session( entityManager );
action.accept( searchSession );
} );
}
Expand Down
Expand Up @@ -221,7 +221,7 @@ private CompletableFuture<?> runTransactionInDifferentThread(SessionFactory sess
CompletableFuture<?> transactionFuture = CompletableFuture.runAsync( () -> {
OrmUtils.withinTransaction( sessionFactory, session -> {
if ( customStrategy != null ) {
Search.getSearchSession( session ).setAutomaticIndexingSynchronizationStrategy( customStrategy );
Search.session( session ).setAutomaticIndexingSynchronizationStrategy( customStrategy );
}
IndexedEntity entity1 = new IndexedEntity();
entity1.setId( 1 );
Expand Down
Expand Up @@ -81,7 +81,7 @@ public void setup() {
@Test
public void toHibernateOrmSession() {
OrmUtils.withinSession( sessionFactory, session -> {
SearchSession searchSession = Search.getSearchSession( session );
SearchSession searchSession = Search.session( session );
assertThat( searchSession.toOrmSession() ).isSameAs( session );
} );
}
Expand All @@ -100,7 +100,7 @@ public void toHibernateOrmSession_withClosedSession() {

Session closedSession = session;
SubTest.expectException( () -> {
Search.getSearchSession( closedSession );
Search.session( closedSession );
} )
.assertThrown()
.isInstanceOf( SearchException.class )
Expand All @@ -110,7 +110,7 @@ public void toHibernateOrmSession_withClosedSession() {
@Test
public void toHibernateOrmQuery() {
OrmUtils.withinSession( sessionFactory, session -> {
SearchSession searchSession = Search.getSearchSession( session );
SearchSession searchSession = Search.session( session );
Query<IndexedEntity> query = Search.toOrmQuery( createSimpleQuery( searchSession ) );
assertThat( query ).isNotNull();
} );
Expand All @@ -119,7 +119,7 @@ public void toHibernateOrmQuery() {
@Test
public void list() {
OrmUtils.withinSession( sessionFactory, session -> {
SearchSession searchSession = Search.getSearchSession( session );
SearchSession searchSession = Search.session( session );
Query<IndexedEntity> query = Search.toOrmQuery( createSimpleQuery( searchSession ) );

backendMock.expectSearchObjects(
Expand All @@ -144,7 +144,7 @@ public void list() {
@Test
public void uniqueResult() {
OrmUtils.withinSession( sessionFactory, session -> {
SearchSession searchSession = Search.getSearchSession( session );
SearchSession searchSession = Search.session( session );
Query<IndexedEntity> query = Search.toOrmQuery( createSimpleQuery( searchSession ) );

backendMock.expectSearchObjects(
Expand Down Expand Up @@ -204,7 +204,7 @@ public void uniqueResult() {
@Test
public void pagination() {
OrmUtils.withinSession( sessionFactory, session -> {
SearchSession searchSession = Search.getSearchSession( session );
SearchSession searchSession = Search.session( session );
Query<IndexedEntity> query = Search.toOrmQuery( createSimpleQuery( searchSession ) );

assertThat( query.getFirstResult() ).isEqualTo( 0 );
Expand Down Expand Up @@ -232,7 +232,7 @@ public void pagination() {
@TestForIssue( jiraKey = "HSEARCH-1857" )
public void reuseSearchSessionAfterOrmSessionIsClosed_noMatching() {
Session session = sessionFactory.openSession();
SearchSession searchSession = Search.getSearchSession( session );
SearchSession searchSession = Search.session( session );
// a SearchSession instance is created lazily,
// so we need to use it to have an instance of it
createSimpleQuery( searchSession );
Expand All @@ -250,7 +250,7 @@ public void reuseSearchSessionAfterOrmSessionIsClosed_noMatching() {
public void lazyCrateSearchSessionAfterOrmSessionIsClosed() {
Session session = sessionFactory.openSession();
// Search session is not created, since we don't use it
SearchSession searchSession = Search.getSearchSession( session );
SearchSession searchSession = Search.session( session );
session.close();

SubTest.expectException( () -> {
Expand All @@ -265,7 +265,7 @@ public void lazyCrateSearchSessionAfterOrmSessionIsClosed() {
@TestForIssue( jiraKey = "HSEARCH-1857" )
public void reuseSearchQueryAfterOrmSessionIsClosed_noMatching() {
Session session = sessionFactory.openSession();
SearchSession searchSession = Search.getSearchSession( session );
SearchSession searchSession = Search.session( session );
SearchQuery<IndexedEntity> query = createSimpleQuery( searchSession );
session.close();

Expand Down

0 comments on commit 4ef444b

Please sign in to comment.