From b945b82e8fc58bf4844c9c010e476de2a7e74f46 Mon Sep 17 00:00:00 2001 From: Connie Date: Wed, 3 Jun 2020 14:55:16 -0700 Subject: [PATCH 01/42] Add examples. --- sdk/tables/azure-data-tables/pom.xml | 37 +++++ .../com/azure/data/tables/AzureTable.java | 23 +++ .../data/tables/AzureTableAsyncClient.java | 32 +++++ .../azure/data/tables/AzureTableEntity.java | 22 +++ .../tables/AzureTablesAsyncClientTest.java | 134 ++++++++++++++++++ 5 files changed, 248 insertions(+) create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTable.java create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableEntity.java create mode 100644 sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/AzureTablesAsyncClientTest.java diff --git a/sdk/tables/azure-data-tables/pom.xml b/sdk/tables/azure-data-tables/pom.xml index 4fb23afccc72..a8ce90ddaf1d 100644 --- a/sdk/tables/azure-data-tables/pom.xml +++ b/sdk/tables/azure-data-tables/pom.xml @@ -42,6 +42,43 @@ Licensed under the MIT License. azure-core 1.6.0 + + + com.azure + azure-core-test + 1.2.1 + test + + + org.junit.jupiter + junit-jupiter-api + 5.6.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.6.2 + test + + + org.junit.jupiter + junit-jupiter-params + 5.6.2 + test + + + io.projectreactor + reactor-test + 3.3.5.RELEASE + test + + + org.mockito + mockito-core + 3.0.0 + test + 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 new file mode 100644 index 000000000000..d36e7c0d0719 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTable.java @@ -0,0 +1,23 @@ +package com.azure.data.tables; + +import reactor.core.publisher.Mono; + +import java.time.Duration; + +public class AzureTable { + private final String name; + + AzureTable(String name) { + this.name = name; + } + + public String getName() { + return name; + } + + public Mono createEntity(String key, Object value) { + AzureTableEntity azureTableEntity = new AzureTableEntity(key, value); + System.out.println("Creating entity with key: " + key + ". Value: " + value); + return Mono.delay(Duration.ofSeconds(3)).thenReturn(azureTableEntity); + } +} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java new file mode 100644 index 000000000000..435b0e9c0c19 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java @@ -0,0 +1,32 @@ +package com.azure.data.tables; + +import reactor.core.publisher.Mono; + +import java.time.Duration; +import java.util.HashSet; +import java.util.Set; + +public class AzureTableAsyncClient { + private final Set existingTables = new HashSet<>(); + + /** + * Creates a table. This artificially takes 3 seconds. + * + * @param name The name of the table. + * + * @return A Mono that completes when the table is created. + */ + public Mono createTable(String name) { + return Mono.delay(Duration.ofSeconds(3)).flatMap(delay -> { + if (existingTables.add(name)) { + System.out.printf("CREATING TABLE '%s'.%n", name); + final AzureTable table = new AzureTable(name); + return Mono.just(table); + } else { + System.err.printf("TABLE '%s' ALREADY EXISTS.%n", name); + return Mono.error(new IllegalArgumentException( + String.format("Table with name '%s' already exists.", name))); + } + }); + } +} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableEntity.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableEntity.java new file mode 100644 index 000000000000..d382f733ff8e --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableEntity.java @@ -0,0 +1,22 @@ +package com.azure.data.tables; + +/** + * Represents an entity in azure table. + */ +public class AzureTableEntity { + private final String key; + private final Object value; + + AzureTableEntity(String key, Object value) { + this.key = key; + this.value = value; + } + + public Object getValue() { + return value; + } + + public String getKey() { + return key; + } +} diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/AzureTablesAsyncClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/AzureTablesAsyncClientTest.java new file mode 100644 index 000000000000..204c76d433e8 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/AzureTablesAsyncClientTest.java @@ -0,0 +1,134 @@ +package com.azure.data.tables; + +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +public class AzureTablesAsyncClientTest { + @Test + void createTableTest() { + // Ideally, we'd use a builder to create this rather than a constructor. + AzureTableAsyncClient client = new AzureTableAsyncClient(); + + // Every time this variable is used in a downstream subscriber, it will invoke the `createTable` operation. + Mono createTableMono = client.createTable("my-table"); + + // This is a subscription to the Mono. `subscribe` is a non-blocking call. + createTableMono.subscribe(table -> { + System.out.println("Table created is: " + table.getName()); + }, error -> { + System.err.println("There was an error creating the table. " + error); + }); + + // Since .subscribe is a non-blocking call, after it hooks up the asynchronous operation, it will move + // onto the next statement. If `client.createTable` takes 30 seconds, the program would have ended before we + // ever know the response because it will leave this method. + // You'll see that there is no "System.out.println" console output because the program has ended. + } + + /** + * Notice how "CREATING TABLE with name: my-table" errors when we try to add another entrythe second time? This is + * because, every time we chain the `createTableMono`, it invokes that `createTable` operation again. + * After an error occurs in one of the operations upstream in the chain, it will call the (error) -> { } handler. + * You'll see that we didn't try to add another entity (ie. new-key-2). + * + * See {@link #createAndUpdateTableFixed()} for a resolved version. + */ + @Test + void createAndUpdateTable() throws InterruptedException { + AzureTableAsyncClient client = new AzureTableAsyncClient(); + + // Every time this variable is used in a downstream subscriber, it will invoke the `createTable` operation. + Mono createTableMono = client.createTable("my-table"); + + // FirstMono -> SecondFlatMap -> Map -> Subscribe + createTableMono.flatMap(azureTable -> { + // We are chaining another operation to this table creation. We want to use the resulting table and + // create an entity in it. We use `flatMap` because it is asynchronous (ie. returns Mono or Flux). + Mono entity = azureTable.createEntity("my-key", "my-value"); + // We return the `createEntity` operation. + return entity; + }).map(azureTableEntity -> { + // This is a transformation, maybe we only care about the value of that entity we added. + return azureTableEntity.getValue(); + }).subscribe(theValue -> { + System.out.println("This was added: " + theValue); + }, error -> { + System.err.println("Error: " + error); + }); + + createTableMono.flatMap(azureTable -> { + // We are chaining another operation to this table creation. We want to use the resulting table and + // create an entity in it. We use `flatMap` because it is asynchronous (ie. returns Mono or Flux). + return azureTable.createEntity("my-key-2", "my-value-2"); + }).map(azureTableEntity -> { + // This is a transformation, maybe we only care about the value of that entity we added. + return azureTableEntity.getValue(); + }).subscribe(theValue -> { + System.out.println("This was added: " + theValue); + }, error -> { + System.err.println("Error: " + error); + }); + + TimeUnit.SECONDS.sleep(20); + } + + /** + * We've fixed this by caching the result of the `createTable` operation if it is successful. So we don't try to + * create the table again. + * + * See {@link #createAndUpdateTable()} + */ + @Test + void createAndUpdateTableFixed() throws InterruptedException { + AzureTableAsyncClient client = new AzureTableAsyncClient(); + + // Every time this variable is used in a downstream subscriber, it will invoke the `createTable` operation. + Mono createTableMono = client.createTable("my-table") + .cache(success -> { + System.out.println("--- Table added. Caching value."); + return Duration.ofSeconds(Long.MAX_VALUE); + }, error -> { + System.out.println("--- Error while adding table. Not caching value."); + return Duration.ZERO; + }, () -> { + // This can occur because Monos can output 0 or 1 items. This would be the case where it output 0 items. + // For example, Mono.empty() will complete, but not output any items. + System.out.println("--- Expected a table to be output, not an empty value. Not caching."); + return Duration.ZERO; + }); + + // FirstMono -> SecondFlatMap -> Map -> Subscribe + createTableMono.flatMap(azureTable -> { + // We are chaining another operation to this table creation. We want to use the resulting table and + // create an entity in it. We use `flatMap` because it is asynchronous (ie. returns Mono or Flux). + Mono entity = azureTable.createEntity("my-new-key", "my-new-value"); + // We return the `createEntity` operation. + return entity; + }).map(azureTableEntity -> { + // This is a transformation, maybe we only care about the value of that entity we added. + return azureTableEntity.getValue(); + }).subscribe(theValue -> { + System.out.println("This was added: " + theValue); + }, error -> { + System.err.println("ERROR: " + error); + }); + + createTableMono.flatMap(azureTable -> { + // We are chaining another operation to this table creation. We want to use the resulting table and + // create an entity in it. We use `flatMap` because it is asynchronous (ie. returns Mono or Flux). + return azureTable.createEntity("my-new-key-2", "my-new-value-2"); + }).map(azureTableEntity -> { + // This is a transformation, maybe we only care about the value of that entity we added. + return azureTableEntity.getValue(); + }).subscribe(theValue -> { + System.out.println("This was added: " + theValue); + }, error -> { + System.err.println("ERROR: " + error); + }); + + TimeUnit.SECONDS.sleep(20); + } +} From 2805b2eaf4cf387654fc313673799cce3f57a33c Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 8 Jun 2020 09:28:57 -0400 Subject: [PATCH 02/42] rebase with changes that move Table to new folderCode Snippets, Sync done and Async in progress --- .../table/implementation/AzureTable.java | 25 +++++ .../table/implementation/CodeSnippets.java | 53 +++++++++++ .../table/implementation/CodeSnippetsAysnc | 46 +++++++++ .../implementation/CodeSnippetsAysnc.java | 5 + .../table/implementation/CodeSnippetsSync | 48 ++++++++++ .../implementation/CodeSnippetsSync.java | 95 +++++++++++++++++++ .../table/implementation/TableClient.java | 55 +++++++++++ .../implementation/TableClientBuilder.java | 19 ++++ .../table/implementation/TableEntity.java | 20 ++++ 9 files changed, 366 insertions(+) create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java new file mode 100644 index 000000000000..e74efb0d81b1 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java @@ -0,0 +1,25 @@ +package com.azure.cosmos.table.implementation; + +import java.util.List; + +public class AzureTable { + + public AzureTable(String name) { + + } + public void insertEntity(TableEntity te){ + + } + public TableEntity insertEntity(String key, Object value){ + + } + public void deleteEntity(TableEntity te){ + + } + public void deleteEntity(String key){ + + } + public List query(String select, String filter){ + return null; + } +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java new file mode 100644 index 000000000000..4e2c556cadcb --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java @@ -0,0 +1,53 @@ +package com.azure.cosmos.table.implementation; + +import com.azure.cosmos.table.implementation.models.TableEntityQueryResponse; + +import javax.swing.*; +import java.util.Observable; + +public class CodeSnippets { + //add a table + + //sync + TableClient tableClientBuilder = new TableClientBuilder(); + .endpoint(foo) + .credential(new DefaultAzureCredential() + .build(); + + .connectionString + + AzureTable azureTable = tableClientBuilder.createTableIfNotExists("tableName"); + + //aysnc + TableAysncClientBuilder tableAysncClient = new TableAsyncClientBuilder(); + .pipeline("pipline") + .build(); + AzureTable azureTable2; + Mono createTableMono = tableAysncClient.createTable("tableName"); + createTableMono + .subscribe( + response -> { + azureTable2 = + }, + error -> { + + } + ) + + + //delete a table + //sync + azureTable.delete(); + + //async + + + + //query a table + + //sync + TableEntityQueryResponse tableEntityQueryResponse = azureTable.query(Filter); + + + //aysnc +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc new file mode 100644 index 000000000000..d5b52e41b1df --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc @@ -0,0 +1,46 @@ +//create a table + +TableAyncClient tableAyncClient = new TableAyncClientBuilder(); + .connectionString("connectionString") + .build(); + +Mono createTableMono = tableAsyncClient.createTable("tableName"); +createTableMono.subscribe((AzureTable azureTable) -> { + System.out.println("Table creation successful, table name: " + azureTable.getName()); + }, error -> { + System.out.println("There was an error creating the table. Error: " + error); +}); + + + +//deleteTable +Mono deleteTableMono = tableAsyncClient.deleteTable("tableName"); +deleteTableMono.subscribe( void -> { + System.out.println("Table Successfully deleted.") + }, error -> { + System.out.println("Table deletion unsuccessful. Error: " + ERROR); +}); + + +//query a table +//queryEntities(string tableName, string filter, string select ...) +String query = "filter: $"PartitionKey eq '{PartitionKeyValue}' and RowKey eq '{x}'" +Flux queryEntities = tableAsyncClient.queryEntities("tableName", query); +queryEntities.flatMap( (Map resultEntity) -> { + return new tableEntity(resultEntity.get(), +} + +//add an entity + +Mono getTableMono = tableAsyncClient.getTable("TableName"); +getTableMono.flatMap( azureTable -> { + Mono azureTableEntity = azureTable.createEntity("value","rowKey","partitionKey"); + return azureTableEntity; + }.map(azureTableEntity -> { + System.out.println("Successfully added" + azureTableEntity.getValue() + "to table."); + }, error -> { + System.out.println("Unsuccessful"); + }); + + + diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java new file mode 100644 index 000000000000..d72dde11f61a --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java @@ -0,0 +1,5 @@ +package com.azure.cosmos.table.implementation; + +public class CodeSnippetsAysnc { + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync new file mode 100644 index 000000000000..9f6e6722a016 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync @@ -0,0 +1,48 @@ + + +//create table + +TableClient tableClient = new TableClientBuilder(); + .connectionString("connectionString") + .build(); + +//two options to create a table +tableClient.createTableIfNotExists("tableName"); +tableClient.createTable("tableName"); + + + +//delete table +azureTable.delete(); + + +//query tables +List responseTables = tableClient.query(); + + +// +class TableEntity { +String rowKey +String partitionKey +Map value + +} + +//insert entity +TableEntity tableEntity = new TableEntity(String key, Object value); +azureTable.insert(tableEntity); + +//delete entity +azureTable.delete(tableEntity); + +//update entity +//key to object containing properties (which consumer handles) +azureTable.update(oldEntity.getRowKey(), newEntity); +azureTable.update(newEntity); //new entity has existing row key that is unique + + +//creating odata query and listing entities +some sort of odata builder + +List = azureTable.query(odataQuery); + diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java new file mode 100644 index 000000000000..6877e299e36d --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java @@ -0,0 +1,95 @@ +package com.azure.cosmos.table.implementation; + +import com.azure.core.exception.HttpResponseException; +import com.azure.cosmos.table.implementation.models.TableServiceErrorException; +import com.azure.cosmos.table.implementation.models.TablesQueryEntitiesResponse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CodeSnippetsSync { + + public static void methods(){ + + //client-builder pattern + TableClientBuilder tableClientBuilder = new TableClientBuilder(); + TableClient tableClient = new TableClientBuilder() + .connectionString("connectionString") + .build(); + + + //create a table + try { + tableClient.createTable("Office Supplies;"); + } catch (TableServiceErrorException e) { + System.out.println("Create Table Unsuccessful. Error: " + e); + } + + //delete table + try { + tableClient.deleteTable("Office Supplies"); + } catch (TableServiceErrorException e) { + System.out.println("Delete Table Unsuccessful. Error: " + e); + } + + //query tables + String filterString = "$filter= name eq 'Office Supplies'"; + String selectString = "$select= Product, Price"; + try { + List responseTables = tableClient.queryTables(selectString, filterString); + } catch (HttpResponseException e){ + System.out.println("Table Query Unsuccessful. Error: " + e); + } + + + //insert entity + String tableName = "Office Supplies"; + String row = "crayola markers"; + String partitionKey = "markers"; + HashMap tableEntityProperties = new HashMap<>(); + TableEntity tableEntity = new TableEntity(tableName, row, partitionKey, tableEntityProperties); + try { + tableEntity = tableClient.insertEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Insert Entity Unsuccessful. Error: " + e); + } + + + //update entity + tableEntity.addProperty("Seller","Crayola"); + try { + tableClient.updateEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Update Entity Unsuccessful. Error: " + e); + } + + + //upsert entity + tableEntity.addProperty("Price","$5"); + try { + tableEntity = tableClient.upsertEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Upsert Entity Unsuccessful. Error: " + e); + } + + + //delete entity + try { + tableClient.deleteEntity(tableName, tableEntity); + } catch (HttpResponseException e){ + System.out.println("Delete Entity Unsuccessful. Error: " + e); + } + + + //query a table + String filterString2 = "$filter = Product eq 'markers'"; + String selectString2 = "$select = Seller eq 'crayola'"; + try { + List list= tableClient.queryEntity(tableName, filterString2, selectString2); + } catch (HttpResponseException e){ + System.out.println("Query Table Entities Unsuccessful. Error: " + e); + } + } + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java new file mode 100644 index 000000000000..9444ac60e39e --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java @@ -0,0 +1,55 @@ +package com.azure.cosmos.table.implementation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class TableClient { + String name; + + + public AzureTable createTable(String name){ + return new AzureTable(name); + } + + + public TableClient(){ + name = "Hi"; + } + + public String getName() { + return name; + } + + public AzureTable createTableIfNotExist(String name) { + return new AzureTable(name); + } + public void deleteTable(AzureTable az) { + + } + public void deleteTable(String name) { + + } + public List queryTables(String selectString, String filterString){ + return null; + } + public List queryEntity(String az, String selectString, String filterString){ + return null; + } + + public TableEntity insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ + return new TableEntity(); + } + public TableEntity insertEntity(TableEntity te){ + return te; + } + public void deleteEntity(String tableName, TableEntity tableEntity){ + + } + public void updateEntity(TableEntity te){ + + } + public TableEntity upsertEntity(TableEntity te){ + return new TableEntity(); + } +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java new file mode 100644 index 000000000000..8bbe8b0898fb --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java @@ -0,0 +1,19 @@ +package com.azure.cosmos.table.implementation; + +public class TableClientBuilder { + String connectionString; + + + public TableClientBuilder connectionString(String connectionString){ + connectionString = connectionString; + return this; + } + public TableClient build(){ + return new TableClient(); + } + + public TableClientBuilder(){ + + } + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java new file mode 100644 index 000000000000..7eec0b807ec5 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java @@ -0,0 +1,20 @@ +package com.azure.cosmos.table.implementation; + +import java.util.Map; + +public class TableEntity { + Map properties; + public TableEntity(){ + + } + public TableEntity(String table, String row, String partition, Map properties){ + this.properties = properties; + } + + public Map getProperties(){ + return properties; + } + public void addProperty(String key, Object value){ + + } +} From a09b66b6d875ce7b906d73133d993d20f59d8df1 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 8 Jun 2020 09:53:42 -0400 Subject: [PATCH 03/42] stashing --- .../table/implementation/AzureTable.java | 2 +- .../implementation/CodeSnippetsAysnc.java | 2 +- .../table/implementation/CodeSnippetsSync | 48 ------------------- 3 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java index e74efb0d81b1..25a3af3e009d 100644 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java @@ -11,7 +11,7 @@ public void insertEntity(TableEntity te){ } public TableEntity insertEntity(String key, Object value){ - + return null; } public void deleteEntity(TableEntity te){ diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java index d72dde11f61a..74fd061138ec 100644 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java @@ -1,5 +1,5 @@ package com.azure.cosmos.table.implementation; public class CodeSnippetsAysnc { - + } diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync deleted file mode 100644 index 9f6e6722a016..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync +++ /dev/null @@ -1,48 +0,0 @@ - - -//create table - -TableClient tableClient = new TableClientBuilder(); - .connectionString("connectionString") - .build(); - -//two options to create a table -tableClient.createTableIfNotExists("tableName"); -tableClient.createTable("tableName"); - - - -//delete table -azureTable.delete(); - - -//query tables -List responseTables = tableClient.query(); - - -// -class TableEntity { -String rowKey -String partitionKey -Map value - -} - -//insert entity -TableEntity tableEntity = new TableEntity(String key, Object value); -azureTable.insert(tableEntity); - -//delete entity -azureTable.delete(tableEntity); - -//update entity -//key to object containing properties (which consumer handles) -azureTable.update(oldEntity.getRowKey(), newEntity); -azureTable.update(newEntity); //new entity has existing row key that is unique - - -//creating odata query and listing entities -some sort of odata builder - -List = azureTable.query(odataQuery); - From bdce02505d035882862acef594d0237a7307dd6a Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 8 Jun 2020 11:35:48 -0400 Subject: [PATCH 04/42] rebase with folder changes for tables --- sdk/cosmos/azure-cosmos-table/pom.xml | 110 ++++++++++++++++++ .../table/implementation/AzureTable.java | 25 ---- .../table/implementation/CodeSnippets.java | 53 --------- .../implementation/CodeSnippetsAysnc.java | 5 - .../tables}/implementation/CodeSnippetsAysnc | 0 .../implementation/CodeSnippetsAysnc.java | 29 +++++ .../implementation/CodeSnippetsSync.java | 2 +- .../implementation/TableAsyncClient.java | 39 +++++++ .../TableAsyncClientBuilder.java | 19 +++ .../tables}/implementation/TableClient.java | 38 ++---- .../implementation/TableClientBuilder.java | 2 +- .../tables}/implementation/TableEntity.java | 2 +- 12 files changed, 209 insertions(+), 115 deletions(-) create mode 100644 sdk/cosmos/azure-cosmos-table/pom.xml delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java rename sdk/{cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table => tables/azure-data-tables/src/main/java/com/azure/data/tables}/implementation/CodeSnippetsAysnc (100%) create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java rename sdk/{cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table => tables/azure-data-tables/src/main/java/com/azure/data/tables}/implementation/CodeSnippetsSync.java (98%) create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClientBuilder.java rename sdk/{cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table => tables/azure-data-tables/src/main/java/com/azure/data/tables}/implementation/TableClient.java (50%) rename sdk/{cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table => tables/azure-data-tables/src/main/java/com/azure/data/tables}/implementation/TableClientBuilder.java (87%) rename sdk/{cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table => tables/azure-data-tables/src/main/java/com/azure/data/tables}/implementation/TableEntity.java (89%) diff --git a/sdk/cosmos/azure-cosmos-table/pom.xml b/sdk/cosmos/azure-cosmos-table/pom.xml new file mode 100644 index 000000000000..9b0b11444ef6 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/pom.xml @@ -0,0 +1,110 @@ + + + 4.0.0 + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.azure + azure-data-tables + 1.0.0-beta.1 + Microsoft Azure SDK for Azure Table + This package contains the Microsoft Azure Table storage client library. + https://github.com/Azure/azure-sdk-for-java + + + + azure-java-build-docs + ${site.url}/site/${project.artifactId} + + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + + true + + + + + com.azure + azure-core + 1.5.0 + + + + com.azure + azure-core-test + 1.2.1 + test + + + org.junit.jupiter + junit-jupiter-api + 5.6.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.6.2 + test + + + org.junit.jupiter + junit-jupiter-params + 5.6.2 + test + + + io.projectreactor + reactor-test + 3.3.5.RELEASE + test + + + org.mockito + mockito-core + 3.0.0 + test + + + io.projectreactor + reactor-core + 12.7.0-beta.1 + compile + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + + + com.azure:* + + + + + + + + + diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java deleted file mode 100644 index 25a3af3e009d..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import java.util.List; - -public class AzureTable { - - public AzureTable(String name) { - - } - public void insertEntity(TableEntity te){ - - } - public TableEntity insertEntity(String key, Object value){ - return null; - } - public void deleteEntity(TableEntity te){ - - } - public void deleteEntity(String key){ - - } - public List query(String select, String filter){ - return null; - } -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java deleted file mode 100644 index 4e2c556cadcb..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import com.azure.cosmos.table.implementation.models.TableEntityQueryResponse; - -import javax.swing.*; -import java.util.Observable; - -public class CodeSnippets { - //add a table - - //sync - TableClient tableClientBuilder = new TableClientBuilder(); - .endpoint(foo) - .credential(new DefaultAzureCredential() - .build(); - - .connectionString - - AzureTable azureTable = tableClientBuilder.createTableIfNotExists("tableName"); - - //aysnc - TableAysncClientBuilder tableAysncClient = new TableAsyncClientBuilder(); - .pipeline("pipline") - .build(); - AzureTable azureTable2; - Mono createTableMono = tableAysncClient.createTable("tableName"); - createTableMono - .subscribe( - response -> { - azureTable2 = - }, - error -> { - - } - ) - - - //delete a table - //sync - azureTable.delete(); - - //async - - - - //query a table - - //sync - TableEntityQueryResponse tableEntityQueryResponse = azureTable.query(Filter); - - - //aysnc -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java deleted file mode 100644 index 74fd061138ec..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.azure.cosmos.table.implementation; - -public class CodeSnippetsAysnc { - -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc similarity index 100% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java new file mode 100644 index 000000000000..d99686d067e3 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java @@ -0,0 +1,29 @@ +package com.azure.data.tables.implementation; + +import reactor.core.publisher.Mono; +import reactor.core.*; + +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +public class CodeSnippetsAysnc { + + //client-builder pattern + TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); + TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + .connectionString("connectionString") + .build(); + + //add table + Mono createTableMono = tableAsyncClient.createTable("tableName"); + + createTableMono.subscribe(void -> { + System.out.println("Table creation successful"); + }, error -> { + System.out.println("There was an error creating the table. Error: " + error); + }); + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsSync.java similarity index 98% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsSync.java index 6877e299e36d..e553ca4b1769 100644 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsSync.java @@ -1,4 +1,4 @@ -package com.azure.cosmos.table.implementation; +package com.azure.data.tables.implementation; import com.azure.core.exception.HttpResponseException; import com.azure.cosmos.table.implementation.models.TableServiceErrorException; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java new file mode 100644 index 000000000000..7cf3b163bc5a --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java @@ -0,0 +1,39 @@ +package com.azure.data.tables.implementation; + +import reactor.core.publisher.Mono; + +import java.util.List; +import java.util.Map; + +public class TableAsyncClient { + + public TableAsyncClient(){ + + } + + public Mono createTable(String name){ } + + public Mono createTableIfNotExist(String name) { } + + public Mono deleteTable(String name) { } + + public List queryTables(String selectString, String filterString){ + return null; + } + + public List queryEntity(String az, String selectString, String filterString){ + return null; + } + + public TableEntity insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ + return new TableEntity(); + } + public TableEntity insertEntity(TableEntity te){ + return te; + } + public Mono deleteEntity(String tableName, TableEntity tableEntity){ } + + public Mono updateEntity(TableEntity te){ } + public TableEntity upsertEntity(TableEntity te){ return new TableEntity(); } + +} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClientBuilder.java new file mode 100644 index 000000000000..e6a176911e34 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClientBuilder.java @@ -0,0 +1,19 @@ +package com.azure.data.tables.implementation; + +public class TableAsyncClientBuilder { + + String connectionString; + + + public TableAsyncClientBuilder connectionString(String connectionString){ + connectionString = connectionString; + return this; + } + public TableAsyncClient build(){ + return new TableAsyncClient(); + } + + public void TableAysncClientBuilder(){ + + } +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClient.java similarity index 50% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClient.java index 9444ac60e39e..680c2f729143 100644 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClient.java @@ -1,38 +1,23 @@ -package com.azure.cosmos.table.implementation; +package com.azure.data.tables.implementation; import java.util.ArrayList; import java.util.List; import java.util.Map; public class TableClient { - String name; + public TableClient(){ } - public AzureTable createTable(String name){ - return new AzureTable(name); - } - - - public TableClient(){ - name = "Hi"; - } + public void createTable(String name){ } - public String getName() { - return name; - } - - public AzureTable createTableIfNotExist(String name) { - return new AzureTable(name); - } - public void deleteTable(AzureTable az) { + public void createTableIfNotExist(String name) { } - } - public void deleteTable(String name) { + public void deleteTable(String name) { } - } public List queryTables(String selectString, String filterString){ return null; } + public List queryEntity(String az, String selectString, String filterString){ return null; } @@ -43,13 +28,8 @@ public TableEntity insertEntity(String tableName, String row, String partition, public TableEntity insertEntity(TableEntity te){ return te; } - public void deleteEntity(String tableName, TableEntity tableEntity){ - - } - public void updateEntity(TableEntity te){ + public void deleteEntity(String tableName, TableEntity tableEntity){ } - } - public TableEntity upsertEntity(TableEntity te){ - return new TableEntity(); - } + public void updateEntity(TableEntity te){ } + public TableEntity upsertEntity(TableEntity te){ return new TableEntity(); } } diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClientBuilder.java similarity index 87% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClientBuilder.java index 8bbe8b0898fb..4473c5ba951f 100644 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClientBuilder.java @@ -1,4 +1,4 @@ -package com.azure.cosmos.table.implementation; +package com.azure.data.tables.implementation; public class TableClientBuilder { String connectionString; diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableEntity.java similarity index 89% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableEntity.java index 7eec0b807ec5..2c73cde6d2ce 100644 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableEntity.java @@ -1,4 +1,4 @@ -package com.azure.cosmos.table.implementation; +package com.azure.data.tables.implementation; import java.util.Map; From 63f19679999ea0000bc98eb7b8ec01bdcb3a007f Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 8 Jun 2020 09:28:57 -0400 Subject: [PATCH 05/42] rebase on connie's branch with test filesCode Snippets, Sync done and Async in progress --- sdk/cosmos/azure-cosmos-table/pom.xml | 110 ------------------ .../table/implementation/AzureTable.java | 25 ++++ .../table/implementation/CodeSnippets.java | 53 +++++++++ .../table/implementation/CodeSnippetsAysnc | 46 ++++++++ .../implementation/CodeSnippetsAysnc.java | 5 + .../table/implementation/CodeSnippetsSync | 48 ++++++++ .../implementation/CodeSnippetsSync.java | 95 +++++++++++++++ .../table/implementation/TableClient.java | 55 +++++++++ .../implementation/TableClientBuilder.java | 19 +++ .../table/implementation/TableEntity.java | 20 ++++ 10 files changed, 366 insertions(+), 110 deletions(-) delete mode 100644 sdk/cosmos/azure-cosmos-table/pom.xml create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java diff --git a/sdk/cosmos/azure-cosmos-table/pom.xml b/sdk/cosmos/azure-cosmos-table/pom.xml deleted file mode 100644 index 9b0b11444ef6..000000000000 --- a/sdk/cosmos/azure-cosmos-table/pom.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - 4.0.0 - - com.azure - azure-client-sdk-parent - 1.7.0 - ../../parents/azure-client-sdk-parent - - - com.azure - azure-data-tables - 1.0.0-beta.1 - Microsoft Azure SDK for Azure Table - This package contains the Microsoft Azure Table storage client library. - https://github.com/Azure/azure-sdk-for-java - - - - azure-java-build-docs - ${site.url}/site/${project.artifactId} - - - - - scm:git:https://github.com/Azure/azure-sdk-for-java - scm:git:git@github.com:Azure/azure-sdk-for-java.git - HEAD - - - - - true - - - - - com.azure - azure-core - 1.5.0 - - - - com.azure - azure-core-test - 1.2.1 - test - - - org.junit.jupiter - junit-jupiter-api - 5.6.2 - test - - - org.junit.jupiter - junit-jupiter-engine - 5.6.2 - test - - - org.junit.jupiter - junit-jupiter-params - 5.6.2 - test - - - io.projectreactor - reactor-test - 3.3.5.RELEASE - test - - - org.mockito - mockito-core - 3.0.0 - test - - - io.projectreactor - reactor-core - 12.7.0-beta.1 - compile - - - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M3 - - - - - com.azure:* - - - - - - - - - diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java new file mode 100644 index 000000000000..e74efb0d81b1 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java @@ -0,0 +1,25 @@ +package com.azure.cosmos.table.implementation; + +import java.util.List; + +public class AzureTable { + + public AzureTable(String name) { + + } + public void insertEntity(TableEntity te){ + + } + public TableEntity insertEntity(String key, Object value){ + + } + public void deleteEntity(TableEntity te){ + + } + public void deleteEntity(String key){ + + } + public List query(String select, String filter){ + return null; + } +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java new file mode 100644 index 000000000000..4e2c556cadcb --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java @@ -0,0 +1,53 @@ +package com.azure.cosmos.table.implementation; + +import com.azure.cosmos.table.implementation.models.TableEntityQueryResponse; + +import javax.swing.*; +import java.util.Observable; + +public class CodeSnippets { + //add a table + + //sync + TableClient tableClientBuilder = new TableClientBuilder(); + .endpoint(foo) + .credential(new DefaultAzureCredential() + .build(); + + .connectionString + + AzureTable azureTable = tableClientBuilder.createTableIfNotExists("tableName"); + + //aysnc + TableAysncClientBuilder tableAysncClient = new TableAsyncClientBuilder(); + .pipeline("pipline") + .build(); + AzureTable azureTable2; + Mono createTableMono = tableAysncClient.createTable("tableName"); + createTableMono + .subscribe( + response -> { + azureTable2 = + }, + error -> { + + } + ) + + + //delete a table + //sync + azureTable.delete(); + + //async + + + + //query a table + + //sync + TableEntityQueryResponse tableEntityQueryResponse = azureTable.query(Filter); + + + //aysnc +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc new file mode 100644 index 000000000000..d5b52e41b1df --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc @@ -0,0 +1,46 @@ +//create a table + +TableAyncClient tableAyncClient = new TableAyncClientBuilder(); + .connectionString("connectionString") + .build(); + +Mono createTableMono = tableAsyncClient.createTable("tableName"); +createTableMono.subscribe((AzureTable azureTable) -> { + System.out.println("Table creation successful, table name: " + azureTable.getName()); + }, error -> { + System.out.println("There was an error creating the table. Error: " + error); +}); + + + +//deleteTable +Mono deleteTableMono = tableAsyncClient.deleteTable("tableName"); +deleteTableMono.subscribe( void -> { + System.out.println("Table Successfully deleted.") + }, error -> { + System.out.println("Table deletion unsuccessful. Error: " + ERROR); +}); + + +//query a table +//queryEntities(string tableName, string filter, string select ...) +String query = "filter: $"PartitionKey eq '{PartitionKeyValue}' and RowKey eq '{x}'" +Flux queryEntities = tableAsyncClient.queryEntities("tableName", query); +queryEntities.flatMap( (Map resultEntity) -> { + return new tableEntity(resultEntity.get(), +} + +//add an entity + +Mono getTableMono = tableAsyncClient.getTable("TableName"); +getTableMono.flatMap( azureTable -> { + Mono azureTableEntity = azureTable.createEntity("value","rowKey","partitionKey"); + return azureTableEntity; + }.map(azureTableEntity -> { + System.out.println("Successfully added" + azureTableEntity.getValue() + "to table."); + }, error -> { + System.out.println("Unsuccessful"); + }); + + + diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java new file mode 100644 index 000000000000..d72dde11f61a --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java @@ -0,0 +1,5 @@ +package com.azure.cosmos.table.implementation; + +public class CodeSnippetsAysnc { + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync new file mode 100644 index 000000000000..9f6e6722a016 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync @@ -0,0 +1,48 @@ + + +//create table + +TableClient tableClient = new TableClientBuilder(); + .connectionString("connectionString") + .build(); + +//two options to create a table +tableClient.createTableIfNotExists("tableName"); +tableClient.createTable("tableName"); + + + +//delete table +azureTable.delete(); + + +//query tables +List responseTables = tableClient.query(); + + +// +class TableEntity { +String rowKey +String partitionKey +Map value + +} + +//insert entity +TableEntity tableEntity = new TableEntity(String key, Object value); +azureTable.insert(tableEntity); + +//delete entity +azureTable.delete(tableEntity); + +//update entity +//key to object containing properties (which consumer handles) +azureTable.update(oldEntity.getRowKey(), newEntity); +azureTable.update(newEntity); //new entity has existing row key that is unique + + +//creating odata query and listing entities +some sort of odata builder + +List = azureTable.query(odataQuery); + diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java new file mode 100644 index 000000000000..6877e299e36d --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java @@ -0,0 +1,95 @@ +package com.azure.cosmos.table.implementation; + +import com.azure.core.exception.HttpResponseException; +import com.azure.cosmos.table.implementation.models.TableServiceErrorException; +import com.azure.cosmos.table.implementation.models.TablesQueryEntitiesResponse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CodeSnippetsSync { + + public static void methods(){ + + //client-builder pattern + TableClientBuilder tableClientBuilder = new TableClientBuilder(); + TableClient tableClient = new TableClientBuilder() + .connectionString("connectionString") + .build(); + + + //create a table + try { + tableClient.createTable("Office Supplies;"); + } catch (TableServiceErrorException e) { + System.out.println("Create Table Unsuccessful. Error: " + e); + } + + //delete table + try { + tableClient.deleteTable("Office Supplies"); + } catch (TableServiceErrorException e) { + System.out.println("Delete Table Unsuccessful. Error: " + e); + } + + //query tables + String filterString = "$filter= name eq 'Office Supplies'"; + String selectString = "$select= Product, Price"; + try { + List responseTables = tableClient.queryTables(selectString, filterString); + } catch (HttpResponseException e){ + System.out.println("Table Query Unsuccessful. Error: " + e); + } + + + //insert entity + String tableName = "Office Supplies"; + String row = "crayola markers"; + String partitionKey = "markers"; + HashMap tableEntityProperties = new HashMap<>(); + TableEntity tableEntity = new TableEntity(tableName, row, partitionKey, tableEntityProperties); + try { + tableEntity = tableClient.insertEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Insert Entity Unsuccessful. Error: " + e); + } + + + //update entity + tableEntity.addProperty("Seller","Crayola"); + try { + tableClient.updateEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Update Entity Unsuccessful. Error: " + e); + } + + + //upsert entity + tableEntity.addProperty("Price","$5"); + try { + tableEntity = tableClient.upsertEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Upsert Entity Unsuccessful. Error: " + e); + } + + + //delete entity + try { + tableClient.deleteEntity(tableName, tableEntity); + } catch (HttpResponseException e){ + System.out.println("Delete Entity Unsuccessful. Error: " + e); + } + + + //query a table + String filterString2 = "$filter = Product eq 'markers'"; + String selectString2 = "$select = Seller eq 'crayola'"; + try { + List list= tableClient.queryEntity(tableName, filterString2, selectString2); + } catch (HttpResponseException e){ + System.out.println("Query Table Entities Unsuccessful. Error: " + e); + } + } + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java new file mode 100644 index 000000000000..9444ac60e39e --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java @@ -0,0 +1,55 @@ +package com.azure.cosmos.table.implementation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class TableClient { + String name; + + + public AzureTable createTable(String name){ + return new AzureTable(name); + } + + + public TableClient(){ + name = "Hi"; + } + + public String getName() { + return name; + } + + public AzureTable createTableIfNotExist(String name) { + return new AzureTable(name); + } + public void deleteTable(AzureTable az) { + + } + public void deleteTable(String name) { + + } + public List queryTables(String selectString, String filterString){ + return null; + } + public List queryEntity(String az, String selectString, String filterString){ + return null; + } + + public TableEntity insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ + return new TableEntity(); + } + public TableEntity insertEntity(TableEntity te){ + return te; + } + public void deleteEntity(String tableName, TableEntity tableEntity){ + + } + public void updateEntity(TableEntity te){ + + } + public TableEntity upsertEntity(TableEntity te){ + return new TableEntity(); + } +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java new file mode 100644 index 000000000000..8bbe8b0898fb --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java @@ -0,0 +1,19 @@ +package com.azure.cosmos.table.implementation; + +public class TableClientBuilder { + String connectionString; + + + public TableClientBuilder connectionString(String connectionString){ + connectionString = connectionString; + return this; + } + public TableClient build(){ + return new TableClient(); + } + + public TableClientBuilder(){ + + } + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java new file mode 100644 index 000000000000..7eec0b807ec5 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java @@ -0,0 +1,20 @@ +package com.azure.cosmos.table.implementation; + +import java.util.Map; + +public class TableEntity { + Map properties; + public TableEntity(){ + + } + public TableEntity(String table, String row, String partition, Map properties){ + this.properties = properties; + } + + public Map getProperties(){ + return properties; + } + public void addProperty(String key, Object value){ + + } +} From 0d9dc52576530913c2ebb2f7a5c5b7ce8db44fe6 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 8 Jun 2020 16:42:51 -0400 Subject: [PATCH 06/42] sync + async --- .../table/implementation/AzureTable.java | 0 .../table/implementation/CodeSnippets.java | 0 .../table/implementation/CodeSnippetsAysnc | 0 .../implementation/CodeSnippetsAysnc.java | 0 .../table/implementation/CodeSnippetsSync | 0 .../implementation/CodeSnippetsSync.java | 0 .../table/implementation/TableClient.java | 0 .../implementation/TableClientBuilder.java | 0 .../table/implementation/TableEntity.java | 0 .../implementation/CodeSnippetsAysnc.java | 209 ++++++++++++++++-- .../implementation/CodeSnippetsSync.java | 3 +- .../implementation/TableAsyncClient.java | 25 ++- .../com/azure/data/tables/autorestTest.java | 73 ++++++ 13 files changed, 279 insertions(+), 31 deletions(-) rename sdk/cosmos/{ => azure-cosmos}/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java (100%) rename sdk/cosmos/{ => azure-cosmos}/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java (100%) rename sdk/cosmos/{ => azure-cosmos}/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc (100%) rename sdk/cosmos/{ => azure-cosmos}/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java (100%) rename sdk/cosmos/{ => azure-cosmos}/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync (100%) rename sdk/cosmos/{ => azure-cosmos}/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java (100%) rename sdk/cosmos/{ => azure-cosmos}/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java (100%) rename sdk/cosmos/{ => azure-cosmos}/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java (100%) rename sdk/cosmos/{ => azure-cosmos}/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java (100%) create mode 100644 sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/autorestTest.java diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java similarity index 100% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java rename to sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java similarity index 100% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java rename to sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc similarity index 100% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc rename to sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java similarity index 100% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java rename to sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync similarity index 100% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync rename to sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java similarity index 100% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java rename to sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java similarity index 100% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java rename to sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java similarity index 100% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java rename to sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java similarity index 100% rename from sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java rename to sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java index d99686d067e3..ee561444485a 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java @@ -1,29 +1,204 @@ package com.azure.data.tables.implementation; +import com.azure.core.exception.HttpResponseException; +import reactor.core.Disposable; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import reactor.core.*; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; +import java.util.HashMap; +import java.util.List; -import java.time.Duration; -import java.util.concurrent.TimeUnit; public class CodeSnippetsAysnc { - //client-builder pattern - TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); - TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() - .connectionString("connectionString") - .build(); - //add table - Mono createTableMono = tableAsyncClient.createTable("tableName"); + public void AsyncSnippets() { + + //client-builder pattern + TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); + TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + .connectionString("connectionString") + .build(); + + //add table + Mono createTableMono = tableAsyncClient.createTable("tableName"); + + createTableMono.subscribe(Void -> { + System.out.println("Table creation successful."); + }, error -> { + System.out.println("There was an error creating the table. Error: " + error); + }); + + //delete a table + Mono deleteTableMono = tableAsyncClient.deleteTable("tableName"); + + deleteTableMono.subscribe(Void -> { + System.out.println("Table deletion successful"); + }, error -> { + System.out.println("There was an error deleting the table. Error: " + error); + }); + + + //query tables + String filterString = "$filter= name eq 'Office Supplies'"; + String selectString = "$select= Product, Price"; + Flux queryTableFlux = tableAsyncClient.queryTables(selectString, filterString); + Disposable subscription = queryTableFlux.subscribe(s -> { + System.out.println(s); + }, error -> { + System.out.println("There was an error querying the table. Error: " + error); + }); + } + + public void InsertEntity(){ + + //client-builder pattern + TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); + TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + .connectionString("connectionString") + .build(); + + + Mono createTableMono = tableAsyncClient.createTable("tableName"); + + createTableMono.flatMap(Void -> { + System.out.println("Table creation successful."); + + String tableName = "Office Supplies"; + String row = "crayola markers"; + String partitionKey = "markers"; + HashMap tableEntityProperties = new HashMap<>(); + Mono insertEntityMono = tableAsyncClient.insertEntity(tableName, row, partitionKey, tableEntityProperties); + return insertEntityMono; + }).subscribe(tableEntity1 -> { + System.out.println("Insert Entity Successful. Entity: " + tableEntity1); + }, error -> { + System.out.println("There was an error inserting the Entity. Error: " + error); + }); + + + } + + public void DeleteEntity(){ + + //client-builder pattern + TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); + TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + .connectionString("connectionString") + .build(); + + Mono createTableMono = tableAsyncClient.createTable("tableName"); + createTableMono.flatMap(Void -> { + System.out.println("Table creation successful."); + + String tableName = "Office Supplies"; + String row = "crayola markers"; + String partitionKey = "markers"; + HashMap tableEntityProperties = new HashMap<>(); + Mono insertEntityMono = tableAsyncClient.insertEntity(tableName, row, partitionKey, tableEntityProperties); + return insertEntityMono; + }).flatMap(tableEntity1 -> { + System.out.println("Insert Entity Successful. Table Entity: " + tableEntity1); + Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity1); + return deleteEntityMono; + }).subscribe(tableEntity1 -> { + System.out.println("Delete Entity Successful. Entity: " + tableEntity1); + }, error -> { + System.out.println("There was an error deleting the Entity. Error: " + error); + }); + + + } + public void UpdateEntity(){ + + //client-builder pattern + TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); + TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + .connectionString("connectionString") + .build(); + + Mono createTableMono = tableAsyncClient.createTable("tableName"); + createTableMono.flatMap(Void -> { + System.out.println("Table creation successful."); + + String tableName = "Office Supplies"; + String row = "crayola markers"; + String partitionKey = "markers"; + HashMap tableEntityProperties = new HashMap<>(); + Mono insertEntityMono = tableAsyncClient.insertEntity(tableName, row, partitionKey, tableEntityProperties); + return insertEntityMono; + }).flatMap(tableEntity1 -> { + System.out.println("Insert Entity Successful. Table Entity: " + tableEntity1); + + tableEntity1.addProperty("Seller","Crayola"); + Mono updateEntityMono = tableAsyncClient.updateEntity(tableEntity1); + return updateEntityMono; + }).subscribe(Void -> { + System.out.println("Update Entity Successful."); + }, error -> { + System.out.println("There was an error updating the Entity. Error: " + error); + }); + + + } + + public void UpsertEntity(){ + + //client-builder pattern + TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); + TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + .connectionString("connectionString") + .build(); + + + Mono createTableMono = tableAsyncClient.createTable("tableName"); + createTableMono.flatMap(Void -> { + System.out.println("Table creation successful."); + + String tableName = "Office Supplies"; + String row = "crayola markers"; + String partitionKey = "markers"; + HashMap tableEntityProperties = new HashMap<>(); + Mono insertEntityMono = tableAsyncClient.insertEntity(tableName, row, partitionKey, tableEntityProperties); + return insertEntityMono; + }).flatMap(tableEntity1 -> { + System.out.println("Insert Entity Successful. Table Entity: " + tableEntity1); + + tableEntity1.addProperty("Price","$5"); + Mono upsertEntityMono = tableAsyncClient.upsertEntity(tableEntity1); + return upsertEntityMono; + }).subscribe(tableEntity1 -> { + System.out.println("Upsert Entity Successful. Entity: " + tableEntity1); + }, error -> { + System.out.println("There was an error upserting the Entity. Error: " + error); + }); + + + } + + public void QueryEntities(){ + + //client-builder pattern + TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); + TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + .connectionString("connectionString") + .build(); + + + Mono createTableMono = tableAsyncClient.createTable("tableName"); + createTableMono.flatMap(Void -> { + System.out.println("Table creation successful."); + + String filterString2 = "$filter = Product eq 'markers'"; + String selectString2 = "$select = Seller eq 'crayola'"; + Flux queryTableEntity = tableAsyncClient.queryEntity("tableName", filterString2, selectString2); + return queryTableEntity; + }).subscribe(tableEntity1 -> { + System.out.println("Table Entity: " + tableEntity1); + }, error -> { + System.out.println("There was an error querying the table. Error: " + error); + }); - createTableMono.subscribe(void -> { - System.out.println("Table creation successful"); - }, error -> { - System.out.println("There was an error creating the table. Error: " + error); - }); + } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsSync.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsSync.java index e553ca4b1769..852a70095496 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsSync.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsSync.java @@ -1,8 +1,7 @@ package com.azure.data.tables.implementation; import com.azure.core.exception.HttpResponseException; -import com.azure.cosmos.table.implementation.models.TableServiceErrorException; -import com.azure.cosmos.table.implementation.models.TablesQueryEntitiesResponse; +import com.azure.data.tables.implementation.models.TableServiceErrorException; import java.util.HashMap; import java.util.List; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java index 7cf3b163bc5a..b0e21eff997a 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java @@ -1,5 +1,6 @@ package com.azure.data.tables.implementation; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.List; @@ -11,29 +12,29 @@ public TableAsyncClient(){ } - public Mono createTable(String name){ } + public Mono createTable(String name){return Mono.empty(); } - public Mono createTableIfNotExist(String name) { } + public Mono createTableIfNotExist(String name) {return Mono.empty(); } - public Mono deleteTable(String name) { } + public Mono deleteTable(String name) {return Mono.empty(); } - public List queryTables(String selectString, String filterString){ + public Flux queryTables(String selectString, String filterString){ return null; } - public List queryEntity(String az, String selectString, String filterString){ + public Flux queryEntity(String az, String selectString, String filterString){ return null; } - public TableEntity insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ - return new TableEntity(); + public Mono insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ + return null; } - public TableEntity insertEntity(TableEntity te){ - return te; + public Mono insertEntity(TableEntity te){ + return null; } - public Mono deleteEntity(String tableName, TableEntity tableEntity){ } + public Mono deleteEntity(TableEntity tableEntity){return Mono.empty(); } - public Mono updateEntity(TableEntity te){ } - public TableEntity upsertEntity(TableEntity te){ return new TableEntity(); } + public Mono updateEntity(TableEntity te){ return Mono.empty(); } + public Mono upsertEntity(TableEntity te){ return null; } } diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/autorestTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/autorestTest.java new file mode 100644 index 000000000000..60f956e29343 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/autorestTest.java @@ -0,0 +1,73 @@ +package com.azure.data.tables; + +import com.azure.data.tables.implementation.AzureTableImpl; +import com.azure.data.tables.implementation.AzureTableImplBuilder; +import com.azure.data.tables.implementation.TablesImpl; +import org.junit.jupiter.api.Test; +import reactor.core.publisher.Mono; + +import java.time.Duration; +import java.util.concurrent.TimeUnit; + +public class autorestTest { + + private AzureTableImpl createClient() { + final String connectionString = System.getenv("azure_tables_connection_string"); + final ServiceBusSharedKeyCredential credential = new ServiceBusSharedKeyCredential( + properties.getSharedAccessKeyName(), properties.getSharedAccessKey()); + final List policies = new ArrayList<>(); + policies.add(new UserAgentPolicy()); + policies.add(new ServiceBusTokenCredentialHttpPolicy(credential)); + policies.add(new HttpLoggingPolicy(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))); + + final HttpClient httpClientToUse; + if (interceptorManager.isPlaybackMode()) { + httpClientToUse = interceptorManager.getPlaybackClient(); + } else { + httpClientToUse = httpClient; + policies.add(interceptorManager.getRecordPolicy()); + policies.add(new RetryPolicy()); + } + + final HttpPipeline pipeline = new HttpPipelineBuilder() + .httpClient(httpClientToUse) + .policies(policies.toArray(new HttpPipelinePolicy[0])) + .build(); + + return new ServiceBusManagementClientImplBuilder() + .serializer(serializer) + .endpoint(properties.getEndpoint().getHost()) + .apiVersion("2017-04") + .pipeline(pipeline) + .buildClient(); + } + + + + + + + @Test + void createTableTest() { + AzureTableImplBuilder atib = new AzureTableImplBuilder() + .url() + .pipeline() + + } + + + @Test + void createAndUpdateTable() throws InterruptedException { + } + + /** + * We've fixed this by caching the result of the `createTable` operation if it is successful. So we don't try to + * create the table again. + * + * See {@link #createAndUpdateTable()} + */ + @Test + void createAndUpdateTableFixed() throws InterruptedException { + + } +} From 87f1baa24f3ad6225d634145cdd888eeb4e523e2 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 8 Jun 2020 09:28:57 -0400 Subject: [PATCH 07/42] rebase with changes that move Table to new folderCode Snippets, Sync done and Async in progress --- .../table/implementation/AzureTable.java | 25 +++++ .../table/implementation/CodeSnippets.java | 53 +++++++++++ .../table/implementation/CodeSnippetsAysnc | 46 +++++++++ .../implementation/CodeSnippetsAysnc.java | 5 + .../table/implementation/CodeSnippetsSync | 48 ++++++++++ .../implementation/CodeSnippetsSync.java | 95 +++++++++++++++++++ .../table/implementation/TableClient.java | 55 +++++++++++ .../implementation/TableClientBuilder.java | 19 ++++ .../table/implementation/TableEntity.java | 20 ++++ 9 files changed, 366 insertions(+) create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java new file mode 100644 index 000000000000..e74efb0d81b1 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java @@ -0,0 +1,25 @@ +package com.azure.cosmos.table.implementation; + +import java.util.List; + +public class AzureTable { + + public AzureTable(String name) { + + } + public void insertEntity(TableEntity te){ + + } + public TableEntity insertEntity(String key, Object value){ + + } + public void deleteEntity(TableEntity te){ + + } + public void deleteEntity(String key){ + + } + public List query(String select, String filter){ + return null; + } +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java new file mode 100644 index 000000000000..4e2c556cadcb --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java @@ -0,0 +1,53 @@ +package com.azure.cosmos.table.implementation; + +import com.azure.cosmos.table.implementation.models.TableEntityQueryResponse; + +import javax.swing.*; +import java.util.Observable; + +public class CodeSnippets { + //add a table + + //sync + TableClient tableClientBuilder = new TableClientBuilder(); + .endpoint(foo) + .credential(new DefaultAzureCredential() + .build(); + + .connectionString + + AzureTable azureTable = tableClientBuilder.createTableIfNotExists("tableName"); + + //aysnc + TableAysncClientBuilder tableAysncClient = new TableAsyncClientBuilder(); + .pipeline("pipline") + .build(); + AzureTable azureTable2; + Mono createTableMono = tableAysncClient.createTable("tableName"); + createTableMono + .subscribe( + response -> { + azureTable2 = + }, + error -> { + + } + ) + + + //delete a table + //sync + azureTable.delete(); + + //async + + + + //query a table + + //sync + TableEntityQueryResponse tableEntityQueryResponse = azureTable.query(Filter); + + + //aysnc +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc new file mode 100644 index 000000000000..d5b52e41b1df --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc @@ -0,0 +1,46 @@ +//create a table + +TableAyncClient tableAyncClient = new TableAyncClientBuilder(); + .connectionString("connectionString") + .build(); + +Mono createTableMono = tableAsyncClient.createTable("tableName"); +createTableMono.subscribe((AzureTable azureTable) -> { + System.out.println("Table creation successful, table name: " + azureTable.getName()); + }, error -> { + System.out.println("There was an error creating the table. Error: " + error); +}); + + + +//deleteTable +Mono deleteTableMono = tableAsyncClient.deleteTable("tableName"); +deleteTableMono.subscribe( void -> { + System.out.println("Table Successfully deleted.") + }, error -> { + System.out.println("Table deletion unsuccessful. Error: " + ERROR); +}); + + +//query a table +//queryEntities(string tableName, string filter, string select ...) +String query = "filter: $"PartitionKey eq '{PartitionKeyValue}' and RowKey eq '{x}'" +Flux queryEntities = tableAsyncClient.queryEntities("tableName", query); +queryEntities.flatMap( (Map resultEntity) -> { + return new tableEntity(resultEntity.get(), +} + +//add an entity + +Mono getTableMono = tableAsyncClient.getTable("TableName"); +getTableMono.flatMap( azureTable -> { + Mono azureTableEntity = azureTable.createEntity("value","rowKey","partitionKey"); + return azureTableEntity; + }.map(azureTableEntity -> { + System.out.println("Successfully added" + azureTableEntity.getValue() + "to table."); + }, error -> { + System.out.println("Unsuccessful"); + }); + + + diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java new file mode 100644 index 000000000000..d72dde11f61a --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java @@ -0,0 +1,5 @@ +package com.azure.cosmos.table.implementation; + +public class CodeSnippetsAysnc { + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync new file mode 100644 index 000000000000..9f6e6722a016 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync @@ -0,0 +1,48 @@ + + +//create table + +TableClient tableClient = new TableClientBuilder(); + .connectionString("connectionString") + .build(); + +//two options to create a table +tableClient.createTableIfNotExists("tableName"); +tableClient.createTable("tableName"); + + + +//delete table +azureTable.delete(); + + +//query tables +List responseTables = tableClient.query(); + + +// +class TableEntity { +String rowKey +String partitionKey +Map value + +} + +//insert entity +TableEntity tableEntity = new TableEntity(String key, Object value); +azureTable.insert(tableEntity); + +//delete entity +azureTable.delete(tableEntity); + +//update entity +//key to object containing properties (which consumer handles) +azureTable.update(oldEntity.getRowKey(), newEntity); +azureTable.update(newEntity); //new entity has existing row key that is unique + + +//creating odata query and listing entities +some sort of odata builder + +List = azureTable.query(odataQuery); + diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java new file mode 100644 index 000000000000..6877e299e36d --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java @@ -0,0 +1,95 @@ +package com.azure.cosmos.table.implementation; + +import com.azure.core.exception.HttpResponseException; +import com.azure.cosmos.table.implementation.models.TableServiceErrorException; +import com.azure.cosmos.table.implementation.models.TablesQueryEntitiesResponse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CodeSnippetsSync { + + public static void methods(){ + + //client-builder pattern + TableClientBuilder tableClientBuilder = new TableClientBuilder(); + TableClient tableClient = new TableClientBuilder() + .connectionString("connectionString") + .build(); + + + //create a table + try { + tableClient.createTable("Office Supplies;"); + } catch (TableServiceErrorException e) { + System.out.println("Create Table Unsuccessful. Error: " + e); + } + + //delete table + try { + tableClient.deleteTable("Office Supplies"); + } catch (TableServiceErrorException e) { + System.out.println("Delete Table Unsuccessful. Error: " + e); + } + + //query tables + String filterString = "$filter= name eq 'Office Supplies'"; + String selectString = "$select= Product, Price"; + try { + List responseTables = tableClient.queryTables(selectString, filterString); + } catch (HttpResponseException e){ + System.out.println("Table Query Unsuccessful. Error: " + e); + } + + + //insert entity + String tableName = "Office Supplies"; + String row = "crayola markers"; + String partitionKey = "markers"; + HashMap tableEntityProperties = new HashMap<>(); + TableEntity tableEntity = new TableEntity(tableName, row, partitionKey, tableEntityProperties); + try { + tableEntity = tableClient.insertEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Insert Entity Unsuccessful. Error: " + e); + } + + + //update entity + tableEntity.addProperty("Seller","Crayola"); + try { + tableClient.updateEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Update Entity Unsuccessful. Error: " + e); + } + + + //upsert entity + tableEntity.addProperty("Price","$5"); + try { + tableEntity = tableClient.upsertEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Upsert Entity Unsuccessful. Error: " + e); + } + + + //delete entity + try { + tableClient.deleteEntity(tableName, tableEntity); + } catch (HttpResponseException e){ + System.out.println("Delete Entity Unsuccessful. Error: " + e); + } + + + //query a table + String filterString2 = "$filter = Product eq 'markers'"; + String selectString2 = "$select = Seller eq 'crayola'"; + try { + List list= tableClient.queryEntity(tableName, filterString2, selectString2); + } catch (HttpResponseException e){ + System.out.println("Query Table Entities Unsuccessful. Error: " + e); + } + } + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java new file mode 100644 index 000000000000..9444ac60e39e --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java @@ -0,0 +1,55 @@ +package com.azure.cosmos.table.implementation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class TableClient { + String name; + + + public AzureTable createTable(String name){ + return new AzureTable(name); + } + + + public TableClient(){ + name = "Hi"; + } + + public String getName() { + return name; + } + + public AzureTable createTableIfNotExist(String name) { + return new AzureTable(name); + } + public void deleteTable(AzureTable az) { + + } + public void deleteTable(String name) { + + } + public List queryTables(String selectString, String filterString){ + return null; + } + public List queryEntity(String az, String selectString, String filterString){ + return null; + } + + public TableEntity insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ + return new TableEntity(); + } + public TableEntity insertEntity(TableEntity te){ + return te; + } + public void deleteEntity(String tableName, TableEntity tableEntity){ + + } + public void updateEntity(TableEntity te){ + + } + public TableEntity upsertEntity(TableEntity te){ + return new TableEntity(); + } +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java new file mode 100644 index 000000000000..8bbe8b0898fb --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java @@ -0,0 +1,19 @@ +package com.azure.cosmos.table.implementation; + +public class TableClientBuilder { + String connectionString; + + + public TableClientBuilder connectionString(String connectionString){ + connectionString = connectionString; + return this; + } + public TableClient build(){ + return new TableClient(); + } + + public TableClientBuilder(){ + + } + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java new file mode 100644 index 000000000000..7eec0b807ec5 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java @@ -0,0 +1,20 @@ +package com.azure.cosmos.table.implementation; + +import java.util.Map; + +public class TableEntity { + Map properties; + public TableEntity(){ + + } + public TableEntity(String table, String row, String partition, Map properties){ + this.properties = properties; + } + + public Map getProperties(){ + return properties; + } + public void addProperty(String key, Object value){ + + } +} From af877ee34bc9a6089ad45c68d2e6d190777dbfa1 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 8 Jun 2020 09:53:42 -0400 Subject: [PATCH 08/42] stashing --- .../table/implementation/AzureTable.java | 2 +- .../implementation/CodeSnippetsAysnc.java | 2 +- .../table/implementation/CodeSnippetsSync | 48 ------------------- 3 files changed, 2 insertions(+), 50 deletions(-) delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java index e74efb0d81b1..25a3af3e009d 100644 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java @@ -11,7 +11,7 @@ public void insertEntity(TableEntity te){ } public TableEntity insertEntity(String key, Object value){ - + return null; } public void deleteEntity(TableEntity te){ diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java index d72dde11f61a..74fd061138ec 100644 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java @@ -1,5 +1,5 @@ package com.azure.cosmos.table.implementation; public class CodeSnippetsAysnc { - + } diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync deleted file mode 100644 index 9f6e6722a016..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync +++ /dev/null @@ -1,48 +0,0 @@ - - -//create table - -TableClient tableClient = new TableClientBuilder(); - .connectionString("connectionString") - .build(); - -//two options to create a table -tableClient.createTableIfNotExists("tableName"); -tableClient.createTable("tableName"); - - - -//delete table -azureTable.delete(); - - -//query tables -List responseTables = tableClient.query(); - - -// -class TableEntity { -String rowKey -String partitionKey -Map value - -} - -//insert entity -TableEntity tableEntity = new TableEntity(String key, Object value); -azureTable.insert(tableEntity); - -//delete entity -azureTable.delete(tableEntity); - -//update entity -//key to object containing properties (which consumer handles) -azureTable.update(oldEntity.getRowKey(), newEntity); -azureTable.update(newEntity); //new entity has existing row key that is unique - - -//creating odata query and listing entities -some sort of odata builder - -List = azureTable.query(odataQuery); - From 07c6fb7da9694f3ee25ac97289c1cffdd14e898a Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 8 Jun 2020 11:35:48 -0400 Subject: [PATCH 09/42] rebase with folder changes for tables --- sdk/cosmos/azure-cosmos-table/pom.xml | 110 ++++++++++++++++++ .../table/implementation/AzureTable.java | 25 ---- .../table/implementation/CodeSnippets.java | 53 --------- .../table/implementation/CodeSnippetsAysnc | 46 -------- .../implementation/CodeSnippetsAysnc.java | 5 - .../implementation/CodeSnippetsSync.java | 95 --------------- .../table/implementation/TableClient.java | 55 --------- .../implementation/TableClientBuilder.java | 19 --- .../table/implementation/TableEntity.java | 20 ---- 9 files changed, 110 insertions(+), 318 deletions(-) create mode 100644 sdk/cosmos/azure-cosmos-table/pom.xml delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java diff --git a/sdk/cosmos/azure-cosmos-table/pom.xml b/sdk/cosmos/azure-cosmos-table/pom.xml new file mode 100644 index 000000000000..9b0b11444ef6 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/pom.xml @@ -0,0 +1,110 @@ + + + 4.0.0 + + com.azure + azure-client-sdk-parent + 1.7.0 + ../../parents/azure-client-sdk-parent + + + com.azure + azure-data-tables + 1.0.0-beta.1 + Microsoft Azure SDK for Azure Table + This package contains the Microsoft Azure Table storage client library. + https://github.com/Azure/azure-sdk-for-java + + + + azure-java-build-docs + ${site.url}/site/${project.artifactId} + + + + + scm:git:https://github.com/Azure/azure-sdk-for-java + scm:git:git@github.com:Azure/azure-sdk-for-java.git + HEAD + + + + + true + + + + + com.azure + azure-core + 1.5.0 + + + + com.azure + azure-core-test + 1.2.1 + test + + + org.junit.jupiter + junit-jupiter-api + 5.6.2 + test + + + org.junit.jupiter + junit-jupiter-engine + 5.6.2 + test + + + org.junit.jupiter + junit-jupiter-params + 5.6.2 + test + + + io.projectreactor + reactor-test + 3.3.5.RELEASE + test + + + org.mockito + mockito-core + 3.0.0 + test + + + io.projectreactor + reactor-core + 12.7.0-beta.1 + compile + + + + + + + + org.apache.maven.plugins + maven-enforcer-plugin + 3.0.0-M3 + + + + + com.azure:* + + + + + + + + + diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java deleted file mode 100644 index 25a3af3e009d..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import java.util.List; - -public class AzureTable { - - public AzureTable(String name) { - - } - public void insertEntity(TableEntity te){ - - } - public TableEntity insertEntity(String key, Object value){ - return null; - } - public void deleteEntity(TableEntity te){ - - } - public void deleteEntity(String key){ - - } - public List query(String select, String filter){ - return null; - } -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java deleted file mode 100644 index 4e2c556cadcb..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import com.azure.cosmos.table.implementation.models.TableEntityQueryResponse; - -import javax.swing.*; -import java.util.Observable; - -public class CodeSnippets { - //add a table - - //sync - TableClient tableClientBuilder = new TableClientBuilder(); - .endpoint(foo) - .credential(new DefaultAzureCredential() - .build(); - - .connectionString - - AzureTable azureTable = tableClientBuilder.createTableIfNotExists("tableName"); - - //aysnc - TableAysncClientBuilder tableAysncClient = new TableAsyncClientBuilder(); - .pipeline("pipline") - .build(); - AzureTable azureTable2; - Mono createTableMono = tableAysncClient.createTable("tableName"); - createTableMono - .subscribe( - response -> { - azureTable2 = - }, - error -> { - - } - ) - - - //delete a table - //sync - azureTable.delete(); - - //async - - - - //query a table - - //sync - TableEntityQueryResponse tableEntityQueryResponse = azureTable.query(Filter); - - - //aysnc -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc deleted file mode 100644 index d5b52e41b1df..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc +++ /dev/null @@ -1,46 +0,0 @@ -//create a table - -TableAyncClient tableAyncClient = new TableAyncClientBuilder(); - .connectionString("connectionString") - .build(); - -Mono createTableMono = tableAsyncClient.createTable("tableName"); -createTableMono.subscribe((AzureTable azureTable) -> { - System.out.println("Table creation successful, table name: " + azureTable.getName()); - }, error -> { - System.out.println("There was an error creating the table. Error: " + error); -}); - - - -//deleteTable -Mono deleteTableMono = tableAsyncClient.deleteTable("tableName"); -deleteTableMono.subscribe( void -> { - System.out.println("Table Successfully deleted.") - }, error -> { - System.out.println("Table deletion unsuccessful. Error: " + ERROR); -}); - - -//query a table -//queryEntities(string tableName, string filter, string select ...) -String query = "filter: $"PartitionKey eq '{PartitionKeyValue}' and RowKey eq '{x}'" -Flux queryEntities = tableAsyncClient.queryEntities("tableName", query); -queryEntities.flatMap( (Map resultEntity) -> { - return new tableEntity(resultEntity.get(), -} - -//add an entity - -Mono getTableMono = tableAsyncClient.getTable("TableName"); -getTableMono.flatMap( azureTable -> { - Mono azureTableEntity = azureTable.createEntity("value","rowKey","partitionKey"); - return azureTableEntity; - }.map(azureTableEntity -> { - System.out.println("Successfully added" + azureTableEntity.getValue() + "to table."); - }, error -> { - System.out.println("Unsuccessful"); - }); - - - diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java deleted file mode 100644 index 74fd061138ec..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.azure.cosmos.table.implementation; - -public class CodeSnippetsAysnc { - -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java deleted file mode 100644 index 6877e299e36d..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import com.azure.core.exception.HttpResponseException; -import com.azure.cosmos.table.implementation.models.TableServiceErrorException; -import com.azure.cosmos.table.implementation.models.TablesQueryEntitiesResponse; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class CodeSnippetsSync { - - public static void methods(){ - - //client-builder pattern - TableClientBuilder tableClientBuilder = new TableClientBuilder(); - TableClient tableClient = new TableClientBuilder() - .connectionString("connectionString") - .build(); - - - //create a table - try { - tableClient.createTable("Office Supplies;"); - } catch (TableServiceErrorException e) { - System.out.println("Create Table Unsuccessful. Error: " + e); - } - - //delete table - try { - tableClient.deleteTable("Office Supplies"); - } catch (TableServiceErrorException e) { - System.out.println("Delete Table Unsuccessful. Error: " + e); - } - - //query tables - String filterString = "$filter= name eq 'Office Supplies'"; - String selectString = "$select= Product, Price"; - try { - List responseTables = tableClient.queryTables(selectString, filterString); - } catch (HttpResponseException e){ - System.out.println("Table Query Unsuccessful. Error: " + e); - } - - - //insert entity - String tableName = "Office Supplies"; - String row = "crayola markers"; - String partitionKey = "markers"; - HashMap tableEntityProperties = new HashMap<>(); - TableEntity tableEntity = new TableEntity(tableName, row, partitionKey, tableEntityProperties); - try { - tableEntity = tableClient.insertEntity(tableEntity); - } catch (HttpResponseException e){ - System.out.println("Insert Entity Unsuccessful. Error: " + e); - } - - - //update entity - tableEntity.addProperty("Seller","Crayola"); - try { - tableClient.updateEntity(tableEntity); - } catch (HttpResponseException e){ - System.out.println("Update Entity Unsuccessful. Error: " + e); - } - - - //upsert entity - tableEntity.addProperty("Price","$5"); - try { - tableEntity = tableClient.upsertEntity(tableEntity); - } catch (HttpResponseException e){ - System.out.println("Upsert Entity Unsuccessful. Error: " + e); - } - - - //delete entity - try { - tableClient.deleteEntity(tableName, tableEntity); - } catch (HttpResponseException e){ - System.out.println("Delete Entity Unsuccessful. Error: " + e); - } - - - //query a table - String filterString2 = "$filter = Product eq 'markers'"; - String selectString2 = "$select = Seller eq 'crayola'"; - try { - List list= tableClient.queryEntity(tableName, filterString2, selectString2); - } catch (HttpResponseException e){ - System.out.println("Query Table Entities Unsuccessful. Error: " + e); - } - } - -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java deleted file mode 100644 index 9444ac60e39e..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class TableClient { - String name; - - - public AzureTable createTable(String name){ - return new AzureTable(name); - } - - - public TableClient(){ - name = "Hi"; - } - - public String getName() { - return name; - } - - public AzureTable createTableIfNotExist(String name) { - return new AzureTable(name); - } - public void deleteTable(AzureTable az) { - - } - public void deleteTable(String name) { - - } - public List queryTables(String selectString, String filterString){ - return null; - } - public List queryEntity(String az, String selectString, String filterString){ - return null; - } - - public TableEntity insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ - return new TableEntity(); - } - public TableEntity insertEntity(TableEntity te){ - return te; - } - public void deleteEntity(String tableName, TableEntity tableEntity){ - - } - public void updateEntity(TableEntity te){ - - } - public TableEntity upsertEntity(TableEntity te){ - return new TableEntity(); - } -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java deleted file mode 100644 index 8bbe8b0898fb..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.azure.cosmos.table.implementation; - -public class TableClientBuilder { - String connectionString; - - - public TableClientBuilder connectionString(String connectionString){ - connectionString = connectionString; - return this; - } - public TableClient build(){ - return new TableClient(); - } - - public TableClientBuilder(){ - - } - -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java deleted file mode 100644 index 7eec0b807ec5..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import java.util.Map; - -public class TableEntity { - Map properties; - public TableEntity(){ - - } - public TableEntity(String table, String row, String partition, Map properties){ - this.properties = properties; - } - - public Map getProperties(){ - return properties; - } - public void addProperty(String key, Object value){ - - } -} From 0840acd165bf796b4c0ccd9a349ee438656f25ad Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 8 Jun 2020 09:28:57 -0400 Subject: [PATCH 10/42] Code Snippets, Sync done and Async in progress --- .../table/implementation/AzureTable.java | 25 +++++ .../table/implementation/CodeSnippets.java | 53 +++++++++++ .../table/implementation/CodeSnippetsAysnc | 46 +++++++++ .../implementation/CodeSnippetsAysnc.java | 5 + .../table/implementation/CodeSnippetsSync | 48 ++++++++++ .../implementation/CodeSnippetsSync.java | 95 +++++++++++++++++++ .../table/implementation/TableClient.java | 55 +++++++++++ .../implementation/TableClientBuilder.java | 19 ++++ .../table/implementation/TableEntity.java | 20 ++++ 9 files changed, 366 insertions(+) create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java create mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java new file mode 100644 index 000000000000..e74efb0d81b1 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java @@ -0,0 +1,25 @@ +package com.azure.cosmos.table.implementation; + +import java.util.List; + +public class AzureTable { + + public AzureTable(String name) { + + } + public void insertEntity(TableEntity te){ + + } + public TableEntity insertEntity(String key, Object value){ + + } + public void deleteEntity(TableEntity te){ + + } + public void deleteEntity(String key){ + + } + public List query(String select, String filter){ + return null; + } +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java new file mode 100644 index 000000000000..4e2c556cadcb --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java @@ -0,0 +1,53 @@ +package com.azure.cosmos.table.implementation; + +import com.azure.cosmos.table.implementation.models.TableEntityQueryResponse; + +import javax.swing.*; +import java.util.Observable; + +public class CodeSnippets { + //add a table + + //sync + TableClient tableClientBuilder = new TableClientBuilder(); + .endpoint(foo) + .credential(new DefaultAzureCredential() + .build(); + + .connectionString + + AzureTable azureTable = tableClientBuilder.createTableIfNotExists("tableName"); + + //aysnc + TableAysncClientBuilder tableAysncClient = new TableAsyncClientBuilder(); + .pipeline("pipline") + .build(); + AzureTable azureTable2; + Mono createTableMono = tableAysncClient.createTable("tableName"); + createTableMono + .subscribe( + response -> { + azureTable2 = + }, + error -> { + + } + ) + + + //delete a table + //sync + azureTable.delete(); + + //async + + + + //query a table + + //sync + TableEntityQueryResponse tableEntityQueryResponse = azureTable.query(Filter); + + + //aysnc +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc new file mode 100644 index 000000000000..d5b52e41b1df --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc @@ -0,0 +1,46 @@ +//create a table + +TableAyncClient tableAyncClient = new TableAyncClientBuilder(); + .connectionString("connectionString") + .build(); + +Mono createTableMono = tableAsyncClient.createTable("tableName"); +createTableMono.subscribe((AzureTable azureTable) -> { + System.out.println("Table creation successful, table name: " + azureTable.getName()); + }, error -> { + System.out.println("There was an error creating the table. Error: " + error); +}); + + + +//deleteTable +Mono deleteTableMono = tableAsyncClient.deleteTable("tableName"); +deleteTableMono.subscribe( void -> { + System.out.println("Table Successfully deleted.") + }, error -> { + System.out.println("Table deletion unsuccessful. Error: " + ERROR); +}); + + +//query a table +//queryEntities(string tableName, string filter, string select ...) +String query = "filter: $"PartitionKey eq '{PartitionKeyValue}' and RowKey eq '{x}'" +Flux queryEntities = tableAsyncClient.queryEntities("tableName", query); +queryEntities.flatMap( (Map resultEntity) -> { + return new tableEntity(resultEntity.get(), +} + +//add an entity + +Mono getTableMono = tableAsyncClient.getTable("TableName"); +getTableMono.flatMap( azureTable -> { + Mono azureTableEntity = azureTable.createEntity("value","rowKey","partitionKey"); + return azureTableEntity; + }.map(azureTableEntity -> { + System.out.println("Successfully added" + azureTableEntity.getValue() + "to table."); + }, error -> { + System.out.println("Unsuccessful"); + }); + + + diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java new file mode 100644 index 000000000000..d72dde11f61a --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java @@ -0,0 +1,5 @@ +package com.azure.cosmos.table.implementation; + +public class CodeSnippetsAysnc { + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync new file mode 100644 index 000000000000..9f6e6722a016 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync @@ -0,0 +1,48 @@ + + +//create table + +TableClient tableClient = new TableClientBuilder(); + .connectionString("connectionString") + .build(); + +//two options to create a table +tableClient.createTableIfNotExists("tableName"); +tableClient.createTable("tableName"); + + + +//delete table +azureTable.delete(); + + +//query tables +List responseTables = tableClient.query(); + + +// +class TableEntity { +String rowKey +String partitionKey +Map value + +} + +//insert entity +TableEntity tableEntity = new TableEntity(String key, Object value); +azureTable.insert(tableEntity); + +//delete entity +azureTable.delete(tableEntity); + +//update entity +//key to object containing properties (which consumer handles) +azureTable.update(oldEntity.getRowKey(), newEntity); +azureTable.update(newEntity); //new entity has existing row key that is unique + + +//creating odata query and listing entities +some sort of odata builder + +List = azureTable.query(odataQuery); + diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java new file mode 100644 index 000000000000..6877e299e36d --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java @@ -0,0 +1,95 @@ +package com.azure.cosmos.table.implementation; + +import com.azure.core.exception.HttpResponseException; +import com.azure.cosmos.table.implementation.models.TableServiceErrorException; +import com.azure.cosmos.table.implementation.models.TablesQueryEntitiesResponse; + +import java.util.HashMap; +import java.util.List; +import java.util.Map; + +public class CodeSnippetsSync { + + public static void methods(){ + + //client-builder pattern + TableClientBuilder tableClientBuilder = new TableClientBuilder(); + TableClient tableClient = new TableClientBuilder() + .connectionString("connectionString") + .build(); + + + //create a table + try { + tableClient.createTable("Office Supplies;"); + } catch (TableServiceErrorException e) { + System.out.println("Create Table Unsuccessful. Error: " + e); + } + + //delete table + try { + tableClient.deleteTable("Office Supplies"); + } catch (TableServiceErrorException e) { + System.out.println("Delete Table Unsuccessful. Error: " + e); + } + + //query tables + String filterString = "$filter= name eq 'Office Supplies'"; + String selectString = "$select= Product, Price"; + try { + List responseTables = tableClient.queryTables(selectString, filterString); + } catch (HttpResponseException e){ + System.out.println("Table Query Unsuccessful. Error: " + e); + } + + + //insert entity + String tableName = "Office Supplies"; + String row = "crayola markers"; + String partitionKey = "markers"; + HashMap tableEntityProperties = new HashMap<>(); + TableEntity tableEntity = new TableEntity(tableName, row, partitionKey, tableEntityProperties); + try { + tableEntity = tableClient.insertEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Insert Entity Unsuccessful. Error: " + e); + } + + + //update entity + tableEntity.addProperty("Seller","Crayola"); + try { + tableClient.updateEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Update Entity Unsuccessful. Error: " + e); + } + + + //upsert entity + tableEntity.addProperty("Price","$5"); + try { + tableEntity = tableClient.upsertEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Upsert Entity Unsuccessful. Error: " + e); + } + + + //delete entity + try { + tableClient.deleteEntity(tableName, tableEntity); + } catch (HttpResponseException e){ + System.out.println("Delete Entity Unsuccessful. Error: " + e); + } + + + //query a table + String filterString2 = "$filter = Product eq 'markers'"; + String selectString2 = "$select = Seller eq 'crayola'"; + try { + List list= tableClient.queryEntity(tableName, filterString2, selectString2); + } catch (HttpResponseException e){ + System.out.println("Query Table Entities Unsuccessful. Error: " + e); + } + } + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java new file mode 100644 index 000000000000..9444ac60e39e --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java @@ -0,0 +1,55 @@ +package com.azure.cosmos.table.implementation; + +import java.util.ArrayList; +import java.util.List; +import java.util.Map; + +public class TableClient { + String name; + + + public AzureTable createTable(String name){ + return new AzureTable(name); + } + + + public TableClient(){ + name = "Hi"; + } + + public String getName() { + return name; + } + + public AzureTable createTableIfNotExist(String name) { + return new AzureTable(name); + } + public void deleteTable(AzureTable az) { + + } + public void deleteTable(String name) { + + } + public List queryTables(String selectString, String filterString){ + return null; + } + public List queryEntity(String az, String selectString, String filterString){ + return null; + } + + public TableEntity insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ + return new TableEntity(); + } + public TableEntity insertEntity(TableEntity te){ + return te; + } + public void deleteEntity(String tableName, TableEntity tableEntity){ + + } + public void updateEntity(TableEntity te){ + + } + public TableEntity upsertEntity(TableEntity te){ + return new TableEntity(); + } +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java new file mode 100644 index 000000000000..8bbe8b0898fb --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java @@ -0,0 +1,19 @@ +package com.azure.cosmos.table.implementation; + +public class TableClientBuilder { + String connectionString; + + + public TableClientBuilder connectionString(String connectionString){ + connectionString = connectionString; + return this; + } + public TableClient build(){ + return new TableClient(); + } + + public TableClientBuilder(){ + + } + +} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java new file mode 100644 index 000000000000..7eec0b807ec5 --- /dev/null +++ b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java @@ -0,0 +1,20 @@ +package com.azure.cosmos.table.implementation; + +import java.util.Map; + +public class TableEntity { + Map properties; + public TableEntity(){ + + } + public TableEntity(String table, String row, String partition, Map properties){ + this.properties = properties; + } + + public Map getProperties(){ + return properties; + } + public void addProperty(String key, Object value){ + + } +} From 5cf42ad8214121b0f588bdfa5fd88cb662d7d643 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Fri, 12 Jun 2020 10:33:55 -0400 Subject: [PATCH 11/42] code snippets --- sdk/tables/azure-data-tables/pom.xml | 15 +++++++++- .../{implementation => }/CodeSnippetsAysnc | 0 .../CodeSnippetsAysnc.java | 30 +++++++++---------- .../CodeSnippetsSync.java | 19 +++++++----- .../TableAsyncClient.java | 3 +- .../TableAsyncClientBuilder.java | 2 +- .../{implementation => }/TableClient.java | 5 ++-- .../TableClientBuilder.java | 2 +- .../{implementation => }/TableEntity.java | 2 +- 9 files changed, 46 insertions(+), 32 deletions(-) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{implementation => }/CodeSnippetsAysnc (100%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{implementation => }/CodeSnippetsAysnc.java (91%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{implementation => }/CodeSnippetsSync.java (78%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{implementation => }/TableAsyncClient.java (94%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{implementation => }/TableAsyncClientBuilder.java (88%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{implementation => }/TableClient.java (85%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{implementation => }/TableClientBuilder.java (87%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{implementation => }/TableEntity.java (89%) diff --git a/sdk/tables/azure-data-tables/pom.xml b/sdk/tables/azure-data-tables/pom.xml index a8ce90ddaf1d..a1922861ee6e 100644 --- a/sdk/tables/azure-data-tables/pom.xml +++ b/sdk/tables/azure-data-tables/pom.xml @@ -2,7 +2,8 @@ Copyright (c) Microsoft Corporation. All rights reserved. Licensed under the MIT License. --> - + 4.0.0 com.azure @@ -79,6 +80,18 @@ Licensed under the MIT License. 3.0.0 test + + com.azure + azure-storage-common + 12.7.0-beta.1 + test + + + com.azure + azure-storage-common + 12.6.1 + compile + diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc similarity index 100% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java similarity index 91% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java index ee561444485a..97878d707535 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsAysnc.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java @@ -1,4 +1,4 @@ -package com.azure.data.tables.implementation; +package com.azure.data.tables; import com.azure.core.exception.HttpResponseException; import reactor.core.Disposable; @@ -6,7 +6,6 @@ import reactor.core.publisher.Mono; import java.util.HashMap; -import java.util.List; public class CodeSnippetsAysnc { @@ -186,19 +185,18 @@ public void QueryEntities(){ Mono createTableMono = tableAsyncClient.createTable("tableName"); - createTableMono.flatMap(Void -> { - System.out.println("Table creation successful."); - - String filterString2 = "$filter = Product eq 'markers'"; - String selectString2 = "$select = Seller eq 'crayola'"; - Flux queryTableEntity = tableAsyncClient.queryEntity("tableName", filterString2, selectString2); - return queryTableEntity; - }).subscribe(tableEntity1 -> { - System.out.println("Table Entity: " + tableEntity1); - }, error -> { - System.out.println("There was an error querying the table. Error: " + error); - }); + createTableMono.then(Mono.fromCallable(()-> { + System.out.println("Table creation successful."); + + String filterString2 = "$filter = Product eq 'markers'"; + String selectString2 = "$select = Seller eq 'crayola'"; + Flux queryTableEntity = tableAsyncClient.queryEntity("tableName", filterString2, selectString2); + return queryTableEntity; + })).subscribe(tableEntity1 -> { + System.out.println("Table Entity: " + tableEntity1); + }, error -> { + System.out.println("There was an error querying the table. Error: " + error); + }); + } } - -} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsSync.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java similarity index 78% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsSync.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java index 852a70095496..05e9647698d3 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/CodeSnippetsSync.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java @@ -1,11 +1,10 @@ -package com.azure.data.tables.implementation; +package com.azure.data.tables; import com.azure.core.exception.HttpResponseException; import com.azure.data.tables.implementation.models.TableServiceErrorException; import java.util.HashMap; import java.util.List; -import java.util.Map; public class CodeSnippetsSync { @@ -20,22 +19,26 @@ public static void methods(){ //create a table try { - tableClient.createTable("Office Supplies;"); + tableClient.createTable("OfficeSupplies"); } catch (TableServiceErrorException e) { + //use azure core errors? based on System.out.println("Create Table Unsuccessful. Error: " + e); } //delete table try { - tableClient.deleteTable("Office Supplies"); + //equivilant to pass in string var vs string so each person can choose + tableClient.deleteTable("OfficeSupplies"); } catch (TableServiceErrorException e) { System.out.println("Delete Table Unsuccessful. Error: " + e); } //query tables - String filterString = "$filter= name eq 'Office Supplies'"; + String filterString = "$filter= name eq 'OfficeSupplies'"; + //TODO: remove selectString since it is not queried with tables String selectString = "$select= Product, Price"; try { + //TODO: create Table class TableName is the odata feild List responseTables = tableClient.queryTables(selectString, filterString); } catch (HttpResponseException e){ System.out.println("Table Query Unsuccessful. Error: " + e); @@ -43,7 +46,7 @@ public static void methods(){ //insert entity - String tableName = "Office Supplies"; + String tableName = "OfficeSupplies"; String row = "crayola markers"; String partitionKey = "markers"; HashMap tableEntityProperties = new HashMap<>(); @@ -56,6 +59,7 @@ public static void methods(){ //update entity + //TODO: let the customer specify if it is a replacement or a merge? tableEntity.addProperty("Seller","Crayola"); try { tableClient.updateEntity(tableEntity); @@ -65,6 +69,7 @@ public static void methods(){ //upsert entity + //TODO: which upsert do we want to reflect? Replace or merge? Update vs Merge as well tableEntity.addProperty("Price","$5"); try { tableEntity = tableClient.upsertEntity(tableEntity); @@ -75,7 +80,7 @@ public static void methods(){ //delete entity try { - tableClient.deleteEntity(tableName, tableEntity); + tableClient.deleteEntity(tableEntity); } catch (HttpResponseException e){ System.out.println("Delete Entity Unsuccessful. Error: " + e); } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java similarity index 94% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java index b0e21eff997a..c2961b3a665c 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClient.java @@ -1,9 +1,8 @@ -package com.azure.data.tables.implementation; +package com.azure.data.tables; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.util.List; import java.util.Map; public class TableAsyncClient { diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java similarity index 88% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClientBuilder.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java index e6a176911e34..a4b8ad61d87d 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableAsyncClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java @@ -1,4 +1,4 @@ -package com.azure.data.tables.implementation; +package com.azure.data.tables; public class TableAsyncClientBuilder { diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java similarity index 85% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClient.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java index 680c2f729143..f2e5dc30a612 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClient.java @@ -1,6 +1,5 @@ -package com.azure.data.tables.implementation; +package com.azure.data.tables; -import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -28,7 +27,7 @@ public TableEntity insertEntity(String tableName, String row, String partition, public TableEntity insertEntity(TableEntity te){ return te; } - public void deleteEntity(String tableName, TableEntity tableEntity){ } + public void deleteEntity(TableEntity tableEntity){ } public void updateEntity(TableEntity te){ } public TableEntity upsertEntity(TableEntity te){ return new TableEntity(); } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java similarity index 87% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClientBuilder.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java index 4473c5ba951f..ad2a145e6e29 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientBuilder.java @@ -1,4 +1,4 @@ -package com.azure.data.tables.implementation; +package com.azure.data.tables; public class TableClientBuilder { String connectionString; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableEntity.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java similarity index 89% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableEntity.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java index 2c73cde6d2ce..8071c582d1bf 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/implementation/TableEntity.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableEntity.java @@ -1,4 +1,4 @@ -package com.azure.data.tables.implementation; +package com.azure.data.tables; import java.util.Map; From 2e07c02a0b528e2ffb81e26177fd0f91c956a3fb Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Fri, 12 Jun 2020 10:45:33 -0400 Subject: [PATCH 12/42] delete testing from code snippets branch --- .../tables/AzureTablesAsyncClientTest.java | 134 ------------------ .../com/azure/data/tables/autorestTest.java | 73 ---------- 2 files changed, 207 deletions(-) delete mode 100644 sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/AzureTablesAsyncClientTest.java delete mode 100644 sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/autorestTest.java diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/AzureTablesAsyncClientTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/AzureTablesAsyncClientTest.java deleted file mode 100644 index 204c76d433e8..000000000000 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/AzureTablesAsyncClientTest.java +++ /dev/null @@ -1,134 +0,0 @@ -package com.azure.data.tables; - -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; - -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -public class AzureTablesAsyncClientTest { - @Test - void createTableTest() { - // Ideally, we'd use a builder to create this rather than a constructor. - AzureTableAsyncClient client = new AzureTableAsyncClient(); - - // Every time this variable is used in a downstream subscriber, it will invoke the `createTable` operation. - Mono createTableMono = client.createTable("my-table"); - - // This is a subscription to the Mono. `subscribe` is a non-blocking call. - createTableMono.subscribe(table -> { - System.out.println("Table created is: " + table.getName()); - }, error -> { - System.err.println("There was an error creating the table. " + error); - }); - - // Since .subscribe is a non-blocking call, after it hooks up the asynchronous operation, it will move - // onto the next statement. If `client.createTable` takes 30 seconds, the program would have ended before we - // ever know the response because it will leave this method. - // You'll see that there is no "System.out.println" console output because the program has ended. - } - - /** - * Notice how "CREATING TABLE with name: my-table" errors when we try to add another entrythe second time? This is - * because, every time we chain the `createTableMono`, it invokes that `createTable` operation again. - * After an error occurs in one of the operations upstream in the chain, it will call the (error) -> { } handler. - * You'll see that we didn't try to add another entity (ie. new-key-2). - * - * See {@link #createAndUpdateTableFixed()} for a resolved version. - */ - @Test - void createAndUpdateTable() throws InterruptedException { - AzureTableAsyncClient client = new AzureTableAsyncClient(); - - // Every time this variable is used in a downstream subscriber, it will invoke the `createTable` operation. - Mono createTableMono = client.createTable("my-table"); - - // FirstMono -> SecondFlatMap -> Map -> Subscribe - createTableMono.flatMap(azureTable -> { - // We are chaining another operation to this table creation. We want to use the resulting table and - // create an entity in it. We use `flatMap` because it is asynchronous (ie. returns Mono or Flux). - Mono entity = azureTable.createEntity("my-key", "my-value"); - // We return the `createEntity` operation. - return entity; - }).map(azureTableEntity -> { - // This is a transformation, maybe we only care about the value of that entity we added. - return azureTableEntity.getValue(); - }).subscribe(theValue -> { - System.out.println("This was added: " + theValue); - }, error -> { - System.err.println("Error: " + error); - }); - - createTableMono.flatMap(azureTable -> { - // We are chaining another operation to this table creation. We want to use the resulting table and - // create an entity in it. We use `flatMap` because it is asynchronous (ie. returns Mono or Flux). - return azureTable.createEntity("my-key-2", "my-value-2"); - }).map(azureTableEntity -> { - // This is a transformation, maybe we only care about the value of that entity we added. - return azureTableEntity.getValue(); - }).subscribe(theValue -> { - System.out.println("This was added: " + theValue); - }, error -> { - System.err.println("Error: " + error); - }); - - TimeUnit.SECONDS.sleep(20); - } - - /** - * We've fixed this by caching the result of the `createTable` operation if it is successful. So we don't try to - * create the table again. - * - * See {@link #createAndUpdateTable()} - */ - @Test - void createAndUpdateTableFixed() throws InterruptedException { - AzureTableAsyncClient client = new AzureTableAsyncClient(); - - // Every time this variable is used in a downstream subscriber, it will invoke the `createTable` operation. - Mono createTableMono = client.createTable("my-table") - .cache(success -> { - System.out.println("--- Table added. Caching value."); - return Duration.ofSeconds(Long.MAX_VALUE); - }, error -> { - System.out.println("--- Error while adding table. Not caching value."); - return Duration.ZERO; - }, () -> { - // This can occur because Monos can output 0 or 1 items. This would be the case where it output 0 items. - // For example, Mono.empty() will complete, but not output any items. - System.out.println("--- Expected a table to be output, not an empty value. Not caching."); - return Duration.ZERO; - }); - - // FirstMono -> SecondFlatMap -> Map -> Subscribe - createTableMono.flatMap(azureTable -> { - // We are chaining another operation to this table creation. We want to use the resulting table and - // create an entity in it. We use `flatMap` because it is asynchronous (ie. returns Mono or Flux). - Mono entity = azureTable.createEntity("my-new-key", "my-new-value"); - // We return the `createEntity` operation. - return entity; - }).map(azureTableEntity -> { - // This is a transformation, maybe we only care about the value of that entity we added. - return azureTableEntity.getValue(); - }).subscribe(theValue -> { - System.out.println("This was added: " + theValue); - }, error -> { - System.err.println("ERROR: " + error); - }); - - createTableMono.flatMap(azureTable -> { - // We are chaining another operation to this table creation. We want to use the resulting table and - // create an entity in it. We use `flatMap` because it is asynchronous (ie. returns Mono or Flux). - return azureTable.createEntity("my-new-key-2", "my-new-value-2"); - }).map(azureTableEntity -> { - // This is a transformation, maybe we only care about the value of that entity we added. - return azureTableEntity.getValue(); - }).subscribe(theValue -> { - System.out.println("This was added: " + theValue); - }, error -> { - System.err.println("ERROR: " + error); - }); - - TimeUnit.SECONDS.sleep(20); - } -} diff --git a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/autorestTest.java b/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/autorestTest.java deleted file mode 100644 index 60f956e29343..000000000000 --- a/sdk/tables/azure-data-tables/src/test/java/com/azure/data/tables/autorestTest.java +++ /dev/null @@ -1,73 +0,0 @@ -package com.azure.data.tables; - -import com.azure.data.tables.implementation.AzureTableImpl; -import com.azure.data.tables.implementation.AzureTableImplBuilder; -import com.azure.data.tables.implementation.TablesImpl; -import org.junit.jupiter.api.Test; -import reactor.core.publisher.Mono; - -import java.time.Duration; -import java.util.concurrent.TimeUnit; - -public class autorestTest { - - private AzureTableImpl createClient() { - final String connectionString = System.getenv("azure_tables_connection_string"); - final ServiceBusSharedKeyCredential credential = new ServiceBusSharedKeyCredential( - properties.getSharedAccessKeyName(), properties.getSharedAccessKey()); - final List policies = new ArrayList<>(); - policies.add(new UserAgentPolicy()); - policies.add(new ServiceBusTokenCredentialHttpPolicy(credential)); - policies.add(new HttpLoggingPolicy(new HttpLogOptions().setLogLevel(HttpLogDetailLevel.BODY_AND_HEADERS))); - - final HttpClient httpClientToUse; - if (interceptorManager.isPlaybackMode()) { - httpClientToUse = interceptorManager.getPlaybackClient(); - } else { - httpClientToUse = httpClient; - policies.add(interceptorManager.getRecordPolicy()); - policies.add(new RetryPolicy()); - } - - final HttpPipeline pipeline = new HttpPipelineBuilder() - .httpClient(httpClientToUse) - .policies(policies.toArray(new HttpPipelinePolicy[0])) - .build(); - - return new ServiceBusManagementClientImplBuilder() - .serializer(serializer) - .endpoint(properties.getEndpoint().getHost()) - .apiVersion("2017-04") - .pipeline(pipeline) - .buildClient(); - } - - - - - - - @Test - void createTableTest() { - AzureTableImplBuilder atib = new AzureTableImplBuilder() - .url() - .pipeline() - - } - - - @Test - void createAndUpdateTable() throws InterruptedException { - } - - /** - * We've fixed this by caching the result of the `createTable` operation if it is successful. So we don't try to - * create the table again. - * - * See {@link #createAndUpdateTable()} - */ - @Test - void createAndUpdateTableFixed() throws InterruptedException { - - } -} From ee74e38978d3719f71dd42a32dd6cad933d5d1b3 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Fri, 12 Jun 2020 15:18:04 -0400 Subject: [PATCH 13/42] adding service level client --- .../com/azure/data/tables/CodeSnippetsAysnc | 46 ------------------- .../azure/data/tables/CodeSnippetsAysnc.java | 19 +++++--- .../azure/data/tables/CodeSnippetsSync.java | 22 +++++---- .../azure/data/tables/TableAsyncClient.java | 14 +----- .../data/tables/TableAsyncClientBuilder.java | 8 +++- .../data/tables/TableAsyncServiceClient.java | 21 +++++++++ .../TableAsyncServiceClientBuilder.java | 19 ++++++++ .../com/azure/data/tables/TableClient.java | 21 +++------ .../azure/data/tables/TableClientBuilder.java | 10 +++- .../azure/data/tables/TableServiceClient.java | 20 ++++++++ .../tables/TableServiceClientBuilder.java | 20 ++++++++ 11 files changed, 126 insertions(+), 94 deletions(-) delete mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClientBuilder.java create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientBuilder.java diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc deleted file mode 100644 index d5b52e41b1df..000000000000 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc +++ /dev/null @@ -1,46 +0,0 @@ -//create a table - -TableAyncClient tableAyncClient = new TableAyncClientBuilder(); - .connectionString("connectionString") - .build(); - -Mono createTableMono = tableAsyncClient.createTable("tableName"); -createTableMono.subscribe((AzureTable azureTable) -> { - System.out.println("Table creation successful, table name: " + azureTable.getName()); - }, error -> { - System.out.println("There was an error creating the table. Error: " + error); -}); - - - -//deleteTable -Mono deleteTableMono = tableAsyncClient.deleteTable("tableName"); -deleteTableMono.subscribe( void -> { - System.out.println("Table Successfully deleted.") - }, error -> { - System.out.println("Table deletion unsuccessful. Error: " + ERROR); -}); - - -//query a table -//queryEntities(string tableName, string filter, string select ...) -String query = "filter: $"PartitionKey eq '{PartitionKeyValue}' and RowKey eq '{x}'" -Flux queryEntities = tableAsyncClient.queryEntities("tableName", query); -queryEntities.flatMap( (Map resultEntity) -> { - return new tableEntity(resultEntity.get(), -} - -//add an entity - -Mono getTableMono = tableAsyncClient.getTable("TableName"); -getTableMono.flatMap( azureTable -> { - Mono azureTableEntity = azureTable.createEntity("value","rowKey","partitionKey"); - return azureTableEntity; - }.map(azureTableEntity -> { - System.out.println("Successfully added" + azureTableEntity.getValue() + "to table."); - }, error -> { - System.out.println("Unsuccessful"); - }); - - - diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java index 97878d707535..28ed1c200a86 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java @@ -13,14 +13,19 @@ public class CodeSnippetsAysnc { public void AsyncSnippets() { - //client-builder pattern - TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); + //build service client + TableAsyncServiceClient tableAsyncServiceClient = new TableAsyncServiceClientBuilder() + .connectionString("connectionString") + .build(); + + //build table client TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() .connectionString("connectionString") + .tableName("OfficeSupplies") .build(); //add table - Mono createTableMono = tableAsyncClient.createTable("tableName"); + Mono createTableMono = tableAsyncServiceClient.createTable("OfficeSupplies"); createTableMono.subscribe(Void -> { System.out.println("Table creation successful."); @@ -29,7 +34,7 @@ public void AsyncSnippets() { }); //delete a table - Mono deleteTableMono = tableAsyncClient.deleteTable("tableName"); + Mono deleteTableMono = tableAsyncServiceClient.deleteTable("OfficeSupplies"); deleteTableMono.subscribe(Void -> { System.out.println("Table deletion successful"); @@ -39,9 +44,9 @@ public void AsyncSnippets() { //query tables - String filterString = "$filter= name eq 'Office Supplies'"; + String filterString = "$filter= name eq 'OfficeSupplies'"; String selectString = "$select= Product, Price"; - Flux queryTableFlux = tableAsyncClient.queryTables(selectString, filterString); + Flux queryTableFlux = tableAsyncServiceClient.queryTables(filterString); Disposable subscription = queryTableFlux.subscribe(s -> { System.out.println(s); }, error -> { @@ -58,7 +63,7 @@ public void InsertEntity(){ .build(); - Mono createTableMono = tableAsyncClient.createTable("tableName"); + Mono createTableMono = tableAsyncClient.createTable("OfficeSupplies"); createTableMono.flatMap(Void -> { System.out.println("Table creation successful."); diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java index 05e9647698d3..9dba26788ce5 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java @@ -10,16 +10,21 @@ public class CodeSnippetsSync { public static void methods(){ - //client-builder pattern - TableClientBuilder tableClientBuilder = new TableClientBuilder(); + //create a tableServiceClient + TableServiceClient tableServiceClient = new TableServiceClientBuilder() + .connectionString("connectionString") + .build(); + + //create TableClient TableClient tableClient = new TableClientBuilder() .connectionString("connectionString") + .tableName("OfficeSupplies") .build(); //create a table try { - tableClient.createTable("OfficeSupplies"); + tableServiceClient.createTable("OfficeSupplies"); } catch (TableServiceErrorException e) { //use azure core errors? based on System.out.println("Create Table Unsuccessful. Error: " + e); @@ -27,19 +32,17 @@ public static void methods(){ //delete table try { - //equivilant to pass in string var vs string so each person can choose - tableClient.deleteTable("OfficeSupplies"); + tableServiceClient.deleteTable("OfficeSupplies"); } catch (TableServiceErrorException e) { System.out.println("Delete Table Unsuccessful. Error: " + e); } //query tables String filterString = "$filter= name eq 'OfficeSupplies'"; - //TODO: remove selectString since it is not queried with tables - String selectString = "$select= Product, Price"; + try { //TODO: create Table class TableName is the odata feild - List responseTables = tableClient.queryTables(selectString, filterString); + List responseTables = tableServiceClient.queryTables(filterString); } catch (HttpResponseException e){ System.out.println("Table Query Unsuccessful. Error: " + e); } @@ -59,7 +62,7 @@ public static void methods(){ //update entity - //TODO: let the customer specify if it is a replacement or a merge? + //TODO: let the customer specify if it is a replacement or a merge tableEntity.addProperty("Seller","Crayola"); try { tableClient.updateEntity(tableEntity); @@ -69,7 +72,6 @@ public static void methods(){ //upsert entity - //TODO: which upsert do we want to reflect? Replace or merge? Update vs Merge as well tableEntity.addProperty("Price","$5"); try { tableEntity = tableClient.upsertEntity(tableEntity); 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 c2961b3a665c..944f65da995f 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 @@ -7,19 +7,7 @@ public class TableAsyncClient { - public TableAsyncClient(){ - - } - - public Mono createTable(String name){return Mono.empty(); } - - public Mono createTableIfNotExist(String name) {return Mono.empty(); } - - public Mono deleteTable(String name) {return Mono.empty(); } - - public Flux queryTables(String selectString, String filterString){ - return null; - } + public TableAsyncClient(String tableName){ } public Flux queryEntity(String az, String selectString, String filterString){ return null; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java index a4b8ad61d87d..6dc78dbd6556 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java @@ -3,14 +3,20 @@ public class TableAsyncClientBuilder { String connectionString; + String tableName; public TableAsyncClientBuilder connectionString(String connectionString){ connectionString = connectionString; return this; } + + public TableAsyncClientBuilder tableName(String tableName) { + this.tableName = tableName; + return this; + } public TableAsyncClient build(){ - return new TableAsyncClient(); + return new TableAsyncClient(tableName); } public void TableAysncClientBuilder(){ diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java new file mode 100644 index 000000000000..08c10f7c8dde --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java @@ -0,0 +1,21 @@ +package com.azure.data.tables; + +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.Map; + +public class TableAsyncServiceClient{ + + public TableAsyncServiceClient(){ } + public Mono createTable(String name){return Mono.empty(); } + + public Mono createTableIfNotExist(String name) {return Mono.empty(); } + + public Mono deleteTable(String name) {return Mono.empty(); } + + public Flux queryTables(String filterString){ + return null; + } + +} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClientBuilder.java new file mode 100644 index 000000000000..df9e0a40a368 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClientBuilder.java @@ -0,0 +1,19 @@ +package com.azure.data.tables; + +public class TableAsyncServiceClientBuilder { + + String connectionString; + + + public TableAsyncServiceClientBuilder connectionString(String connectionString){ + connectionString = connectionString; + return this; + } + public TableAsyncServiceClient build(){ + return new TableAsyncServiceClient(); + } + + public void TableAysncClientBuilder(){ + + } +} 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 f2e5dc30a612..69b3f3444e90 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 @@ -4,31 +4,22 @@ import java.util.Map; public class TableClient { + String tableName; - public TableClient(){ } - - public void createTable(String name){ } - - public void createTableIfNotExist(String name) { } - - public void deleteTable(String name) { } - - public List queryTables(String selectString, String filterString){ - return null; - } + public TableClient(String tableName){ this.tableName = tableName; } public List queryEntity(String az, String selectString, String filterString){ return null; } - public TableEntity insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ + public TableEntity insertEntity(String row, String partition, Map tableEntityProperties){ return new TableEntity(); } - public TableEntity insertEntity(TableEntity te){ - return te; + public TableEntity insertEntity(TableEntity tableEntity){ + return tableEntity; } public void deleteEntity(TableEntity tableEntity){ } public void updateEntity(TableEntity te){ } - public TableEntity upsertEntity(TableEntity te){ return new TableEntity(); } + public TableEntity upsertEntity(TableEntity tableEntity){ return new TableEntity(); } } 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 ad2a145e6e29..24777e6d23d2 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 @@ -2,14 +2,20 @@ public class TableClientBuilder { String connectionString; + String tableName; public TableClientBuilder connectionString(String connectionString){ - connectionString = connectionString; + this.connectionString = connectionString; return this; } + public TableClientBuilder tableName(String tableName) { + this.tableName = tableName; + return this; + } + public TableClient build(){ - return new TableClient(); + return new TableClient(tableName); } public TableClientBuilder(){ 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 new file mode 100644 index 000000000000..6208e804352c --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClient.java @@ -0,0 +1,20 @@ +package com.azure.data.tables; + +import java.util.List; +import java.util.Map; + +public class TableServiceClient { + + public TableServiceClient(){ } + + public void createTable(String name){ } + + public void createTableIfNotExist(String name) { } + + public void deleteTable(String name) { } + + public List queryTables(String filterString){ + return null; + } + +} 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 new file mode 100644 index 000000000000..0a703a7897e0 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientBuilder.java @@ -0,0 +1,20 @@ +package com.azure.data.tables; + +public class TableServiceClientBuilder { + + String connectionString; + + + public TableServiceClientBuilder connectionString(String connectionString){ + connectionString = connectionString; + return this; + } + public TableServiceClient build(){ + return new TableServiceClient(); + } + + public TableServiceClientBuilder(){ + + } + +} From 330f7b5fe4845a133deb489ad57fea52953270ec Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Tue, 16 Jun 2020 14:22:42 -0400 Subject: [PATCH 14/42] stashing async --- .../azure/data/tables/CodeSnippetsAysnc.java | 22 ++++++++++--------- .../data/tables/TableAsyncServiceClient.java | 4 +++- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java index 28ed1c200a86..838a31c328d5 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java @@ -56,16 +56,16 @@ public void AsyncSnippets() { public void InsertEntity(){ - //client-builder pattern - TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); - TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + //build service client + TableAsyncServiceClient tableAsyncServiceClient = new TableAsyncServiceClientBuilder() .connectionString("connectionString") .build(); - Mono createTableMono = tableAsyncClient.createTable("OfficeSupplies"); - createTableMono.flatMap(Void -> { + Mono createTableMono = tableAsyncServiceClient.createTable("OfficeSupplies"); + + createTableMono.flatMap(tableAsyncClient -> { System.out.println("Table creation successful."); String tableName = "Office Supplies"; @@ -85,14 +85,16 @@ public void InsertEntity(){ public void DeleteEntity(){ - //client-builder pattern - TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); - TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + //build service client + TableAsyncServiceClient tableAsyncServiceClient = new TableAsyncServiceClientBuilder() .connectionString("connectionString") .build(); - Mono createTableMono = tableAsyncClient.createTable("tableName"); - createTableMono.flatMap(Void -> { + + + Mono createTableMono = tableAsyncServiceClient.createTable("OfficeSupplies"); + + createTableMono.flatMap(tableAsyncClient -> { System.out.println("Table creation successful."); String tableName = "Office Supplies"; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java index 08c10f7c8dde..4a32c03d3fd8 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java @@ -8,7 +8,9 @@ public class TableAsyncServiceClient{ public TableAsyncServiceClient(){ } - public Mono createTable(String name){return Mono.empty(); } + //public Mono createTable(String name){return Mono.empty(); } + + public Mono createTable(String name){return null; } public Mono createTableIfNotExist(String name) {return Mono.empty(); } From a409f80d5d9bdcf71cde929987c88e8076e99ff0 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Tue, 16 Jun 2020 16:42:02 -0400 Subject: [PATCH 15/42] fixed async --- .../table/implementation/AzureTable.java | 25 --- .../table/implementation/CodeSnippets.java | 53 ------ .../table/implementation/CodeSnippetsAysnc | 46 ----- .../implementation/CodeSnippetsAysnc.java | 5 - .../table/implementation/CodeSnippetsSync | 48 ----- .../implementation/CodeSnippetsSync.java | 95 ---------- .../table/implementation/TableClient.java | 55 ------ .../implementation/TableClientBuilder.java | 19 -- .../table/implementation/TableEntity.java | 20 -- .../table/implementation/AzureTable.java | 25 --- .../table/implementation/CodeSnippets.java | 53 ------ .../table/implementation/CodeSnippetsAysnc | 46 ----- .../implementation/CodeSnippetsAysnc.java | 5 - .../table/implementation/CodeSnippetsSync | 48 ----- .../implementation/CodeSnippetsSync.java | 95 ---------- .../table/implementation/TableClient.java | 55 ------ .../implementation/TableClientBuilder.java | 19 -- .../table/implementation/TableEntity.java | 20 -- .../azure/data/tables/CodeSnippetsAysnc.java | 173 ++++++------------ .../azure/data/tables/CodeSnippetsSync.java | 19 +- .../azure/data/tables/TableAsyncClient.java | 4 + .../com/azure/data/tables/TableClient.java | 3 +- ...ient.java => TableServiceAsyncClient.java} | 13 +- ...va => TableServiceAsyncClientBuilder.java} | 8 +- 24 files changed, 85 insertions(+), 867 deletions(-) delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java delete mode 100644 sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java delete mode 100644 sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java delete mode 100644 sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java delete mode 100644 sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc delete mode 100644 sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java delete mode 100644 sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync delete mode 100644 sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java delete mode 100644 sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java delete mode 100644 sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java delete mode 100644 sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{TableAsyncServiceClient.java => TableServiceAsyncClient.java} (50%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{TableAsyncServiceClientBuilder.java => TableServiceAsyncClientBuilder.java} (51%) diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java deleted file mode 100644 index e74efb0d81b1..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import java.util.List; - -public class AzureTable { - - public AzureTable(String name) { - - } - public void insertEntity(TableEntity te){ - - } - public TableEntity insertEntity(String key, Object value){ - - } - public void deleteEntity(TableEntity te){ - - } - public void deleteEntity(String key){ - - } - public List query(String select, String filter){ - return null; - } -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java deleted file mode 100644 index 4e2c556cadcb..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import com.azure.cosmos.table.implementation.models.TableEntityQueryResponse; - -import javax.swing.*; -import java.util.Observable; - -public class CodeSnippets { - //add a table - - //sync - TableClient tableClientBuilder = new TableClientBuilder(); - .endpoint(foo) - .credential(new DefaultAzureCredential() - .build(); - - .connectionString - - AzureTable azureTable = tableClientBuilder.createTableIfNotExists("tableName"); - - //aysnc - TableAysncClientBuilder tableAysncClient = new TableAsyncClientBuilder(); - .pipeline("pipline") - .build(); - AzureTable azureTable2; - Mono createTableMono = tableAysncClient.createTable("tableName"); - createTableMono - .subscribe( - response -> { - azureTable2 = - }, - error -> { - - } - ) - - - //delete a table - //sync - azureTable.delete(); - - //async - - - - //query a table - - //sync - TableEntityQueryResponse tableEntityQueryResponse = azureTable.query(Filter); - - - //aysnc -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc deleted file mode 100644 index d5b52e41b1df..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc +++ /dev/null @@ -1,46 +0,0 @@ -//create a table - -TableAyncClient tableAyncClient = new TableAyncClientBuilder(); - .connectionString("connectionString") - .build(); - -Mono createTableMono = tableAsyncClient.createTable("tableName"); -createTableMono.subscribe((AzureTable azureTable) -> { - System.out.println("Table creation successful, table name: " + azureTable.getName()); - }, error -> { - System.out.println("There was an error creating the table. Error: " + error); -}); - - - -//deleteTable -Mono deleteTableMono = tableAsyncClient.deleteTable("tableName"); -deleteTableMono.subscribe( void -> { - System.out.println("Table Successfully deleted.") - }, error -> { - System.out.println("Table deletion unsuccessful. Error: " + ERROR); -}); - - -//query a table -//queryEntities(string tableName, string filter, string select ...) -String query = "filter: $"PartitionKey eq '{PartitionKeyValue}' and RowKey eq '{x}'" -Flux queryEntities = tableAsyncClient.queryEntities("tableName", query); -queryEntities.flatMap( (Map resultEntity) -> { - return new tableEntity(resultEntity.get(), -} - -//add an entity - -Mono getTableMono = tableAsyncClient.getTable("TableName"); -getTableMono.flatMap( azureTable -> { - Mono azureTableEntity = azureTable.createEntity("value","rowKey","partitionKey"); - return azureTableEntity; - }.map(azureTableEntity -> { - System.out.println("Successfully added" + azureTableEntity.getValue() + "to table."); - }, error -> { - System.out.println("Unsuccessful"); - }); - - - diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java deleted file mode 100644 index d72dde11f61a..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.azure.cosmos.table.implementation; - -public class CodeSnippetsAysnc { - -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync deleted file mode 100644 index 9f6e6722a016..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync +++ /dev/null @@ -1,48 +0,0 @@ - - -//create table - -TableClient tableClient = new TableClientBuilder(); - .connectionString("connectionString") - .build(); - -//two options to create a table -tableClient.createTableIfNotExists("tableName"); -tableClient.createTable("tableName"); - - - -//delete table -azureTable.delete(); - - -//query tables -List responseTables = tableClient.query(); - - -// -class TableEntity { -String rowKey -String partitionKey -Map value - -} - -//insert entity -TableEntity tableEntity = new TableEntity(String key, Object value); -azureTable.insert(tableEntity); - -//delete entity -azureTable.delete(tableEntity); - -//update entity -//key to object containing properties (which consumer handles) -azureTable.update(oldEntity.getRowKey(), newEntity); -azureTable.update(newEntity); //new entity has existing row key that is unique - - -//creating odata query and listing entities -some sort of odata builder - -List = azureTable.query(odataQuery); - diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java deleted file mode 100644 index 6877e299e36d..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import com.azure.core.exception.HttpResponseException; -import com.azure.cosmos.table.implementation.models.TableServiceErrorException; -import com.azure.cosmos.table.implementation.models.TablesQueryEntitiesResponse; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class CodeSnippetsSync { - - public static void methods(){ - - //client-builder pattern - TableClientBuilder tableClientBuilder = new TableClientBuilder(); - TableClient tableClient = new TableClientBuilder() - .connectionString("connectionString") - .build(); - - - //create a table - try { - tableClient.createTable("Office Supplies;"); - } catch (TableServiceErrorException e) { - System.out.println("Create Table Unsuccessful. Error: " + e); - } - - //delete table - try { - tableClient.deleteTable("Office Supplies"); - } catch (TableServiceErrorException e) { - System.out.println("Delete Table Unsuccessful. Error: " + e); - } - - //query tables - String filterString = "$filter= name eq 'Office Supplies'"; - String selectString = "$select= Product, Price"; - try { - List responseTables = tableClient.queryTables(selectString, filterString); - } catch (HttpResponseException e){ - System.out.println("Table Query Unsuccessful. Error: " + e); - } - - - //insert entity - String tableName = "Office Supplies"; - String row = "crayola markers"; - String partitionKey = "markers"; - HashMap tableEntityProperties = new HashMap<>(); - TableEntity tableEntity = new TableEntity(tableName, row, partitionKey, tableEntityProperties); - try { - tableEntity = tableClient.insertEntity(tableEntity); - } catch (HttpResponseException e){ - System.out.println("Insert Entity Unsuccessful. Error: " + e); - } - - - //update entity - tableEntity.addProperty("Seller","Crayola"); - try { - tableClient.updateEntity(tableEntity); - } catch (HttpResponseException e){ - System.out.println("Update Entity Unsuccessful. Error: " + e); - } - - - //upsert entity - tableEntity.addProperty("Price","$5"); - try { - tableEntity = tableClient.upsertEntity(tableEntity); - } catch (HttpResponseException e){ - System.out.println("Upsert Entity Unsuccessful. Error: " + e); - } - - - //delete entity - try { - tableClient.deleteEntity(tableName, tableEntity); - } catch (HttpResponseException e){ - System.out.println("Delete Entity Unsuccessful. Error: " + e); - } - - - //query a table - String filterString2 = "$filter = Product eq 'markers'"; - String selectString2 = "$select = Seller eq 'crayola'"; - try { - List list= tableClient.queryEntity(tableName, filterString2, selectString2); - } catch (HttpResponseException e){ - System.out.println("Query Table Entities Unsuccessful. Error: " + e); - } - } - -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java deleted file mode 100644 index 9444ac60e39e..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class TableClient { - String name; - - - public AzureTable createTable(String name){ - return new AzureTable(name); - } - - - public TableClient(){ - name = "Hi"; - } - - public String getName() { - return name; - } - - public AzureTable createTableIfNotExist(String name) { - return new AzureTable(name); - } - public void deleteTable(AzureTable az) { - - } - public void deleteTable(String name) { - - } - public List queryTables(String selectString, String filterString){ - return null; - } - public List queryEntity(String az, String selectString, String filterString){ - return null; - } - - public TableEntity insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ - return new TableEntity(); - } - public TableEntity insertEntity(TableEntity te){ - return te; - } - public void deleteEntity(String tableName, TableEntity tableEntity){ - - } - public void updateEntity(TableEntity te){ - - } - public TableEntity upsertEntity(TableEntity te){ - return new TableEntity(); - } -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java deleted file mode 100644 index 8bbe8b0898fb..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.azure.cosmos.table.implementation; - -public class TableClientBuilder { - String connectionString; - - - public TableClientBuilder connectionString(String connectionString){ - connectionString = connectionString; - return this; - } - public TableClient build(){ - return new TableClient(); - } - - public TableClientBuilder(){ - - } - -} diff --git a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java b/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java deleted file mode 100644 index 7eec0b807ec5..000000000000 --- a/sdk/cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import java.util.Map; - -public class TableEntity { - Map properties; - public TableEntity(){ - - } - public TableEntity(String table, String row, String partition, Map properties){ - this.properties = properties; - } - - public Map getProperties(){ - return properties; - } - public void addProperty(String key, Object value){ - - } -} diff --git a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java deleted file mode 100644 index e74efb0d81b1..000000000000 --- a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/AzureTable.java +++ /dev/null @@ -1,25 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import java.util.List; - -public class AzureTable { - - public AzureTable(String name) { - - } - public void insertEntity(TableEntity te){ - - } - public TableEntity insertEntity(String key, Object value){ - - } - public void deleteEntity(TableEntity te){ - - } - public void deleteEntity(String key){ - - } - public List query(String select, String filter){ - return null; - } -} diff --git a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java deleted file mode 100644 index 4e2c556cadcb..000000000000 --- a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippets.java +++ /dev/null @@ -1,53 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import com.azure.cosmos.table.implementation.models.TableEntityQueryResponse; - -import javax.swing.*; -import java.util.Observable; - -public class CodeSnippets { - //add a table - - //sync - TableClient tableClientBuilder = new TableClientBuilder(); - .endpoint(foo) - .credential(new DefaultAzureCredential() - .build(); - - .connectionString - - AzureTable azureTable = tableClientBuilder.createTableIfNotExists("tableName"); - - //aysnc - TableAysncClientBuilder tableAysncClient = new TableAsyncClientBuilder(); - .pipeline("pipline") - .build(); - AzureTable azureTable2; - Mono createTableMono = tableAysncClient.createTable("tableName"); - createTableMono - .subscribe( - response -> { - azureTable2 = - }, - error -> { - - } - ) - - - //delete a table - //sync - azureTable.delete(); - - //async - - - - //query a table - - //sync - TableEntityQueryResponse tableEntityQueryResponse = azureTable.query(Filter); - - - //aysnc -} diff --git a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc deleted file mode 100644 index d5b52e41b1df..000000000000 --- a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc +++ /dev/null @@ -1,46 +0,0 @@ -//create a table - -TableAyncClient tableAyncClient = new TableAyncClientBuilder(); - .connectionString("connectionString") - .build(); - -Mono createTableMono = tableAsyncClient.createTable("tableName"); -createTableMono.subscribe((AzureTable azureTable) -> { - System.out.println("Table creation successful, table name: " + azureTable.getName()); - }, error -> { - System.out.println("There was an error creating the table. Error: " + error); -}); - - - -//deleteTable -Mono deleteTableMono = tableAsyncClient.deleteTable("tableName"); -deleteTableMono.subscribe( void -> { - System.out.println("Table Successfully deleted.") - }, error -> { - System.out.println("Table deletion unsuccessful. Error: " + ERROR); -}); - - -//query a table -//queryEntities(string tableName, string filter, string select ...) -String query = "filter: $"PartitionKey eq '{PartitionKeyValue}' and RowKey eq '{x}'" -Flux queryEntities = tableAsyncClient.queryEntities("tableName", query); -queryEntities.flatMap( (Map resultEntity) -> { - return new tableEntity(resultEntity.get(), -} - -//add an entity - -Mono getTableMono = tableAsyncClient.getTable("TableName"); -getTableMono.flatMap( azureTable -> { - Mono azureTableEntity = azureTable.createEntity("value","rowKey","partitionKey"); - return azureTableEntity; - }.map(azureTableEntity -> { - System.out.println("Successfully added" + azureTableEntity.getValue() + "to table."); - }, error -> { - System.out.println("Unsuccessful"); - }); - - - diff --git a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java deleted file mode 100644 index d72dde11f61a..000000000000 --- a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsAysnc.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.azure.cosmos.table.implementation; - -public class CodeSnippetsAysnc { - -} diff --git a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync deleted file mode 100644 index 9f6e6722a016..000000000000 --- a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync +++ /dev/null @@ -1,48 +0,0 @@ - - -//create table - -TableClient tableClient = new TableClientBuilder(); - .connectionString("connectionString") - .build(); - -//two options to create a table -tableClient.createTableIfNotExists("tableName"); -tableClient.createTable("tableName"); - - - -//delete table -azureTable.delete(); - - -//query tables -List responseTables = tableClient.query(); - - -// -class TableEntity { -String rowKey -String partitionKey -Map value - -} - -//insert entity -TableEntity tableEntity = new TableEntity(String key, Object value); -azureTable.insert(tableEntity); - -//delete entity -azureTable.delete(tableEntity); - -//update entity -//key to object containing properties (which consumer handles) -azureTable.update(oldEntity.getRowKey(), newEntity); -azureTable.update(newEntity); //new entity has existing row key that is unique - - -//creating odata query and listing entities -some sort of odata builder - -List = azureTable.query(odataQuery); - diff --git a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java deleted file mode 100644 index 6877e299e36d..000000000000 --- a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/CodeSnippetsSync.java +++ /dev/null @@ -1,95 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import com.azure.core.exception.HttpResponseException; -import com.azure.cosmos.table.implementation.models.TableServiceErrorException; -import com.azure.cosmos.table.implementation.models.TablesQueryEntitiesResponse; - -import java.util.HashMap; -import java.util.List; -import java.util.Map; - -public class CodeSnippetsSync { - - public static void methods(){ - - //client-builder pattern - TableClientBuilder tableClientBuilder = new TableClientBuilder(); - TableClient tableClient = new TableClientBuilder() - .connectionString("connectionString") - .build(); - - - //create a table - try { - tableClient.createTable("Office Supplies;"); - } catch (TableServiceErrorException e) { - System.out.println("Create Table Unsuccessful. Error: " + e); - } - - //delete table - try { - tableClient.deleteTable("Office Supplies"); - } catch (TableServiceErrorException e) { - System.out.println("Delete Table Unsuccessful. Error: " + e); - } - - //query tables - String filterString = "$filter= name eq 'Office Supplies'"; - String selectString = "$select= Product, Price"; - try { - List responseTables = tableClient.queryTables(selectString, filterString); - } catch (HttpResponseException e){ - System.out.println("Table Query Unsuccessful. Error: " + e); - } - - - //insert entity - String tableName = "Office Supplies"; - String row = "crayola markers"; - String partitionKey = "markers"; - HashMap tableEntityProperties = new HashMap<>(); - TableEntity tableEntity = new TableEntity(tableName, row, partitionKey, tableEntityProperties); - try { - tableEntity = tableClient.insertEntity(tableEntity); - } catch (HttpResponseException e){ - System.out.println("Insert Entity Unsuccessful. Error: " + e); - } - - - //update entity - tableEntity.addProperty("Seller","Crayola"); - try { - tableClient.updateEntity(tableEntity); - } catch (HttpResponseException e){ - System.out.println("Update Entity Unsuccessful. Error: " + e); - } - - - //upsert entity - tableEntity.addProperty("Price","$5"); - try { - tableEntity = tableClient.upsertEntity(tableEntity); - } catch (HttpResponseException e){ - System.out.println("Upsert Entity Unsuccessful. Error: " + e); - } - - - //delete entity - try { - tableClient.deleteEntity(tableName, tableEntity); - } catch (HttpResponseException e){ - System.out.println("Delete Entity Unsuccessful. Error: " + e); - } - - - //query a table - String filterString2 = "$filter = Product eq 'markers'"; - String selectString2 = "$select = Seller eq 'crayola'"; - try { - List list= tableClient.queryEntity(tableName, filterString2, selectString2); - } catch (HttpResponseException e){ - System.out.println("Query Table Entities Unsuccessful. Error: " + e); - } - } - -} diff --git a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java deleted file mode 100644 index 9444ac60e39e..000000000000 --- a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClient.java +++ /dev/null @@ -1,55 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import java.util.ArrayList; -import java.util.List; -import java.util.Map; - -public class TableClient { - String name; - - - public AzureTable createTable(String name){ - return new AzureTable(name); - } - - - public TableClient(){ - name = "Hi"; - } - - public String getName() { - return name; - } - - public AzureTable createTableIfNotExist(String name) { - return new AzureTable(name); - } - public void deleteTable(AzureTable az) { - - } - public void deleteTable(String name) { - - } - public List queryTables(String selectString, String filterString){ - return null; - } - public List queryEntity(String az, String selectString, String filterString){ - return null; - } - - public TableEntity insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ - return new TableEntity(); - } - public TableEntity insertEntity(TableEntity te){ - return te; - } - public void deleteEntity(String tableName, TableEntity tableEntity){ - - } - public void updateEntity(TableEntity te){ - - } - public TableEntity upsertEntity(TableEntity te){ - return new TableEntity(); - } -} diff --git a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java deleted file mode 100644 index 8bbe8b0898fb..000000000000 --- a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableClientBuilder.java +++ /dev/null @@ -1,19 +0,0 @@ -package com.azure.cosmos.table.implementation; - -public class TableClientBuilder { - String connectionString; - - - public TableClientBuilder connectionString(String connectionString){ - connectionString = connectionString; - return this; - } - public TableClient build(){ - return new TableClient(); - } - - public TableClientBuilder(){ - - } - -} diff --git a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java b/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java deleted file mode 100644 index 7eec0b807ec5..000000000000 --- a/sdk/cosmos/azure-cosmos/azure-cosmos-table/src/main/java/com/azure/cosmos/table/implementation/TableEntity.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.azure.cosmos.table.implementation; - -import java.util.Map; - -public class TableEntity { - Map properties; - public TableEntity(){ - - } - public TableEntity(String table, String row, String partition, Map properties){ - this.properties = properties; - } - - public Map getProperties(){ - return properties; - } - public void addProperty(String key, Object value){ - - } -} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java index 838a31c328d5..04d01c7b30b8 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsAysnc.java @@ -1,7 +1,5 @@ package com.azure.data.tables; -import com.azure.core.exception.HttpResponseException; -import reactor.core.Disposable; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @@ -14,27 +12,20 @@ public class CodeSnippetsAysnc { public void AsyncSnippets() { //build service client - TableAsyncServiceClient tableAsyncServiceClient = new TableAsyncServiceClientBuilder() + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceAsyncClientBuilder() .connectionString("connectionString") .build(); - //build table client - TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() - .connectionString("connectionString") - .tableName("OfficeSupplies") - .build(); - //add table - Mono createTableMono = tableAsyncServiceClient.createTable("OfficeSupplies"); - - createTableMono.subscribe(Void -> { + tableServiceAsyncClient.createTable("OfficeSupplies").subscribe(Void -> { System.out.println("Table creation successful."); }, error -> { System.out.println("There was an error creating the table. Error: " + error); }); + //delete a table - Mono deleteTableMono = tableAsyncServiceClient.deleteTable("OfficeSupplies"); + Mono deleteTableMono = tableServiceAsyncClient.deleteTable("OfficeSupplies"); deleteTableMono.subscribe(Void -> { System.out.println("Table deletion successful"); @@ -44,38 +35,33 @@ public void AsyncSnippets() { //query tables - String filterString = "$filter= name eq 'OfficeSupplies'"; - String selectString = "$select= Product, Price"; - Flux queryTableFlux = tableAsyncServiceClient.queryTables(filterString); - Disposable subscription = queryTableFlux.subscribe(s -> { - System.out.println(s); + String selectString = "$select= TableName eq 'OfficeSupplies'"; + Flux queryTableFlux = tableServiceAsyncClient.queryTables(selectString); + queryTableFlux.subscribe(azureTable -> { + System.out.println(azureTable.getName()); }, error -> { - System.out.println("There was an error querying the table. Error: " + error); + System.out.println("There was an error querying the service. Error: " + error); }); } - public void InsertEntity(){ + public void InsertEntity() { //build service client - TableAsyncServiceClient tableAsyncServiceClient = new TableAsyncServiceClientBuilder() + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceAsyncClientBuilder() .connectionString("connectionString") .build(); + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - Mono createTableMono = tableAsyncServiceClient.createTable("OfficeSupplies"); - - createTableMono.flatMap(tableAsyncClient -> { - System.out.println("Table creation successful."); - - String tableName = "Office Supplies"; - String row = "crayola markers"; - String partitionKey = "markers"; - HashMap tableEntityProperties = new HashMap<>(); - Mono insertEntityMono = tableAsyncClient.insertEntity(tableName, row, partitionKey, tableEntityProperties); - return insertEntityMono; - }).subscribe(tableEntity1 -> { - System.out.println("Insert Entity Successful. Entity: " + tableEntity1); + String tableName = "OfficeSupplies"; + String row = "crayolaMarkers"; + String partitionKey = "markers"; + HashMap tableEntityProperties = new HashMap<>(); + Mono insertEntityMono = tableAsyncClient.insertEntity(tableName, row, partitionKey, + tableEntityProperties); + insertEntityMono.subscribe(tableEntity -> { + System.out.println("Insert Entity Successful. Entity: " + tableEntity); }, error -> { System.out.println("There was an error inserting the Entity. Error: " + error); }); @@ -83,61 +69,45 @@ public void InsertEntity(){ } - public void DeleteEntity(){ + public void DeleteEntity() { //build service client - TableAsyncServiceClient tableAsyncServiceClient = new TableAsyncServiceClientBuilder() + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceAsyncClientBuilder() .connectionString("connectionString") .build(); + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); + String selectString = "$select = RowKey eq 'crayolaMarkers'"; + Flux queryTableEntity = tableAsyncClient.queryEntity("OfficeSupplies", selectString); - Mono createTableMono = tableAsyncServiceClient.createTable("OfficeSupplies"); - - createTableMono.flatMap(tableAsyncClient -> { - System.out.println("Table creation successful."); - - String tableName = "Office Supplies"; - String row = "crayola markers"; - String partitionKey = "markers"; - HashMap tableEntityProperties = new HashMap<>(); - Mono insertEntityMono = tableAsyncClient.insertEntity(tableName, row, partitionKey, tableEntityProperties); - return insertEntityMono; - }).flatMap(tableEntity1 -> { - System.out.println("Insert Entity Successful. Table Entity: " + tableEntity1); - Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity1); + queryTableEntity.flatMap(tableEntity -> { + System.out.println("Table Entity: " + tableEntity); + Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity); return deleteEntityMono; - }).subscribe(tableEntity1 -> { - System.out.println("Delete Entity Successful. Entity: " + tableEntity1); + }).subscribe(Void -> { + System.out.println("Delete Entity Successful."); }, error -> { System.out.println("There was an error deleting the Entity. Error: " + error); }); - - } - public void UpdateEntity(){ - //client-builder pattern - TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); - TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + public void UpdateEntity() { + + //build service client + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceAsyncClientBuilder() .connectionString("connectionString") .build(); - Mono createTableMono = tableAsyncClient.createTable("tableName"); - createTableMono.flatMap(Void -> { - System.out.println("Table creation successful."); + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String tableName = "Office Supplies"; - String row = "crayola markers"; - String partitionKey = "markers"; - HashMap tableEntityProperties = new HashMap<>(); - Mono insertEntityMono = tableAsyncClient.insertEntity(tableName, row, partitionKey, tableEntityProperties); - return insertEntityMono; - }).flatMap(tableEntity1 -> { - System.out.println("Insert Entity Successful. Table Entity: " + tableEntity1); - - tableEntity1.addProperty("Seller","Crayola"); - Mono updateEntityMono = tableAsyncClient.updateEntity(tableEntity1); + String selectString2 = "$select = RowKey eq 'crayolaMarkers'"; + Flux queryTableEntity = tableAsyncClient.queryEntity("OfficeSupplies", selectString2); + + queryTableEntity.flatMap(tableEntity -> { + System.out.println("Table Entity: " + tableEntity); + tableEntity.addProperty("Price", "5"); + Mono updateEntityMono = tableAsyncClient.updateEntity(tableEntity); return updateEntityMono; }).subscribe(Void -> { System.out.println("Update Entity Successful."); @@ -148,62 +118,25 @@ public void UpdateEntity(){ } - public void UpsertEntity(){ + public void QueryEntities() { - //client-builder pattern - TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); - TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() + //build service client + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceAsyncClientBuilder() .connectionString("connectionString") .build(); + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - Mono createTableMono = tableAsyncClient.createTable("tableName"); - createTableMono.flatMap(Void -> { - System.out.println("Table creation successful."); + String filterString2 = "$filter = price eq '5'"; + String selectString2 = "$select = PartitionKey eq 'markers'"; + Flux queryTableEntity = tableAsyncClient.queryEntity("OfficeSupplies", filterString2, selectString2); - String tableName = "Office Supplies"; - String row = "crayola markers"; - String partitionKey = "markers"; - HashMap tableEntityProperties = new HashMap<>(); - Mono insertEntityMono = tableAsyncClient.insertEntity(tableName, row, partitionKey, tableEntityProperties); - return insertEntityMono; - }).flatMap(tableEntity1 -> { - System.out.println("Insert Entity Successful. Table Entity: " + tableEntity1); - - tableEntity1.addProperty("Price","$5"); - Mono upsertEntityMono = tableAsyncClient.upsertEntity(tableEntity1); - return upsertEntityMono; - }).subscribe(tableEntity1 -> { - System.out.println("Upsert Entity Successful. Entity: " + tableEntity1); + queryTableEntity.subscribe(tableEntity -> { + System.out.println("Table Entity: " + tableEntity); }, error -> { - System.out.println("There was an error upserting the Entity. Error: " + error); + System.out.println("There was an error querying the table. Error: " + error); }); - } - public void QueryEntities(){ - - //client-builder pattern - TableAsyncClientBuilder tableAsyncClientBuilder = new TableAsyncClientBuilder(); - TableAsyncClient tableAsyncClient = new TableAsyncClientBuilder() - .connectionString("connectionString") - .build(); - - - Mono createTableMono = tableAsyncClient.createTable("tableName"); - createTableMono.then(Mono.fromCallable(()-> { - System.out.println("Table creation successful."); - - String filterString2 = "$filter = Product eq 'markers'"; - String selectString2 = "$select = Seller eq 'crayola'"; - Flux queryTableEntity = tableAsyncClient.queryEntity("tableName", filterString2, selectString2); - return queryTableEntity; - })).subscribe(tableEntity1 -> { - System.out.println("Table Entity: " + tableEntity1); - }, error -> { - System.out.println("There was an error querying the table. Error: " + error); - }); - } - - } +} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java index 9dba26788ce5..993ce66f2b1f 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java @@ -38,11 +38,11 @@ public static void methods(){ } //query tables - String filterString = "$filter= name eq 'OfficeSupplies'"; + String selectString = "$selectString= TableName eq 'OfficeSupplies'"; try { //TODO: create Table class TableName is the odata feild - List responseTables = tableServiceClient.queryTables(filterString); + List responseTables = tableServiceClient.queryTables(selectString); } catch (HttpResponseException e){ System.out.println("Table Query Unsuccessful. Error: " + e); } @@ -62,7 +62,6 @@ public static void methods(){ //update entity - //TODO: let the customer specify if it is a replacement or a merge tableEntity.addProperty("Seller","Crayola"); try { tableClient.updateEntity(tableEntity); @@ -71,10 +70,18 @@ public static void methods(){ } - //upsert entity - tableEntity.addProperty("Price","$5"); + //upsert entity (where it is an update and replace) + tableEntity.addProperty("Price","5"); try { - tableEntity = tableClient.upsertEntity(tableEntity); + tableClient.updateAndReplaceEntity(tableEntity); + } catch (HttpResponseException e){ + System.out.println("Upsert Entity Unsuccessful. Error: " + e); + } + + //upsert entity (where it is an update and replace) + tableEntity.addProperty("Price","5"); + try { + tableClient.updateAndMergeEntity(tableEntity); } catch (HttpResponseException e){ System.out.println("Upsert Entity Unsuccessful. Error: " + e); } 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 944f65da995f..9cfed9c927b4 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 @@ -13,6 +13,10 @@ public Flux queryEntity(String az, String selectString, String filt return null; } + public Flux queryEntity(String az, String filterString){ + return null; + } + public Mono insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ return null; } 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 69b3f3444e90..573150e14858 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 @@ -21,5 +21,6 @@ public TableEntity insertEntity(TableEntity tableEntity){ public void deleteEntity(TableEntity tableEntity){ } public void updateEntity(TableEntity te){ } - public TableEntity upsertEntity(TableEntity tableEntity){ return new TableEntity(); } + public void updateAndReplaceEntity(TableEntity tableEntity){ } + public void updateAndMergeEntity(TableEntity tableEntity){ } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java similarity index 50% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java index 4a32c03d3fd8..1d8633ef9d20 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClient.java @@ -5,19 +5,24 @@ import java.util.Map; -public class TableAsyncServiceClient{ +public class TableServiceAsyncClient{ - public TableAsyncServiceClient(){ } + public TableServiceAsyncClient(){ } //public Mono createTable(String name){return Mono.empty(); } - public Mono createTable(String name){return null; } + public Mono createTable(String name){ + return null; } public Mono createTableIfNotExist(String name) {return Mono.empty(); } public Mono deleteTable(String name) {return Mono.empty(); } - public Flux queryTables(String filterString){ + public Flux queryTables(String filterString){ return null; } + public Mono getTable(String tableName) { return null;} + + public TableAsyncClient getClient(String tableName) { return null;} + } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java similarity index 51% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClientBuilder.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java index df9e0a40a368..a02f409d4f74 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncServiceClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java @@ -1,16 +1,16 @@ package com.azure.data.tables; -public class TableAsyncServiceClientBuilder { +public class TableServiceAsyncClientBuilder { String connectionString; - public TableAsyncServiceClientBuilder connectionString(String connectionString){ + public TableServiceAsyncClientBuilder connectionString(String connectionString){ connectionString = connectionString; return this; } - public TableAsyncServiceClient build(){ - return new TableAsyncServiceClient(); + public TableServiceAsyncClient build(){ + return new TableServiceAsyncClient(); } public void TableAysncClientBuilder(){ From 7245126b7aaee9b8bb14807af024093fafa4351e Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 17 Jun 2020 15:26:08 -0400 Subject: [PATCH 16/42] reformatting --- .../data/tables/AzureTableAsyncClient.java | 1 - .../azure/data/tables/CodeSnippetsSync.java | 26 ++++++++-------- .../azure/data/tables/TableAsyncClient.java | 26 +++++++++++----- .../data/tables/TableAsyncClientBuilder.java | 7 +++-- .../com/azure/data/tables/TableClient.java | 26 +++++++++++----- .../azure/data/tables/TableClientBuilder.java | 7 +++-- .../com/azure/data/tables/TableEntity.java | 13 ++++---- .../data/tables/TableServiceAsyncClient.java | 30 ++++++++++++------- .../TableServiceAsyncClientBuilder.java | 7 +++-- .../azure/data/tables/TableServiceClient.java | 15 ++++++---- .../tables/TableServiceClientBuilder.java | 7 +++-- 11 files changed, 101 insertions(+), 64 deletions(-) diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java index 435b0e9c0c19..11d910cc8999 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java @@ -13,7 +13,6 @@ public class AzureTableAsyncClient { * Creates a table. This artificially takes 3 seconds. * * @param name The name of the table. - * * @return A Mono that completes when the table is created. */ public Mono createTable(String name) { diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java index 993ce66f2b1f..5ca550991fa8 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java @@ -8,7 +8,7 @@ public class CodeSnippetsSync { - public static void methods(){ + public static void methods() { //create a tableServiceClient TableServiceClient tableServiceClient = new TableServiceClientBuilder() @@ -43,7 +43,7 @@ public static void methods(){ try { //TODO: create Table class TableName is the odata feild List responseTables = tableServiceClient.queryTables(selectString); - } catch (HttpResponseException e){ + } catch (HttpResponseException e) { System.out.println("Table Query Unsuccessful. Error: " + e); } @@ -55,34 +55,34 @@ public static void methods(){ HashMap tableEntityProperties = new HashMap<>(); TableEntity tableEntity = new TableEntity(tableName, row, partitionKey, tableEntityProperties); try { - tableEntity = tableClient.insertEntity(tableEntity); - } catch (HttpResponseException e){ + tableEntity = tableClient.insertEntity(tableEntity); + } catch (HttpResponseException e) { System.out.println("Insert Entity Unsuccessful. Error: " + e); } //update entity - tableEntity.addProperty("Seller","Crayola"); + tableEntity.addProperty("Seller", "Crayola"); try { tableClient.updateEntity(tableEntity); - } catch (HttpResponseException e){ + } catch (HttpResponseException e) { System.out.println("Update Entity Unsuccessful. Error: " + e); } //upsert entity (where it is an update and replace) - tableEntity.addProperty("Price","5"); + tableEntity.addProperty("Price", "5"); try { tableClient.updateAndReplaceEntity(tableEntity); - } catch (HttpResponseException e){ + } catch (HttpResponseException e) { System.out.println("Upsert Entity Unsuccessful. Error: " + e); } //upsert entity (where it is an update and replace) - tableEntity.addProperty("Price","5"); + tableEntity.addProperty("Price", "5"); try { tableClient.updateAndMergeEntity(tableEntity); - } catch (HttpResponseException e){ + } catch (HttpResponseException e) { System.out.println("Upsert Entity Unsuccessful. Error: " + e); } @@ -90,7 +90,7 @@ public static void methods(){ //delete entity try { tableClient.deleteEntity(tableEntity); - } catch (HttpResponseException e){ + } catch (HttpResponseException e) { System.out.println("Delete Entity Unsuccessful. Error: " + e); } @@ -99,8 +99,8 @@ public static void methods(){ String filterString2 = "$filter = Product eq 'markers'"; String selectString2 = "$select = Seller eq 'crayola'"; try { - List list= tableClient.queryEntity(tableName, filterString2, selectString2); - } catch (HttpResponseException e){ + List list = tableClient.queryEntity(tableName, filterString2, selectString2); + } catch (HttpResponseException e) { System.out.println("Query Table Entities Unsuccessful. Error: " + e); } } 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 9cfed9c927b4..69b335ce41d1 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 @@ -7,25 +7,35 @@ public class TableAsyncClient { - public TableAsyncClient(String tableName){ } + public TableAsyncClient(String tableName) { + } - public Flux queryEntity(String az, String selectString, String filterString){ + public Flux queryEntity(String az, String selectString, String filterString) { return null; } - public Flux queryEntity(String az, String filterString){ + public Flux queryEntity(String az, String filterString) { return null; } - public Mono insertEntity(String tableName, String row, String partition, Map tableEntityProperties){ + public Mono insertEntity(String tableName, String row, String partition, Map tableEntityProperties) { return null; } - public Mono insertEntity(TableEntity te){ + + public Mono insertEntity(TableEntity te) { return null; } - public Mono deleteEntity(TableEntity tableEntity){return Mono.empty(); } - public Mono updateEntity(TableEntity te){ return Mono.empty(); } - public Mono upsertEntity(TableEntity te){ return null; } + public Mono deleteEntity(TableEntity tableEntity) { + return Mono.empty(); + } + + public Mono updateEntity(TableEntity te) { + return Mono.empty(); + } + + public Mono upsertEntity(TableEntity te) { + return null; + } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java index 6dc78dbd6556..de0c8dba676c 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java @@ -6,7 +6,7 @@ public class TableAsyncClientBuilder { String tableName; - public TableAsyncClientBuilder connectionString(String connectionString){ + public TableAsyncClientBuilder connectionString(String connectionString) { connectionString = connectionString; return this; } @@ -15,11 +15,12 @@ public TableAsyncClientBuilder tableName(String tableName) { this.tableName = tableName; return this; } - public TableAsyncClient build(){ + + public TableAsyncClient build() { return new TableAsyncClient(tableName); } - public void TableAysncClientBuilder(){ + public void TableAysncClientBuilder() { } } 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 573150e14858..dcf89c5b5598 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 @@ -6,21 +6,31 @@ public class TableClient { String tableName; - public TableClient(String tableName){ this.tableName = tableName; } + public TableClient(String tableName) { + this.tableName = tableName; + } - public List queryEntity(String az, String selectString, String filterString){ + public List queryEntity(String az, String selectString, String filterString) { return null; } - public TableEntity insertEntity(String row, String partition, Map tableEntityProperties){ + public TableEntity insertEntity(String row, String partition, Map tableEntityProperties) { return new TableEntity(); } - public TableEntity insertEntity(TableEntity tableEntity){ + + public TableEntity insertEntity(TableEntity tableEntity) { return tableEntity; } - public void deleteEntity(TableEntity tableEntity){ } - public void updateEntity(TableEntity te){ } - public void updateAndReplaceEntity(TableEntity tableEntity){ } - public void updateAndMergeEntity(TableEntity tableEntity){ } + public void deleteEntity(TableEntity tableEntity) { + } + + public void updateEntity(TableEntity te) { + } + + public void updateAndReplaceEntity(TableEntity tableEntity) { + } + + public void updateAndMergeEntity(TableEntity tableEntity) { + } } 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 24777e6d23d2..7e864b3497cd 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 @@ -5,20 +5,21 @@ public class TableClientBuilder { String tableName; - public TableClientBuilder connectionString(String connectionString){ + public TableClientBuilder connectionString(String connectionString) { this.connectionString = connectionString; return this; } + public TableClientBuilder tableName(String tableName) { this.tableName = tableName; return this; } - public TableClient build(){ + public TableClient build() { return new TableClient(tableName); } - public TableClientBuilder(){ + public TableClientBuilder() { } 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 index 8071c582d1bf..af4673c6c431 100644 --- 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 @@ -3,18 +3,21 @@ import java.util.Map; public class TableEntity { - Map properties; - public TableEntity(){ + Map properties; + + public TableEntity() { } - public TableEntity(String table, String row, String partition, Map properties){ + + public TableEntity(String table, String row, String partition, Map properties) { this.properties = properties; } - public Map getProperties(){ + public Map getProperties() { return properties; } - public void addProperty(String key, Object value){ + + public void addProperty(String key, Object value) { } } 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 1d8633ef9d20..c53ade489eda 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 @@ -3,26 +3,34 @@ import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; -import java.util.Map; +public class TableServiceAsyncClient { -public class TableServiceAsyncClient{ - - public TableServiceAsyncClient(){ } + public TableServiceAsyncClient() { + } //public Mono createTable(String name){return Mono.empty(); } - public Mono createTable(String name){ - return null; } + public Mono createTable(String name) { + return null; + } - public Mono createTableIfNotExist(String name) {return Mono.empty(); } + public Mono createTableIfNotExist(String name) { + return Mono.empty(); + } - public Mono deleteTable(String name) {return Mono.empty(); } + public Mono deleteTable(String name) { + return Mono.empty(); + } - public Flux queryTables(String filterString){ + public Flux queryTables(String filterString) { return null; } - public Mono getTable(String tableName) { return null;} + public Mono getTable(String tableName) { + return null; + } - public TableAsyncClient getClient(String tableName) { return null;} + public TableAsyncClient getClient(String tableName) { + return null; + } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java index a02f409d4f74..af97960b2e32 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java @@ -5,15 +5,16 @@ public class TableServiceAsyncClientBuilder { String connectionString; - public TableServiceAsyncClientBuilder connectionString(String connectionString){ + public TableServiceAsyncClientBuilder connectionString(String connectionString) { connectionString = connectionString; return this; } - public TableServiceAsyncClient build(){ + + public TableServiceAsyncClient build() { return new TableServiceAsyncClient(); } - public void TableAysncClientBuilder(){ + public void TableAysncClientBuilder() { } } 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 6208e804352c..a9800d52f385 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 @@ -1,19 +1,22 @@ package com.azure.data.tables; import java.util.List; -import java.util.Map; public class TableServiceClient { - public TableServiceClient(){ } + public TableServiceClient() { + } - public void createTable(String name){ } + public void createTable(String name) { + } - public void createTableIfNotExist(String name) { } + public void createTableIfNotExist(String name) { + } - public void deleteTable(String name) { } + public void deleteTable(String name) { + } - public List queryTables(String filterString){ + public List queryTables(String filterString) { return null; } 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 0a703a7897e0..5aa3f5b845dd 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 @@ -5,15 +5,16 @@ public class TableServiceClientBuilder { String connectionString; - public TableServiceClientBuilder connectionString(String connectionString){ + public TableServiceClientBuilder connectionString(String connectionString) { connectionString = connectionString; return this; } - public TableServiceClient build(){ + + public TableServiceClient build() { return new TableServiceClient(); } - public TableServiceClientBuilder(){ + public TableServiceClientBuilder() { } From 044356b812f01cf31c44c82b5f0247d4303469d3 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 18 Jun 2020 15:43:42 -0400 Subject: [PATCH 17/42] fixing conflictfile name changes --- sdk/cosmos/azure-cosmos-table/pom.xml | 4 +- sdk/tables/azure-data-tables/pom.xml | 20 ++---- .../com/azure/data/tables/AzureTable.java | 15 ++--- .../data/tables/AzureTableAsyncClient.java | 31 --------- .../azure/data/tables/AzureTableEntity.java | 22 ------ .../azure/data/tables/TableAsyncClient.java | 10 ++- .../data/tables/TableAsyncClientBuilder.java | 26 ------- .../com/azure/data/tables/TableClient.java | 22 +++++- ...java => TableClientAsyncCodeSnippets.java} | 67 ++++++++----------- .../azure/data/tables/TableClientBuilder.java | 13 +++- ...Sync.java => TableClientCodeSnippets.java} | 9 +-- .../com/azure/data/tables/TableEntity.java | 2 + .../data/tables/TableServiceAsyncClient.java | 9 ++- .../TableServiceAsyncClientBuilder.java | 20 ------ .../azure/data/tables/TableServiceClient.java | 11 +-- .../tables/TableServiceClientBuilder.java | 10 ++- 16 files changed, 111 insertions(+), 180 deletions(-) delete mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java delete mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableEntity.java delete mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{CodeSnippetsAysnc.java => TableClientAsyncCodeSnippets.java} (71%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{CodeSnippetsSync.java => TableClientCodeSnippets.java} (94%) delete mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java diff --git a/sdk/cosmos/azure-cosmos-table/pom.xml b/sdk/cosmos/azure-cosmos-table/pom.xml index 9b0b11444ef6..0399a66c0b67 100644 --- a/sdk/cosmos/azure-cosmos-table/pom.xml +++ b/sdk/cosmos/azure-cosmos-table/pom.xml @@ -40,13 +40,13 @@ Licensed under the MIT License. com.azure azure-core - 1.5.0 + 1.5.1 com.azure azure-core-test - 1.2.1 + 1.3.0 test diff --git a/sdk/tables/azure-data-tables/pom.xml b/sdk/tables/azure-data-tables/pom.xml index a1922861ee6e..94d18ab8659c 100644 --- a/sdk/tables/azure-data-tables/pom.xml +++ b/sdk/tables/azure-data-tables/pom.xml @@ -43,11 +43,15 @@ Licensed under the MIT License. azure-core 1.6.0 - + + com.azure + azure-storage-common + 12.7.0 + com.azure azure-core-test - 1.2.1 + 1.3.0 test @@ -80,18 +84,6 @@ Licensed under the MIT License. 3.0.0 test - - com.azure - azure-storage-common - 12.7.0-beta.1 - test - - - com.azure - azure-storage-common - 12.6.1 - compile - 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 index d36e7c0d0719..d2b0a6195bad 100644 --- 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 @@ -1,9 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; -import reactor.core.publisher.Mono; - -import java.time.Duration; - public class AzureTable { private final String name; @@ -11,13 +9,10 @@ public class AzureTable { this.name = name; } + /** + * Returns the name of this Table + */ public String getName() { return name; } - - public Mono createEntity(String key, Object value) { - AzureTableEntity azureTableEntity = new AzureTableEntity(key, value); - System.out.println("Creating entity with key: " + key + ". Value: " + value); - return Mono.delay(Duration.ofSeconds(3)).thenReturn(azureTableEntity); - } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java deleted file mode 100644 index 11d910cc8999..000000000000 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableAsyncClient.java +++ /dev/null @@ -1,31 +0,0 @@ -package com.azure.data.tables; - -import reactor.core.publisher.Mono; - -import java.time.Duration; -import java.util.HashSet; -import java.util.Set; - -public class AzureTableAsyncClient { - private final Set existingTables = new HashSet<>(); - - /** - * Creates a table. This artificially takes 3 seconds. - * - * @param name The name of the table. - * @return A Mono that completes when the table is created. - */ - public Mono createTable(String name) { - return Mono.delay(Duration.ofSeconds(3)).flatMap(delay -> { - if (existingTables.add(name)) { - System.out.printf("CREATING TABLE '%s'.%n", name); - final AzureTable table = new AzureTable(name); - return Mono.just(table); - } else { - System.err.printf("TABLE '%s' ALREADY EXISTS.%n", name); - return Mono.error(new IllegalArgumentException( - String.format("Table with name '%s' already exists.", name))); - } - }); - } -} diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableEntity.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableEntity.java deleted file mode 100644 index d382f733ff8e..000000000000 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/AzureTableEntity.java +++ /dev/null @@ -1,22 +0,0 @@ -package com.azure.data.tables; - -/** - * Represents an entity in azure table. - */ -public class AzureTableEntity { - private final String key; - private final Object value; - - AzureTableEntity(String key, Object value) { - this.key = key; - this.value = value; - } - - public Object getValue() { - return value; - } - - public String getKey() { - return key; - } -} 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 69b335ce41d1..263f2b7c3fc7 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 @@ -1,13 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; +import com.azure.core.annotation.ServiceClient; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.Map; +@ServiceClient( + builder = TableClientBuilder.class, + isAsync = true) public class TableAsyncClient { + String tableName; - public TableAsyncClient(String tableName) { + TableAsyncClient(String tableName) { + this.tableName = tableName; } public Flux queryEntity(String az, String selectString, String filterString) { diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java deleted file mode 100644 index de0c8dba676c..000000000000 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableAsyncClientBuilder.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.azure.data.tables; - -public class TableAsyncClientBuilder { - - String connectionString; - String tableName; - - - public TableAsyncClientBuilder connectionString(String connectionString) { - connectionString = connectionString; - return this; - } - - public TableAsyncClientBuilder tableName(String tableName) { - this.tableName = tableName; - return this; - } - - public TableAsyncClient build() { - return new TableAsyncClient(tableName); - } - - public void TableAysncClientBuilder() { - - } -} 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 dcf89c5b5598..beb04a191f8a 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 @@ -1,16 +1,29 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; +import com.azure.core.annotation.ServiceClient; + import java.util.List; import java.util.Map; +@ServiceClient( + builder = TableClientBuilder.class) public class TableClient { String tableName; - public TableClient(String tableName) { + TableClient(String tableName) { this.tableName = tableName; } - public List queryEntity(String az, String selectString, String filterString) { + /** + * Queries and returns entities in the given table using the select and filter strings + * @param tableName name of table to query + * @param selectString odata select string + * @param filterString odata filter string + * @return + */ + public List queryEntity(String tableName, String selectString, String filterString) { return null; } @@ -18,6 +31,11 @@ public TableEntity insertEntity(String row, String partition, Map { System.out.println("Table creation successful."); }, error -> { @@ -24,20 +26,17 @@ public void AsyncSnippets() { }); - //delete a table - Mono deleteTableMono = tableServiceAsyncClient.deleteTable("OfficeSupplies"); - - deleteTableMono.subscribe(Void -> { + // Delete a table + tableServiceAsyncClient.deleteTable("OfficeSupplies").subscribe(Void -> { System.out.println("Table deletion successful"); }, error -> { System.out.println("There was an error deleting the table. Error: " + error); }); - //query tables + // Query tables String selectString = "$select= TableName eq 'OfficeSupplies'"; - Flux queryTableFlux = tableServiceAsyncClient.queryTables(selectString); - queryTableFlux.subscribe(azureTable -> { + tableServiceAsyncClient.queryTables(selectString).subscribe(azureTable -> { System.out.println(azureTable.getName()); }, error -> { System.out.println("There was an error querying the service. Error: " + error); @@ -46,21 +45,19 @@ public void AsyncSnippets() { public void InsertEntity() { - //build service client - TableServiceAsyncClient tableServiceAsyncClient = new TableServiceAsyncClientBuilder() + // Build service client + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") - .build(); + .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - - String tableName = "OfficeSupplies"; String row = "crayolaMarkers"; String partitionKey = "markers"; HashMap tableEntityProperties = new HashMap<>(); - Mono insertEntityMono = tableAsyncClient.insertEntity(tableName, row, partitionKey, - tableEntityProperties); - insertEntityMono.subscribe(tableEntity -> { + + tableAsyncClient.insertEntity(tableName, row, partitionKey, + tableEntityProperties).subscribe(tableEntity -> { System.out.println("Insert Entity Successful. Entity: " + tableEntity); }, error -> { System.out.println("There was an error inserting the Entity. Error: " + error); @@ -71,17 +68,15 @@ public void InsertEntity() { public void DeleteEntity() { - //build service client - TableServiceAsyncClient tableServiceAsyncClient = new TableServiceAsyncClientBuilder() + // Build service client + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") - .build(); + .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String selectString = "$select = RowKey eq 'crayolaMarkers'"; - Flux queryTableEntity = tableAsyncClient.queryEntity("OfficeSupplies", selectString); - queryTableEntity.flatMap(tableEntity -> { + tableAsyncClient.queryEntity("OfficeSupplies", selectString).flatMap(tableEntity -> { System.out.println("Table Entity: " + tableEntity); Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity); return deleteEntityMono; @@ -94,17 +89,15 @@ public void DeleteEntity() { public void UpdateEntity() { - //build service client - TableServiceAsyncClient tableServiceAsyncClient = new TableServiceAsyncClientBuilder() + // Build service client + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") - .build(); + .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String selectString2 = "$select = RowKey eq 'crayolaMarkers'"; - Flux queryTableEntity = tableAsyncClient.queryEntity("OfficeSupplies", selectString2); - queryTableEntity.flatMap(tableEntity -> { + tableAsyncClient.queryEntity("OfficeSupplies", selectString2).flatMap(tableEntity -> { System.out.println("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); Mono updateEntityMono = tableAsyncClient.updateEntity(tableEntity); @@ -120,18 +113,16 @@ public void UpdateEntity() { public void QueryEntities() { - //build service client - TableServiceAsyncClient tableServiceAsyncClient = new TableServiceAsyncClientBuilder() + // Build service client + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") - .build(); + .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String filterString2 = "$filter = price eq '5'"; String selectString2 = "$select = PartitionKey eq 'markers'"; - Flux queryTableEntity = tableAsyncClient.queryEntity("OfficeSupplies", filterString2, selectString2); - queryTableEntity.subscribe(tableEntity -> { + tableAsyncClient.queryEntity("OfficeSupplies", filterString2, selectString2).subscribe(tableEntity -> { System.out.println("Table Entity: " + tableEntity); }, error -> { System.out.println("There was an error querying the table. Error: " + error); 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 7e864b3497cd..1a1b7f0f0caa 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 @@ -1,5 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; +import com.azure.core.annotation.ServiceClientBuilder; + +@ServiceClientBuilder(serviceClients = {TableClient.class, TableAsyncClient.class}) public class TableClientBuilder { String connectionString; String tableName; @@ -15,11 +20,15 @@ public TableClientBuilder tableName(String tableName) { return this; } - public TableClient build() { + public TableClient buildClient() { return new TableClient(tableName); } - public TableClientBuilder() { + public TableAsyncClient buildAsyncClient() { + return new TableAsyncClient(tableName); + } + + TableClientBuilder() { } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java similarity index 94% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java index 5ca550991fa8..ba7787334884 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/CodeSnippetsSync.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java @@ -1,3 +1,5 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; import com.azure.core.exception.HttpResponseException; @@ -6,20 +8,20 @@ import java.util.HashMap; import java.util.List; -public class CodeSnippetsSync { +public class TableClientCodeSnippets { public static void methods() { //create a tableServiceClient TableServiceClient tableServiceClient = new TableServiceClientBuilder() .connectionString("connectionString") - .build(); + .buildClient(); //create TableClient TableClient tableClient = new TableClientBuilder() .connectionString("connectionString") .tableName("OfficeSupplies") - .build(); + .buildClient(); //create a table @@ -41,7 +43,6 @@ public static void methods() { String selectString = "$selectString= TableName eq 'OfficeSupplies'"; try { - //TODO: create Table class TableName is the odata feild List responseTables = tableServiceClient.queryTables(selectString); } catch (HttpResponseException e) { System.out.println("Table Query Unsuccessful. Error: " + e); 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 index af4673c6c431..542682f7bbdb 100644 --- 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 @@ -1,3 +1,5 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; import java.util.Map; 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 c53ade489eda..c795cbec2fdd 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 @@ -1,13 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; +import com.azure.core.annotation.ServiceClient; import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; +@ServiceClient( + builder = TableServiceClientBuilder.class, + isAsync = true) public class TableServiceAsyncClient { - public TableServiceAsyncClient() { + TableServiceAsyncClient() { } - //public Mono createTable(String name){return Mono.empty(); } public Mono createTable(String name) { return null; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java deleted file mode 100644 index af97960b2e32..000000000000 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientBuilder.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.azure.data.tables; - -public class TableServiceAsyncClientBuilder { - - String connectionString; - - - public TableServiceAsyncClientBuilder connectionString(String connectionString) { - connectionString = connectionString; - return this; - } - - public TableServiceAsyncClient build() { - return new TableServiceAsyncClient(); - } - - public void TableAysncClientBuilder() { - - } -} 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 a9800d52f385..73f1e0dc9246 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 @@ -1,18 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; +import com.azure.core.annotation.ServiceClient; + import java.util.List; +@ServiceClient( + builder = TableServiceClientBuilder.class) public class TableServiceClient { - public TableServiceClient() { + TableServiceClient() { } public void createTable(String name) { } - public void createTableIfNotExist(String name) { - } - public void deleteTable(String name) { } 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 5aa3f5b845dd..61bd86d534cf 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 @@ -1,3 +1,5 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; public class TableServiceClientBuilder { @@ -6,14 +8,18 @@ public class TableServiceClientBuilder { public TableServiceClientBuilder connectionString(String connectionString) { - connectionString = connectionString; + this.connectionString = connectionString; return this; } - public TableServiceClient build() { + public TableServiceClient buildClient() { return new TableServiceClient(); } + public TableServiceAsyncClient buildAsyncClient() { + return new TableServiceAsyncClient(); + } + public TableServiceClientBuilder() { } From a9a61c1401415ea55d4bfa0d48dad287e4883a27 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 18 Jun 2020 17:28:21 -0400 Subject: [PATCH 18/42] writing in docs --- .../com/azure/data/tables/AzureTable.java | 4 +- .../azure/data/tables/TableAsyncClient.java | 79 ++++++++++++++++--- .../com/azure/data/tables/TableClient.java | 53 +++++++++++-- .../tables/TableClientAsyncCodeSnippets.java | 6 +- .../azure/data/tables/TableClientBuilder.java | 22 ++++++ .../data/tables/TableClientCodeSnippets.java | 10 +-- .../com/azure/data/tables/TableEntity.java | 23 +++++- .../data/tables/TableServiceAsyncClient.java | 35 +++++--- .../azure/data/tables/TableServiceClient.java | 16 ++++ .../tables/TableServiceClientBuilder.java | 17 +++- 10 files changed, 225 insertions(+), 40 deletions(-) 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 index d2b0a6195bad..f12ae2d276ac 100644 --- 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 @@ -10,7 +10,9 @@ public class AzureTable { } /** - * Returns the name of this Table + * returns the name of this table + * + * @return table name */ public String getName() { return name; 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 263f2b7c3fc7..d1dbfa9e0f93 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 @@ -3,7 +3,7 @@ package com.azure.data.tables; import com.azure.core.annotation.ServiceClient; -import reactor.core.publisher.Flux; +import com.azure.core.http.rest.PagedFlux; import reactor.core.publisher.Mono; import java.util.Map; @@ -14,36 +14,95 @@ public class TableAsyncClient { String tableName; + TableAsyncClient(String tableName) { this.tableName = tableName; } - public Flux queryEntity(String az, String selectString, String filterString) { + /** + * Queries and returns entities in the given table using the select and filter strings + * + * @param selectString odata select string + * @param filterString odata filter string + * @return a paged flux of all the entity which fit this criteria + */ + public PagedFlux queryEntity(String selectString, String filterString) { return null; } - public Flux queryEntity(String az, String filterString) { - return null; - } - public Mono insertEntity(String tableName, String row, String partition, Map tableEntityProperties) { + /** + * insert a TableEntity with the given properties and return that TableEntity + * + * @param row the RowKey + * @param partition the PartitionKey + * @param tableEntityProperties a map of properties for the TableEntity + * @return the created TableEntity + */ + public Mono insertEntity(String row, String partition, Map tableEntityProperties) { return null; } - public Mono insertEntity(TableEntity te) { + /** + * insert a new entity into the Table attached to this client + * + * @param tableEntity the entity in which to insert + * @return the inserted TableEntity + */ + public Mono insertEntity(TableEntity tableEntity) { return null; } + /** + * deletes the given entity + * + * @param tableEntity entity to delete + * @return a mono void + */ public Mono deleteEntity(TableEntity tableEntity) { return Mono.empty(); } - public Mono updateEntity(TableEntity te) { + /** + * updates the provided TableEntity + * + * @param tableEntity the TableEntity to update + * @return a mono void + */ + public Mono updateEntity(TableEntity tableEntity) { return Mono.empty(); } - public Mono upsertEntity(TableEntity te) { - return null; + + /** + * merges the given entity with the entity which exists on the storage account + * + * @param tableEntity the entity with which to merge + * @return a mono void + */ + public Mono mergeEntity(TableEntity tableEntity) { + return Mono.empty(); } + /** + * inserts the TableEntity if it doesn't exist or replace it if it does + * + * @param tableEntity the TableEntity to insert or replace + * @return a mono void + */ + public Mono insertOrReplaceEntity(TableEntity tableEntity) { + return Mono.empty(); + } + + /** + * inserts the TableEntity if it doesn't exist or merges it with the existing entity if it does + * + * @param tableEntity the TableEntity to insert or merge + * @return a mono void + */ + public Mono insertOrMergeEntity(TableEntity tableEntity) { + return Mono.empty(); + } + + } 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 beb04a191f8a..b7648c30f0cb 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 @@ -18,37 +18,74 @@ public class TableClient { /** * Queries and returns entities in the given table using the select and filter strings - * @param tableName name of table to query + * * @param selectString odata select string * @param filterString odata filter string - * @return + * @return a list of the tables that fit the query */ - public List queryEntity(String tableName, String selectString, String filterString) { + public List queryEntity(String selectString, String filterString) { return null; } + /** + * insert a TableEntity with the given properties and return that TableEntity + * + * @param row the RowKey + * @param partition the PartitionKey + * @param tableEntityProperties a map of properties for the TableEntity + * @return the created TableEntity + */ public TableEntity insertEntity(String row, String partition, Map tableEntityProperties) { return new TableEntity(); } /** + * insert a new entity into the Table attached to this client * - * @param tableEntity - * @return + * @param tableEntity the entity in which to insert + * @return the inserted TableEntity */ public TableEntity insertEntity(TableEntity tableEntity) { return tableEntity; } + /** + * deletes the given entity + * + * @param tableEntity entity to delete + */ public void deleteEntity(TableEntity tableEntity) { } - public void updateEntity(TableEntity te) { + /** + * merges the given entity with the entity which exists on the storage account + * + * @param tableEntity the entity with which to merge + */ + public void mergeEntity(TableEntity tableEntity) { } - public void updateAndReplaceEntity(TableEntity tableEntity) { + /** + * updates the provided TableEntity + * + * @param tableEntity the TableEntity to update + */ + public void updateEntity(TableEntity tableEntity) { + } + + /** + * inserts the TableEntity if it doesn't exist or replace it if it does + * + * @param tableEntity the TableEntity to insert or replace + */ + public void insertOrReplaceEntity(TableEntity tableEntity) { } - public void updateAndMergeEntity(TableEntity tableEntity) { + /** + * inserts the TableEntity if it doesn't exist or merges it with the existing entity if it does + * + * @param tableEntity the TableEntity to insert or merge + */ + public void insertOrMergeEntity(TableEntity tableEntity) { } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java index db5d67fef624..e2a210a2f851 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java @@ -2,7 +2,6 @@ // Licensed under the MIT License. package com.azure.data.tables; -import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import java.util.HashMap; @@ -56,8 +55,7 @@ public void InsertEntity() { String partitionKey = "markers"; HashMap tableEntityProperties = new HashMap<>(); - tableAsyncClient.insertEntity(tableName, row, partitionKey, - tableEntityProperties).subscribe(tableEntity -> { + tableAsyncClient.insertEntity(row, partitionKey, tableEntityProperties).subscribe(tableEntity -> { System.out.println("Insert Entity Successful. Entity: " + tableEntity); }, error -> { System.out.println("There was an error inserting the Entity. Error: " + error); @@ -122,7 +120,7 @@ public void QueryEntities() { String filterString2 = "$filter = price eq '5'"; String selectString2 = "$select = PartitionKey eq 'markers'"; - tableAsyncClient.queryEntity("OfficeSupplies", filterString2, selectString2).subscribe(tableEntity -> { + tableAsyncClient.queryEntity(filterString2, selectString2).subscribe(tableEntity -> { System.out.println("Table Entity: " + tableEntity); }, error -> { System.out.println("There was an error querying the table. Error: " + error); 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 1a1b7f0f0caa..286db5300c3f 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 @@ -10,20 +10,42 @@ public class TableClientBuilder { String tableName; + /** + * Sets the connection string to help build the client + * + * @param connectionString the connection string to the storage account + * @return the TableClientBuilder + */ public TableClientBuilder connectionString(String connectionString) { this.connectionString = connectionString; return this; } + /** + * Sets the table name to help build the client + * + * @param tableName name of the table for which the client is created for + * @return the TableClientBuilder + */ public TableClientBuilder tableName(String tableName) { this.tableName = tableName; return this; } + /** + * builds a sync tableClient + * + * @return a sync tableClient + */ public TableClient buildClient() { return new TableClient(tableName); } + /** + * builds an async tableClient + * + * @return an aysnc tableClient + */ public TableAsyncClient buildAsyncClient() { return new TableAsyncClient(tableName); } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java index ba7787334884..59c6ab6cbd16 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java @@ -71,18 +71,18 @@ public static void methods() { } - //upsert entity (where it is an update and replace) + //upsert entity (where it is an insert or replace) tableEntity.addProperty("Price", "5"); try { - tableClient.updateAndReplaceEntity(tableEntity); + tableClient.insertOrReplaceEntity(tableEntity); } catch (HttpResponseException e) { System.out.println("Upsert Entity Unsuccessful. Error: " + e); } - //upsert entity (where it is an update and replace) + //upsert entity (where it is an insert or merge) tableEntity.addProperty("Price", "5"); try { - tableClient.updateAndMergeEntity(tableEntity); + tableClient.insertOrMergeEntity(tableEntity); } catch (HttpResponseException e) { System.out.println("Upsert Entity Unsuccessful. Error: " + e); } @@ -100,7 +100,7 @@ public static void methods() { String filterString2 = "$filter = Product eq 'markers'"; String selectString2 = "$select = Seller eq 'crayola'"; try { - List list = tableClient.queryEntity(tableName, filterString2, selectString2); + List list = tableClient.queryEntity(filterString2, selectString2); } catch (HttpResponseException e) { System.out.println("Query Table Entities Unsuccessful. Error: " + e); } 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 index 542682f7bbdb..a1e39246fcc3 100644 --- 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 @@ -7,18 +7,37 @@ public class TableEntity { Map properties; - public TableEntity() { + TableEntity() { } - public TableEntity(String table, String row, String partition, Map properties) { + /** + * creates a new TableEntity + * + * @param table table which the TableEntity exists in + * @param row rowKey + * @param partition partitionKey + * @param properties map of properties of the entity + */ + TableEntity(String table, String row, String partition, 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 + */ public void addProperty(String key, Object value) { } 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 c795cbec2fdd..92c51a4428f2 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 @@ -3,7 +3,7 @@ package com.azure.data.tables; import com.azure.core.annotation.ServiceClient; -import reactor.core.publisher.Flux; +import com.azure.core.http.rest.PagedFlux; import reactor.core.publisher.Mono; @ServiceClient( @@ -14,26 +14,43 @@ public class TableServiceAsyncClient { TableServiceAsyncClient() { } + /** + * creates the table with the given name. If a table with the same name already exists, the operation fails. + * + * @param name the name of the table to create + * @return a table client connected to the given table + */ public Mono createTable(String name) { return null; } - public Mono createTableIfNotExist(String name) { - return Mono.empty(); - } - + /** + * deletes the given table. Will error if the table doesn't exists or cannot be found with the given name. + * + * @param name the name of the table to create + * @return mono void + */ public Mono deleteTable(String name) { return Mono.empty(); } - public Flux queryTables(String filterString) { + /** + * query all the tables under the storage account and return them + * + * @param filterString the odata filter string + * @return a flux of the tables that met this criteria + */ + public PagedFlux queryTables(String filterString) { return null; } - public Mono getTable(String tableName) { - return null; - } + /** + * gets the client for this table + * + * @param tableName the table to get the client from + * @return the table client + */ public TableAsyncClient getClient(String tableName) { return null; } 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 73f1e0dc9246..0e7d612d2192 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 @@ -13,12 +13,28 @@ public class TableServiceClient { TableServiceClient() { } + /** + * creates the table with the given name. If a table with the same name already exists, the operation fails. + * + * @param name the name of the table to create + */ public void createTable(String name) { } + /** + * deletes the given table. Will error if the table doesn't exists or cannot be found with the given name. + * + * @param name + */ public void deleteTable(String name) { } + /** + * query all the tables under the storage account and return them + * + * @param filterString the odata filter string + * @return a list of tables that meet the query + */ public List queryTables(String filterString) { return null; } 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 61bd86d534cf..de62ce194ce2 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 @@ -6,16 +6,31 @@ public class TableServiceClientBuilder { String connectionString; - + /** + * Sets the connection string to help build the client + * + * @param connectionString the connection string to the storage account + * @return the TableServiceClientBuilder + */ public TableServiceClientBuilder connectionString(String connectionString) { this.connectionString = connectionString; return this; } + /** + * builds a sync TableServiceClient + * + * @return a sync TableServiceClient + */ public TableServiceClient buildClient() { return new TableServiceClient(); } + /** + * builds an async TableServiceAsyncClient + * + * @return an aysnc TableServiceAsyncClient + */ public TableServiceAsyncClient buildAsyncClient() { return new TableServiceAsyncClient(); } From 4cbcfef6f7865ad191cb7dc9c9dfad9f72b19270 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 24 Jun 2020 11:29:10 -0400 Subject: [PATCH 19/42] fixing stash --- .../src/main/java/com/azure/data/tables/TableAsyncClient.java | 2 +- .../src/main/java/com/azure/data/tables/TableClient.java | 3 ++- .../com/azure/data/tables/TableClientAsyncCodeSnippets.java | 2 +- .../java/com/azure/data/tables/TableServiceAsyncClient.java | 2 +- .../main/java/com/azure/data/tables/TableServiceClient.java | 3 ++- 5 files changed, 7 insertions(+), 5 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 d1dbfa9e0f93..117a94729af8 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,7 +26,7 @@ public class TableAsyncClient { * @param filterString odata filter string * @return a paged flux of all the entity which fit this criteria */ - public PagedFlux queryEntity(String selectString, String filterString) { + public PagedFlux queryEntity(Integer top, String selectString, String filterString) { return null; } 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 b7648c30f0cb..875fed30e513 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 @@ -19,11 +19,12 @@ public class TableClient { /** * Queries and returns entities in the given table using the select and filter strings * + * @param top odata top integer * @param selectString odata select string * @param filterString odata filter string * @return a list of the tables that fit the query */ - public List queryEntity(String selectString, String filterString) { + public List queryEntity(Integer top, String selectString, String filterString) { return null; } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java index e2a210a2f851..d53fe0a9338f 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java @@ -64,7 +64,7 @@ public void InsertEntity() { } - public void DeleteEntity() { + public void deleteEntity() { // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() 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 92c51a4428f2..6d261490fc39 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 @@ -20,7 +20,7 @@ public class TableServiceAsyncClient { * @param name the name of the table to create * @return a table client connected to the given table */ - public Mono createTable(String name) { + public Mono createTable(String name) { return null; } 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 0e7d612d2192..107a265e7240 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 @@ -18,7 +18,8 @@ public class TableServiceClient { * * @param name the name of the table to create */ - public void createTable(String name) { + public AzureTable createTable(String name) { + return null; } /** From bdb4d426906401308b6f542bb4c1f6eb6dcd5a19 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 24 Jun 2020 11:30:50 -0400 Subject: [PATCH 20/42] fixing stash2 --- .../java/com/azure/data/tables/TableAsyncClient.java | 10 ++++++++++ .../main/java/com/azure/data/tables/TableClient.java | 9 +++++++++ .../data/tables/TableClientAsyncCodeSnippets.java | 11 +++++------ .../azure/data/tables/TableClientCodeSnippets.java | 9 +++++---- .../main/java/com/azure/data/tables/TableEntity.java | 3 +-- .../azure/data/tables/TableServiceAsyncClient.java | 9 +++++++++ .../com/azure/data/tables/TableServiceClient.java | 9 +++++++++ 7 files changed, 48 insertions(+), 12 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 117a94729af8..07dd9ad138af 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 @@ -19,6 +19,16 @@ public class TableAsyncClient { this.tableName = tableName; } + + /** + * returns the table associated with this table client + * @param tableName the name of the table + * @return the table + */ + public Mono getTable(String tableName){ + return null; + } + /** * Queries and returns entities in the given table using the select and filter strings * 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 875fed30e513..eebb7faa692e 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 @@ -16,6 +16,15 @@ public class TableClient { this.tableName = tableName; } + /** + * returns the table associated with this TableClient + * @param tableName name of the table + * @return the AzureTable + */ + public AzureTable getTable(String tableName){ + return null; + } + /** * Queries and returns entities in the given table using the select and filter strings * diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java index d53fe0a9338f..b275f248d644 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java @@ -50,7 +50,6 @@ public void InsertEntity() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String tableName = "OfficeSupplies"; String row = "crayolaMarkers"; String partitionKey = "markers"; HashMap tableEntityProperties = new HashMap<>(); @@ -74,7 +73,7 @@ public void deleteEntity() { TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); String selectString = "$select = RowKey eq 'crayolaMarkers'"; - tableAsyncClient.queryEntity("OfficeSupplies", selectString).flatMap(tableEntity -> { + tableAsyncClient.queryEntity(null,"OfficeSupplies", selectString).flatMap(tableEntity -> { System.out.println("Table Entity: " + tableEntity); Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity); return deleteEntityMono; @@ -95,7 +94,7 @@ public void UpdateEntity() { TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); String selectString2 = "$select = RowKey eq 'crayolaMarkers'"; - tableAsyncClient.queryEntity("OfficeSupplies", selectString2).flatMap(tableEntity -> { + tableAsyncClient.queryEntity(null,"OfficeSupplies", selectString2).flatMap(tableEntity -> { System.out.println("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); Mono updateEntityMono = tableAsyncClient.updateEntity(tableEntity); @@ -117,10 +116,10 @@ public void QueryEntities() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String filterString2 = "$filter = price eq '5'"; - String selectString2 = "$select = PartitionKey eq 'markers'"; + String filterString2 = "$filter = Product eq 'markers'"; + String selectString2 = "$select = Seller, Price"; - tableAsyncClient.queryEntity(filterString2, selectString2).subscribe(tableEntity -> { + tableAsyncClient.queryEntity(null,filterString2, selectString2).subscribe(tableEntity -> { System.out.println("Table Entity: " + tableEntity); }, error -> { System.out.println("There was an error querying the table. Error: " + error); diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java index 59c6ab6cbd16..db840ad69ff5 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java @@ -50,11 +50,12 @@ public static void methods() { //insert entity - String tableName = "OfficeSupplies"; String row = "crayola markers"; String partitionKey = "markers"; HashMap tableEntityProperties = new HashMap<>(); - TableEntity tableEntity = new TableEntity(tableName, row, partitionKey, tableEntityProperties); + tableEntityProperties.put("RowKey", "crayolaMarkers"); + tableEntityProperties.put("ParitionKey", "markers"); + TableEntity tableEntity = new TableEntity(tableEntityProperties); try { tableEntity = tableClient.insertEntity(tableEntity); } catch (HttpResponseException e) { @@ -98,9 +99,9 @@ public static void methods() { //query a table String filterString2 = "$filter = Product eq 'markers'"; - String selectString2 = "$select = Seller eq 'crayola'"; + String selectString2 = "$select = Seller, Price"; try { - List list = tableClient.queryEntity(filterString2, selectString2); + List list = tableClient.queryEntity(null, filterString2, selectString2); } catch (HttpResponseException e) { System.out.println("Query Table Entities Unsuccessful. Error: " + e); } 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 index a1e39246fcc3..2decd9e65af9 100644 --- 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 @@ -14,12 +14,11 @@ public class TableEntity { /** * creates a new TableEntity * - * @param table table which the TableEntity exists in * @param row rowKey * @param partition partitionKey * @param properties map of properties of the entity */ - TableEntity(String table, String row, String partition, Map properties) { + TableEntity(Map properties) { this.properties = properties; } 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 6d261490fc39..62b763396a5c 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 @@ -34,6 +34,15 @@ public Mono deleteTable(String name) { return Mono.empty(); } + /** + * retrieves the table client for the provided table or creates one if it doesn't exist + * @param name the name of the table + * @return associated TableClient + */ + public Mono getTableClient(String name) { + return null; + } + /** * query all the tables under the storage account and return them * 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 107a265e7240..66399ad0343c 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 @@ -30,6 +30,15 @@ public AzureTable createTable(String name) { public void deleteTable(String name) { } + /** + * retrieves the table client for the provided table or creates one if it doesn't exist + * @param name the name of the table + * @return associated TableClient + */ + public TableClient getTableClient(String name) { + return null; + } + /** * query all the tables under the storage account and return them * From c6b283ae42f77df9173208c8e9a982ba92e78db4 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 24 Jun 2020 12:00:40 -0400 Subject: [PATCH 21/42] Brandon's suggestions --- .../azure/data/tables/TableAsyncClient.java | 4 +++- .../com/azure/data/tables/TableClient.java | 3 ++- .../tables/TableClientAsyncCodeSnippets.java | 18 +++++++++--------- .../data/tables/TableClientCodeSnippets.java | 14 +++++--------- .../com/azure/data/tables/TableEntity.java | 8 ++++---- .../data/tables/TableServiceAsyncClient.java | 7 +++++-- .../azure/data/tables/TableServiceClient.java | 7 +++++-- 7 files changed, 33 insertions(+), 28 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 07dd9ad138af..ad41a9296feb 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 @@ -22,16 +22,18 @@ public class TableAsyncClient { /** * returns the table associated with this table client + * * @param tableName the name of the table * @return the table */ - public Mono getTable(String tableName){ + public Mono getTable(String tableName) { return null; } /** * Queries and returns entities in the given table using the select and filter strings * + * @param top odata top parameter * @param selectString odata select string * @param filterString odata filter string * @return a paged flux of all the entity which fit this criteria 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 eebb7faa692e..dff090dcb615 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 @@ -18,10 +18,11 @@ public class TableClient { /** * returns the table associated with this TableClient + * * @param tableName name of the table * @return the AzureTable */ - public AzureTable getTable(String tableName){ + public AzureTable getTable(String tableName) { return null; } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java index b275f248d644..e224c3bb6d47 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java @@ -34,8 +34,8 @@ public void AsyncSnippets() { // Query tables - String selectString = "$select= TableName eq 'OfficeSupplies'"; - tableServiceAsyncClient.queryTables(selectString).subscribe(azureTable -> { + String filterString = "$filter=TableName eq 'OfficeSupplies'"; + tableServiceAsyncClient.queryTables(null, null, filterString).subscribe(azureTable -> { System.out.println(azureTable.getName()); }, error -> { System.out.println("There was an error querying the service. Error: " + error); @@ -71,9 +71,9 @@ public void deleteEntity() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String selectString = "$select = RowKey eq 'crayolaMarkers'"; + String filterString = "$filter=RowKey eq 'crayolaMarkers'"; - tableAsyncClient.queryEntity(null,"OfficeSupplies", selectString).flatMap(tableEntity -> { + tableAsyncClient.queryEntity(null, null, filterString).flatMap(tableEntity -> { System.out.println("Table Entity: " + tableEntity); Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity); return deleteEntityMono; @@ -92,9 +92,9 @@ public void UpdateEntity() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String selectString2 = "$select = RowKey eq 'crayolaMarkers'"; + String filterString2 = "$filter=RowKey eq 'crayolaMarkers'"; - tableAsyncClient.queryEntity(null,"OfficeSupplies", selectString2).flatMap(tableEntity -> { + tableAsyncClient.queryEntity(null, null, filterString2).flatMap(tableEntity -> { System.out.println("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); Mono updateEntityMono = tableAsyncClient.updateEntity(tableEntity); @@ -116,10 +116,10 @@ public void QueryEntities() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String filterString2 = "$filter = Product eq 'markers'"; - String selectString2 = "$select = Seller, Price"; + String filterString2 = "$filter=Product eq 'markers'"; + String selectString2 = "$select=Seller, Price"; - tableAsyncClient.queryEntity(null,filterString2, selectString2).subscribe(tableEntity -> { + tableAsyncClient.queryEntity(null, selectString2, filterString2).subscribe(tableEntity -> { System.out.println("Table Entity: " + tableEntity); }, error -> { System.out.println("There was an error querying the table. Error: " + error); diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java index db840ad69ff5..531a92382722 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java @@ -5,7 +5,6 @@ import com.azure.core.exception.HttpResponseException; import com.azure.data.tables.implementation.models.TableServiceErrorException; -import java.util.HashMap; import java.util.List; public class TableClientCodeSnippets { @@ -40,10 +39,10 @@ public static void methods() { } //query tables - String selectString = "$selectString= TableName eq 'OfficeSupplies'"; + String filterString = "$filter=TableName eq 'OfficeSupplies'"; try { - List responseTables = tableServiceClient.queryTables(selectString); + List responseTables = tableServiceClient.queryTables(null, null, filterString); } catch (HttpResponseException e) { System.out.println("Table Query Unsuccessful. Error: " + e); } @@ -52,10 +51,7 @@ public static void methods() { //insert entity String row = "crayola markers"; String partitionKey = "markers"; - HashMap tableEntityProperties = new HashMap<>(); - tableEntityProperties.put("RowKey", "crayolaMarkers"); - tableEntityProperties.put("ParitionKey", "markers"); - TableEntity tableEntity = new TableEntity(tableEntityProperties); + TableEntity tableEntity = new TableEntity(row, partitionKey, null); try { tableEntity = tableClient.insertEntity(tableEntity); } catch (HttpResponseException e) { @@ -98,8 +94,8 @@ public static void methods() { //query a table - String filterString2 = "$filter = Product eq 'markers'"; - String selectString2 = "$select = Seller, Price"; + String filterString2 = "$filter=Product eq 'markers'"; + String selectString2 = "$select=Seller, Price"; try { List list = tableClient.queryEntity(null, filterString2, selectString2); } catch (HttpResponseException e) { 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 index 2decd9e65af9..12718b2ee19f 100644 --- 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 @@ -14,11 +14,11 @@ public class TableEntity { /** * creates a new TableEntity * - * @param row rowKey - * @param partition partitionKey - * @param properties map of properties of the entity + * @param rowKey rowKey + * @param partitionKey partitionKey + * @param properties map of properties of the entity */ - TableEntity(Map properties) { + TableEntity(String rowKey, String partitionKey, Map properties) { this.properties = properties; } 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 62b763396a5c..781bd0ba9216 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 @@ -36,6 +36,7 @@ public Mono deleteTable(String name) { /** * retrieves the table client for the provided table or creates one if it doesn't exist + * * @param name the name of the table * @return associated TableClient */ @@ -46,10 +47,12 @@ public Mono getTableClient(String name) { /** * query all the tables under the storage account and return them * - * @param filterString the odata filter string + * @param top odata top integer + * @param selectString odata select string + * @param filterString odata filter string * @return a flux of the tables that met this criteria */ - public PagedFlux queryTables(String filterString) { + public PagedFlux queryTables(Integer top, String selectString, String filterString) { return null; } 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 66399ad0343c..4fda513cda0d 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 @@ -32,6 +32,7 @@ public void deleteTable(String name) { /** * retrieves the table client for the provided table or creates one if it doesn't exist + * * @param name the name of the table * @return associated TableClient */ @@ -42,10 +43,12 @@ public TableClient getTableClient(String name) { /** * query all the tables under the storage account and return them * - * @param filterString the odata filter string + * @param top odata top integer + * @param selectString odata select string + * @param filterString odata filter string * @return a list of tables that meet the query */ - public List queryTables(String filterString) { + public List queryTables(Integer top, String selectString, String filterString) { return null; } From 42b1fba6209dcfb91864a46674a19bf4926eb3ea Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 29 Jun 2020 17:02:06 -0400 Subject: [PATCH 22/42] stashing changes --- .../azure/data/tables/TableAsyncClient.java | 22 +++++++++++-------- .../com/azure/data/tables/TableClient.java | 16 +++++++++++--- .../azure/data/tables/TableClientBuilder.java | 2 -- .../com/azure/data/tables/TableEntity.java | 7 +++--- .../data/tables/TableServiceAsyncClient.java | 3 +-- ... TableServiceAsyncClientCodeSnippets.java} | 11 ++-------- .../azure/data/tables/TableServiceClient.java | 2 +- ...va => TableServiceClientCodeSnippets.java} | 9 +------- 8 files changed, 34 insertions(+), 38 deletions(-) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{TableClientAsyncCodeSnippets.java => TableServiceAsyncClientCodeSnippets.java} (95%) rename sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/{TableClientCodeSnippets.java => TableServiceClientCodeSnippets.java} (98%) 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 ad41a9296feb..435724cd7a09 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 @@ -14,12 +14,10 @@ public class TableAsyncClient { String tableName; - TableAsyncClient(String tableName) { this.tableName = tableName; } - /** * returns the table associated with this table client * @@ -33,7 +31,7 @@ public Mono getTable(String tableName) { /** * Queries and returns entities in the given table using the select and filter strings * - * @param top odata top parameter + * @param top odata top parameter * @param selectString odata select string * @param filterString odata filter string * @return a paged flux of all the entity which fit this criteria @@ -42,12 +40,11 @@ public PagedFlux queryEntity(Integer top, String selectString, Stri return null; } - /** * insert a TableEntity with the given properties and return that TableEntity * - * @param row the RowKey - * @param partition the PartitionKey + * @param row the RowKey + * @param partition the PartitionKey * @param tableEntityProperties a map of properties for the TableEntity * @return the created TableEntity */ @@ -55,6 +52,16 @@ public Mono insertEntity(String row, String partition, Map insertEntity(String row, String partition ) { + return null; + } + /** * insert a new entity into the Table attached to this client * @@ -85,7 +92,6 @@ public Mono updateEntity(TableEntity tableEntity) { return Mono.empty(); } - /** * merges the given entity with the entity which exists on the storage account * @@ -115,6 +121,4 @@ public Mono insertOrReplaceEntity(TableEntity tableEntity) { public Mono insertOrMergeEntity(TableEntity tableEntity) { return Mono.empty(); } - - } 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 dff090dcb615..e14e06a4af66 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 @@ -29,7 +29,7 @@ public AzureTable getTable(String tableName) { /** * Queries and returns entities in the given table using the select and filter strings * - * @param top odata top integer + * @param top odata top integer * @param selectString odata select string * @param filterString odata filter string * @return a list of the tables that fit the query @@ -41,8 +41,8 @@ public List queryEntity(Integer top, String selectString, String fi /** * insert a TableEntity with the given properties and return that TableEntity * - * @param row the RowKey - * @param partition the PartitionKey + * @param row the RowKey + * @param partition the PartitionKey * @param tableEntityProperties a map of properties for the TableEntity * @return the created TableEntity */ @@ -50,6 +50,16 @@ public TableEntity insertEntity(String row, String partition, Map properties; TableEntity() { - } /** * creates a new TableEntity * - * @param rowKey rowKey + * @param rowKey rowKey * @param partitionKey partitionKey - * @param properties map of properties of the entity + * @param properties map of properties of the entity */ TableEntity(String rowKey, String partitionKey, Map properties) { this.properties = properties; @@ -34,7 +33,7 @@ public Map getProperties() { /** * adds a new property to this entity's property map * - * @param key the key of the property + * @param key the key of the property * @param value the value of the property */ public void addProperty(String key, Object value) { 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 781bd0ba9216..414ff9eacb07 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 @@ -47,7 +47,7 @@ public Mono getTableClient(String name) { /** * query all the tables under the storage account and return them * - * @param top odata top integer + * @param top odata top integer * @param selectString odata select string * @param filterString odata filter string * @return a flux of the tables that met this criteria @@ -66,5 +66,4 @@ public PagedFlux queryTables(Integer top, String selectString, Strin public TableAsyncClient getClient(String tableName) { return null; } - } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java similarity index 95% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java index e224c3bb6d47..a4aff408ed56 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientAsyncCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java @@ -7,7 +7,7 @@ import java.util.HashMap; -public class TableClientAsyncCodeSnippets { +public class TableServiceAsyncClientCodeSnippets { public void AsyncSnippets() { @@ -52,15 +52,12 @@ public void InsertEntity() { TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); String row = "crayolaMarkers"; String partitionKey = "markers"; - HashMap tableEntityProperties = new HashMap<>(); - tableAsyncClient.insertEntity(row, partitionKey, tableEntityProperties).subscribe(tableEntity -> { + tableAsyncClient.insertEntity(row, partitionKey).subscribe(tableEntity -> { System.out.println("Insert Entity Successful. Entity: " + tableEntity); }, error -> { System.out.println("There was an error inserting the Entity. Error: " + error); }); - - } public void deleteEntity() { @@ -104,8 +101,6 @@ public void UpdateEntity() { }, error -> { System.out.println("There was an error updating the Entity. Error: " + error); }); - - } public void QueryEntities() { @@ -124,7 +119,5 @@ public void QueryEntities() { }, error -> { System.out.println("There was an error querying the table. Error: " + error); }); - } - } 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 4fda513cda0d..033331c5b297 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 @@ -43,7 +43,7 @@ public TableClient getTableClient(String name) { /** * query all the tables under the storage account and return them * - * @param top odata top integer + * @param top odata top integer * @param selectString odata select string * @param filterString odata filter string * @return a list of tables that meet the query diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java similarity index 98% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java rename to sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java index 531a92382722..e48d11931c10 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java @@ -7,7 +7,7 @@ import java.util.List; -public class TableClientCodeSnippets { +public class TableServiceClientCodeSnippets { public static void methods() { @@ -22,7 +22,6 @@ public static void methods() { .tableName("OfficeSupplies") .buildClient(); - //create a table try { tableServiceClient.createTable("OfficeSupplies"); @@ -47,7 +46,6 @@ public static void methods() { System.out.println("Table Query Unsuccessful. Error: " + e); } - //insert entity String row = "crayola markers"; String partitionKey = "markers"; @@ -58,7 +56,6 @@ public static void methods() { System.out.println("Insert Entity Unsuccessful. Error: " + e); } - //update entity tableEntity.addProperty("Seller", "Crayola"); try { @@ -67,7 +64,6 @@ public static void methods() { System.out.println("Update Entity Unsuccessful. Error: " + e); } - //upsert entity (where it is an insert or replace) tableEntity.addProperty("Price", "5"); try { @@ -84,7 +80,6 @@ public static void methods() { System.out.println("Upsert Entity Unsuccessful. Error: " + e); } - //delete entity try { tableClient.deleteEntity(tableEntity); @@ -92,7 +87,6 @@ public static void methods() { System.out.println("Delete Entity Unsuccessful. Error: " + e); } - //query a table String filterString2 = "$filter=Product eq 'markers'"; String selectString2 = "$select=Seller, Price"; @@ -102,5 +96,4 @@ public static void methods() { System.out.println("Query Table Entities Unsuccessful. Error: " + e); } } - } From 40cdbf7d1a1d8fb845f53fe3802bfb375a218580 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Tue, 30 Jun 2020 12:14:14 -0400 Subject: [PATCH 23/42] QueryOptions added --- .../src/main/java/com/azure/data/tables/QueryOptions.java | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java new file mode 100644 index 000000000000..e72802095b8d --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java @@ -0,0 +1,4 @@ +package com.azure.data.tables; + +public class QueryOptions { +} From d8ff221cfb18cebc31c7d6357fa7991d92d2d89b Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Tue, 30 Jun 2020 12:14:35 -0400 Subject: [PATCH 24/42] Added QueryOptions class --- .../com/azure/data/tables/QueryOptions.java | 74 +++++++++++++++++++ .../azure/data/tables/TableAsyncClient.java | 9 +-- .../com/azure/data/tables/TableClient.java | 7 +- .../data/tables/TableServiceAsyncClient.java | 6 +- .../TableServiceAsyncClientCodeSnippets.java | 22 +++--- .../azure/data/tables/TableServiceClient.java | 6 +- .../TableServiceClientCodeSnippets.java | 11 +-- 7 files changed, 104 insertions(+), 31 deletions(-) diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java index e72802095b8d..a80850a501ca 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java @@ -1,4 +1,78 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; public class QueryOptions { + + private String filter; + private String select; + private Integer top; + + + QueryOptions(String filter, String select, Integer top) { + this.filter = filter; + this.select = select; + this.top = top; + } + + QueryOptions() { + filter = null; + select = null; + top = null; + } + + /** + * getter for Filter parameter + * + * @return filter parameter + */ + public String getFilter() { + return filter; + } + + /** + * getter for Select parameter + * + * @return select parameter + */ + public String getSelect() { + return select; + } + + /** + * getter for Top parameter + * + * @return top parameter + */ + public Integer getTop() { + return top; + } + + /** + * setter for filter parameter + * + * @param filter the odata filter string + */ + public void setFilter(String filter) { + this.filter = filter; + } + + /** + * setter for select parameter + * + * @param select the odata select string + */ + public void setSelect(String select) { + this.select = select; + } + + /** + * setter for top parameter + * + * @param top the odata top integer + */ + public void setTop(Integer top) { + this.top = top; + } + } 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 435724cd7a09..617d76bf5315 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 @@ -31,12 +31,10 @@ public Mono getTable(String tableName) { /** * Queries and returns entities in the given table using the select and filter strings * - * @param top odata top parameter - * @param selectString odata select string - * @param filterString odata filter string + * @param queryOptions the odata query object * @return a paged flux of all the entity which fit this criteria */ - public PagedFlux queryEntity(Integer top, String selectString, String filterString) { + public PagedFlux queryEntity(QueryOptions queryOptions) { return null; } @@ -54,11 +52,12 @@ public Mono insertEntity(String row, String partition, Map insertEntity(String row, String partition ) { + public Mono insertEntity(String row, String partition) { return null; } 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 e14e06a4af66..ee0503e7c76a 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 @@ -29,12 +29,10 @@ public AzureTable getTable(String tableName) { /** * Queries and returns entities in the given table using the select and filter strings * - * @param top odata top integer - * @param selectString odata select string - * @param filterString odata filter string + * @param queryOptions the odata query object * @return a list of the tables that fit the query */ - public List queryEntity(Integer top, String selectString, String filterString) { + public List queryEntity(QueryOptions queryOptions) { return null; } @@ -52,6 +50,7 @@ public TableEntity insertEntity(String row, String partition, Map getTableClient(String name) { /** * query all the tables under the storage account and return them * - * @param top odata top integer - * @param selectString odata select string - * @param filterString odata filter string + * @param queryOptions the odata query object * @return a flux of the tables that met this criteria */ - public PagedFlux queryTables(Integer top, String selectString, String filterString) { + public PagedFlux queryTables(QueryOptions queryOptions) { return null; } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java index a4aff408ed56..6dbe7fd4a9fe 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java @@ -34,8 +34,9 @@ public void AsyncSnippets() { // Query tables - String filterString = "$filter=TableName eq 'OfficeSupplies'"; - tableServiceAsyncClient.queryTables(null, null, filterString).subscribe(azureTable -> { + QueryOptions queryOptions = new QueryOptions(); + queryOptions.setFilter("TableName eq OfficeSupplies"); + tableServiceAsyncClient.queryTables(queryOptions).subscribe(azureTable -> { System.out.println(azureTable.getName()); }, error -> { System.out.println("There was an error querying the service. Error: " + error); @@ -68,9 +69,10 @@ public void deleteEntity() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String filterString = "$filter=RowKey eq 'crayolaMarkers'"; + QueryOptions queryOptions = new QueryOptions(); + queryOptions.setFilter("RowKey eq crayolaMarkers"); - tableAsyncClient.queryEntity(null, null, filterString).flatMap(tableEntity -> { + tableAsyncClient.queryEntity(queryOptions).flatMap(tableEntity -> { System.out.println("Table Entity: " + tableEntity); Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity); return deleteEntityMono; @@ -89,9 +91,10 @@ public void UpdateEntity() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String filterString2 = "$filter=RowKey eq 'crayolaMarkers'"; + QueryOptions queryOptions = new QueryOptions(); + queryOptions.setFilter("RowKey eq crayolaMarkers"); - tableAsyncClient.queryEntity(null, null, filterString2).flatMap(tableEntity -> { + tableAsyncClient.queryEntity(queryOptions).flatMap(tableEntity -> { System.out.println("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); Mono updateEntityMono = tableAsyncClient.updateEntity(tableEntity); @@ -111,10 +114,11 @@ public void QueryEntities() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String filterString2 = "$filter=Product eq 'markers'"; - String selectString2 = "$select=Seller, Price"; + QueryOptions queryOptions = new QueryOptions(); + queryOptions.setFilter("Product eq markers"); + queryOptions.setSelect("Seller, Price"); - tableAsyncClient.queryEntity(null, selectString2, filterString2).subscribe(tableEntity -> { + tableAsyncClient.queryEntity(queryOptions).subscribe(tableEntity -> { System.out.println("Table Entity: " + tableEntity); }, error -> { System.out.println("There was an error querying the table. Error: " + error); 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 033331c5b297..0338df1fba86 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 @@ -43,12 +43,10 @@ public TableClient getTableClient(String name) { /** * query all the tables under the storage account and return them * - * @param top odata top integer - * @param selectString odata select string - * @param filterString odata filter string + * @param queryOptions the odata query object * @return a list of tables that meet the query */ - public List queryTables(Integer top, String selectString, String filterString) { + public List queryTables(QueryOptions queryOptions) { return null; } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java index e48d11931c10..e867fc006b5f 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java @@ -38,10 +38,11 @@ public static void methods() { } //query tables - String filterString = "$filter=TableName eq 'OfficeSupplies'"; + QueryOptions queryOptions = new QueryOptions(); + queryOptions.setFilter("TableName eq OfficeSupplies"); try { - List responseTables = tableServiceClient.queryTables(null, null, filterString); + List responseTables = tableServiceClient.queryTables(queryOptions); } catch (HttpResponseException e) { System.out.println("Table Query Unsuccessful. Error: " + e); } @@ -88,10 +89,10 @@ public static void methods() { } //query a table - String filterString2 = "$filter=Product eq 'markers'"; - String selectString2 = "$select=Seller, Price"; + queryOptions.setFilter("Product eq markers"); + queryOptions.setSelect("Seller, Price"); try { - List list = tableClient.queryEntity(null, filterString2, selectString2); + List list = tableClient.queryEntity(queryOptions); } catch (HttpResponseException e) { System.out.println("Query Table Entities Unsuccessful. Error: " + e); } From 1b2339b129edbc712a22573ccb3985de59a343aa Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Tue, 30 Jun 2020 12:23:31 -0400 Subject: [PATCH 25/42] brandon comments round 2 --- .../com/azure/data/tables/AzureTable.java | 8 +++++++ .../azure/data/tables/TableAsyncClient.java | 21 ------------------- .../com/azure/data/tables/TableClient.java | 21 ------------------- .../data/tables/TableServiceAsyncClient.java | 12 ++++++++++- .../TableServiceAsyncClientCodeSnippets.java | 2 +- .../azure/data/tables/TableServiceClient.java | 16 ++++++++++---- .../TableServiceClientCodeSnippets.java | 2 +- 7 files changed, 33 insertions(+), 49 deletions(-) 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 index f12ae2d276ac..bf836239e335 100644 --- 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 @@ -17,4 +17,12 @@ public class AzureTable { 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 617d76bf5315..5c368b0e1702 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 @@ -18,16 +18,6 @@ public class TableAsyncClient { this.tableName = tableName; } - /** - * returns the table associated with this table client - * - * @param tableName the name of the table - * @return the table - */ - public Mono getTable(String tableName) { - return null; - } - /** * Queries and returns entities in the given table using the select and filter strings * @@ -50,17 +40,6 @@ public Mono insertEntity(String row, String partition, Map insertEntity(String row, String partition) { - return null; - } - /** * insert a new entity into the Table attached to this client * 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 ee0503e7c76a..53197e272922 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 @@ -16,16 +16,6 @@ public class TableClient { this.tableName = tableName; } - /** - * returns the table associated with this TableClient - * - * @param tableName name of the table - * @return the AzureTable - */ - public AzureTable getTable(String tableName) { - return null; - } - /** * Queries and returns entities in the given table using the select and filter strings * @@ -48,17 +38,6 @@ public TableEntity insertEntity(String row, String partition, Map createTable(String name) { /** * deletes the given table. Will error if the table doesn't exists or cannot be found with the given name. * - * @param name the name of the table to create + * @param name the name of the table to delete * @return mono void */ public Mono deleteTable(String name) { return Mono.empty(); } + /** + * deletes the given table. Will error if the table doesn't exists or cannot be found with the given name. + * + * @param azureTable the table to delete + * @return mono void + */ + public Mono deleteTable(AzureTable azureTable) { + return Mono.empty(); + } + /** * retrieves the table client for the provided table or creates one if it doesn't exist * diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java index 6dbe7fd4a9fe..fa76273160a3 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java @@ -54,7 +54,7 @@ public void InsertEntity() { String row = "crayolaMarkers"; String partitionKey = "markers"; - tableAsyncClient.insertEntity(row, partitionKey).subscribe(tableEntity -> { + tableAsyncClient.insertEntity(new TableEntity(row, partitionKey, null)).subscribe(tableEntity -> { System.out.println("Insert Entity Successful. Entity: " + tableEntity); }, error -> { System.out.println("There was an error inserting the Entity. Error: " + error); 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 0338df1fba86..fafdb0ff024f 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 @@ -25,18 +25,26 @@ public AzureTable createTable(String name) { /** * deletes the given table. Will error if the table doesn't exists or cannot be found with the given name. * - * @param name + * @param name the name of the table to be deleted */ public void deleteTable(String name) { } /** - * retrieves the table client for the provided table or creates one if it doesn't exist + * deletes the given table. Will error if the table doesn't exists or cannot be found with the given name. + * + * @param azureTable the table to be deleted + */ + public void deleteTable(AzureTable azureTable) { + } + + /** + * gets a given table by name * * @param name the name of the table - * @return associated TableClient + * @return associated azure table object */ - public TableClient getTableClient(String name) { + public AzureTable getTable(String name) { return null; } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java index e867fc006b5f..49686fb7c46f 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java @@ -24,7 +24,7 @@ public static void methods() { //create a table try { - tableServiceClient.createTable("OfficeSupplies"); + AzureTable officeSuppliesTable = tableServiceClient.createTable("OfficeSupplies"); } catch (TableServiceErrorException e) { //use azure core errors? based on System.out.println("Create Table Unsuccessful. Error: " + e); From c2b6dd97e22e73685bae41c1fbcfd9943a3c211d Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Tue, 30 Jun 2020 12:24:39 -0400 Subject: [PATCH 26/42] delete pom from cosmos tables --- sdk/cosmos/azure-cosmos-table/pom.xml | 110 -------------------------- 1 file changed, 110 deletions(-) delete mode 100644 sdk/cosmos/azure-cosmos-table/pom.xml diff --git a/sdk/cosmos/azure-cosmos-table/pom.xml b/sdk/cosmos/azure-cosmos-table/pom.xml deleted file mode 100644 index 0399a66c0b67..000000000000 --- a/sdk/cosmos/azure-cosmos-table/pom.xml +++ /dev/null @@ -1,110 +0,0 @@ - - - 4.0.0 - - com.azure - azure-client-sdk-parent - 1.7.0 - ../../parents/azure-client-sdk-parent - - - com.azure - azure-data-tables - 1.0.0-beta.1 - Microsoft Azure SDK for Azure Table - This package contains the Microsoft Azure Table storage client library. - https://github.com/Azure/azure-sdk-for-java - - - - azure-java-build-docs - ${site.url}/site/${project.artifactId} - - - - - scm:git:https://github.com/Azure/azure-sdk-for-java - scm:git:git@github.com:Azure/azure-sdk-for-java.git - HEAD - - - - - true - - - - - com.azure - azure-core - 1.5.1 - - - - com.azure - azure-core-test - 1.3.0 - test - - - org.junit.jupiter - junit-jupiter-api - 5.6.2 - test - - - org.junit.jupiter - junit-jupiter-engine - 5.6.2 - test - - - org.junit.jupiter - junit-jupiter-params - 5.6.2 - test - - - io.projectreactor - reactor-test - 3.3.5.RELEASE - test - - - org.mockito - mockito-core - 3.0.0 - test - - - io.projectreactor - reactor-core - 12.7.0-beta.1 - compile - - - - - - - - org.apache.maven.plugins - maven-enforcer-plugin - 3.0.0-M3 - - - - - com.azure:* - - - - - - - - - From cf4e00f4a1ec94fa35ac5f1a2f071fdce171c6e6 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Tue, 30 Jun 2020 13:36:21 -0400 Subject: [PATCH 27/42] fix query options builder --- .../com/azure/data/tables/QueryOptions.java | 78 ------------------- .../azure/data/tables/TableAsyncClient.java | 1 + .../com/azure/data/tables/TableClient.java | 1 + .../data/tables/TableServiceAsyncClient.java | 1 + .../TableServiceAsyncClientCodeSnippets.java | 3 +- .../azure/data/tables/TableServiceClient.java | 1 + .../TableServiceClientCodeSnippets.java | 1 + 7 files changed, 6 insertions(+), 80 deletions(-) delete mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java deleted file mode 100644 index a80850a501ca..000000000000 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java +++ /dev/null @@ -1,78 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. -package com.azure.data.tables; - -public class QueryOptions { - - private String filter; - private String select; - private Integer top; - - - QueryOptions(String filter, String select, Integer top) { - this.filter = filter; - this.select = select; - this.top = top; - } - - QueryOptions() { - filter = null; - select = null; - top = null; - } - - /** - * getter for Filter parameter - * - * @return filter parameter - */ - public String getFilter() { - return filter; - } - - /** - * getter for Select parameter - * - * @return select parameter - */ - public String getSelect() { - return select; - } - - /** - * getter for Top parameter - * - * @return top parameter - */ - public Integer getTop() { - return top; - } - - /** - * setter for filter parameter - * - * @param filter the odata filter string - */ - public void setFilter(String filter) { - this.filter = filter; - } - - /** - * setter for select parameter - * - * @param select the odata select string - */ - public void setSelect(String select) { - this.select = select; - } - - /** - * setter for top parameter - * - * @param top the odata top integer - */ - public void setTop(Integer top) { - this.top = top; - } - -} 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 5c368b0e1702..e74f232db52b 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 @@ -4,6 +4,7 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.http.rest.PagedFlux; +import com.azure.data.tables.implementation.models.QueryOptions; import reactor.core.publisher.Mono; import java.util.Map; 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 53197e272922..bf187b7b4153 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 @@ -3,6 +3,7 @@ package com.azure.data.tables; import com.azure.core.annotation.ServiceClient; +import com.azure.data.tables.implementation.models.QueryOptions; import java.util.List; import java.util.Map; 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 3ec2eadd2056..f15629900454 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 @@ -4,6 +4,7 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.http.rest.PagedFlux; +import com.azure.data.tables.implementation.models.QueryOptions; import reactor.core.publisher.Mono; @ServiceClient( diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java index fa76273160a3..34c4cfd4bf26 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java @@ -2,10 +2,9 @@ // Licensed under the MIT License. package com.azure.data.tables; +import com.azure.data.tables.implementation.models.QueryOptions; import reactor.core.publisher.Mono; -import java.util.HashMap; - public class TableServiceAsyncClientCodeSnippets { 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 fafdb0ff024f..d9c8a35162fb 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 @@ -3,6 +3,7 @@ package com.azure.data.tables; import com.azure.core.annotation.ServiceClient; +import com.azure.data.tables.implementation.models.QueryOptions; import java.util.List; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java index 49686fb7c46f..1a2ea80184f7 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java @@ -3,6 +3,7 @@ package com.azure.data.tables; import com.azure.core.exception.HttpResponseException; +import com.azure.data.tables.implementation.models.QueryOptions; import com.azure.data.tables.implementation.models.TableServiceErrorException; import java.util.List; From d804bfbb690e368572eb5f4c60d72c2e4a1bb899 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 1 Jul 2020 08:58:07 -0400 Subject: [PATCH 28/42] fixing javadocs error --- .../src/main/java/com/azure/data/tables/TableServiceClient.java | 1 + 1 file changed, 1 insertion(+) 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 d9c8a35162fb..075827d434d0 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 @@ -18,6 +18,7 @@ public class TableServiceClient { * creates the table with the given name. If a table with the same name already exists, the operation fails. * * @param name the name of the table to create + * @return AzureTable of the created table */ public AzureTable createTable(String name) { return null; From aba06e6024251f359747ce7da20ed1c23fa73998 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 1 Jul 2020 11:21:53 -0400 Subject: [PATCH 29/42] fix pom --- sdk/tables/azure-data-tables/pom.xml | 1 - 1 file changed, 1 deletion(-) diff --git a/sdk/tables/azure-data-tables/pom.xml b/sdk/tables/azure-data-tables/pom.xml index 94d18ab8659c..242dd0054b3f 100644 --- a/sdk/tables/azure-data-tables/pom.xml +++ b/sdk/tables/azure-data-tables/pom.xml @@ -32,7 +32,6 @@ Licensed under the MIT License. HEAD - true From 0f2962662a4d3053da935af6e22ceb47e11ea352 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 1 Jul 2020 11:51:56 -0400 Subject: [PATCH 30/42] checkstyles --- .../com/azure/data/tables/AzureTable.java | 3 + .../com/azure/data/tables/QueryOptions.java | 76 +++++++++++++++++++ .../azure/data/tables/TableAsyncClient.java | 6 +- .../com/azure/data/tables/TableClient.java | 6 +- .../azure/data/tables/TableClientBuilder.java | 3 + .../com/azure/data/tables/TableEntity.java | 13 +++- .../data/tables/TableServiceAsyncClient.java | 4 +- .../TableServiceAsyncClientCodeSnippets.java | 64 ++++++++-------- .../azure/data/tables/TableServiceClient.java | 4 +- .../tables/TableServiceClientBuilder.java | 11 ++- .../TableServiceClientCodeSnippets.java | 28 +++---- .../com/azure/data/tables/package-info.java | 7 ++ 12 files changed, 173 insertions(+), 52 deletions(-) create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/package-info.java 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 index bf836239e335..98cbc8598203 100644 --- 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 @@ -2,6 +2,9 @@ // Licensed under the MIT License. package com.azure.data.tables; +/** + * class for a table object + */ public class AzureTable { private final String name; diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java new file mode 100644 index 000000000000..892a822a2fd1 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java @@ -0,0 +1,76 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +package com.azure.data.tables; + +/** + * helps construct a query + */ +public final class QueryOptions { + private Integer top; + private String select; + private String filter; + + /** + * Get the top property: Maximum number of records to return. + * + * @return the top value. + */ + public Integer getTop() { + return this.top; + } + + /** + * Set the top property: Maximum number of records to return. + * + * @param top the top value to set. + * @return the QueryOptions object itself. + */ + public QueryOptions setTop(Integer top) { + this.top = top; + return this; + } + + /** + * Get the select property: Select expression using OData notation. Limits the columns on each record to just those + * requested, e.g. "$select=PolicyAssignmentId, ResourceId". + * + * @return the select value. + */ + public String getSelect() { + return this.select; + } + + /** + * Set the select property: Select expression using OData notation. Limits the columns on each record to just those + * requested, e.g. "$select=PolicyAssignmentId, ResourceId". + * + * @param select the select value to set. + * @return the QueryOptions object itself. + */ + public QueryOptions setSelect(String select) { + this.select = select; + return this; + } + + /** + * Get the filter property: OData filter expression. + * + * @return the filter value. + */ + public String getFilter() { + return this.filter; + } + + /** + * Set the filter property: OData filter expression. + * + * @param filter the filter value to set. + * @return the QueryOptions object itself. + */ + public QueryOptions setFilter(String filter) { + this.filter = filter; + return this; + } +} + 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 e74f232db52b..5c1c44ebe680 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 @@ -4,16 +4,18 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.http.rest.PagedFlux; -import com.azure.data.tables.implementation.models.QueryOptions; import reactor.core.publisher.Mono; import java.util.Map; +/** + * class for the table async client + */ @ServiceClient( builder = TableClientBuilder.class, isAsync = true) public class TableAsyncClient { - String tableName; + final String tableName; TableAsyncClient(String tableName) { this.tableName = tableName; 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 bf187b7b4153..be3874ecd69f 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 @@ -3,15 +3,17 @@ package com.azure.data.tables; import com.azure.core.annotation.ServiceClient; -import com.azure.data.tables.implementation.models.QueryOptions; import java.util.List; import java.util.Map; +/** + * sync client for table operations + */ @ServiceClient( builder = TableClientBuilder.class) public class TableClient { - String tableName; + final String tableName; TableClient(String tableName) { this.tableName = tableName; 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 928be5772f54..220cae5c17c5 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 @@ -4,6 +4,9 @@ import com.azure.core.annotation.ServiceClientBuilder; +/** + * builds table client + */ @ServiceClientBuilder(serviceClients = {TableClient.class, TableAsyncClient.class}) public class TableClientBuilder { String connectionString; 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 index 0e89cddac0df..0f00ed50d937 100644 --- 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 @@ -4,8 +4,11 @@ import java.util.Map; +/** + * table entity class + */ public class TableEntity { - Map properties; + private Map properties; TableEntity() { } @@ -39,4 +42,12 @@ public Map getProperties() { public void addProperty(String key, Object value) { } + + /** + * set the properties + * @param properties properties to set to this entity + */ + public void setProperties(Map properties) { + this.properties = properties; + } } 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 f15629900454..aded42e045e9 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 @@ -4,9 +4,11 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.http.rest.PagedFlux; -import com.azure.data.tables.implementation.models.QueryOptions; import reactor.core.publisher.Mono; +/** + * async client for account operations + */ @ServiceClient( builder = TableServiceClientBuilder.class, isAsync = true) diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java index 34c4cfd4bf26..2e9620c77f68 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java @@ -2,14 +2,16 @@ // Licensed under the MIT License. package com.azure.data.tables; -import com.azure.data.tables.implementation.models.QueryOptions; +import com.azure.core.util.logging.ClientLogger; import reactor.core.publisher.Mono; - +/** + * async code snippets for the table service + */ public class TableServiceAsyncClientCodeSnippets { + final ClientLogger logger = new ClientLogger("TableServiceAsyncClientCodeSnippets"); - - public void AsyncSnippets() { + private void methods() { // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() @@ -18,31 +20,31 @@ public void AsyncSnippets() { // Add a table tableServiceAsyncClient.createTable("OfficeSupplies").subscribe(Void -> { - System.out.println("Table creation successful."); + logger.info("Table creation successful."); }, error -> { - System.out.println("There was an error creating the table. Error: " + error); - }); + logger.error("There was an error creating the table. Error: " + error); + }); // Delete a table tableServiceAsyncClient.deleteTable("OfficeSupplies").subscribe(Void -> { - System.out.println("Table deletion successful"); + logger.info("Table deletion successful"); }, error -> { - System.out.println("There was an error deleting the table. Error: " + error); - }); + logger.error("There was an error deleting the table. Error: " + error); + }); // Query tables QueryOptions queryOptions = new QueryOptions(); queryOptions.setFilter("TableName eq OfficeSupplies"); tableServiceAsyncClient.queryTables(queryOptions).subscribe(azureTable -> { - System.out.println(azureTable.getName()); + logger.info(azureTable.getName()); }, error -> { - System.out.println("There was an error querying the service. Error: " + error); - }); + logger.error("There was an error querying the service. Error: " + error); + }); } - public void InsertEntity() { + private void insertEntity() { // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() @@ -54,13 +56,13 @@ public void InsertEntity() { String partitionKey = "markers"; tableAsyncClient.insertEntity(new TableEntity(row, partitionKey, null)).subscribe(tableEntity -> { - System.out.println("Insert Entity Successful. Entity: " + tableEntity); + logger.info("Insert Entity Successful. Entity: " + tableEntity); }, error -> { - System.out.println("There was an error inserting the Entity. Error: " + error); - }); + logger.error("There was an error inserting the Entity. Error: " + error); + }); } - public void deleteEntity() { + private void deleteEntity() { // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() @@ -72,17 +74,17 @@ public void deleteEntity() { queryOptions.setFilter("RowKey eq crayolaMarkers"); tableAsyncClient.queryEntity(queryOptions).flatMap(tableEntity -> { - System.out.println("Table Entity: " + tableEntity); + logger.info("Table Entity: " + tableEntity); Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity); return deleteEntityMono; }).subscribe(Void -> { - System.out.println("Delete Entity Successful."); + logger.info("Delete Entity Successful."); }, error -> { - System.out.println("There was an error deleting the Entity. Error: " + error); - }); + logger.error("There was an error deleting the Entity. Error: " + error); + }); } - public void UpdateEntity() { + private void updateEntity() { // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() @@ -94,18 +96,18 @@ public void UpdateEntity() { queryOptions.setFilter("RowKey eq crayolaMarkers"); tableAsyncClient.queryEntity(queryOptions).flatMap(tableEntity -> { - System.out.println("Table Entity: " + tableEntity); + logger.info("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); Mono updateEntityMono = tableAsyncClient.updateEntity(tableEntity); return updateEntityMono; }).subscribe(Void -> { - System.out.println("Update Entity Successful."); + logger.info("Update Entity Successful."); }, error -> { - System.out.println("There was an error updating the Entity. Error: " + error); - }); + logger.error("There was an error updating the Entity. Error: " + error); + }); } - public void QueryEntities() { + private void queryEntities() { // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() @@ -118,9 +120,9 @@ public void QueryEntities() { queryOptions.setSelect("Seller, Price"); tableAsyncClient.queryEntity(queryOptions).subscribe(tableEntity -> { - System.out.println("Table Entity: " + tableEntity); + logger.info("Table Entity: " + tableEntity); }, error -> { - System.out.println("There was an error querying the table. Error: " + error); - }); + logger.error("There was an error querying the table. Error: " + error); + }); } } 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 075827d434d0..2dfe7e693220 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 @@ -3,10 +3,12 @@ package com.azure.data.tables; import com.azure.core.annotation.ServiceClient; -import com.azure.data.tables.implementation.models.QueryOptions; import java.util.List; +/** + * client for table service + */ @ServiceClient( builder = TableServiceClientBuilder.class) public class TableServiceClient { 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 de62ce194ce2..922c32a33527 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 @@ -2,6 +2,12 @@ // Licensed under the MIT License. package com.azure.data.tables; +import com.azure.core.annotation.ServiceClientBuilder; + +/** + * builds the table service clients + */ +@ServiceClientBuilder(serviceClients = {TableServiceClient.class, TableServiceAsyncClient.class}) public class TableServiceClientBuilder { String connectionString; @@ -29,12 +35,15 @@ public TableServiceClient buildClient() { /** * builds an async TableServiceAsyncClient * - * @return an aysnc TableServiceAsyncClient + * @return TableServiceAsyncClient an aysnc TableServiceAsyncClient */ public TableServiceAsyncClient buildAsyncClient() { return new TableServiceAsyncClient(); } + /** + * constructor + */ public TableServiceClientBuilder() { } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java index 1a2ea80184f7..935ad4eb7017 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java @@ -3,14 +3,17 @@ package com.azure.data.tables; import com.azure.core.exception.HttpResponseException; -import com.azure.data.tables.implementation.models.QueryOptions; +import com.azure.core.util.logging.ClientLogger; import com.azure.data.tables.implementation.models.TableServiceErrorException; - import java.util.List; +/** + * sync code snippets for the table service + */ public class TableServiceClientCodeSnippets { - public static void methods() { + private static void methods() { + ClientLogger logger = new ClientLogger("TableServiceClientCodeSnippets"); //create a tableServiceClient TableServiceClient tableServiceClient = new TableServiceClientBuilder() @@ -27,15 +30,14 @@ public static void methods() { try { AzureTable officeSuppliesTable = tableServiceClient.createTable("OfficeSupplies"); } catch (TableServiceErrorException e) { - //use azure core errors? based on - System.out.println("Create Table Unsuccessful. Error: " + e); + logger.error("Create Table Unsuccessful. Error: " + e); } //delete table try { tableServiceClient.deleteTable("OfficeSupplies"); } catch (TableServiceErrorException e) { - System.out.println("Delete Table Unsuccessful. Error: " + e); + logger.error("Delete Table Unsuccessful. Error: " + e); } //query tables @@ -45,7 +47,7 @@ public static void methods() { try { List responseTables = tableServiceClient.queryTables(queryOptions); } catch (HttpResponseException e) { - System.out.println("Table Query Unsuccessful. Error: " + e); + logger.error("Table Query Unsuccessful. Error: " + e); } //insert entity @@ -55,7 +57,7 @@ public static void methods() { try { tableEntity = tableClient.insertEntity(tableEntity); } catch (HttpResponseException e) { - System.out.println("Insert Entity Unsuccessful. Error: " + e); + logger.error("Insert Entity Unsuccessful. Error: " + e); } //update entity @@ -63,7 +65,7 @@ public static void methods() { try { tableClient.updateEntity(tableEntity); } catch (HttpResponseException e) { - System.out.println("Update Entity Unsuccessful. Error: " + e); + logger.error("Update Entity Unsuccessful. Error: " + e); } //upsert entity (where it is an insert or replace) @@ -71,7 +73,7 @@ public static void methods() { try { tableClient.insertOrReplaceEntity(tableEntity); } catch (HttpResponseException e) { - System.out.println("Upsert Entity Unsuccessful. Error: " + e); + logger.error("Upsert Entity Unsuccessful. Error: " + e); } //upsert entity (where it is an insert or merge) @@ -79,14 +81,14 @@ public static void methods() { try { tableClient.insertOrMergeEntity(tableEntity); } catch (HttpResponseException e) { - System.out.println("Upsert Entity Unsuccessful. Error: " + e); + logger.error("Upsert Entity Unsuccessful. Error: " + e); } //delete entity try { tableClient.deleteEntity(tableEntity); } catch (HttpResponseException e) { - System.out.println("Delete Entity Unsuccessful. Error: " + e); + logger.error("Delete Entity Unsuccessful. Error: " + e); } //query a table @@ -95,7 +97,7 @@ public static void methods() { try { List list = tableClient.queryEntity(queryOptions); } catch (HttpResponseException e) { - System.out.println("Query Table Entities Unsuccessful. Error: " + e); + logger.error("Query Table Entities Unsuccessful. Error: " + e); } } } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/package-info.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/package-info.java new file mode 100644 index 000000000000..42528acca50a --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/package-info.java @@ -0,0 +1,7 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +/** + * Package containing the classes for Tables Clients. + */ +package com.azure.data.tables; From 4ccbbc3adbb41fb9402c21dbc89144a0df5df32d Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 1 Jul 2020 13:51:46 -0400 Subject: [PATCH 31/42] move samples --- .../azure/data/tables/TableAsyncClient.java | 8 ++++ .../com/azure/data/tables/TableClient.java | 19 ++++++++ .../azure/data/tables/TableClientBuilder.java | 8 ++++ .../tables/TableServiceClientBuilder.java | 10 +++- .../TableServiceAsyncClientCodeSnippets.java | 46 +++++++++++++------ .../java}/TableServiceClientCodeSnippets.java | 6 ++- 6 files changed, 80 insertions(+), 17 deletions(-) rename sdk/tables/azure-data-tables/src/{main/java/com/azure/data/tables => samples/java}/TableServiceAsyncClientCodeSnippets.java (81%) rename sdk/tables/azure-data-tables/src/{main/java/com/azure/data/tables => samples/java}/TableServiceClientCodeSnippets.java (96%) 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 5c1c44ebe680..6b21e173bb82 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 @@ -102,4 +102,12 @@ public Mono insertOrReplaceEntity(TableEntity tableEntity) { public Mono insertOrMergeEntity(TableEntity tableEntity) { return Mono.empty(); } + + /** + * returns the table name associated with the client + * @return table name + */ + public Mono getTableName(){ + return Mono.empty(); + } } 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 be3874ecd69f..9d8f121c6ece 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 @@ -6,6 +6,7 @@ import java.util.List; import java.util.Map; +import reactor.core.publisher.Mono; /** * sync client for table operations @@ -59,6 +60,16 @@ public TableEntity insertEntity(TableEntity tableEntity) { public void deleteEntity(TableEntity tableEntity) { } + /** + * deletes the given entity + * + * @param partitionKey the partition key + * @param rowKey the row key + */ + public void deleteEntity(String partitionKey, String rowKey) { + } + + /** * merges the given entity with the entity which exists on the storage account * @@ -90,4 +101,12 @@ public void insertOrReplaceEntity(TableEntity tableEntity) { */ public void insertOrMergeEntity(TableEntity tableEntity) { } + + /** + * returns the table name associated with the client + * @return table name + */ + public String getTableName(){ + return this.tableName; + } } 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 220cae5c17c5..af3cf55989e5 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 @@ -55,4 +55,12 @@ public TableAsyncClient buildAsyncClient() { TableClientBuilder() { } + /** + * gets the connection string + * @return the connection string + */ + public String getConnectionString(){ + return this.connectionString; + } + } 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 922c32a33527..37f737912681 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 @@ -10,7 +10,7 @@ @ServiceClientBuilder(serviceClients = {TableServiceClient.class, TableServiceAsyncClient.class}) public class TableServiceClientBuilder { - String connectionString; + private String connectionString; /** * Sets the connection string to help build the client @@ -48,4 +48,12 @@ public TableServiceClientBuilder() { } + /** + * gets the connection string + * @return the connection string + */ + public String getConnectionString(){ + return this.connectionString; + } + } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java similarity index 81% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java rename to sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java index 2e9620c77f68..30b0d205bd82 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java @@ -11,7 +11,10 @@ public class TableServiceAsyncClientCodeSnippets { final ClientLogger logger = new ClientLogger("TableServiceAsyncClientCodeSnippets"); - private void methods() { + /** + * all methods on tables in the Tables SDK (Add, Delete, Query) + */ + public void TableLevelMethods() { // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() @@ -22,16 +25,16 @@ private void methods() { tableServiceAsyncClient.createTable("OfficeSupplies").subscribe(Void -> { logger.info("Table creation successful."); }, error -> { - logger.error("There was an error creating the table. Error: " + error); - }); + logger.error("There was an error creating the table. Error: " + error); + }); // Delete a table tableServiceAsyncClient.deleteTable("OfficeSupplies").subscribe(Void -> { logger.info("Table deletion successful"); }, error -> { - logger.error("There was an error deleting the table. Error: " + error); - }); + logger.error("There was an error deleting the table. Error: " + error); + }); // Query tables @@ -40,10 +43,13 @@ private void methods() { tableServiceAsyncClient.queryTables(queryOptions).subscribe(azureTable -> { logger.info(azureTable.getName()); }, error -> { - logger.error("There was an error querying the service. Error: " + error); - }); + logger.error("There was an error querying the service. Error: " + error); + }); } + /** + * insert entity code snippet + */ private void insertEntity() { // Build service client @@ -58,10 +64,13 @@ private void insertEntity() { tableAsyncClient.insertEntity(new TableEntity(row, partitionKey, null)).subscribe(tableEntity -> { logger.info("Insert Entity Successful. Entity: " + tableEntity); }, error -> { - logger.error("There was an error inserting the Entity. Error: " + error); - }); + logger.error("There was an error inserting the Entity. Error: " + error); + }); } + /** + * delete entity code snippet + */ private void deleteEntity() { // Build service client @@ -80,10 +89,13 @@ private void deleteEntity() { }).subscribe(Void -> { logger.info("Delete Entity Successful."); }, error -> { - logger.error("There was an error deleting the Entity. Error: " + error); - }); + logger.error("There was an error deleting the Entity. Error: " + error); + }); } + /** + * update entity code snippet + */ private void updateEntity() { // Build service client @@ -103,10 +115,13 @@ private void updateEntity() { }).subscribe(Void -> { logger.info("Update Entity Successful."); }, error -> { - logger.error("There was an error updating the Entity. Error: " + error); - }); + logger.error("There was an error updating the Entity. Error: " + error); + }); } + /** + * query entity code snippet + */ private void queryEntities() { // Build service client @@ -122,7 +137,8 @@ private void queryEntities() { tableAsyncClient.queryEntity(queryOptions).subscribe(tableEntity -> { logger.info("Table Entity: " + tableEntity); }, error -> { - logger.error("There was an error querying the table. Error: " + error); - }); + logger.error("There was an error querying the table. Error: " + error); + }); } + } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java b/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java similarity index 96% rename from sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java rename to sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java index 935ad4eb7017..113c7bb16d58 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java @@ -12,7 +12,10 @@ */ public class TableServiceClientCodeSnippets { - private static void methods() { + /** + * all the functionality of the Tables SDK written sync + */ + public static void methods() { ClientLogger logger = new ClientLogger("TableServiceClientCodeSnippets"); //create a tableServiceClient @@ -100,4 +103,5 @@ private static void methods() { logger.error("Query Table Entities Unsuccessful. Error: " + e); } } + } From 155024345924fd67e584d7e7cca9461d76c09aa6 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Wed, 1 Jul 2020 13:56:39 -0400 Subject: [PATCH 32/42] adding private to some local vars --- .../src/main/java/com/azure/data/tables/TableAsyncClient.java | 2 +- .../main/java/com/azure/data/tables/TableClientBuilder.java | 4 ++-- 2 files changed, 3 insertions(+), 3 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 6b21e173bb82..1923b3663096 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 @@ -15,7 +15,7 @@ builder = TableClientBuilder.class, isAsync = true) public class TableAsyncClient { - final String tableName; + private final String tableName; TableAsyncClient(String tableName) { this.tableName = tableName; 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 af3cf55989e5..886c673f7054 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 @@ -9,8 +9,8 @@ */ @ServiceClientBuilder(serviceClients = {TableClient.class, TableAsyncClient.class}) public class TableClientBuilder { - String connectionString; - String tableName; + private String connectionString; + private String tableName; /** * Sets the connection string to help build the client From f18d4ffb47ccfd450070b2766f237eb5715f728f Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 2 Jul 2020 12:23:20 -0400 Subject: [PATCH 33/42] switching code samples --- sdk/tables/azure-data-tables/pom.xml | 6 -- .../com/azure/data/tables/TableClient.java | 77 ++++++++----------- .../com/azure/data/tables/UpdateMode.java | 6 ++ 3 files changed, 38 insertions(+), 51 deletions(-) create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/UpdateMode.java diff --git a/sdk/tables/azure-data-tables/pom.xml b/sdk/tables/azure-data-tables/pom.xml index 242dd0054b3f..b1519f8b62c6 100644 --- a/sdk/tables/azure-data-tables/pom.xml +++ b/sdk/tables/azure-data-tables/pom.xml @@ -47,12 +47,6 @@ Licensed under the MIT License. azure-storage-common 12.7.0 - - com.azure - azure-core-test - 1.3.0 - test - org.junit.jupiter junit-jupiter-api 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 9d8f121c6ece..002dc0ab635c 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 @@ -4,6 +4,7 @@ import com.azure.core.annotation.ServiceClient; +import com.azure.data.tables.implementation.TablesImpl; import java.util.List; import java.util.Map; import reactor.core.publisher.Mono; @@ -30,26 +31,43 @@ public List queryEntity(QueryOptions queryOptions) { return null; } + /** - * insert a TableEntity with the given properties and return that TableEntity + * insert a TableEntity with the given properties and return that TableEntity. Property map must include + * rowKey and partitionKey * - * @param row the RowKey - * @param partition the PartitionKey * @param tableEntityProperties a map of properties for the TableEntity * @return the created TableEntity */ - public TableEntity insertEntity(String row, String partition, Map tableEntityProperties) { + public TableEntity createEntity(Map tableEntityProperties) throws Exception { + if (!tableEntityProperties.containsKey("PartitionKey")) { + throw new Exception("property map must contain PartitionKey as a key in key-value pair"); + } + if (!tableEntityProperties.containsKey("RowKey")) { + throw new Exception("property map must contain RowKey as a key in key-value pair"); + } + return new TableEntity(); + + //Questions: What spellings for those are accepted? What type of exception should be thrown? } - /** - * insert a new entity into the Table attached to this client - * - * @param tableEntity the entity in which to insert - * @return the inserted TableEntity - */ - public TableEntity insertEntity(TableEntity tableEntity) { - return tableEntity; + public void upsertEntity( UpdateMode updateMode, TableEntity tableEntity){ + if (updateMode.equals(UpdateMode.Merge)){ + //insert or merge if exists + } + if (updateMode.equals(UpdateMode.Replace)){ + //insert or replace if exists + } + } + + public void updateEntity( UpdateMode updateMode, TableEntity tableEntity) { + if (updateMode.equals(UpdateMode.Merge)){ + //update if exists, fails if entity does not exist + } + if (updateMode.equals(UpdateMode.Replace)){ + //replaces if exists, fails if entity does not exist + } } /** @@ -69,39 +87,6 @@ public void deleteEntity(TableEntity tableEntity) { public void deleteEntity(String partitionKey, String rowKey) { } - - /** - * merges the given entity with the entity which exists on the storage account - * - * @param tableEntity the entity with which to merge - */ - public void mergeEntity(TableEntity tableEntity) { - } - - /** - * updates the provided TableEntity - * - * @param tableEntity the TableEntity to update - */ - public void updateEntity(TableEntity tableEntity) { - } - - /** - * inserts the TableEntity if it doesn't exist or replace it if it does - * - * @param tableEntity the TableEntity to insert or replace - */ - public void insertOrReplaceEntity(TableEntity tableEntity) { - } - - /** - * inserts the TableEntity if it doesn't exist or merges it with the existing entity if it does - * - * @param tableEntity the TableEntity to insert or merge - */ - public void insertOrMergeEntity(TableEntity tableEntity) { - } - /** * returns the table name associated with the client * @return table name @@ -109,4 +94,6 @@ public void insertOrMergeEntity(TableEntity tableEntity) { public String getTableName(){ return this.tableName; } + + } 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/UpdateMode.java new file mode 100644 index 000000000000..c0a5f3d06181 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/UpdateMode.java @@ -0,0 +1,6 @@ +package com.azure.data.tables; + +enum UpdateMode { + Merge, + Replace +} From 6e725d874c8969b501d45d5dcb67ec86192214ba Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 2 Jul 2020 13:52:46 -0400 Subject: [PATCH 34/42] switch to create, update, upsert --- .../azure/data/tables/TableAsyncClient.java | 68 +++++++------------ .../com/azure/data/tables/TableClient.java | 47 +++++-------- .../azure/data/tables/TableClientBuilder.java | 2 +- .../com/azure/data/tables/TableEntity.java | 9 +-- .../tables/TableServiceClientBuilder.java | 2 +- .../com/azure/data/tables/UpdateMode.java | 2 + .../TableServiceAsyncClientCodeSnippets.java | 39 +++++++++-- .../java/TableServiceClientCodeSnippets.java | 25 +++---- 8 files changed, 93 insertions(+), 101 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 1923b3663096..4108614c961a 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 @@ -4,9 +4,8 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.http.rest.PagedFlux; -import reactor.core.publisher.Mono; - import java.util.Map; +import reactor.core.publisher.Mono; /** * class for the table async client @@ -32,82 +31,65 @@ public PagedFlux queryEntity(QueryOptions queryOptions) { } /** - * insert a TableEntity with the given properties and return that TableEntity + * insert a TableEntity with the given properties and return that TableEntity. Property map must include + * rowKey and partitionKey * - * @param row the RowKey - * @param partition the PartitionKey * @param tableEntityProperties a map of properties for the TableEntity * @return the created TableEntity */ - public Mono insertEntity(String row, String partition, Map tableEntityProperties) { - return null; - } - - /** - * insert a new entity into the Table attached to this client - * - * @param tableEntity the entity in which to insert - * @return the inserted TableEntity - */ - public Mono insertEntity(TableEntity tableEntity) { - return null; - } - - /** - * deletes the given entity - * - * @param tableEntity entity to delete - * @return a mono void - */ - public Mono deleteEntity(TableEntity tableEntity) { + public Mono createEntity(Map tableEntityProperties) { return Mono.empty(); } /** - * updates the provided TableEntity + * based on Mode it either inserts or merges if exists or inserts or merges if exists * - * @param tableEntity the TableEntity to update - * @return a mono void + * @param updateMode type of upsert + * @param tableEntity entity to upsert + * @return void */ - public Mono updateEntity(TableEntity tableEntity) { + public Mono upsertEntity(UpdateMode updateMode, TableEntity tableEntity) { return Mono.empty(); } /** - * merges the given entity with the entity which exists on the storage account + * based on Mode it either updates or fails if it does exists or replaces or fails if it does exists * - * @param tableEntity the entity with which to merge - * @return a mono void + * @param updateMode type of update + * @param tableEntity entity to update + * @return void */ - public Mono mergeEntity(TableEntity tableEntity) { + public Mono updateEntity(UpdateMode updateMode, TableEntity tableEntity) { return Mono.empty(); } /** - * inserts the TableEntity if it doesn't exist or replace it if it does + * deletes the given entity * - * @param tableEntity the TableEntity to insert or replace - * @return a mono void + * @param tableEntity entity to delete + * @return void */ - public Mono insertOrReplaceEntity(TableEntity tableEntity) { + public Mono deleteEntity(TableEntity tableEntity) { return Mono.empty(); } /** - * inserts the TableEntity if it doesn't exist or merges it with the existing entity if it does + * deletes the given entity * - * @param tableEntity the TableEntity to insert or merge - * @return a mono void + * @param partitionKey the partition key + * @param rowKey the row key + * @return void */ - public Mono insertOrMergeEntity(TableEntity tableEntity) { + public Mono deleteEntity(String partitionKey, String rowKey) { return Mono.empty(); } /** * returns the table name associated with the client + * * @return table name */ - public Mono getTableName(){ + public Mono getTableName() { return Mono.empty(); } } 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 002dc0ab635c..f507b8300155 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 @@ -3,11 +3,8 @@ package com.azure.data.tables; import com.azure.core.annotation.ServiceClient; - -import com.azure.data.tables.implementation.TablesImpl; import java.util.List; import java.util.Map; -import reactor.core.publisher.Mono; /** * sync client for table operations @@ -39,35 +36,26 @@ public List queryEntity(QueryOptions queryOptions) { * @param tableEntityProperties a map of properties for the TableEntity * @return the created TableEntity */ - public TableEntity createEntity(Map tableEntityProperties) throws Exception { - if (!tableEntityProperties.containsKey("PartitionKey")) { - throw new Exception("property map must contain PartitionKey as a key in key-value pair"); - } - if (!tableEntityProperties.containsKey("RowKey")) { - throw new Exception("property map must contain RowKey as a key in key-value pair"); - } - - return new TableEntity(); - - //Questions: What spellings for those are accepted? What type of exception should be thrown? + public TableEntity createEntity(Map tableEntityProperties) { + return null; } - public void upsertEntity( UpdateMode updateMode, TableEntity tableEntity){ - if (updateMode.equals(UpdateMode.Merge)){ - //insert or merge if exists - } - if (updateMode.equals(UpdateMode.Replace)){ - //insert or replace if exists - } + /** + * based on Mode it either inserts or merges if exists or inserts or merges if exists + * + * @param updateMode type of upsert + * @param tableEntity entity to upsert + */ + public void upsertEntity(UpdateMode updateMode, TableEntity tableEntity) { } - public void updateEntity( UpdateMode updateMode, TableEntity tableEntity) { - if (updateMode.equals(UpdateMode.Merge)){ - //update if exists, fails if entity does not exist - } - if (updateMode.equals(UpdateMode.Replace)){ - //replaces if exists, fails if entity does not exist - } + /** + * based on Mode it either updates or fails if it does exists or replaces or fails if it does exists + * + * @param updateMode type of update + * @param tableEntity entity to update + */ + public void updateEntity(UpdateMode updateMode, TableEntity tableEntity) { } /** @@ -89,9 +77,10 @@ public void deleteEntity(String partitionKey, String rowKey) { /** * returns the table name associated with the client + * * @return table name */ - public String getTableName(){ + public String getTableName() { return this.tableName; } 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 886c673f7054..f4374042bc57 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 @@ -59,7 +59,7 @@ public TableAsyncClient buildAsyncClient() { * gets the connection string * @return the connection string */ - public String getConnectionString(){ + public String getConnectionString() { return this.connectionString; } 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 index 0f00ed50d937..7512340af7ab 100644 --- 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 @@ -10,18 +10,12 @@ public class TableEntity { private Map properties; - TableEntity() { - } - /** * creates a new TableEntity * - * @param rowKey rowKey - * @param partitionKey partitionKey * @param properties map of properties of the entity */ - TableEntity(String rowKey, String partitionKey, Map properties) { - this.properties = properties; + public TableEntity(Map properties) { } /** @@ -45,6 +39,7 @@ public void addProperty(String key, Object value) { /** * set the properties + * * @param properties properties to set to this entity */ public void setProperties(Map properties) { 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 37f737912681..63e14b5b3482 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 @@ -52,7 +52,7 @@ public TableServiceClientBuilder() { * gets the connection string * @return the connection string */ - public String getConnectionString(){ + public String getConnectionString() { return this.connectionString; } 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/UpdateMode.java index c0a5f3d06181..c704ce3f557f 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/UpdateMode.java @@ -1,3 +1,5 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. package com.azure.data.tables; enum UpdateMode { 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 30b0d205bd82..999218baec9b 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java @@ -3,6 +3,8 @@ package com.azure.data.tables; import com.azure.core.util.logging.ClientLogger; +import java.util.HashMap; +import java.util.Map; import reactor.core.publisher.Mono; /** @@ -58,10 +60,11 @@ private void insertEntity() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); - String row = "crayolaMarkers"; - String partitionKey = "markers"; + Map properties = new HashMap<>(); + properties.put("RowKey", "crayolaMarkers"); + properties.put("PartitionKey", "markers"); - tableAsyncClient.insertEntity(new TableEntity(row, partitionKey, null)).subscribe(tableEntity -> { + tableAsyncClient.createEntity(properties).subscribe(tableEntity -> { logger.info("Insert Entity Successful. Entity: " + tableEntity); }, error -> { logger.error("There was an error inserting the Entity. Error: " + error); @@ -93,10 +96,36 @@ private void deleteEntity() { }); } + /** + * upsert entity code snippet + */ + private void upsert() { + + // Build service client + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() + .connectionString("connectionString") + .buildAsyncClient(); + + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); + QueryOptions queryOptions = new QueryOptions(); + queryOptions.setFilter("RowKey eq crayolaMarkers"); + + tableAsyncClient.queryEntity(queryOptions).flatMap(tableEntity -> { + logger.info("Table Entity: " + tableEntity); + tableEntity.addProperty("Price", "5"); + Mono updateEntityMono = tableAsyncClient.upsertEntity(UpdateMode.Merge, tableEntity); + return updateEntityMono; + }).subscribe(Void -> { + logger.info("Update Entity Successful."); + }, error -> { + logger.error("There was an error updating the Entity. Error: " + error); + }); + } + /** * update entity code snippet */ - private void updateEntity() { + private void update() { // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() @@ -110,7 +139,7 @@ private void updateEntity() { tableAsyncClient.queryEntity(queryOptions).flatMap(tableEntity -> { logger.info("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); - Mono updateEntityMono = tableAsyncClient.updateEntity(tableEntity); + Mono updateEntityMono = tableAsyncClient.upsertEntity(UpdateMode.Replace, tableEntity); return updateEntityMono; }).subscribe(Void -> { logger.info("Update Entity Successful."); 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 113c7bb16d58..96368a3409c8 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java @@ -5,7 +5,9 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.util.logging.ClientLogger; import com.azure.data.tables.implementation.models.TableServiceErrorException; +import java.util.HashMap; import java.util.List; +import java.util.Map; /** * sync code snippets for the table service @@ -54,11 +56,12 @@ public static void methods() { } //insert entity - String row = "crayola markers"; - String partitionKey = "markers"; - TableEntity tableEntity = new TableEntity(row, partitionKey, null); + Map properties = new HashMap<>(); + properties.put("RowKey", "crayolaMarkers"); + properties.put("PartitionKey", "markers"); + TableEntity tableEntity = null; try { - tableEntity = tableClient.insertEntity(tableEntity); + tableEntity = tableClient.createEntity(properties); } catch (HttpResponseException e) { logger.error("Insert Entity Unsuccessful. Error: " + e); } @@ -66,23 +69,15 @@ public static void methods() { //update entity tableEntity.addProperty("Seller", "Crayola"); try { - tableClient.updateEntity(tableEntity); + tableClient.updateEntity(UpdateMode.Replace, tableEntity); } catch (HttpResponseException e) { logger.error("Update Entity Unsuccessful. Error: " + e); } - //upsert entity (where it is an insert or replace) + //upsert entity tableEntity.addProperty("Price", "5"); try { - tableClient.insertOrReplaceEntity(tableEntity); - } catch (HttpResponseException e) { - logger.error("Upsert Entity Unsuccessful. Error: " + e); - } - - //upsert entity (where it is an insert or merge) - tableEntity.addProperty("Price", "5"); - try { - tableClient.insertOrMergeEntity(tableEntity); + tableClient.upsertEntity(UpdateMode.Replace, tableEntity); } catch (HttpResponseException e) { logger.error("Upsert Entity Unsuccessful. Error: " + e); } From 68a3d3f2fd077f074e42cf36baef2e2563de7098 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 6 Jul 2020 10:22:58 -0400 Subject: [PATCH 35/42] additional changes --- .../src/main/java/com/azure/data/tables/TableEntity.java | 2 ++ .../src/samples/java/TableServiceAsyncClientCodeSnippets.java | 2 +- 2 files changed, 3 insertions(+), 1 deletion(-) 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 index 7512340af7ab..7d2997277435 100644 --- 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 @@ -9,6 +9,8 @@ */ public class TableEntity { private Map properties; + //tableName + //etag /** * creates a new TableEntity 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 999218baec9b..00e1cfaffab5 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java @@ -139,7 +139,7 @@ private void update() { tableAsyncClient.queryEntity(queryOptions).flatMap(tableEntity -> { logger.info("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); - Mono updateEntityMono = tableAsyncClient.upsertEntity(UpdateMode.Replace, tableEntity); + Mono updateEntityMono = tableAsyncClient.updateEntity(UpdateMode.Replace, tableEntity); return updateEntityMono; }).subscribe(Void -> { logger.info("Update Entity Successful."); From 773eb7f68ce9104f5b55e4463828b2530c9b9bef Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Mon, 6 Jul 2020 12:38:48 -0400 Subject: [PATCH 36/42] edits based on comments --- .../azure/data/tables/TableAsyncClient.java | 12 ++ .../com/azure/data/tables/TableClient.java | 11 ++ .../azure/data/tables/TableClientBuilder.java | 5 +- .../data/tables/TableServiceAsyncClient.java | 16 +- .../azure/data/tables/TableServiceClient.java | 9 + .../TableServiceAsyncClientCodeSnippets.java | 57 ++++-- .../java/TableServiceClientCodeSnippets.java | 167 ++++++++++++++---- 7 files changed, 220 insertions(+), 57 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 4108614c961a..afe2c4c77f5e 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 @@ -4,6 +4,7 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.http.rest.PagedFlux; +import java.util.List; import java.util.Map; import reactor.core.publisher.Mono; @@ -30,6 +31,17 @@ public PagedFlux queryEntity(QueryOptions queryOptions) { return null; } + /** + * Queries and returns entities in the given table with the given rowKey and ParitionKey + * + * @param rowKey the given row key + * @param partitionKey the given partition key + * @return a list of the tables that fit the row and partition key + */ + public PagedFlux queryEntitiesWithPartitionAndRowKey(String rowKey, String partitionKey) { + return null; + } + /** * insert a TableEntity with the given properties and return that TableEntity. Property map must include * rowKey and partitionKey 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 f507b8300155..acaf6cee84d3 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 @@ -28,6 +28,17 @@ public List queryEntity(QueryOptions queryOptions) { return null; } + /** + * Queries and returns entities in the given table with the given rowKey and ParitionKey + * + * @param rowKey the given row key + * @param partitionKey the given partition key + * @return a list of the tables that fit the row and partition key + */ + public List queryEntitiesWithPartitionAndRowKey(String rowKey, String partitionKey) { + return null; + } + /** * insert a TableEntity with the given properties and return that TableEntity. Property map must include 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 f4374042bc57..eeaf7997fe9d 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 @@ -52,7 +52,10 @@ public TableAsyncClient buildAsyncClient() { return new TableAsyncClient(tableName); } - TableClientBuilder() { + /** + * table client builder constructor + */ + public TableClientBuilder() { } /** 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 aded42e045e9..bc4dac36d2c9 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 @@ -48,12 +48,12 @@ public Mono deleteTable(AzureTable azureTable) { } /** - * retrieves the table client for the provided table or creates one if it doesn't exist + * retrieves the async table client for the provided table or creates one if it doesn't exist * * @param name the name of the table - * @return associated TableClient + * @return associated TableAsyncClient */ - public Mono getTableClient(String name) { + public TableAsyncClient getTableAsyncClient(String name) { return null; } @@ -67,14 +67,4 @@ public PagedFlux queryTables(QueryOptions queryOptions) { return null; } - - /** - * gets the client for this table - * - * @param tableName the table to get the client from - * @return the table client - */ - public TableAsyncClient getClient(String tableName) { - return null; - } } 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 2dfe7e693220..8bca972d9156 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 @@ -52,6 +52,15 @@ public AzureTable getTable(String name) { return null; } + /** + * gets the Table Client for the given table + * @param name the name of the table + * @return the Table Client for the table + */ + public TableClient getTableClient(String name) { + return null; + } + /** * query all the tables under the storage account and return them * 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 00e1cfaffab5..6ad76075fc1e 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java @@ -14,34 +14,45 @@ public class TableServiceAsyncClientCodeSnippets { final ClientLogger logger = new ClientLogger("TableServiceAsyncClientCodeSnippets"); /** - * all methods on tables in the Tables SDK (Add, Delete, Query) + * create table code snippet */ - public void TableLevelMethods() { - - // Build service client + public void createTable() { TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") .buildAsyncClient(); - // Add a table tableServiceAsyncClient.createTable("OfficeSupplies").subscribe(Void -> { logger.info("Table creation successful."); }, error -> { logger.error("There was an error creating the table. Error: " + error); }); + } + /** + * delete table code snippet + */ + public void deleteTable() { + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() + .connectionString("connectionString") + .buildAsyncClient(); - // Delete a table tableServiceAsyncClient.deleteTable("OfficeSupplies").subscribe(Void -> { logger.info("Table deletion successful"); }, error -> { logger.error("There was an error deleting the table. Error: " + error); }); + } - - // Query tables + /** + * query tables code snippet + */ + public void queryTable() { + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() + .connectionString("connectionString") + .buildAsyncClient(); QueryOptions queryOptions = new QueryOptions(); queryOptions.setFilter("TableName eq OfficeSupplies"); + tableServiceAsyncClient.queryTables(queryOptions).subscribe(azureTable -> { logger.info(azureTable.getName()); }, error -> { @@ -59,7 +70,7 @@ private void insertEntity() { .connectionString("connectionString") .buildAsyncClient(); - TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); Map properties = new HashMap<>(); properties.put("RowKey", "crayolaMarkers"); properties.put("PartitionKey", "markers"); @@ -81,7 +92,7 @@ private void deleteEntity() { .connectionString("connectionString") .buildAsyncClient(); - TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); QueryOptions queryOptions = new QueryOptions(); queryOptions.setFilter("RowKey eq crayolaMarkers"); @@ -106,7 +117,7 @@ private void upsert() { .connectionString("connectionString") .buildAsyncClient(); - TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); QueryOptions queryOptions = new QueryOptions(); queryOptions.setFilter("RowKey eq crayolaMarkers"); @@ -132,7 +143,7 @@ private void update() { .connectionString("connectionString") .buildAsyncClient(); - TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); QueryOptions queryOptions = new QueryOptions(); queryOptions.setFilter("RowKey eq crayolaMarkers"); @@ -158,7 +169,7 @@ private void queryEntities() { .connectionString("connectionString") .buildAsyncClient(); - TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getClient("OfficeSupplies"); + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); QueryOptions queryOptions = new QueryOptions(); queryOptions.setFilter("Product eq markers"); queryOptions.setSelect("Seller, Price"); @@ -170,4 +181,24 @@ private void queryEntities() { }); } + /** + * checks to see if an entity exists code snippet + */ + private void existsEntity() { + + // Build service client + TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() + .connectionString("connectionString") + .buildAsyncClient(); + + TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); + + tableAsyncClient.queryEntitiesWithPartitionAndRowKey("crayolaMarkers", "markers") + .subscribe(tableEntity -> { + logger.info("Table Entity exists: " + tableEntity); + }, error -> { + logger.error("There was an error querying the table. Error: " + error); + }); + } + } 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 96368a3409c8..86c71e31e51a 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java @@ -13,39 +13,46 @@ * sync code snippets for the table service */ public class TableServiceClientCodeSnippets { + private final ClientLogger logger = new ClientLogger("TableServiceClientCodeSnippets"); /** - * all the functionality of the Tables SDK written sync + * create table code snippet */ - public static void methods() { - ClientLogger logger = new ClientLogger("TableServiceClientCodeSnippets"); - - //create a tableServiceClient + public void createTable() { TableServiceClient tableServiceClient = new TableServiceClientBuilder() .connectionString("connectionString") .buildClient(); - //create TableClient - TableClient tableClient = new TableClientBuilder() - .connectionString("connectionString") - .tableName("OfficeSupplies") - .buildClient(); - - //create a table try { AzureTable officeSuppliesTable = tableServiceClient.createTable("OfficeSupplies"); } catch (TableServiceErrorException e) { logger.error("Create Table Unsuccessful. Error: " + e); } + } + + /** + * delete table code snippet + */ + public void deleteTable() { + TableServiceClient tableServiceClient = new TableServiceClientBuilder() + .connectionString("connectionString") + .buildClient(); - //delete table try { tableServiceClient.deleteTable("OfficeSupplies"); } catch (TableServiceErrorException e) { logger.error("Delete Table Unsuccessful. Error: " + e); } + } + + /** + * query table code snippet + */ + public void queryTables() { + TableServiceClient tableServiceClient = new TableServiceClientBuilder() + .connectionString("connectionString") + .buildClient(); - //query tables QueryOptions queryOptions = new QueryOptions(); queryOptions.setFilter("TableName eq OfficeSupplies"); @@ -54,49 +61,149 @@ public static void methods() { } catch (HttpResponseException e) { logger.error("Table Query Unsuccessful. Error: " + e); } + } + + /** + * insert entity code snippet + */ + private void insertEntity() { + TableClient tableClient = new TableClientBuilder() + .connectionString("connectionString") + .tableName("OfficeSupplies") + .buildClient(); - //insert entity Map properties = new HashMap<>(); properties.put("RowKey", "crayolaMarkers"); properties.put("PartitionKey", "markers"); - TableEntity tableEntity = null; try { - tableEntity = tableClient.createEntity(properties); + TableEntity tableEntity = tableClient.createEntity(properties); } catch (HttpResponseException e) { logger.error("Insert Entity Unsuccessful. Error: " + e); } + } - //update entity - tableEntity.addProperty("Seller", "Crayola"); + /** + * update entity code snippet + */ + private void updateEntity() { + TableClient tableClient = new TableClientBuilder() + .connectionString("connectionString") + .tableName("OfficeSupplies") + .buildClient(); + + QueryOptions queryOptions = new QueryOptions(); + queryOptions.setFilter("RowKey eq crayolaMarkers"); + List tableEntities = null; try { - tableClient.updateEntity(UpdateMode.Replace, tableEntity); + tableEntities = tableClient.queryEntity(queryOptions); } catch (HttpResponseException e) { - logger.error("Update Entity Unsuccessful. Error: " + e); + logger.error("Query Table Entities Unsuccessful. Error: " + e); } + if (tableEntities != null) { + TableEntity tableEntity = tableEntities.get(0); + tableEntity.addProperty("Seller", "Crayola"); + try { + tableClient.updateEntity(UpdateMode.Replace, tableEntity); + } catch (HttpResponseException e) { + logger.error("Update Entity Unsuccessful. Error: " + e); + } + } + } - //upsert entity - tableEntity.addProperty("Price", "5"); + /** + * upsert entity code snippet + */ + private void upsertEntity() { + TableClient tableClient = new TableClientBuilder() + .connectionString("connectionString") + .tableName("OfficeSupplies") + .buildClient(); + + QueryOptions queryOptions = new QueryOptions(); + queryOptions.setFilter("RowKey eq crayolaMarkers"); + List tableEntities = null; try { - tableClient.upsertEntity(UpdateMode.Replace, tableEntity); + tableEntities = tableClient.queryEntity(queryOptions); } catch (HttpResponseException e) { - logger.error("Upsert Entity Unsuccessful. Error: " + e); + logger.error("Query Table Entities Unsuccessful. Error: " + e); } + if (tableEntities != null) { + TableEntity tableEntity = tableEntities.get(0); + tableEntity.addProperty("Price", "5"); + try { + tableClient.upsertEntity(UpdateMode.Replace, tableEntity); + } catch (HttpResponseException e) { + logger.error("Upsert Entity Unsuccessful. Error: " + e); + } + } + } - //delete entity + /** + * delete entity code snippet + */ + private void deleteEntity() { + TableClient tableClient = new TableClientBuilder() + .connectionString("connectionString") + .tableName("OfficeSupplies") + .buildClient(); + + QueryOptions queryOptions = new QueryOptions(); + queryOptions.setFilter("RowKey eq crayolaMarkers"); + List tableEntities = null; try { - tableClient.deleteEntity(tableEntity); + tableEntities = tableClient.queryEntity(queryOptions); } catch (HttpResponseException e) { - logger.error("Delete Entity Unsuccessful. Error: " + e); + logger.error("Query Table Entities Unsuccessful. Error: " + e); + } + if (tableEntities != null) { + TableEntity tableEntity = tableEntities.get(0); + try { + tableClient.deleteEntity(tableEntity); + } catch (HttpResponseException e) { + logger.error("Delete Entity Unsuccessful. Error: " + e); + } } + } + + /** + * query entity code snippet + */ + private void queryEntity() { + TableClient tableClient = new TableClientBuilder() + .connectionString("connectionString") + .tableName("OfficeSupplies") + .buildClient(); - //query a table + QueryOptions queryOptions = new QueryOptions(); queryOptions.setFilter("Product eq markers"); queryOptions.setSelect("Seller, Price"); try { - List list = tableClient.queryEntity(queryOptions); + List tableEntities = tableClient.queryEntity(queryOptions); } catch (HttpResponseException e) { logger.error("Query Table Entities Unsuccessful. Error: " + e); } } + /** + * check to see if a table entity exists + */ + public void entityExists() { + TableClient tableClient = new TableClientBuilder() + .connectionString("connectionString") + .tableName("OfficeSupplies") + .buildClient(); + + QueryOptions queryOptions = new QueryOptions(); + queryOptions.setFilter("TableName eq OfficeSupplies"); + try { + List responseTables = + tableClient.queryEntitiesWithPartitionAndRowKey("crayolaMarkers", "markers"); + if (responseTables != null && responseTables.get(0) != null) { + logger.info("Entity with the rowKey = crayolaMarkers and partitionKey = markers exists."); + } + } catch (HttpResponseException e) { + logger.error("Table Query Unsuccessful. Error: " + e); + } + + } } From c763ac9daa2ed13b3f83cb1e4d6e9171e20ddeb1 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 9 Jul 2020 10:21:53 -0400 Subject: [PATCH 37/42] Edits based on comments --- .../azure/data/tables/TableAsyncClient.java | 8 +- .../com/azure/data/tables/TableClient.java | 8 +- .../azure/data/tables/TableClientBuilder.java | 13 +++ .../tables/TableServiceClientBuilder.java | 107 +++++++++++++++++- .../data/tables/TablesServiceVersion.java | 35 ++++++ .../TableServiceAsyncClientCodeSnippets.java | 24 ++-- .../java/TableServiceClientCodeSnippets.java | 85 ++++++-------- 7 files changed, 208 insertions(+), 72 deletions(-) create mode 100644 sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesServiceVersion.java 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 afe2c4c77f5e..a13763d2e3f2 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 @@ -27,18 +27,18 @@ public class TableAsyncClient { * @param queryOptions the odata query object * @return a paged flux of all the entity which fit this criteria */ - public PagedFlux queryEntity(QueryOptions queryOptions) { + public PagedFlux queryEntities(QueryOptions queryOptions) { return null; } /** - * Queries and returns entities in the given table with the given rowKey and ParitionKey + * returns the entity with the given rowKey and ParitionKey * * @param rowKey the given row key * @param partitionKey the given partition key - * @return a list of the tables that fit the row and partition key + * @return an entity that fits the criteria */ - public PagedFlux queryEntitiesWithPartitionAndRowKey(String rowKey, String partitionKey) { + public Mono get(String rowKey, String partitionKey) { return null; } 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 acaf6cee84d3..6eabb5e67b87 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 @@ -24,18 +24,18 @@ public class TableClient { * @param queryOptions the odata query object * @return a list of the tables that fit the query */ - public List queryEntity(QueryOptions queryOptions) { + public List queryEntities(QueryOptions queryOptions) { return null; } /** - * Queries and returns entities in the given table with the given rowKey and ParitionKey + * returns the entity with the given rowKey and ParitionKey * * @param rowKey the given row key * @param partitionKey the given partition key - * @return a list of the tables that fit the row and partition key + * @return an entity that fits the criteria */ - public List queryEntitiesWithPartitionAndRowKey(String rowKey, String partitionKey) { + public TableEntity get(String rowKey, String partitionKey) { return null; } 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 eeaf7997fe9d..c72933e8a333 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 @@ -3,6 +3,7 @@ package com.azure.data.tables; import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.credential.TokenCredential; /** * builds table client @@ -11,6 +12,7 @@ public class TableClientBuilder { private String connectionString; private String tableName; + private TokenCredential tokenCredential; /** * Sets the connection string to help build the client @@ -23,6 +25,17 @@ public TableClientBuilder connectionString(String connectionString) { return this; } + /** + * Sets the tokenCredential to help build the client + * + * @param tokenCredential the tokenCredential to the storage account + * @return the TableClientBuilder + */ + public TableClientBuilder connectionString(TokenCredential tokenCredential) { + this.tokenCredential = tokenCredential; + return this; + } + /** * Sets the table name to help build the client * 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 63e14b5b3482..285033ef25f6 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 @@ -3,14 +3,29 @@ package com.azure.data.tables; import com.azure.core.annotation.ServiceClientBuilder; +import com.azure.core.http.HttpClient; +import com.azure.core.http.policy.HttpLogOptions; +import com.azure.core.http.policy.HttpPipelinePolicy; +import com.azure.core.util.logging.ClientLogger; +import java.util.ArrayList; +import java.util.List; +import com.azure.core.util.Configuration; +import java.util.Objects; /** * builds the table service clients */ @ServiceClientBuilder(serviceClients = {TableServiceClient.class, TableServiceAsyncClient.class}) public class TableServiceClientBuilder { - + private final ClientLogger logger = new ClientLogger(TableServiceClientBuilder.class); + private final List additionalPolicies = new ArrayList<>(); private String connectionString; + private Configuration configuration; + private TablesSharedKeyCredential tablesSharedKeyCredential; + private String endpoint; + private HttpClient httpClient; + private HttpLogOptions logOptions; + private TablesServiceVersion version; /** * Sets the connection string to help build the client @@ -56,4 +71,94 @@ public String getConnectionString() { return this.connectionString; } + /** + * Sets the configuration object used to retrieve environment configuration values during building of the client. + * + * @param configuration Configuration store used to retrieve environment configurations. + * @return the updated TableServiceClientBuilder object + */ + public TableServiceClientBuilder configuration(Configuration configuration) { + this.configuration = configuration; + return this; + } + + /** + * update credential + * @param credential the tables shared key credential + * @return the updated TableServiceClient builder + * @throws NullPointerException If {@code credential} is {@code null}. + */ + public TableServiceClientBuilder credential(TablesSharedKeyCredential credential) { + this.tablesSharedKeyCredential = Objects.requireNonNull(tablesSharedKeyCredential, "credential cannot" + + "be null"); + return this; + } + + /** + * Sets the table service endpoint + * + * @param endpoint URL of the service + * @return the updated TableServiceClientBuilder object + */ + public TableServiceClientBuilder endpoint(String endpoint) { + this.endpoint = endpoint; + return this; + } + + /** + * Sets the {@link HttpClient} to use for sending a receiving requests to and from the service. + * + * @param httpClient HttpClient to use for requests. + * @return the updated TableServiceClientBuilder object + */ + public TableServiceClientBuilder httpClient(HttpClient httpClient) { + if (this.httpClient != null && httpClient == null) { + logger.info("'httpClient' is being set to 'null' when it was previously configured."); + } + this.httpClient = httpClient; + return this; + } + + /** + * Sets the {@link HttpLogOptions} for service requests. + * + * @param logOptions The logging configuration to use when sending and receiving HTTP requests/responses. + * @return the updated TableServiceClientBuilder object + * @throws NullPointerException If {@code logOptions} is {@code null}. + */ + public TableServiceClientBuilder httpLogOptions(HttpLogOptions logOptions) { + this.logOptions = Objects.requireNonNull(logOptions, "'logOptions' cannot be null."); + return this; + } + + /** + * Adds a pipeline policy to apply on each request sent. The policy will be added after the retry policy. If + * the method is called multiple times, all policies will be added and their order preserved. + * + * @param pipelinePolicy a pipeline policy + * @return the updated TableServiceClientBuilder object + * @throws NullPointerException If {@code pipelinePolicy} is {@code null}. + */ + public TableServiceClientBuilder addPolicy(HttpPipelinePolicy pipelinePolicy) { + this.additionalPolicies.add(Objects.requireNonNull(pipelinePolicy, "'pipelinePolicy' cannot be null")); + return this; + } + + /** + * Sets the TablesServiceVersion that is used when making API requests. + *

+ * If a service version is not provided, the service version that will be used will be the latest known service + * version based on the version of the client library being used. If no service version is specified, updating to a + * newer version of the client library will have the result of potentially moving to a newer service version. + *

+ * Targeting a specific service version may also mean that the service will return an error for newer APIs. + * + * @param version {@link TablesServiceVersion} of the service to be used when making requests. + * @return the updated TableServiceClientBuilder object + */ + public TableServiceClientBuilder serviceVersion(TablesServiceVersion version) { + this.version = version; + return this; + } + } diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesServiceVersion.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesServiceVersion.java new file mode 100644 index 000000000000..6deb608f8cc4 --- /dev/null +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/TablesServiceVersion.java @@ -0,0 +1,35 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. +package com.azure.data.tables; + +import com.azure.core.util.ServiceVersion; + +/** + * The versions of Azure Storage Tables supported by this client library. + */ +public enum TablesServiceVersion implements ServiceVersion { + V2019_02_02("no yet implemented"); + private final String version; + + TablesServiceVersion(String version) { + this.version = version; + } + + /** + * {@inheritDoc} + */ + @Override + public String getVersion() { + return this.version; + } + + /** + * Gets the latest service version supported by this client library + * + * @return the latest TablesServiceVersion + */ + public static TablesServiceVersion getLatest() { + return V2019_02_02; + } + +} 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 6ad76075fc1e..24413b9f4134 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java @@ -93,10 +93,10 @@ private void deleteEntity() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("RowKey eq crayolaMarkers"); + String rowKey = "crayolaMarkers"; + String partitionKey = "markers"; - tableAsyncClient.queryEntity(queryOptions).flatMap(tableEntity -> { + tableAsyncClient.get(rowKey, partitionKey).flatMap(tableEntity -> { logger.info("Table Entity: " + tableEntity); Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity); return deleteEntityMono; @@ -118,10 +118,10 @@ private void upsert() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("RowKey eq crayolaMarkers"); + String rowKey = "crayolaMarkers"; + String partitionKey = "markers"; - tableAsyncClient.queryEntity(queryOptions).flatMap(tableEntity -> { + tableAsyncClient.get(rowKey, partitionKey).flatMap(tableEntity -> { logger.info("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); Mono updateEntityMono = tableAsyncClient.upsertEntity(UpdateMode.Merge, tableEntity); @@ -144,10 +144,10 @@ private void update() { .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("RowKey eq crayolaMarkers"); + String rowKey = "crayolaMarkers"; + String partitionKey = "markers"; - tableAsyncClient.queryEntity(queryOptions).flatMap(tableEntity -> { + tableAsyncClient.get(rowKey, partitionKey).flatMap(tableEntity -> { logger.info("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); Mono updateEntityMono = tableAsyncClient.updateEntity(UpdateMode.Replace, tableEntity); @@ -174,7 +174,7 @@ private void queryEntities() { queryOptions.setFilter("Product eq markers"); queryOptions.setSelect("Seller, Price"); - tableAsyncClient.queryEntity(queryOptions).subscribe(tableEntity -> { + tableAsyncClient.queryEntities(queryOptions).subscribe(tableEntity -> { logger.info("Table Entity: " + tableEntity); }, error -> { logger.error("There was an error querying the table. Error: " + error); @@ -193,11 +193,11 @@ private void existsEntity() { TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); - tableAsyncClient.queryEntitiesWithPartitionAndRowKey("crayolaMarkers", "markers") + tableAsyncClient.get("crayolaMarkers", "markers") .subscribe(tableEntity -> { logger.info("Table Entity exists: " + tableEntity); }, error -> { - logger.error("There was an error querying the table. Error: " + error); + logger.error("There was an error getting the entity. Error: " + error); }); } 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 86c71e31e51a..15ff60c11dd2 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java @@ -4,7 +4,6 @@ import com.azure.core.exception.HttpResponseException; import com.azure.core.util.logging.ClientLogger; -import com.azure.data.tables.implementation.models.TableServiceErrorException; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -25,7 +24,7 @@ public void createTable() { try { AzureTable officeSuppliesTable = tableServiceClient.createTable("OfficeSupplies"); - } catch (TableServiceErrorException e) { + } catch (Exception e) { logger.error("Create Table Unsuccessful. Error: " + e); } } @@ -40,7 +39,7 @@ public void deleteTable() { try { tableServiceClient.deleteTable("OfficeSupplies"); - } catch (TableServiceErrorException e) { + } catch (Exception e) { logger.error("Delete Table Unsuccessful. Error: " + e); } } @@ -91,22 +90,18 @@ private void updateEntity() { .tableName("OfficeSupplies") .buildClient(); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("RowKey eq crayolaMarkers"); - List tableEntities = null; + String rowKey = "crayolaMarkers"; + String partitionKey = "markers"; + TableEntity tableEntity = null; try { - tableEntities = tableClient.queryEntity(queryOptions); + tableEntity = tableClient.get(rowKey, partitionKey); } catch (HttpResponseException e) { - logger.error("Query Table Entities Unsuccessful. Error: " + e); + logger.error("Get Entity Unsuccessful: " + e); } - if (tableEntities != null) { - TableEntity tableEntity = tableEntities.get(0); - tableEntity.addProperty("Seller", "Crayola"); - try { - tableClient.updateEntity(UpdateMode.Replace, tableEntity); - } catch (HttpResponseException e) { - logger.error("Update Entity Unsuccessful. Error: " + e); - } + try { + tableClient.updateEntity(UpdateMode.Replace, tableEntity); + } catch (HttpResponseException e) { + logger.error("Update Entity Unsuccessful. Error: " + e); } } @@ -119,22 +114,18 @@ private void upsertEntity() { .tableName("OfficeSupplies") .buildClient(); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("RowKey eq crayolaMarkers"); - List tableEntities = null; + String rowKey = "crayolaMarkers"; + String partitionKey = "markers"; + TableEntity tableEntity = null; try { - tableEntities = tableClient.queryEntity(queryOptions); + tableEntity = tableClient.get(rowKey, partitionKey); } catch (HttpResponseException e) { - logger.error("Query Table Entities Unsuccessful. Error: " + e); + logger.error("Get Entity Unsuccessful: " + e); } - if (tableEntities != null) { - TableEntity tableEntity = tableEntities.get(0); - tableEntity.addProperty("Price", "5"); - try { - tableClient.upsertEntity(UpdateMode.Replace, tableEntity); - } catch (HttpResponseException e) { - logger.error("Upsert Entity Unsuccessful. Error: " + e); - } + try { + tableClient.upsertEntity(UpdateMode.Replace, tableEntity); + } catch (HttpResponseException e) { + logger.error("Upsert Entity Unsuccessful. Error: " + e); } } @@ -147,21 +138,18 @@ private void deleteEntity() { .tableName("OfficeSupplies") .buildClient(); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("RowKey eq crayolaMarkers"); - List tableEntities = null; + String rowKey = "crayolaMarkers"; + String partitionKey = "markers"; + TableEntity tableEntity = null; try { - tableEntities = tableClient.queryEntity(queryOptions); + tableEntity = tableClient.get(rowKey, partitionKey); } catch (HttpResponseException e) { - logger.error("Query Table Entities Unsuccessful. Error: " + e); + logger.error("Get Entity Unsuccessful: " + e); } - if (tableEntities != null) { - TableEntity tableEntity = tableEntities.get(0); - try { - tableClient.deleteEntity(tableEntity); - } catch (HttpResponseException e) { - logger.error("Delete Entity Unsuccessful. Error: " + e); - } + try { + tableClient.deleteEntity(tableEntity); + } catch (HttpResponseException e) { + logger.error("Delete Entity Unsuccessful. Error: " + e); } } @@ -178,7 +166,7 @@ private void queryEntity() { queryOptions.setFilter("Product eq markers"); queryOptions.setSelect("Seller, Price"); try { - List tableEntities = tableClient.queryEntity(queryOptions); + List tableEntities = tableClient.queryEntities(queryOptions); } catch (HttpResponseException e) { logger.error("Query Table Entities Unsuccessful. Error: " + e); } @@ -193,17 +181,12 @@ public void entityExists() { .tableName("OfficeSupplies") .buildClient(); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("TableName eq OfficeSupplies"); + String rowKey = "crayolaMarkers"; + String partitionKey = "markers"; try { - List responseTables = - tableClient.queryEntitiesWithPartitionAndRowKey("crayolaMarkers", "markers"); - if (responseTables != null && responseTables.get(0) != null) { - logger.info("Entity with the rowKey = crayolaMarkers and partitionKey = markers exists."); - } + TableEntity tableEntity = tableClient.get(rowKey, partitionKey); } catch (HttpResponseException e) { - logger.error("Table Query Unsuccessful. Error: " + e); + logger.error("Get Entity Unsuccessful. Entity may not exist: " + e); } - } } From 58f9b78fe1369dd3535213bf5f504e1f45b32366 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 9 Jul 2020 12:55:54 -0400 Subject: [PATCH 38/42] fix void async --- .../azure/data/tables/TableAsyncClient.java | 4 +- .../TableServiceAsyncClientCodeSnippets.java | 45 +++++++++---------- 2 files changed, 22 insertions(+), 27 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 a13763d2e3f2..5e04579b63fe 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 @@ -101,7 +101,7 @@ public Mono deleteEntity(String partitionKey, String rowKey) { * * @return table name */ - public Mono getTableName() { - return Mono.empty(); + public String getTableName() { + return null; } } 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 24413b9f4134..17055a383df5 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java @@ -21,11 +21,10 @@ public void createTable() { .connectionString("connectionString") .buildAsyncClient(); - tableServiceAsyncClient.createTable("OfficeSupplies").subscribe(Void -> { - logger.info("Table creation successful."); - }, error -> { - logger.error("There was an error creating the table. Error: " + error); - }); + tableServiceAsyncClient.createTable("OfficeSupplies").subscribe( + Void -> {}, + error -> logger.error("There was an error creating the table. Error: " + error), + () -> logger.info("Table creation successful.")); } /** @@ -36,11 +35,10 @@ public void deleteTable() { .connectionString("connectionString") .buildAsyncClient(); - tableServiceAsyncClient.deleteTable("OfficeSupplies").subscribe(Void -> { - logger.info("Table deletion successful"); - }, error -> { - logger.error("There was an error deleting the table. Error: " + error); - }); + tableServiceAsyncClient.deleteTable("OfficeSupplies").subscribe( + Void -> {}, + error -> logger.error("There was an error deleting the table. Error: " + error), + () -> logger.info("Table deletion successful.")); } /** @@ -100,11 +98,10 @@ private void deleteEntity() { logger.info("Table Entity: " + tableEntity); Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity); return deleteEntityMono; - }).subscribe(Void -> { - logger.info("Delete Entity Successful."); - }, error -> { - logger.error("There was an error deleting the Entity. Error: " + error); - }); + }).subscribe( + Void -> {}, + error -> logger.error("There was an error deleting the Entity. Error: " + error), + () -> logger.info("Delete Entity Successful.")); } /** @@ -126,11 +123,10 @@ private void upsert() { tableEntity.addProperty("Price", "5"); Mono updateEntityMono = tableAsyncClient.upsertEntity(UpdateMode.Merge, tableEntity); return updateEntityMono; - }).subscribe(Void -> { - logger.info("Update Entity Successful."); - }, error -> { - logger.error("There was an error updating the Entity. Error: " + error); - }); + }).subscribe( + Void -> {}, + error -> logger.error("There was an error upserting the Entity. Error: " + error), + () -> logger.info("Upsert Entity Successful.")); } /** @@ -152,11 +148,10 @@ private void update() { tableEntity.addProperty("Price", "5"); Mono updateEntityMono = tableAsyncClient.updateEntity(UpdateMode.Replace, tableEntity); return updateEntityMono; - }).subscribe(Void -> { - logger.info("Update Entity Successful."); - }, error -> { - logger.error("There was an error updating the Entity. Error: " + error); - }); + }).subscribe( + Void -> {}, + error -> logger.error("There was an error updating the Entity. Error: " + error), + () -> logger.info("Update Entity Successful.")); } /** From 07e1baade298eae9e0c92cf5fd649b6b1e66a4c3 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 9 Jul 2020 14:25:08 -0400 Subject: [PATCH 39/42] connie edits --- sdk/tables/azure-data-tables/pom.xml | 6 ++ .../com/azure/data/tables/QueryOptions.java | 3 + .../com/azure/data/tables/TableEntity.java | 16 ++-- .../tables/TableServiceClientBuilder.java | 2 +- .../com/azure/data/tables/UpdateMode.java | 4 +- .../TableServiceAsyncClientCodeSnippets.java | 73 ++++++++----------- .../java/TableServiceClientCodeSnippets.java | 37 +++++----- 7 files changed, 64 insertions(+), 77 deletions(-) diff --git a/sdk/tables/azure-data-tables/pom.xml b/sdk/tables/azure-data-tables/pom.xml index b1519f8b62c6..5b354a291b28 100644 --- a/sdk/tables/azure-data-tables/pom.xml +++ b/sdk/tables/azure-data-tables/pom.xml @@ -71,6 +71,12 @@ Licensed under the MIT License. 3.3.5.RELEASE test + + com.azure + azure-core-test + 1.3.1 + test + org.mockito mockito-core diff --git a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java index 892a822a2fd1..bd10b72ae4b0 100644 --- a/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java +++ b/sdk/tables/azure-data-tables/src/main/java/com/azure/data/tables/QueryOptions.java @@ -3,9 +3,12 @@ package com.azure.data.tables; +import com.azure.core.annotation.Fluent; + /** * helps construct a query */ +@Fluent public final class QueryOptions { private Integer top; private String select; 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 index 7d2997277435..b2df1fdabd87 100644 --- 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 @@ -2,11 +2,13 @@ // 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 Map properties; //tableName @@ -34,17 +36,9 @@ public Map getProperties() { * * @param key the key of the property * @param value the value of the property + * @return the updated entity */ - public void addProperty(String key, Object value) { - - } - - /** - * set the properties - * - * @param properties properties to set to this entity - */ - public void setProperties(Map properties) { - this.properties = properties; + public TableEntity addProperty(String key, Object value) { + return this; } } 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 285033ef25f6..0a28d96150c5 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 @@ -113,7 +113,7 @@ public TableServiceClientBuilder endpoint(String endpoint) { */ public TableServiceClientBuilder httpClient(HttpClient httpClient) { if (this.httpClient != null && httpClient == null) { - logger.info("'httpClient' is being set to 'null' when it was previously configured."); + System.out.println("'httpClient' is being set to 'null' when it was previously configured."); } this.httpClient = httpClient; return this; 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/UpdateMode.java index c704ce3f557f..20dc6f8365ee 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/UpdateMode.java @@ -3,6 +3,6 @@ package com.azure.data.tables; enum UpdateMode { - Merge, - Replace + 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 17055a383df5..9f3a38950ae5 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java @@ -11,7 +11,7 @@ * async code snippets for the table service */ public class TableServiceAsyncClientCodeSnippets { - final ClientLogger logger = new ClientLogger("TableServiceAsyncClientCodeSnippets"); + /** * create table code snippet @@ -23,8 +23,8 @@ public void createTable() { tableServiceAsyncClient.createTable("OfficeSupplies").subscribe( Void -> {}, - error -> logger.error("There was an error creating the table. Error: " + error), - () -> logger.info("Table creation successful.")); + error -> System.err.println("There was an error creating the table. Error: " + error), + () -> System.out.println("Table creation successful.")); } /** @@ -37,8 +37,8 @@ public void deleteTable() { tableServiceAsyncClient.deleteTable("OfficeSupplies").subscribe( Void -> {}, - error -> logger.error("There was an error deleting the table. Error: " + error), - () -> logger.info("Table deletion successful.")); + error -> System.err.println("There was an error deleting the table. Error: " + error), + () -> System.out.println("Table deletion successful.")); } /** @@ -48,13 +48,12 @@ public void queryTable() { TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") .buildAsyncClient(); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("TableName eq OfficeSupplies"); + QueryOptions queryOptions = new QueryOptions().setFilter("TableName eq OfficeSupplies"); tableServiceAsyncClient.queryTables(queryOptions).subscribe(azureTable -> { - logger.info(azureTable.getName()); + System.out.println(azureTable.getName()); }, error -> { - logger.error("There was an error querying the service. Error: " + error); + System.err.println("There was an error querying the service. Error: " + error); }); } @@ -62,8 +61,6 @@ public void queryTable() { * insert entity code snippet */ private void insertEntity() { - - // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") .buildAsyncClient(); @@ -74,9 +71,9 @@ private void insertEntity() { properties.put("PartitionKey", "markers"); tableAsyncClient.createEntity(properties).subscribe(tableEntity -> { - logger.info("Insert Entity Successful. Entity: " + tableEntity); + System.out.println("Insert Entity Successful. Entity: " + tableEntity); }, error -> { - logger.error("There was an error inserting the Entity. Error: " + error); + System.err.println("There was an error inserting the Entity. Error: " + error); }); } @@ -84,8 +81,6 @@ private void insertEntity() { * delete entity code snippet */ private void deleteEntity() { - - // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") .buildAsyncClient(); @@ -95,21 +90,18 @@ private void deleteEntity() { String partitionKey = "markers"; tableAsyncClient.get(rowKey, partitionKey).flatMap(tableEntity -> { - logger.info("Table Entity: " + tableEntity); - Mono deleteEntityMono = tableAsyncClient.deleteEntity(tableEntity); - return deleteEntityMono; + System.out.println("Table Entity: " + tableEntity); + return tableAsyncClient.deleteEntity(tableEntity); }).subscribe( Void -> {}, - error -> logger.error("There was an error deleting the Entity. Error: " + error), - () -> logger.info("Delete Entity Successful.")); + error -> System.err.println("There was an error deleting the Entity. Error: " + error), + () -> System.out.println("Delete Entity Successful.")); } /** * upsert entity code snippet */ private void upsert() { - - // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") .buildAsyncClient(); @@ -119,22 +111,20 @@ private void upsert() { String partitionKey = "markers"; tableAsyncClient.get(rowKey, partitionKey).flatMap(tableEntity -> { - logger.info("Table Entity: " + tableEntity); + System.out.println("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); - Mono updateEntityMono = tableAsyncClient.upsertEntity(UpdateMode.Merge, tableEntity); + Mono updateEntityMono = tableAsyncClient.upsertEntity(UpdateMode.MERGE, tableEntity); return updateEntityMono; }).subscribe( Void -> {}, - error -> logger.error("There was an error upserting the Entity. Error: " + error), - () -> logger.info("Upsert Entity Successful.")); + error -> System.err.println("There was an error upserting the Entity. Error: " + error), + () -> System.out.println("Upsert Entity Successful.")); } /** * update entity code snippet */ private void update() { - - // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") .buildAsyncClient(); @@ -144,35 +134,33 @@ private void update() { String partitionKey = "markers"; tableAsyncClient.get(rowKey, partitionKey).flatMap(tableEntity -> { - logger.info("Table Entity: " + tableEntity); + System.out.println("Table Entity: " + tableEntity); tableEntity.addProperty("Price", "5"); - Mono updateEntityMono = tableAsyncClient.updateEntity(UpdateMode.Replace, tableEntity); + Mono updateEntityMono = tableAsyncClient.updateEntity(UpdateMode.REPLACE, tableEntity); return updateEntityMono; }).subscribe( Void -> {}, - error -> logger.error("There was an error updating the Entity. Error: " + error), - () -> logger.info("Update Entity Successful.")); + error -> System.err.println("There was an error updating the Entity. Error: " + error), + () -> System.out.println("Update Entity Successful.")); } /** * query entity code snippet */ private void queryEntities() { - - // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") .buildAsyncClient(); TableAsyncClient tableAsyncClient = tableServiceAsyncClient.getTableAsyncClient("OfficeSupplies"); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("Product eq markers"); - queryOptions.setSelect("Seller, Price"); + QueryOptions queryOptions = new QueryOptions() + .setFilter("Product eq markers") + .setSelect("Seller, Price"); tableAsyncClient.queryEntities(queryOptions).subscribe(tableEntity -> { - logger.info("Table Entity: " + tableEntity); + System.out.println("Table Entity: " + tableEntity); }, error -> { - logger.error("There was an error querying the table. Error: " + error); + System.err.println("There was an error querying the table. Error: " + error); }); } @@ -180,8 +168,6 @@ private void queryEntities() { * checks to see if an entity exists code snippet */ private void existsEntity() { - - // Build service client TableServiceAsyncClient tableServiceAsyncClient = new TableServiceClientBuilder() .connectionString("connectionString") .buildAsyncClient(); @@ -190,10 +176,9 @@ private void existsEntity() { tableAsyncClient.get("crayolaMarkers", "markers") .subscribe(tableEntity -> { - logger.info("Table Entity exists: " + tableEntity); + System.out.println("Table Entity exists: " + tableEntity); }, error -> { - logger.error("There was an error getting the entity. Error: " + error); + System.err.println("There was an error getting the entity. Error: " + error); }); } - } 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 15ff60c11dd2..797df52758cf 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceClientCodeSnippets.java @@ -25,7 +25,7 @@ public void createTable() { try { AzureTable officeSuppliesTable = tableServiceClient.createTable("OfficeSupplies"); } catch (Exception e) { - logger.error("Create Table Unsuccessful. Error: " + e); + System.err.println("Create Table Unsuccessful. Error: " + e); } } @@ -40,7 +40,7 @@ public void deleteTable() { try { tableServiceClient.deleteTable("OfficeSupplies"); } catch (Exception e) { - logger.error("Delete Table Unsuccessful. Error: " + e); + System.err.println("Delete Table Unsuccessful. Error: " + e); } } @@ -52,13 +52,12 @@ public void queryTables() { .connectionString("connectionString") .buildClient(); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("TableName eq OfficeSupplies"); + QueryOptions queryOptions = new QueryOptions().setFilter("TableName eq OfficeSupplies"); try { List responseTables = tableServiceClient.queryTables(queryOptions); } catch (HttpResponseException e) { - logger.error("Table Query Unsuccessful. Error: " + e); + System.err.println("Table Query Unsuccessful. Error: " + e); } } @@ -77,7 +76,7 @@ private void insertEntity() { try { TableEntity tableEntity = tableClient.createEntity(properties); } catch (HttpResponseException e) { - logger.error("Insert Entity Unsuccessful. Error: " + e); + System.err.println("Insert Entity Unsuccessful. Error: " + e); } } @@ -96,12 +95,12 @@ private void updateEntity() { try { tableEntity = tableClient.get(rowKey, partitionKey); } catch (HttpResponseException e) { - logger.error("Get Entity Unsuccessful: " + e); + System.err.println("Get Entity Unsuccessful: " + e); } try { - tableClient.updateEntity(UpdateMode.Replace, tableEntity); + tableClient.updateEntity(UpdateMode.REPLACE, tableEntity); } catch (HttpResponseException e) { - logger.error("Update Entity Unsuccessful. Error: " + e); + System.err.println("Update Entity Unsuccessful. Error: " + e); } } @@ -120,12 +119,12 @@ private void upsertEntity() { try { tableEntity = tableClient.get(rowKey, partitionKey); } catch (HttpResponseException e) { - logger.error("Get Entity Unsuccessful: " + e); + System.err.println("Get Entity Unsuccessful: " + e); } try { - tableClient.upsertEntity(UpdateMode.Replace, tableEntity); + tableClient.upsertEntity(UpdateMode.REPLACE, tableEntity); } catch (HttpResponseException e) { - logger.error("Upsert Entity Unsuccessful. Error: " + e); + System.err.println("Upsert Entity Unsuccessful. Error: " + e); } } @@ -144,12 +143,12 @@ private void deleteEntity() { try { tableEntity = tableClient.get(rowKey, partitionKey); } catch (HttpResponseException e) { - logger.error("Get Entity Unsuccessful: " + e); + System.err.println("Get Entity Unsuccessful: " + e); } try { tableClient.deleteEntity(tableEntity); } catch (HttpResponseException e) { - logger.error("Delete Entity Unsuccessful. Error: " + e); + System.err.println("Delete Entity Unsuccessful. Error: " + e); } } @@ -162,13 +161,13 @@ private void queryEntity() { .tableName("OfficeSupplies") .buildClient(); - QueryOptions queryOptions = new QueryOptions(); - queryOptions.setFilter("Product eq markers"); - queryOptions.setSelect("Seller, Price"); + QueryOptions queryOptions = new QueryOptions() + .setFilter("Product eq markers") + .setSelect("Seller, Price"); try { List tableEntities = tableClient.queryEntities(queryOptions); } catch (HttpResponseException e) { - logger.error("Query Table Entities Unsuccessful. Error: " + e); + System.err.println("Query Table Entities Unsuccessful. Error: " + e); } } @@ -186,7 +185,7 @@ public void entityExists() { try { TableEntity tableEntity = tableClient.get(rowKey, partitionKey); } catch (HttpResponseException e) { - logger.error("Get Entity Unsuccessful. Entity may not exist: " + e); + System.err.println("Get Entity Unsuccessful. Entity may not exist: " + e); } } } From 2aef60f0ac4a23cb828d994d1971b457f40c2d59 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 9 Jul 2020 14:55:47 -0400 Subject: [PATCH 40/42] fix pom --- sdk/tables/azure-data-tables/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/tables/azure-data-tables/pom.xml b/sdk/tables/azure-data-tables/pom.xml index 5b354a291b28..5c2eb2ab5cf3 100644 --- a/sdk/tables/azure-data-tables/pom.xml +++ b/sdk/tables/azure-data-tables/pom.xml @@ -45,7 +45,7 @@ Licensed under the MIT License. com.azure azure-storage-common - 12.7.0 + 12.7.0 org.junit.jupiter From d83fd306119e02d8f522fed16ba58f20db6eae53 Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 9 Jul 2020 15:04:06 -0400 Subject: [PATCH 41/42] fix version --- sdk/tables/azure-data-tables/pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sdk/tables/azure-data-tables/pom.xml b/sdk/tables/azure-data-tables/pom.xml index 5c2eb2ab5cf3..79c42cfcdfd2 100644 --- a/sdk/tables/azure-data-tables/pom.xml +++ b/sdk/tables/azure-data-tables/pom.xml @@ -45,7 +45,7 @@ Licensed under the MIT License. com.azure azure-storage-common - 12.7.0 + 12.8.0-beta.1 org.junit.jupiter From 612014446e5ac97641c1c050575026c56080647a Mon Sep 17 00:00:00 2001 From: Eleanor Boyd Date: Thu, 9 Jul 2020 16:07:18 -0400 Subject: [PATCH 42/42] checkstyle errors --- .../azure/data/tables/TableAsyncClient.java | 3 +- .../azure/data/tables/TableClientBuilder.java | 2 -- .../com/azure/data/tables/TableEntity.java | 3 +- .../tables/TableServiceClientBuilder.java | 6 ++-- .../com/azure/data/tables/UpdateMode.java | 5 ++- .../TableServiceAsyncClientCodeSnippets.java | 31 +++++++++---------- 6 files changed, 25 insertions(+), 25 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 5e04579b63fe..a1f5d555f399 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 @@ -4,7 +4,6 @@ import com.azure.core.annotation.ServiceClient; import com.azure.core.http.rest.PagedFlux; -import java.util.List; import java.util.Map; import reactor.core.publisher.Mono; @@ -102,6 +101,6 @@ public Mono deleteEntity(String partitionKey, String rowKey) { * @return table name */ public String getTableName() { - return null; + return tableName; } } 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 c72933e8a333..fa1e59dec040 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 @@ -12,7 +12,6 @@ public class TableClientBuilder { private String connectionString; private String tableName; - private TokenCredential tokenCredential; /** * Sets the connection string to help build the client @@ -32,7 +31,6 @@ public TableClientBuilder connectionString(String connectionString) { * @return the TableClientBuilder */ public TableClientBuilder connectionString(TokenCredential tokenCredential) { - this.tokenCredential = tokenCredential; return this; } 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 index b2df1fdabd87..26a8cdf99e09 100644 --- 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 @@ -10,7 +10,7 @@ */ @Fluent public class TableEntity { - private Map properties; + private final Map properties; //tableName //etag @@ -20,6 +20,7 @@ public class TableEntity { * @param properties map of properties of the entity */ public TableEntity(Map properties) { + this.properties = properties; } /** 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 0a28d96150c5..4eefce10a47f 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 @@ -89,8 +89,8 @@ public TableServiceClientBuilder configuration(Configuration configuration) { * @throws NullPointerException If {@code credential} is {@code null}. */ public TableServiceClientBuilder credential(TablesSharedKeyCredential credential) { - this.tablesSharedKeyCredential = Objects.requireNonNull(tablesSharedKeyCredential, "credential cannot" + - "be null"); + this.tablesSharedKeyCredential = Objects.requireNonNull(tablesSharedKeyCredential, "credential cannot" + + "be null"); return this; } @@ -113,7 +113,7 @@ public TableServiceClientBuilder endpoint(String endpoint) { */ public TableServiceClientBuilder httpClient(HttpClient httpClient) { if (this.httpClient != null && httpClient == null) { - System.out.println("'httpClient' is being set to 'null' when it was previously configured."); + logger.error("'httpClient' is being set to 'null' when it was previously configured."); } this.httpClient = httpClient; return this; 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/UpdateMode.java index 20dc6f8365ee..8e990483add0 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/UpdateMode.java @@ -2,7 +2,10 @@ // Licensed under the MIT License. package com.azure.data.tables; -enum UpdateMode { +/** + * update type for update and upsert methods + */ +public enum UpdateMode { 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 9f3a38950ae5..6f2eadec8698 100644 --- a/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java +++ b/sdk/tables/azure-data-tables/src/samples/java/TableServiceAsyncClientCodeSnippets.java @@ -2,7 +2,6 @@ // Licensed under the MIT License. package com.azure.data.tables; -import com.azure.core.util.logging.ClientLogger; import java.util.HashMap; import java.util.Map; import reactor.core.publisher.Mono; @@ -22,7 +21,7 @@ public void createTable() { .buildAsyncClient(); tableServiceAsyncClient.createTable("OfficeSupplies").subscribe( - Void -> {}, + Void -> { }, error -> System.err.println("There was an error creating the table. Error: " + error), () -> System.out.println("Table creation successful.")); } @@ -36,7 +35,7 @@ public void deleteTable() { .buildAsyncClient(); tableServiceAsyncClient.deleteTable("OfficeSupplies").subscribe( - Void -> {}, + Void -> { }, error -> System.err.println("There was an error deleting the table. Error: " + error), () -> System.out.println("Table deletion successful.")); } @@ -53,8 +52,8 @@ public void queryTable() { tableServiceAsyncClient.queryTables(queryOptions).subscribe(azureTable -> { System.out.println(azureTable.getName()); }, error -> { - System.err.println("There was an error querying the service. Error: " + error); - }); + System.err.println("There was an error querying the service. Error: " + error); + }); } /** @@ -73,8 +72,8 @@ private void insertEntity() { tableAsyncClient.createEntity(properties).subscribe(tableEntity -> { System.out.println("Insert Entity Successful. Entity: " + tableEntity); }, error -> { - System.err.println("There was an error inserting the Entity. Error: " + error); - }); + System.err.println("There was an error inserting the Entity. Error: " + error); + }); } /** @@ -93,7 +92,7 @@ private void deleteEntity() { System.out.println("Table Entity: " + tableEntity); return tableAsyncClient.deleteEntity(tableEntity); }).subscribe( - Void -> {}, + Void -> { }, error -> System.err.println("There was an error deleting the Entity. Error: " + error), () -> System.out.println("Delete Entity Successful.")); } @@ -116,7 +115,7 @@ private void upsert() { Mono updateEntityMono = tableAsyncClient.upsertEntity(UpdateMode.MERGE, tableEntity); return updateEntityMono; }).subscribe( - Void -> {}, + Void -> { }, error -> System.err.println("There was an error upserting the Entity. Error: " + error), () -> System.out.println("Upsert Entity Successful.")); } @@ -139,7 +138,7 @@ private void update() { Mono updateEntityMono = tableAsyncClient.updateEntity(UpdateMode.REPLACE, tableEntity); return updateEntityMono; }).subscribe( - Void -> {}, + Void -> { }, error -> System.err.println("There was an error updating the Entity. Error: " + error), () -> System.out.println("Update Entity Successful.")); } @@ -160,8 +159,8 @@ private void queryEntities() { tableAsyncClient.queryEntities(queryOptions).subscribe(tableEntity -> { System.out.println("Table Entity: " + tableEntity); }, error -> { - System.err.println("There was an error querying the table. Error: " + error); - }); + System.err.println("There was an error querying the table. Error: " + error); + }); } /** @@ -176,9 +175,9 @@ private void existsEntity() { tableAsyncClient.get("crayolaMarkers", "markers") .subscribe(tableEntity -> { - System.out.println("Table Entity exists: " + tableEntity); - }, error -> { - System.err.println("There was an error getting the entity. Error: " + error); - }); + System.out.println("Table Entity exists: " + tableEntity); + }, error -> { + System.err.println("There was an error getting the entity. Error: " + error); + }); } }