写入DynamoDB的数据未显示在表

时间:2016-10-31 07:41:12

标签: amazon-dynamodb nosql

我希望有人可以帮助我。我正在向dynamoDB写入数据,该数据执行没有错误,但数据不会显示在dynamoDB表上。该表如下:

@DynamoDBTable(tableName = "*table name")

public class AttractionsLibraryDO {
  private String _attractionName;
  private String _attractionCategory;
  private String _attractionCountry;
  private String _attractionDate;
  private String _attractionDescription;
  private Double _attractionEntrance;
  private String _attractionGps;
  private String _attractionLocation;
  private String _attractionPicture;
  private Double _attractionRating;
  private String _attractionToken;
  private Double _attractionVisits;

@DynamoDBHashKey(attributeName = "Attraction_name")
public String getAttractionName() {
    return _attractionName;
}

public void setAttractionName(final String _attractionName) {
    this._attractionName = _attractionName;
}

@DynamoDBAttribute(attributeName = "Attraction_category")
public String getAttractionCategory() {
    return _attractionCategory;
}

public void setAttractionCategory(final String _attractionCategory) {
    this._attractionCategory = _attractionCategory;
}
@DynamoDBAttribute(attributeName = "Attraction_country")
public String getAttractionCountry() {
    return _attractionCountry;
}

public void setAttractionCountry(final String _attractionCountry) {
    this._attractionCountry = _attractionCountry;
}
@DynamoDBAttribute(attributeName = "Attraction_date")
public String getAttractionDate() {
    return _attractionDate;
}

public void setAttractionDate(final String _attractionDate) {
    this._attractionDate = _attractionDate;
}
@DynamoDBAttribute(attributeName = "Attraction_description")
public String getAttractionDescription() {
    return _attractionDescription;
}

public void setAttractionDescription(final String _attractionDescription) {
    this._attractionDescription = _attractionDescription;
}
@DynamoDBAttribute(attributeName = "Attraction_entrance")
public Double getAttractionEntrance() {
    return _attractionEntrance;
}

public void setAttractionEntrance(final Double _attractionEntrance) {
    this._attractionEntrance = _attractionEntrance;
}
@DynamoDBAttribute(attributeName = "Attraction_gps")
public String getAttractionGps() {
    return _attractionGps;
}

public void setAttractionGps(final String _attractionGps) {
    this._attractionGps = _attractionGps;
}
@DynamoDBAttribute(attributeName = "Attraction_location")
public String getAttractionLocation() {
    return _attractionLocation;
}

public void setAttractionLocation(final String _attractionLocation) {
    this._attractionLocation = _attractionLocation;
}
@DynamoDBAttribute(attributeName = "Attraction_picture")
public String getAttractionPicture() {
    return _attractionPicture;
}

public void setAttractionPicture(final String _attractionPicture) {
    this._attractionPicture = _attractionPicture;
}
@DynamoDBAttribute(attributeName = "Attraction_rating")
public Double getAttractionRating() {
    return _attractionRating;
}

public void setAttractionRating(final Double _attractionRating) {
    this._attractionRating = _attractionRating;
}
@DynamoDBAttribute(attributeName = "Attraction_token")
public String getAttractionToken() {
    return _attractionToken;
}

public void setAttractionToken(final String _attractionToken) {
    this._attractionToken = _attractionToken;
}
@DynamoDBAttribute(attributeName = "Attraction_visits")
public Double getAttractionVisits() {
    return _attractionVisits;
}

public void setAttractionVisits(final Double _attractionVisits) {
    this._attractionVisits = _attractionVisits;
}
}

我将数据写入数据库,如下所示:

 public class AddAttraction extends AppCompatActivity {
   protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_add_attraction);

    CognitoCachingCredentialsProvider credentialsProvider = new CognitoCachingCredentialsProvider(
            getApplicationContext(), // Context
            "*Cognito identity pool id", // Identity Pool ID
            Regions.EU_WEST_1 // Region
    );
    AmazonDynamoDBClient ddbClient = new AmazonDynamoDBClient(credentialsProvider);
    final DynamoDBMapper dynamoDBMapper = new DynamoDBMapper(ddbClient);
    final AttractionsLibraryDO attractions_Library = new AttractionsLibraryDO();

    SUBMIT = (Button)findViewById(R.id.button_submit_attraction);
    SUBMIT.setOnClickListener(new View.OnClickListener() 
    {
        @Override
        public void onClick(View v) 
           {
           writeToDynamoDB(attractions_Library, dynamoDBMapper);
           }
    });

}


public Thread writeToDynamoDB(final AttractionsLibraryDO attractions, final DynamoDBMapper dynamoDBMapper) {


        Runnable runnableWrite = new Runnable() {
            public void run() {
                try {
                    Log.d("Event:", "Writing to DynamoDB.");
                    attractions.setAttractionCategory("String");
                    attractions.setAttractionRating(int);
                    attractions.setAttractionCountry("String");
                    attractions.setAttractionDate("String");
                    attractions.setAttractionEntrance(int);
                    attractions.setAttractionGps("String");
                    attractions.setAttractionLocation("String");
                    attractions.setAttractionName("String");
                    attractions.setAttractionPicture("String");
                    attractions.setAttractionToken("String");
                    attractions.setAttractionDescription("String");
                    attractions.setAttractionVisits(int);

                    AmazonClientException lastException = null;
                        dynamoDBMapper.save(attractions);
                    Log.d("Event:", "Writing to DynamoDB done.");
                    } catch (final AmazonClientException ex) {
                        Log.d("Error", "Failed saving item : " + ex.getMessage(), ex);

                    }
                }
        };
        Thread t = new Thread(runnableWrite);
        t.start();
        return null;

}
}

数据没有出现在dynamoDB上,也没有写入dynamoDB。并写入dynamoDB完成。已记录。问题可能是使用了错误的表名(我已经对此进行了两次检查)?我不知道这是否重要,但还记录了以下行:

 I/System.out: (HTTPLog)-Static: isSBSettingEnabled false

我的想法用完了,请帮忙。 提前谢谢。

1 个答案:

答案 0 :(得分:0)

由于您的表位于“eu-west-1”,而不是默认的“us-east-1”,因此您需要显式设置DynamoDB客户端的区域。

根据您的评论,您需要添加以下行:

ddbClient.setRegion(Region.getRegion(Regions.EU_WEST_1));