@Override public void merge(String project, Object user, Object anonymousId, Instant createdAt, Instant mergedAt) { try { mergeInternal(project, user, anonymousId, createdAt, mergedAt); } catch (RuntimeException e) { if (e.getCause() instanceof PSQLException && ((PSQLException) e.getCause()).getSQLState().equals("42P01")) { new PostgresqlModule.UserMergeTableHook(projectConfig, executor) .createTable(project).join(); mergeInternal(project, user, anonymousId, createdAt, mergedAt); } } }
public Object retryOnFailure(ProceedingJoinPoint jp) throws Throwable { Object result = null; int retryCount = 0; do { try { Object[] args = jp.getArgs(); if ( args != null && args.length > 0 ) result = jp.proceed(jp.getArgs()); else result = jp.proceed(); break; } catch (DataAccessResourceFailureException ex) { if ( ex.getCause() instanceof PSQLException ) { PSQLException psqlEx = (PSQLException) ex.getCause(); String sqlState = psqlEx.getSQLState(); LOG.warn("Got exception with sqlState=" + sqlState + ": " + ex); if ( sqlStatesToRetry.contains(sqlState) && retryCount < maxRetriesOnConnDrop ) { LOG.warn("Retrying...(retryCount=" + retryCount + ")"); sleep(retryWaitInMillis); } else { throw ex; } } } retryCount++; } while ( retryCount <= maxRetriesOnConnDrop ); return result; }
private MolgenisDataException doTranslate(PSQLException pSqlException) { switch (pSqlException.getSQLState()) { case "22001": return translateValueTooLongViolation(); case "22007": // invalid_datetime_format case "22P02": // not an integer exception return translateInvalidIntegerException(pSqlException); case "23502": // not_null_violation return translateNotNullViolation(pSqlException); case "23503": // foreign_key_violation return translateForeignKeyViolation(pSqlException); case "23505": // unique_violation return translateUniqueKeyViolation(pSqlException); case "23514": // check_violation return translateCheckConstraintViolation(pSqlException); case "2BP01": return translateDependentObjectsStillExist(pSqlException); case "42703": return translateUndefinedColumnException(pSqlException); case PostgreSqlQueryGenerator.ERR_CODE_READONLY_VIOLATION: return translateReadonlyViolation(pSqlException); default: return null; } }