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