Java 类com.amazonaws.services.simpledb.AmazonSimpleDBClient 实例源码

项目:Android_Code_Arbiter    文件:AwsQueryInjection.java   
public void doGet(HttpServletRequest request, HttpServletResponse response) throws IOException{
    try{
        String customerID = request.getParameter("customerID");
  BasicAWSCredentials awsCredentials = new BasicAWSCredentials("test", "test");
        AmazonSimpleDBClient sdbc = new AmazonSimpleDBClient(awsCredentials);

        String query = "select * from invoices where customerID = '"
            + customerID;
        SelectResult sdbResult = sdbc.select(new SelectRequest(query)); //BAD

        SelectResult sdbResult2 = sdbc.select(new SelectRequest(query, false)); //BAD

        SelectRequest sdbRequest = new SelectRequest();
        SelectResult sdbResult3 = sdbc.select(sdbRequest.withSelectExpression(query)); //BAD

        String query2 = "select * from invoices where customerID = 123";
        SelectResult sdbResult4 = sdbc.select(new SelectRequest(query2)); //OK

    }catch(Exception e){
        System.out.println(e);
   }
}
项目:OpenUnison    文件:AmazonSimpleDB.java   
@Override
public void configure(String name, Properties props, NameSpace ns)
        throws LDAPException {
    this.name = name;
    this.accessKey = props.getProperty("accessKey");
    this.secretKey = props.getProperty("secretKey");
    this.userDomain = props.getProperty("userDomain");
    this.groupDomain = props.getProperty("groupDomain");

    this.userDN = new DN("ou=users," + ns.getBase().getDN().toString());
    this.groupDN = new DN("ou=groups," + ns.getBase().getDN().toString());
    this.baseDN = new DN(ns.getBase().getDN().toString());

    this.sdb = new AmazonSimpleDBClient(new BasicAWSCredentials(accessKey,secretKey));

}
项目:dwtc-extractor    文件:StatHandler.java   
public AmazonStatHandler(AmazonSimpleDBClient client, String domain) {
    this.client = client;
    this.domain = domain;

    int tries = 0;
    do {
        tries++;
        try {
            ListDomainsResult domainsL = client.listDomains();
            if (!domainsL.getDomainNames().contains(domain)) {
                client.createDomain(new CreateDomainRequest(domain));
            }
            return;
        } catch (Exception ase) {
            log.warn(ase);
            try {
                Thread.sleep(1000);
            } catch (InterruptedException e) {
            }               log.warn(ase);

        }
    } while (tries < MAX_TRIES);
    throw new RuntimeException("Unable to connect to SDB " + domain);

}
项目:olfs    文件:demo.java   
/**
  * The only information needed to create a client are security credentials
  * consisting of the AWS Access Key ID and Secret Access Key. All other
  * configuration, such as the service endpoints, are performed
  * automatically. Client parameters, such as proxies, can be specified in an
  * optional ClientConfiguration object when constructing a client.
  *
  * @see com.amazonaws.auth.BasicAWSCredentials
  * @see com.amazonaws.auth.PropertiesCredentials
  * @see com.amazonaws.ClientConfiguration
  */
 private static void init() throws Exception {
    /*
* This credentials provider implementation loads your AWS credentials
* from a properties file at the root of your classpath.
*/
     //AWSCredentialsProvider credentialsProvider = new ClasspathPropertiesFileCredentialsProvider();


     BasicAWSCredentials basicAWSCredentials = new BasicAWSCredentials("accessKey","secretKey");

     AWSCredentialsProvider credentialsProvider = new CredentialsProvider();

     ec2 = new AmazonEC2Client(credentialsProvider);
     s3  = new AmazonS3Client(credentialsProvider);
     sdb = new AmazonSimpleDBClient(credentialsProvider);
 }
项目:QuotesSocial    文件:SimpleDB.java   
/**
 * Retrieve itemNames for all quotes that were not posted by the user
 *
 * @param myUserId user ID of the viewer so that their posts do not appear in their main feed
 */
