<commit_before>//This file is part of the OpenNMS(R) Application.
//
// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.
// OpenNMS(R) is a derivative work, containing both original code, included code and modified
// code that was published under the GNU General Public License. Copyrights for modified 
// and included code are below.
//
// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
//
// Modifications:
//
// 2008 Jan 27: Implement EventProcessor interface and make this class
//              and its subclasses thread safe. - <EMAIL>
// 2008 Jan 27: Push methods in Persist that are only used by a single
//              subclass into that subclass.
// 2008 Jan 26: Dependency injection using setter injection instead of
//              constructor injection and implement InitializingBean.
//              Move some common setters and initializion into Persist.
//              Implement log method. - <EMAIL>
// 2008 Jan 23: Use Java 5 generics, format code, wrap debug logs within an if
//              statement unless they are logging a plain String. - <EMAIL>
//
// Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.                                                            
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//       
// For more information contact: 
//      OpenNMS Licensing       <<EMAIL>>
//      http://www.opennms.org/
//      http://www.opennms.com/
//
package org.opennms.netmgt.eventd.processor;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.text.ParseException;

import javax.sql.DataSource;

import org.opennms.core.utils.ThreadCategory;
import org.opennms.netmgt.EventConstants;
import org.opennms.netmgt.eventd.EventdConstants;
import org.opennms.netmgt.eventd.EventdServiceManager;
import org.opennms.netmgt.xml.event.Event;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.Assert;

/**
 * EventWriter loads the information in each 'Event' into the database.
 *
 * While loading mutiple values of the same element into a single DB column, the
 * mutiple values are delimited by MULTIPLE_VAL_DELIM.
 *
 * When an element and its attribute are loaded into a single DB column, the
 * value and the attribute are separated by a DB_ATTRIB_DELIM.
 *
 * When using delimiters to append values, if the values already have the
 * delimiter, the delimiter in the value is escaped as in URLs.
 *
 * Values for the ' <parms>' block are loaded with each parm name and parm value
 * delimited with the NAME_VAL_DELIM.
 *
 * @see org.opennms.netmgt.model.events.Constants#MULTIPLE_VAL_DELIM
 * @see org.opennms.netmgt.model.events.Constants#DB_ATTRIB_DELIM
 * @see org.opennms.netmgt.model.events.Constants#NAME_VAL_DELIM
 * @see org.opennms.netmgt.model.events.Constants#MULTIPLE_VAL_DELIM
 * @see org.opennms.netmgt.model.events.Constants#DB_ATTRIB_DELIM
 * @see org.opennms.netmgt.model.events.Constants#NAME_VAL_DELIM
 * @see org.opennms.netmgt.model.events.Constants#MULTIPLE_VAL_DELIM
 * @see org.opennms.netmgt.model.events.Constants#DB_ATTRIB_DELIM
 * @see org.opennms.netmgt.model.events.Constants#NAME_VAL_DELIM
 * @author <A HREF="mailto:<EMAIL>"><NAME> </A>
 * @author <A HREF="http://www.opennms.org">OpenNMS.org </A>
 *
 * Changes:
 *
 * - Alarm persisting added (many moons ago)
 * - Alarm persisting now removes oldest events by default.  Use "auto-clean" attribute
 *   in eventconf files.
 * @author <NAME> </A>
 * @author <A HREF="mailto:<EMAIL>"><NAME> </A>
 * @author <A HREF="http://www.opennms.org">OpenNMS.org </A>
 *
 * Changes:
 *
 * - Alarm persisting added (many moons ago)
 * - Alarm persisting now removes oldest events by default.  Use "auto-clean" attribute
 *   in eventconf files.
 * @version $Id: $
 */
public abstract class AbstractJdbcPersister implements InitializingBean, EventProcessor {
    // Field sizes in the events table
    /** Constant <code>EVENT_UEI_FIELD_SIZE=256</code> */
    protected static final int EVENT_UEI_FIELD_SIZE = 256;

