📄 functionaltestcase.java
字号:
* Shorthand for ( {@link org.hibernate.engine.SessionFactoryImplementor} ) {@link #getSessions()}...
*
* @return The factory
*/
protected SessionFactoryImplementor sfi() {
return ( SessionFactoryImplementor ) getSessions();
}
protected Dialect getDialect() {
return ExecutionEnvironment.DIALECT;
}
protected Configuration getCfg() {
return environment.getConfiguration();
}
public org.hibernate.classic.Session openSession() throws HibernateException {
session = getSessions().openSession();
return session;
}
public org.hibernate.classic.Session openSession(Interceptor interceptor) throws HibernateException {
session = getSessions().openSession(interceptor);
return session;
}
/**
* Do connections enforce SERIALIZABLE isolation...
*
* @return
* @throws Exception
*/
protected boolean isSerializableIsolationEnforced() throws Exception {
Connection conn = null;
try {
conn = sfi().getConnectionProvider().getConnection();
return conn.getTransactionIsolation() >= Connection.TRANSACTION_SERIALIZABLE;
}
finally {
if ( conn != null ) {
try {
sfi().getConnectionProvider().closeConnection( conn );
}
catch ( Throwable ignore ) {
// ignore...
}
}
}
}
/**
* Is connection at least read committed?
* <p/>
* Not, that this skip check relies on the JDBC driver reporting
* the true isolation level correctly. HSQLDB, for example, will
* report whatever you specify as the isolation
* (Connection.setTransationIsolation()), even though it only supports
* read-uncommitted.
*
* @param scenario text description of the scenario being tested.
* @return true if read-committed isolation is maintained.
*/
protected boolean readCommittedIsolationMaintained(String scenario) {
int isolation = java.sql.Connection.TRANSACTION_READ_UNCOMMITTED;
Session testSession = null;
try {
testSession = openSession();
isolation = testSession.connection().getTransactionIsolation();
}
catch( Throwable ignore ) {
}
finally {
if ( testSession != null ) {
try {
testSession.close();
}
catch( Throwable ignore ) {
}
}
}
if ( isolation < java.sql.Connection.TRANSACTION_READ_COMMITTED ) {
reportSkip( "environment does not support at least read committed isolation", scenario );
return false;
}
else {
return true;
}
}
/**
* Does the db/dialect support using a column's physical name in the order-by clause
* even after it has been aliased in the select clause. This is not actually
* required by the SQL spec, although virtually ever DB in the world supports this
* (the most glaring omission here being IBM-variant DBs ala DB2 and Derby).
*
* @param testDescription description of the scenario being tested.
* @return true if is allowed
*/
protected boolean allowsPhysicalColumnNameInOrderby(String testDescription) {
if ( DB2Dialect.class.isInstance( getDialect() ) ) {
// https://issues.apache.org/jira/browse/DERBY-1624
reportSkip( "Dialect does not support physical column name in order-by clause after it is aliased", testDescription );
return false;
}
return true;
}
/**
* Does the db/dialect support using a column's physical name in the having clause
* even after it has been aliased in the select/group-by clause. This is not actually
* required by the SQL spec, although virtually ever DB in the world supports this.
*
* @param testDescription description of the scenario being tested.
* @return true if is allowed
*/
protected boolean allowsPhysicalColumnNameInHaving(String testDescription) {
// I only *know* of this being a limitation on Derby, although I highly suspect
// it is a limitation on any IBM/DB2 variant
if ( DerbyDialect.class.isInstance( getDialect() ) ) {
// https://issues.apache.org/jira/browse/DERBY-1624
reportSkip( "Dialect does not support physical column name in having clause after it is aliased", testDescription );
return false;
}
return true;
}
/**
* Does the db/dialect support empty lists in the IN operator?
* <p/>
* For example, is "... a.b IN () ..." supported?
*
* @param testDescription description of the scenario being tested.
* @return true if is allowed
*/
protected boolean dialectSupportsEmptyInList(String testDescription) {
if ( ! getDialect().supportsEmptyInList() ) {
reportSkip( "Dialect does not support SQL empty in list : x in ()", testDescription );
return false;
}
return true;
}
/**
* Is the db/dialect sensitive in terms of string comparisons?
* @param testDescription description of the scenario being tested.
* @return true if sensitive
*/
protected boolean dialectIsCaseSensitive(String testDescription) {
if ( ! getDialect().areStringComparisonsCaseInsensitive() ) {
reportSkip( "Dialect is case sensitive. ", testDescription );
return true;
}
return false;
}
protected boolean supportsRowValueConstructorSyntaxInInList() {
if ( ! getDialect().supportsRowValueConstructorSyntaxInInList() ) {
reportSkip( "Dialect does not support 'tuple' syntax as part of an IN value list", "query support" );
return false;
}
return true;
}
protected boolean supportsResultSetPositionQueryMethodsOnForwardOnlyCursor() {
if ( ! getDialect().supportsResultSetPositionQueryMethodsOnForwardOnlyCursor() ) {
reportSkip( "Driver does not support 'position query' methods on forward-only cursors", "query support" );
return false;
}
return true;
}
protected boolean supportsCircularCascadeDelete() {
if ( ! getDialect().supportsCircularCascadeDeleteConstraints() ) {
reportSkip( "db/dialect does not support 'circular' cascade delete constraints", "cascade delete constraint support" );
return false;
}
return true;
}
protected boolean supportsSubselectOnLeftSideIn() {
if ( ! getDialect().supportsSubselectAsInPredicateLHS() ) {
reportSkip( "Database does not support (<subselect>) in ( ... ) ", "query support" );
return false;
}
return true;
}
/**
* Expected LOB usage pattern is such that I can perform an insert
* via prepared statement with a parameter binding for a LOB value
* without crazy casting to JDBC driver implementation-specific classes...
* <p/>
* Part of the trickiness here is the fact that this is largely
* driver dependent. For Oracle, which is notoriously bad with
* LOB support in their drivers actually does a pretty good job with
* LOB support as of the 10.2.x versions of their drivers...
*
* @return True if expected usage pattern is support; false otherwise.
*/
protected boolean supportsExpectedLobUsagePattern() {
if ( ! getDialect().supportsExpectedLobUsagePattern() ) {
reportSkip( "database/driver does not support expected LOB usage pattern", "LOB support" );
return false;
}
return true;
}
/**
* Does the current dialect support propogating changes to LOB
* values back to the database? Talking about mutating the
* underlying value as opposed to supplying a new
* LOB instance...
*
* @return True if the changes are propogated back to the
* database; false otherwise.
*/
protected boolean supportsLobValueChangePropogation() {
if ( ! getDialect().supportsLobValueChangePropogation() ) {
reportSkip( "database/driver does not support propogating LOB value change back to database", "LOB support" );
return false;
}
return true;
}
/**
* Is it supported to materialize a LOB locator outside the transaction in
* which it was created?
* <p/>
* Again, part of the trickiness here is the fact that this is largely
* driver dependent.
* <p/>
* NOTE: all database I have tested which {@link #supportsExpectedLobUsagePattern()}
* also support the ability to materialize a LOB outside the owning transaction...
*
* @return True if unbounded materialization is supported; false otherwise.
*/
protected boolean supportsUnboundedLobLocatorMaterialization() {
if ( !getDialect().supportsUnboundedLobLocatorMaterialization() ) {
reportSkip( "database/driver does not support materializing a LOB locator outside the 'owning' transaction", "LOB support" );
return false;
}
return true;
}
protected boolean supportsSubqueryOnMutatingTable() {
if ( !getDialect().supportsSubqueryOnMutatingTable() ) {
reportSkip( "database/driver does not support referencing mutating table in subquery", "bulk DML support" );
return false;
}
return true;
}
protected boolean dialectIs(Class dialectClass) {
return dialectClass.isInstance( getDialect() );
}
protected boolean dialectIsOneOf(Class[] dialectClasses) {
for ( int i = 0; i < dialectClasses.length; i++ ) {
if ( dialectClasses[i].isInstance( getDialect() ) ) {
return true;
}
}
return false;
}
protected boolean dialectIsNot(Class dialectClass) {
return ! dialectIs( dialectClass );
}
protected boolean dialectIsNot(Class[] dialectClasses) {
return ! dialectIsOneOf( dialectClasses );
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -