List of usage examples for javax.persistence Query executeUpdate
int executeUpdate();
From source file:mx.edu.ittepic.proyectofinal.ejbs.ejbContrasena.java
public String updateUserWithPassword(String userid, String username, String password, String phone, String neigborhood, String zipcode, String city, String country, String state, String region, String street, String email, String streetnumber, String photo, String cellphone, String companyid, String roleid, String gender) { Message m = new Message(); Users r = new Users(); GsonBuilder builder = new GsonBuilder(); Gson gson = builder.create();//from w ww .j av a2s.c o m Company com = entity.find(Company.class, Integer.parseInt(companyid)); Role rol = entity.find(Role.class, Integer.parseInt(roleid)); try { Query q = entity.createNamedQuery("Users.updateUserWithPassword").setParameter("username", username) .setParameter("password", password).setParameter("phone", phone) .setParameter("neigborhood", neigborhood).setParameter("zipcode", zipcode) .setParameter("city", city).setParameter("country", country).setParameter("state", state) .setParameter("region", region).setParameter("street", street).setParameter("email", email) .setParameter("streetnumber", streetnumber).setParameter("photo", photo) .setParameter("cellphone", cellphone).setParameter("companyid", com).setParameter("roleid", rol) .setParameter("gender", gender.charAt(0)).setParameter("userid", Integer.parseInt(userid)); String pass = password; String passmd5 = DigestUtils.md5Hex(pass); Query a = entity.createNamedQuery("Users.updateUserWithPasswordE").setParameter("username", username) .setParameter("password", passmd5).setParameter("phone", phone) .setParameter("neigborhood", neigborhood).setParameter("zipcode", zipcode) .setParameter("city", city).setParameter("country", country).setParameter("state", state) .setParameter("region", region).setParameter("street", street).setParameter("email", email) .setParameter("streetnumber", streetnumber).setParameter("photo", photo) .setParameter("cellphone", cellphone).setParameter("companyid", com).setParameter("roleid", rol) .setParameter("gender", gender.charAt(0)).setParameter("userid", Integer.parseInt(userid)); if (q.executeUpdate() == 1 && a.executeUpdate() == 1) { m.setCode(200); m.setMsg("Se actualizo correctamente."); m.setDetail("OK"); } else { m.setCode(404); m.setMsg("No se realizo la actualizacion"); m.setDetail(""); } } catch (IllegalStateException e) { m.setCode(404); m.setMsg("No se realizo la actualizacion"); m.setDetail(e.toString()); } catch (TransactionRequiredException e) { m.setCode(404); m.setMsg("No se realizo la actualizacion"); m.setDetail(e.toString()); } catch (QueryTimeoutException e) { m.setCode(404); m.setMsg("No se realizo la actualizacion"); m.setDetail(e.toString()); } catch (PersistenceException e) { m.setCode(404); m.setMsg("No se realizo la actualizacion"); m.setDetail(e.toString()); } return gson.toJson(m); }
From source file:org.rhq.enterprise.server.alert.AlertManagerBean.java
public int deleteAlerts(Subject user, int[] alertIds) { if (alertIds == null || alertIds.length == 0) { return 0; }//from w w w.j a v a2 s . com List<Integer> alertIdList = ArrayUtils.wrapInList(alertIds); checkAlertsPermission(user, alertIdList); Query deleteConditionLogsQuery = entityManager .createNamedQuery(AlertConditionLog.QUERY_DELETE_BY_ALERT_IDS); Query deleteNotifLogsQuery = entityManager.createNamedQuery(AlertNotificationLog.QUERY_DELETE_BY_ALERT_IDS); Query deleteAlertsQuery = entityManager.createNamedQuery(Alert.QUERY_DELETE_BY_IDS); int updated = 0; BatchIterator<Integer> batchIter = new BatchIterator<Integer>(alertIdList); for (List<Integer> nextBatch : batchIter) { // need to delete related objects before deleting alerts deleteConditionLogsQuery.setParameter("alertIds", nextBatch); deleteConditionLogsQuery.executeUpdate(); deleteNotifLogsQuery.setParameter("alertIds", nextBatch); deleteNotifLogsQuery.executeUpdate(); // now we can delete alerts deleteAlertsQuery.setParameter("alertIds", nextBatch); updated += deleteAlertsQuery.executeUpdate(); } return updated; }
From source file:org.orcid.persistence.dao.impl.ProfileDaoImpl.java
@Override @Transactional/*w ww.j a v a 2s. c o m*/ public void updatePreferences(String orcid, boolean sendChangeNotifications, boolean sendAdministrativeChangeNotifications, boolean sendOrcidNews, boolean sendMemberUpdateRequests, Visibility activitiesVisibilityDefault, boolean enableDeveloperTools, float sendEmailFrequencyDays) { Query updateQuery = entityManager.createQuery( "update ProfileEntity set lastModified = now(), sendChangeNotifications = :sendChangeNotifications, sendAdministrativeChangeNotifications = :sendAdministrativeChangeNotifications, sendOrcidNews = :sendOrcidNews, sendMemberUpdateRequests = :sendMemberUpdateRequests, activitiesVisibilityDefault = :activitiesVisibilityDefault, enableDeveloperTools = :enableDeveloperTools, sendEmailFrequencyDays = :sendEmailFrequencyDays where orcid = :orcid"); updateQuery.setParameter("orcid", orcid); updateQuery.setParameter("sendChangeNotifications", sendChangeNotifications); updateQuery.setParameter("sendAdministrativeChangeNotifications", sendAdministrativeChangeNotifications); updateQuery.setParameter("sendOrcidNews", sendOrcidNews); updateQuery.setParameter("sendMemberUpdateRequests", sendMemberUpdateRequests); updateQuery.setParameter("activitiesVisibilityDefault", activitiesVisibilityDefault); updateQuery.setParameter("enableDeveloperTools", enableDeveloperTools); updateQuery.setParameter("sendEmailFrequencyDays", sendEmailFrequencyDays); updateQuery.executeUpdate(); }
From source file:com.gettec.fsnip.fsn.dao.product.impl.ProductDAOImpl.java
@Override public boolean setBarcodeToQRcode(String barcode, Long productID, String QRStart, String QREnd) { //???0?/*from www . jav a2s .c om*/ String isExist = "SELECT pb.start_num,pb.end_num FROM product_barcode_to_qrcode pb WHERE ?1 BETWEEN start_num and end_num OR ?2 BETWEEN start_num AND end_num or ?1<=start_num AND ?2>=end_num"; Query isExistQuery = entityManager.createNativeQuery(isExist); isExistQuery.setParameter(1, QRStart); isExistQuery.setParameter(2, QREnd); int existSize = isExistQuery.getResultList().size(); //0?? if (existSize == 0) { String insertSql = "INSERT INTO product_barcode_to_qrcode (product_barcode,product_id,start_num,end_num )VALUES (?1,?2,?3,?4) "; Query insertQuery = entityManager.createNativeQuery(insertSql); insertQuery.setParameter(1, barcode); insertQuery.setParameter(2, productID); insertQuery.setParameter(3, QRStart); insertQuery.setParameter(4, QREnd); int success = insertQuery.executeUpdate(); System.out.print("----sql----" + success); if (success == 1) { return true; } else { return false; } } return false; }
From source file:org.j2free.jpa.Controller.java
/** * //w w w . j a v a 2 s .c om * @param query * @param parameters * @return */ public int update(Query query, KeyValuePair<String, ? extends Object>... parameters) { if (parameters != null) { for (KeyValuePair<String, ? extends Object> parameter : parameters) { query.setParameter(parameter.key, parameter.value); } } return query.executeUpdate(); }
From source file:org.apache.ambari.server.upgrade.UpgradeCatalog210.java
private void updateAlertDefinitionEntitySource(final String alertName, final String source, final String newHash) { executeInTransaction(new Runnable() { @Override// w ww . ja v a 2 s . c o m public void run() { EntityManager em = getEntityManagerProvider().get(); Query nativeQuery = em.createNativeQuery( "UPDATE alert_definition SET alert_source=?1, hash=?2 WHERE " + "definition_name=?3"); nativeQuery.setParameter(1, source); nativeQuery.setParameter(2, newHash); nativeQuery.setParameter(3, alertName); nativeQuery.executeUpdate(); } }); }
From source file:org.apache.falcon.state.store.jdbc.JDBCStateStore.java
@Override public void updateExecutionInstance(InstanceState instanceState) throws StateStoreException { InstanceID id = new InstanceID(instanceState.getInstance()); String key = id.toString();/*from ww w. j a v a 2 s . com*/ if (!executionInstanceExists(id)) { throw new StateStoreException("Instance with key, " + key + " does not exist."); } EntityManager entityManager = getEntityManager(); beginTransaction(entityManager); Query q = entityManager.createNamedQuery(PersistenceConstants.UPDATE_INSTANCE); ExecutionInstance instance = instanceState.getInstance(); q.setParameter("id", key); q.setParameter("cluster", instance.getCluster()); q.setParameter("externalID", instance.getExternalID()); q.setParameter("instanceTime", new Timestamp(instance.getInstanceTime().getMillis())); q.setParameter("creationTime", new Timestamp(instance.getCreationTime().getMillis())); if (instance.getActualEnd() != null) { q.setParameter("actualEndTime", new Timestamp(instance.getActualEnd().getMillis())); } q.setParameter("currentState", instanceState.getCurrentState().toString()); if (instance.getActualStart() != null) { q.setParameter("actualStartTime", new Timestamp(instance.getActualStart().getMillis())); } q.setParameter("instanceSequence", instance.getInstanceSequence()); if (instanceState.getInstance().getAwaitingPredicates() != null && !instanceState.getInstance().getAwaitingPredicates().isEmpty()) { try { q.setParameter("awaitedPredicates", BeanMapperUtil.getAwaitedPredicates(instanceState)); } catch (IOException e) { throw new StateStoreException(e); } } if (instance.getProperties() != null && !instance.getProperties().isEmpty()) { try { q.setParameter("properties", BeanMapperUtil.getProperties(instanceState)); } catch (IOException e) { throw new StateStoreException(e); } } q.executeUpdate(); commitAndCloseTransaction(entityManager); }
From source file:org.broadleafcommerce.core.order.dao.OrderDaoImpl.java
@Override public boolean acquireLock(Order order) { String orderLockKey = getOrderLockKey(); // First, we'll see if there's a record of a lock for this order Query q = em.createNamedQuery("BC_ORDER_LOCK_READ"); q.setParameter("orderId", order.getId()); q.setParameter("key", orderLockKey); q.setHint(QueryHints.HINT_CACHEABLE, false); Long count = (Long) q.getSingleResult(); if (count == 0L) { // If there wasn't a lock, we'll try to create one. It's possible that another thread is attempting the // same thing at the same time, so we might get a constraint violation exception here. That's ok. If we // successfully inserted a record, that means that we are the owner of the lock right now. try {/* ww w . ja v a2s. co m*/ OrderLock ol = (OrderLock) entityConfiguration.createEntityInstance(OrderLock.class.getName()); ol.setOrderId(order.getId()); ol.setLocked(true); ol.setKey(orderLockKey); ol.setLastUpdated(System.currentTimeMillis()); em.persist(ol); return true; } catch (EntityExistsException e) { return false; } } // We weren't successful in creating a lock, which means that there was some previously created lock // for this order. We'll attempt to update the status from unlocked to locked. If that is successful, // we acquired the lock. q = em.createNamedQuery("BC_ORDER_LOCK_ACQUIRE"); q.setParameter("orderId", order.getId()); q.setParameter("currentTime", System.currentTimeMillis()); q.setParameter("key", orderLockKey); Long orderLockTimeToLive = getDatabaseOrderLockTimeToLive(); q.setParameter("timeout", orderLockTimeToLive == -1L ? orderLockTimeToLive : System.currentTimeMillis() - orderLockTimeToLive); q.setHint(QueryHints.HINT_CACHEABLE, false); int rowsAffected = q.executeUpdate(); return rowsAffected == 1; }
From source file:org.rhq.enterprise.server.content.ContentManagerBean.java
@RequiredPermission(Permission.MANAGE_INVENTORY) public void deletePackageVersion(Subject subject, int packageVersionId) { Query q = entityManager.createNamedQuery(PackageVersion.DELETE_SINGLE_IF_NO_CONTENT_SOURCES_OR_REPOS); q.setParameter("packageVersionId", packageVersionId); q.executeUpdate(); }
From source file:org.rhq.enterprise.server.operation.OperationManagerBean.java
@SuppressWarnings("unchecked") private void deleteOperationHistory_helper(int historyId) { Query historyArgumentsQuery = entityManager .createNamedQuery(OperationHistory.QUERY_GET_PARAMETER_CONFIGURATION_IDS); Query historyResultsQuery = entityManager .createNamedQuery(OperationHistory.QUERY_GET_RESULT_CONFIGURATION_IDS); historyArgumentsQuery.setParameter("historyId", historyId); historyResultsQuery.setParameter("historyId", historyId); List<Integer> historyArgumentConfigurationIds = historyArgumentsQuery.getResultList(); List<Integer> historyResultConfigurationIds = historyResultsQuery.getResultList(); Query operationHistoryDeleteQuery = entityManager .createNamedQuery(OperationHistory.QUERY_DELETE_BY_HISTORY_IDS); operationHistoryDeleteQuery.setParameter("historyId", historyId); operationHistoryDeleteQuery.executeUpdate(); List<Integer> allConfigurationIdsToDelete = new ArrayList<Integer>( historyArgumentConfigurationIds.size() + historyResultConfigurationIds.size()); allConfigurationIdsToDelete.addAll(historyArgumentConfigurationIds); allConfigurationIdsToDelete.addAll(historyResultConfigurationIds); configurationManager.deleteConfigurations(allConfigurationIdsToDelete); return;//from ww w . j ava 2 s. com }