public static List<String> getFeedItemNames(String myUserId) {
    SelectRequest selectRequest = new SelectRequest("select itemName() from Quotes where userId != '" + myUserId +
            "' and timestamp is not null order by timestamp desc").withConsistentRead(true);

    AmazonSimpleDBClient client = getInstance();
    if (client != null) {
        List<Item> items = client.select(selectRequest).getItems();

        List<String> itemNames = new ArrayList<String>();
        for (int i = 0; i < items.size(); i++) {
            itemNames.add((items.get(i)).getName());
        }
        return itemNames;
    } else return new ArrayList<String>();
}
项目:QuotesSocial    文件:MainPageListFragment.java   
protected AmazonSimpleDBClient doInBackground(String... urls) {
    if (isNetworkAvailable(getActivity())) {
        try {

            // Initialize the Amazon Cognito credentials provider
            CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
                    getActivity().getApplicationContext(), // Context
                    "us-east-1:1caef7b3-7585-4ded-961d-0cc8f4bbc87f", // Identity Pool ID
                    Regions.US_EAST_1 // Region
            );

            Map<String, String> logins = new HashMap<String, String>();
            logins.put("graph.facebook.com", Session.getActiveSession().getAccessToken());
            credentialsProvider.withLogins(logins);

            Log.d("SimpleDBClient", "My ID is " + credentialsProvider.getIdentityId());
            AmazonSimpleDBClient client = new AmazonSimpleDBClient(credentialsProvider);
            return client;
        } catch (Exception e) {
            this.exception = e;
            return null;
        }
    } else return null;
}
项目:QuotesSocial    文件:MainPageListFragment.java   
protected void onPostExecute(AmazonSimpleDBClient client) {
    if (isNetworkAvailable(getActivity())) {
        MainPage.simpleDBClient = client;
        new Thread(new Runnable() {
            public void run() {
                itemNames = SimpleDB.getFeedItemNames(userId);
                adapter = new MySimpleArrayAdapter(getActivity().getApplicationContext(), itemNames);
                adAdapter = new AdListAdapter(mActivity, adapter);
                mActivity.runOnUiThread(new Runnable() {
                    @Override
                    public void run() {
                        setListAdapter(adAdapter);

                    }
                });
            }
        }).start();
    }
}
项目:agathon    文件:SdbDaoModule.java   
@Provides @Named(RINGS_PROPERTY)
Set<String> provideRings(AmazonSimpleDBClient client, CassandraDomainFactory domainFactory) {
  List<String> rings = Lists.newArrayList();
  String nextToken = null;

  do {
    ListDomainsRequest request = new ListDomainsRequest().withNextToken(nextToken);
    ListDomainsResult result = client.listDomains(request);
    for (String domain : result.getDomainNames()) {
      CassandraDomain cassandraDomain = domainFactory.createFromDomain(domain);
      if (cassandraDomain != null) {
        rings.add(cassandraDomain.getRing());
      }
    }
    nextToken = result.getNextToken();
  } while (nextToken != null);
  return ImmutableSet.copyOf(rings);
}
项目:spring-data-simpledb    文件:SimpleDb.java   
@Override
public final void afterPropertiesSet() {
    final AWSCredentials awsCredentials = new AWSCredentials() {

        @Override
        public String getAWSAccessKeyId() {
            return accessID;
        }

        @Override
        public String getAWSSecretKey() {
            return secretKey;
        }
    };

    this.simpleDbClient = new AmazonSimpleDBClient(awsCredentials);

    simpleDbDomain = new SimpleDbDomain(domainPrefix);
}
项目:Tank    文件:AmazonSimpleDBTest.java   
@BeforeClass
public void before() {
    AWSCredentials credentials = new BasicAWSCredentials(System.getProperty("AWS_SECRET_KEY_ID"),
            System.getProperty("AWS_SECRET_KEY"));
    simpeDB = new AmazonSimpleDBClient(credentials, new ClientConfiguration());
    simpeDB.setEndpoint(VMRegion.US_WEST_2.getEndpoint());
}
项目:aws-cms-plugins    文件:WPBAwsSdbAdminDataStorage.java   
public void initialize(Map<String, String> params) throws WPBIOException {

        String accessKey = params.get(CONFIG_ACCESS_KEY);
        String secretkey = params.get(CONFIG_SECRET_KEY);
        BasicAWSCredentials awsCredentials = new BasicAWSCredentials(accessKey, secretkey);

        ClientConfiguration clientConfig = new ClientConfiguration();

        String protocolStr = params.get(CONFIG_PROTOCOL);
        if (protocolStr != null && protocolStr.length()>0)
        {
            Protocol protocol = Protocol.valueOf(params.get(CONFIG_PROTOCOL));
            if (protocol != null)
            {
                clientConfig.setProtocol(protocol);
            }
        }
        sdbClient = new AmazonSimpleDBClient(awsCredentials, clientConfig);     
        String endpoint = params.get(CONFIG_ENDPOINT);
        if (endpoint != null)
        {
            sdbClient.setEndpoint(endpoint);
        }

        domainName = params.get(CONFIG_DOMAIN);
        // create the domain if not exists
        CreateDomainRequest createDomainRequest = new CreateDomainRequest();
        createDomainRequest.setDomainName(domainName);
        sdbClient.createDomain(createDomainRequest);    
    }
