All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.databene.dbsanity.report.TempResultFileModule Maven / Gradle / Ivy

Go to download

DB Sanity is a tool for verifying a database's sanity and data integrity.

There is a newer version: 0.9.4
Show newest version
/*
 * (c) Copyright 2010 by Volker Bergmann. All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, is permitted under the terms of the
 * GNU General Public License (GPL).
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
 * WITHOUT A WARRANTY OF ANY KIND. ALL EXPRESS OR IMPLIED CONDITIONS,
 * REPRESENTATIONS AND WARRANTIES, INCLUDING ANY IMPLIED WARRANTY OF
 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE
 * HEREBY EXCLUDED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
 * POSSIBILITY OF SUCH DAMAGE.
 */

package org.databene.dbsanity.report;

import java.io.File;
import java.io.FileWriter;
import java.io.IOException;

import org.databene.commons.FileUtil;
import org.databene.commons.IOUtil;
import org.databene.dbsanity.model.SanityCheck;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Writes defect data to a temporary file for later evaluation and consolidation.

* Created: 26.10.2010 11:53:15 * @since 1.0 * @author Yibo Wang */ public class TempResultFileModule extends AbstractReportModule { private static final Logger LOGGER = LoggerFactory.getLogger(TempResultFileModule.class); @Override public void failure(SanityCheck check, Object[] errorInfo, String[] infoHeaders) { File tempResultFileName = check.getTmpResultFile(); try { String result = ""; for (Object part : errorInfo) if (null != part) result += part.toString() + " "; LOGGER.debug("Result of FAILURE: {}", result); appendToFile(tempResultFileName, result); // TODO v1.0 this might be critical for performance } catch (IOException e) { throw new RuntimeException("Error writing temporary result file: " + tempResultFileName, e); } } private void appendToFile(File file, String text) throws IOException { FileUtil.ensureDirectoryExists(file.getParentFile()); FileWriter fileWriter = null; try { fileWriter = new FileWriter(file, true); fileWriter.write(text); } catch (IOException e) { throw e; } finally { IOUtil.close(fileWriter); } } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy