org.hibernate.search.backend.spi.Worker.performWork()方法的使用及代码示例

x33g5p2x  于2022-02-03 转载在 其他  
字(9.9k)|赞(0)|评价(0)|浏览(219)

本文整理了Java中org.hibernate.search.backend.spi.Worker.performWork()方法的一些代码示例,展示了Worker.performWork()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Worker.performWork()方法的具体详情如下:
包路径:org.hibernate.search.backend.spi.Worker
类名称:Worker
方法名:performWork

Worker.performWork介绍

[英]Declare a work to be done within a given transaction context
[中]声明要在给定事务上下文中完成的工作

代码示例

代码示例来源:origin: org.infinispan/infinispan-query

private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) {
 Worker worker = searchFactory.getWorker();
 for (Work work : works) {
   worker.performWork(work, transactionContext);
 }
}

代码示例来源:origin: org.infinispan/infinispan-embedded-query

private void performSearchWorks(Collection<Work> works, TransactionContext transactionContext) {
 Worker worker = searchFactory.getWorker();
 for (Work work : works) {
   worker.performWork(work, transactionContext);
 }
}

代码示例来源:origin: fenix-framework/fenix-framework

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;
  }
}

代码示例来源:origin: hibernate/hibernate-search

@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();
  }
}

代码示例来源:origin: hibernate/hibernate-search

private void createAndPerformWork(IndexedTypeIdentifier type, Serializable id, WorkType workType) {
  Work work = new Work( delegate.getTenantIdentifier(), type, id, workType );
  getSearchIntegrator().getWorker().performWork( work, transactionContext );
}

代码示例来源:origin: hibernate/hibernate-search

public void execute() {
    TransactionContextForTest tc = new TransactionContextForTest();
    works.forEach(
        w -> integratorProvider.get().getWorker().performWork( w, tc )
    );
    tc.end();
    works.clear();
  }
}

代码示例来源:origin: hibernate/hibernate-search

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 );
}

代码示例来源:origin: hibernate/hibernate-search

@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 );
}

代码示例来源:origin: hibernate/hibernate-search

@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 );
      }
    }
  }
}

代码示例来源:origin: hibernate/hibernate-search

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();
}

代码示例来源:origin: hibernate/hibernate-search

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();
}

代码示例来源:origin: hibernate/hibernate-search

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();
}

代码示例来源:origin: hibernate/hibernate-search

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();
}

代码示例来源:origin: hibernate/hibernate-search

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." );
}

代码示例来源:origin: hibernate/hibernate-search

@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();
}

代码示例来源:origin: hibernate/hibernate-search

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 );
}

代码示例来源:origin: hibernate/hibernate-search

@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!
}

代码示例来源:origin: hibernate/hibernate-search

@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();
}

代码示例来源:origin: hibernate/hibernate-search

@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!
}

代码示例来源:origin: hibernate/hibernate-search

@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!
}

相关文章