com.sfs.dao.BaseDAOImpl.java Source code

Java tutorial

Introduction

Here is the source code for com.sfs.dao.BaseDAOImpl.java

Source

/*******************************************************************************
 * Copyright (c) 2009 David Harrison.
 * All rights reserved. This program and the accompanying materials
 * are made available under the terms of the GNU Public License v3.0
 * which accompanies this distribution, and is available at
 * http://www.gnu.org/licenses/gpl-3.0.html
 *
 * Contributors:
 *     David Harrison - initial API and implementation
 ******************************************************************************/
package com.sfs.dao;

import com.sfs.beans.SQLBean;

import javax.annotation.Resource;
import javax.sql.DataSource;

import org.springframework.jdbc.core.JdbcTemplate;

/**
 * The Class BaseDAOImpl.
 *
 * @author David Harrison
 */
public class BaseDAOImpl {

    /** The sql. */
    private SQLBean sql;

    /** The data source. */
    @Resource
    private DataSource dataSource;

    /** The data source writer. */
    @Resource
    private DataSource dataSourceWriter;

    /**
     * Instantiates a new base dao impl.
     */
    public BaseDAOImpl() {
        this.sql = new SQLBean("com.sfs.sql");
    }

    /**
     * Sets the data source.
     *
     * @param dataSourceRef the new data source
     */
    public final void setDataSource(final DataSource dataSourceRef) {
        this.dataSource = dataSourceRef;
    }

    /**
     * Sets the data source writer.
     *
     * @param dataSourceWriterRef the new data source writer
     */
    public final void setDataSourceWriter(final DataSource dataSourceWriterRef) {
        this.dataSourceWriter = dataSourceWriterRef;
    }

    /**
     * Gets the jdbc template reader.
     *
     * @return the jdbc template reader
     */
    protected final JdbcTemplate getJdbcTemplateReader() {
        return new JdbcTemplate(dataSource);
    }

    /**
     * Gets the jdbc template writer.
     *
     * @return the jdbc template writer
     */
    protected final JdbcTemplate getJdbcTemplateWriter() {
        return new JdbcTemplate(dataSourceWriter);
    }

    /**
     * Gets the sQL.
     *
     * @return the sQL
     */
    protected final SQLBean getSQL() {
        return sql;
    }
}