Class JdbcSession
java.lang.Object
com.evolveum.midpoint.repo.sqlbase.JdbcSession
- All Implemented Interfaces:
- AutoCloseable
Wrapper around JDBC 
Connection representing "session", typically a transactional one.
 The construction can be fluently followed by startTransaction() or its variants.
 Without starting the transaction connection will likely be in auto-commit mode.
 Use commit() or rollback() to finish the transaction.
 While not typical, multiple transactions can be executed in sequence (not concurrently).
 The next transaction starts immediately after committing/rolling back the previous one, there
 is no need to explicitly start another transaction if one of startTransaction() methods
 was called before.
 Using multiple transactions is in general discouraged in favour of multiple try-with-resource
 blocks each using new session (physical SQL connections are pooled, of course).
 Object is AutoCloseable and can be used in try-with-resource blocks (which is preferred).
 *Always commit the transaction explicitly* before the JDBC session is automatically closed,
 even for read-only transactions; *otherwise the transaction is just closed and default cleanup
 procedure of the underlying connection pool or driver is used (rollback for Hikari)*.
 Note: There is no simple way how to determine "active transaction" on the JDBC level,
 so we can't log a warning for this because it would happen every time.
 If database does not support read-only transactions directly,
 commit() executes rollback instead.- 
Constructor SummaryConstructorsConstructorDescriptionJdbcSession(@NotNull Connection connection, @NotNull JdbcRepositoryConfiguration jdbcRepositoryConfiguration, @NotNull SqlRepoContext sqlRepoContext) 
- 
Method SummaryModifier and TypeMethodDescriptionvoidAlters table adding another column - intended for custom/extension columns.voidclose()voidcommit()Commits current transaction.voidexecuteStatement(String sql) This is used for technical statements and throwsSystemException.getNativeTypeName(int typeCode) com.querydsl.sql.dml.SQLDeleteClausenewDelete(com.querydsl.sql.RelationalPath<?> entity) com.querydsl.sql.dml.SQLInsertClausenewInsert(com.querydsl.sql.RelationalPath<?> entity) Starts insert clause for specified entity.com.querydsl.sql.SQLQuery<?>newQuery()Creates Querydsl query based on current Querydsl configuration and session's connection.com.querydsl.sql.dml.SQLUpdateClausenewUpdate(com.querydsl.sql.RelationalPath<?> entity) voidrollback()Rolls back the transaction.Starts read-only transaction and returnsthis.Starts transaction and returnsthis.startTransaction(int transactionLevel) Starts transaction with different transaction isolation level.
- 
Constructor Details- 
JdbcSessionpublic JdbcSession(@NotNull @NotNull Connection connection, @NotNull @NotNull JdbcRepositoryConfiguration jdbcRepositoryConfiguration, @NotNull @NotNull SqlRepoContext sqlRepoContext) 
 
- 
- 
Method Details- 
startTransactionStarts transaction and returnsthis. *Do not forget to explicitly commit the transaction* callingcommit()at the end of positive flow block, otherwise the transaction will be terminated by the connection pool automatically - which is likely a rollback.
- 
startTransactionStarts transaction with different transaction isolation level. This level will NOT be reverted to previous level after the end of transaction. It is advisable to use this only for short-lived JDBC sessions with special requirements.
- 
startReadOnlyTransactionStarts read-only transaction and returnsthis. If read-only transaction is truly supported commit, rollback or nothing can be used. Using neither commit nor rollback is perfectly OK, rollback will be likely used by the connection pool after reclaiming the connection. There should be no performance difference between commit and rollback.
- 
commitpublic void commit()Commits current transaction. If read-only transaction is not supported by database it rolls back read-only transaction.
- 
rollbackpublic void rollback()Rolls back the transaction. See also varioushandle*Exception()methods that do the same thing adding exception logging and changes to the operation result.
- 
executeStatementThis is used for technical statements and throwsSystemException. Don't use this for unsafe concatenated statements with parameters!- Throws:
- SystemException
 
- 
addColumnAlters table adding another column - intended for custom/extension columns.
- 
newQuerypublic com.querydsl.sql.SQLQuery<?> newQuery()Creates Querydsl query based on current Querydsl configuration and session's connection.
- 
newInsertpublic com.querydsl.sql.dml.SQLInsertClause newInsert(com.querydsl.sql.RelationalPath<?> entity) Starts insert clause for specified entity. Check Querydsl docs on insert for more about various ways how to use it.
- 
newUpdatepublic com.querydsl.sql.dml.SQLUpdateClause newUpdate(com.querydsl.sql.RelationalPath<?> entity) 
- 
newDeletepublic com.querydsl.sql.dml.SQLDeleteClause newDelete(com.querydsl.sql.RelationalPath<?> entity) 
- 
getNativeTypeName
- 
connection
- 
sessionId
- 
databaseType
- 
closepublic void close()- Specified by:
- closein interface- AutoCloseable
 
 
-