Search in sources :

Example 56 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project spring-data-mongodb by spring-projects.

the class MongoTemplateTests method throwsExceptionForIndexViolationIfConfigured.

// DATAMONGO-480
@Test
public void throwsExceptionForIndexViolationIfConfigured() {
    MongoTemplate template = new MongoTemplate(factory);
    template.setWriteResultChecking(WriteResultChecking.EXCEPTION);
    template.indexOps(Person.class).ensureIndex(new Index().on("firstName", Direction.DESC).unique());
    Person person = new Person(new ObjectId(), "Amol");
    person.setAge(28);
    template.save(person);
    person = new Person(new ObjectId(), "Amol");
    person.setAge(28);
    try {
        template.save(person);
        fail("Expected DataIntegrityViolationException!");
    } catch (DataIntegrityViolationException e) {
        assertThat(e.getMessage()).contains("E11000 duplicate key error");
    }
}
Also used : ObjectId(org.bson.types.ObjectId) Index(org.springframework.data.mongodb.core.index.Index) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) Test(org.junit.jupiter.api.Test)

Example 57 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project metacat by Netflix.

the class PolarisConnectorDatabaseService method create.

/**
 * {@inheritDoc}.
 */
@Override
public void create(final ConnectorRequestContext context, final DatabaseInfo databaseInfo) {
    final QualifiedName name = databaseInfo.getName();
    // check exists then create in non-transactional optimistic manner
    if (exists(context, name)) {
        throw new DatabaseAlreadyExistsException(name);
    }
    try {
        final String location = databaseInfo.getUri() == null ? this.defaultLocationPrefix + name.getDatabaseName() + DEFAULT_LOCATION_SUFFIX : databaseInfo.getUri();
        this.polarisStoreService.createDatabase(name.getDatabaseName(), location);
    } catch (DataIntegrityViolationException exception) {
        throw new InvalidMetaException(name, exception);
    } catch (Exception exception) {
        throw new ConnectorException(String.format("Failed creating polaris database %s", name), exception);
    }
}
Also used : DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 58 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project metacat by Netflix.

the class PolarisConnectorDatabaseService method update.

/**
 * {@inheritDoc}.
 */
@Override
public void update(final ConnectorRequestContext context, final DatabaseInfo databaseInfo) {
    final QualifiedName name = databaseInfo.getName();
    try {
        final PolarisDatabaseEntity db = polarisStoreService.getDatabase(name.getDatabaseName()).orElseThrow(() -> new DatabaseNotFoundException(name));
        // currently db objects have no mutable fields so this is noop
        polarisStoreService.saveDatabase(db.toBuilder().build());
    } catch (DatabaseNotFoundException exception) {
        log.error(String.format("Not found exception for polaris database %s", name), exception);
        throw exception;
    } catch (DataIntegrityViolationException exception) {
        throw new InvalidMetaException(name, exception);
    } catch (Exception exception) {
        throw new ConnectorException(String.format("Failed updating polaris database %s", databaseInfo.getName()), exception);
    }
}
Also used : QualifiedName(com.netflix.metacat.common.QualifiedName) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) PolarisDatabaseEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisDatabaseEntity) DatabaseAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.DatabaseAlreadyExistsException) DatabaseNotFoundException(com.netflix.metacat.common.server.connectors.exception.DatabaseNotFoundException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 59 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project metacat by Netflix.

the class PolarisConnectorTableService method create.

/**
 * {@inheritDoc}.
 */
@Override
public void create(final ConnectorRequestContext requestContext, final TableInfo tableInfo) {
    final QualifiedName name = tableInfo.getName();
    // check exists then create in non-transactional optimistic manner
    if (exists(requestContext, name)) {
        throw new TableAlreadyExistsException(name);
    }
    try {
        final PolarisTableEntity entity = polarisTableMapper.toEntity(tableInfo);
        polarisStoreService.createTable(entity.getDbName(), entity.getTblName(), entity.getMetadataLocation());
    } catch (DataIntegrityViolationException | InvalidMetaException exception) {
        throw new InvalidMetaException(name, exception);
    } catch (Exception exception) {
        final String msg = String.format("Failed creating polaris table %s", name);
        log.error(msg, exception);
        throw new ConnectorException(msg, exception);
    }
}
Also used : TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) QualifiedName(com.netflix.metacat.common.QualifiedName) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) PolarisTableEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) TablePreconditionFailedException(com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Example 60 with DataIntegrityViolationException

use of org.springframework.dao.DataIntegrityViolationException in project metacat by Netflix.

the class PolarisConnectorTableService method rename.

/**
 * {@inheritDoc}.
 */
@Override
public void rename(final ConnectorRequestContext context, final QualifiedName oldName, final QualifiedName newName) {
    // check exists then rename in non-transactional optimistic manner
    if (exists(context, newName)) {
        throw new TableAlreadyExistsException(newName);
    }
    try {
        final PolarisTableEntity table = polarisStoreService.getTable(oldName.getDatabaseName(), oldName.getTableName()).orElseThrow(() -> new TableNotFoundException(oldName));
        polarisStoreService.saveTable(table.toBuilder().tblName(newName.getTableName()).build());
    } catch (TableNotFoundException exception) {
        log.error(String.format("Not found exception for polaris table %s", oldName), exception);
        throw exception;
    } catch (DataIntegrityViolationException exception) {
        throw new InvalidMetaException(oldName, exception);
    } catch (Exception exception) {
        final String msg = String.format("Failed renaming polaris table %s", oldName);
        log.error(msg, exception);
        throw new ConnectorException(msg, exception);
    }
}
Also used : TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) PolarisTableEntity(com.netflix.metacat.connector.polaris.store.entities.PolarisTableEntity) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) TablePreconditionFailedException(com.netflix.metacat.common.server.connectors.exception.TablePreconditionFailedException) InvalidMetaException(com.netflix.metacat.common.server.connectors.exception.InvalidMetaException) ConnectorException(com.netflix.metacat.common.server.connectors.exception.ConnectorException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException) TableNotFoundException(com.netflix.metacat.common.server.connectors.exception.TableNotFoundException) TableAlreadyExistsException(com.netflix.metacat.common.server.connectors.exception.TableAlreadyExistsException) DataIntegrityViolationException(org.springframework.dao.DataIntegrityViolationException)

Aggregations

DataIntegrityViolationException (org.springframework.dao.DataIntegrityViolationException)117 Test (org.junit.Test)26 HashMap (java.util.HashMap)12 BadRequestException (com.sequenceiq.cloudbreak.controller.BadRequestException)11 Transactional (org.springframework.transaction.annotation.Transactional)11 Test (org.junit.jupiter.api.Test)10 Transactional (javax.transaction.Transactional)9 SpringBootTest (org.springframework.boot.test.context.SpringBootTest)9 User (ca.corefacility.bioinformatics.irida.model.user.User)8 SQLException (java.sql.SQLException)8 ConstraintViolation (javax.validation.ConstraintViolation)8 HashSet (java.util.HashSet)7 Locale (java.util.Locale)6 ConstraintViolationException (javax.validation.ConstraintViolationException)6 Date (java.util.Date)5 List (java.util.List)5 Set (java.util.Set)5 EntityExistsException (ca.corefacility.bioinformatics.irida.exceptions.EntityExistsException)4 ConnectorException (com.netflix.metacat.common.server.connectors.exception.ConnectorException)4 InvalidMetaException (com.netflix.metacat.common.server.connectors.exception.InvalidMetaException)4