Class BaseHelper
- java.lang.Object
-
- com.evolveum.midpoint.repo.sql.helpers.BaseHelper
-
@Component public class BaseHelper extends Object
Core functionality needed in all members of SQL service family. Taken out of SqlBaseService in order to be accessible from other components by autowiring.Originally more Hibernate oriented, some pure JDBC parts are added (
newJdbcSession()
anddataSource
field) which may be basis of pure JDBC repository in the future. It may go away from this class, but for now, hybrid approach is chosen. But while helper methods are used for ORM/Hibernate stuff, after creatingJdbcSession
all other methods are called on the returned object.
-
-
Field Summary
Fields Modifier and Type Field Description static long
LOCKING_DELAY_INTERVAL_BASE
Timeout will be a random number between 0 and LOCKING_DELAY_INTERVAL_BASE * 2^exp where exp is either real attempt # minus 1, or LOCKING_EXP_THRESHOLD (whatever is lesser).static int
LOCKING_EXP_THRESHOLD
static int
LOCKING_MAX_RETRIES
How many times we want to repeat operation after lock acquisition, pessimistic, optimistic exception.
-
Constructor Summary
Constructors Constructor Description BaseHelper(@NotNull SqlRepositoryConfiguration sqlRepositoryConfiguration, org.hibernate.SessionFactory sessionFactory, DataSource dataSource)
BaseHelper(SqlRepositoryFactory repositoryFactory, org.hibernate.SessionFactory sessionFactory, DataSource dataSource)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description org.hibernate.Session
beginReadOnlyTransaction()
org.hibernate.Session
beginTransaction()
org.hibernate.Session
beginTransaction(String startTransactionStatement)
void
cleanupSessionAndResult(org.hibernate.Session session, OperationResult result)
DataSource
dataSource()
@NotNull SqlRepositoryConfiguration
getConfiguration()
org.hibernate.SessionFactory
getSessionFactory()
void
handleGeneralCheckedException(Throwable ex, org.hibernate.Session session, OperationResult result)
void
handleGeneralException(Throwable ex, OperationResult result)
void
handleGeneralException(Throwable ex, org.hibernate.Session session, OperationResult result)
void
handleGeneralRuntimeException(RuntimeException ex, org.hibernate.Session session, OperationResult result)
int
logOperationAttempt(String oid, String operation, int attempt, @NotNull RuntimeException ex, OperationResult result)
JdbcSession
newJdbcSession()
CreatesJdbcSession
that typically represents transactional work on JDBC connection.com.querydsl.sql.Configuration
querydslConfiguration()
-
-
-
Field Detail
-
LOCKING_MAX_RETRIES
public static final int LOCKING_MAX_RETRIES
How many times we want to repeat operation after lock acquisition, pessimistic, optimistic exception.- See Also:
- Constant Field Values
-
LOCKING_DELAY_INTERVAL_BASE
public static final long LOCKING_DELAY_INTERVAL_BASE
Timeout will be a random number between 0 and LOCKING_DELAY_INTERVAL_BASE * 2^exp where exp is either real attempt # minus 1, or LOCKING_EXP_THRESHOLD (whatever is lesser).- See Also:
- Constant Field Values
-
LOCKING_EXP_THRESHOLD
public static final int LOCKING_EXP_THRESHOLD
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
BaseHelper
public BaseHelper(@NotNull @NotNull SqlRepositoryConfiguration sqlRepositoryConfiguration, org.hibernate.SessionFactory sessionFactory, DataSource dataSource)
-
BaseHelper
@Autowired public BaseHelper(SqlRepositoryFactory repositoryFactory, org.hibernate.SessionFactory sessionFactory, DataSource dataSource)
-
-
Method Detail
-
getSessionFactory
public org.hibernate.SessionFactory getSessionFactory()
-
beginReadOnlyTransaction
public org.hibernate.Session beginReadOnlyTransaction()
-
beginTransaction
public org.hibernate.Session beginTransaction()
-
beginTransaction
public org.hibernate.Session beginTransaction(String startTransactionStatement)
-
getConfiguration
@NotNull public @NotNull SqlRepositoryConfiguration getConfiguration()
-
cleanupSessionAndResult
public void cleanupSessionAndResult(org.hibernate.Session session, OperationResult result)
-
handleGeneralException
public void handleGeneralException(Throwable ex, OperationResult result)
-
handleGeneralException
public void handleGeneralException(Throwable ex, org.hibernate.Session session, OperationResult result)
-
handleGeneralRuntimeException
public void handleGeneralRuntimeException(RuntimeException ex, org.hibernate.Session session, OperationResult result)
-
handleGeneralCheckedException
public void handleGeneralCheckedException(Throwable ex, org.hibernate.Session session, OperationResult result)
-
logOperationAttempt
public int logOperationAttempt(String oid, String operation, int attempt, @NotNull @NotNull RuntimeException ex, OperationResult result)
-
dataSource
public DataSource dataSource()
-
querydslConfiguration
public com.querydsl.sql.Configuration querydslConfiguration()
-
newJdbcSession
public JdbcSession newJdbcSession()
CreatesJdbcSession
that typically represents transactional work on JDBC connection. All other lifecycle methods are to be called on the returned object. Object isAutoCloseable
and can be used in try-with-resource blocks.
-
-