<commit_before>/*
 * Copyright 2004-2009 the original author or authors.
 * 
 * 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 org.compass.gps.device.jdbc;

import java.lang.reflect.Array;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.compass.core.CompassException;
import org.compass.core.CompassSession;
import org.compass.gps.CompassGpsException;
import org.compass.gps.device.AbstractGpsDevice;
import org.compass.gps.device.jdbc.dialect.DialectResolver;
import org.compass.gps.device.jdbc.dialect.JdbcDialect;

/**
 * A helper base class for Jdbc Gps Device. Provides supprot for
 * <code>DataSource</code> and
 * {@link org.compass.gps.device.jdbc.dialect.JdbcDialect}. Also
 * provides template like support for processing database indexing using the
 * <code>IndexExecution</code> object hint, and a set of callback methods:
 * {@link #processResultSet(Object, ResultSet, CompassSession)},
 * {@link #processRow(Object, ResultSet, CompassSession)}, and
 * {@link #processRowValue(Object, ResultSet, CompassSession)}. One of the
 * callback mehtods should be overriden by the derived class otherwize the class
 * won't index anyhting.
 *
 * @author kimchy
 */
public abstract class AbstractJdbcGpsDevice extends AbstractGpsDevice implements JdbcGpsDevice {

    protected Log log = LogFactory.getLog(getClass());

    /**
     * A hint object which provides the statement query to execute or the actual
     * <code>PreparedStatement</code>. It also provides a general data holder
     * called <code>description</code>.
     *
     * @author kimchy
     */
    public static class IndexExecution {
        private Object description;

        private PreparedStatement statement;

        private String statementQuery;

        public IndexExecution(Object description) {
            this.description = description;
        }

        public IndexExecution(Object description, String statementQuery) {
            this.description = description;
            this.statementQuery = statementQuery;
        }

        public IndexExecution(Object description, PreparedStatement statement) {
            this.description = description;
            this.statement = statement;
        }

        public Object getDescription() {
            return description;
        }

        public PreparedStatement getStatement() {
            return statement;
        }

        public String getStatementQuery() {
            return statementQuery;
        }

        public void setStatementQuery(String statementQuery) {
            this.statementQuery = statementQuery;
        }

        public void setStatement(PreparedStatement statement) {
            this.statement = statement;
        }

        public void setDescription(Object description) {
            this.description = description;
        }
    }

    protected DataSource dataSource;

    protected JdbcDialect dialect;

    protected void doStart() throws CompassGpsException {
        if (dataSource == null) {
            throw new IllegalArgumentException("dataSource property must be set");
        }

        try {
            this.dialect = new DialectResolver(true).getDialect(dataSource);
        } catch (Exception e) {
            log.warn("Failed to detect database dialect", e);
            throw new JdbcGpsDeviceException("Failed to detect database dialect", e);
        }
    }<commit_msg>CMP-879<commit_after>/*
 * Copyright 2004-2009 the original author or authors.
 * 
 * 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 org.compass.gps.device.jdbc;

import java.lang.reflect.Array;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import javax.sql.DataSource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.compass.core.CompassException;
import org.compass.core.CompassSession;
import org.compass.gps.CompassGpsException;
import org.compass.gps.device.AbstractGpsDevice;
import org.compass.gps.device.jdbc.dialect.DialectResolver;
import org.compass.gps.device.jdbc.dialect.JdbcDialect;

/**
 * A helper base class for Jdbc Gps Device. Provides supprot for
 * <code>DataSource</code> and
 * {@link org.compass.gps.device.jdbc.dialect.JdbcDialect}. Also
 * provides template like support for processing database indexing using the
 * <code>IndexExecution</code> object hint, and a set of callback methods:
 * {@link #processResultSet(Object, ResultSet, CompassSession)},
 * {@link #processRow(Object, ResultSet, CompassSession)}, and
 * {@link #processRowValue(Object, ResultSet, CompassSession)}. One of the
 * callback mehtods should be overriden by the derived class otherwize the class
 * won't index anyhting.
 *
 * @author kimchy
 */
public abstract class AbstractJdbcGpsDevice extends AbstractGpsDevice implements JdbcGpsDevice {

    protected Log log = LogFactory.getLog(getClass());

    /**
     * A hint object which provides the statement query to execute or the actual
     * <code>PreparedStatement</code>. It also provides a general data holder
     * called <code>description</code>.
     *
     * @author kimchy
     */
    public static class IndexExecution {
        private Object description;

        private PreparedStatement statement;

        private String statementQuery;

        public IndexExecution(Object description) {
            this.description = description;
        }

        public IndexExecution(Object description, String statementQuery) {
            this.description = description;
            this.statementQuery = statementQuery;
        }

        public IndexExecution(Object description, PreparedStatement statement) {
            this.description = description;
            this.statement = statement;
        }

        public Object getDescription() {
            return description;
        }

        public PreparedStatement getStatement() {
            return statement;
        }

        public String getStatementQuery() {
            return statementQuery;
        }

        public void setStatementQuery(String statementQuery) {
            this.statementQuery = statementQuery;
        }

        public void setStatement(PreparedStatement statement) {
            this.statement = statement;
        }

        public void setDescription(Object description) {
            this.description = description;
        }
    }

    protected DataSource dataSource;

    protected JdbcDialect dialect;

    protected void doStart() throws CompassGpsException {
        if (dataSource == null) {
            throw new IllegalArgumentException("dataSource property must be set");
        }

        if (dialect == null) {
            try {
                this.dialect = new DialectResolver(true).getDialect(dataSource);
            } catch (Exception e) {
                log.warn("Failed to detect database dialect", e);
                throw new JdbcGpsDeviceException("Failed to detect database dialect", e);
            }
        }
    }
{'fraction_non_alphanumeric': 0.07992722862340812, 'fraction_numerical': 0.003274711946634324, 'mean_word_length': 2.9874274661508706, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '7060030', 'n_tokens_mistral': 2129, 'n_tokens_neox': 2041, 'n_words': 667}