当前位置: 首页>>代码示例>>Java>>正文


Java AmazonSimpleDB类代码示例

本文整理汇总了Java中com.amazonaws.services.simpledb.AmazonSimpleDB的典型用法代码示例。如果您正苦于以下问题:Java AmazonSimpleDB类的具体用法?Java AmazonSimpleDB怎么用?Java AmazonSimpleDB使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


AmazonSimpleDB类属于com.amazonaws.services.simpledb包,在下文中一共展示了AmazonSimpleDB类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: deleteAllAttributes

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
@Override
public void deleteAllAttributes(String itemName) {

  if (!initialised) {
    throw new IllegalStateException("The optimistic persister has not been initialised");
  }

  logger.log("About to delete all attributes from simpledb item: " + itemName);

  DeleteAttributesRequest deleteAttributesRequest = new DeleteAttributesRequest(
      simpleDbDomainName, itemName);
  AmazonSimpleDB client = getSimpleDBClient();
  client.deleteAttributes(deleteAttributesRequest);

  logger.log("Deleted all attributes from simpledb item.");
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:17,代码来源:OptimisticPersister.java

示例2: manageDomain

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
/**
 * Creates a domain, based on the Domain Policy; The default is UPDATE(if it does not exist create it)
 *
 * @return true if the domain was successfuly managed, false if the domain has been managed before
 */
public synchronized boolean manageDomain(final String domainName, final DomainManagementPolicy policy, final AmazonSimpleDB sdb) {
	Assert.notNull(sdb);
	
	if(! managedDomains.contains(domainName)) {
		try {
			if(policy == DomainManagementPolicy.UPDATE || policy == null) {
				createDomain(domainName, sdb);
				
			} else if(policy == DomainManagementPolicy.DROP_CREATE) {
				dropDomain(domainName, sdb);
				createDomain(domainName, sdb);
			}
			
			managedDomains.add(domainName);
			
			return true;
		} catch(AmazonClientException e) {
			throw SimpleDbExceptionTranslator.getTranslatorInstance().translateAmazonClientException(e);
		}
	} else {
		LOGGER.debug("Domain has been managed before: {}", domainName);
	}
	
	return false;
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:31,代码来源:DomainManager.java

示例3: createDomain

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
protected void createDomain(final String domainName, final AmazonSimpleDB sdb) {
	try {
		LOGGER.debug("Creating domain: {}", domainName);
		CreateDomainRequest request = new CreateDomainRequest(domainName);
		sdb.createDomain(request);
		LOGGER.debug("Created domain: {}", domainName);
	} catch(AmazonClientException amazonException) {
		throw SimpleDbExceptionTranslator.getTranslatorInstance().translateAmazonClientException(amazonException);
	}
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:11,代码来源:DomainManager.java

示例4: manageDomains_should_create_domains_referred_by_repository

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
@Test
public void manageDomains_should_create_domains_referred_by_repository() {
	AmazonSimpleDB sdb = operations.getDB();

	final String domainPrefix = operations.getSimpleDb().getDomainPrefix();

	ListDomainsResult listDomainsResult = sdb.listDomains(new ListDomainsRequest());
	List<String> domainNames = listDomainsResult.getDomainNames();
	String nextToken = listDomainsResult.getNextToken(); 
	while (nextToken != null && !nextToken.isEmpty()) {
		listDomainsResult = sdb.listDomains(new ListDomainsRequest().withNextToken(nextToken));
		domainNames.addAll(listDomainsResult.getDomainNames());
		nextToken = listDomainsResult.getNextToken();
	}

	assertThat(domainNames.contains(domainPrefix + ".simpleDbReferences"), is(true));
	assertThat(domainNames.contains(domainPrefix + ".firstNestedEntity"), is(true));
	assertThat(domainNames.contains(domainPrefix + ".secondNestedEntity"), is(true));

	Assert.assertNotNull(operations);
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:22,代码来源:SimpleDbReferencesRepositoryTest.java

示例5: get

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
@Override
public ImmutablePair<Optional<Integer>, Set<Attribute>> get(String itemName) {

  if (!initialised) {
    throw new IllegalStateException("The optimistic persister has not been initialised");
  }

  logger.log("About to get all active attributes from simpledb item: " + itemName);

  AmazonSimpleDB client = getSimpleDBClient();

  // Do a consistent read - to ensure we get correct version number
  GetAttributesRequest simpleDBRequest = new GetAttributesRequest(simpleDbDomainName, itemName);
  logger.log("Using simpleDB domain: " + simpleDbDomainName);

  simpleDBRequest.setConsistentRead(true);
  GetAttributesResult result = client.getAttributes(simpleDBRequest);
  List<Attribute> attributes = result.getAttributes();

  // Get the version number and other attributes.
  Optional<Integer> version = Optional.empty();
  Set<Attribute> nonVersionAttributes = new HashSet<>();
  if (attributes.size() > 0) {
    // If we have any attributes, we'll always have a version number
    Attribute versionNumberAttribute = attributes.stream()
        .filter(attribute -> attribute.getName().equals(versionAttributeName)).findFirst().get();
    version = Optional.of(Integer.parseInt(versionNumberAttribute.getValue()));
    logger.log("Retrieved version number: " + versionNumberAttribute.getValue());
    attributes.remove(versionNumberAttribute);

    // Add all active attributes (i.e. those not pending deletion)
    nonVersionAttributes.addAll(attributes.stream()
        .filter(attribute -> !attribute.getValue().startsWith("Inactive"))
        .collect(Collectors.toSet()));
  }
  logger.log("Got all attributes from simpledb");

  return new ImmutablePair<>(version, nonVersionAttributes);
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:40,代码来源:OptimisticPersister.java

示例6: getSimpleDBClient

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
/**
 * Returns a SimpleDB database client.
 */
protected AmazonSimpleDB getSimpleDBClient() {

  // Use a getter here so unit tests can substitute a mock client
  AmazonSimpleDB client = AmazonSimpleDBClientBuilder.standard().withRegion(region.getName())
      .build();
  return client;
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:11,代码来源:OptimisticPersister.java

示例7: beforeTest

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
@Before
public void beforeTest() {

  optimisticPersister = new TestOptimisticPersister();

  // Set up the mocks
  mockLogger = mockery.mock(LambdaLogger.class);
  mockery.checking(new Expectations() {
    {
      ignoring(mockLogger);
    }
  });
  mockSimpleDBClient = mockery.mock(AmazonSimpleDB.class);

  optimisticPersister.setSimpleDBClient(mockSimpleDBClient);

  // Set up some typical test attributes
  allAttributes = new HashSet<>();
  nonVersionAttributes = new HashSet<>();
  activeNonVersionAttributes = new HashSet<>();
  Attribute versionAttribute = new Attribute();
  versionAttribute.setName(versionAttributeName);
  versionAttribute.setValue(Integer.toString(testVersionNumber));
  Attribute activeAttribute = new Attribute();
  activeAttribute.setName("ActiveAttribute");
  activeAttribute.setValue("Active");
  Attribute inactiveAttribute = new Attribute();
  inactiveAttribute.setName("InactiveAttribute");
  inactiveAttribute.setValue("Inactive");
  allAttributes.add(versionAttribute);
  allAttributes.add(activeAttribute);
  allAttributes.add(inactiveAttribute);
  nonVersionAttributes.add(activeAttribute);
  nonVersionAttributes.add(inactiveAttribute);
  activeNonVersionAttributes.add(activeAttribute);
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:37,代码来源:OptimisticPersisterTest.java

示例8: loadsItemFromSimpleDb

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
/**
 * AwsItem can load an item.
 * @throws Exception If some problem inside
 */
@Test
public void loadsItemFromSimpleDb() throws Exception {
    final AmazonSimpleDB aws = Mockito.mock(AmazonSimpleDB.class);
    Mockito.doReturn(
        new GetAttributesResult().withAttributes(
            new Attribute().withName("attr-1").withValue("value-1")
        )
    ).when(aws).getAttributes(Mockito.any(GetAttributesRequest.class));
    final Credentials credentials = Mockito.mock(Credentials.class);
    Mockito.doReturn(aws).when(credentials).aws();
    final String name = "item-name";
    final String table = "table-name";
    final Item item = new AwsItem(credentials, table, name);
    item.get("hello");
    Mockito.verify(aws).getAttributes(
        GetAttributesRequest.class.cast(
            Mockito.argThat(
                Matchers.allOf(
                    Matchers.hasProperty(
                        "domainName",
                        Matchers.equalTo(table)
                    ),
                    Matchers.hasProperty(
                        "itemName",
                        Matchers.equalTo(name)
                    )
                )
            )
        )
    );
}
 
开发者ID:jcabi,项目名称:jcabi-simpledb,代码行数:36,代码来源:AwsItemTest.java

示例9: dropDomain

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
/**
 * Running the delete-domain command over & over again on the same domain, or if the domain does NOT exist will NOT
 * result in a Amazon Exception
 * 
 * @param domainName
 */
protected void dropDomain(final String domainName, final AmazonSimpleDB sdb) {
	try {
		LOGGER.debug("Dropping domain: {}", domainName);
		DeleteDomainRequest request = new DeleteDomainRequest(domainName);
		sdb.deleteDomain(request);
		LOGGER.debug("Dropped domain: {}", domainName);
	} catch(AmazonClientException amazonException) {
		throw SimpleDbExceptionTranslator.getTranslatorInstance().translateAmazonClientException(amazonException);
	}
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:17,代码来源:DomainManager.java

示例10: exists

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
protected boolean exists(final String domainName, final AmazonSimpleDB sdb) {
	try {
		ListDomainsResult listDomainsResult = sdb.listDomains(new ListDomainsRequest());
		List<String> domainNames = listDomainsResult.getDomainNames();
		String nextToken = listDomainsResult.getNextToken(); 
		while (nextToken != null && !nextToken.isEmpty()) {
			listDomainsResult = sdb.listDomains(new ListDomainsRequest().withNextToken(nextToken));
			domainNames.addAll(listDomainsResult.getDomainNames());
			nextToken = listDomainsResult.getNextToken();
		}
		return domainNames.contains(domainName);
	} catch(AmazonClientException amazonException) {
		throw SimpleDbExceptionTranslator.getTranslatorInstance().translateAmazonClientException(amazonException);
	}
}
 
开发者ID:3pillarlabs,项目名称:spring-data-simpledb,代码行数:16,代码来源:DomainManager.java

示例11: getAllItems

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
@Override
public List<ImmutablePair<String, List<Attribute>>> getAllItems() {

  if (!initialised) {
    throw new IllegalStateException("The optimistic persister has not been initialised");
  }

  // Query database to get items
  List<ImmutablePair<String, List<Attribute>>> items = new ArrayList<>();
  AmazonSimpleDB client = getSimpleDBClient();

  SelectRequest selectRequest = new SelectRequest();
  // N.B. Think if results are paged, second and subsequent pages will always
  // be eventually-consistent only. This is currently used only to back up the
  // database - so being eventually-consistent is good enough - after all -
  // even if we were fully consistent, someone could still add a new booking
  // right after our call anyway.
  selectRequest.setConsistentRead(true);
  // Query all items in the domain
  selectRequest.setSelectExpression("select * from `" + simpleDbDomainName + "`");
  String nextToken = null;
  do {
    SelectResult selectResult = client.select(selectRequest);
    selectResult.getItems().forEach(
        item -> {
          List<Attribute> attributes = new ArrayList<>();
          item.getAttributes()
              .stream()
              // Do not return the version attribute or inactive attributes
              .filter(
                  attribute -> (!attribute.getName().equals(versionAttributeName) && !attribute
                      .getValue().startsWith("Inactive"))).forEach(attribute -> {
                attributes.add(attribute);
              });
          items.add(new ImmutablePair<>(item.getName(), attributes));
        });
    nextToken = selectResult.getNextToken();
    selectRequest.setNextToken(nextToken);
  } while (nextToken != null);

  return items;
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:43,代码来源:OptimisticPersister.java

示例12: delete

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
@Override
public void delete(String itemName, Attribute attribute) throws Exception {

  if (!initialised) {
    throw new IllegalStateException("The optimistic persister has not been initialised");
  }

  logger.log("About to delete attribute from simpledb item: " + itemName);

  AmazonSimpleDB client = getSimpleDBClient();

  // We retry the delete if necessary if we get a
  // ConditionalCheckFailed exception, i.e. if someone else modifies the
  // database between us reading and writing it.
  RetryHelper
      .DoWithRetries(() -> {
        try {
          // Get existing attributes (and version number), via consistent
          // read:
          ImmutablePair<Optional<Integer>, Set<Attribute>> versionedAttributes = get(itemName);

          if (!versionedAttributes.left.isPresent()) {
            logger
                .log("A version number attribute did not exist - this means no attributes exist, so we have nothing to delete.");
            return null;
          }
          if (!versionedAttributes.right.contains(attribute)) {
            logger.log("The attribute did not exist - so we have nothing to delete.");
            return null;
          }

          // Since it seems impossible to update the version number while
          // deleting an attribute, we first mark the attribute as inactive,
          // and then delete it.
          ReplaceableAttribute inactiveAttribute = new ReplaceableAttribute();
          inactiveAttribute.setName(attribute.getName());
          inactiveAttribute.setValue("Inactive" + attribute.getValue());
          inactiveAttribute.setReplace(true);
          put(itemName, versionedAttributes.left, inactiveAttribute);

          // Now we can safely delete the attribute, as other readers will now
          // ignore it.
          UpdateCondition updateCondition = new UpdateCondition();
          updateCondition.setName(inactiveAttribute.getName());
          updateCondition.setValue(inactiveAttribute.getValue());
          // Update will proceed unless the attribute no longer exists
          updateCondition.setExists(true);

          Attribute attributeToDelete = new Attribute();
          attributeToDelete.setName(inactiveAttribute.getName());
          attributeToDelete.setValue(inactiveAttribute.getValue());
          List<Attribute> attributesToDelete = new ArrayList<>();
          attributesToDelete.add(attributeToDelete);
          DeleteAttributesRequest simpleDBDeleteRequest = new DeleteAttributesRequest(
              simpleDbDomainName, itemName, attributesToDelete, updateCondition);
          client.deleteAttributes(simpleDBDeleteRequest);
          logger.log("Deleted attribute from simpledb");
          return null;
        } catch (AmazonServiceException ase) {
          if (ase.getErrorCode().contains("AttributeDoesNotExist")) {
            // Case of trying to delete an attribute that no longer exists -
            // that's ok - it probably just means more than one person was
            // trying to delete the attribute at once. So swallow this
            // exception
            logger
                .log("Caught AmazonServiceException for AttributeDoesNotExist whilst deleting attribute so"
                    + " swallowing and continuing");
            return null;
          } else {
            throw ase;
          }
        }
      }, Exception.class, Optional.of("Database put failed - conditional check failed"), logger);
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:75,代码来源:OptimisticPersister.java

示例13: setSimpleDBClient

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
public void setSimpleDBClient(AmazonSimpleDB simpleDBClient) {
  this.simpleDBClient = simpleDBClient;
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:4,代码来源:OptimisticPersisterTest.java

示例14: getSimpleDBClient

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
@Override
public AmazonSimpleDB getSimpleDBClient() {
  return simpleDBClient;
}
 
开发者ID:robinsteel,项目名称:Sqawsh,代码行数:5,代码来源:OptimisticPersisterTest.java

示例15: getSdbClient

import com.amazonaws.services.simpledb.AmazonSimpleDB; //导入依赖的package包/类
public AmazonSimpleDB getSdbClient() {
    return sdbClient;
}
 
开发者ID:HydAu,项目名称:Camel,代码行数:4,代码来源:SdbEndpoint.java


注:本文中的com.amazonaws.services.simpledb.AmazonSimpleDB类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。