当前位置: 首页>>代码示例>>Java>>正文


Java Query.executeUpdate方法代码示例

本文整理汇总了Java中javax.persistence.Query.executeUpdate方法的典型用法代码示例。如果您正苦于以下问题:Java Query.executeUpdate方法的具体用法?Java Query.executeUpdate怎么用?Java Query.executeUpdate使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在javax.persistence.Query的用法示例。


在下文中一共展示了Query.executeUpdate方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: removeLocalizedValue

import javax.persistence.Query; //导入方法依赖的package包/类
@Override
@TransactionAttribute(TransactionAttributeType.MANDATORY)
public void removeLocalizedValue(long objectKey,
        LocalizedObjectTypes objectType, String localeString) {

    Query query = dm
            .createNamedQuery("LocalizedResource.deleteForObjectAndTypeAndLocale");
    query.setParameter("objectKey", Long.valueOf(objectKey));
    query.setParameter("objectType", objectType);
    query.setParameter("locale", localeString);
    query.executeUpdate();

}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:14,代码来源:LocalizerServiceBean.java

示例2: deleteGroupLevelAppResource

import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public int deleteGroupLevelAppResource(String appName, final String groupName, final String templateName) {
    final Query q = em.createNamedQuery(JpaGroupAppConfigTemplate.QUERY_DELETE_GROUP_LEVEL_APP_RESOURCE_BY_APP_GROUP_TEMPLATE_NAME);
    q.setParameter(JpaGroupAppConfigTemplate.QUERY_PARAM_APP_NAME, appName);
    q.setParameter(JpaGroupAppConfigTemplate.QUERY_PARAM_GRP_NAME, groupName);
    q.setParameter(JpaGroupAppConfigTemplate.QUERY_PARAM_TEMPLATE_NAME, templateName);
    return q.executeUpdate();
}
 
开发者ID:cerner,项目名称:jwala,代码行数:9,代码来源:ResourceDaoImpl.java

示例3: deleteEntities

import javax.persistence.Query; //导入方法依赖的package包/类
private void deleteEntities(Class<?> entity){

        if(entity == null || entity.getAnnotation(Entity.class) == null){
            throw new IllegalArgumentException("Invalid non-entity class");
        }

        String name = entity.getSimpleName();

        /*
            Note: we passed as input a Class<?> instead of a String to
            avoid SQL injection. However, being here just test code, it should
            not be a problem. But, as a good habit, always be paranoiac about
            security, above all when you have code that can delete the whole
            database...
         */

        Query query = em.createQuery("delete from " + name);
        query.executeUpdate();
    }
 
开发者ID:arcuri82,项目名称:testing_security_development_enterprise_systems,代码行数:20,代码来源:ResetService.java

示例4: updateGroupWebServerResourceMetaData

import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public void updateGroupWebServerResourceMetaData(String groupName, String resourceName, String metaData) {
    final Query q = entityManager.createNamedQuery(JpaGroupWebServerConfigTemplate.UPDATE_GROUP_WEBSERVER_TEMPLATE_META_DATA);
    q.setParameter("grpName", groupName);
    q.setParameter("templateName", resourceName);
    q.setParameter("metaData", metaData);

    int numEntities;

    try {
        numEntities = q.executeUpdate();
    } catch (RuntimeException re) {
        LOGGER.error("Error updating group web server resource meta data {} in group {}", resourceName, groupName, re);
        throw new ResourceTemplateMetaDataUpdateException(groupName, resourceName, re);
    }

    if (numEntities == 0) {
        LOGGER.error("Error updating group web server resource meta data numEntities=0 {} in group {}", resourceName, groupName);
        throw new ResourceTemplateMetaDataUpdateException(groupName, resourceName);
    }

}
 
开发者ID:cerner,项目名称:jwala,代码行数:23,代码来源:GroupCrudServiceImpl.java

示例5: executeSqlQuery

import javax.persistence.Query; //导入方法依赖的package包/类
/**
 * Run a good old SQL query
 *
 * @return the number of entities updated or deleted
 */
