本文整理了Java中javax.persistence.Query.executeUpdate
方法的一些代码示例,展示了Query.executeUpdate
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.executeUpdate
方法的具体详情如下:
包路径:javax.persistence.Query
类名称:Query
方法名:executeUpdate
[英]Execute an update or delete statement.
[中]执行update或delete语句。
代码示例来源:origin: spring-projects/spring-framework
protected void deleteAllPeopleUsingEntityManager(EntityManager em) {
em.createQuery("delete from Person p").executeUpdate();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void deferredQueryWithUpdate() {
EntityManagerFactory emf = mock(EntityManagerFactory.class);
EntityManager targetEm = mock(EntityManager.class);
Query query = mock(Query.class);
given(emf.createEntityManager()).willReturn(targetEm);
given(targetEm.createQuery("x")).willReturn(query);
given(targetEm.isOpen()).willReturn(true);
EntityManager em = SharedEntityManagerCreator.createSharedEntityManager(emf);
em.createQuery("x").executeUpdate();
verify(query).executeUpdate();
verify(targetEm).close();
}
代码示例来源:origin: kiegroup/jbpm
@After
public void after() throws Exception {
EntityManagerFactory emf = (EntityManagerFactory) context.get(EnvironmentName.ENTITY_MANAGER_FACTORY);
UserTransaction ut = InitialContext.doLookup("java:comp/UserTransaction");
ut.begin();
try {
EntityManager em = emf.createEntityManager();
em.createQuery("delete from CorrelationPropertyInfo").executeUpdate();
em.createQuery("delete from CorrelationKeyInfo").executeUpdate();
ut.commit();
} catch (Exception ex) {
ut.rollback();
Assert.fail("Exception thrown while trying to cleanup correlation data.");
}
cleanUp(context);
}
代码示例来源:origin: Impetus/Kundera
/**
* @return
*/
private void updateNamed(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
String updateQuery = "Update StudentLongPrimitive s SET s.name=Vivek where s.name=Amresh";
Query q = em.createQuery(updateQuery);
q.executeUpdate();
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
StudentLongPrimitive newStudent = em.find(StudentLongPrimitive.class, getRandomValue(long.class));
Assert.assertNotNull(newStudent);
Assert.assertEquals(getRandomValue(short.class), newStudent.getAge());
Assert.assertEquals("Vivek", newStudent.getName());
em.close();
}
代码示例来源:origin: Impetus/Kundera
/**
* Test delete all.
*/
private void testDeleteAll()
{
persistBooks();
int result = em.createQuery("delete from Book b").executeUpdate();
Assert.assertEquals(4, result);
assertDeleted(T, T, T, T);
}
代码示例来源:origin: hibernate/hibernate-orm
entityManager.createQuery( "delete from Book" ).executeUpdate();
entityManager.createQuery( "delete from Person" ).executeUpdate();
Person person = entityManager.find( Person.class, personId );
entityManager.createQuery( "delete from Book" ).executeUpdate();
entityManager.createQuery( "delete from Person" ).executeUpdate();
Person person = entityManager.find( Person.class, personId );
person.setName("John Doe");
entityManager.flush();
Person person = entityManager.find( Person.class, personId );
entityManager.createQuery( "update Person set name = UPPER(name)" ).executeUpdate();
代码示例来源:origin: Impetus/Kundera
/**
* Tear down.
*/
@After
public void tearDown()
{
em.createQuery("DELETE FROM Person p").executeUpdate();
em.close();
emf.close();
}
代码示例来源:origin: hibernate/hibernate-orm
@Test
public void testOrder() {
doInJPA( this::entityManagerFactory, entityManager -> {
entityManager.createNativeQuery("delete from Person").executeUpdate();
});
doInJPA( this::entityManagerFactory, entityManager -> {
Person person = new Person("John Doe");
person.id = 1L;
entityManager.persist(person);
});
doInJPA( this::entityManagerFactory, entityManager -> {
log.info("testFlushSQL");
//tag::flushing-order-example[]
Person person = entityManager.find( Person.class, 1L);
entityManager.remove(person);
Person newPerson = new Person( );
newPerson.setId( 2L );
newPerson.setName( "John Doe" );
entityManager.persist( newPerson );
//end::flushing-order-example[]
});
}
代码示例来源:origin: kiegroup/jbpm
EntityManager em = getEmf().createEntityManager();
Query query = em.createNativeQuery(
"select SEQUENCE_NAME from INFORMATION_SCHEMA.COLUMNS "
String seqName = (String) query.getSingleResult();
query = em.createNativeQuery("alter sequence " + seqName + " increment by 1000");
query.executeUpdate();
代码示例来源:origin: Impetus/Kundera
/**
* @return
*/
private void updateNamed(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
String updateQuery = "Update StudentLongWrapper s SET s.name='Vivek' where s.name='Amresh'";
Query q = em.createQuery(updateQuery);
q.executeUpdate();
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
StudentLongWrapper newStudent = em.find(StudentLongWrapper.class, getRandomValue(Long.class));
Assert.assertNotNull(newStudent);
Assert.assertEquals(getRandomValue(short.class), newStudent.getAge());
Assert.assertEquals("Vivek", newStudent.getName());
em.close();
}
代码示例来源:origin: hibernate/hibernate-orm
final EntityManagerFactory emf = persistenceProvider.createEntityManagerFactory( "hibernate-osgi-test", null );
EntityManager em = emf.createEntityManager();
em.getTransaction().begin();
em.persist( new DataPoint( "Brett" ) );
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
dp = em.find( DataPoint.class, 1 );
dp.setName( "Brett2" );
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
em.createQuery( "delete from DataPoint" ).executeUpdate();
em.getTransaction().commit();
em.close();
em = emf.createEntityManager();
em.getTransaction().begin();
dp = em.find( DataPoint.class, 1 );
assertNull( dp );
em.getTransaction().commit();
代码示例来源:origin: spring-projects/spring-data-jpa
@Transactional
@Override
public void deleteAllInBatch() {
em.createQuery(getDeleteAllQueryString()).executeUpdate();
}
代码示例来源:origin: Impetus/Kundera
/**
* Test delete simple.
*/
private void testDeleteSimple()
{
persistData();
int result = em.createQuery("delete from PersonEmbed p").executeUpdate();
Assert.assertEquals(4, result);
assertDeleted(T, T, T, T);
}
代码示例来源:origin: Impetus/Kundera
/**
* @return
*/
private void updateNamed(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
String updateQuery = "Update StudentDoublePrimitive s SET s.name='Vivek' where s.name='Amresh'";
Query q = em.createQuery(updateQuery);
q.executeUpdate();
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
StudentDoublePrimitive newStudent = em.find(StudentDoublePrimitive.class, getRandomValue(Double.class));
Assert.assertNotNull(newStudent);
Assert.assertEquals(getRandomValue(short.class), newStudent.getAge());
Assert.assertEquals("Vivek", newStudent.getName());
em.close();
}
代码示例来源:origin: kiegroup/jbpm
EntityManager em = emf.createEntityManager();
int varsUpdated = varLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Variable instances updated = " + varsUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
int nodesUpdated = nodeLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Node instances updated = " + nodesUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
int pInstancesUpdated = pInstanceLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Process instances updated = " + pInstancesUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
int taskVarUpdated = taskVarLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Task variables updated = " + taskVarUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
} catch (Throwable e) {
int auditTaskUpdated = auditTaskLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Task audit updated = " + auditTaskUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
int taskUpdated = taskLogQuery.executeUpdate();
report.addEntry(Type.INFO, "Tasks updated = " + taskUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
int contextInfoUpdated = contextInfoQuery.executeUpdate();
report.addEntry(Type.INFO, "Context info updated = " + contextInfoUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
} catch (Throwable e) {
int executorRequestsUpdated = executorRequestQuery.executeUpdate();
report.addEntry(Type.INFO, "Executor Jobs updated = " + executorRequestsUpdated + " for process instance id " + migrationSpec.getProcessInstanceId());
代码示例来源:origin: kiegroup/jbpm
@Override
public int executeUpdateString(String updateString) {
check();
Query query = this.em.createQuery(updateString);
return query.executeUpdate();
}
代码示例来源:origin: Impetus/Kundera
/**
* @return
*/
private void updateNamed(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
String updateQuery = "Update StudentDate s SET s.name=Vivek where s.name=Amresh";
Query q = em.createQuery(updateQuery);
q.executeUpdate();
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
StudentDate newStudent = em.find(StudentDate.class, getRandomValue(Date.class));
Assert.assertNotNull(newStudent);
Assert.assertEquals(getRandomValue(short.class), newStudent.getAge());
Assert.assertEquals("Vivek", newStudent.getName());
em.close();
}
代码示例来源:origin: Impetus/Kundera
private EntityManager getNewEM()
{
if (em != null && em.isOpen())
{
em.close();
}
// Delete by query.
Query query = em.createQuery("Delete from PersonMTORedis p");
int updateCount = query.executeUpdate();
return em = emf.createEntityManager();
}
}
代码示例来源:origin: kiegroup/jbpm
public int executeUpdateString(String updateString) {
check();
Query query = this.em.createQuery(updateString);
return query.executeUpdate();
}
代码示例来源:origin: Impetus/Kundera
/**
* @return
*/
private void updateNamed(boolean useSameEm)
{
EntityManager em = emf.createEntityManager();
String updateQuery = "Update StudentInt s SET s.name=Vivek where s.name=Amresh";
Query q = em.createQuery(updateQuery);
q.executeUpdate();
if (!useSameEm)
{
em.close();
em = emf.createEntityManager();
}
StudentInt newStudent = em.find(StudentInt.class, getRandomValue(int.class));
Assert.assertNotNull(newStudent);
Assert.assertEquals(getRandomValue(short.class), newStudent.getAge());
Assert.assertEquals("Vivek", newStudent.getName());
em.close();
}
内容来源于网络,如有侵权,请联系作者删除!