Пример #1
0
  /*
   * Creates a table with the following attributes:
   *
   * Table name: testTableName Hash key: userNo type N Read Capacity Units: 10
   * Write Capacity Units: 5
   */
  public static void createTable() {

    /*AmazonDynamoDBClient ddb = UserPreferenceDemoActivity.clientManager
    .ddb();*/
    AmazonDynamoDBClient ddb = LoginActivity.clientManager.ddb();
    KeySchemaElement kse =
        new KeySchemaElement().withAttributeName("userNo").withKeyType(KeyType.HASH);
    AttributeDefinition ad =
        new AttributeDefinition()
            .withAttributeName("userNo")
            .withAttributeType(ScalarAttributeType.N);
    ProvisionedThroughput pt =
        new ProvisionedThroughput().withReadCapacityUnits(10l).withWriteCapacityUnits(5l);

    CreateTableRequest request =
        new CreateTableRequest()
            .withTableName(PropertyLoader.getInstance().getTestTableName())
            .withKeySchema(kse)
            .withAttributeDefinitions(ad)
            .withProvisionedThroughput(pt);

    try {
      ddb.createTable(request);
    } catch (AmazonServiceException ex) {
      /*UserPreferenceDemoActivity.clientManager
      .wipeCredentialsOnAuthError(ex);*/
      LoginActivity.clientManager.wipeCredentialsOnAuthError(ex);
    }
  }
Пример #2
0
  public void createSimTradeTable() {

    CreateTableRequest createTableRequest = mapper.generateCreateTableRequest(SimDetails.class);
    // Table provision throughput is still required since it cannot be
    // specified in your POJO
    createTableRequest.setProvisionedThroughput(new ProvisionedThroughput(5L, 5L));
    // Fire off the CreateTableRequest using the low-level client
    amazonDynamoDBClient.createTable(createTableRequest);
  }
