Tabnine Logo
SessionImplementor.getJdbcCoordinator
Code IndexAdd Tabnine to your IDE (free)

How to use
getJdbcCoordinator
method
in
org.hibernate.engine.spi.SessionImplementor

Best Java code snippets using org.hibernate.engine.spi.SessionImplementor.getJdbcCoordinator (Showing top 20 results out of 315)

origin: hibernate/hibernate-orm

@Override
public JdbcCoordinator getJdbcCoordinator() {
  return delegate.getJdbcCoordinator();
}
origin: spring-projects/spring-framework

/**
 * Return whether the given Hibernate Session will always hold the same
 * JDBC Connection. This is used to check whether the transaction manager
 * can safely prepare and clean up the JDBC Connection used for a transaction.
 * <p>The default implementation checks the Session's connection release mode
 * to be "on_close".
 * @param session the Hibernate Session to check
 * @see ConnectionReleaseMode#ON_CLOSE
 */
@SuppressWarnings("deprecation")
protected boolean isSameConnectionForEntireSession(Session session) {
  if (!(session instanceof SessionImplementor)) {
    // The best we can do is to assume we're safe.
    return true;
  }
  ConnectionReleaseMode releaseMode =
      ((SessionImplementor) session).getJdbcCoordinator().getConnectionReleaseMode();
  return ConnectionReleaseMode.ON_CLOSE.equals(releaseMode);
}
origin: spring-projects/spring-framework

/**
 * Determine whether the given Session is (still) physically connected
 * to the database, that is, holds an active JDBC Connection internally.
 * @param session the Hibernate Session to check
 * @see #isSameConnectionForEntireSession(Session)
 */
protected boolean isPhysicallyConnected(Session session) {
  if (!(session instanceof SessionImplementor)) {
    // The best we can do is to check whether we're logically connected.
    return session.isConnected();
  }
  return ((SessionImplementor) session).getJdbcCoordinator().getLogicalConnection().isPhysicallyConnected();
}
origin: org.springframework/spring-orm

/**
 * Return whether the given Hibernate Session will always hold the same
 * JDBC Connection. This is used to check whether the transaction manager
 * can safely prepare and clean up the JDBC Connection used for a transaction.
 * <p>The default implementation checks the Session's connection release mode
 * to be "on_close".
 * @param session the Hibernate Session to check
 * @see ConnectionReleaseMode#ON_CLOSE
 */
@SuppressWarnings("deprecation")
protected boolean isSameConnectionForEntireSession(Session session) {
  if (!(session instanceof SessionImplementor)) {
    // The best we can do is to assume we're safe.
    return true;
  }
  ConnectionReleaseMode releaseMode =
      ((SessionImplementor) session).getJdbcCoordinator().getConnectionReleaseMode();
  return ConnectionReleaseMode.ON_CLOSE.equals(releaseMode);
}
origin: org.springframework/spring-orm

/**
 * Determine whether the given Session is (still) physically connected
 * to the database, that is, holds an active JDBC Connection internally.
 * @param session the Hibernate Session to check
 * @see #isSameConnectionForEntireSession(Session)
 */