项目:agathon    文件:SdbCassandraRingDao.java   
@Inject
public SdbCassandraRingDao(AmazonSimpleDBClient client, SdbCassandraInstanceDao instanceDao,
    CassandraDomainFactory domainFactory,
    @Named(SdbDaoModule.RINGS_PROPERTY) Provider<Set<String>> ringsProvider) {
  this.client = client;
  this.instanceDao = instanceDao;
  this.domainFactory = domainFactory;
  this.ringsProvider = ringsProvider;
}
项目:wildfly-camel    文件:SDBIntegrationTest.java   
public static void assertNoStaleDomain(AmazonSimpleDBClient client, String when) {
    List<String> staleInstances = client.listDomains().getDomainNames().stream() //
            .filter(name -> !name.startsWith(SDBIntegrationTest.class.getSimpleName())
                    || System.currentTimeMillis() - AWSUtils.toEpochMillis(name) > AWSUtils.HOUR) //
            .collect(Collectors.toList());
    Assert.assertEquals(String.format("Found stale SDB domans %s running the test: %s", when, staleInstances), 0,
            staleInstances.size());
}
项目:wildfly-camel    文件:SDBUtils.java   
public static AmazonSimpleDBClient createDBClient() {
    BasicCredentialsProvider credentials = BasicCredentialsProvider.standard();
    AmazonSimpleDBClient client = !credentials.isValid() ? null : (AmazonSimpleDBClient)
            AmazonSimpleDBClientBuilder.standard()
            .withCredentials(credentials)
            .withRegion("eu-west-1").build();
    return client;
}
项目:wildfly-camel    文件:SDBUtils.java   
public static void createDomain(AmazonSimpleDBClient client, String domainName) throws InterruptedException {
    client.createDomain(new CreateDomainRequest(domainName));

    // Unfortunatly, there is no waiters for domain create

    int retries = 10;
    List<String> domainNames = client.listDomains().getDomainNames();
    while (!domainNames.contains(domainName) && 0 < retries--) {
        Thread.sleep(500);
        domainNames = client.listDomains().getDomainNames();
    }
    Assert.assertTrue(domainNames.contains(domainName));
}
项目:OpenUnison    文件:AmazonSimpleDBProvider.java   
@Override
public void init(Map<String, Attribute> cfg,ConfigManager cfgMgr,String name)
        throws ProvisioningException {

    this.name = name;

    this.cfgMgr = cfgMgr;
    this.userDomain = cfg.get("userDomain").getValues().get(0);
    this.groupDomain = cfg.get("groupDomain").getValues().get(0);

    this.accessKey = cfg.get("accessKey").getValues().get(0);
    this.secretKey = cfg.get("secretKey").getValues().get(0);
    this.uidAttrName = cfg.get("uidAttributeName").getValues().get(0);


    sdb = new AmazonSimpleDBClient(new BasicAWSCredentials(accessKey,secretKey));


}
项目:aws-utilization-monitor    文件:AwsScan.java   
/**
 * Collect data for SimpleDB.
 *
 * @param stats
 *            current statistics object.
 * @param account
 *            currently used credentials object.
 * @param region
 *            currently used aws region.
 */
