001/*
002 * Copyright 2011 Atteo.
003 *
004 * Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except
005 * in compliance with the License. You may obtain a copy of the License at
006 *
007 * http://www.apache.org/licenses/LICENSE-2.0
008 *
009 * Unless required by applicable law or agreed to in writing, software distributed under the License
010 * is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express
011 * or implied. See the License for the specific language governing permissions and limitations under
012 * the License.
013 */
014package org.atteo.moonshine.jta;
015
016import javax.annotation.Nullable;
017import javax.sql.DataSource;
018import javax.sql.XADataSource;
019
020/**
021 * Wraps {@link XADataSource} into {@link DataSource} adding transaction support.
022 */
023public interface JtaDataSourceWrapper {
024    /**
025     * Wrap given {@link XADataSource} into {@link DataSource} adding transaction support.
026     * @param name unique name for the returned {@link DataSource}
027     * @param xaDataSource {@link XADataSource} to wrap
028     * @param poolOptions options for the connection pool
029     * @param testQuery SQL query or statement used to validate a connection before returning it
030     * @return wrapped {@link DataSource}
031     */
032    DataSource wrap(String name, XADataSource xaDataSource, @Nullable PoolOptions poolOptions, String testQuery);
033
034    /**
035     * Close previously wrapped data source.
036     * @param dataSource data source to close
037     */
038    void close(DataSource dataSource);
039}