    /** Constant <code>EVENT_HOST_FIELD_SIZE=256</code> */
    protected static final int EVENT_HOST_FIELD_SIZE = 256;

    /** Constant <code>EVENT_INTERFACE_FIELD_SIZE=39</code> */
    protected static final int EVENT_INTERFACE_FIELD_SIZE = 39;

    /** Constant <code>EVENT_DPNAME_FIELD_SIZE=12</code> */
    protected static final int EVENT_DPNAME_FIELD_SIZE = 12;

    /** Constant <code>EVENT_SNMPHOST_FIELD_SIZE=256</code> */
    protected static final int EVENT_SNMPHOST_FIELD_SIZE = 256;

    /** Constant <code>EVENT_SNMP_FIELD_SIZE=256</code> */
    protected static final int EVENT_SNMP_FIELD_SIZE = 256;

    /** Constant <code>EVENT_LOGGRP_FIELD_SIZE=32</code> */
    protected static final int EVENT_LOGGRP_FIELD_SIZE = 32;

    /** Constant <code>EVENT_PATHOUTAGE_FIELD_SIZE=1024</code> */
    protected static final int EVENT_PATHOUTAGE_FIELD_SIZE = 1024;
<commit_msg>Expanded the ipaddr field in events out to 50 characters to accommodate IPv6 addresses with a 10-digit numeric scope indentifier. This will prevent events.ipaddr from being truncated in the database (which leads to UI exceptions).<commit_after>//This file is part of the OpenNMS(R) Application.
//
// OpenNMS(R) is Copyright (C) 2002-2003 The OpenNMS Group, Inc.  All rights reserved.
// OpenNMS(R) is a derivative work, containing both original code, included code and modified
// code that was published under the GNU General Public License. Copyrights for modified 
// and included code are below.
//
// OpenNMS(R) is a registered trademark of The OpenNMS Group, Inc.
//
// Modifications:
//
// 2008 Jan 27: Implement EventProcessor interface and make this class
//              and its subclasses thread safe. - <EMAIL>
// 2008 Jan 27: Push methods in Persist that are only used by a single
//              subclass into that subclass.
// 2008 Jan 26: Dependency injection using setter injection instead of
//              constructor injection and implement InitializingBean.
//              Move some common setters and initializion into Persist.
//              Implement log method. - <EMAIL>
// 2008 Jan 23: Use Java 5 generics, format code, wrap debug logs within an if
//              statement unless they are logging a plain String. - <EMAIL>
//
// Copyright (C) 1999-2001 Oculan Corp.  All rights reserved.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program 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 General Public License for more details.                                                            
//
// You should have received a copy of the GNU General Public License
// along with this program; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
//       
// For more information contact: 
//      OpenNMS Licensing       <<EMAIL>>
//      http://www.opennms.org/
//      http://www.opennms.com/
//
package org.opennms.netmgt.eventd.processor;

import java.sql.PreparedStatement;
import java.sql.SQLException;
import java.sql.Timestamp;
import java.sql.Types;
import java.text.ParseException;

import javax.sql.DataSource;

import org.opennms.core.utils.ThreadCategory;
import org.opennms.netmgt.EventConstants;
import org.opennms.netmgt.eventd.EventdConstants;
import org.opennms.netmgt.eventd.EventdServiceManager;
import org.opennms.netmgt.xml.event.Event;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.util.Assert;

/**
 * EventWriter loads the information in each 'Event' into the database.
 *
 * While loading mutiple values of the same element into a single DB column, the
 * mutiple values are delimited by MULTIPLE_VAL_DELIM.
 *
 * When an element and its attribute are loaded into a single DB column, the
 * value and the attribute are separated by a DB_ATTRIB_DELIM.
 *
 * When using delimiters to append values, if the values already have the
 * delimiter, the delimiter in the value is escaped as in URLs.
 *
 * Values for the ' <parms>' block are loaded with each parm name and parm value
 * delimited with the NAME_VAL_DELIM.
 *
 * @see org.opennms.netmgt.model.events.Constants#MULTIPLE_VAL_DELIM
 * @see org.opennms.netmgt.model.events.Constants#DB_ATTRIB_DELIM
 * @see org.opennms.netmgt.model.events.Constants#NAME_VAL_DELIM
 * @see org.opennms.netmgt.model.events.Constants#MULTIPLE_VAL_DELIM
 * @see org.opennms.netmgt.model.events.Constants#DB_ATTRIB_DELIM
 * @see org.opennms.netmgt.model.events.Constants#NAME_VAL_DELIM
 * @see org.opennms.netmgt.model.events.Constants#MULTIPLE_VAL_DELIM
 * @see org.opennms.netmgt.model.events.Constants#DB_ATTRIB_DELIM
 * @see org.opennms.netmgt.model.events.Constants#NAME_VAL_DELIM
 * @author <A HREF="mailto:<EMAIL>"><NAME> </A>
 * @author <A HREF="http://www.opennms.org">OpenNMS.org </A>
 *
 * Changes:
 *
 * - Alarm persisting added (many moons ago)
 * - Alarm persisting now removes oldest events by default.  Use "auto-clean" attribute
 *   in eventconf files.
 * @author <NAME> </A>
 * @author <A HREF="mailto:<EMAIL>"><NAME> </A>
 * @author <A HREF="http://www.opennms.org">OpenNMS.org </A>
 *
 * Changes:
 *
 * - Alarm persisting added (many moons ago)
 * - Alarm persisting now removes oldest events by default.  Use "auto-clean" attribute
 *   in eventconf files.
 * @version $Id: $
 */
public abstract class AbstractJdbcPersister implements InitializingBean, EventProcessor {
    // Field sizes in the events table
    /** Constant <code>EVENT_UEI_FIELD_SIZE=256</code> */
    protected static final int EVENT_UEI_FIELD_SIZE = 256;

