001/* 002 * HA-JDBC: High-Availability JDBC 003 * Copyright (C) 2012 Paul Ferraro 004 * 005 * This program is free software: you can redistribute it and/or modify 006 * it under the terms of the GNU Lesser General Public License as published by 007 * the Free Software Foundation, either version 3 of the License, or 008 * (at your option) any later version. 009 * 010 * This program is distributed in the hope that it will be useful, 011 * but WITHOUT ANY WARRANTY; without even the implied warranty of 012 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 013 * GNU Lesser General Public License for more details. 014 * 015 * You should have received a copy of the GNU Lesser General Public License 016 * along with this program. If not, see <http://www.gnu.org/licenses/>. 017 */ 018package net.sf.hajdbc.sql.pool; 019 020import javax.sql.ConnectionPoolDataSource; 021import javax.xml.bind.annotation.XmlElement; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlType; 024 025import net.sf.hajdbc.sql.AbstractDatabaseClusterConfiguration; 026 027/** 028 * @author Paul Ferraro 029 */ 030@XmlRootElement(name = "ha-jdbc") 031@XmlType(name = "databaseClusterConfiguration") 032public class ConnectionPoolDataSourceDatabaseClusterConfiguration extends AbstractDatabaseClusterConfiguration<ConnectionPoolDataSource, ConnectionPoolDataSourceDatabase> 033{ 034 private static final long serialVersionUID = 6137340553506862286L; 035 036 @XmlElement(name = "cluster", required = true) 037 private ConnectionPoolDataSourceNestedConfiguration configuration = new ConnectionPoolDataSourceNestedConfiguration(); 038 039 @Override 040 protected AbstractDatabaseClusterConfiguration.NestedConfiguration<ConnectionPoolDataSource, ConnectionPoolDataSourceDatabase> getNestedConfiguration() 041 { 042 return this.configuration; 043 } 044 045 @XmlType(name = "nestedConfiguration") 046 static class ConnectionPoolDataSourceNestedConfiguration extends AbstractDatabaseClusterConfiguration.NestedConfiguration<ConnectionPoolDataSource, ConnectionPoolDataSourceDatabase> 047 { 048 private static final long serialVersionUID = 3139842065941633881L; 049 050 @XmlElement(name = "database") 051 private ConnectionPoolDataSourceDatabase[] getDatabases() 052 { 053 return this.getDatabaseMap().values().toArray(new ConnectionPoolDataSourceDatabase[this.getDatabaseMap().size()]); 054 } 055 056 @SuppressWarnings("unused") 057 private void setDatabases(ConnectionPoolDataSourceDatabase[] databases) 058 { 059 for (ConnectionPoolDataSourceDatabase database: databases) 060 { 061 this.getDatabaseMap().put(database.getId(), database); 062 } 063 } 064 065 @Override 066 public ConnectionPoolDataSourceDatabase createDatabase(String id) 067 { 068 ConnectionPoolDataSourceDatabase database = new ConnectionPoolDataSourceDatabase(); 069 database.setId(id); 070 return database; 071 } 072 } 073}