public int executeSqlQuery(@Nonnull final String queryString,
                           @Nullable final Map<String, Object> parameters) throws DatabaseException {
    final EntityManager em = this.databaseConnection.getEntityManager();
    try {
        final Query q = em.createNativeQuery(queryString);
        if (parameters != null) {
            parameters.forEach(q::setParameter);
        }
        em.getTransaction().begin();
        int updated = q.executeUpdate();
        em.getTransaction().commit();
        return updated;
    } catch (final PersistenceException e) {
        final String message = String.format("Failed to execute plain SQL query %s with %s parameters on DB %s",
                queryString, parameters != null ? parameters.size() : "null", this.databaseConnection.getName());
        throw new DatabaseException(message, e);
    } finally {
        em.close();
    }
}
 
开发者ID:napstr,项目名称:SqlSauce,代码行数:26,代码来源:DatabaseWrapper.java

示例6: deleteByPersona

import javax.persistence.Query; //导入方法依赖的package包/类
public void deleteByPersona(Long personaId) {
	Query query = entityManager.createNamedQuery("TreasureHuntEntity.deleteByPersona");
	query.setParameter("personaId", personaId);
	query.executeUpdate();
}
 
开发者ID:SoapboxRaceWorld,项目名称:soapbox-race-core,代码行数:6,代码来源:TreasureHuntDAO.java

示例7: updateGroupJvmResourceMetaData

import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public void updateGroupJvmResourceMetaData(String groupName, String resourceName, String metaData) {
    final Query q = entityManager.createNamedQuery(JpaGroupJvmConfigTemplate.UPDATE_GROUP_JVM_TEMPLATE_META_DATA);
    q.setParameter("grpName", groupName);
    q.setParameter("templateName", resourceName);
    q.setParameter("metaData", metaData);

    int numEntities;

    try {
        numEntities = q.executeUpdate();
    } catch (RuntimeException re) {
        LOGGER.error("Error updating group JVM resource meta data {} in group {}", resourceName, groupName, re);
        throw new ResourceTemplateMetaDataUpdateException(groupName, resourceName, re);
    }

    if (numEntities == 0) {
        LOGGER.error("Error updating group JVM resource meta data numEntities==0 {} in group {}", resourceName, groupName);
        throw new ResourceTemplateMetaDataUpdateException(groupName, resourceName);
    }
}
 
开发者ID:cerner,项目名称:jwala,代码行数:22,代码来源:GroupCrudServiceImpl.java

示例8: removeTemplate

import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public int removeTemplate(final String webServerName, final String templateName) {
    final Query q = entityManager.createNamedQuery(JpaWebServerConfigTemplate.QUERY_DELETE_WEBSERVER_RESOURCE_BY_TEMPLATE_WEBSERVER_NAME);
    q.setParameter(JpaWebServerConfigTemplate.QUERY_PARAM_WEBSERVER_NAME, webServerName);
    q.setParameter(JpaWebServerConfigTemplate.QUERY_PARAM_TEMPLATE_NAME, templateName);
    return q.executeUpdate();
}
 
开发者ID:cerner,项目名称:jwala,代码行数:8,代码来源:WebServerCrudServiceImpl.java

示例9: executeSql

import javax.persistence.Query; //导入方法依赖的package包/类
/**
 * select count(*) from table 
 * @param sql
 * @param params
 * @return
 */
public int executeSql(String sql, List<Object> params){
	try {
		Query query = em.createNativeQuery(sql);
		if(params != null && !params.isEmpty()){
			for(int i = 0, size = params.size(); i < size; i++){
				query.setParameter(i+1, params.get(i));
			}
		}
		return query.executeUpdate();
	} finally {
		if(em != null){
			em.close();
		}
	}
}
 
开发者ID:xujeff,项目名称:tianti,代码行数:22,代码来源:CustomBaseSqlDaoImpl.java

示例10: changeServiceVisibilityForUnit

