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; 019 020import javax.sql.DataSource; 021import javax.xml.bind.annotation.XmlElement; 022import javax.xml.bind.annotation.XmlRootElement; 023import javax.xml.bind.annotation.XmlType; 024 025/** 026 * @author Paul Ferraro 027 * 028 */ 029@XmlRootElement(name = "ha-jdbc") 030@XmlType(name = "databaseClusterConfiguration") 031public class DataSourceDatabaseClusterConfiguration extends AbstractDatabaseClusterConfiguration<DataSource, DataSourceDatabase> 032{ 033 private static final long serialVersionUID = -2213490659407620585L; 034 035 @XmlElement(name = "cluster", required = true) 036 private DataSourceNestedConfiguration configuration = new DataSourceNestedConfiguration(); 037 038 @Override 039 protected AbstractDatabaseClusterConfiguration.NestedConfiguration<DataSource, DataSourceDatabase> getNestedConfiguration() 040 { 041 return this.configuration; 042 } 043 044 @XmlType(name = "nestedConfiguration") 045 static class DataSourceNestedConfiguration extends AbstractDatabaseClusterConfiguration.NestedConfiguration<DataSource, DataSourceDatabase> 046 { 047 private static final long serialVersionUID = -5155160003090960720L; 048 049 @XmlElement(name = "database") 050 private DataSourceDatabase[] getDatabases() 051 { 052 return this.getDatabaseMap().values().toArray(new DataSourceDatabase[this.getDatabaseMap().size()]); 053 } 054 055 @SuppressWarnings("unused") 056 private void setDatabases(DataSourceDatabase[] databases) 057 { 058 for (DataSourceDatabase database: databases) 059 { 060 this.getDatabaseMap().put(database.getId(), database); 061 } 062 } 063 064 @Override 065 public DataSourceDatabase createDatabase(String id) 066 { 067 DataSourceDatabase database = new DataSourceDatabase(); 068 database.setId(id); 069 return database; 070 } 071 } 072}