本文整理了Java中com.haulmont.cuba.core.Query.executeUpdate
方法的一些代码示例,展示了Query.executeUpdate
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Query.executeUpdate
方法的具体详情如下:
包路径:com.haulmont.cuba.core.Query
类名称:Query
方法名:executeUpdate
[英]Execute an update or delete statement.
[中]执行update或delete语句。
代码示例来源:origin: com.haulmont.cuba/cuba-core
@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";
}
代码示例来源:origin: com.haulmont.fts/fts-core
@Override
public void emptyQueue() {
EntityManager em = persistence.getEntityManager();
Query q = em.createQuery("delete from sys$FtsQueue q");
q.executeUpdate();
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
@Override
public void run(EntityManager em) {
Query query = em.createQuery("delete from sys$ScheduledExecution e where e.id in ?1");
query.setParameter(1, subList);
query.executeUpdate();
}
});
代码示例来源:origin: com.haulmont.fts/fts-core
protected void removeQueuedItems(List<FtsQueue> list) {
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
for (int i = 0; i < list.size(); i += DEL_CHUNK) {
StringBuilder sb = new StringBuilder("delete from SYS_FTS_QUEUE where ID in (");
List<FtsQueue> sublist = list.subList(i, Math.min(i + DEL_CHUNK, list.size()));
for (int idx = 0; idx < sublist.size(); idx++) {
sb.append("?");
if (idx < sublist.size() - 1)
sb.append(", ");
}
sb.append(")");
DbTypeConverter converter = persistence.getDbTypeConverter();
Query query = em.createNativeQuery(sb.toString());
for (int idx = 0; idx < sublist.size(); idx++) {
query.setParameter(idx + 1, converter.getSqlObject(sublist.get(idx).getId()));
}
query.executeUpdate();
}
tx.commit();
}
}
代码示例来源:origin: com.haulmont.fts/fts-core
@Override
public void emptyFakeQueue(String entityName) {
EntityManager em = persistence.getEntityManager();
Query q = em.createQuery("delete from sys$FtsQueue q where q.entityName = ?1 and q.fake = true");
q.setParameter(1, entityName);
q.executeUpdate();
}
代码示例来源:origin: com.haulmont.fts/fts-core
@Override
public void emptyQueue(String entityName) {
EntityManager em = persistence.getEntityManager();
Query q = em.createQuery("delete from sys$FtsQueue q where q.entityName = ?1");
q.setParameter(1, entityName);
q.executeUpdate();
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
@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();
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
protected void deleteExpiredAccessTokensInDatabase() {
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
em.createQuery("delete from sys$AccessToken t where t.expiry < CURRENT_TIMESTAMP")
.executeUpdate();
tx.commit();
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
protected void deleteExpiredRefreshTokensInDatabase() {
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
em.createQuery("delete from sys$RefreshToken t where t.expiry < CURRENT_TIMESTAMP")
.executeUpdate();
tx.commit();
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
if (list.isEmpty()) {
query = em.createNativeQuery(sequenceSupport.createSequenceSql(sequenceName, sequence.getStartValue(), sequence.getIncrement()));
query.executeUpdate();
代码示例来源:origin: com.haulmont.cuba/cuba-core
@Override
public void resetRememberMeTokens() {
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
Query query = em.createQuery("delete from sec$RememberMeToken rt");
query.executeUpdate();
tx.commit();
} finally {
tx.end();
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
protected void removeAccessTokenFromDatabase(String accessTokenValue) {
try (Transaction tx = persistence.getTransaction()) {
EntityManager em = persistence.getEntityManager();
em.createQuery("delete from sys$AccessToken t where t.tokenValue = :tokenValue")
.setParameter("tokenValue", accessTokenValue)
.executeUpdate();
tx.commit();
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
protected void removeRefreshTokenFromDatabase(String refreshTokenValue) {
try (Transaction tx = persistence.getTransaction()) {
EntityManager em = persistence.getEntityManager();
em.createQuery("delete from sys$RefreshToken t where t.tokenValue = :tokenValue")
.setParameter("tokenValue", refreshTokenValue)
.executeUpdate();
tx.commit();
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
@Authenticated
@Override
public String jpqlExecuteUpdate(String queryString, boolean softDeletion) {
try {
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
em.setSoftDeletion(softDeletion);
Query query = em.createQuery(queryString);
int count = query.executeUpdate();
tx.commit();
return "Done: " + count + " entities affected, softDeletion=" + softDeletion;
} finally {
tx.end();
}
} catch (Throwable e) {
log.error("jpqlExecuteUpdate error", e);
return ExceptionUtils.getStackTrace(e);
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
@Override
public void resetRememberMeTokens(List<UUID> userIds) {
Transaction tx = persistence.getTransaction();
try {
EntityManager em = persistence.getEntityManager();
Query query = em.createQuery("delete from sec$RememberMeToken rt where rt.user.id in :userIds");
query.setParameter("userIds", userIds);
query.executeUpdate();
tx.commit();
} finally {
tx.end();
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
"delete from sec$ScreenHistory h where h.id in ?1");
deleteQuery.setParameter(1, toDelete);
deleteQuery.executeUpdate();
tx.commitRetaining();
代码示例来源:origin: com.haulmont.cuba/cuba-core
@Override
public void deleteStatistics(String name) {
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
Query q = em.createQuery("delete from sys$EntityStatistics s where s.name = ?1");
q.setParameter(1, getOriginalOrThisEntityName(name));
q.executeUpdate();
tx.commit();
} finally {
tx.end();
}
flushStatisticsCache();
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
protected void copyUserFolders(User fromUser, User toUser, Map<UUID, Presentation> presentationsMap) {
try (Transaction tx = persistence.createTransaction()) {
MetaClass effectiveMetaClass = metadata.getExtendedEntities().getEffectiveMetaClass(SearchFolder.class);
EntityManager em = persistence.getEntityManager();
try {
em.setSoftDeletion(false);
Query deleteSettingsQuery = em.createQuery(
String.format("delete from %s s where s.user.id = ?1", effectiveMetaClass.getName())
);
deleteSettingsQuery.setParameter(1, toUser.getId());
deleteSettingsQuery.executeUpdate();
} finally {
em.setSoftDeletion(true);
}
TypedQuery<SearchFolder> q = em.createQuery(
String.format("select s from %s s where s.user.id = ?1", effectiveMetaClass.getName()),
SearchFolder.class);
q.setParameter(1, fromUser.getId());
List<SearchFolder> fromUserFolders = q.getResultList();
Map<SearchFolder, SearchFolder> copiedFolders = new HashMap<>();
for (SearchFolder searchFolder : fromUserFolders) {
copyFolder(searchFolder, toUser, copiedFolders, presentationsMap);
}
tx.commit();
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
@Override
public void changeUserPassword(UUID userId, String newPasswordHash) {
Transaction tx = persistence.createTransaction();
try {
EntityManager em = persistence.getEntityManager();
User user = em.find(User.class, userId, CHANGE_PASSWORD_VIEW);
if (user == null) {
throw new EntityAccessException(User.class, userId);
}
user.setPassword(newPasswordHash);
user.setChangePasswordAtNextLogon(false);
// reset remember me for user
Query query = em.createQuery("delete from sec$RememberMeToken rt where rt.user.id=:userId");
query.setParameter("userId", userId);
query.executeUpdate();
tx.commit();
} finally {
tx.end();
}
}
代码示例来源:origin: com.haulmont.cuba/cuba-core
protected Map<UUID, Presentation> copyPresentations(User fromUser, User toUser) {
Map<UUID, Presentation> presentationMap = new HashMap<>();
try (Transaction tx = persistence.createTransaction()) {
EntityManager em = persistence.getEntityManager();
// delete existing
Query delete = em.createQuery("delete from sec$Presentation p where p.user.id = ?1");
delete.setParameter(1, toUser.getId());
delete.executeUpdate();
// copy settings
TypedQuery<Presentation> selectQuery = em.createQuery(
"select p from sec$Presentation p where p.user.id = ?1", Presentation.class);
selectQuery.setParameter(1, fromUser.getId());
List<Presentation> presentations = selectQuery.getResultList();
for (Presentation presentation : presentations) {
Presentation newPresentation = metadata.create(Presentation.class);
newPresentation.setUser(toUser);
newPresentation.setComponentId(presentation.getComponentId());
newPresentation.setAutoSave(presentation.getAutoSave());
newPresentation.setName(presentation.getName());
newPresentation.setXml(presentation.getXml());
presentationMap.put(presentation.getId(), newPresentation);
em.persist(newPresentation);
}
tx.commit();
return presentationMap;
}
}
内容来源于网络,如有侵权,请联系作者删除!