Package org.springframework.jdbc.support.nativejdbc

Examples of org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor


* @author Juergen Hoeller
*/
public class NativeJdbcExtractorTests extends TestCase {

  public void testSimpleNativeJdbcExtractor() throws SQLException {
    SimpleNativeJdbcExtractor extractor = new SimpleNativeJdbcExtractor();

    MockControl conControl = MockControl.createControl(Connection.class);
    Connection con = (Connection) conControl.getMock();
    MockControl dbmdControl = MockControl.createControl(DatabaseMetaData.class);
    DatabaseMetaData dbmd = (DatabaseMetaData) dbmdControl.getMock();
    MockControl con2Control = MockControl.createControl(Connection.class);
    Connection con2 = (Connection) con2Control.getMock();
    con.getMetaData();
    conControl.setReturnValue(dbmd, 2);
    dbmd.getConnection();
    dbmdControl.setReturnValue(con2, 2);
    conControl.replay();
    dbmdControl.replay();
    con2Control.replay();

    Connection nativeCon = extractor.getNativeConnection(con);
    assertEquals(con2, nativeCon);

    MockControl stmtControl = MockControl.createControl(Statement.class);
    Statement stmt = (Statement) stmtControl.getMock();
    stmt.getConnection();
    stmtControl.setReturnValue(con);
    stmtControl.replay();

    nativeCon = extractor.getNativeConnectionFromStatement(stmt);
    assertEquals(con2, nativeCon);

    Statement nativeStmt = extractor.getNativeStatement(stmt);
    assertEquals(nativeStmt, stmt);

    MockControl psControl = MockControl.createControl(PreparedStatement.class);
    PreparedStatement ps = (PreparedStatement) psControl.getMock();
    psControl.replay();

    PreparedStatement nativePs = extractor.getNativePreparedStatement(ps);
    assertEquals(ps, nativePs);

    MockControl csControl = MockControl.createControl(CallableStatement.class);
    CallableStatement cs = (CallableStatement) csControl.getMock();
    MockControl rsControl = MockControl.createControl(ResultSet.class);
    ResultSet rs = (ResultSet) rsControl.getMock();
    cs.getResultSet();
    csControl.setReturnValue(rs);
    csControl.replay();
    rsControl.replay();

    CallableStatement nativeCs = extractor.getNativeCallableStatement(cs);
    assertEquals(cs, nativeCs);

    ResultSet nativeRs = extractor.getNativeResultSet(cs.getResultSet());
    assertEquals(nativeRs, rs);

    conControl.verify();
    dbmdControl.verify();
    con2Control.verify();
View Full Code Here


        assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
        Connection tCon = DataSourceUtils.getConnection(dsToUse);
        try {
          if (createStatement) {
            tCon.createStatement();
            assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(tCon));
          }
        }
        catch (SQLException ex) {
          throw new UncategorizedSQLException("", "", ex);
        }
View Full Code Here

