Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
 /*
  * Copyright Openmind http://www.openmindonline.it
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
  *
  *      http://www.apache.org/licenses/LICENSE-2.0
  *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package it.openutils.testing.dbunit;
Extended operation for dbunit that disables FK checks.

Author(s):
fgiust
Version:
$Id: MySqlAbstractNoFkOperation.java 578 2008-01-31 13:13:40Z fgiust $
{

    
Wrapped operation.
    private final DatabaseOperation operation;

    
Creates a new InsertIdentityOperation object that decorates the specified operation.

Parameters:
operation wrapped operation
    {
        this. = operation;
    }

    
    @Override
    public void execute(IDatabaseConnection connectionIDataSet dataSetthrows DatabaseUnitExceptionSQLException
    {
        Connection jdbcConnection = connection.getConnection();
        Statement statement = jdbcConnection.createStatement();
        try
        {
            if (!jdbcConnection.getAutoCommit())
            {
                throw new ExclusiveTransactionException();
            }
            jdbcConnection.setAutoCommit(false);
            // disable FK
            statement.execute("SET FOREIGN_KEY_CHECKS=0");
            try
            {
                .execute(connectionconnection.createDataSet());
            }
            finally
            {
                // enable FK
                statement.execute("SET FOREIGN_KEY_CHECKS=1");
                jdbcConnection.commit();
            }
        }
        finally
        {
            jdbcConnection.setAutoCommit(true);
            statement.close();
        }
    }
New to GrepCode? Check out our FAQ X