本文整理汇总了Java中org.hibernate.search.jpa.FullTextEntityManager.beginSearchTransaction方法的典型用法代码示例。如果您正苦于以下问题:Java FullTextEntityManager.beginSearchTransaction方法的具体用法?Java FullTextEntityManager.beginSearchTransaction怎么用?Java FullTextEntityManager.beginSearchTransaction使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.hibernate.search.jpa.FullTextEntityManager
的用法示例。
在下文中一共展示了FullTextEntityManager.beginSearchTransaction方法的9个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testDeleteByTerm
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
@Test
public void testDeleteByTerm() {
FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em );
//TODO: testCustomUpdatedEntity if all the Sorcerers still available?
fem.beginSearchTransaction();
fem.purgeByTerm( Place.class, "id", String.valueOf( this.valinorId ) );
fem.commitSearchTransaction();
//TODO: testCustomUpdatedEntity this for the other query types
assertEquals(
0, fem.createFullTextQuery( new TermQuery( new Term( "name", "valinor" ) ), Place.class )
.getResultList()
.size()
);
}
示例2: testManualIndexing
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
@Test
public void testManualIndexing() throws Exception {
this.shouldFindAllGamesInIndex();
FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em );
fem.beginSearchTransaction();
Game newGame = new Game( "Legend of Zelda" );
newGame.setId( -10L );
fem.index( newGame );
fem.commitSearchTransaction();
Sleep.sleep(
MAX_SLEEP_TIME, () -> {
FullTextQuery fullTextQuery = fem.createFullTextQuery(
fem.getSearchFactory().buildQueryBuilder().forEntity( Game.class ).get().keyword().onField(
"title"
).matching( "Legend of Zelda" ).createQuery(), Game.class
);
// we can find it in the index even though it is not persisted in the database
boolean val1 = 1 == fullTextQuery.getResultSize();
// but no result should be returned here:
boolean val2 = 0 == fullTextQuery.getResultList().size();
return val1 && val2;
}, 100, ""
);
}
示例3: test
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
@Test
public void test() throws InterruptedException {
System.out.println( "starting MassIndexer testCustomUpdatedEntity!" );
FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em );
fem.beginSearchTransaction();
fem.purgeAll( Sorcerer.class );
fem.commitSearchTransaction();
//make sure every Sorcerer is deleted
assertEquals( 0, fem.createFullTextQuery( new MatchAllDocsQuery(), Sorcerer.class ).getResultSize() );
this.massIndexer.threadsToLoadObjects( 15 );
this.massIndexer.batchSizeToLoadObjects( 100 );
this.massIndexer.batchSizeToLoadIds( 500 );
long pre = System.currentTimeMillis();
try {
this.massIndexer.startAndWait();
}
catch (InterruptedException e) {
throw new SearchException( e );
}
long after = System.currentTimeMillis();
System.out.println( "indexed " + COUNT + " root entities (3 sub each) in " + (after - pre) + "ms." );
//make sure no Sorcerer was added
assertEquals( 0, fem.createFullTextQuery( new MatchAllDocsQuery(), Sorcerer.class ).getResultSize() );
assertEquals( COUNT, fem.createFullTextQuery( new MatchAllDocsQuery(), Place.class ).getResultSize() );
}
示例4: testObjectHandlerTask
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
@Test
public void testObjectHandlerTask() {
FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em );
fem.beginSearchTransaction();
fem.purgeAll( Place.class );
fem.commitSearchTransaction();
Map<Class<?>, String> idProperties = new HashMap<>();
idProperties.put( Place.class, "id" );
BatchBackend batchBackend = new DefaultBatchBackend( this.searchFactory.getSearchIntegrator(), null );
ObjectHandlerTask handler = new ObjectHandlerTask(
batchBackend, Place.class, this.searchFactory.getSearchIntegrator().getIndexBinding( Place.class ),
() -> new BasicEntityProvider( this.em, idProperties ), (x, y) -> {
}, this.emf.getPersistenceUnitUtil()
);
List<UpdateConsumer.UpdateEventInfo> batch = new ArrayList<>();
batch.add( new UpdateConsumer.UpdateEventInfo( Place.class, this.valinorId, EventType.INSERT ) );
batch.add( new UpdateConsumer.UpdateEventInfo( Place.class, this.helmsDeepId, EventType.INSERT ) );
handler.batch( batch );
handler.run();
batchBackend.flush( new HashSet<>( Arrays.asList( Place.class ) ) );
assertEquals( 2, fem.createFullTextQuery( new MatchAllDocsQuery(), Place.class ).getResultList().size() );
}
示例5: clearData
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
private void clearData() throws Exception {
utx.begin();
em.joinTransaction();
System.out.println( "Dumping old records..." );
em.createQuery( "delete from Game" ).executeUpdate();
utx.commit();
FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em );
fem.beginSearchTransaction();
fem.purgeAll( Game.class );
fem.commitSearchTransaction();
}
示例6: testMassIndexer
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
@Test
public void testMassIndexer()
throws InterruptedException {
Game tmp = new Game( "should not appear in index" );
tmp.setId( -1L );
FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( null );
fem.beginSearchTransaction();
fem.index( tmp );
fem.commitSearchTransaction();
//all the minimum stuff, so we can testCustomUpdatedEntity with our little amount of entities
//the beefy tests are done in the jpa module anyways
//we just want to testCustomUpdatedEntity whether we can do the indexing
//in a EJB context :)
this.searchFactory.pauseUpdating( true );
try {
this.searchFactory.getFullTextEntityManager( this.em )
.createIndexer( Game.class )
.batchSizeToLoadIds( 1 )
.batchSizeToLoadObjects( 1 )
.threadsToLoadIds( 1 )
.threadsToLoadObjects( 1 )
//just make sure there is no exception in setting this limit, we can't really testCustomUpdatedEntity this properly as of now
//manual testCustomUpdatedEntity showed this was done correctly
.idProducerTransactionTimeout( 1000 ).startAndWait();
assertEquals(
GAME_TITLES.length, this.searchFactory.getFullTextEntityManager( this.em ).createFullTextQuery(
new MatchAllDocsQuery(),
Game.class
).getResultList().size()
);
}
finally {
this.searchFactory.pauseUpdating( false );
}
}
示例7: testRollback
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
@Test
public void testRollback() throws Exception {
this.shouldFindAllGamesInIndex();
FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em );
fem.beginSearchTransaction();
Game newGame = new Game( "Pong" );
newGame.setId( -10L );
fem.index( newGame );
fem.rollbackSearchTransaction();
Sleep.sleep(
MAX_SLEEP_TIME, () -> {
FullTextQuery fullTextQuery = fem.createFullTextQuery(
fem.getSearchFactory()
.buildQueryBuilder()
.forEntity( Game.class )
.get()
.keyword()
.onField(
"title"
)
.matching( "Pong" )
.createQuery(),
Game.class
);
// we can find it in the index even though it is not persisted in the database
boolean val1 = 0 == fullTextQuery.getResultSize();
// no result should be returned here either
boolean val2 = 0 == fullTextQuery.getResultList().size();
return val1 && val2;
}, 100, ""
);
}
示例8: clearData
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
private void clearData() throws Exception {
this.utx.begin();
this.em.joinTransaction();
System.out.println( "Dumping old records..." );
this.em.createQuery( "delete from Game" ).executeUpdate();
utx.commit();
FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em );
fem.beginSearchTransaction();
fem.purgeAll( Game.class );
fem.commitSearchTransaction();
}
开发者ID:Hotware,项目名称:Hibernate-Search-GenericJPA,代码行数:13,代码来源:EclipseLinkGlassFishIntegrationTest.java
示例9: testRollback
import org.hibernate.search.jpa.FullTextEntityManager; //导入方法依赖的package包/类
@Test
public void testRollback() throws Exception {
this.shouldFindAllGamesInIndex();
FullTextEntityManager fem = this.searchFactory.getFullTextEntityManager( this.em );
fem.beginSearchTransaction();
Game newGame = new Game( "Pong" );
fem.index( newGame );
newGame.setId( -10L );
fem.rollbackSearchTransaction();
Sleep.sleep(
MAX_SLEEP_TIME, () -> {
FullTextQuery fullTextQuery = fem.createFullTextQuery(
fem.getSearchFactory()
.buildQueryBuilder()
.forEntity( Game.class )
.get()
.keyword()
.onField(
"title"
)
.matching( "Pong" )
.createQuery(),
Game.class
);
// we can find it in the index even though it is not persisted in the database
boolean val1 = 0 == fullTextQuery.getResultSize();
// no result should be returned here either
boolean val2 = 0 == fullTextQuery.getResultList().size();
return val1 && val2;
}, 100, ""
);
}
开发者ID:Hotware,项目名称:Hibernate-Search-GenericJPA,代码行数:34,代码来源:EclipseLinkGlassFishIntegrationTest.java