本文整理汇总了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();
}
示例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();
}
示例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();
}
示例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);
}
}
示例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();
}
}
示例6: deleteByPersona
import javax.persistence.Query; //导入方法依赖的package包/类
public void deleteByPersona(Long personaId) {
Query query = entityManager.createNamedQuery("TreasureHuntEntity.deleteByPersona");
query.setParameter("personaId", personaId);
query.executeUpdate();
}
示例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);
}
}
示例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();
}
示例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();
}
}
}
示例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();
}
}
}
示例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();
}
示例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();
}
示例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());
}
};
}
示例14: deleteByPersona
import javax.persistence.Query; //导入方法依赖的package包/类
public void deleteByPersona(PersonaEntity personaEntity) {
Query query = entityManager.createNamedQuery("CarSlotEntity.deleteByPersona");
query.setParameter("persona", personaEntity);
query.executeUpdate();
}
示例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;
}