Пример #3
0
  public static void main(String[] args) throws Exception {
    init();

    try {
      String violationsTable = "violations-table";
      String citationsTable = "citations-table";
      String warrantsTable = "warrants-table";
      String contactsTable = "contacts-table";
      String notificationsTable = "notifications-table";

      // VIOLATIONS TABLE
      //
      //

      // Create violationsTable if it does not exist yet
      if (Tables.doesTableExist(dynamoDB, violationsTable)) {
        System.out.println("Table " + violationsTable + " is already ACTIVE");
      } else {
        // Create a table with a primary hash key named 'name', which holds a string
        CreateTableRequest createTableRequest =
            new CreateTableRequest()
                .withTableName(violationsTable)
                .withKeySchema(
                    new KeySchemaElement()
                        .withAttributeName("citation_number")
                        .withKeyType(KeyType.HASH))
                .withAttributeDefinitions(
                    new AttributeDefinition()
                        .withAttributeName("citation_number")
                        .withAttributeType(ScalarAttributeType.N))
                .withProvisionedThroughput(
                    new ProvisionedThroughput()
                        .withReadCapacityUnits(25L)
                        .withWriteCapacityUnits(25L));
        TableDescription createdTableDescription =
            dynamoDB.createTable(createTableRequest).getTableDescription();
        System.out.println("Created Table: " + createdTableDescription);

        // Wait for it to become active
        System.out.println("Waiting for " + violationsTable + " to become ACTIVE...");
        Tables.awaitTableToBecomeActive(dynamoDB, violationsTable);
      }

      // Describe our new table
      DescribeTableRequest describeTableRequest =
          new DescribeTableRequest().withTableName(violationsTable);
      TableDescription tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
      System.out.println("Table Description: " + tableDescription);

      // CITATIONS TABLE
      //
      //
      // Create citationsTable if it does not exist yet
      if (Tables.doesTableExist(dynamoDB, citationsTable)) {
        System.out.println("Table " + citationsTable + " is already ACTIVE");
      } else {
        // Create a table with a primary hash key named 'name', which holds a string
        /*
                        GlobalSecondaryIndex _firstLast = new GlobalSecondaryIndex()
                            .withIndexName("first_last")
                            .withProvisionedThroughput(new ProvisionedThroughput()
                                .withReadCapacityUnits((long) 10)
                                .withWriteCapacityUnits((long) 1))
                                .withProjection(new Projection().withProjectionType(ProjectionType.ALL));

                        GlobalSecondaryIndex _firstLastDOB = new GlobalSecondaryIndex()
                            .withIndexName("first_last_dob")
                            .withProvisionedThroughput(new ProvisionedThroughput()
                                .withReadCapacityUnits((long) 10)
                                .withWriteCapacityUnits((long) 1))
                                .withProjection(new Projection().withProjectionType(ProjectionType.ALL));
        */
        CreateTableRequest createTableRequest =
            new CreateTableRequest()
                .withTableName(citationsTable)
                .withKeySchema(
                    new KeySchemaElement()
                        .withAttributeName("first_last")
                        .withKeyType(KeyType.HASH))
                .withAttributeDefinitions(
                    new AttributeDefinition()
                        .withAttributeName("first_last")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                    new ProvisionedThroughput()
                        .withReadCapacityUnits(25L)
                        .withWriteCapacityUnits(25L));
        // .withGlobalSecondaryIndexes(_firstLast, _firstLastDOB);
        TableDescription createdTableDescription =
            dynamoDB.createTable(createTableRequest).getTableDescription();
        System.out.println("Created Table: " + createdTableDescription);

        // Wait for it to become active
        System.out.println("Waiting for " + citationsTable + " to become ACTIVE...");
        Tables.awaitTableToBecomeActive(dynamoDB, citationsTable);
      }

      // Describe our new table
      describeTableRequest = new DescribeTableRequest().withTableName(citationsTable);
      tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
      System.out.println("Table Description: " + tableDescription);

      // WARRANTS TABLE
      //
      //
      // Create warrantsTable if it does not exist yet
      if (Tables.doesTableExist(dynamoDB, warrantsTable)) {
        System.out.println("Table " + warrantsTable + " is already ACTIVE");
      } else {
        /*
                        GlobalSecondaryIndex _firstLastDOB = new GlobalSecondaryIndex()
                            .withIndexName("first_last_dob")
                            .withProvisionedThroughput(new ProvisionedThroughput()
                                .withReadCapacityUnits((long) 10)
                                .withWriteCapacityUnits((long) 1))
                                .withProjection(new Projection().withProjectionType(ProjectionType.ALL));
        */
        // Create a table with a primary hash key named 'name', which holds a string
        CreateTableRequest createTableRequest =
            new CreateTableRequest()
                .withTableName(warrantsTable)
                .withKeySchema(
                    new KeySchemaElement().withAttributeName("id").withKeyType(KeyType.HASH))
                .withAttributeDefinitions(
                    new AttributeDefinition()
                        .withAttributeName("id")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                    new ProvisionedThroughput()
                        .withReadCapacityUnits(25L)
                        .withWriteCapacityUnits(25L));
        // .withGlobalSecondaryIndexes(_firstLastDOB);
        TableDescription createdTableDescription =
            dynamoDB.createTable(createTableRequest).getTableDescription();
        System.out.println("Created Table: " + createdTableDescription);

        // Wait for it to become active
        System.out.println("Waiting for " + warrantsTable + " to become ACTIVE...");
        Tables.awaitTableToBecomeActive(dynamoDB, warrantsTable);
      }

      // Describe our new table
      describeTableRequest = new DescribeTableRequest().withTableName(warrantsTable);
      tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
      System.out.println("Table Description: " + tableDescription);

      // CONTACTS TABLE
      //
      //

      // Create violationsTable if it does not exist yet
      if (Tables.doesTableExist(dynamoDB, contactsTable)) {
        System.out.println("Table " + contactsTable + " is already ACTIVE");
      } else {
        // Create a table with a primary hash key named 'name', which holds a string
        CreateTableRequest createTableRequest =
            new CreateTableRequest()
                .withTableName(contactsTable)
                .withKeySchema(
                    new KeySchemaElement()
                        .withAttributeName("first_last")
                        .withKeyType(KeyType.HASH))
                .withAttributeDefinitions(
                    new AttributeDefinition()
                        .withAttributeName("first_last")
                        .withAttributeType(ScalarAttributeType.S))
                .withProvisionedThroughput(
                    new ProvisionedThroughput()
                        .withReadCapacityUnits(25L)
                        .withWriteCapacityUnits(25L));
        TableDescription createdTableDescription =
            dynamoDB.createTable(createTableRequest).getTableDescription();
        System.out.println("Created Table: " + createdTableDescription);

        // Wait for it to become active
        System.out.println("Waiting for " + contactsTable + " to become ACTIVE...");
        Tables.awaitTableToBecomeActive(dynamoDB, contactsTable);
      }

      // Describe our new table
      describeTableRequest = new DescribeTableRequest().withTableName(violationsTable);
      tableDescription = dynamoDB.describeTable(describeTableRequest).getTable();
      System.out.println("Table Description: " + tableDescription);

      ssnHashMap = new HashMap<>();
      saltHashMap = new HashMap<>();
      hashedssnHashMap = new HashMap<>();

      ssnList = new ArrayList<>();

      for (int i = 1010001; i < 1200001; i++) {
        SocialSecurityNumber ssn = new SocialSecurityNumber(i);
        String ssnString = ssn.toString();
        ssnList.add(ssnString);
      }
      /*
      for (String str : ssnList) {
          System.out.println("SSN: " + str);
      }
      */

      // oneTimeAddViolations();
      // oneTimeAddCitations();
      oneTimeAddWarrants();
      // oneTimeAddContacts();

    } catch (AmazonServiceException ase) {
      System.out.println(
          "Caught an AmazonServiceException, which means your request made it "
              + "to AWS, but was rejected with an error response for some reason.");
      System.out.println("Error Message:    " + ase.getMessage());
      System.out.println("HTTP Status Code: " + ase.getStatusCode());
      System.out.println("AWS Error Code:   " + ase.getErrorCode());
      System.out.println("Error Type:       " + ase.getErrorType());
      System.out.println("Request ID:       " + ase.getRequestId());
    } catch (AmazonClientException ace) {
      System.out.println(
          "Caught an AmazonClientException, which means the client encountered "
              + "a serious internal problem while trying to communicate with AWS, "
              + "such as not being able to access the network.");
      System.out.println("Error Message: " + ace.getMessage());
    }
  }