本文整理匯總了Java中com.haulmont.cuba.core.Query.executeUpdate方法的典型用法代碼示例。如果您正苦於以下問題:Java Query.executeUpdate方法的具體用法?Java Query.executeUpdate怎麽用?Java Query.executeUpdate使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類com.haulmont.cuba.core.Query
的用法示例。
在下文中一共展示了Query.executeUpdate方法的11個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: clearScheduledTasks
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Override
public void clearScheduledTasks() {
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
Query query = em.createNativeQuery("delete from SYS_SCHEDULED_EXECUTION");
query.executeUpdate();
query = em.createNativeQuery("delete from SYS_SCHEDULED_TASK");
query.executeUpdate();
tx.commit();
} finally {
tx.end();
}
}
示例2: checkSequenceExists
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
protected void checkSequenceExists(String entityName, long startValue, long increment) {
String seqName = getSequenceName(entityName);
if (existingSequences.contains(seqName))
return;
// Create sequence in separate transaction because it's name is cached and we want to be sure it is created
// regardless of possible errors in the invoking code
Transaction tx = persistence.createTransaction(getDataStore(entityName));
try {
EntityManager em = persistence.getEntityManager(getDataStore(entityName));
SequenceSupport sequenceSupport = getSequenceSupport(entityName);
Query query = em.createNativeQuery(sequenceSupport.sequenceExistsSql(seqName));
List list = query.getResultList();
if (list.isEmpty()) {
query = em.createNativeQuery(sequenceSupport.createSequenceSql(seqName, startValue, increment));
query.executeUpdate();
}
existingSequences.add(seqName);
tx.commit();
} finally {
tx.end();
}
}
示例3: testUpdateQuery
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Test
public void testUpdateQuery() throws Exception {
appender.clearMessages();
loadUser();
assertEquals(2, appender.filterMessages(m -> m.contains("> SELECT")).count()); // User, Group
appender.clearMessages();
try (Transaction tx = cont.persistence().createTransaction()) {
Query query = cont.entityManager().createQuery("update sec$User u set u.position = ?1 where u.loginLowerCase = ?2");
query.setParameter(1, "new position");
query.setParameter(2, this.user.getLoginLowerCase());
query.executeUpdate();
tx.commit();
}
appender.clearMessages();
User u = loadUser();
assertEquals("new position", u.getPosition());
assertEquals(1, appender.filterMessages(m -> m.contains("> SELECT")).count()); // Group
}
示例4: testUpdateQuery_CleanupMode
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Test
public void testUpdateQuery_CleanupMode() {
System.out.println("===================== BEGIN testUpdateQuery_CleanupMode =====================");
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
em.setSoftDeletion(false);
Query query = em.createQuery("update sec$Role r set r.description = ?1 where r.name = ?2");
query.setParameter(1, "Updated");
query.setParameter(2, "roleToBeDeleted");
int updated = query.executeUpdate();
assertEquals(1, updated);
tx.commit();
} finally {
tx.end();
}
System.out.println("===================== END testUpdateQuery_CleanupMode =====================");
}
示例5: deleteAll
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Override
public void deleteAll() {
try (Transaction tx = persistence.createTransaction()) {
Query query = persistence.getEntityManager().createQuery(
"delete from sample$Customer c where c.createdBy = :createdBy");
query.setParameter("createdBy", userSessionSource.getUserSession().getUser().getLogin());
query.executeUpdate();
tx.commit();
}
}
示例6: checkSequenceExists
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
protected void checkSequenceExists(String domain) {
String seqName = getSequenceName(domain);
if (containsSequence(seqName))
return;
// Create sequence in separate transaction because it's name is cached and we want to be sure it is created
// regardless of possible errors in the invoking code
Transaction tx = persistence.createTransaction(getDataStore(domain));
try {
lock.readLock().unlock();
lock.writeLock().lock();
EntityManager em = persistence.getEntityManager(getDataStore(domain));
Query query = em.createNativeQuery(getSequenceSupport(domain).sequenceExistsSql(seqName));
List list = query.getResultList();
if (list.isEmpty()) {
query = em.createNativeQuery(getSequenceSupport(domain).createSequenceSql(seqName, 1, 1));
query.executeUpdate();
}
tx.commit();
existingSequences.add(seqName);
} finally {
lock.readLock().lock();
lock.writeLock().unlock();
tx.end();
}
}
示例7: executeUpdateSql
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Override
@Transactional(timeout = 2)
public String executeUpdateSql(String sql) {
checkTestMode();
log.info("started: " + sql);
EntityManager em = persistence.getEntityManager();
Query query = em.createNativeQuery(sql);
query.executeUpdate();
log.info("finished: " + sql);
return "Done";
}
示例8: testNativeQuery
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Test
public void testNativeQuery() throws Exception {
appender.clearMessages();
loadUser();
assertEquals(2, appender.filterMessages(m -> m.contains("> SELECT")).count()); // User, Group
appender.clearMessages();
try (Transaction tx = cont.persistence().createTransaction()) {
Query query = cont.entityManager().createNativeQuery("update sec_user set position_ = ? where login_lc = ?");
query.setParameter(1, "new position");
query.setParameter(2, this.user.getLoginLowerCase());
query.executeUpdate(); // all evicted here
tx.commit();
}
appender.clearMessages();
User u;
try (Transaction tx = cont.persistence().createTransaction()) {
u = cont.entityManager().find(User.class, this.user.getId(), "user.browse");
assertNotNull(u);
tx.commit();
}
u = reserialize(u);
Group g = u.getGroup();
assertEquals(this.group, g);
assertNotNull(g.getName());
assertEquals("new position", u.getPosition());
assertEquals(2, appender.filterMessages(m -> m.contains("> SELECT")).count()); // User,Group
}
示例9: tearDown
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@After
public void tearDown() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Query q;
q = em.createNativeQuery("delete from SEC_USER_ROLE where ID = ? or ID = ?");
q.setParameter(1, userRole1Id.toString());
q.setParameter(2, userRole2Id.toString());
q.executeUpdate();
q = em.createNativeQuery("delete from SEC_USER where ID = ?");
q.setParameter(1, userId.toString());
q.executeUpdate();
q = em.createNativeQuery("delete from SEC_GROUP where ID = ?");
q.setParameter(1, groupId.toString());
q.executeUpdate();
q = em.createNativeQuery("delete from SEC_PERMISSION where ID = ? or ID = ?");
q.setParameter(1, permission1Id.toString());
q.setParameter(2, permission2Id.toString());
q.executeUpdate();
q = em.createNativeQuery("delete from SEC_ROLE where ID = ? or ID = ?");
q.setParameter(1, role1Id.toString());
q.setParameter(2, role2Id.toString());
q.executeUpdate();
tx.commit();
} finally {
tx.end();
}
}
示例10: setUp
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@Before
public void setUp() throws Exception {
cleanup();
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Query q;
q = em.createNativeQuery("delete from SEC_ENTITY_LOG");
q.executeUpdate();
LoggedEntity le = new LoggedEntity();
le.setName("sec$User");
le.setAuto(true);
em.persist(le);
LoggedAttribute la = new LoggedAttribute();
la.setEntity(le);
la.setName("email");
em.persist(la);
le = new LoggedEntity();
le.setName("sec$Role");
le.setAuto(true);
em.persist(le);
la = new LoggedAttribute();
la.setEntity(le);
la.setName("type");
em.persist(la);
tx.commit();
} finally {
tx.end();
}
entityLog = AppBeans.get(EntityLogAPI.NAME);
entityLog.invalidateCache();
}
示例11: tearDown
import com.haulmont.cuba.core.Query; //導入方法依賴的package包/類
@After
public void tearDown() throws Exception {
Transaction tx = cont.persistence().createTransaction();
try {
EntityManager em = cont.persistence().getEntityManager();
Query q = em.createNativeQuery("delete from SEC_USER_SETTING where USER_ID = ?");
q.setParameter(1, TestUserSessionSource.USER_ID);
q.executeUpdate();
tx.commit();
} finally {
tx.end();
}
}