Skip to content

Commit

Permalink
TEIID-1070: couple minor corrections not to add the data, rather repl…
Browse files Browse the repository at this point in the history
…ace or create it; ability to create domains if not existing
  • Loading branch information
rareddy committed Apr 10, 2014
1 parent 37a4e05 commit 70cf1f6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 10 deletions.
Expand Up @@ -40,6 +40,7 @@

public class SimpleDBConnectionImpl extends BasicConnection implements SimpleDBConnection {
private AmazonSimpleDBClient client;
private List<String> domains;

public SimpleDBConnectionImpl(String accessKey, String secretAccessKey) {
this.client = new AmazonSimpleDBClient(new BasicAWSCredentials(accessKey, secretAccessKey));
Expand All @@ -64,6 +65,9 @@ public void createDomain(String domainName) throws TranslatorException {
public void deleteDomain(String domainName) throws TranslatorException {
try {
this.client.deleteDomain(new DeleteDomainRequest(domainName));
if (this.domains.contains(domainName)) {
this.domains.remove(domainName);
}
} catch (AmazonServiceException e) {
throw new TranslatorException(e);
} catch (AmazonClientException e) {
Expand Down Expand Up @@ -138,6 +142,7 @@ public SelectResult performSelect(String selectExpression, String nextToken) thr
if (nextToken != null) {
selectRequest.setNextToken(nextToken);
}
selectRequest.setConsistentRead(true);
return client.select(selectRequest);
} catch (AmazonServiceException e) {
throw new TranslatorException(e);
Expand All @@ -156,7 +161,7 @@ public int performUpdate(String domainName, Map<String, Object> updateAttributes
try {
List<ReplaceableAttribute> attributes = new ArrayList<ReplaceableAttribute>();
for (Map.Entry<String, Object> column : updateAttributes.entrySet()) {
addAttribute(column.getKey(), column.getValue(), true, attributes);
addAttribute(column.getKey(), column.getValue(), attributes);
}

List<ReplaceableItem> updateItems = new ArrayList<ReplaceableItem>();
Expand Down Expand Up @@ -195,6 +200,14 @@ public int performUpdate(String domainName, Map<String, Object> updateAttributes
@Override
public int performInsert(String domainName, List<Column> columns, Iterator<? extends List<?>> valueList) throws TranslatorException {
try {
if (this.domains == null) {
this.domains = getDomains();
}

if (!this.domains.contains(domainName)) {
createDomain(domainName);
}

int count = 0;
List<ReplaceableItem> insertItems = new ArrayList<ReplaceableItem>();
while(valueList.hasNext()) {
Expand Down Expand Up @@ -237,22 +250,18 @@ private void executeBatch(String domainName, List<ReplaceableItem> insertItems)
this.client.batchPutAttributes(request);
}
}

private void addAttribute(String name, Object value, List<ReplaceableAttribute> attributes) {
addAttribute(name, value, false, attributes);
}

private void addAttribute(String name, Object value, boolean replace, List<ReplaceableAttribute> attributes) {
private void addAttribute(String name, Object value, List<ReplaceableAttribute> attributes) {
if (value.getClass().isArray()) {
String[] values = (String[])value;
for (int i = 0; i < values.length; i++) {
addAttribute(name, values[i], replace, attributes);
addAttribute(name, values[i], attributes);
}
}
else {
ReplaceableAttribute attribute = new ReplaceableAttribute();
attribute.setName(name);
attribute.setReplace(replace);
attribute.setReplace(true);
attribute.setValue((String)value);
attributes.add(attribute);
}
Expand Down
Expand Up @@ -50,7 +50,6 @@ public void execute() throws TranslatorException {
// this is domain delete. otherwise this could be lot of items. deleted count can
// not be measured.
this.connection.deleteDomain(domainName);
this.connection.createDomain(domainName);
}
}

Expand Down
Expand Up @@ -140,7 +140,6 @@ public void testDeleteAll() throws Exception {
exec.execute();

Mockito.verify(connection).deleteDomain("item");
Mockito.verify(connection).createDomain("item");
}

@Test
Expand Down

0 comments on commit 70cf1f6

Please sign in to comment.