本文整理了Java中org.hibernate.query.NativeQuery.addSynchronizedEntityClass()
方法的一些代码示例,展示了NativeQuery.addSynchronizedEntityClass()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。NativeQuery.addSynchronizedEntityClass()
方法的具体详情如下:
包路径:org.hibernate.query.NativeQuery
类名称:NativeQuery
方法名:addSynchronizedEntityClass
暂无
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testFlushAutoSQLSynchronization() {
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.createNativeQuery( "delete from Person" ).executeUpdate();;
} );
doInJPA( this::entityManagerFactory, entityManager -> {
log.info( "testFlushAutoSQLSynchronization" );
//tag::flushing-auto-flush-sql-synchronization-example[]
assertTrue(((Number) entityManager
.createNativeQuery( "select count(*) from Person")
.getSingleResult()).intValue() == 0 );
Person person = new Person( "John Doe" );
entityManager.persist( person );
Session session = entityManager.unwrap( Session.class );
assertTrue(((Number) session
.createNativeQuery( "select count(*) from Person")
.addSynchronizedEntityClass( Person.class )
.uniqueResult()).intValue() == 1 );
//end::flushing-auto-flush-sql-synchronization-example[]
} );
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testManualSynchronization() {
Session s = openSession();
s.beginTransaction();
sessionFactory().getStatistics().clear();
// create an Organization...
Organization jboss = new Organization( "JBoss" );
s.persist( jboss );
// now query on Employment, this should not cause an auto-flush
s.createSQLQuery( getEmploymentSQL() ).addSynchronizedQuerySpace( "ABC" ).list();
assertEquals( 0, sessionFactory().getStatistics().getEntityInsertCount() );
// now try to query on Employment but this time add Organization as a synchronized query space...
s.createSQLQuery( getEmploymentSQL() ).addSynchronizedEntityClass( Organization.class ).list();
assertEquals( 1, sessionFactory().getStatistics().getEntityInsertCount() );
// clean up
s.delete( jboss );
s.getTransaction().commit();
s.close();
}
代码示例来源:origin: hibernate/hibernate-ogm
@Benchmark
@OperationsPerInvocation(OPERATIONS_PER_INVOCATION)
public void findEntityByPropertyUsingNativeQuery(TestDataInserter inserter, Blackhole blackhole) throws Exception {
EntityManagerFactoryHolder stateHolder = inserter.stateHolder;
EntityManager entityManager = stateHolder.entityManagerFactory.createEntityManager();
stateHolder.transactionManager.begin();
entityManager.joinTransaction();
for ( int i = 0; i < OPERATIONS_PER_INVOCATION; i++ ) {
int mName = stateHolder.rand.nextInt( 26 );
Query nativeQuery = entityManager.createNativeQuery( "db.AuthorWithSequence.find( { 'mname' : '" + mName + "' } )", AuthorWithSequence.class );
nativeQuery.unwrap( NativeQuery.class ).addSynchronizedEntityClass( AuthorWithSequence.class );
nativeQuery.setMaxResults( 50 );
@SuppressWarnings("unchecked")
List<AuthorWithSequence> authors = nativeQuery.getResultList();
for ( AuthorWithSequence author : authors ) {
blackhole.consume( author.getLname() );
}
}
stateHolder.transactionManager.commit();
entityManager.close();
}
代码示例来源:origin: hibernate/hibernate-ogm
@Benchmark
@OperationsPerInvocation(OPERATIONS_PER_INVOCATION)
public void findEntityByPropertyUsingNativeQueryWithManualFlushing(TestDataInserter inserter, Blackhole blackhole) throws Exception {
EntityManagerFactoryHolder stateHolder = inserter.stateHolder;
EntityManager entityManager = stateHolder.entityManagerFactory.createEntityManager();
stateHolder.transactionManager.begin();
entityManager.joinTransaction();
for ( int i = 0; i < OPERATIONS_PER_INVOCATION; i++ ) {
int mName = stateHolder.rand.nextInt( 26 );
Query nativeQuery = entityManager.createNativeQuery( "db.AuthorWithSequence.find( { 'mname' : '" + mName + "' } )", AuthorWithSequence.class );
nativeQuery.unwrap( NativeQuery.class ).addSynchronizedEntityClass( AuthorWithSequence.class );
nativeQuery.setMaxResults( 50 );
nativeQuery.unwrap( NativeQuery.class ).setFlushMode( FlushMode.MANUAL );
@SuppressWarnings("unchecked")
List<AuthorWithSequence> authors = nativeQuery.getResultList();
for ( AuthorWithSequence author : authors ) {
blackhole.consume( author.getLname() );
}
}
stateHolder.transactionManager.commit();
entityManager.close();
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@Test
public void test2ndLevelCacheWithNativeUpdateStatementSynchronization() {
doInJPA(entityManager -> {
assertEquals(1, getLatestPostComments(entityManager).size());
printQueryCacheRegionStatistics();
LOGGER.info("Execute native query with synchronization");
entityManager.createNativeQuery(
"UPDATE post SET title = '\"'||title||'\"' ")
.unwrap(NativeQuery.class)
.addSynchronizedEntityClass(Post.class)
.executeUpdate();
assertEquals(1, getLatestPostComments(entityManager).size());
printQueryCacheRegionStatistics();
});
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@Test
public void testFlushAutoNativeSQLSynchronizedEntityClass() {
doInJPA(entityManager -> {
assertEquals(
0,
((Number)
entityManager
.createNativeQuery(
"select count(*) " +
"from post")
.getSingleResult()
).intValue()
);
Post post = new Post("High-Performance Java Persistence");
entityManager.persist(post);
int postCount = ((Number)
entityManager
.unwrap(Session.class)
.createNativeQuery(
"select count(*) " +
"from post")
.addSynchronizedEntityClass(Post.class)
.getSingleResult()).intValue();
assertEquals(1, postCount);
});
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
@Test
public void testConsistencyWhenSQLUpdating() {
LOGGER.info("Updating Child entities using SQL");
doInJPA(entityManager -> {
Repository repository = (Repository)
entityManager.find(Repository.class, 1L);
for (Commit commit : repository.getCommits()) {
assertFalse(commit.review);
}
});
doInJPA(entityManager -> {
entityManager.createNativeQuery(
"update Commit c " +
"set c.review = true ")
.unwrap(NativeQuery.class)
.addSynchronizedEntityClass(Commit.class)
.executeUpdate();
});
doInJPA(entityManager -> {
Repository repository =
entityManager.find(Repository.class, 1L);
for(Commit commit : repository.getCommits()) {
assertTrue(commit.review);
}
});
}
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
"JOIN board b on b.id = p.board_id " +
"GROUP BY forum")
.addSynchronizedEntityClass(Board.class)
.addSynchronizedEntityClass(Post.class)
.setResultTransformer( Transformers.aliasToBean(ForumCount.class))
.list();
代码示例来源:origin: vladmihalcea/high-performance-java-persistence
"JOIN board b on b.id = p.board_id " +
"GROUP BY forum")
.addSynchronizedEntityClass(Board.class)
.addSynchronizedEntityClass(Post.class)
.setResultTransformer( Transformers.aliasToBean(ForumCount.class))
.list();
内容来源于网络,如有侵权,请联系作者删除!