Package me.ahoo.cosid.jdbc
Class JdbcSupport
java.lang.Object
me.ahoo.cosid.jdbc.JdbcSupport
Shared JDBC helpers: statement query timeout, transaction rollback and duplicate key detection.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final DurationDefault query timeout applied to every distributor statement. -
Method Summary
Modifier and TypeMethodDescriptionstatic booleanisDuplicateKey(SQLException sqlException) Whether the exception (or any exception in itschain) reports a duplicate key.static inttoQueryTimeoutSeconds(Duration queryTimeout) Converts a query timeout to the whole seconds expected byStatement.setQueryTimeout(int).
-
Field Details
-
DEFAULT_QUERY_TIMEOUT
Default query timeout applied to every distributor statement.
-
-
Method Details
-
toQueryTimeoutSeconds
Converts a query timeout to the whole seconds expected byStatement.setQueryTimeout(int). Sub-second values are rounded up so that a positive timeout never turns into "no timeout".- Parameters:
queryTimeout- query timeout,nullor zero means no timeout- Returns:
- timeout in seconds,
0means no timeout
-
isDuplicateKey
Whether the exception (or any exception in itschain) reports a duplicate key.SQLState class
23alone is too broad: it also covers NOT NULL, foreign key and CHECK violations, and MySQL, Oracle and SQL Server report every integrity violation as23000. So this matches SQLState23505(PostgreSQL, H2, Derby, DB2, HSQLDB) or a class23error with a known duplicate-key vendor code: MySQL/MariaDB1062, Oracle1(ORA-00001), SQL Server2627/2601. ASQLIntegrityConstraintViolationExceptionwithout any SQLState is also treated as a duplicate.- Parameters:
sqlException- the exception thrown by the driver- Returns:
- true if it is a duplicate key violation
-