<commit_before>/* File:        $Id$
 * Revision:    $Revision$
 * Author:      $Author$
 * Date:        $Date$
 *
 * The Netarchive Suite - Software to harvest and preserve websites
 * Copyright 2004-2007 <NAME> and Statsbiblioteket, Denmark
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

package dk.netarkivet.harvester.datamodel;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import dk.netarkivet.common.exceptions.ArgumentNotValid;
import dk.netarkivet.common.exceptions.IOFailure;
import dk.netarkivet.common.exceptions.PermissionDenied;
import dk.netarkivet.common.exceptions.UnknownID;
import dk.netarkivet.common.utils.FilterIterator;

/**
 * A database-oriented implementation of the HarvestDefinitionDAO.
 *
 * Statements to create the tables are in
 * scripts/sql/createfullhddb.sql
 *
 */

public class HarvestDefinitionDBDAO extends HarvestDefinitionDAO {
    private final Log log = LogFactory.getLog(getClass());

    /** Create a new HarvestDefinitionDAO using database.
     */
    HarvestDefinitionDBDAO() {
        DBConnect.checkTableVersion("fullharvests", 2);
        DBConnect.checkTableVersion("partialharvests", 1);
        DBConnect.checkTableVersion("harvest_configs", 1);
    }

    /**
     * Create a harvest definition in Database.
     * The harvest definition object should not have its ID set
     * unless we are in the middle of migrating.
     *
     * @param harvestDefinition A new harvest definition to store in the database.
     * @return The harvestId for the just created harvest definition.
     * @see HarvestDefinitionDAO#create(HarvestDefinition)
     */
    public synchronized Long create(HarvestDefinition harvestDefinition) {
        Long id = harvestDefinition.getOid();
        if (id == null) {
            id = generateNextID();
        }

        Connection c = DBConnect.getDBConnection();
        PreparedStatement s = null;
        try {
            c.setAutoCommit(false);
            s = c.prepareStatement("INSERT INTO harvestdefinitions "
                    + "( harvest_id, name, comments, numevents, submitted,"
                    + "  isactive, edition ) "<commit_msg>Fixing bu 1250<commit_after>/* File:        $Id$
 * Revision:    $Revision$
 * Author:      $Author$
 * Date:        $Date$
 *
 * The Netarchive Suite - Software to harvest and preserve websites
 * Copyright 2004-2007 Det Kongelige Bibliotek and Statsbiblioteket, Denmark
 *
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 *
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */

package dk.netarkivet.harvester.datamodel;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.util.ArrayList;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;

import dk.netarkivet.common.exceptions.ArgumentNotValid;
import dk.netarkivet.common.exceptions.IOFailure;
import dk.netarkivet.common.exceptions.PermissionDenied;
import dk.netarkivet.common.exceptions.UnknownID;
import dk.netarkivet.common.utils.FilterIterator;

/**
 * A database-oriented implementation of the HarvestDefinitionDAO.
 *
 * Statements to create the tables are in
 * scripts/sql/createfullhddb.sql
 *
 */

public class HarvestDefinitionDBDAO extends HarvestDefinitionDAO {
    private final Log log = LogFactory.getLog(getClass());

    /** Create a new HarvestDefinitionDAO using database.
     */
    HarvestDefinitionDBDAO() {
    	DBConnect.checkTableVersion("harvestdefinitions", 2);
        DBConnect.checkTableVersion("fullharvests", 2);
        DBConnect.checkTableVersion("partialharvests", 1);
        DBConnect.checkTableVersion("harvest_configs", 1);
    }

    /**
     * Create a harvest definition in Database.
     * The harvest definition object should not have its ID set
     * unless we are in the middle of migrating.
     *
     * @param harvestDefinition A new harvest definition to store in the database.
     * @return The harvestId for the just created harvest definition.
     * @see HarvestDefinitionDAO#create(HarvestDefinition)
     */
    public synchronized Long create(HarvestDefinition harvestDefinition) {
        Long id = harvestDefinition.getOid();
        if (id == null) {
            id = generateNextID();
        }

        Connection c = DBConnect.getDBConnection();
        PreparedStatement s = null;
        try {
            c.setAutoCommit(false);
            s = c.prepareStatement("INSERT INTO harvestdefinitions "
                    + "( harvest_id, name, comments, numevents, submitted,"
                    + "  isactive, edition ) "
{'fraction_non_alphanumeric': 0.08262548262548262, 'fraction_numerical': 0.008185328185328185, 'mean_word_length': 3.432580424366872, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1890068', 'n_tokens_mistral': 1803, 'n_tokens_neox': 1747, 'n_words': 596}