import javax.persistence.Query; //导入方法依赖的package包/类
private void changeServiceVisibilityForUnit(String unitId,
        List<String> visibleServices, boolean forAllUsers) {
    List<Long> existingInvisibleProductKeys = getExistingInvisibleProductKeys(unitId);

    for (String product : visibleServices) {
        if (existingInvisibleProductKeys.contains(Long.valueOf(product))) {
            String queryString = "UPDATE UserGroupToInvisibleProduct as ug2ip "
                    + "SET forallusers=:forallusers "
                    + "WHERE ug2ip.usergroup_tkey=:unitId AND ug2ip.product_tkey=:productId";
            Query query = dm.createNativeQuery(queryString);
            query.setParameter("productId", Long.valueOf(product));
            query.setParameter("unitId", Long.valueOf(unitId));
            query.setParameter("forallusers", forAllUsers);
            query.executeUpdate();
        }
    }
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:18,代码来源:UserGroupServiceLocalBean.java

示例11: restore

import javax.persistence.Query; //导入方法依赖的package包/类
public void restore(Long id) {
  Query query = manager
	   .createQuery("UPDATE Funcionario fun "
	   				+ "SET fun.deleted = false "
								+ "WHERE fun.id_funcionario = :id");
query.setParameter("id", id);
query.executeUpdate();
 }
 
开发者ID:iurigodoy,项目名称:Monsters_Portal,代码行数:9,代码来源:JpaFuncionarioDao.java

示例12: delete

import javax.persistence.Query; //导入方法依赖的package包/类
@Override
public void delete(Long[] ids) {
	Query query = entityManager.createQuery("delete from User WHERE id in :ids");
	query.setParameter("ids", Arrays.asList(ids));
	query.executeUpdate();
}
 
开发者ID:lf23617358,项目名称:training-sample,代码行数:7,代码来源:JPAUserRepository.java

示例13: actionRemove

import javax.persistence.Query; //导入方法依赖的package包/类
private void actionRemove(){
	
	remove = new ActionListener() {

		@Override
		public void actionPerformed(ActionEvent e) {
			
			if (tabela.getSelectedRow()==-1){
				JOptionPane.showMessageDialog(null, "Selecione o registro a ser apagado","Alerta", JOptionPane.PLAIN_MESSAGE);
				return;
			}
			Object[] options = {"Sim", "Não"};
			int n = JOptionPane.showOptionDialog(null, "Deseja realmente apagar o registro: "+tabela.getSelectedRow(), "Alerta", JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE, null, options,options[0] );
			
			if (n == 1){
				return;
			}
			
			EntityManager em = Persistence.createEntityManagerFactory("notaFiscal_unit").createEntityManager();
			em.getTransaction().begin();
			
			String j =""+tabela.getValueAt(tabela.getSelectedRow(), 0);
			long i = Long.parseLong(j);
			Query q = em.createQuery("delete from Nf n " 
					+ "where n.notaFiscalNumero = :name");
			q.setParameter("name", i);
			int deleted = q.executeUpdate();	  
				  
			em.getTransaction().commit();
			em.close();
			
			model.removeRow(tabela.getSelectedRow());
			
		}
	};
}
 
开发者ID:matheusPeresDeAraujo,项目名称:20170612-NotaFIscalEletronica,代码行数:37,代码来源:FrameInicial.java

示例14: deleteByPersona

import javax.persistence.Query; //导入方法依赖的package包/类
public void deleteByPersona(PersonaEntity personaEntity) {
	Query query = entityManager.createNamedQuery("CarSlotEntity.deleteByPersona");
	query.setParameter("persona", personaEntity);
	query.executeUpdate();
}
 
开发者ID:SoapboxRaceWorld,项目名称:soapbox-race-core,代码行数:6,代码来源:CarSlotDAO.java

示例15: edit

import javax.persistence.Query; //导入方法依赖的package包/类
public Cat edit(Cat kot) {
	Query query = entityManager.createQuery("UPDATE Cat SET  custId = :custId, birthDate = :birthDate, name = :name, owner = :owner, weight = :weight, sex = :sex, coloring = :coloring WHERE custId = :custId");

	query.setParameter("custId", kot.getCustId());
	query.setParameter("birthDate", kot.getBirthDate());
	query.setParameter("name", kot.getName());
	query.setParameter("owner", kot.getOwner());
	query.setParameter("weight", kot.getWeight());
	query.setParameter("sex", kot.getSex());
	query.setParameter("coloring", kot.getColoring());
	query.executeUpdate();
	return kot;
	

}
 
开发者ID:Shonsu,项目名称:koty,代码行数:16,代码来源:JpaKotDAO.java


注:本文中的javax.persistence.Query.executeUpdate方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。