Search in sources :

Example 1 with IntegrityConstraintViolationException

use of org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException in project che-server by eclipse-che.

the class JpaFreeResourcesLimitDao method doStore.

@Transactional(rollbackOn = { RuntimeException.class, ConflictException.class })
protected void doStore(FreeResourcesLimitImpl resourcesLimit) throws ConflictException {
    EntityManager manager = managerProvider.get();
    try {
        final FreeResourcesLimitImpl existedLimit = doGet(resourcesLimit.getAccountId());
        existedLimit.setResources(resourcesLimit.getResources());
        manager.flush();
    } catch (NoResultException n) {
        try {
            manager.persist(resourcesLimit);
            manager.flush();
        } catch (IntegrityConstraintViolationException e) {
            throw new ConflictException(format("The specified account '%s' does not exist", resourcesLimit.getAccountId()));
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) IntegrityConstraintViolationException(org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException) ConflictException(org.eclipse.che.api.core.ConflictException) NoResultException(javax.persistence.NoResultException) Transactional(com.google.inject.persist.Transactional)

Example 2 with IntegrityConstraintViolationException

use of org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException in project che-server by eclipse-che.

the class JpaUserDevfileDao method create.

@Override
public UserDevfile create(UserDevfile userDevfile) throws ConflictException, ServerException {
    requireNonNull(userDevfile);
    try {
        Account account = accountDao.getByName(userDevfile.getNamespace());
        UserDevfileImpl userDevfileImpl = new UserDevfileImpl(userDevfile, account);
        doCreate(userDevfileImpl);
        return userDevfileImpl;
    } catch (DuplicateKeyException ex) {
        throw new ConflictException(format("Devfile with name '%s' already exists in the specified account '%s'", userDevfile.getName(), userDevfile.getNamespace()));
    } catch (IntegrityConstraintViolationException ex) {
        throw new ConflictException("Could not create devfile with creator that refers to a non-existent user");
    } catch (RuntimeException ex) {
        throw new ServerException(ex.getMessage(), ex);
    } catch (NotFoundException e) {
        throw new ConflictException(format("Not able to create devfile in requested namespace %s bacause it is not found", userDevfile.getNamespace()));
    }
}
Also used : Account(org.eclipse.che.account.shared.model.Account) IntegrityConstraintViolationException(org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) DuplicateKeyException(org.eclipse.che.core.db.jpa.DuplicateKeyException)

Example 3 with IntegrityConstraintViolationException

use of org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException in project devspaces-images by redhat-developer.

the class JpaUserDevfileDao method create.

@Override
public UserDevfile create(UserDevfile userDevfile) throws ConflictException, ServerException {
    requireNonNull(userDevfile);
    try {
        Account account = accountDao.getByName(userDevfile.getNamespace());
        UserDevfileImpl userDevfileImpl = new UserDevfileImpl(userDevfile, account);
        doCreate(userDevfileImpl);
        return userDevfileImpl;
    } catch (DuplicateKeyException ex) {
        throw new ConflictException(format("Devfile with name '%s' already exists in the specified account '%s'", userDevfile.getName(), userDevfile.getNamespace()));
    } catch (IntegrityConstraintViolationException ex) {
        throw new ConflictException("Could not create devfile with creator that refers to a non-existent user");
    } catch (RuntimeException ex) {
        throw new ServerException(ex.getMessage(), ex);
    } catch (NotFoundException e) {
        throw new ConflictException(format("Not able to create devfile in requested namespace %s bacause it is not found", userDevfile.getNamespace()));
    }
}
Also used : Account(org.eclipse.che.account.shared.model.Account) IntegrityConstraintViolationException(org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException) ServerException(org.eclipse.che.api.core.ServerException) ConflictException(org.eclipse.che.api.core.ConflictException) UserDevfileImpl(org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl) NotFoundException(org.eclipse.che.api.core.NotFoundException) DuplicateKeyException(org.eclipse.che.core.db.jpa.DuplicateKeyException)

Example 4 with IntegrityConstraintViolationException

use of org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException in project devspaces-images by redhat-developer.

the class JpaFreeResourcesLimitDao method doStore.

@Transactional(rollbackOn = { RuntimeException.class, ConflictException.class })
protected void doStore(FreeResourcesLimitImpl resourcesLimit) throws ConflictException {
    EntityManager manager = managerProvider.get();
    try {
        final FreeResourcesLimitImpl existedLimit = doGet(resourcesLimit.getAccountId());
        existedLimit.setResources(resourcesLimit.getResources());
        manager.flush();
    } catch (NoResultException n) {
        try {
            manager.persist(resourcesLimit);
            manager.flush();
        } catch (IntegrityConstraintViolationException e) {
            throw new ConflictException(format("The specified account '%s' does not exist", resourcesLimit.getAccountId()));
        }
    }
}
Also used : EntityManager(javax.persistence.EntityManager) FreeResourcesLimitImpl(org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl) IntegrityConstraintViolationException(org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException) ConflictException(org.eclipse.che.api.core.ConflictException) NoResultException(javax.persistence.NoResultException) Transactional(com.google.inject.persist.Transactional)

Aggregations

ConflictException (org.eclipse.che.api.core.ConflictException)4 IntegrityConstraintViolationException (org.eclipse.che.core.db.jpa.IntegrityConstraintViolationException)4 Transactional (com.google.inject.persist.Transactional)2 EntityManager (javax.persistence.EntityManager)2 NoResultException (javax.persistence.NoResultException)2 Account (org.eclipse.che.account.shared.model.Account)2 NotFoundException (org.eclipse.che.api.core.NotFoundException)2 ServerException (org.eclipse.che.api.core.ServerException)2 UserDevfileImpl (org.eclipse.che.api.devfile.server.model.impl.UserDevfileImpl)2 DuplicateKeyException (org.eclipse.che.core.db.jpa.DuplicateKeyException)2 FreeResourcesLimitImpl (org.eclipse.che.multiuser.resource.spi.impl.FreeResourcesLimitImpl)2