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


Java DataIntegrityViolationException类代码示例

本文整理汇总了Java中org.springframework.dao.DataIntegrityViolationException的典型用法代码示例。如果您正苦于以下问题:Java DataIntegrityViolationException类的具体用法?Java DataIntegrityViolationException怎么用?Java DataIntegrityViolationException使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: deleteBuilding

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
@Override
public String deleteBuilding(long buildingId) {

    AssertParam.throwIfNull(buildingId, "buildingId");

    try {
        buildingRepository.delete(buildingId);
        Building deletedBuilding = buildingRepository.findOne(buildingId);
        boolean operationSuccessful = deletedBuilding == null;

        if (operationSuccessful) {
            return ResponseConstants.BUILDING_DELETE_SUCCESS;
        } else {
            return ResponseConstants.BUILDING_DELETE_FAILURE_DB_WRITE;
        }
    } catch (DataIntegrityViolationException e) {
        e.printStackTrace();
        return ResponseConstants.BUILDING_DELETE_FAILURE_CONSTRAINT_VIOLATION;
    }


}
 
开发者ID:ProjectIndoor,项目名称:projectindoorweb,代码行数:23,代码来源:PersistencyServiceImpl.java

示例2: deleteEvaalFile

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
@Override
public String deleteEvaalFile(long evaalFileId) {

    AssertParam.throwIfNull(evaalFileId, "evaalFileId");

    try{
        evaalFileRepository.delete(evaalFileId);
        EvaalFile deletedEvaalFile = evaalFileRepository.findOne(evaalFileId);
        boolean operationSuccess = deletedEvaalFile == null;

        if(operationSuccess){
            return ResponseConstants.EVAAL_DELETE_SUCCESS;
        }else{
            return ResponseConstants.EVAAL_DELETE_FAILURE_DB_WRITE;
        }
    }catch(DataIntegrityViolationException e){
        e.printStackTrace();
        return ResponseConstants.EVAAL_DELETE_FAILURE_CONSTRAINT_VIOLATION;
    }


}
 
开发者ID:ProjectIndoor,项目名称:projectindoorweb,代码行数:23,代码来源:PersistencyServiceImpl.java

示例3: register

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
@Override
public JsonResult<User> register(User userToAdd) {

    if (userToAdd.getAccount() == null || !Util.checkEmail(userToAdd.getAccount())) {
        return JsonResult.<User>builder().error("注册帐号错误!").build();
    }

    BCryptPasswordEncoder encoder = new BCryptPasswordEncoder();
    final String rawPassword = userToAdd.getPassword();
    userToAdd.setPassword(encoder.encode(rawPassword));
    userToAdd.setLastPasswordResetDate(new Date());
    Role userRole = roleRepository.findByName("ROLE_USER");
    if (userRole == null){
        userRole = roleRepository.save(new Role("ROLE_USER"));
    }
    userToAdd.setRoles(Collections.singletonList(userRole));
    try {
        return JsonResult.<User>builder().data(userRepository.save(userToAdd)).build();
    } catch (DataIntegrityViolationException e) {
        logger.debug(e.getMessage());
        return JsonResult.<User>builder().error(e.getRootCause().getMessage()).build();
    }
}
 
开发者ID:DigAg,项目名称:digag-server,代码行数:24,代码来源:AuthServiceImpl.java

