Search in sources :

Example 1 with NoSuchDomainException

use of com.amazonaws.services.simpledb.model.NoSuchDomainException in project camel by apache.

the class SdbEndpoint method doStart.

@Override
public void doStart() throws Exception {
    super.doStart();
    sdbClient = configuration.getAmazonSDBClient() != null ? configuration.getAmazonSDBClient() : createSdbClient();
    if (ObjectHelper.isNotEmpty(configuration.getAmazonSdbEndpoint())) {
        sdbClient.setEndpoint(configuration.getAmazonSdbEndpoint());
    }
    String domainName = getConfiguration().getDomainName();
    LOG.trace("Querying whether domain [{}] already exists...", domainName);
    try {
        sdbClient.domainMetadata(new DomainMetadataRequest(domainName));
        LOG.trace("Domain [{}] already exists", domainName);
        return;
    } catch (NoSuchDomainException ase) {
        LOG.trace("Domain [{}] doesn't exist yet", domainName);
        LOG.trace("Creating domain [{}]...", domainName);
        sdbClient.createDomain(new CreateDomainRequest(domainName));
        LOG.trace("Domain [{}] created", domainName);
    }
}
Also used : DomainMetadataRequest(com.amazonaws.services.simpledb.model.DomainMetadataRequest) CreateDomainRequest(com.amazonaws.services.simpledb.model.CreateDomainRequest) NoSuchDomainException(com.amazonaws.services.simpledb.model.NoSuchDomainException)

Example 2 with NoSuchDomainException

use of com.amazonaws.services.simpledb.model.NoSuchDomainException in project simplejpa by appoxy.

the class AbstractQuery method getResultList.

public List getResultList() {
    // convert to amazon query
    AmazonQueryString amazonQuery;
    try {
        amazonQuery = createAmazonQuery();
    } catch (RuntimeException e) {
        throw e;
    } catch (Exception e) {
        throw new RuntimeException(e);
    }
    if (amazonQuery == null) {
        return new ArrayList();
    }
    try {
        // String qToSend = amazonQuery != null ? amazonQuery.toString() : null;
        em.incrementQueryCount();
        if (amazonQuery.isCount()) {
            // String domainName = em.getDomainName(tClass);
            String nextToken = null;
            SelectResult qr;
            long count = 0;
            while ((qr = DomainHelper.selectItems(this.em.getSimpleDb(), amazonQuery.getValue(), nextToken)) != null) {
                Map<String, List<Attribute>> itemMap = new HashMap<String, List<Attribute>>();
                for (Item item : qr.getItems()) {
                    itemMap.put(item.getName(), item.getAttributes());
                }
                for (String id : itemMap.keySet()) {
                    List<Attribute> list = itemMap.get(id);
                    for (Attribute itemAttribute : list) {
                        if (itemAttribute.getName().equals("Count")) {
                            count += Long.parseLong(itemAttribute.getValue());
                        }
                    }
                }
                nextToken = qr.getNextToken();
                if (nextToken == null) {
                    break;
                }
            }
            return Arrays.asList(count);
        } else {
            LazyList ret = new LazyList(em, tClass, this);
            return ret;
        }
    } catch (NoSuchDomainException e) {
        // no need to throw here
        return new ArrayList();
    } catch (Exception e) {
        throw new PersistenceException(e);
    }
}
Also used : LazyList(com.spaceprogram.simplejpa.LazyList) Attribute(com.amazonaws.services.simpledb.model.Attribute) NoSuchDomainException(com.amazonaws.services.simpledb.model.NoSuchDomainException) NotImplementedException(org.apache.commons.lang.NotImplementedException) AmazonClientException(com.amazonaws.AmazonClientException) NoSuchDomainException(com.amazonaws.services.simpledb.model.NoSuchDomainException) SelectResult(com.amazonaws.services.simpledb.model.SelectResult) Item(com.amazonaws.services.simpledb.model.Item) LazyList(com.spaceprogram.simplejpa.LazyList)

Example 3 with NoSuchDomainException

use of com.amazonaws.services.simpledb.model.NoSuchDomainException in project camel by apache.

the class AmazonSDBClientMock method domainMetadata.

@Override
public DomainMetadataResult domainMetadata(DomainMetadataRequest domainMetadataRequest) throws AmazonServiceException, AmazonClientException {
    this.domainMetadataRequest = domainMetadataRequest;
    if ("NonExistingDomain".equals(domainMetadataRequest.getDomainName())) {
        throw new NoSuchDomainException("Domain 'NonExistingDomain' doesn't exist.");
    }
    DomainMetadataResult result = new DomainMetadataResult();
    result.setTimestamp(new Integer(10));
    result.setItemCount(new Integer(11));
    result.setAttributeNameCount(new Integer(12));
    result.setAttributeValueCount(new Integer(13));
    result.setAttributeNamesSizeBytes(new Long(1000000));
    result.setAttributeValuesSizeBytes(new Long(2000000));
    result.setItemNamesSizeBytes(new Long(3000000));
    return result;
}
Also used : DomainMetadataResult(com.amazonaws.services.simpledb.model.DomainMetadataResult) NoSuchDomainException(com.amazonaws.services.simpledb.model.NoSuchDomainException)

Aggregations

NoSuchDomainException (com.amazonaws.services.simpledb.model.NoSuchDomainException)3 AmazonClientException (com.amazonaws.AmazonClientException)1 Attribute (com.amazonaws.services.simpledb.model.Attribute)1 CreateDomainRequest (com.amazonaws.services.simpledb.model.CreateDomainRequest)1 DomainMetadataRequest (com.amazonaws.services.simpledb.model.DomainMetadataRequest)1 DomainMetadataResult (com.amazonaws.services.simpledb.model.DomainMetadataResult)1 Item (com.amazonaws.services.simpledb.model.Item)1 SelectResult (com.amazonaws.services.simpledb.model.SelectResult)1 LazyList (com.spaceprogram.simplejpa.LazyList)1 NotImplementedException (org.apache.commons.lang.NotImplementedException)1