protected boolean isPhysicallyConnected(Session session) {
  if (!(session instanceof SessionImplementor)) {
    // The best we can do is to check whether we're logically connected.
    return session.isConnected();
  }
  return ((SessionImplementor) session).getJdbcCoordinator().getLogicalConnection().isPhysicallyConnected();
}
origin: hibernate/hibernate-orm

  @Override
  public void execute(Connection connection) throws SQLException {
    Statement stmt = ((SessionImplementor)s).getJdbcCoordinator().getStatementPreparer().createStatement();
    ((SessionImplementor)s).getJdbcCoordinator().getResultSetReturn().executeUpdate( stmt, "DROP FUNCTION spLock FROM TestInterSystemsFunctionsClass" );
  }
}
origin: hibernate/hibernate-orm

  public void execute(Connection connection) throws SQLException {
    Statement st = s.getJdbcCoordinator().getStatementPreparer().createStatement();
    s.getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT COUNT(*) FROM " + table );
    ResultSet result = s.getJdbcCoordinator().getResultSetReturn().extract( st, "SELECT COUNT(*) FROM " + table );
    result.next();
    int rowCount = result.getInt( 1 );
    assertEquals( "Unexpected row count", expectedRowCount, rowCount );
  }
}
origin: hibernate/hibernate-orm

  private void releaseStatement(Session session, PreparedStatement ps) {
    if ( ps != null ) {
      try {
        ( (SessionImplementor) session ).getJdbcCoordinator().getResourceRegistry().release( ps );
      }
      catch ( Throwable ignore ) {
        // ignore...
      }
    }
  }
}
origin: hibernate/hibernate-orm

  @Override
  public void execute(Connection connection) throws SQLException {
    PreparedStatement statement = ((SessionImplementor)s).getJdbcCoordinator().getStatementPreparer().prepareStatement( "SELECT * FROM STRANGE_TYPED_OBJECT WHERE ID=?" );
    statement.setInt(1, id.intValue());
    ResultSet resultSet = ((SessionImplementor)s).getJdbcCoordinator().getResultSetReturn().extract( statement );
    assertTrue("A row should have been returned", resultSet.next());
    assertTrue("Default value should have been mapped to null", resultSet.getObject("VALUE_ONE") == null);
    assertTrue("Default value should have been mapped to null", resultSet.getObject("VALUE_TWO") == null);
    assertEquals("Non-Default value should not be changed", resultSet.getInt("VALUE_THREE"), 5);
    assertTrue("Default value should have been mapped to null", resultSet.getObject("VALUE_FOUR") == null);
  }
}
origin: hibernate/hibernate-orm

  @Override
  public void execute(Connection connection) throws SQLException {
    PreparedStatement stmnt = null;
    try {
      stmnt = session.getJdbcCoordinator().getStatementPreparer().prepareStatement( "UPDATE T_JOB SET JOB_STATUS = 1" );
      session.getJdbcCoordinator().getResultSetReturn().executeUpdate( stmnt );
    }
    finally {
      if ( stmnt != null ) {
        try {
          session.getJdbcCoordinator().getResourceRegistry().release( stmnt );
        }
        catch( Throwable ignore ) {
        }
      }
    }
  }
}
origin: hibernate/hibernate-orm

  @Override
  public void execute(Connection connection) throws SQLException {
    // Attempt to insert some bad values into the T_MEMBERSHIP table that should
    // result in a constraint violation
    PreparedStatement ps = null;
    try {
      ps = ((SessionImplementor)session).getJdbcCoordinator().getStatementPreparer().prepareStatement( "INSERT INTO T_MEMBERSHIP (user_id, group_id) VALUES (?, ?)" );
      ps.setLong(1, 52134241);    // Non-existent user_id
      ps.setLong(2, 5342);        // Non-existent group_id
      ((SessionImplementor)session).getJdbcCoordinator().getResultSetReturn().executeUpdate( ps );
      fail("INSERT should have failed");
    }
    catch (ConstraintViolationException ignore) {
      // expected outcome
    }
    finally {
      releaseStatement( session, ps );
    }
  }
}
origin: hibernate/hibernate-orm