public static void scanSimpleDB(AwsStats stats, AwsAccount account, Regions region) {
    if (region == Regions.EU_CENTRAL_1)
        return;

    LOG.debug("Scan for SimpleDB in region " + region.getName() + " in account " + account.getAccountId());

    /*
     * Amazon SimpleDB
     * 
     * The AWS SimpleDB client allows you to query and manage your data
     * stored in SimpleDB domains (similar to tables in a relational DB).
     * 
     * In this sample, we use a SimpleDB client to iterate over all the
     * domains owned by the current user, and add up the number of items
     * (similar to rows of data in a relational DB) in each domain.
     */
    try {
        AmazonSimpleDB simpleDB = new AmazonSimpleDBClient(account.getCredentials());
        simpleDB.setRegion(Region.getRegion(region));

        ListDomainsRequest sdbRequest = new ListDomainsRequest().withMaxNumberOfDomains(100);
        ListDomainsResult sdbResult = simpleDB.listDomains(sdbRequest);

        int totalItems = 0;
        for (String domainName : sdbResult.getDomainNames()) {
            DomainMetadataRequest metadataRequest = new DomainMetadataRequest().withDomainName(domainName);
            DomainMetadataResult domainMetadata = simpleDB.domainMetadata(metadataRequest);
            int items = domainMetadata.getItemCount();
            totalItems += items;
            AwsResource res = new AwsResource(domainName, account.getAccountId(), AwsResourceType.SimpleDB, region);
            res.addInfo(AwsTag.Items, items);
            stats.add(res);
        }

        LOG.info(sdbResult.getDomainNames().size() + " SimpleDB domains containing a total of " + totalItems + " items in region " + region.getName()
                + " in account " + account.getAccountId());
    } catch (AmazonServiceException ase) {
        LOG.error("Exception of SimpleDB: " + ase.getMessage());
    } catch (Exception ex) {
        LOG.error("Exception of SimpleDB: " + ex.getMessage());
    }
}
项目:teiid    文件:SimpleDBConnectionImpl.java   
public SimpleDBConnectionImpl(String accessKey, String secretAccessKey) {
    this.client = new AmazonSimpleDBClient(new BasicAWSCredentials(accessKey, secretAccessKey));
}
项目:dwtc-extractor    文件:Master.java   
private static Set<String> getSdbAttributes(AmazonSimpleDBClient client,
        String domainName, int sampleSize) {
    if (!client.listDomains().getDomainNames().contains(domainName)) {
        throw new IllegalArgumentException("SimpleDB domain '" + domainName
                + "' not accessible from given client instance");
    }

    int domainCount = client.domainMetadata(
            new DomainMetadataRequest(domainName)).getItemCount();
    if (domainCount < sampleSize) {
        throw new IllegalArgumentException("SimpleDB domain '" + domainName
                + "' does not have enough entries for accurate sampling.");
    }

    int avgSkipCount = domainCount / sampleSize;
    int processedCount = 0;
    String nextToken = null;
    Set<String> attributeNames = new HashSet<String>();
    Random r = new Random();
    do {
        int nextSkipCount = r.nextInt(avgSkipCount * 2) + 1;

        SelectResult countResponse = client.select(new SelectRequest(
                "select count(*) from `" + domainName + "` limit "
                        + nextSkipCount).withNextToken(nextToken));

        nextToken = countResponse.getNextToken();

        processedCount += Integer.parseInt(countResponse.getItems().get(0)
                .getAttributes().get(0).getValue());

        SelectResult getResponse = client.select(new SelectRequest(
                "select * from `" + domainName + "` limit 1")
                .withNextToken(nextToken));

        nextToken = getResponse.getNextToken();

        processedCount++;

        if (getResponse.getItems().size() > 0) {
            for (Attribute a : getResponse.getItems().get(0)
                    .getAttributes()) {
                attributeNames.add(a.getName());
            }
        }
    } while (domainCount > processedCount);
    return attributeNames;
}
项目:dwtc-extractor    文件:ProcessingNode.java   
public void setDbClient(AmazonSimpleDBClient client) {
    sdb = client;
}
项目:QuotesSocial    文件:SimpleDB.java   
public static AmazonSimpleDBClient getInstance() {
    return MainPage.simpleDBClient;
}
项目:agathon    文件:SdbDaoModule.java   
@Provides
AmazonSimpleDBClient provideAmazonSimpleDBClient(AWSCredentials credentials) {
  return new AmazonSimpleDBClient(credentials);
}
项目:agathon    文件:SdbCassandraInstanceDao.java   
@Inject
public SdbCassandraInstanceDao(AmazonSimpleDBClient client, CassandraDomainFactory domainFactory) {
  this.client = client;
  this.domainFactory = domainFactory;
}
项目:agathon    文件:SdbCassandraInstanceDaoTest.java   
@Before
public void setUp() {
  simpleDbClient = createMock(AmazonSimpleDBClient.class);
  domainFactory = createMock(CassandraDomainFactory.class);
  dao = new SdbCassandraInstanceDao(simpleDbClient, domainFactory);
}
项目:wildfly-camel    文件:SDBClientProducer.java   
SDBClientProvider(AmazonSimpleDBClient client) {
    this.client = client;
}
项目:wildfly-camel    文件:SDBClientProducer.java   
public AmazonSimpleDBClient getClient() {
    return client;
}
项目:wildfly-camel    文件:SDBClientProducer.java   
@Produces
@Singleton
public SDBClientProvider getClientProvider() throws Exception {
    AmazonSimpleDBClient client = SDBUtils.createDBClient();
    return new SDBClientProvider(client);
}