OW2 Consortium elastic-grid

Rev

Rev 456 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 456 Rev 530
1
/**
1
/**
2
 * Elastic Grid
2
 * Elastic Grid
3
 * Copyright (C) 2008-2009 Elastic Grid, LLC.
-
 
4
 * 
-
 
-
 
3
 * Copyright (C) 2008-2010 Elastic Grid, LLC.
-
 
4
 *
5
 * This program is free software: you can redistribute it and/or modify
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
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
7
 * published by the Free Software Foundation, either version 3 of the
8
 * License, or (at your option) any later version.
8
 * License, or (at your option) any later version.
9
 * 
-
 
-
 
9
 *
10
 * This program is distributed in the hope that it will be useful,
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU Affero General Public License for more details.
13
 * GNU Affero General Public License for more details.
14
 * 
-
 
-
 
14
 *
15
 * You should have received a copy of the GNU Affero General Public License
15
 * You should have received a copy of the GNU Affero General Public License
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
16
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
17
 */
17
 */
18

-
 
19
package com.elasticgrid.amazon.sdb.impl;
18
package com.elasticgrid.amazon.sdb.impl;
20

19

21
import com.elasticgrid.amazon.sdb.SimpleDB;
20
import com.elasticgrid.amazon.sdb.SimpleDB;
22
import com.elasticgrid.amazon.sdb.Domain;
21
import com.elasticgrid.amazon.sdb.Domain;
23
import com.elasticgrid.amazon.sdb.SimpleDBException;
22
import com.elasticgrid.amazon.sdb.SimpleDBException;
24
import com.xerox.amazonws.sdb.SDBException;
23
import com.xerox.amazonws.sdb.SDBException;
25
import com.xerox.amazonws.sdb.ListDomainsResult;
24
import com.xerox.amazonws.sdb.ListDomainsResult;
26
import org.springframework.beans.factory.InitializingBean;
25
import org.springframework.beans.factory.InitializingBean;
27
import java.util.logging.Logger;
26
import java.util.logging.Logger;
28
import java.util.logging.Level;
27
import java.util.logging.Level;
29
import java.util.List;
28
import java.util.List;
30
import java.util.ArrayList;
29
import java.util.ArrayList;
31

30

32
public class SimpleDBImpl implements SimpleDB, InitializingBean {
31
public class SimpleDBImpl implements SimpleDB, InitializingBean {
33
    private com.xerox.amazonws.sdb.SimpleDB sdb;
32
    private com.xerox.amazonws.sdb.SimpleDB sdb;
34
    private String awsAccessID, awsSecretKey;
33
    private String awsAccessID, awsSecretKey;
35
    private static final Logger logger = Logger.getLogger(SimpleDB.class.getName());
34
    private static final Logger logger = Logger.getLogger(SimpleDB.class.getName());
36

35

37
    public Domain createDomain(String name) throws SimpleDBException {
36
    public Domain createDomain(String name) throws SimpleDBException {
38
        try {
37
        try {
39
            logger.log(Level.INFO, "Creating domain {0}", name);
38
            logger.log(Level.INFO, "Creating domain {0}", name);
40
            return new DomainImpl(sdb.createDomain(name));
39
            return new DomainImpl(sdb.createDomain(name));
41
        } catch (SDBException e) {
40
        } catch (SDBException e) {
42
            throw new SimpleDBException("Can't create domain " + name, e);
41
            throw new SimpleDBException("Can't create domain " + name, e);
43
        }
42
        }
44
    }
43
    }
45

44

46
    public void deleteDomain(String name) throws SimpleDBException {
45
    public void deleteDomain(String name) throws SimpleDBException {
47
        try {
46
        try {
48
            logger.log(Level.INFO, "Deleting domain {0}", name);
47
            logger.log(Level.INFO, "Deleting domain {0}", name);
49
            sdb.deleteDomain(name);
48
            sdb.deleteDomain(name);
50
        } catch (SDBException e) {
49
        } catch (SDBException e) {
51
            throw new SimpleDBException("Can't delete domain " + name, e);
50
            throw new SimpleDBException("Can't delete domain " + name, e);
52
        }
51
        }
53
    }
52
    }
54

53

55
    public Domain findDomain(String name) throws SimpleDBException {
54
    public Domain findDomain(String name) throws SimpleDBException {
56
        try {
55
        try {
57
            logger.log(Level.INFO, "Searching for domain {0}", name);
56
            logger.log(Level.INFO, "Searching for domain {0}", name);
58
            return new DomainImpl(sdb.getDomain(name));
57
            return new DomainImpl(sdb.getDomain(name));
59
        } catch (SDBException e) {
58
        } catch (SDBException e) {
60
            throw new SimpleDBException("Can't find domain " + name, e);
59
            throw new SimpleDBException("Can't find domain " + name, e);
61
        }
60
        }
62
    }
61
    }
63

62

64
    public List<Domain> listDomains() throws SimpleDBException {
63
    public List<Domain> listDomains() throws SimpleDBException {
65
        try {
64
        try {
66
            logger.info("Searching for all domains");
65
            logger.info("Searching for all domains");
67
            ListDomainsResult raw = sdb.listDomains();
66
            ListDomainsResult raw = sdb.listDomains();
68
            List<Domain> domains = new ArrayList<Domain>(raw.getDomainList().size());
67
            List<Domain> domains = new ArrayList<Domain>(raw.getDomainList().size());
69
            for (com.xerox.amazonws.sdb.Domain domain : raw.getDomainList()) {
68
            for (com.xerox.amazonws.sdb.Domain domain : raw.getDomainList()) {
70
                domains.add(new DomainImpl(domain));
69
                domains.add(new DomainImpl(domain));
71
            }
70
            }
72
            logger.log(Level.INFO, "Found {0} domain(s)", domains.size());
71
            logger.log(Level.INFO, "Found {0} domain(s)", domains.size());
73
            return domains;
72
            return domains;
74
        } catch (SDBException e) {
73
        } catch (SDBException e) {
75
            throw new SimpleDBException("Can't list domains", e);
74
            throw new SimpleDBException("Can't list domains", e);
76
        }
75
        }
77
    }
76
    }
78

77

79
    public void setAwsAccessID(String awsAccessID) {
78
    public void setAwsAccessID(String awsAccessID) {
80
        this.awsAccessID = awsAccessID;
79
        this.awsAccessID = awsAccessID;
81
    }
80
    }
82

81

83
    public void setAwsSecretKey(String awsSecretKey) {
82
    public void setAwsSecretKey(String awsSecretKey) {
84
        this.awsSecretKey = awsSecretKey;
83
        this.awsSecretKey = awsSecretKey;
85
    }
84
    }
86

85

87
    public void afterPropertiesSet() throws Exception {
86
    public void afterPropertiesSet() throws Exception {
88
        sdb = new com.xerox.amazonws.sdb.SimpleDB(awsAccessID, awsSecretKey);
87
        sdb = new com.xerox.amazonws.sdb.SimpleDB(awsAccessID, awsSecretKey);
89
    }
88
    }
90
}
89
}