Package org.hibernate.jdbc

Examples of org.hibernate.jdbc.Expectation


      try {
        // create all the new entries
        Iterator entries = collection.entries( this );
        if ( entries.hasNext() ) {
          Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );
          collection.preInsert( this );
          int i = 0;
          int count = 0;
          while ( entries.hasNext() ) {

            final Object entry = entries.next();
            if ( collection.entryExists( entry, i ) ) {
              int offset = 1;
              PreparedStatement st = null;
              boolean callable = isInsertCallable();
              boolean useBatch = expectation.canBeBatched();
              String sql = getSQLInsertRowString();

              if ( useBatch ) {
                if ( recreateBatchKey == null ) {
                  recreateBatchKey = new BasicBatchKey(
                      getRole() + "#RECREATE",
                      expectation
                      );
                }
                st = session.getTransactionCoordinator()
                    .getJdbcCoordinator()
                    .getBatch( recreateBatchKey )
                    .getBatchStatement( sql, callable );
              }
              else {
                st = session.getTransactionCoordinator()
                    .getJdbcCoordinator()
                    .getStatementPreparer()
                    .prepareStatement( sql, callable );
              }

              try {
                offset += expectation.prepare( st );

                // TODO: copy/paste from insertRows()
                int loc = writeKey( st, id, offset, session );
                if ( hasIdentifier ) {
                  loc = writeIdentifier( st, collection.getIdentifier( entry, i ), loc, session );
                }
                if ( hasIndex /* && !indexIsFormula */) {
                  loc = writeIndex( st, collection.getIndex( entry, i, this ), loc, session );
                }
                loc = writeElement( st, collection.getElement( entry ), loc, session );

                if ( useBatch ) {
                  session.getTransactionCoordinator()
                      .getJdbcCoordinator()
                      .getBatch( recreateBatchKey )
                      .addToBatch();
                }
                else {
                  expectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
                }

                collection.afterRowInsert( this, entry, i );
                count++;
              }
View Full Code Here


        LOG.debugf( "Deleting rows of collection: %s",
            MessageHelper.collectionInfoString( this, collection, id, session ) );
      }

      boolean deleteByIndex = !isOneToMany() && hasIndex && !indexContainsFormula;
      final Expectation expectation = Expectations.appropriateExpectation( getDeleteCheckStyle() );
      try {
        // delete all the deleted entries
        Iterator deletes = collection.getDeletes( this, !deleteByIndex );
        if ( deletes.hasNext() ) {
          int offset = 1;
          int count = 0;
          while ( deletes.hasNext() ) {
            PreparedStatement st = null;
            boolean callable = isDeleteCallable();
            boolean useBatch = expectation.canBeBatched();
            String sql = getSQLDeleteRowString();

            if ( useBatch ) {
              if ( deleteBatchKey == null ) {
                deleteBatchKey = new BasicBatchKey(
                    getRole() + "#DELETE",
                    expectation
                    );
              }
              st = session.getTransactionCoordinator()
                  .getJdbcCoordinator()
                  .getBatch( deleteBatchKey )
                  .getBatchStatement( sql, callable );
            }
            else {
              st = session.getTransactionCoordinator()
                  .getJdbcCoordinator()
                  .getStatementPreparer()
                  .prepareStatement( sql, callable );
            }

            try {
              expectation.prepare( st );

              Object entry = deletes.next();
              int loc = offset;
              if ( hasIdentifier ) {
                writeIdentifier( st, entry, loc, session );
              }
              else {
                loc = writeKey( st, id, loc, session );
                if ( deleteByIndex ) {
                  writeIndexToWhere( st, entry, loc, session );
                }
                else {
                  writeElementToWhere( st, entry, loc, session );
                }
              }

              if ( useBatch ) {
                session.getTransactionCoordinator()
                    .getJdbcCoordinator()
                    .getBatch( deleteBatchKey )
                    .addToBatch();
              }
              else {
                expectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
              }
              count++;
            }
            catch ( SQLException sqle ) {
              if ( useBatch ) {
View Full Code Here

      try {
        // insert all the new entries
        collection.preInsert( this );
        Iterator entries = collection.entries( this );
        Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );
        boolean callable = isInsertCallable();
        boolean useBatch = expectation.canBeBatched();
        String sql = getSQLInsertRowString();
        int i = 0;
        int count = 0;
        while ( entries.hasNext() ) {
          int offset = 1;
          Object entry = entries.next();
          PreparedStatement st = null;
          if ( collection.needsInserting( entry, i, elementType ) ) {

            if ( useBatch ) {
              if ( insertBatchKey == null ) {
                insertBatchKey = new BasicBatchKey(
                    getRole() + "#INSERT",
                    expectation
                    );
              }
              if ( st == null ) {
                st = session.getTransactionCoordinator()
                    .getJdbcCoordinator()
                    .getBatch( insertBatchKey )
                    .getBatchStatement( sql, callable );
              }
            }
            else {
              st = session.getTransactionCoordinator()
                  .getJdbcCoordinator()
                  .getStatementPreparer()
                  .prepareStatement( sql, callable );
            }

            try {
              offset += expectation.prepare( st );
              // TODO: copy/paste from recreate()
              offset = writeKey( st, id, offset, session );
              if ( hasIdentifier ) {
                offset = writeIdentifier( st, collection.getIdentifier( entry, i ), offset, session );
              }
              if ( hasIndex /* && !indexIsFormula */) {
                offset = writeIndex( st, collection.getIndex( entry, i, this ), offset, session );
              }
              writeElement( st, collection.getElement( entry ), offset, session );

              if ( useBatch ) {
                session.getTransactionCoordinator().getJdbcCoordinator().getBatch( insertBatchKey ).addToBatch();
              }
              else {
                expectation.verifyOutcome( session.getTransactionCoordinator().getJdbcCoordinator().getResultSetReturn().executeUpdate( st ), st, -1 );
              }
              collection.afterRowInsert( this, entry, i );
              count++;
            }
            catch ( SQLException sqle ) {
View Full Code Here

      // Remove all the old entries

      try {
        int offset = 1;
        PreparedStatement st = null;
        Expectation expectation = Expectations.appropriateExpectation( getDeleteAllCheckStyle() );
        boolean callable = isDeleteAllCallable();
        boolean useBatch = expectation.canBeBatched();
        String sql = getSQLDeleteString();
        if ( useBatch ) {
          if ( callable ) {
            st = session.getBatcher().prepareBatchCallableStatement( sql );
          }
          else {
            st = session.getBatcher().prepareBatchStatement( sql );
          }
        }
        else {
          if ( callable ) {
            st = session.getBatcher().prepareCallableStatement( sql );
          }
          else {
            st = session.getBatcher().prepareStatement( sql );
          }
        }


        try {
          offset+= expectation.prepare( st );

          writeKey( st, id, offset, session );
          if ( useBatch ) {
            session.getBatcher().addToBatch( expectation );
          }
          else {
            expectation.verifyOutcome( st.executeUpdate(), st, -1 );
          }
        }
        catch ( SQLException sqle ) {
          if ( useBatch ) {
            session.getBatcher().abortBatch( sqle );
View Full Code Here

            final Object entry = entries.next();
            if ( collection.entryExists( entry, i ) ) {
              int offset = 1;
              PreparedStatement st = null;
              Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );
              boolean callable = isInsertCallable();
              boolean useBatch = expectation.canBeBatched();
              String sql = getSQLInsertRowString();

              if ( useBatch ) {
                if ( callable ) {
                  st = session.getBatcher().prepareBatchCallableStatement( sql );
                }
                else {
                  st = session.getBatcher().prepareBatchStatement( sql );
                }
              }
              else {
                if ( callable ) {
                  st = session.getBatcher().prepareCallableStatement( sql );
                }
                else {
                  st = session.getBatcher().prepareStatement( sql );
                }
              }


              try {
                offset+= expectation.prepare( st );

                //TODO: copy/paste from insertRows()
                int loc = writeKey( st, id, offset, session );
                if ( hasIdentifier ) {
                  loc = writeIdentifier( st, collection.getIdentifier(entry, i), loc, session );
                }
                if ( hasIndex /*&& !indexIsFormula*/ ) {
                  loc = writeIndex( st, collection.getIndex(entry, i, this), loc, session );
                }
                loc = writeElement(st, collection.getElement(entry), loc, session );

                if ( useBatch ) {
                  session.getBatcher().addToBatch( expectation );
                }
                else {
                  expectation.verifyOutcome( st.executeUpdate(), st, -1 );
                }

                collection.afterRowInsert( this, entry, i );
                count++;
              }
View Full Code Here

        if ( deletes.hasNext() ) {
          int offset = 1;
          int count = 0;
          while ( deletes.hasNext() ) {
            PreparedStatement st = null;
            Expectation expectation = Expectations.appropriateExpectation( getDeleteCheckStyle() );
            boolean callable = isDeleteCallable();
            boolean useBatch = expectation.canBeBatched();
            String sql = getSQLDeleteRowString();

            if ( useBatch ) {
              if ( callable ) {
                st = session.getBatcher().prepareBatchCallableStatement( sql );
              }
              else {
                st = session.getBatcher().prepareBatchStatement( sql );
              }
            }
            else {
              if ( callable ) {
                st = session.getBatcher().prepareCallableStatement( sql );
              }
              else {
                st = session.getBatcher().prepareStatement( sql );
              }
            }

            try {
              expectation.prepare( st );

              Object entry = deletes.next();
              int loc = offset;
              if ( hasIdentifier ) {
                writeIdentifier( st, entry, loc, session );
              }
              else {
                loc = writeKey( st, id, loc, session );
                if ( deleteByIndex ) {
                  writeIndexToWhere( st, entry, loc, session );
                }
                else {
                  writeElementToWhere( st, entry, loc, session );
                }
              }

              if ( useBatch ) {
                session.getBatcher().addToBatch( expectation );
              }
              else {
                expectation.verifyOutcome( st.executeUpdate(), st, -1 );
              }
              count++;
            }
            catch ( SQLException sqle ) {
              if ( useBatch ) {
View Full Code Here

      try {
        //insert all the new entries
        collection.preInsert( this );
        Iterator entries = collection.entries( this );
        Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );
        boolean callable = isInsertCallable();
        boolean useBatch = expectation.canBeBatched();
        String sql = getSQLInsertRowString();
        int i = 0;
        int count = 0;
        while ( entries.hasNext() ) {
          int offset = 1;
          Object entry = entries.next();
          PreparedStatement st = null;
          if ( collection.needsInserting( entry, i, elementType ) ) {

            if ( useBatch ) {
              if ( st == null ) {
                if ( callable ) {
                  st = session.getBatcher().prepareBatchCallableStatement( sql );
                }
                else {
                  st = session.getBatcher().prepareBatchStatement( sql );
                }
              }
            }
            else {
              if ( callable ) {
                st = session.getBatcher().prepareCallableStatement( sql );
              }
              else {
                st = session.getBatcher().prepareStatement( sql );
              }
            }

            try {
              offset += expectation.prepare( st );
              //TODO: copy/paste from recreate()
              offset = writeKey( st, id, offset, session );
              if ( hasIdentifier ) {
                offset = writeIdentifier( st, collection.getIdentifier(entry, i), offset, session );
              }
              if ( hasIndex /*&& !indexIsFormula*/ ) {
                offset = writeIndex( st, collection.getIndex(entry, i, this), offset, session );
              }
              writeElement(st, collection.getElement(entry), offset, session );

              if ( useBatch ) {
                session.getBatcher().addToBatch( expectation );
              }
              else {
                expectation.verifyOutcome( st.executeUpdate(), st, -1 );
              }
              collection.afterRowInsert( this, entry, i );
              count++;
            }
            catch ( SQLException sqle ) {
View Full Code Here

      return;
    }

    final boolean useVersion = j == 0 && isVersioned();
    final boolean callable = isDeleteCallable( j );
    final Expectation expectation = Expectations.appropriateExpectation( deleteResultCheckStyles[j] );
    final boolean useBatch = j == 0 && isBatchable() && expectation.canBeBatched();

    if ( log.isTraceEnabled() ) {
      log.trace( "Deleting entity: " + MessageHelper.infoString( this, id, getFactory() ) );
      if ( useVersion ) {
        log.trace( "Version: " + version );
      }
    }

    if ( isTableCascadeDeleteEnabled( j ) ) {
      if ( log.isTraceEnabled() ) {
        log.trace( "delete handled by foreign key constraint: " + getTableName( j ) );
      }
      return; //EARLY EXIT!
    }

    try {

      //Render the SQL query
      PreparedStatement delete;
      int index = 1;
      if ( useBatch ) {
        if ( callable ) {
          delete = session.getBatcher().prepareBatchCallableStatement( sql );
        }
        else {
          delete = session.getBatcher().prepareBatchStatement( sql );
        }
      }
      else {
        if ( callable ) {
          delete = session.getBatcher().prepareCallableStatement( sql );
        }
        else {
          delete = session.getBatcher().prepareStatement( sql );
        }
      }

      try {

        index += expectation.prepare( delete );

        // Do the key. The key is immutable so we can use the _current_ object state - not necessarily
        // the state at the time the delete was issued
        getIdentifierType().nullSafeSet( delete, id, index, session );
        index += getIdentifierColumnSpan();
View Full Code Here

      // Remove all the old entries

      try {
        int offset = 1;
        PreparedStatement st = null;
        Expectation expectation = Expectations.appropriateExpectation( getDeleteAllCheckStyle() );
        boolean callable = isDeleteAllCallable();
        boolean useBatch = expectation.canBeBatched();
        String sql = getSQLDeleteString();
        if ( useBatch ) {
          if ( callable ) {
            st = session.getBatcher().prepareBatchCallableStatement( sql );
          }
          else {
            st = session.getBatcher().prepareBatchStatement( sql );
          }
        }
        else {
          if ( callable ) {
            st = session.getBatcher().prepareCallableStatement( sql );
          }
          else {
            st = session.getBatcher().prepareStatement( sql );
          }
        }


        try {
          offset+= expectation.prepare( st );

          writeKey( st, id, offset, session );
          if ( useBatch ) {
            session.getBatcher().addToBatch( expectation );
          }
          else {
            expectation.verifyOutcome( st.executeUpdate(), st, -1 );
          }
        }
        catch ( SQLException sqle ) {
          if ( useBatch ) {
            session.getBatcher().abortBatch( sqle );
View Full Code Here

            final Object entry = entries.next();
            if ( collection.entryExists( entry, i ) ) {
              int offset = 1;
              PreparedStatement st = null;
              Expectation expectation = Expectations.appropriateExpectation( getInsertCheckStyle() );
              boolean callable = isInsertCallable();
              boolean useBatch = expectation.canBeBatched();
              String sql = getSQLInsertRowString();

              if ( useBatch ) {
                if ( callable ) {
                  st = session.getBatcher().prepareBatchCallableStatement( sql );
                }
                else {
                  st = session.getBatcher().prepareBatchStatement( sql );
                }
              }
              else {
                if ( callable ) {
                  st = session.getBatcher().prepareCallableStatement( sql );
                }
                else {
                  st = session.getBatcher().prepareStatement( sql );
                }
              }


              try {
                offset+= expectation.prepare( st );

                //TODO: copy/paste from insertRows()
                int loc = writeKey( st, id, offset, session );
                if ( hasIdentifier ) {
                  loc = writeIdentifier( st, collection.getIdentifier(entry, i), loc, session );
                }
                if ( hasIndex /*&& !indexIsFormula*/ ) {
                  loc = writeIndex( st, collection.getIndex(entry, i, this), loc, session );
                }
                loc = writeElement(st, collection.getElement(entry), loc, session );

                if ( useBatch ) {
                  session.getBatcher().addToBatch( expectation );
                }
                else {
                  expectation.verifyOutcome( st.executeUpdate(), st, -1 );
                }

                collection.afterRowInsert( this, entry, i );
                count++;
              }
View Full Code Here

TOP

Related Classes of org.hibernate.jdbc.Expectation

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.