示例4: getPropertyById

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
public Serializable getPropertyById(Long id)
{
    if (id == null)
    {
        throw new IllegalArgumentException("Cannot look up entity by null ID.");
    }
    Pair<Long, Serializable> entityPair = propertyCache.getByKey(id);
    if (entityPair == null)
    {
        // Remove from cache
        propertyCache.removeByKey(id);
        
        throw new DataIntegrityViolationException("No property value exists for ID " + id);
    }
    return entityPair.getSecond();
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:AbstractPropertyValueDAOImpl.java

示例5: updateValue

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
/**
 * Updates a property.  The <b>alf_prop_root</b> entity is updated
 * to ensure concurrent modification is detected.
 * 
 * @return              Returns 1 always
 */
@Override
public int updateValue(Long key, Serializable value)
{
    // Remove all entries for the root
    PropertyRootEntity entity = getPropertyRoot(key);
    if (entity == null)
    {
        throw new DataIntegrityViolationException("No property root exists for ID " + key);
    }
    // Remove all links using the root
    deletePropertyLinks(key);
    // Create the new properties and update the cache
    createPropertyImpl(key, 0L, 0L, null, value);
    // Update the property root to detect concurrent modification
    updatePropertyRoot(entity);
    // Done
    if (logger.isDebugEnabled())
    {
        logger.debug(
                "Updated property: \n" +
                "   ID: " + key + "\n" +
                "   Value: " + value);
    }
    return 1;
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:32,代码来源:AbstractPropertyValueDAOImpl.java

示例6: updateAuditApplicationModel

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
public void updateAuditApplicationModel(Long id, Long modelId)
{
    AuditApplicationEntity entity = getAuditApplicationById(id);
    if (entity == null)
    {
        throw new DataIntegrityViolationException("No audit application exists for ID " + id);
    }
    if (entity.getAuditModelId().equals(modelId))
    {
        // There is nothing to update
        return;
    }
    // Update
    entity.setAuditModelId(modelId);
    updateAuditApplication(entity);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:17,代码来源:AbstractAuditDAOImpl.java

示例7: updateAuditApplicationDisabledPaths

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public void updateAuditApplicationDisabledPaths(Long id, Set<String> disabledPaths)
{
    AuditApplicationEntity entity = getAuditApplicationById(id);
    if (entity == null)
    {
        throw new DataIntegrityViolationException("No audit application exists for ID " + id);
    }
    // Resolve the current set
    Long disabledPathsId = entity.getDisabledPathsId();
    Set<String> oldDisabledPaths = (Set<String>) propertyValueDAO.getPropertyById(disabledPathsId);
    if (oldDisabledPaths.equals(disabledPaths))
    {
        // Nothing changed
        return;
    }
    // Update the property
    propertyValueDAO.updateProperty(disabledPathsId, (Serializable) disabledPaths);
    // Do a precautionary update to ensure that the application row is locked appropriately
    updateAuditApplication(entity);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:22,代码来源:AbstractAuditDAOImpl.java

示例8: updateNamespace

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
public void updateNamespace(String oldNamespaceUri, String newNamespaceUri)
{
    ParameterCheck.mandatory("newNamespaceUri", newNamespaceUri);

    Pair<Long, String> oldEntityPair = getNamespace(oldNamespaceUri);   // incl. null check
    if (oldEntityPair == null)
    {
        throw new DataIntegrityViolationException(
                "Cannot update namespace as it doesn't exist: " + oldNamespaceUri);
    }
    // Find the value
    int updated = namespaceCache.updateValue(oldEntityPair.getFirst(), newNamespaceUri);
    if (updated != 1)
    {
        throw new ConcurrencyFailureException(
                "Incorrect update count: \n" +
                "   Namespace:    " + oldNamespaceUri + "\n" +
                "   Rows Updated: " + updated);
    }
    // All the QNames need to be dumped
    qnameCache.clear();
    // Done
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:AbstractQNameDAOImpl.java

示例9: deleteContentDataEntity

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
@Override
protected int deleteContentDataEntity(Long id)
{
    // Get the content urls
    try
    {
        ContentData contentData = getContentData(id).getSecond();
        String contentUrl = contentData.getContentUrl();
        if (contentUrl != null)
        {
            // It has been dereferenced and may be orphaned - we'll check later
            registerDereferencedContentUrl(contentUrl);
        }
    }
    catch (DataIntegrityViolationException e)
    {
        // Doesn't exist.  The node doesn't enforce a FK constraint, so we protect against this.
    }
    // Issue the delete statement
    Map<String, Object> params = new HashMap<String, Object>(11);
    params.put("id", id);
    return template.delete(DELETE_CONTENT_DATA, params);
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:24,代码来源:ContentDataDAOImpl.java

示例10: findByKey

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
public Pair<NodeVersionKey, Set<QName>> findByKey(NodeVersionKey nodeVersionKey)
{
    Long nodeId = nodeVersionKey.getNodeId();
    Set<Long> nodeIds = Collections.singleton(nodeId);
    Map<NodeVersionKey, Set<QName>> nodeAspectQNameIdsByVersionKey = selectNodeAspects(nodeIds);
    Set<QName> nodeAspectQNames = nodeAspectQNameIdsByVersionKey.get(nodeVersionKey);
    if (nodeAspectQNames == null)
    {
        // Didn't find a match.  Is this because there are none?
        if (nodeAspectQNameIdsByVersionKey.size() == 0)
        {
            // This is OK.  The node has no properties
            nodeAspectQNames = Collections.emptySet();
        }
        else
        {
            // We found properties associated with a different node ID and version
            invalidateNodeCaches(nodeId);
            throw new DataIntegrityViolationException(
                    "Detected stale node entry: " + nodeVersionKey +
                    " (now " + nodeAspectQNameIdsByVersionKey.keySet() + ")");
        }
    }
    // Done
    return new Pair<NodeVersionKey, Set<QName>>(nodeVersionKey, Collections.unmodifiableSet(nodeAspectQNames));
}
 
开发者ID:Alfresco,项目名称:alfresco-repository,代码行数:27,代码来源:AbstractNodeDAOImpl.java

示例11: refreshFromGameAdminData

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
private void refreshFromGameAdminData(String address, Map<String, String> data) {
    String subId = data.get("SUBID");
    String name = data.get("name");

    GameServer server = gameServerRepository.findByAddress(address).orElseGet(this::newGameServer);

    boolean changed = !server.getId().equals(subId)
        || !server.getName().equals(name)
        || !server.getAddress().equals(address);

    server.setId(subId);
    server.setAddress(address);
    server.setName(name);
    try {
        server = gameServerRepository.save(server);
        if (changed) {
            initServerMetrics(server);
        }
    } catch (DataIntegrityViolationException e) {
        log.warn("Unable to update server data", e);
    }
}
 
开发者ID:quanticc,项目名称:sentry,代码行数:23,代码来源:GameServerService.java

示例12: submit

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
/**
 * Maps and handles custom behavior in the Edit page (POST mode)
 * @param message The information that is bound to the HTML form and used to update the database
 * @return Custom message sent to the client - in this case, a redirect
 */
@RequestMapping(value="/edit", method=RequestMethod.POST)
public String submit(@ModelAttribute Message message)
{
    try
    {
        String username = Util.getUsername();
        message.setUsername(username);

        message = encryptMessage(message);
        messageRepository.save(message);

        // TO-DO: redirect and show a success message
        return "redirect:/cpanel.html";
    }
    catch(DataIntegrityViolationException ex) // message is too long for DB field
    {
        return "redirect:/edit?error";
    }
}
 
开发者ID:arturhgca,项目名称:message-crypto,代码行数:25,代码来源:MessageController.java

示例13: process

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
@Override
public void process(ResultItems resultItems, Task task) {
    List<IndustryInfo> industryInfos = resultItems.get("industryInfos");
    if (industryInfos != null && industryInfos.size() > 0) {
        for (IndustryInfo industryInfo : industryInfos) {
            try {
                industryInfoDao.add(industryInfo);
            } catch (Exception e) {
                if (e instanceof DataIntegrityViolationException) {

                } else {
                    e.printStackTrace();
                }
            }
        }
    }
}
 
开发者ID:leon66666,项目名称:financehelper,代码行数:18,代码来源:IndustryInfoPipeline.java

示例14: renameTermValue

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
@Override
@Transactional(propagation = Propagation.MANDATORY)
public void renameTermValue(Term term, String newValue)
{
	final Taxonomy taxonomy = term.getTaxonomy();

	newValue = newValue.trim();
	checkTermValue(newValue, taxonomy, term.getParent());

	term.setValue(newValue);
	try
	{
		save(term);	
		invalidateFullValues(term);
		updateFullValues(taxonomy);
	}catch(DataIntegrityViolationException e2){
		throw new DataIntegrityViolationException("SIBLING_CHECK");			
	}
}
 
开发者ID:equella,项目名称:Equella,代码行数:20,代码来源:TermDaoImpl.java

示例15: doTranslate

import org.springframework.dao.DataIntegrityViolationException; //导入依赖的package包/类
@Override
protected DataAccessException doTranslate(String task, String sql, SQLException ex) {
	String sqlState = getSqlState(ex);
	if (sqlState != null && sqlState.length() >= 2) {
		String classCode = sqlState.substring(0, 2);
		if (logger.isDebugEnabled()) {
			logger.debug("Extracted SQL state class '" + classCode + "' from value '" + sqlState + "'");
		}
		if (BAD_SQL_GRAMMAR_CODES.contains(classCode)) {
			return new BadSqlGrammarException(task, sql, ex);
		}
		else if (DATA_INTEGRITY_VIOLATION_CODES.contains(classCode)) {
			return new DataIntegrityViolationException(buildMessage(task, sql, ex), ex);
		}
		else if (DATA_ACCESS_RESOURCE_FAILURE_CODES.contains(classCode)) {
			return new DataAccessResourceFailureException(buildMessage(task, sql, ex), ex);
		}
		else if (TRANSIENT_DATA_ACCESS_RESOURCE_CODES.contains(classCode)) {
			return new TransientDataAccessResourceException(buildMessage(task, sql, ex), ex);
		}
		else if (CONCURRENCY_FAILURE_CODES.contains(classCode)) {
			return new ConcurrencyFailureException(buildMessage(task, sql, ex), ex);
		}
	}
	return null;
}
 
开发者ID:lamsfoundation,项目名称:lams,代码行数:27,代码来源:SQLStateSQLExceptionTranslator.java


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