OW2 Consortium elastic-grid

Rev

Rev 456 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
45 jeje 1
/**
456 jeje 2
 * Elastic Grid
530 jeje 3
 * Copyright (C) 2008-2010 Elastic Grid, LLC.
4
 *
456 jeje 5
 * This program is free software: you can redistribute it and/or modify
6
 * it under the terms of the GNU Affero General Public License as
7
 * published by the Free Software Foundation, either version 3 of the
8
 * License, or (at your option) any later version.
530 jeje 9
 *
456 jeje 10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
530 jeje 14
 *
456 jeje 15
 * You should have received a copy of the GNU Affero General Public License
182 jeje 16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
45 jeje 17
 */
18
package com.elasticgrid.amazon.sdb.impl;
19
 
20
import com.elasticgrid.amazon.sdb.SimpleDB;
21
import com.elasticgrid.amazon.sdb.Domain;
22
import com.elasticgrid.amazon.sdb.SimpleDBException;
23
import com.xerox.amazonws.sdb.SDBException;
24
import com.xerox.amazonws.sdb.ListDomainsResult;
25
import org.springframework.beans.factory.InitializingBean;
26
import java.util.logging.Logger;
27
import java.util.logging.Level;
28
import java.util.List;
29
import java.util.ArrayList;
30
 
31
public class SimpleDBImpl implements SimpleDB, InitializingBean {
32
    private com.xerox.amazonws.sdb.SimpleDB sdb;
33
    private String awsAccessID, awsSecretKey;
34
    private static final Logger logger = Logger.getLogger(SimpleDB.class.getName());
35
 
36
    public Domain createDomain(String name) throws SimpleDBException {
37
        try {
38
            logger.log(Level.INFO, "Creating domain {0}", name);
39
            return new DomainImpl(sdb.createDomain(name));
40
        } catch (SDBException e) {
41
            throw new SimpleDBException("Can't create domain " + name, e);
42
        }
43
    }
44
 
45
    public void deleteDomain(String name) throws SimpleDBException {
46
        try {
47
            logger.log(Level.INFO, "Deleting domain {0}", name);
48
            sdb.deleteDomain(name);
49
        } catch (SDBException e) {
50
            throw new SimpleDBException("Can't delete domain " + name, e);
51
        }
52
    }
53
 
54
    public Domain findDomain(String name) throws SimpleDBException {
55
        try {
56
            logger.log(Level.INFO, "Searching for domain {0}", name);
57
            return new DomainImpl(sdb.getDomain(name));
58
        } catch (SDBException e) {
59
            throw new SimpleDBException("Can't find domain " + name, e);
60
        }
61
    }
62
 
63
    public List<Domain> listDomains() throws SimpleDBException {
64
        try {
65
            logger.info("Searching for all domains");
66
            ListDomainsResult raw = sdb.listDomains();
67
            List<Domain> domains = new ArrayList<Domain>(raw.getDomainList().size());
68
            for (com.xerox.amazonws.sdb.Domain domain : raw.getDomainList()) {
69
                domains.add(new DomainImpl(domain));
70
            }
71
            logger.log(Level.INFO, "Found {0} domain(s)", domains.size());
72
            return domains;
73
        } catch (SDBException e) {
74
            throw new SimpleDBException("Can't list domains", e);
75
        }
76
    }
77
 
78
    public void setAwsAccessID(String awsAccessID) {
79
        this.awsAccessID = awsAccessID;
80
    }
81
 
82
    public void setAwsSecretKey(String awsSecretKey) {
83
        this.awsSecretKey = awsSecretKey;
84
    }
85
 
86
    public void afterPropertiesSet() throws Exception {
87
        sdb = new com.xerox.amazonws.sdb.SimpleDB(awsAccessID, awsSecretKey);
88
    }
89
}