        // something transactional
        assertEquals(con, DataSourceUtils.getConnection(ds));
        TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy(ds);
        try {
          assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
          assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
          // should be ignored
          dsProxy.getConnection().close();
        }
        catch (SQLException ex) {
          throw new UncategorizedSQLException("", "", ex);
View Full Code Here

        // something transactional
        assertEquals(con, DataSourceUtils.getConnection(ds));
        final TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy(ds);
        try {
          assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
          assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
          // should be ignored
          dsProxy.getConnection().close();
        }
        catch (SQLException ex) {
          throw new UncategorizedSQLException("", "", ex);
        }

        tt.execute(new TransactionCallbackWithoutResult() {
          protected void doInTransactionWithoutResult(TransactionStatus status) {
            // something transactional
            assertEquals(con, DataSourceUtils.getConnection(ds));
            try {
              assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
              assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
              // should be ignored
              dsProxy.getConnection().close();
            }
            catch (SQLException ex) {
              throw new UncategorizedSQLException("", "", ex);
View Full Code Here

        assertEquals(con, DataSourceUtils.getConnection(ds));
        final TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy(ds);
        dsProxy.setReobtainTransactionalConnections(true);
        try {
          assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
          assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
          // should be ignored
          dsProxy.getConnection().close();
        }
        catch (SQLException ex) {
          throw new UncategorizedSQLException("", "", ex);
        }

        tt.execute(new TransactionCallbackWithoutResult() {
          protected void doInTransactionWithoutResult(TransactionStatus status) {
            // something transactional
            assertEquals(con, DataSourceUtils.getConnection(ds));
            try {
              assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
              assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
              // should be ignored
              dsProxy.getConnection().close();
            }
            catch (SQLException ex) {
              throw new UncategorizedSQLException("", "", ex);
View Full Code Here

*/
public class NativeJdbcExtractorTests {

  @Test
  public void testSimpleNativeJdbcExtractor() throws SQLException {
    SimpleNativeJdbcExtractor extractor = new SimpleNativeJdbcExtractor();

    Connection con = mock(Connection.class);
    DatabaseMetaData dbmd = mock(DatabaseMetaData.class);
    Connection con2 = mock(Connection.class);
    given(con.getMetaData()).willReturn(dbmd);
    given(dbmd.getConnection()).willReturn(con2);

    Connection nativeCon = extractor.getNativeConnection(con);
    assertEquals(con2, nativeCon);

    Statement stmt = mock(Statement.class);
    given(stmt.getConnection()).willReturn(con);

    nativeCon = extractor.getNativeConnectionFromStatement(stmt);
    assertEquals(con2, nativeCon);

    Statement nativeStmt = extractor.getNativeStatement(stmt);
    assertEquals(nativeStmt, stmt);

    PreparedStatement ps = mock(PreparedStatement.class);

    PreparedStatement nativePs = extractor.getNativePreparedStatement(ps);
    assertEquals(ps, nativePs);

    CallableStatement cs = mock(CallableStatement.class);
    ResultSet rs = mock(ResultSet.class);
    given(cs.getResultSet()).willReturn(rs);

    CallableStatement nativeCs = extractor.getNativeCallableStatement(cs);
    assertEquals(cs, nativeCs);

    ResultSet nativeRs = extractor.getNativeResultSet(cs.getResultSet());
    assertEquals(nativeRs, rs);
  }
View Full Code Here

        assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
        Connection tCon = DataSourceUtils.getConnection(dsToUse);
        try {
          if (createStatement) {
            tCon.createStatement();
            assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(tCon));
          }
        }
        catch (SQLException ex) {
          throw new UncategorizedSQLException("", "", ex);
        }
View Full Code Here

        // something transactional
        assertEquals(con, DataSourceUtils.getConnection(ds));
        TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy(ds);
        try {
          assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
          assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
          // should be ignored
          dsProxy.getConnection().close();
        }
        catch (SQLException ex) {
          throw new UncategorizedSQLException("", "", ex);
View Full Code Here

        // something transactional
        assertEquals(con, DataSourceUtils.getConnection(ds));
        final TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy(ds);
        try {
          assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
          assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
          // should be ignored
          dsProxy.getConnection().close();
        }
        catch (SQLException ex) {
          throw new UncategorizedSQLException("", "", ex);
        }

        tt.execute(new TransactionCallbackWithoutResult() {
          @Override
          protected void doInTransactionWithoutResult(TransactionStatus status) {
            // something transactional
            assertEquals(con, DataSourceUtils.getConnection(ds));
            try {
              assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
              assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
              // should be ignored
              dsProxy.getConnection().close();
            }
            catch (SQLException ex) {
              throw new UncategorizedSQLException("", "", ex);
View Full Code Here

        assertEquals(con, DataSourceUtils.getConnection(ds));
        final TransactionAwareDataSourceProxy dsProxy = new TransactionAwareDataSourceProxy(ds);
        dsProxy.setReobtainTransactionalConnections(true);
        try {
          assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
          assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
          // should be ignored
          dsProxy.getConnection().close();
        }
        catch (SQLException ex) {
          throw new UncategorizedSQLException("", "", ex);
        }

        tt.execute(new TransactionCallbackWithoutResult() {
          @Override
          protected void doInTransactionWithoutResult(TransactionStatus status) {
            // something transactional
            assertEquals(con, DataSourceUtils.getConnection(ds));
            try {
              assertEquals(con, ((ConnectionProxy) dsProxy.getConnection()).getTargetConnection());
              assertEquals(con, new SimpleNativeJdbcExtractor().getNativeConnection(dsProxy.getConnection()));
              // should be ignored
              dsProxy.getConnection().close();
            }
            catch (SQLException ex) {
              throw new UncategorizedSQLException("", "", ex);
View Full Code Here

TOP

Related Classes of org.springframework.jdbc.support.nativejdbc.SimpleNativeJdbcExtractor

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.