@Test
public void basicStreamTest() {
  Session session = openSession();
  session.getTransaction().begin();
  // mainly we want to make sure that closing the Stream releases the ScrollableResults too
  assertThat( ( (SessionImplementor) session ).getJdbcCoordinator().getLogicalConnection().getResourceRegistry().hasRegisteredResources(), is( false ) );
  final Stream<MyEntity> stream = session.createQuery( "from MyEntity", MyEntity.class ).stream();
  assertThat( ( (SessionImplementor) session ).getJdbcCoordinator().getLogicalConnection().getResourceRegistry().hasRegisteredResources(), is( true ) );
  stream.forEach( System.out::println );
  assertThat( ( (SessionImplementor) session ).getJdbcCoordinator().getLogicalConnection().getResourceRegistry().hasRegisteredResources(), is( true ) );
  stream.close();
  assertThat( ( (SessionImplementor) session ).getJdbcCoordinator().getLogicalConnection().getResourceRegistry().hasRegisteredResources(), is( false ) );
  session.getTransaction().commit();
  session.close();
}
origin: hibernate/hibernate-orm

  @Override
  public void execute(Connection connection) throws SQLException {
    Statement stmt = ( (SessionImplementor) s ).getJdbcCoordinator()
        .getStatementPreparer()
        .createStatement();
    String create_function = "CREATE FUNCTION SQLUser.TestInterSystemsFunctionsClass_spLock\n" +
        "     ( INOUT pHandle %SQLProcContext, \n" +
        "       ROWID INTEGER \n" +
        " )\n" +
        " FOR User.TestInterSystemsFunctionsClass " +
        "    PROCEDURE\n" +
        "    RETURNS INTEGER\n" +
        "    LANGUAGE OBJECTSCRIPT\n" +
        "    {\n" +
        "        q 0\n" +
        "     }";
    ( (SessionImplementor) s ).getJdbcCoordinator().getResultSetReturn().executeUpdate(
        stmt,
        create_function
    );
  }
}
origin: hibernate/hibernate-orm

  @Override
  public void execute(Connection connection) throws SQLException {
    // prepare/execute a query against a non-existent table
    PreparedStatement ps = null;
    try {
      ps = ((SessionImplementor)session).getJdbcCoordinator().getStatementPreparer().prepareStatement( "SELECT user_id, user_name FROM tbl_no_there" );
      ((SessionImplementor)session).getJdbcCoordinator().getResultSetReturn().extract( ps );
      fail("SQL compilation should have failed");
    }
    catch (SQLGrammarException ignored) {
      // expected outcome
    }
    finally {
      releaseStatement( session, ps );
    }
  }
}
origin: hibernate/hibernate-orm

private void validateColumn(Connection connection, String columnName, int expectedJdbcTypeCode)
    throws SQLException {
  DatabaseMetaData meta = connection.getMetaData();
  // DBs treat the meta information differently, in particular case sensitivity.
  // We need to use the meta information to find out how to treat names
  String tableNamePattern = generateFinalNamePattern( meta, SOME_ENTITY_TABLE_NAME );
  String columnNamePattern = generateFinalNamePattern( meta, columnName );
  ResultSet columnInfo = meta.getColumns( null, null, tableNamePattern, columnNamePattern );
  s.getJdbcCoordinator().getResourceRegistry().register(columnInfo, columnInfo.getStatement());
  assertTrue( columnInfo.next() );
  int dataType = columnInfo.getInt( "DATA_TYPE" );
  s.getJdbcCoordinator().getResourceRegistry().release( columnInfo, columnInfo.getStatement() );
  assertEquals(
      columnName,
      JdbcTypeNameMapper.getTypeName( expectedJdbcTypeCode ),
      JdbcTypeNameMapper.getTypeName( dataType )
  );
}
origin: hibernate/hibernate-orm

  @Override
  public void execute(Connection connection) throws SQLException {
    PreparedStatement ps = sessionImplementor.getJdbcCoordinator().getStatementPreparer().prepareStatement( QUERY_STRING );
    ResultSet rs = sessionImplementor.getJdbcCoordinator().getResultSetReturn().extract( ps );
    try {
      ResultSetMetaData metadata = rs.getMetaData();
      String column1Alias = getDialect().getColumnAliasExtractor().extractColumnAlias( metadata, 1 );
      String column2Alias = getDialect().getColumnAliasExtractor().extractColumnAlias( metadata, 2 );
      Assert.assertFalse( "bad dialect.getColumnAliasExtractor impl", column1Alias.equals( column2Alias ) );
    }
    finally {
      sessionImplementor.getJdbcCoordinator().getResourceRegistry().release( rs, ps );
      sessionImplementor.getJdbcCoordinator().getResourceRegistry().release( ps );
    }
  }
}
origin: hibernate/hibernate-orm