    /** Constant <code>EVENT_HOST_FIELD_SIZE=256</code> */
    protected static final int EVENT_HOST_FIELD_SIZE = 256;

    /** 
     * Constant <code>EVENT_INTERFACE_FIELD_SIZE=50</code>.
     * This value must be long enough to accommodate an IPv6 address
     * with scope identifier suffix (if present). Basic IPv6 addresses
     * are 39 characters so this will accommodate a 10-digit scope
     * identifier (any 32-bit decimal value). 
     */
    protected static final int EVENT_INTERFACE_FIELD_SIZE = 50;

    /** Constant <code>EVENT_DPNAME_FIELD_SIZE=12</code> */
    protected static final int EVENT_DPNAME_FIELD_SIZE = 12;

    /** Constant <code>EVENT_SNMPHOST_FIELD_SIZE=256</code> */
    protected static final int EVENT_SNMPHOST_FIELD_SIZE = 256;

    /** Constant <code>EVENT_SNMP_FIELD_SIZE=256</code> */
    protected static final int EVENT_SNMP_FIELD_SIZE = 256;

    /** Constant <code>EVENT_LOGGRP_FIELD_SIZE=32</code> */
    protected static final int EVENT_LOGGRP_FIELD_SIZE = 32;

    /** Constant <code>EVENT_PATHOUTAGE_FIELD_SIZE=1024</code> */
    protected static final int EVENT_PATHOUTAGE_FIELD_SIZE = 1024;

{'fraction_non_alphanumeric': 0.09548625703958981, 'fraction_numerical': 0.01790367319492309, 'mean_word_length': 3.544690603514133, 'pattern_counts': {'":': 0, '<': 75, '<?xml version=': 0, '>': 75, 'https://': 0, 'lorem ipsum': 0, 'www.': 8, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6350970', 'n_tokens_mistral': 3748, 'n_tokens_neox': 3480, 'n_words': 1187}