private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) { Worker worker = searchFactory.getWorker(); for (Work work : works) { worker.performWork(work, transactionContext); } }
private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) { Worker worker = searchFactory.getWorker(); for (Work work : works) { worker.performWork(work, transactionContext); } }
protected static void updateIndex(TransactionContext context, Collection<DomainObject> objects, WorkType workType) { try { for (DomainObject obj : objects) { if (!INDEXED_CLASSES.contains(obj.getClass())) continue; searchFactory.getWorker().performWork(new Work<DomainObject>(obj, workType), context); } } catch (RuntimeException e) { logger.warn("Problem inside updateIndex", e); throw e; } }
@Override public void accept(int id) { AbstractBookEntity book = dataset.create( id ); Work work = new Work( book, id, WorkType.ADD, false ); worker.performWork( work, tc ); needsFlush = true; ++count; if ( count % 1000 == 0 ) { //commit in batches of 1000: flush(); } }
private void createAndPerformWork(IndexedTypeIdentifier type, Serializable id, WorkType workType) { Work work = new Work( delegate.getTenantIdentifier(), type, id, workType ); getSearchIntegrator().getWorker().performWork( work, transactionContext ); }
public void execute() { TransactionContextForTest tc = new TransactionContextForTest(); works.forEach( w -> integratorProvider.get().getWorker().performWork( w, tc ) ); tc.end(); works.clear(); } }
protected void processWork(String tenantIdentifier, Object entity, Serializable id, WorkType workType, AbstractEvent event, boolean identifierRollbackEnabled) { Work work = new Work( tenantIdentifier, entity, id, workType, identifierRollbackEnabled ); final EventSourceTransactionContext transactionContext = new EventSourceTransactionContext( event.getSession() ); getExtendedSearchFactoryIntegrator().getWorker().performWork( work, transactionContext ); }
@Benchmark @Threads(3 * AbstractBookEntity.TYPE_COUNT) public void write(NonStreamWriteEngineHolder eh, ChangesetGenerator changesetGenerator, NonStreamWriteCounters counters) { SearchIntegrator si = eh.getSearchIntegrator(); Worker worker = si.getWorker(); IndexedTypeIdentifier typeId = changesetGenerator.getTypeId(); changesetGenerator.stream().forEach( changeset -> { TransactionContextForTest tc = new TransactionContextForTest(); changeset.toAdd().forEach( book -> { Work work = new Work( book, book.getId(), WorkType.ADD ); worker.performWork( work, tc ); } ); changeset.toUpdate().forEach( book -> { Work work = new Work( book, book.getId(), WorkType.UPDATE ); worker.performWork( work, tc ); } ); changeset.toDelete().forEach( id -> { Work work = new Work( typeId, id, WorkType.DELETE ); worker.performWork( work, tc ); } ); tc.end(); ++counters.changeset; } ); // Ensure that we'll block until all works have been performed SearchIntegratorHelper.flush( si, typeId ); }
@Override public void run() { for ( int i = 1; i <= docsPerThread; i++ ) { final Worker worker = integrator.getWorker(); Work work = workLog.generateNewWork(); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); workLog.workApplied( work ); tc.end(); if ( i % printEach == 0 ) { System.out.println( Thread.currentThread().getName() + " sent " + i ); } } } }
private void storeObject(Object entity, Serializable id) { Work work = new Work( entity, id, WorkType.UPDATE, false ); TransactionContextForTest tc = new TransactionContextForTest(); searchIntegrator.getWorker().performWork( work, tc ); tc.end(); }
private static void writeABook(Integer id, String bookTitle, Worker worker) { Book book = new Book(); book.id = id; book.title = bookTitle; Work work = new Work( book, book.id, WorkType.ADD, false ); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); tc.end(); }
private static void deleteABook(Integer id, Worker worker) { Book book = new Book(); book.id = id; Work work = new Work( book, id, WorkType.DELETE, false ); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); tc.end(); }
private void storeObject(Object entity, Serializable id) { Work work = new Work( entity, id, WorkType.UPDATE, false ); TransactionContextForTest tc = new TransactionContextForTest(); slaveNode.getSearchFactory().getWorker().performWork( work, tc ); tc.end(); }
public static void preindexEntities(SearchIntegrator si, int numEntities) { println( "Starting index creation..." ); Worker worker = si.getWorker(); TransactionContextForTest tc = new TransactionContextForTest(); boolean needsFlush = false; int i = 1; for ( ; i <= numEntities; i++ ) { BookEntity book = new BookEntity(); book.setId( Long.valueOf( i ) ); book.setText( "Some very long text should be stored here. No, I mean long as in a book." ); book.setTitle( "Naaa" ); book.setRating( Float.intBitsToFloat( i ) ); Work work = new Work( book, book.getId(), WorkType.ADD, false ); worker.performWork( work, tc ); needsFlush = true; if ( i % 1000 == 0 ) { //commit in batches of 1000: tc.end(); needsFlush = false; tc = new TransactionContextForTest(); } } if ( needsFlush ) { //commit remaining work tc.end(); } println( " ... created an index of " + numEntities + " entities." ); }
@Benchmark @Threads(20) public void simpleIndexing(QueryEngineHolder eh) { Worker worker = eh.si.getWorker(); BookEntity book = new BookEntity(); book.setId( 1L ); book.setText( "Some very long text should be stored here. No, I mean long as in a book." ); book.setTitle( "Naaa" ); Work work = new Work( book, book.getId(), WorkType.ADD, false ); TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( work, tc ); tc.end(); }
private void testForQuery(Class<?> entityType, ExtendedSearchIntegrator integrator, DeletionQuery query, int expectedCount) { Worker worker = integrator.getWorker(); makeBooksForNumRangeQuery(); this.assertCount( entityType, 2 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( BOOK_TYPE, query ), tc ); tc.end(); } this.assertCount( entityType, expectedCount ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new Work( BOOK_TYPE, null, WorkType.PURGE_ALL ), tc ); tc.end(); } this.assertCount( entityType, 0 ); }
@Test public void testStringIdTermQuery() { ExtendedSearchIntegrator integrator = this.factoryHolder.getSearchFactory(); Worker worker = integrator.getWorker(); makeBooksForSingularTermQuery(); this.assertCount( Book.class, 2 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( BOOK_TYPE, new SingularTermDeletionQuery( "id", String.valueOf( 5 ) ) ), tc ); tc.end(); } this.assertCount( Book.class, 1 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( BOOK_TYPE, new SingularTermDeletionQuery( "id", String.valueOf( 6 ) ) ), tc ); tc.end(); } this.assertCount( Book.class, 0 ); // this should stay empty now! }
@Test public void canDeleteByQuery() throws Exception { Session s = openSession(); FullTextSession session = Search.getFullTextSession( s ); ExtendedSearchIntegrator integrator = session.getSearchFactory() .unwrap( ExtendedSearchIntegrator.class ); DeleteByQueryWork queryWork = new DeleteByQueryWork( new PojoIndexedTypeIdentifier( HockeyPlayer.class ), new SingularTermDeletionQuery( "active", "false" ) ); TransactionContext tc = new TransactionContextForTest(); integrator.getWorker().performWork( queryWork, tc ); integrator.getWorker().flushWorks( tc ); QueryDescriptor query = ElasticsearchQueries.fromJson( "{ 'query': { 'match_all' : {} } }" ); Transaction tx = s.beginTransaction(); @SuppressWarnings("unchecked") List<HockeyPlayer> result = session.createFullTextQuery( query, HockeyPlayer.class ).list(); assertThat( result ).extracting( "name" ).containsExactlyInAnyOrder( "Hergesheimer", "Brand" ); tx.commit(); s.close(); }
@Test public void testSingularTermQuery() { ExtendedSearchIntegrator integrator = this.factoryHolder.getSearchFactory(); Worker worker = integrator.getWorker(); makeBooksForSingularTermQuery(); this.assertCount( Book.class, 2 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( BOOK_TYPE, new SingularTermDeletionQuery( "url", "lordoftherings" ) ), tc ); tc.end(); } this.assertCount( Book.class, 1 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( BOOK_TYPE, new SingularTermDeletionQuery( "url", "thehobbit" ) ), tc ); tc.end(); } this.assertCount( Book.class, 0 ); // this should stay empty now! }
@Test public void testNumericIdTermQuery() { ExtendedSearchIntegrator integrator = this.factoryHolder.getSearchFactory(); Worker worker = integrator.getWorker(); makeMoviesForNumericIdTermQuery(); this.assertCount( Movie.class, 2 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( MOVIE_TYPE, new SingularTermDeletionQuery( "id", 3 ) ), tc ); tc.end(); } this.assertCount( Movie.class, 1 ); { TransactionContextForTest tc = new TransactionContextForTest(); worker.performWork( new DeleteByQueryWork( MOVIE_TYPE, new SingularTermDeletionQuery( "id", 4 ) ), tc ); tc.end(); } this.assertCount( Movie.class, 0 ); // this should stay empty now! }