From 6d40c0ddf853ce1c380c7d03fb889dd6c59b2679 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 29 Jul 2020 13:43:24 -0400 Subject: [PATCH 1/6] renaming with Table prefix --- .../com/azure/data/tables/AzureTable.java | 31 ------- .../azure/data/tables/TableAsyncClient.java | 92 +++++++++---------- ...derHelper.java => TableBuilderHelper.java} | 2 +- .../com/azure/data/tables/TableClient.java | 56 +++++------ .../azure/data/tables/TableClientBuilder.java | 2 +- .../data/tables/TableServiceAsyncClient.java | 40 ++++---- .../azure/data/tables/TableServiceClient.java | 12 +-- .../tables/TableServiceClientBuilder.java | 2 +- .../{UpdateMode.java => TableUpdateMode.java} | 2 +- .../tables/implementation/EntityHelper.java | 10 +- .../models/{Table.java => AzureTable.java} | 4 +- .../models/{Entity.java => TableEntity.java} | 10 +- ...QueryParams.java => TableQueryParams.java} | 8 +- .../{UpdateMode.java => TableUpdateMode.java} | 2 +- .../TableServiceAsyncClientCodeSnippets.java | 14 +-- .../java/TableServiceClientCodeSnippets.java | 30 +++--- .../tables/TableServiceAsyncClientTest.java | 4 +- .../data/tables/TableServiceClientTest.java | 4 +- .../data/tables/TablesAsyncClientTest.java | 57 ++++++------ 19 files changed, 177 insertions(+), 205 deletions(-) delete mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTable.java rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{BuilderHelper.java => TableBuilderHelper.java} (99%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{UpdateMode.java => TableUpdateMode.java} (87%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/{Table.java => AzureTable.java} (87%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/{Entity.java => TableEntity.java} (91%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/{QueryParams.java => TableQueryParams.java} (90%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/{UpdateMode.java => TableUpdateMode.java} (87%) diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTable.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTable.java deleted file mode 100644 index 98cbc85982034..0000000000000 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTable.java +++ /dev/null @@ -1,31 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -package com.azure.data.tables; - -/** - * class for a table object - */ -public class AzureTable { - private final String name; - - AzureTable(String name) { - this.name = name; - } - - /** - * returns the name of this table - * - * @return table name - */ - public String getName() { - return name; - } - - /** - * returns the associated table client or null if it doesn't exist - * @return the associated table client - */ - public TableClient getClient() { - return null; - } -} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java index d8b915c0f816d..3f5d1f3cfb7a5 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java @@ -26,10 +26,10 @@ import com.azure.data.tables.implementation.models.ResponseFormat; import com.azure.data.tables.implementation.models.TableEntityQueryResponse; import com.azure.data.tables.implementation.models.TableProperties; -import com.azure.data.tables.models.Entity; -import com.azure.data.tables.models.QueryParams; -import com.azure.data.tables.models.Table; -import com.azure.data.tables.models.UpdateMode; +import com.azure.data.tables.models.TableEntity; +import com.azure.data.tables.models.TableQueryParams; +import com.azure.data.tables.models.AzureTable; +import com.azure.data.tables.models.TableUpdateMode; import reactor.core.publisher.Mono; import java.net.URI; @@ -126,7 +126,7 @@ public TablesServiceVersion getApiVersion() { * * @return a table */ - public Mono create() { + public Mono create() { return createWithResponse().flatMap(response -> Mono.justOrEmpty(response.getValue())); } @@ -135,7 +135,7 @@ public Mono
create() { * * @return a table */ - public Mono> createWithResponse() { + public Mono> createWithResponse() { return withContext(context -> createWithResponse(context)); } @@ -146,10 +146,10 @@ public Mono> createWithResponse() { * * @return a table */ - Mono> createWithResponse(Context context) { + Mono> createWithResponse(Context context) { return tableImplementation.createWithResponseAsync(new TableProperties().setTableName(tableName), null, ResponseFormat.RETURN_CONTENT, null, context).map(response -> { - Table table = response.getValue() == null ? null : new Table(response.getValue().getTableName()); + AzureTable table = response.getValue() == null ? null : new AzureTable(response.getValue().getTableName()); return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), table); }); @@ -164,7 +164,7 @@ Mono> createWithResponse(Context context) { * @return the created TableEntity */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono createEntity(Entity entity) { + public Mono createEntity(TableEntity entity) { return createEntityWithResponse(entity).flatMap(response -> Mono.justOrEmpty(response.getValue())); } @@ -177,16 +177,16 @@ public Mono createEntity(Entity entity) { * @return a mono of the response with the TableEntity */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> createEntityWithResponse(Entity entity) { + public Mono> createEntityWithResponse(TableEntity entity) { return withContext(context -> createEntityWithResponse(entity, context)); } - Mono> createEntityWithResponse(Entity entity, Context context) { + Mono> createEntityWithResponse(TableEntity entity, Context context) { return tableImplementation.insertEntityWithResponseAsync(tableName, null, null, ResponseFormat.RETURN_CONTENT, entity.getProperties(), null, context).map(response -> { - final Entity createdEntity = deserializeEntity(logger, response.getValue()); + final TableEntity createdEntity = deserializeEntity(logger, response.getValue()); return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), createdEntity); }); @@ -200,7 +200,7 @@ Mono> createEntityWithResponse(Entity entity, Context context) * @return void */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono upsertEntity(Entity entity) { + public Mono upsertEntity(TableEntity entity) { return upsertEntityWithResponse(entity, null).flatMap(response -> Mono.justOrEmpty(response.getValue())); } @@ -213,7 +213,7 @@ public Mono upsertEntity(Entity entity) { * @return void */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono upsertEntity(Entity entity, UpdateMode updateMode) { + public Mono upsertEntity(TableEntity entity, TableUpdateMode updateMode) { return upsertEntityWithResponse(entity, updateMode).flatMap(response -> Mono.justOrEmpty(response.getValue())); } @@ -226,17 +226,17 @@ public Mono upsertEntity(Entity entity, UpdateMode updateMode) { * @return a response */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> upsertEntityWithResponse(Entity entity, UpdateMode updateMode) { + public Mono> upsertEntityWithResponse(TableEntity entity, TableUpdateMode updateMode) { return withContext(context -> upsertEntityWithResponse(entity, updateMode, null, context)); } - Mono> upsertEntityWithResponse(Entity entity, UpdateMode updateMode, Duration timeout, + Mono> upsertEntityWithResponse(TableEntity entity, TableUpdateMode updateMode, Duration timeout, Context context) { Integer timeoutInt = timeout == null ? null : (int) timeout.getSeconds(); if (entity == null) { return monoError(logger, new NullPointerException("TableEntity cannot be null")); } - if (updateMode == UpdateMode.REPLACE) { + if (updateMode == TableUpdateMode.REPLACE) { return tableImplementation.updateEntityWithResponseAsync(tableName, entity.getPartitionKey(), entity.getRowKey(), timeoutInt, null, "*", entity.getProperties(), null, context).map(response -> { @@ -262,7 +262,7 @@ Mono> upsertEntityWithResponse(Entity entity, UpdateMode updateMo * @return void */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono updateEntity(Entity entity) { + public Mono updateEntity(TableEntity entity) { //TODO: merge or throw an error if it cannot be found return Mono.empty(); } @@ -275,7 +275,7 @@ public Mono updateEntity(Entity entity) { * * @return void */ - public Mono updateEntity(Entity entity, UpdateMode updateMode) { + public Mono updateEntity(TableEntity entity, TableUpdateMode updateMode) { return updateEntity(entity, false, updateMode); } @@ -290,7 +290,7 @@ public Mono updateEntity(Entity entity, UpdateMode updateMode) { * @return void */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono updateEntity(Entity entity, boolean ifUnchanged, UpdateMode updateMode) { + public Mono updateEntity(TableEntity entity, boolean ifUnchanged, TableUpdateMode updateMode) { return updateEntityWithResponse(entity, ifUnchanged, updateMode).flatMap(response -> Mono.justOrEmpty(response.getValue())); } @@ -306,14 +306,14 @@ public Mono updateEntity(Entity entity, boolean ifUnchanged, UpdateMode up * @return a response */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> updateEntityWithResponse(Entity entity, boolean ifUnchanged, UpdateMode updateMode) { + public Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnchanged, TableUpdateMode updateMode) { return withContext(context -> updateEntityWithResponse(entity, ifUnchanged, updateMode, null, context)); } - Mono> updateEntityWithResponse(Entity entity, boolean ifUnchanged, UpdateMode updateMode, + Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnchanged, TableUpdateMode updateMode, Duration timeout, Context context) { Integer timeoutInt = timeout == null ? null : (int) timeout.getSeconds(); - if (updateMode == null || updateMode == UpdateMode.MERGE) { + if (updateMode == null || updateMode == TableUpdateMode.MERGE) { if (ifUnchanged) { return tableImplementation.mergeEntityWithResponseAsync(tableName, entity.getPartitionKey(), entity.getRowKey(), timeoutInt, null, entity.getETag(), entity.getProperties(), null, @@ -363,7 +363,7 @@ Mono> updateEntityWithResponse(Entity entity, boolean ifUnchanged * @return void */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono deleteEntity(Entity entity) { + public Mono deleteEntity(TableEntity entity) { return deleteEntity(entity, false); } @@ -376,7 +376,7 @@ public Mono deleteEntity(Entity entity) { * @return void */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono deleteEntity(Entity entity, boolean ifUnchanged) { + public Mono deleteEntity(TableEntity entity, boolean ifUnchanged) { return deleteEntityWithResponse(entity, ifUnchanged).then(); } @@ -389,11 +389,11 @@ public Mono deleteEntity(Entity entity, boolean ifUnchanged) { * @return a response */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> deleteEntityWithResponse(Entity entity, boolean ifUnchanged) { + public Mono> deleteEntityWithResponse(TableEntity entity, boolean ifUnchanged) { return withContext(context -> deleteEntityWithResponse(entity, ifUnchanged, null, context)); } - Mono> deleteEntityWithResponse(Entity entity, boolean ifUnchanged, Duration timeout, + Mono> deleteEntityWithResponse(TableEntity entity, boolean ifUnchanged, Duration timeout, Context context) { String matchParam = ifUnchanged ? entity.getETag() : "*"; Integer timeoutInt = timeout == null ? null : (int) timeout.getSeconds(); @@ -412,8 +412,8 @@ Mono> deleteEntityWithResponse(Entity entity, boolean ifUnchanged * @return a paged flux of all the entity which fit this criteria */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux listEntities() { - return listEntities(new QueryParams()); + public PagedFlux listEntities() { + return listEntities(new TableQueryParams()); } /** @@ -424,20 +424,20 @@ public PagedFlux listEntities() { * @return a paged flux of all the entity which fit this criteria */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux listEntities(QueryParams queryParams) { + public PagedFlux listEntities(TableQueryParams queryParams) { return new PagedFlux<>( () -> withContext(context -> listFirstPageEntities(context, queryParams)), token -> withContext(context -> listNextPageEntities(token, context, queryParams))); } //802 - PagedFlux listTables(QueryParams queryParams, Context context) { + PagedFlux listTables(TableQueryParams queryParams, Context context) { return new PagedFlux<>( () -> listFirstPageEntities(context, queryParams), token -> listNextPageEntities(token, context, queryParams)); } //802 - private Mono> listFirstPageEntities(Context context, QueryParams queryParams) { + private Mono> listFirstPageEntities(Context context, TableQueryParams queryParams) { try { return listTables(null, null, context, queryParams); } catch (RuntimeException e) { @@ -445,7 +445,7 @@ private Mono> listFirstPageEntities(Context context, Query } } //1459 - private Mono> listNextPageEntities(String token, Context context, QueryParams queryParams) { + private Mono> listNextPageEntities(String token, Context context, TableQueryParams queryParams) { if (token == null) { return Mono.empty(); } @@ -463,8 +463,8 @@ private Mono> listNextPageEntities(String token, Context c } } //1459 - private Mono> listTables(String nextPartitionKey, String nextRowKey, Context context, - QueryParams queryParams) { + private Mono> listTables(String nextPartitionKey, String nextRowKey, Context context, + TableQueryParams queryParams) { QueryOptions queryOptions = new QueryOptions() .setFilter(queryParams.getFilter()) .setTop(queryParams.getTop()) @@ -483,7 +483,7 @@ private Mono> listTables(String nextPartitionKey, String n return Mono.empty(); } - final List entities = entityResponseValue.stream() + final List entities = entityResponseValue.stream() .map(entityMap -> deserializeEntity(logger, entityMap)) .collect(Collectors.toList()); @@ -494,12 +494,12 @@ private Mono> listTables(String nextPartitionKey, String n }); } //1836 - private static class EntityPaged implements PagedResponse { + private static class EntityPaged implements PagedResponse { private final Response httpResponse; - private final IterableStream entityStream; + private final IterableStream entityStream; private final String continuationToken; - EntityPaged(Response httpResponse, List entityList, String nextPartitionKey, + EntityPaged(Response httpResponse, List entityList, String nextPartitionKey, String nextRowKey) { if (nextPartitionKey == null || nextRowKey == null) { this.continuationToken = null; @@ -526,7 +526,7 @@ public HttpRequest getRequest() { } @Override - public IterableStream getElements() { + public IterableStream getElements() { return entityStream; } @@ -549,7 +549,7 @@ public void close() { * @return a mono of the table entity */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono getEntity(String partitionKey, String rowKey) { + public Mono getEntity(String partitionKey, String rowKey) { return getEntityWithResponse(partitionKey, rowKey).flatMap(response -> Mono.justOrEmpty(response.getValue())); } @@ -563,11 +563,11 @@ public Mono getEntity(String partitionKey, String rowKey) { * @return a mono of the response with the table entity */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> getEntityWithResponse(String partitionKey, String rowKey) { + public Mono> getEntityWithResponse(String partitionKey, String rowKey) { return withContext(context -> getEntityWithResponse(partitionKey, rowKey, defaultQueryOptions, context)); } - Mono> getEntityWithResponse(String partitionKey, String rowKey, QueryOptions queryOptions, + Mono> getEntityWithResponse(String partitionKey, String rowKey, QueryOptions queryOptions, Context context) { return tableImplementation.queryEntitiesWithPartitionAndRowKeyWithResponseAsync(tableName, partitionKey, @@ -597,7 +597,7 @@ Mono> getEntityWithResponse(String partitionKey, String rowKey, // Deserialize the first entity. // TODO: Potentially update logic to deserialize them all. - final Entity entity = deserializeEntity(logger, matchingEntities.get(0)); + final TableEntity entity = deserializeEntity(logger, matchingEntities.get(0)); sink.next(new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), entity)); }); @@ -612,7 +612,7 @@ Mono> getEntityWithResponse(String partitionKey, String rowKey, * @throws IllegalArgumentException if the Map is missing a row key or partition key. * @throws NullPointerException if 'properties' is null. */ - private static Entity deserializeEntity(ClientLogger logger, Map properties) { + private static TableEntity deserializeEntity(ClientLogger logger, Map properties) { final Object partitionKeyValue = properties.get(PARTITION_KEY); if (!(partitionKeyValue instanceof String) || ((String) partitionKeyValue).isEmpty()) { throw logger.logExceptionAsError(new IllegalArgumentException(String.format( @@ -625,7 +625,7 @@ private static Entity deserializeEntity(ClientLogger logger, Map "'%s' does not exist in property map or is an empty value.", ROW_KEY))); } - final Entity entity = new Entity((String) partitionKeyValue, (String) rowKeyValue); + final TableEntity entity = new TableEntity((String) partitionKeyValue, (String) rowKeyValue); properties.forEach((key, value) -> { if (key.equals(TableConstants.ETAG_KEY)) { EntityHelper.setETag(entity, String.valueOf(value)); diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/BuilderHelper.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableBuilderHelper.java similarity index 99% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/BuilderHelper.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableBuilderHelper.java index 1258c08ca8941..cf4eb43ad8e19 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/BuilderHelper.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableBuilderHelper.java @@ -31,7 +31,7 @@ import java.util.List; import java.util.Map; -class BuilderHelper { +class TableBuilderHelper { private static final Map PROPERTIES = CoreUtils.getProperties("azure-data-tables.properties"); private static final String SDK_NAME = "name"; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java index a7afee1b6b841..249a72a8d171e 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java @@ -9,10 +9,10 @@ import com.azure.core.http.rest.Response; import com.azure.core.util.Context; import com.azure.data.tables.implementation.models.QueryOptions; -import com.azure.data.tables.models.Entity; -import com.azure.data.tables.models.QueryParams; -import com.azure.data.tables.models.Table; -import com.azure.data.tables.models.UpdateMode; +import com.azure.data.tables.models.TableEntity; +import com.azure.data.tables.models.TableQueryParams; +import com.azure.data.tables.models.AzureTable; +import com.azure.data.tables.models.TableUpdateMode; import java.time.Duration; /** @@ -70,7 +70,7 @@ public TablesServiceVersion getApiVersion() { * * @return a table */ - public Table create() { + public AzureTable create() { return client.create().block(); } @@ -80,7 +80,7 @@ public Table create() { * @param timeout Duration to wait for operation to complete. * @return a table */ - public Table create(Duration timeout) { + public AzureTable create(Duration timeout) { return client.create().block(timeout); } @@ -91,7 +91,7 @@ public Table create(Duration timeout) { * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return HTTP response containing the created table. */ - public Response
createWithResponse(Duration timeout, Context context) { + public Response createWithResponse(Duration timeout, Context context) { return client.createWithResponse(context).block(timeout); } @@ -103,7 +103,7 @@ public Response
createWithResponse(Duration timeout, Context context) { * @return the created TableEntity */ @ServiceMethod(returns = ReturnType.SINGLE) - public Entity createEntity(Entity tableEntity) { + public TableEntity createEntity(TableEntity tableEntity) { return client.createEntity(tableEntity).block(); } @@ -116,7 +116,7 @@ public Entity createEntity(Entity tableEntity) { * @return the created TableEntity */ @ServiceMethod(returns = ReturnType.SINGLE) - public Entity createEntity(Entity tableEntity, Duration timeout) { + public TableEntity createEntity(TableEntity tableEntity, Duration timeout) { return createEntityWithResponse(tableEntity, timeout, null).getValue(); } @@ -130,7 +130,7 @@ public Entity createEntity(Entity tableEntity, Duration timeout) { * @return the created TableEntity in a response */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response createEntityWithResponse(Entity tableEntity, Duration timeout, Context context) { + public Response createEntityWithResponse(TableEntity tableEntity, Duration timeout, Context context) { return client.createEntityWithResponse(tableEntity, context).block(timeout); } @@ -140,7 +140,7 @@ public Response createEntityWithResponse(Entity tableEntity, Duration ti * @param entity entity to upsert */ @ServiceMethod(returns = ReturnType.SINGLE) - public void upsertEntity(Entity entity) { + public void upsertEntity(TableEntity entity) { client.upsertEntity(entity).block(); } @@ -151,7 +151,7 @@ public void upsertEntity(Entity entity) { * @param entity entity to upsert */ @ServiceMethod(returns = ReturnType.SINGLE) - public void upsertEntity(Entity entity, UpdateMode updateMode) { + public void upsertEntity(TableEntity entity, TableUpdateMode updateMode) { client.upsertEntity(entity, updateMode).block(); } @@ -163,7 +163,7 @@ public void upsertEntity(Entity entity, UpdateMode updateMode) { * @param timeout max time for query to execute before erroring out */ @ServiceMethod(returns = ReturnType.SINGLE) - public void upsertEntity(Entity entity, UpdateMode updateMode, Duration timeout) { + public void upsertEntity(TableEntity entity, TableUpdateMode updateMode, Duration timeout) { upsertEntityWithResponse(entity, updateMode, timeout, null).getValue(); } @@ -177,7 +177,7 @@ public void upsertEntity(Entity entity, UpdateMode updateMode, Duration timeout) * @return a response */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response upsertEntityWithResponse(Entity entity, UpdateMode updateMode, Duration timeout, + public Response upsertEntityWithResponse(TableEntity entity, TableUpdateMode updateMode, Duration timeout, Context context) { return client.upsertEntityWithResponse(entity, updateMode, timeout, context).block(); } @@ -189,7 +189,7 @@ public Response upsertEntityWithResponse(Entity entity, UpdateMode updateM * @param entity the entity to update */ @ServiceMethod(returns = ReturnType.SINGLE) - public void updateEntity(Entity entity) { + public void updateEntity(TableEntity entity) { client.upsertEntity(entity).block(); } @@ -201,7 +201,7 @@ public void updateEntity(Entity entity) { * @param entity the entity to update */ @ServiceMethod(returns = ReturnType.SINGLE) - public void updateEntity(Entity entity, UpdateMode updateMode) { + public void updateEntity(TableEntity entity, TableUpdateMode updateMode) { client.updateEntity(entity, updateMode).block(); } @@ -214,7 +214,7 @@ public void updateEntity(Entity entity, UpdateMode updateMode) { * @param ifUnchanged if the eTag of the entity must match the entity in the service or not */ @ServiceMethod(returns = ReturnType.SINGLE) - public void updateEntity(Entity entity, boolean ifUnchanged, UpdateMode updateMode) { + public void updateEntity(TableEntity entity, boolean ifUnchanged, TableUpdateMode updateMode) { client.updateEntity(entity, ifUnchanged, updateMode).block(); } @@ -228,7 +228,7 @@ public void updateEntity(Entity entity, boolean ifUnchanged, UpdateMode updateMo * @param timeout max time for query to execute before erroring out */ @ServiceMethod(returns = ReturnType.SINGLE) - public void updateEntity(Entity entity, boolean ifUnchanged, UpdateMode updateMode, Duration timeout) { + public void updateEntity(TableEntity entity, boolean ifUnchanged, TableUpdateMode updateMode, Duration timeout) { updateEntityWithResponse(entity, ifUnchanged, updateMode, timeout, null).getValue(); } @@ -244,7 +244,7 @@ public void updateEntity(Entity entity, boolean ifUnchanged, UpdateMode updateMo * @return a response */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response updateEntityWithResponse(Entity entity, boolean ifUnchanged, UpdateMode updateMode, + public Response updateEntityWithResponse(TableEntity entity, boolean ifUnchanged, TableUpdateMode updateMode, Duration timeout, Context context) { return client.updateEntityWithResponse(entity, ifUnchanged, updateMode, timeout, context).block(); } @@ -255,7 +255,7 @@ public Response updateEntityWithResponse(Entity entity, boolean ifUnchange * @param entity entity to delete */ @ServiceMethod(returns = ReturnType.SINGLE) - public void deleteEntity(Entity entity) { + public void deleteEntity(TableEntity entity) { client.deleteEntity(entity).block(); } @@ -266,7 +266,7 @@ public void deleteEntity(Entity entity) { * @param ifUnchanged if the eTag of the entity must match the entity in the service or not */ @ServiceMethod(returns = ReturnType.SINGLE) - public void deleteEntity(Entity entity, boolean ifUnchanged) { + public void deleteEntity(TableEntity entity, boolean ifUnchanged) { client.deleteEntity(entity, ifUnchanged).block(); } @@ -278,7 +278,7 @@ public void deleteEntity(Entity entity, boolean ifUnchanged) { * @param timeout max time for query to execute before erroring out */ @ServiceMethod(returns = ReturnType.SINGLE) - public void deleteEntity(Entity entity, boolean ifUnchanged, Duration timeout) { + public void deleteEntity(TableEntity entity, boolean ifUnchanged, Duration timeout) { deleteEntityWithResponse(entity, ifUnchanged, timeout, null); } @@ -292,7 +292,7 @@ public void deleteEntity(Entity entity, boolean ifUnchanged, Duration timeout) { * @return a response */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response deleteEntityWithResponse(Entity entity, boolean ifUnchanged, Duration timeout, + public Response deleteEntityWithResponse(TableEntity entity, boolean ifUnchanged, Duration timeout, Context context) { return client.deleteEntityWithResponse(entity, ifUnchanged, timeout, context).block(); } @@ -303,7 +303,7 @@ public Response deleteEntityWithResponse(Entity entity, boolean ifUnchange * @return a list of the tables that fit the query */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable listEntities() { + public PagedIterable listEntities() { return new PagedIterable<>(client.listEntities()); } @@ -314,7 +314,7 @@ public PagedIterable listEntities() { * @return a list of the tables that fit the query */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable listEntities(QueryParams queryOptions) { + public PagedIterable listEntities(TableQueryParams queryOptions) { return new PagedIterable<>(client.listEntities(queryOptions)); } @@ -326,7 +326,7 @@ public PagedIterable listEntities(QueryParams queryOptions) { * @return a list of the tables that fit the query */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable listEntities(QueryParams queryOptions, Duration timeout) { + public PagedIterable listEntities(TableQueryParams queryOptions, Duration timeout) { return null; } @@ -338,7 +338,7 @@ public PagedIterable listEntities(QueryParams queryOptions, Duration tim * @return the table entity */ @ServiceMethod(returns = ReturnType.SINGLE) - public Entity getEntity(String partitionKey, String rowKey) { + public TableEntity getEntity(String partitionKey, String rowKey) { return client.getEntity(partitionKey, rowKey).block(); } @@ -351,7 +351,7 @@ public Entity getEntity(String partitionKey, String rowKey) { * @return a mono of the response with the table entity */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response getEntityWithResponse(String partitionKey, String rowKey, Context context) { + public Response getEntityWithResponse(String partitionKey, String rowKey, Context context) { return client.getEntityWithResponse(partitionKey, rowKey, new QueryOptions(), context).block(); } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java index 0f3ee4af7f135..641df26d63d5d 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java @@ -109,7 +109,7 @@ public TableClient buildClient() { public TableAsyncClient buildAsyncClient() { TablesServiceVersion serviceVersion = version != null ? version : TablesServiceVersion.getLatest(); - HttpPipeline pipeline = (httpPipeline != null) ? httpPipeline : BuilderHelper.buildPipeline( + HttpPipeline pipeline = (httpPipeline != null) ? httpPipeline : TableBuilderHelper.buildPipeline( (TablesSharedKeyCredential) tokenCredential, tokenCredential, sasTokenCredential, endpoint, retryOptions, httpLogOptions, httpClient, policies, configuration, logger); diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java index fdd77886772d1..a3ed349da9fca 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java @@ -24,8 +24,8 @@ import com.azure.data.tables.implementation.models.TableProperties; import com.azure.data.tables.implementation.models.TableQueryResponse; import com.azure.data.tables.implementation.models.TableResponseProperties; -import com.azure.data.tables.models.QueryParams; -import com.azure.data.tables.models.Table; +import com.azure.data.tables.models.TableQueryParams; +import com.azure.data.tables.models.AzureTable; import java.net.URI; import java.util.List; import java.util.stream.Collectors; @@ -76,7 +76,7 @@ public TableAsyncClient getTableAsyncClient(String tableName) { * @param name the name of the table * @return associated azure table object */ - public Table getTable(String name) { + public AzureTable getTable(String name) { return null; //TODO: idk how to do this one } @@ -87,7 +87,7 @@ public Table getTable(String name) { * @return the azure table object for the created table */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono
createTable(String tableName) { + public Mono createTable(String tableName) { return createTableWithResponse(tableName).flatMap(response -> Mono.justOrEmpty(response.getValue())); } @@ -98,11 +98,11 @@ public Mono
createTable(String tableName) { * @return a response wth the azure table object for the created table */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> createTableWithResponse(String tableName) { + public Mono> createTableWithResponse(String tableName) { return withContext(context -> createTableWithResponse(tableName, context)); } - Mono> createTableWithResponse(String tableName, Context context) { + Mono> createTableWithResponse(String tableName, Context context) { context = context == null ? Context.NONE : context; final TableProperties properties = new TableProperties().setTableName(tableName); @@ -111,7 +111,7 @@ Mono> createTableWithResponse(String tableName, Context context) null, ResponseFormat.RETURN_CONTENT, null, context) .map(response -> { - final Table table = new Table(response.getValue().getTableName()); + final AzureTable table = new AzureTable(response.getValue().getTableName()); return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), table); }); @@ -155,8 +155,8 @@ Mono> deleteTableWithResponse(String tableName, Context context) * @return a flux of the tables that met this criteria */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux
listTables() { - return listTables(new QueryParams()); + public PagedFlux listTables() { + return listTables(new TableQueryParams()); } /** @@ -166,21 +166,21 @@ public PagedFlux
listTables() { * @return a flux of the tables that met this criteria */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedFlux
listTables(QueryParams queryParams) { + public PagedFlux listTables(TableQueryParams queryParams) { return new PagedFlux<>( () -> withContext(context -> listTablesFirstPage(context, queryParams)), token -> withContext(context -> listTablesNextPage(token, context, queryParams))); } //802 - PagedFlux
listTables(QueryParams queryParams, Context context) { + PagedFlux listTables(TableQueryParams queryParams, Context context) { return new PagedFlux<>( () -> listTablesFirstPage(context, queryParams), token -> listTablesNextPage(token, context, queryParams)); } //802 - private Mono> listTablesFirstPage(Context context, QueryParams queryParams) { + private Mono> listTablesFirstPage(Context context, TableQueryParams queryParams) { try { return listTables(null, context, queryParams); } catch (RuntimeException e) { @@ -188,7 +188,7 @@ private Mono> listTablesFirstPage(Context context, QueryPar } } //1459 - private Mono> listTablesNextPage(String token, Context context, QueryParams queryParams) { + private Mono> listTablesNextPage(String token, Context context, TableQueryParams queryParams) { try { return listTables(token, context, queryParams); } catch (RuntimeException e) { @@ -196,7 +196,7 @@ private Mono> listTablesNextPage(String token, Context cont } } //1459 - private Mono> listTables(String nextTableName, Context context, QueryParams queryParams) { + private Mono> listTables(String nextTableName, Context context, TableQueryParams queryParams) { QueryOptions queryOptions = new QueryOptions() .setFilter(queryParams.getFilter()) .setTop(queryParams.getTop()) @@ -212,9 +212,9 @@ private Mono> listTables(String nextTableName, Context cont if (tableResponsePropertiesList == null) { return Mono.empty(); } - final List
tables = tableResponsePropertiesList.stream() + final List tables = tableResponsePropertiesList.stream() .map(e -> { - Table table = new Table(e.getTableName()); + AzureTable table = new AzureTable(e.getTableName()); return table; }).collect(Collectors.toList()); @@ -225,12 +225,12 @@ private Mono> listTables(String nextTableName, Context cont } //1836 - private static class TablePaged implements PagedResponse
{ + private static class TablePaged implements PagedResponse { private final Response httpResponse; - private final IterableStream
tableStream; + private final IterableStream tableStream; private final String continuationToken; - TablePaged(Response httpResponse, List
tableList, String continuationToken) { + TablePaged(Response httpResponse, List tableList, String continuationToken) { this.httpResponse = httpResponse; this.tableStream = IterableStream.of(tableList); this.continuationToken = continuationToken; @@ -252,7 +252,7 @@ public HttpRequest getRequest() { } @Override - public IterableStream
getElements() { + public IterableStream getElements() { return tableStream; } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java index 86da535147757..bba2195295b6b 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java @@ -8,8 +8,8 @@ import com.azure.core.http.rest.PagedIterable; import com.azure.core.http.rest.Response; import com.azure.core.util.Context; -import com.azure.data.tables.models.QueryParams; -import com.azure.data.tables.models.Table; +import com.azure.data.tables.models.TableQueryParams; +import com.azure.data.tables.models.AzureTable; /** * client for table service @@ -29,7 +29,7 @@ public class TableServiceClient { * @param name the name of the table * @return associated azure table object */ - public Table getTable(String name) { + public AzureTable getTable(String name) { return null; } @@ -50,7 +50,7 @@ public TableClient getTableClient(String name) { * @return AzureTable of the created table */ @ServiceMethod(returns = ReturnType.SINGLE) - public Table createTable(String tableName) { + public AzureTable createTable(String tableName) { return client.createTable(tableName).block(); } @@ -62,7 +62,7 @@ public Table createTable(String tableName) { * @return response with azureTable of the created table */ @ServiceMethod(returns = ReturnType.SINGLE) - public Response
createTableWithResponse(String tableName, Context context) { + public Response createTableWithResponse(String tableName, Context context) { return client.createTableWithResponse(tableName, context).block(); } @@ -96,7 +96,7 @@ public Response deleteTableWithResponse(String tableName, Context context) * @return a list of tables that meet the query */ @ServiceMethod(returns = ReturnType.COLLECTION) - public PagedIterable
listTables(QueryParams queryParams) { + public PagedIterable listTables(TableQueryParams queryParams) { return new PagedIterable<>(client.listTables(queryParams)); } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientBuilder.java index dc87236035f43..0a3d8da7bf55c 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientBuilder.java @@ -69,7 +69,7 @@ public TableServiceAsyncClient buildAsyncClient() { TablesServiceVersion serviceVersion = version != null ? version : TablesServiceVersion.getLatest(); - HttpPipeline pipeline = (httpPipeline != null) ? httpPipeline : BuilderHelper.buildPipeline( + HttpPipeline pipeline = (httpPipeline != null) ? httpPipeline : TableBuilderHelper.buildPipeline( (TablesSharedKeyCredential) tokenCredential, tokenCredential, sasTokenCredential, endpoint, retryOptions, httpLogOptions, httpClient, policies, configuration, logger); diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/UpdateMode.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableUpdateMode.java similarity index 87% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/UpdateMode.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableUpdateMode.java index 8e990483add07..0fa8cdcce96f1 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/UpdateMode.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableUpdateMode.java @@ -5,7 +5,7 @@ /** * update type for update and upsert methods */ -public enum UpdateMode { +public enum TableUpdateMode { MERGE, REPLACE } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/EntityHelper.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/EntityHelper.java index f3258e5a9d494..a0d1f30fed72e 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/EntityHelper.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/EntityHelper.java @@ -3,7 +3,7 @@ package com.azure.data.tables.implementation; import com.azure.core.util.logging.ClientLogger; -import com.azure.data.tables.models.Entity; +import com.azure.data.tables.models.TableEntity; import java.util.Objects; @@ -40,12 +40,12 @@ public static void setEntityAccessor(EntityAccessor accessor) { } /** - * Sets the ETag on an {@link Entity}. + * Sets the ETag on an {@link TableEntity}. * * @param entity Entity to set the ETag on. * @param eTag ETag to set. */ - public static void setETag(Entity entity, String eTag) { + public static void setETag(TableEntity entity, String eTag) { if (entityAccessor == null) { throw new ClientLogger(EntityHelper.class).logExceptionAsError( new IllegalStateException("'entityAccessor' should not be null.")); @@ -56,11 +56,11 @@ public static void setETag(Entity entity, String eTag) { public interface EntityAccessor { /** - * Sets the ETag on an {@link Entity}. + * Sets the ETag on an {@link TableEntity}. * * @param entity Entity to set the ETag on. * @param eTag ETag to set. */ - void setETag(Entity entity, String eTag); + void setETag(TableEntity entity, String eTag); } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/Table.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/AzureTable.java similarity index 87% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/Table.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/AzureTable.java index b9122c5b79a78..cf8805b1633cc 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/Table.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/AzureTable.java @@ -5,14 +5,14 @@ /** * class for a table object */ -public class Table { +public class AzureTable { private final String name; /** * crete a table * @param name the name of the table */ - public Table(String name) { + public AzureTable(String name) { this.name = name; } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/Entity.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableEntity.java similarity index 91% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/Entity.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableEntity.java index 2f3bed527e908..45a8d7bd464c6 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/Entity.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableEntity.java @@ -18,8 +18,8 @@ * table entity class */ @Fluent -public class Entity { - private final ClientLogger logger = new ClientLogger(Entity.class); +public class TableEntity { + private final ClientLogger logger = new ClientLogger(TableEntity.class); private final String partitionKey; private final String rowKey; private final Map properties = new HashMap<>(); @@ -37,7 +37,7 @@ public class Entity { * @param partitionKey the partition key * @param rowKey the row key */ - public Entity(String partitionKey, String rowKey) { + public TableEntity(String partitionKey, String rowKey) { this.rowKey = Objects.requireNonNull(rowKey, "'rowKey' cannot be null."); this.partitionKey = Objects.requireNonNull(partitionKey, "'partitionKey' cannot be null."); Objects.requireNonNull(properties, "'properties' cannot be null."); @@ -61,10 +61,10 @@ public Map getProperties() { * @param key Key to for the property. * @param value Value of the property. * - * @return The updated {@link Entity} object. + * @return The updated {@link TableEntity} object. * @throws NullPointerException if {@code key} is null. */ - public Entity addProperty(String key, Object value) { + public TableEntity addProperty(String key, Object value) { Objects.requireNonNull(key, "'key' cannot be null."); if (PARTITION_KEY.equals(key)) { diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/QueryParams.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableQueryParams.java similarity index 90% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/QueryParams.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableQueryParams.java index 721ccfd1f4949..08d09d9cb2f3c 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/QueryParams.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableQueryParams.java @@ -9,7 +9,7 @@ * helps construct a query */ @Fluent -public final class QueryParams { +public final class TableQueryParams { private Integer top; private String select; private String filter; @@ -29,7 +29,7 @@ public Integer getTop() { * @param top the top value to set. * @return the QueryOptions object itself. */ - public QueryParams setTop(Integer top) { + public TableQueryParams setTop(Integer top) { this.top = top; return this; } @@ -51,7 +51,7 @@ public String getSelect() { * @param select the select value to set. * @return the QueryOptions object itself. */ - public QueryParams setSelect(String select) { + public TableQueryParams setSelect(String select) { this.select = select; return this; } @@ -71,7 +71,7 @@ public String getFilter() { * @param filter the filter value to set. * @return the QueryOptions object itself. */ - public QueryParams setFilter(String filter) { + public TableQueryParams setFilter(String filter) { this.filter = filter; return this; } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/UpdateMode.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableUpdateMode.java similarity index 87% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/UpdateMode.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableUpdateMode.java index 3f4e9e19ebce8..415be2d924b47 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/UpdateMode.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/models/TableUpdateMode.java @@ -5,7 +5,7 @@ /** * update type for update and upsert methods */ -public enum UpdateMode { +public enum TableUpdateMode { MERGE, REPLACE } diff --git a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java index 2ea4feab3f90b..eb65a2d016d62 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java @@ -2,9 +2,9 @@ // Licensed under the MIT License. package com.azure.data.tables; -import com.azure.data.tables.models.Entity; -import com.azure.data.tables.models.QueryParams; -import com.azure.data.tables.models.UpdateMode; +import com.azure.data.tables.models.TableEntity; +import com.azure.data.tables.models.TableQueryParams; +import com.azure.data.tables.models.TableUpdateMode; /** * async code snippets for the table service @@ -47,7 +47,7 @@ public void listTable() { TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") .buildAsyncClient(); - QueryParams queryParams = new QueryParams().setFilter("TableName eq OfficeSupplies"); + TableQueryParams queryParams = new TableQueryParams().setFilter("TableName eq OfficeSupplies"); tableServiceAsyncClient.listTables(queryParams).subscribe(azureTable -> { System.out.println(azureTable.getName()); @@ -65,7 +65,7 @@ private void insertEntity() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); - Entity entity = new Entity("markers", "crayolaMarkers"); + TableEntity entity = new TableEntity("markers", "crayolaMarkers"); tableAsyncClient.createEntity(entity).subscribe(tableEntity -> { System.out.println("Insert Entity Successful. Entity: " + tableEntity); @@ -141,7 +141,7 @@ private void update() { //UpdateMode.REPLACE: so the entity will be replaced if it exists or the request fails if not found //ifUnchanged being false means the eTags must not match - return tableAsyncClient.updateEntity(tableEntity, false, UpdateMode.REPLACE); + return tableAsyncClient.updateEntity(tableEntity, false, TableUpdateMode.REPLACE); }).subscribe( Void -> { }, error -> System.err.println("There was an error updating the Entity. Error: " + error), @@ -157,7 +157,7 @@ private void listEntities() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); - QueryParams queryParams = new QueryParams() + TableQueryParams queryParams = new TableQueryParams() .setFilter("Product eq markers") .setSelect("Seller, Price"); diff --git a/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java index b4366c0882167..2f9a463f38e1b 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java @@ -4,12 +4,12 @@ import com.azure.core.http.rest.PagedIterable; import com.azure.core.util.logging.ClientLogger; -import com.azure.data.tables.models.Entity; -import com.azure.data.tables.models.QueryParams; -import com.azure.data.tables.models.Table; +import com.azure.data.tables.models.TableEntity; +import com.azure.data.tables.models.TableQueryParams; +import com.azure.data.tables.models.AzureTable; import com.azure.data.tables.models.TableErrorCode; import com.azure.data.tables.models.TableStorageException; -import com.azure.data.tables.models.UpdateMode; +import com.azure.data.tables.models.TableUpdateMode; /** * sync code snippets for the table service @@ -25,7 +25,7 @@ public void createTable() { .connectionString("connectionString") .buildClient(); try { - Table officeSuppliesTable = tableServiceClient.createTable("OfficeSupplies"); + AzureTable officeSuppliesTable = tableServiceClient.createTable("OfficeSupplies"); } catch (TableStorageException e) { if (e.getErrorCode() == TableErrorCode.TABLE_ALREADY_EXISTS) { System.err.println("Create Table Unsuccessful. Table already exists."); @@ -64,10 +64,10 @@ public void listTables() { .connectionString("connectionString") .buildClient(); - QueryParams queryParams = new QueryParams().setFilter("TableName eq OfficeSupplies"); + TableQueryParams queryParams = new TableQueryParams().setFilter("TableName eq OfficeSupplies"); try { - PagedIterable
tablePagedIterable = tableServiceClient.listTables(queryParams); + PagedIterable tablePagedIterable = tableServiceClient.listTables(queryParams); } catch (TableStorageException e) { System.err.println("Table Query Unsuccessful. Error: " + e); } @@ -82,7 +82,7 @@ private void createEntity() { .tableName("OfficeSupplies") .buildClient(); - Entity entity = new Entity("markers", "crayolaMarkers"); + TableEntity entity = new TableEntity("markers", "crayolaMarkers"); try { entity = tableClient.createEntity(entity); @@ -109,7 +109,7 @@ private void deleteEntity() { String partitionKey = "markers"; String rowKey = "crayolaMarkers"; try { - Entity entity = tableClient.getEntity(partitionKey, rowKey); + TableEntity entity = tableClient.getEntity(partitionKey, rowKey); //ifUnchanged being true means the eTags must match to delete tableClient.deleteEntity(entity, true); @@ -134,7 +134,7 @@ private void updateEntity() { String partitionKey = "markers"; String rowKey = "crayolaMarkers"; try { - Entity entity = tableClient.getEntity(partitionKey, rowKey); + TableEntity entity = tableClient.getEntity(partitionKey, rowKey); //default is for UpdateMode is UpdateMode.MERGE, which means it merges if exists; fails if not //ifUnchanged being false means the eTags must not match @@ -160,11 +160,11 @@ private void upsertEntity() { String partitionKey = "markers"; String rowKey = "crayolaMarkers"; try { - Entity entity = tableClient.getEntity(partitionKey, rowKey); + TableEntity entity = tableClient.getEntity(partitionKey, rowKey); //default is for UpdateMode is UpdateMode.REPLACE, which means it replaces if exists; inserts if not //always upsert because if no ifUnchanged boolean present the "*" in request. - tableClient.upsertEntity(entity, UpdateMode.REPLACE); + tableClient.upsertEntity(entity, TableUpdateMode.REPLACE); } catch (TableStorageException e) { if (e.getErrorCode() == TableErrorCode.ENTITY_NOT_FOUND) { System.err.println("Cannot find entity. Upsert unsuccessful"); @@ -183,11 +183,11 @@ private void listEntity() { .tableName("OfficeSupplies") .buildClient(); - QueryParams queryParams = new QueryParams() + TableQueryParams queryParams = new TableQueryParams() .setFilter("Product eq markers") .setSelect("Seller, Price"); try { - PagedIterable tableEntities = tableClient.listEntities(queryParams); + PagedIterable tableEntities = tableClient.listEntities(queryParams); } catch (TableStorageException e) { System.err.println("Query Table Entities Unsuccessful. Error: " + e); } @@ -205,7 +205,7 @@ public void entityExists() { String partitionKey = "markers"; String rowKey = "crayolaMarkers"; try { - Entity entity = tableClient.getEntity(partitionKey, rowKey); + TableEntity entity = tableClient.getEntity(partitionKey, rowKey); } catch (TableStorageException e) { System.err.println("Get Entity Unsuccessful. Entity may not exist: " + e); } diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceAsyncClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceAsyncClientTest.java index c22be23c6af4a..d67f33a2cc26b 100644 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceAsyncClientTest.java +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceAsyncClientTest.java @@ -8,7 +8,7 @@ import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.RetryPolicy; import com.azure.core.test.TestBase; -import com.azure.data.tables.models.QueryParams; +import com.azure.data.tables.models.TableQueryParams; import org.junit.jupiter.api.AfterAll; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; @@ -116,7 +116,7 @@ void serviceDeleteTableWithResponseAsync() { @Test void listTableWithResponseWithParams() { // Arrange - QueryParams queryParams = new QueryParams().setFilter("TableName eq SampleTable"); + TableQueryParams queryParams = new TableQueryParams().setFilter("TableName eq SampleTable"); // Act & Assert StepVerifier.create(asyncClient.listTables(queryParams)) diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceClientTest.java index e9ba003dd0929..c4f829f780878 100644 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceClientTest.java +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TableServiceClientTest.java @@ -8,7 +8,7 @@ import com.azure.core.http.policy.HttpLogOptions; import com.azure.core.http.policy.RetryPolicy; import com.azure.core.test.TestBase; -import com.azure.data.tables.models.Table; +import com.azure.data.tables.models.AzureTable; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertEquals; @@ -40,7 +40,7 @@ void createTable() { String tableName = testResourceNamer.randomName("test", 20); // Act - Table table = client.createTable(tableName); + AzureTable table = client.createTable(tableName); // Assert assertEquals(tableName, table.getName()); diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java index 0a463edbea3f8..4a6be5caa1704 100644 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java @@ -9,9 +9,9 @@ import com.azure.core.http.policy.HttpPipelinePolicy; import com.azure.core.http.policy.RetryPolicy; import com.azure.core.test.TestBase; -import com.azure.data.tables.models.Entity; -import com.azure.data.tables.models.QueryParams; -import com.azure.data.tables.models.UpdateMode; +import com.azure.data.tables.models.TableEntity; +import com.azure.data.tables.models.TableQueryParams; +import com.azure.data.tables.models.TableUpdateMode; import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import reactor.test.StepVerifier; @@ -89,7 +89,7 @@ void createEntityAsync() { // Arrange final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); - final Entity tableEntity = new Entity(partitionKeyValue, rowKeyValue); + final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); // Act & Assert StepVerifier.create(asyncClient.createEntity(tableEntity)) @@ -107,12 +107,15 @@ void createEntityWithResponse() { // Arrange final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); - final Entity entity = new Entity(partitionKeyValue, rowKeyValue); + final TableEntity entity = new TableEntity(partitionKeyValue, rowKeyValue); + entity.addProperty("prop", "false"); + entity.addProperty("prop@odata.type", "Edm.Binary"); final int expectedStatusCode = 201; // Act & Assert StepVerifier.create(asyncClient.createEntityWithResponse(entity)) .assertNext(response -> { + String s = response.toString(); assertEquals(response.getValue().getPartitionKey(), partitionKeyValue); assertEquals(response.getValue().getRowKey(), rowKeyValue); assertNotNull(response.getValue().getETag()); @@ -127,9 +130,9 @@ void deleteEntityAsync() { // Arrange final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); - final Entity tableEntity = new Entity(partitionKeyValue, rowKeyValue); + final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); - final Entity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); + final TableEntity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); assertNotNull(createdEntity, "'createdEntity' should not be null."); assertNotNull(createdEntity.getETag(), "'eTag' should not be null."); @@ -144,10 +147,10 @@ void deleteEntityWithResponse() { // Arrange final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); - final Entity tableEntity = new Entity(partitionKeyValue, rowKeyValue); + final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); final int expectedStatusCode = 204; - final Entity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); + final TableEntity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); assertNotNull(createdEntity, "'createdEntity' should not be null."); assertNotNull(createdEntity.getETag(), "'eTag' should not be null."); @@ -165,10 +168,10 @@ void deleteEntityWithResponseMatchETag() { // Arrange final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); - final Entity tableEntity = new Entity(partitionKeyValue, rowKeyValue); + final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); final int expectedStatusCode = 204; - final Entity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); + final TableEntity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); assertNotNull(createdEntity, "'createdEntity' should not be null."); assertNotNull(createdEntity.getETag(), "'eTag' should not be null."); @@ -186,17 +189,17 @@ void getEntityWithResponse() { // Arrange final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); - final Entity tableEntity = new Entity(partitionKeyValue, rowKeyValue); + final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); final int expectedStatusCode = 200; - final Entity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); + final TableEntity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); assertNotNull(createdEntity, "'createdEntity' should not be null."); assertNotNull(createdEntity.getETag(), "'eTag' should not be null."); // Act & Assert StepVerifier.create(asyncClient.getEntityWithResponse(createdEntity.getPartitionKey(), createdEntity.getRowKey())) .assertNext(response -> { - final Entity entity = response.getValue(); + final TableEntity entity = response.getValue(); assertEquals(expectedStatusCode, response.getStatusCode()); assertNotNull(entity); @@ -213,30 +216,30 @@ void getEntityWithResponse() { @Test void updateEntityWithResponseReplace() { - updateEntityWithResponse(UpdateMode.REPLACE); + updateEntityWithResponse(TableUpdateMode.REPLACE); } @Test void updateEntityWithResponseMerge() { - updateEntityWithResponse(UpdateMode.MERGE); + updateEntityWithResponse(TableUpdateMode.MERGE); } /** - * In the case of {@link UpdateMode#MERGE}, we expect both properties to exist. - * In the case of {@link UpdateMode#REPLACE}, we only expect {@code newPropertyKey} to exist. + * In the case of {@link TableUpdateMode#MERGE}, we expect both properties to exist. + * In the case of {@link TableUpdateMode#REPLACE}, we only expect {@code newPropertyKey} to exist. */ - void updateEntityWithResponse(UpdateMode mode) { + void updateEntityWithResponse(TableUpdateMode mode) { // Arrange - final boolean expectOldProperty = mode == UpdateMode.MERGE; + final boolean expectOldProperty = mode == TableUpdateMode.MERGE; final String partitionKeyValue = testResourceNamer.randomName("APartitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("ARowKey", 20); final int expectedStatusCode = 204; final String oldPropertyKey = "propertyA"; final String newPropertyKey = "propertyB"; - final Entity tableEntity = new Entity(partitionKeyValue, rowKeyValue) + final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue) .addProperty(oldPropertyKey, "valueA"); - final Entity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); + final TableEntity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); assertNotNull(createdEntity, "'createdEntity' should not be null."); assertNotNull(createdEntity.getETag(), "'eTag' should not be null."); @@ -265,8 +268,8 @@ void listEntityWithFilter() { // Arrange final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); - final Entity entity = new Entity(partitionKeyValue, rowKeyValue); - QueryParams queryParams1 = new QueryParams().setFilter("PartitionKey eq '" + entity.getPartitionKey() + "'"); + final TableEntity entity = new TableEntity(partitionKeyValue, rowKeyValue); + TableQueryParams queryParams1 = new TableQueryParams().setFilter("PartitionKey eq '" + entity.getPartitionKey() + "'"); asyncClient.createEntity(entity).block(TIMEOUT); // Act & Assert @@ -285,10 +288,10 @@ void listEntityWithSelect() { // Arrange final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); - final Entity entity = new Entity(partitionKeyValue, rowKeyValue) + final TableEntity entity = new TableEntity(partitionKeyValue, rowKeyValue) .addProperty("propertyC", "valueC") .addProperty("propertyD", "valueD"); - QueryParams queryParams = new QueryParams() + TableQueryParams queryParams = new TableQueryParams() .setFilter("PartitionKey eq '" + entity.getPartitionKey() + "'") .setSelect("propertyC"); asyncClient.createEntity(entity).block(TIMEOUT); @@ -308,7 +311,7 @@ void listEntityWithSelect() { @Test void listEntityWithTop() { // Arrange - QueryParams queryParams = new QueryParams() + TableQueryParams queryParams = new TableQueryParams() .setTop(1); // Act & Assert From 2afd941bfa3443b33bfffca235548c9f0b763737 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 29 Jul 2020 17:36:02 -0400 Subject: [PATCH 2/6] adding odata tags --- .../java/com/azure/data/tables/EdmType.java | 214 ++++++++++++++++++ .../com/azure/data/tables/ODataConstants.java | 82 +++++++ .../azure/data/tables/TableAsyncClient.java | 65 +++++- .../com/azure/data/tables/TableEntity.java | 45 ---- .../azure/data/tables/TableUpdateMode.java | 11 - .../data/tables/TablesAsyncClientTest.java | 5 +- 6 files changed, 363 insertions(+), 59 deletions(-) create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/EdmType.java create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/ODataConstants.java delete mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java delete mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableUpdateMode.java diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/EdmType.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/EdmType.java new file mode 100644 index 0000000000000..93b27cce9823a --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/EdmType.java @@ -0,0 +1,214 @@ +/** + * Copyright Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.azure.data.tables; + +import java.util.Collections; +import java.util.EnumSet; +import java.util.Set; + +/** + * A enumeration used to represent the primitive types of the Entity Data Model (EDM) in the Open Data Protocol (OData). + * The EDM is the underlying abstract data model used by OData services. The {@link EdmType} enumeration includes a + * {@link #parse(String)} method to convert EDM data type names to the enumeration type, and overrides the + * {@link #toString()} method to produce an EDM data type name. + *

+ * For more information about OData, see the Open Data Protocol website. + *

+ * For an overview of the available EDM primitive data types and names, see the Primitive Data Types section of the + * OData Protocol Overview. + *

+ * The Abstract Type System used to define the primitive types supported by OData is defined in detail in [MC-CSDL] (section 2.2.1). + */ +public enum EdmType { + /** + * Null Represents the absence of a value + */ + NULL, + + /** + * Edm.Binary Represents fixed- or variable-length binary data + */ + BINARY, + + /** + * Edm.Boolean Represents the mathematical concept of binary-valued logic + */ + BOOLEAN, + + /** + * Edm.Byte Represents a unsigned 8-bit integer value + */ + BYTE, + + /** + * Edm.DateTime Represents date and time with values ranging from 12:00:00 midnight, January 1, + * 1753 A.D. through 11:59:59 P.M, December 9999 A.D. + */ + DATE_TIME, + + /** + * Edm.DateTimeOffset Represents date and time as an Offset in minutes from GMT, with values + * ranging from 12:00:00 midnight, January 1, 1753 A.D. through 11:59:59 P.M, December 9999 A.D + */ + DATE_TIME_OFFSET, + + /** + * Edm.Decimal Represents numeric values with fixed precision and scale. This type can describe a + * numeric value ranging from negative 10^255 + 1 to positive 10^255 -1 + */ + DECIMAL, + + /** + * Edm.Double Represents a floating point number with 15 digits precision that can represent values + * with approximate range of +/- 2.23e -308 through +/- 1.79e +308 + */ + DOUBLE, + + /** + * Edm.Single Represents a floating point number with 7 digits precision that can represent values + * with approximate range of +/- 1.18e -38 through +/- 3.40e +38 + */ + SINGLE, + + /** + * Edm.Guid Represents a 16-byte (128-bit) unique identifier value + */ + GUID, + + /** + * Edm.Int16 Represents a signed 16-bit integer value + */ + INT16, + + /** + * Edm.Int32 Represents a signed 32-bit integer value + */ + INT32, + + /** + * Edm.Int64 Represents a signed 64-bit integer value + */ + INT64, + + /** + * Edm.SByte Represents a signed 8-bit integer value + */ + SBYTE, + + /** + * Edm.String Represents fixed- or variable-length character data + */ + STRING, + + /** + * Edm.Time Represents the time of day with values ranging from 0:00:00.x to 23:59:59.y, where x + * and y depend upon the precision + */ + TIME; + + private static final Set UNANNOTATED = Collections.unmodifiableSet(EnumSet.of(BOOLEAN, DOUBLE, INT32, + STRING)); + + protected final boolean mustAnnotateType() { + return !UNANNOTATED.contains(this); + } + + /** + * Parses an EDM data type name and return the matching {@link EdmType} enumeration value. A null or + * empty value parameter is matched as {@link EdmType#STRING}. Note that only the subset of EDM data types + * supported in Microsoft Azure Table storage is parsed, consisting of {@link #BINARY}, {@link #BOOLEAN}, + * {@link #BYTE} , {@link #DATE_TIME}, {@link #DOUBLE}, {@link #GUID}, {@link #INT32}, {@link #INT64}, and + * {@link #STRING}. Any + * other type will cause an {@link IllegalArgumentException} to be thrown. + * + * @param value + * A String containing the name of an EDM data type. + * @return + * The {@link EdmType} enumeration value matching the specified EDM data type. + * + * @throws IllegalArgumentException + * if an EDM data type not supported in Microsoft Azure Table storage is passed as an argument. + * + */ + public static EdmType parse(final String value) { + if (value == null || value.length() == 0) { + return EdmType.STRING; + } + else if (value.equals(ODataConstants.EDMTYPE_DATETIME)) { + return EdmType.DATE_TIME; + } + else if (value.equals(ODataConstants.EDMTYPE_INT32)) { + return EdmType.INT32; + } + else if (value.equals(ODataConstants.EDMTYPE_BOOLEAN)) { + return EdmType.BOOLEAN; + } + else if (value.equals(ODataConstants.EDMTYPE_DOUBLE)) { + return EdmType.DOUBLE; + } + else if (value.equals(ODataConstants.EDMTYPE_INT64)) { + return EdmType.INT64; + } + else if (value.equals(ODataConstants.EDMTYPE_GUID)) { + return EdmType.GUID; + } + else if (value.equals(ODataConstants.EDMTYPE_BINARY)) { + return EdmType.BINARY; + } + + throw new IllegalArgumentException("invalid formatting"); + } + + /** + * Returns the name of the EDM data type corresponding to the enumeration value. + * + * @return + * A String containing the name of the EDM data type. + */ + @Override + public String toString() { + if (this == EdmType.BINARY) { + return ODataConstants.EDMTYPE_BINARY; + } + else if (this == EdmType.STRING) { + return ODataConstants.EDMTYPE_STRING; + } + else if (this == EdmType.BOOLEAN) { + return ODataConstants.EDMTYPE_BOOLEAN; + } + else if (this == EdmType.DOUBLE) { + return ODataConstants.EDMTYPE_DOUBLE; + } + else if (this == EdmType.GUID) { + return ODataConstants.EDMTYPE_GUID; + } + else if (this == EdmType.INT32) { + return ODataConstants.EDMTYPE_INT32; + } + else if (this == EdmType.INT64) { + return ODataConstants.EDMTYPE_INT64; + } + else if (this == EdmType.DATE_TIME) { + return ODataConstants.EDMTYPE_DATETIME; + } + else { + // VNext : Update here if we add to supported edmtypes in the future. + return ODataConstants.EDMTYPE_STRING; + } + } +} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/ODataConstants.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/ODataConstants.java new file mode 100644 index 0000000000000..121a24a1695c4 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/ODataConstants.java @@ -0,0 +1,82 @@ +/** + * Copyright Microsoft Corporation + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package com.azure.data.tables; + +/** + * Reserved for internal use. A class that holds relevant constants for interacting with OData feeds. + */ +final class ODataConstants { + + /** + * The String representation of the Atom Entry etag element name. + */ + public static final String ETAG = "etag"; + + /** + * The String representation of the JSON annotation prefix + */ + public static final String ODATA_PREFIX = "odata."; + + /** + * The String representation of the JSON annotation edm type suffix + */ + public static final String ODATA_TYPE_SUFFIX = "@odata.type"; + + /** + * The String representation of the JSON value object name + */ + public static final String VALUE = "value"; + + /** + * The String representation of the Edm.DateTime metadata type attribute value. + */ + public static final String EDMTYPE_DATETIME = "Edm.DateTime"; + + /** + * The String representation of the Edm.Binary metadata type attribute value. + */ + public static final String EDMTYPE_BINARY = "Edm.Binary"; + + /** + * The String representation of the Edm.Boolean metadata type attribute value. + */ + public static final String EDMTYPE_BOOLEAN = "Edm.Boolean"; + + /** + * The String representation of the Edm.Double metadata type attribute value. + */ + public static final String EDMTYPE_DOUBLE = "Edm.Double"; + + /** + * The String representation of the Edm.Guid metadata type attribute value. + */ + public static final String EDMTYPE_GUID = "Edm.Guid"; + + /** + * The String representation of the Edm.Int32 metadata type attribute value. + */ + public static final String EDMTYPE_INT32 = "Edm.Int32"; + + /** + * The String representation of the Edm.Int64 metadata type attribute value. + */ + public static final String EDMTYPE_INT64 = "Edm.Int64"; + + /** + * The String representation of the Edm.String metadata type attribute value. + */ + public static final String EDMTYPE_STRING = "Edm.String"; +} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java index 3f5d1f3cfb7a5..d105cc0149b5a 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java @@ -30,6 +30,9 @@ import com.azure.data.tables.models.TableQueryParams; import com.azure.data.tables.models.AzureTable; import com.azure.data.tables.models.TableUpdateMode; +import java.util.Date; +import java.util.HashMap; +import java.util.UUID; import reactor.core.publisher.Mono; import java.net.URI; @@ -182,8 +185,9 @@ public Mono> createEntityWithResponse(TableEntity entity) } Mono> createEntityWithResponse(TableEntity entity, Context context) { + Map properties = addPropertyTyping(entity.getProperties()); return tableImplementation.insertEntityWithResponseAsync(tableName, null, null, - ResponseFormat.RETURN_CONTENT, entity.getProperties(), + ResponseFormat.RETURN_CONTENT, properties, null, context).map(response -> { final TableEntity createdEntity = deserializeEntity(logger, response.getValue()); @@ -636,4 +640,63 @@ private static TableEntity deserializeEntity(ClientLogger logger, Map addPropertyTyping(Map properties) { + Map result = new HashMap<>(); + for (Map.Entry entry : properties.entrySet()) { + if (!entry.getKey().equals(PARTITION_KEY) && !entry.getKey().equals(ROW_KEY) && !entry.getKey().equals("Timestamp") && !entry.getKey().equals("Etag")) { + String key = entry.getKey().concat(ODataConstants.ODATA_TYPE_SUFFIX); + String value = getEntityProperty(entry.getValue().getClass()).toString(); + result.put(key, value); + } + result.put(entry.getKey(), entry.getValue()); + } + return result; + } + + private EdmType getEntityProperty(final Class type) { + + if (type.equals(byte[].class)) { + return EdmType.BINARY; + } + else if (type.equals(Byte[].class)) { + return EdmType.BINARY; + } + else if (type.equals(String.class)) { + return EdmType.STRING; + } + else if (type.equals(boolean.class)) { + return EdmType.BOOLEAN; + } + else if (type.equals(Boolean.class)) { + return EdmType.BOOLEAN; + } + else if (type.equals(Date.class)) { + return EdmType.DATE_TIME; + } + else if (type.equals(double.class)) { + return EdmType.DOUBLE; + } + else if (type.equals(Double.class)) { + return EdmType.DOUBLE; + } + else if (type.equals(UUID.class)) { + return EdmType.GUID; + } + else if (type.equals(int.class)) { + return EdmType.INT32; + } + else if (type.equals(Integer.class)) { + return EdmType.INT32; + } + else if (type.equals(long.class)) { + return EdmType.INT64; + } + else if (type.equals(Long.class)) { + return EdmType.INT64; + } + else { + throw new IllegalArgumentException("unable to parse"); + } + } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java deleted file mode 100644 index 26a8cdf99e093..0000000000000 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java +++ /dev/null @@ -1,45 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -package com.azure.data.tables; - -import com.azure.core.annotation.Fluent; -import java.util.Map; - -/** - * table entity class - */ -@Fluent -public class TableEntity { - private final Map properties; - //tableName - //etag - - /** - * creates a new TableEntity - * - * @param properties map of properties of the entity - */ - public TableEntity(Map properties) { - this.properties = properties; - } - - /** - * returns a map of properties - * - * @return map of properties of thsi entity - */ - public Map getProperties() { - return properties; - } - - /** - * adds a new property to this entity's property map - * - * @param key the key of the property - * @param value the value of the property - * @return the updated entity - */ - public TableEntity addProperty(String key, Object value) { - return this; - } -} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableUpdateMode.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableUpdateMode.java deleted file mode 100644 index 0fa8cdcce96f1..0000000000000 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableUpdateMode.java +++ /dev/null @@ -1,11 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -package com.azure.data.tables; - -/** - * update type for update and upsert methods - */ -public enum TableUpdateMode { - MERGE, - REPLACE -} diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java index 4a6be5caa1704..a98ee297b6bdd 100644 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java @@ -108,8 +108,9 @@ void createEntityWithResponse() { final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); final TableEntity entity = new TableEntity(partitionKeyValue, rowKeyValue); - entity.addProperty("prop", "false"); - entity.addProperty("prop@odata.type", "Edm.Binary"); + entity.addProperty("prop", false); + entity.addProperty("int", 32); + //entity.addProperty("prop@odata.type", "Edm.Boolean"); final int expectedStatusCode = 201; // Act & Assert From 32f9354bfac658efb275ecb5835559585c5d400a Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 29 Jul 2020 17:48:32 -0400 Subject: [PATCH 3/6] fixing for upsert and update --- .../azure/data/tables/TableAsyncClient.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java index d105cc0149b5a..46eb2d3e83db9 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java @@ -236,6 +236,7 @@ public Mono> upsertEntityWithResponse(TableEntity entity, TableUp Mono> upsertEntityWithResponse(TableEntity entity, TableUpdateMode updateMode, Duration timeout, Context context) { + Map properties = addPropertyTyping(entity.getProperties()); Integer timeoutInt = timeout == null ? null : (int) timeout.getSeconds(); if (entity == null) { return monoError(logger, new NullPointerException("TableEntity cannot be null")); @@ -243,14 +244,14 @@ Mono> upsertEntityWithResponse(TableEntity entity, TableUpdateMod if (updateMode == TableUpdateMode.REPLACE) { return tableImplementation.updateEntityWithResponseAsync(tableName, entity.getPartitionKey(), entity.getRowKey(), timeoutInt, null, "*", - entity.getProperties(), null, context).map(response -> { + properties, null, context).map(response -> { return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); }); } else { return tableImplementation.mergeEntityWithResponseAsync(tableName, entity.getPartitionKey(), entity.getRowKey(), timeoutInt, null, "*", - entity.getProperties(), null, context).map(response -> { + properties, null, context).map(response -> { return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); }); @@ -316,11 +317,12 @@ public Mono> updateEntityWithResponse(TableEntity entity, boolean Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnchanged, TableUpdateMode updateMode, Duration timeout, Context context) { + Map properties = addPropertyTyping(entity.getProperties()); Integer timeoutInt = timeout == null ? null : (int) timeout.getSeconds(); if (updateMode == null || updateMode == TableUpdateMode.MERGE) { if (ifUnchanged) { return tableImplementation.mergeEntityWithResponseAsync(tableName, entity.getPartitionKey(), - entity.getRowKey(), timeoutInt, null, entity.getETag(), entity.getProperties(), null, + entity.getRowKey(), timeoutInt, null, entity.getETag(), properties, null, context).map(response -> { return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); @@ -330,7 +332,7 @@ Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnch .flatMap(entityReturned -> { return tableImplementation.mergeEntityWithResponseAsync(tableName, entity.getPartitionKey(), entity.getRowKey(), timeoutInt, null, - "*", entity.getProperties(), null, context); + "*", properties, null, context); }).map(response -> { return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); @@ -339,7 +341,7 @@ Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnch } else { if (ifUnchanged) { return tableImplementation.updateEntityWithResponseAsync(tableName, entity.getPartitionKey(), - entity.getRowKey(), timeoutInt, null, entity.getETag(), entity.getProperties(), + entity.getRowKey(), timeoutInt, null, entity.getETag(), properties, null, context).map(response -> { return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), null); @@ -349,7 +351,7 @@ Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnch .flatMap(entityReturned -> { return tableImplementation.updateEntityWithResponseAsync(tableName, entity.getPartitionKey(), entity.getRowKey(), - timeoutInt, null, "*", entity.getProperties(), null, + timeoutInt, null, "*", properties, null, context); }).map(response -> { return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), @@ -644,7 +646,9 @@ private static TableEntity deserializeEntity(ClientLogger logger, Map addPropertyTyping(Map properties) { Map result = new HashMap<>(); for (Map.Entry entry : properties.entrySet()) { - if (!entry.getKey().equals(PARTITION_KEY) && !entry.getKey().equals(ROW_KEY) && !entry.getKey().equals("Timestamp") && !entry.getKey().equals("Etag")) { + if (!entry.getKey().equals(PARTITION_KEY) && !entry.getKey().equals(ROW_KEY) + && !entry.getKey().equals("Timestamp") && !entry.getKey().equals("Etag") + && !entry.getKey().equals("odata.etag") && !entry.getKey().equals("odata.metadata")) { String key = entry.getKey().concat(ODataConstants.ODATA_TYPE_SUFFIX); String value = getEntityProperty(entry.getValue().getClass()).toString(); result.put(key, value); From 74c509364114c3c9cf6fe8932593ed49ba8a1006 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 30 Jul 2020 14:54:38 -0400 Subject: [PATCH 4/6] tableEntity file --- .../com/azure/data/tables/TableEntity.java | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java new file mode 100644 index 0000000000000..26a8cdf99e093 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java @@ -0,0 +1,45 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.data.tables; + +import com.azure.core.annotation.Fluent; +import java.util.Map; + +/** + * table entity class + */ +@Fluent +public class TableEntity { + private final Map properties; + //tableName + //etag + + /** + * creates a new TableEntity + * + * @param properties map of properties of the entity + */ + public TableEntity(Map properties) { + this.properties = properties; + } + + /** + * returns a map of properties + * + * @return map of properties of thsi entity + */ + public Map getProperties() { + return properties; + } + + /** + * adds a new property to this entity's property map + * + * @param key the key of the property + * @param value the value of the property + * @return the updated entity + */ + public TableEntity addProperty(String key, Object value) { + return this; + } +} From 5bfcf81dfe4061aad66eacfc51a864254695b592 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 30 Jul 2020 15:23:47 -0400 Subject: [PATCH 5/6] fixing code style errors --- .../java/com/azure/data/tables/EdmType.java | 113 ++---------------- .../com/azure/data/tables/ODataConstants.java | 50 ++------ .../azure/data/tables/TableAsyncClient.java | 68 +++++------ .../com/azure/data/tables/TableClient.java | 3 + .../data/tables/TableServiceAsyncClient.java | 6 +- .../tables/implementation/TableConstants.java | 10 ++ 6 files changed, 70 insertions(+), 180 deletions(-) diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/EdmType.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/EdmType.java index 93b27cce9823a..973bafce8431b 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/EdmType.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/EdmType.java @@ -1,38 +1,9 @@ -/** - * Copyright Microsoft Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; -import java.util.Collections; -import java.util.EnumSet; -import java.util.Set; - /** * A enumeration used to represent the primitive types of the Entity Data Model (EDM) in the Open Data Protocol (OData). - * The EDM is the underlying abstract data model used by OData services. The {@link EdmType} enumeration includes a - * {@link #parse(String)} method to convert EDM data type names to the enumeration type, and overrides the - * {@link #toString()} method to produce an EDM data type name. - *

- * For more information about OData, see the Open Data Protocol website. - *

- * For an overview of the available EDM primitive data types and names, see the Primitive Data Types section of the - * OData Protocol Overview. - *

- * The Abstract Type System used to define the primitive types supported by OData is defined in detail in [MC-CSDL] (section 2.2.1). */ public enum EdmType { /** @@ -121,92 +92,30 @@ public enum EdmType { */ TIME; - private static final Set UNANNOTATED = Collections.unmodifiableSet(EnumSet.of(BOOLEAN, DOUBLE, INT32, - STRING)); - - protected final boolean mustAnnotateType() { - return !UNANNOTATED.contains(this); - } - - /** - * Parses an EDM data type name and return the matching {@link EdmType} enumeration value. A null or - * empty value parameter is matched as {@link EdmType#STRING}. Note that only the subset of EDM data types - * supported in Microsoft Azure Table storage is parsed, consisting of {@link #BINARY}, {@link #BOOLEAN}, - * {@link #BYTE} , {@link #DATE_TIME}, {@link #DOUBLE}, {@link #GUID}, {@link #INT32}, {@link #INT64}, and - * {@link #STRING}. Any - * other type will cause an {@link IllegalArgumentException} to be thrown. - * - * @param value - * A String containing the name of an EDM data type. - * @return - * The {@link EdmType} enumeration value matching the specified EDM data type. - * - * @throws IllegalArgumentException - * if an EDM data type not supported in Microsoft Azure Table storage is passed as an argument. - * - */ - public static EdmType parse(final String value) { - if (value == null || value.length() == 0) { - return EdmType.STRING; - } - else if (value.equals(ODataConstants.EDMTYPE_DATETIME)) { - return EdmType.DATE_TIME; - } - else if (value.equals(ODataConstants.EDMTYPE_INT32)) { - return EdmType.INT32; - } - else if (value.equals(ODataConstants.EDMTYPE_BOOLEAN)) { - return EdmType.BOOLEAN; - } - else if (value.equals(ODataConstants.EDMTYPE_DOUBLE)) { - return EdmType.DOUBLE; - } - else if (value.equals(ODataConstants.EDMTYPE_INT64)) { - return EdmType.INT64; - } - else if (value.equals(ODataConstants.EDMTYPE_GUID)) { - return EdmType.GUID; - } - else if (value.equals(ODataConstants.EDMTYPE_BINARY)) { - return EdmType.BINARY; - } - - throw new IllegalArgumentException("invalid formatting"); - } - /** * Returns the name of the EDM data type corresponding to the enumeration value. * - * @return - * A String containing the name of the EDM data type. + * @return A String containing the name of the EDM data type. */ @Override public String toString() { if (this == EdmType.BINARY) { return ODataConstants.EDMTYPE_BINARY; - } - else if (this == EdmType.STRING) { + } else if (this == EdmType.STRING) { return ODataConstants.EDMTYPE_STRING; - } - else if (this == EdmType.BOOLEAN) { + } else if (this == EdmType.BOOLEAN) { return ODataConstants.EDMTYPE_BOOLEAN; - } - else if (this == EdmType.DOUBLE) { + } else if (this == EdmType.DOUBLE) { return ODataConstants.EDMTYPE_DOUBLE; - } - else if (this == EdmType.GUID) { + } else if (this == EdmType.GUID) { return ODataConstants.EDMTYPE_GUID; - } - else if (this == EdmType.INT32) { + } else if (this == EdmType.INT32) { return ODataConstants.EDMTYPE_INT32; - } - else if (this == EdmType.INT64) { + } else if (this == EdmType.INT64) { return ODataConstants.EDMTYPE_INT64; - } - else if (this == EdmType.DATE_TIME) { + } else if (this == EdmType.DATE_TIME) { return ODataConstants.EDMTYPE_DATETIME; - } - else { + } else { // VNext : Update here if we add to supported edmtypes in the future. return ODataConstants.EDMTYPE_STRING; } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/ODataConstants.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/ODataConstants.java index 121a24a1695c4..40ac23843d5f2 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/ODataConstants.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/ODataConstants.java @@ -1,18 +1,5 @@ -/** - * Copyright Microsoft Corporation - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; /** @@ -20,63 +7,48 @@ */ final class ODataConstants { - /** - * The String representation of the Atom Entry etag element name. - */ - public static final String ETAG = "etag"; - - /** - * The String representation of the JSON annotation prefix - */ - public static final String ODATA_PREFIX = "odata."; - /** * The String representation of the JSON annotation edm type suffix */ - public static final String ODATA_TYPE_SUFFIX = "@odata.type"; - - /** - * The String representation of the JSON value object name - */ - public static final String VALUE = "value"; + static final String ODATA_TYPE_SUFFIX = "@odata.type"; /** * The String representation of the Edm.DateTime metadata type attribute value. */ - public static final String EDMTYPE_DATETIME = "Edm.DateTime"; + static final String EDMTYPE_DATETIME = "Edm.DateTime"; /** * The String representation of the Edm.Binary metadata type attribute value. */ - public static final String EDMTYPE_BINARY = "Edm.Binary"; + static final String EDMTYPE_BINARY = "Edm.Binary"; /** * The String representation of the Edm.Boolean metadata type attribute value. */ - public static final String EDMTYPE_BOOLEAN = "Edm.Boolean"; + static final String EDMTYPE_BOOLEAN = "Edm.Boolean"; /** * The String representation of the Edm.Double metadata type attribute value. */ - public static final String EDMTYPE_DOUBLE = "Edm.Double"; + static final String EDMTYPE_DOUBLE = "Edm.Double"; /** * The String representation of the Edm.Guid metadata type attribute value. */ - public static final String EDMTYPE_GUID = "Edm.Guid"; + static final String EDMTYPE_GUID = "Edm.Guid"; /** * The String representation of the Edm.Int32 metadata type attribute value. */ - public static final String EDMTYPE_INT32 = "Edm.Int32"; + static final String EDMTYPE_INT32 = "Edm.Int32"; /** * The String representation of the Edm.Int64 metadata type attribute value. */ - public static final String EDMTYPE_INT64 = "Edm.Int64"; + static final String EDMTYPE_INT64 = "Edm.Int64"; /** * The String representation of the Edm.String metadata type attribute value. */ - public static final String EDMTYPE_STRING = "Edm.String"; + static final String EDMTYPE_STRING = "Edm.String"; } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java index 46eb2d3e83db9..d55bf1ebd709d 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java @@ -43,8 +43,12 @@ import static com.azure.core.util.FluxUtil.monoError; import static com.azure.core.util.FluxUtil.withContext; +import static com.azure.data.tables.implementation.TableConstants.ETAG; +import static com.azure.data.tables.implementation.TableConstants.ETAG_KEY; +import static com.azure.data.tables.implementation.TableConstants.ODATA_METADATA_KEY; import static com.azure.data.tables.implementation.TableConstants.PARTITION_KEY; import static com.azure.data.tables.implementation.TableConstants.ROW_KEY; +import static com.azure.data.tables.implementation.TableConstants.TIMESTAMP; /** * class for the table async client @@ -152,7 +156,8 @@ public Mono> createWithResponse() { Mono> createWithResponse(Context context) { return tableImplementation.createWithResponseAsync(new TableProperties().setTableName(tableName), null, ResponseFormat.RETURN_CONTENT, null, context).map(response -> { - AzureTable table = response.getValue() == null ? null : new AzureTable(response.getValue().getTableName()); + AzureTable table = response.getValue() == null ? null : new AzureTable(response.getValue() + .getTableName()); return new SimpleResponse<>(response.getRequest(), response.getStatusCode(), response.getHeaders(), table); }); @@ -236,11 +241,11 @@ public Mono> upsertEntityWithResponse(TableEntity entity, TableUp Mono> upsertEntityWithResponse(TableEntity entity, TableUpdateMode updateMode, Duration timeout, Context context) { - Map properties = addPropertyTyping(entity.getProperties()); - Integer timeoutInt = timeout == null ? null : (int) timeout.getSeconds(); if (entity == null) { return monoError(logger, new NullPointerException("TableEntity cannot be null")); } + Map properties = addPropertyTyping(entity.getProperties()); + Integer timeoutInt = timeout == null ? null : (int) timeout.getSeconds(); if (updateMode == TableUpdateMode.REPLACE) { return tableImplementation.updateEntityWithResponseAsync(tableName, entity.getPartitionKey(), entity.getRowKey(), timeoutInt, null, "*", @@ -311,7 +316,8 @@ public Mono updateEntity(TableEntity entity, boolean ifUnchanged, TableUpd * @return a response */ @ServiceMethod(returns = ReturnType.SINGLE) - public Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnchanged, TableUpdateMode updateMode) { + public Mono> updateEntityWithResponse(TableEntity entity, boolean ifUnchanged, + TableUpdateMode updateMode) { return withContext(context -> updateEntityWithResponse(entity, ifUnchanged, updateMode, null, context)); } @@ -451,7 +457,8 @@ private Mono> listFirstPageEntities(Context context, } } //1459 - private Mono> listNextPageEntities(String token, Context context, TableQueryParams queryParams) { + private Mono> listNextPageEntities(String token, Context context, + TableQueryParams queryParams) { if (token == null) { return Mono.empty(); } @@ -505,8 +512,8 @@ private static class EntityPaged implements PagedResponse { private final IterableStream entityStream; private final String continuationToken; - EntityPaged(Response httpResponse, List entityList, String nextPartitionKey, - String nextRowKey) { + EntityPaged(Response httpResponse, List entityList, + String nextPartitionKey, String nextRowKey) { if (nextPartitionKey == null || nextRowKey == null) { this.continuationToken = null; } else { @@ -645,10 +652,10 @@ private static TableEntity deserializeEntity(ClientLogger logger, Map addPropertyTyping(Map properties) { Map result = new HashMap<>(); - for (Map.Entry entry : properties.entrySet()) { + for (Map.Entry entry : properties.entrySet()) { if (!entry.getKey().equals(PARTITION_KEY) && !entry.getKey().equals(ROW_KEY) - && !entry.getKey().equals("Timestamp") && !entry.getKey().equals("Etag") - && !entry.getKey().equals("odata.etag") && !entry.getKey().equals("odata.metadata")) { + && !entry.getKey().equals(TIMESTAMP) && !entry.getKey().equals(ETAG) + && !entry.getKey().equals(ETAG_KEY) && !entry.getKey().equals(ODATA_METADATA_KEY)) { String key = entry.getKey().concat(ODataConstants.ODATA_TYPE_SUFFIX); String value = getEntityProperty(entry.getValue().getClass()).toString(); result.put(key, value); @@ -662,45 +669,32 @@ private EdmType getEntityProperty(final Class type) { if (type.equals(byte[].class)) { return EdmType.BINARY; - } - else if (type.equals(Byte[].class)) { + } else if (type.equals(Byte[].class)) { return EdmType.BINARY; - } - else if (type.equals(String.class)) { + } else if (type.equals(String.class)) { return EdmType.STRING; - } - else if (type.equals(boolean.class)) { + } else if (type.equals(boolean.class)) { return EdmType.BOOLEAN; - } - else if (type.equals(Boolean.class)) { + } else if (type.equals(Boolean.class)) { return EdmType.BOOLEAN; - } - else if (type.equals(Date.class)) { + } else if (type.equals(Date.class)) { return EdmType.DATE_TIME; - } - else if (type.equals(double.class)) { + } else if (type.equals(double.class)) { return EdmType.DOUBLE; - } - else if (type.equals(Double.class)) { + } else if (type.equals(Double.class)) { return EdmType.DOUBLE; - } - else if (type.equals(UUID.class)) { + } else if (type.equals(UUID.class)) { return EdmType.GUID; - } - else if (type.equals(int.class)) { + } else if (type.equals(int.class)) { return EdmType.INT32; - } - else if (type.equals(Integer.class)) { + } else if (type.equals(Integer.class)) { return EdmType.INT32; - } - else if (type.equals(long.class)) { + } else if (type.equals(long.class)) { return EdmType.INT64; - } - else if (type.equals(Long.class)) { + } else if (type.equals(Long.class)) { return EdmType.INT64; - } - else { - throw new IllegalArgumentException("unable to parse"); + } else { + throw logger.logExceptionAsError(new RuntimeException("unable to parse")); } } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java index 249a72a8d171e..1ae98dfe6276e 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java @@ -70,6 +70,7 @@ public TablesServiceVersion getApiVersion() { * * @return a table */ + @ServiceMethod(returns = ReturnType.SINGLE) public AzureTable create() { return client.create().block(); } @@ -80,6 +81,7 @@ public AzureTable create() { * @param timeout Duration to wait for operation to complete. * @return a table */ + @ServiceMethod(returns = ReturnType.SINGLE) public AzureTable create(Duration timeout) { return client.create().block(timeout); } @@ -91,6 +93,7 @@ public AzureTable create(Duration timeout) { * @param context Additional context that is passed through the HTTP pipeline during the service call. * @return HTTP response containing the created table. */ + @ServiceMethod(returns = ReturnType.SINGLE) public Response createWithResponse(Duration timeout, Context context) { return client.createWithResponse(context).block(timeout); } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java index a3ed349da9fca..09b9c661771e9 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java @@ -188,7 +188,8 @@ private Mono> listTablesFirstPage(Context context, Tab } } //1459 - private Mono> listTablesNextPage(String token, Context context, TableQueryParams queryParams) { + private Mono> listTablesNextPage(String token, Context context, + TableQueryParams queryParams) { try { return listTables(token, context, queryParams); } catch (RuntimeException e) { @@ -196,7 +197,8 @@ private Mono> listTablesNextPage(String token, Context } } //1459 - private Mono> listTables(String nextTableName, Context context, TableQueryParams queryParams) { + private Mono> listTables(String nextTableName, Context context, + TableQueryParams queryParams) { QueryOptions queryOptions = new QueryOptions() .setFilter(queryParams.getFilter()) .setTop(queryParams.getTop()) diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableConstants.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableConstants.java index 0c4e038fd65aa..d97bb9ed3c338 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableConstants.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableConstants.java @@ -16,6 +16,16 @@ public final class TableConstants { */ public static final String ROW_KEY = "RowKey"; + /** + * Name in the Map to get the timestamp + */ + public static final String TIMESTAMP = "Timestamp"; + + /** + * Name in the Map to get the etag + */ + public static final String ETAG = "Etag"; + /** * Name in the map to get row key. */ From ae8a85af0f3faf2e65392e67af231b856cbcd994 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 30 Jul 2020 15:47:17 -0400 Subject: [PATCH 6/6] testing for odata parsing --- .../data/tables/TablesAsyncClientTest.java | 74 +++++++++++++++++++ .../createEntityWithTypeMatching.json | 57 ++++++++++++++ 2 files changed, 131 insertions(+) create mode 100644 sdk/tables/azure-data-tables/src/test/resources/session-records/createEntityWithTypeMatching.json diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java index a98ee297b6bdd..18fae3aa206ad 100644 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/TablesAsyncClientTest.java @@ -126,6 +126,37 @@ void createEntityWithResponse() { .verify(); } + @Test + void createEntityWithTypeMatching() { + // Arrange + final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); + final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); + final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); + String propertyBoolean = "propertyB"; + Boolean propertyBooleanValue = false; + tableEntity.addProperty(propertyBoolean, propertyBooleanValue); + String propertyInt = "propertyI"; + Integer propertyIntValue = 1; + tableEntity.addProperty(propertyInt, propertyIntValue); + final int expectedStatusCode = 201; + + // Act & Assert + StepVerifier.create(asyncClient.createEntityWithResponse(tableEntity)) + .assertNext(response -> { + String s = response.toString(); + assertEquals(response.getValue().getPartitionKey(), partitionKeyValue); + assertEquals(response.getValue().getRowKey(), rowKeyValue); + assertNotNull(response.getValue().getETag()); + assertEquals(expectedStatusCode, response.getStatusCode()); + + TableEntity entity = response.getValue(); + assertTrue(entity.getProperties().get(propertyBoolean) instanceof Boolean); + assertTrue(entity.getProperties().get(propertyInt) instanceof Integer); + }) + .expectComplete() + .verify(); + } + @Test void deleteEntityAsync() { // Arrange @@ -215,6 +246,49 @@ void getEntityWithResponse() { .verify(); } + @Disabled("deserialization for get not working yet") + @Test + void getEntityWithTypeMatching() { + // Arrange + final String partitionKeyValue = testResourceNamer.randomName("partitionKey", 20); + final String rowKeyValue = testResourceNamer.randomName("rowKey", 20); + final TableEntity tableEntity = new TableEntity(partitionKeyValue, rowKeyValue); + String propertyBoolean = "propertyB"; + Boolean propertyBooleanValue = false; + tableEntity.addProperty(propertyBoolean, propertyBooleanValue); + String propertyInt = "propertyI"; + Integer propertyIntValue = 1; + tableEntity.addProperty(propertyInt, propertyIntValue); + String propertyDouble = "propertyD"; + Integer propertyDoubleValue = 1000; + tableEntity.addProperty(propertyDouble, propertyDoubleValue); + final int expectedStatusCode = 200; + + final TableEntity createdEntity = asyncClient.createEntity(tableEntity).block(TIMEOUT); + assertNotNull(createdEntity, "'createdEntity' should not be null."); + assertNotNull(createdEntity.getETag(), "'eTag' should not be null."); + + // Act & Assert + StepVerifier.create(asyncClient.getEntityWithResponse(createdEntity.getPartitionKey(), createdEntity.getRowKey())) + .assertNext(response -> { + final TableEntity entity = response.getValue(); + assertEquals(expectedStatusCode, response.getStatusCode()); + + assertNotNull(entity); + assertEquals(tableEntity.getPartitionKey(), entity.getPartitionKey()); + assertEquals(tableEntity.getRowKey(), entity.getRowKey()); + + assertEquals(createdEntity.getETag(), entity.getETag()); + + assertNotNull(entity.getProperties()); + assertTrue(entity.getProperties().get(propertyBoolean) instanceof Boolean); + assertTrue(entity.getProperties().get(propertyInt) instanceof Integer); + assertTrue(entity.getProperties().get(propertyDouble) instanceof Double); + }) + .expectComplete() + .verify(); + } + @Test void updateEntityWithResponseReplace() { updateEntityWithResponse(TableUpdateMode.REPLACE); diff --git a/sdk/tables/azure-data-tables/src/test/resources/session-records/createEntityWithTypeMatching.json b/sdk/tables/azure-data-tables/src/test/resources/session-records/createEntityWithTypeMatching.json new file mode 100644 index 0000000000000..70ee473e23e64 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/test/resources/session-records/createEntityWithTypeMatching.json @@ -0,0 +1,57 @@ +{ + "networkCallRecords" : [ { + "Method" : "POST", + "Uri" : "https://REDACTED.table.core.windows.net/Tables", + "Headers" : { + "x-ms-version" : "2019-02-02", + "User-Agent" : "azsdk-java-UnknownName/UnknownVersion (11.0.7; Windows 10; 10.0)", + "x-ms-client-request-id" : "d5b6211b-b8e7-47c0-8355-5ed9d0dcb79d", + "Content-Type" : "application/json" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2019-02-02", + "Server" : "Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0", + "X-Content-Type-Options" : "nosniff", + "retry-after" : "0", + "StatusCode" : "201", + "Date" : "Thu, 30 Jul 2020 19:45:19 GMT", + "Cache-Control" : "no-cache", + "x-ms-request-id" : "95687745-8002-0084-2ca9-6627fc000000", + "Body" : "{\"odata.metadata\":\"https://telboytrial.table.core.windows.net/$metadata#Tables/@Element\",\"TableName\":\"tablename50387002\"}", + "Preference-Applied" : "return-content", + "x-ms-client-request-id" : "d5b6211b-b8e7-47c0-8355-5ed9d0dcb79d", + "Content-Type" : "application/json;odata=minimalmetadata;streaming=true;charset=utf-8", + "Location" : "https://telboytrial.table.core.windows.net/Tables('tablename50387002')" + }, + "Exception" : null + }, { + "Method" : "POST", + "Uri" : "https://REDACTED.table.core.windows.net/tablename50387002", + "Headers" : { + "x-ms-version" : "2019-02-02", + "User-Agent" : "azsdk-java-UnknownName/UnknownVersion (11.0.7; Windows 10; 10.0)", + "x-ms-client-request-id" : "684f9957-fb06-45ac-8e80-50a9005db20c", + "Content-Type" : "application/json" + }, + "Response" : { + "Transfer-Encoding" : "chunked", + "x-ms-version" : "2019-02-02", + "Server" : "Windows-Azure-Table/1.0 Microsoft-HTTPAPI/2.0", + "X-Content-Type-Options" : "nosniff", + "retry-after" : "0", + "StatusCode" : "201", + "Date" : "Thu, 30 Jul 2020 19:45:19 GMT", + "Cache-Control" : "no-cache", + "ETag" : "W/datetime'2020-07-30T19%3A45%3A19.0778807Z'", + "x-ms-request-id" : "1b7f2eea-b002-007b-68a9-661761000000", + "Body" : "{\"odata.metadata\":\"https://telboytrial.table.core.windows.net/$metadata#tablename50387002/@Element\",\"odata.etag\":\"W/\\\"datetime'2020-07-30T19%3A45%3A19.0778807Z'\\\"\",\"PartitionKey\":\"partitionkey647760\",\"RowKey\":\"rowkey59065db4b\",\"Timestamp\":\"2020-07-30T19:45:19.0778807Z\",\"propertyB\":false,\"propertyI\":1}", + "Preference-Applied" : "return-content", + "x-ms-client-request-id" : "684f9957-fb06-45ac-8e80-50a9005db20c", + "Content-Type" : "application/json;odata=minimalmetadata;streaming=true;charset=utf-8", + "Location" : "https://telboytrial.table.core.windows.net/tablename50387002(PartitionKey='partitionkey647760',RowKey='rowkey59065db4b')" + }, + "Exception" : null + } ], + "variables" : [ "tablename50387002", "partitionkey647760", "rowkey59065db4b" ] +} \ No newline at end of file