<commit_before>// Copyright (c) 2006 ScenPro, Inc.

// $Header: /share/content/gforge/freestylesearch/freestylesearch/src/gov/nih/nci/cadsr/freestylesearch/util/Seed.java,v 1.8 2007-12-17 18:20:30 hebell Exp $
// $Name: not supported by cvs2svn $

package gov.nih.nci.cadsr.freestylesearch.util;

import gov.nih.nci.cadsr.freestylesearch.tool.DBAccess;
import gov.nih.nci.cadsr.freestylesearch.tool.DBAccessIndex;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

/**
 * Seed the freestyle search index tables. The caDSR is scanned for updates using the record date_modified
 * and comparing to the last seed timestamp. Updated records are used to refresh the index tables.
 * 
 * @author lhebel Mar 3, 2006
 */
public class Seed
{
    /**
     * Constructor
     *
     */
    public Seed()
    {
    }
    
    /**
     * Main entry when started from a command line.
     * 
     * @param args_ no valid arguments at this time.
     */
    public static void main(String[] args_)
    {
        long millis = System.currentTimeMillis();

        DOMConfigurator.configure(args_[0]);
        
        Seed var = new Seed();

        Properties prop = new Properties();
        FileInputStream ins = null;
        try
        {
            ins = new FileInputStream(args_[1]);
            prop.loadFromXML(ins);
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
            return;
        }
        catch (InvalidPropertiesFormatException e)
        {
            e.printStackTrace();
            return;
        }
        catch (IOException e)
        {
            e.printStackTrace();
            return;
        }
        finally
        {
            if (ins != null)
            {
                try
                {
                    ins.close();
                }
                catch (Exception ex)
                {
                }
            }
        }
        
        String version = Search.getVersion();
        
        var._dbIndex = prop.getProperty("index.DSurl");
        var._userIndex = prop.getProperty("index.DSusername");
        var._pswdIndex = prop.getProperty("index.DSpassword");
        var._dbData = prop.getProperty("data.DSurl");
        var._userData = prop.getProperty("data.DSusername");
        var._pswdData = prop.getProperty("data.DSpassword");
        
        String schema = prop.getProperty("index.DSschema");
        DBAccessIndex.setSchema(schema);
        
        _logger.info(" ");
        _logger.info("---------------------------------------------------------------------------------");
        _logger.info("Seed " + version + " started for schema... " + schema.toUpperCase());

        try
        {
            var.parseDatabase(millis);
        }
        catch (Exception ex)
        {
            _logger.error(ex.toString());
        }

        _logger.info("Seed ended ...");
    }
    
    /**
     * Set the DataSource holding the connections.
     * 
     * @param ds_ the DataSource<commit_msg>add more error logging<commit_after>// Copyright (c) 2006 ScenPro, Inc.

// $Header: /share/content/gforge/freestylesearch/freestylesearch/src/gov/nih/nci/cadsr/freestylesearch/util/Seed.java,v 1.9 2008-05-28 19:01:20 hebell Exp $
// $Name: not supported by cvs2svn $

package gov.nih.nci.cadsr.freestylesearch.util;

import gov.nih.nci.cadsr.freestylesearch.tool.DBAccess;
import gov.nih.nci.cadsr.freestylesearch.tool.DBAccessIndex;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.sql.Timestamp;
import java.util.Enumeration;
import java.util.InvalidPropertiesFormatException;
import java.util.Properties;
import javax.sql.DataSource;
import org.apache.log4j.Logger;
import org.apache.log4j.xml.DOMConfigurator;

/**
 * Seed the freestyle search index tables. The caDSR is scanned for updates using the record date_modified
 * and comparing to the last seed timestamp. Updated records are used to refresh the index tables.
 * 
 * @author lhebel <NAME>, 2006
 */
public class Seed
{
    /**
     * Constructor
     *
     */
    public Seed()
    {
    }
    
    /**
     * Main entry when started from a command line.
     * 
     * @param args_ no valid arguments at this time.
     */
    public static void main(String[] args_)
    {
        long millis = System.currentTimeMillis();

        DOMConfigurator.configure(args_[0]);
        
        Seed var = new Seed();

        Properties prop = new Properties();
        FileInputStream ins = null;
        try
        {
            ins = new FileInputStream(args_[1]);
            prop.loadFromXML(ins);
        }
        catch (FileNotFoundException e)
        {
            e.printStackTrace();
            return;
        }
        catch (InvalidPropertiesFormatException e)
        {
            e.printStackTrace();
            return;
        }
        catch (IOException e)
        {
            e.printStackTrace();
            return;
        }
        finally
        {
            if (ins != null)
            {
                try
                {
                    ins.close();
                }
                catch (Exception ex)
                {
                }
            }
        }
        
        String version = Search.getVersion();
        
        var._dbIndex = prop.getProperty("index.DSurl");
        var._userIndex = prop.getProperty("index.DSusername");
        var._pswdIndex = prop.getProperty("index.DSpassword");
        var._dbData = prop.getProperty("data.DSurl");
        var._userData = prop.getProperty("data.DSusername");
        var._pswdData = prop.getProperty("data.DSpassword");
        
        String schema = prop.getProperty("index.DSschema");
        DBAccessIndex.setSchema(schema);
        
        _logger.info(" ");
        _logger.info("---------------------------------------------------------------------------------");
        _logger.info("Seed " + version + " started for schema... " + schema.toUpperCase());

        try
        {
            var.parseDatabase(millis);
        }
        catch (Exception ex)
        {
            _logger.error(ex.toString());
            Enumeration loop = prop.propertyNames();
            while (loop.hasMoreElements())
            {
                String key = (String) loop.nextElement();
                _logger.error("Property " + key + " = " + prop.getProperty(key));
            }
        }

        _logger.info("Seed ended ...");
    }
    
    /**
     * Set the DataSource holding the connections.
     * 
     * @param ds_ the DataSource
{'fraction_non_alphanumeric': 0.12985685071574643, 'fraction_numerical': 0.008618171194858311, 'mean_word_length': 1.7138327388030123, 'pattern_counts': {'":': 0, '<': 4, '<?xml version=': 0, '>': 4, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, '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': '3744584', 'n_tokens_mistral': 1933, 'n_tokens_neox': 1873, 'n_words': 405}