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");
}
}
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);
}
}
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);
}
}
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);
}
}
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);
}
}
Aggregations