View Javadoc

1   /*
2    * Copyright 2012-2013 smartics, Kronseder & Reiner GmbH
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *     http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   */
16  package de.smartics.properties.impl.config.ds.mysql;
17  
18  import javax.sql.DataSource;
19  
20  import de.smartics.properties.spi.config.ds.JndiDataSourceProxy;
21  import de.smartics.util.lang.Arg;
22  
23  /**
24   * Implementation based on a JNDI data source.
25   */
26  public final class MySqlJndiDataSourceProxy extends
27      AbstractMySqlDataSourceProxy
28  {
29    // ********************************* Fields *********************************
30  
31    // --- constants ------------------------------------------------------------
32  
33    /**
34     * The class version identifier.
35     */
36    private static final long serialVersionUID = 1L;
37  
38    // --- members --------------------------------------------------------------
39  
40    /**
41     * The data source proxy.
42     *
43     * @serial
44     */
45    private final JndiDataSourceProxy dataSource;
46  
47    // ****************************** Initializer *******************************
48  
49    // ****************************** Constructors ******************************
50  
51    /**
52     * Default constructor.
53     *
54     * @param dataSource the data source proxy.
55     * @throws NullPointerException if {@code dataSource} is <code>null</code>.
56     */
57    public MySqlJndiDataSourceProxy(final JndiDataSourceProxy dataSource)
58      throws NullPointerException
59    {
60      this.dataSource = Arg.checkNotNull("dataSource", dataSource);
61    }
62  
63    // ****************************** Inner Classes *****************************
64  
65    // ********************************* Methods ********************************
66  
67    // --- init -----------------------------------------------------------------
68  
69    // --- get&set --------------------------------------------------------------
70  
71    @Override
72    public String getDataSourceId()
73    {
74      return dataSource.getDataSourceId();
75    }
76  
77    @Override
78    public DataSource getDataSource()
79    {
80      return dataSource.getDataSource();
81    }
82  
83    // --- business -------------------------------------------------------------
84  
85    // --- object basics --------------------------------------------------------
86  
87    @Override
88    public String toString()
89    {
90      return "(MySQL) " + dataSource.toString();
91    }
92  }