List of usage examples for javax.persistence Query executeUpdate
int executeUpdate();
From source file:com.epam.training.taranovski.web.project.repository.implementation.VacancyRepositoryImplementation.java
@Override public boolean clearSkills(Vacancy vacancy) { EntityManager em = entityManagerFactory.createEntityManager(); boolean success = true; try {//from w w w.j av a 2 s. co m em.getTransaction().begin(); Query query = em.createNamedQuery("VacancySkill.clearSkillsForVacancy"); query.setParameter("vacancy", vacancy); query.executeUpdate(); em.getTransaction().commit(); success = true; } catch (RuntimeException e) { Logger.getLogger(VacancyRepositoryImplementation.class.getName()).info(e); success = false; } finally { if (em.getTransaction().isActive()) { em.getTransaction().rollback(); success = false; } em.close(); } return success; }
From source file:com.katsu.jpa.dao.JpaDao.java
@Override @Transactional/*from ww w . j a v a2 s . c om*/ public void deleteById(ID id) { Query q = em.createQuery(getDAOReflection().getDeleteByIdQuery()); q.setParameter(ID, id); q.executeUpdate(); }
From source file:org.orcid.persistence.dao.impl.OrgDisambiguatedDaoImpl.java
@Override @Transactional//ww w .j ava2s. c o m public void updateIndexingStatus(Long orgDisambiguatedId, IndexingStatus indexingStatus) { String queryString = null; if (IndexingStatus.DONE.equals(indexingStatus)) { queryString = "update OrgDisambiguatedEntity set indexingStatus = :indexingStatus, lastIndexedDate = now() where id = :orgDisambiguatedId"; } else { queryString = "update OrgDisambiguatedEntity set indexingStatus = :indexingStatus where id = :orgDisambiguatedId"; } Query query = entityManager.createQuery(queryString); query.setParameter("orgDisambiguatedId", orgDisambiguatedId); query.setParameter("indexingStatus", indexingStatus); query.executeUpdate(); }
From source file:com.mothsoft.alexis.dao.UserDaoImpl.java
private void purgeStaleTokens(User user, Long millisAgeAllowed) { final Date oldestPermissible = new Date(System.currentTimeMillis() - millisAgeAllowed); final Query query = this.em.createQuery( "DELETE FROM UserApiToken token WHERE token.user.id = :userId AND token.lastUsed < :oldestDate"); query.setParameter("userId", user.getId()); query.setParameter("oldestDate", oldestPermissible); int purged = query.executeUpdate(); logger.debug("Purged " + purged + " stale API tokens for user: " + user.getUsername()); }
From source file:com.music.dao.Dao.java
protected int executeQuery(String query, String[] names, Object[] args) { if (names == null) { names = new String[] {}; }/* w ww . ja v a2 s. c o m*/ if (args == null) { args = new Object[] {}; } Query q = entityManager.createQuery(query); for (int i = 0; i < names.length; i++) { q.setParameter(names[i], args[i]); } return q.executeUpdate(); }
From source file:es.ucm.fdi.dalgs.course.repository.CourseRepository.java
public Boolean deleteCoursesForSubject(Collection<Subject> subjects) { try {/* w w w.j a v a2 s . c o m*/ Query query = em.createQuery("UPDATE Course c SET c.isDeleted = true WHERE c.subject in ?1"); query.setParameter(1, subjects); int n = query.executeUpdate(); if (n > 0) return true; else return false; } catch (Exception e) { logger.error(e.getMessage()); return false; } }
From source file:org.orcid.persistence.dao.impl.OrgDisambiguatedDaoImpl.java
@Override @Transactional/*from w ww . j a va 2 s .c om*/ public void createUniqueConstraint() { Query query = entityManager.createNativeQuery( "ALTER TABLE org_disambiguated ADD CONSTRAINT org_disambiguated_unique_constraints UNIQUE (name, city, region, country, source_type)"); query.executeUpdate(); }
From source file:com.epam.ipodromproject.repository.jpa.JPABetRepository.java
@Transactional @Override//from w ww . j a v a 2 s .c o m public void cancelBetsByCompetition(Long competitionID) { Query query = entityManager.createNamedQuery("Bet.cancelBetsByCompetitionID"); query.setParameter("competitionID", competitionID); query.setParameter("betResult", BetResult.NOT_CONSIDERED); query.setParameter("betResultToSet", BetResult.MONEY_RETURNED); query.executeUpdate(); }
From source file:org.esa.cci.sst.tools.BasicTool.java
public void initialize() { if (initialised) { return;//from w w w. j av a2 s .co m } SstLogging.getLogger().info("connecting to database " + config.getStringValue("openjpa.ConnectionURL")); try { persistenceManager = PersistenceManager.create(Constants.PERSISTENCE_UNIT_NAME, Constants.PERSISTENCE_RETRY_COUNT, config.getAsProperties()); } catch (Exception e) { throw new ToolException("Unable to establish database connection.", e, ToolException.TOOL_DB_ERROR); } if (config.getBooleanValue("mms.db.useindex", false)) { try { persistenceManager.transaction(); final Query setSeqScanOff = persistenceManager.createNativeQuery("set enable_seqscan to off"); setSeqScanOff.executeUpdate(); persistenceManager.commit(); } catch (Exception e) { SstLogging.getLogger().warning("failed setting seqscan to off: " + e.getMessage()); } } toolStorage = persistenceManager.getStorage(); initialised = true; }
From source file:org.orcid.persistence.dao.impl.ProfileKeywordDaoImpl.java
/** * Adds a keyword to a specific profile/*from w w w. j a va2s . com*/ * @param orcid * @param keyword * @return true if the keyword was successfully created on database * */ @Override @Transactional public boolean addProfileKeyword(String orcid, String keyword) { Query query = entityManager.createNativeQuery( "INSERT INTO profile_keyword (date_created, last_modified, profile_orcid, keywords_name) VALUES (now(), now(), :orcid, :keywords_name)"); query.setParameter("orcid", orcid); query.setParameter("keywords_name", keyword); return query.executeUpdate() > 0 ? true : false; }