@Test
public void testExceptionHandling() {
  Session session = openSession();
  SessionImplementor sessionImpl = (SessionImplementor) session;
  boolean caught = false;
  try {
    PreparedStatement ps = sessionImpl.getJdbcCoordinator().getStatementPreparer()
        .prepareStatement( "select count(*) from NON_EXISTENT" );
    sessionImpl.getJdbcCoordinator().getResultSetReturn().execute( ps );
  }
  catch ( JDBCException ok ) {
    caught = true;
  }
  finally {
    session.close();
  }
  assertTrue( "The connection did not throw a JDBCException as expected", caught );
}
origin: hibernate/hibernate-orm

Field field = sessionImplementor.getJdbcCoordinator().getClass().getDeclaredField( "currentBatch" );
field.setAccessible( true );
Batch batch = (Batch) field.get( sessionImplementor.getJdbcCoordinator() );
if ( batch != null ) {
origin: hibernate/hibernate-orm

  @Override
  public void execute(Connection connection) throws SQLException {
    final JdbcCoordinator jdbcCoordinator = ( (SessionImplementor) session ).getJdbcCoordinator();
    final StatementPreparer statementPreparer = jdbcCoordinator.getStatementPreparer();
    final ResultSetReturn resultSetReturn = jdbcCoordinator.getResultSetReturn();
    PreparedStatement ps = null;
    try {
      ps = statementPreparer.prepareStatement( "UPDATE T_USER SET user_name = ? WHERE user_id = ?" );
      ps.setNull( 1, Types.VARCHAR ); // Attempt to update user name to NULL (NOT NULL constraint defined).
      ps.setLong( 2, user.getId() );
      resultSetReturn.executeUpdate( ps );
      fail( "UPDATE should have failed because of not NULL constraint." );
    }
    catch ( ConstraintViolationException ignore ) {
      // expected outcome
    }
    finally {
      releaseStatement( session, ps );
    }
  }
}
origin: hibernate/hibernate-orm

session.getJdbcCoordinator().executeBatch();
org.hibernate.engine.spiSessionImplementorgetJdbcCoordinator

Popular methods of SessionImplementor

  • getFactory
    Get the creating SessionFactoryImplementor
  • getTransactionCoordinator
  • connection
  • getPersistenceContext
    Get the persistence context for this session
  • getLoadQueryInfluencers
    Get the load query influencers associated with this session.
  • isTransactionInProgress
    Does this Session have an active Hibernate transaction or is there a JTA transaction in progress?
  • getEntityPersister
    Get the EntityPersister for any instance
  • isClosed
    Determine whether the session is closed. Provided separately from #isOpen() as this method does not
  • flush
  • getTenantIdentifier
    Match te method on org.hibernate.Session and org.hibernate.StatelessSession
  • generateEntityKey
  • getContextEntityIdentifier
  • generateEntityKey,
  • getContextEntityIdentifier,
  • isOpen,
  • bestGuessEntityName,
  • getFlushMode,
  • getSessionFactory,
  • guessEntityName,
  • immediateLoad,
  • initializeCollection

Popular in Java

  • Start an intent from android
  • getApplicationContext (Context)
  • compareTo (BigDecimal)
  • addToBackStack (FragmentTransaction)
  • Graphics2D (java.awt)
    This Graphics2D class extends the Graphics class to provide more sophisticated control overgraphics
  • File (java.io)
    An "abstract" representation of a file system entity identified by a pathname. The pathname may be a
  • KeyStore (java.security)
    KeyStore is responsible for maintaining cryptographic keys and their owners. The type of the syste
  • GregorianCalendar (java.util)
    GregorianCalendar is a concrete subclass of Calendarand provides the standard calendar used by most
  • Vector (java.util)
    Vector is an implementation of List, backed by an array and synchronized. All optional operations in
  • AtomicInteger (java.util.concurrent.atomic)
    An int value that may be updated atomically. See the java.util.concurrent.atomic package specificati
  • Top PhpStorm plugins
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now