@Test void translateCheckConstraintViolation() { ServerErrorMessage serverErrorMessage = mock(ServerErrorMessage.class); when(serverErrorMessage.getTable()).thenReturn("myTable"); when(serverErrorMessage.getConstraint()).thenReturn("myTable_myColumn_chk"); UnknownEnumValueException e = postgreSqlExceptionTranslator.translateCheckConstraintViolation( mock(Throwable.class), new PSQLException(serverErrorMessage)); assertEquals("entityTypeId:myEntity attributeName:myAttr", e.getMessage()); }
UnknownEnumValueException translateCheckConstraintViolation( Throwable sourceThrowable, PSQLException pSqlException) { ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String tableName = serverErrorMessage.getTable(); String constraintName = serverErrorMessage.getConstraint(); String columnName = constraintName.substring(tableName.length() + 1, constraintName.length() - 4); String entityTypeId = tryGetEntityTypeName(tableName).orElse(null); String attributeName = tryGetAttributeName(tableName, columnName).orElse(null); return new UnknownEnumValueException(entityTypeId, attributeName, sourceThrowable); }
PostgreSqlExceptionTranslator extends SQLErrorCodeSQLExceptionTranslator implements TransactionExceptionTranslator { UnknownEnumValueException translateCheckConstraintViolation( Throwable sourceThrowable, PSQLException pSqlException) { ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String tableName = serverErrorMessage.getTable(); String constraintName = serverErrorMessage.getConstraint(); String columnName = constraintName.substring(tableName.length() + 1, constraintName.length() - 4); String entityTypeId = tryGetEntityTypeName(tableName).orElse(null); String attributeName = tryGetAttributeName(tableName, columnName).orElse(null); return new UnknownEnumValueException(entityTypeId, attributeName, sourceThrowable); } }
PostgreSqlExceptionTranslator extends SQLErrorCodeSQLExceptionTranslator implements TransactionExceptionTranslator { UnknownEnumValueException translateCheckConstraintViolation( Throwable sourceThrowable, PSQLException pSqlException) { ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String tableName = serverErrorMessage.getTable(); String constraintName = serverErrorMessage.getConstraint(); String columnName = constraintName.substring(tableName.length() + 1, constraintName.length() - 4); String entityTypeId = tryGetEntityTypeName(tableName).orElse(null); String attributeName = tryGetAttributeName(tableName, columnName).orElse(null); return new UnknownEnumValueException(entityTypeId, attributeName, sourceThrowable); } PostgreSqlExceptionTranslator(DataSource dataSource, EntityTypeRegistry entityTypeRegistry); }
PostgreSqlExceptionTranslator extends SQLErrorCodeSQLExceptionTranslator implements TransactionExceptionTranslator { UnknownEnumValueException translateCheckConstraintViolation( Throwable sourceThrowable, PSQLException pSqlException) { ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String tableName = serverErrorMessage.getTable(); String constraintName = serverErrorMessage.getConstraint(); String columnName = constraintName.substring(tableName.length() + 1, constraintName.length() - 4); String entityTypeId = tryGetEntityTypeName(tableName).orElse(null); String attributeName = tryGetAttributeName(tableName, columnName).orElse(null); return new UnknownEnumValueException(entityTypeId, attributeName, sourceThrowable); } PostgreSqlExceptionTranslator(DataSource dataSource, EntityTypeRegistry entityTypeRegistry); @Override @Nullable @CheckForNull DataAccessException doTranslate(TransactionException transactionException); }
PostgreSqlExceptionTranslator extends SQLErrorCodeSQLExceptionTranslator implements TransactionExceptionTranslator { UnknownEnumValueException translateCheckConstraintViolation( Throwable sourceThrowable, PSQLException pSqlException) { ServerErrorMessage serverErrorMessage = pSqlException.getServerErrorMessage(); String tableName = serverErrorMessage.getTable(); String constraintName = serverErrorMessage.getConstraint(); String columnName = constraintName.substring(tableName.length() + 1, constraintName.length() - 4); String entityTypeId = tryGetEntityTypeName(tableName).orElse(null); String attributeName = tryGetAttributeName(tableName, columnName).orElse(null); return new UnknownEnumValueException(entityTypeId, attributeName, sourceThrowable); } PostgreSqlExceptionTranslator(DataSource dataSource, EntityTypeRegistry entityTypeRegistry); @Override @Nullable @CheckForNull DataAccessException doTranslate(TransactionException transactionException);  }