All Downloads are FREE. Search and download functionalities are using the official Maven repository.

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.
 * 

*

* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
ClassDescription
00Successful completion
01Warning
02No data
07Dynamic SQL Error
08Connection exception
09Triggered action exception
0AFeature not supported
0DInvalid target type specification
0EInvalid schema name list specification
0FLocator exception
0LInvalid grantor
0MInvalid SQL-invoked procedure reference
0PInvalid role specification
0SInvalid transform group name specification
0TTarget table disagrees with cursor specification
0UAttempt to assign to non-updatable column
0VAttempt to assign to ordering column
0WProhibited statement encountered during trigger execution
0ZDiagnostics exception
21Cardinality violation
22Data exception
23Integrity constraint violation
24Invalid cursor state
25Invalid transaction state
26Invalid SQL statement name
27Triggered data change violation
28Invalid authorization specification
2BDependent privilege descriptors still exist
2CInvalid character set name
2DInvalid transaction termination
2EInvalid connection name
2FSQL routine exception
2HInvalid collation name
30Invalid SQL statement identifier
33Invalid SQL descriptor name
34Invalid cursor name
35Invalid condition number
36Cursor sensitivity exception
38External routine exception
39External routine invocation exception
3BSavepoint exception
3CAmbiguous cursor name
3DInvalid catalog name
3FInvalid schema name
40Transaction rollback
42Syntax error or access rule violation
44With check option violation
HZRemote 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