org.jooq.exception.SQLStateClass Maven / Gradle / Ivy
The newest version!
/*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*
* Other licenses:
* -----------------------------------------------------------------------------
* Commercial licenses for this work are available. These replace the above
* Apache-2.0 license and offer limited warranties, support, maintenance, and
* commercial database integrations.
*
* For more information, please visit: https://www.jooq.org/legal/licensing
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*
*/
package org.jooq.exception;
import java.util.HashMap;
import java.util.Map;
// ...
import org.jetbrains.annotations.NotNull;
/**
* The class of the SQL state as specified by the SQL:2011 standard, or by individual
* vendors.
*
*
* Class Description
* 00 Successful completion
* 01 Warning
* 02 No data
* 07 Dynamic SQL Error
* 08 Connection exception
* 09 Triggered action exception
* 0A Feature not supported
* 0D Invalid target type specification
* 0E Invalid schema name list specification
* 0F Locator exception
* 0L Invalid grantor
* 0M Invalid SQL-invoked procedure reference
* 0P Invalid role specification
* 0S Invalid transform group name specification
* 0T Target table disagrees with cursor specification
* 0U Attempt to assign to non-updatable column
* 0V Attempt to assign to ordering column
* 0W Prohibited statement encountered during trigger execution
* 0Z Diagnostics exception
* 21 Cardinality violation
* 22 Data exception
* 23 Integrity constraint violation
* 24 Invalid cursor state
* 25 Invalid transaction state
* 26 Invalid SQL statement name
* 27 Triggered data change violation
* 28 Invalid authorization specification
* 2B Dependent privilege descriptors still exist
* 2C Invalid character set name
* 2D Invalid transaction termination
* 2E Invalid connection name
* 2F SQL routine exception
* 2H Invalid collation name
* 30 Invalid SQL statement identifier
* 33 Invalid SQL descriptor name
* 34 Invalid cursor name
* 35 Invalid condition number
* 36 Cursor sensitivity exception
* 38 External routine exception
* 39 External routine invocation exception
* 3B Savepoint exception
* 3C Ambiguous cursor name
* 3D Invalid catalog name
* 3F Invalid schema name
* 40 Transaction rollback
* 42 Syntax error or access rule violation
* 44 With check option violation
* HZ Remote database access
*
*
* @author Lukas Eder
*/
public enum SQLStateClass {
C00_SUCCESSFUL_COMPLETION("00"),
C01_WARNING("01"),
C02_NO_DATA("02"),
C07_DYNAMIC_SQL_ERROR("07"),
C08_CONNECTION_EXCEPTION("08"),
C09_TRIGGERED_ACTION_EXCEPTION("09"),
C0A_FEATURE_NOT_SUPPORTED("0A"),
C0D_INVALID_TARGET_TYPE_SPECIFICATION("0D"),
C0E_INVALID_SCHEMA_NAME_LIST_SPECIFICATION("0E"),
C0F_LOCATOR_EXCEPTION("0F"),
C0L_INVALID_GRANTOR("0L"),
C0M_INVALID_SQL_INVOKED_PROCEDURE_REFERENCE("0M"),
C0P_INVALID_ROLE_SPECIFICATION("0P"),
C0S_INVALID_TRANSFORM_GROUP_NAME_SPECIFICATION("0S"),
C0T_TARGET_TABLE_DISAGREES_WITH_CURSOR_SPECIFICATION("0T"),
C0U_ATTEMPT_TO_ASSIGN_TO_NON_UPDATABLE_COLUMN("0U"),
C0V_ATTEMPT_TO_ASSIGN_TO_ORDERING_COLUMN("0V"),
C0W_PROHIBITED_STATEMENT_ENCOUNTERED_DURING_TRIGGER_EXECUTION("0W"),
C0Z_DIAGNOSTICS_EXCEPTION("0Z"),
C21_CARDINALITY_VIOLATION("21"),
C22_DATA_EXCEPTION("22"),
C23_INTEGRITY_CONSTRAINT_VIOLATION("23"),
C24_INVALID_CURSOR_STATE("24"),
C25_INVALID_TRANSACTION_STATE("25"),
C26_INVALID_SQL_STATEMENT_NAME("26"),
C27_TRIGGERED_DATA_CHANGE_VIOLATION("27"),
C28_INVALID_AUTHORIZATION_SPECIFICATION("28"),
C2B_DEPENDENT_PRIVILEGE_DESCRIPTORS_STILL_EXIST("2B"),
C2C_INVALID_CHARACTER_SET_NAME("2C"),
C2D_INVALID_TRANSACTION_TERMINATION("2D"),
C2E_INVALID_CONNECTION_NAME("2E"),
C2F_SQL_ROUTINE_EXCEPTION("2F"),
C2H_INVALID_COLLATION_NAME("2H"),
C30_INVALID_SQL_STATEMENT_IDENTIFIER("30"),
C33_INVALID_SQL_DESCRIPTOR_NAME("33"),
C34_INVALID_CURSOR_NAME("34"),
C35_INVALID_CONDITION_NUMBER("35"),
C36_CURSOR_SENSITIVITY_EXCEPTION("36"),
C38_EXTERNAL_ROUTINE_EXCEPTION("38"),
C39_EXTERNAL_ROUTINE_INVOCATION_EXCEPTION("39"),
C3B_SAVEPOINT_EXCEPTION("3B"),
C3C_AMBIGUOUS_CURSOR_NAME("3C"),
C3D_INVALID_CATALOG_NAME("3D"),
C3F_INVALID_SCHEMA_NAME("3F"),
C40_TRANSACTION_ROLLBACK("40"),
C42_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION("42"),
CHZ_REMOTE_DATABASE_ACCESS("HZ"),
OTHER(""),
NONE("")
;
private static final Map lookup = new HashMap<>();
private final String className;
static {
for (SQLStateClass clazz : SQLStateClass.values()) {
lookup.put(clazz.className, clazz);
}
}
private SQLStateClass(String className) {
this.className = className;
}
@NotNull
public String className() {
return className;
}
@NotNull
public static SQLStateClass fromCode(String code) {
if (code == null || code.length() < 2)
return SQLStateClass.OTHER;
SQLStateClass result = lookup.get(code.substring(0, 2));
return result != null ? result : SQLStateClass.OTHER;
}
@NotNull
static SQLStateClass fromSQLiteVendorCode(int errorCode) {
// See https://sqlite.org/c3ref/c_abort.html
// And https://sqlite.org/c3ref/c_abort_rollback.html
switch (errorCode & 0xFF) {
case 0: return C00_SUCCESSFUL_COMPLETION;
case 3: return C42_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION;
case 18: return C22_DATA_EXCEPTION;
case 19: return C23_INTEGRITY_CONSTRAINT_VIOLATION;
case 20: return C22_DATA_EXCEPTION;
case 27: return C01_WARNING;
case 28: return C01_WARNING;
}
return SQLStateClass.OTHER;
}
@NotNull
static SQLStateClass fromTrinoVendorCode(int errorCode) {
// See https://github.com/trinodb/trino/blob/master/core/trino-spi/src/main/java/io/trino/spi/StandardErrorCode.java
switch (errorCode) {
case 1: return C42_SYNTAX_ERROR_OR_ACCESS_RULE_VIOLATION;
case 9:
case 19: return C22_DATA_EXCEPTION;
case 16: return C23_INTEGRITY_CONSTRAINT_VIOLATION;
}
return SQLStateClass.OTHER;
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy