try { cloudTable = tableClient.getTableReference(table); cloudTable.createIfNotExists(); } catch (Exception e) { throw new DBException("Could not connect to the table.\n", e);
public void init() { try { String endpoint = String.format(ENDPOINT_TEMPLATE, configuration.getAccountName()); CloudStorageAccount cosmosAccount = CloudStorageAccount.parse( String.format( COSMOS_CONNECTION_TEMPLATE, configuration.getAccountName(), configuration.getAccountKey(), endpoint)); tableClient = cosmosAccount.createCloudTableClient(); // Create the tables if the do not exist tableClient.getTableReference(JOB_TABLE).createIfNotExists(); tableClient.getTableReference(JOB_DATA_TABLE).createIfNotExists(); CloudStorageAccount blobAccount = CloudStorageAccount.parse( String.format( BLOB_CONNECTION_TEMPLATE, configuration.getAccountName(), configuration.getBlobKey())); blobClient = blobAccount.createCloudBlobClient(); blobClient.getContainerReference(BLOB_CONTAINER).createIfNotExists(); } catch (StorageException | URISyntaxException | InvalidKeyException e) { throw new MicrosoftStorageException(e); } }
public void create(AzureTableName table) { try { tableRefrence(table).createIfNotExists(); return; } catch (StorageException e) { LOG.warn("Error creating table: {}", table, e); } throw new IllegalStateException("Could not create table: " + table); }
/** * Creates the table in the storage service using default request options if it does not already exist. * * @return <code>true</code> if the table is created in the storage service; otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public boolean createIfNotExists() throws StorageException { return this.createIfNotExists(null /* options */, null /* opContext */); }
/** * Creates the table in the storage service using default request options if it does not already exist. * * @return <code>true</code> if the table is created in the storage service; otherwise <code>false</code>. * * @throws StorageException * If a storage service error occurred during the operation. */ @DoesServiceRequest public boolean createIfNotExists() throws StorageException { return this.createIfNotExists(null /* options */, null /* opContext */); }
public AzureAccess(CloudTableClient client, String tableName) throws AzureAccessNotPossibleException { try { table = client.getTableReference(tableName); table.createIfNotExists(); } catch (URISyntaxException | StorageException e) { LOG.error("Azure communication failed", e); throw new AzureAccessNotPossibleException("Azure communication failed"); } }
public TableUtils(AzureClient client, String tableName, String initialState) { this.initialState = initialState; CloudTableClient tableClient = client.getTableClient(); try { table = tableClient.getTableReference(tableName); table.createIfNotExists(); } catch (URISyntaxException e) { LOG.error("\nConnection string specifies an invalid URI.", e); throw new AzureException(e); } catch (StorageException e) { LOG.error("Azure storage exception.", e); throw new AzureException(e); } }
@Override public void start() { try { // Create the table if it doesn't exist. cloudTable = azureClient.getTableClient().getTableReference(jobTableName); cloudTable.createIfNotExists(); } catch (URISyntaxException e) { LOG.error("Connection string {} specifies an invalid URI while creating checkpoint table.", storageConnectionString); throw new AzureException(e); } catch (StorageException e) { LOG.error("Azure Storage failed when creating checkpoint table", e); throw new AzureException(e); } }
public BlobDataIO(String tableName,String accessKey,String secretKey,String connectionProtocol) throws InvalidKeyException, URISyntaxException, StorageException { storageConnectionString="DefaultEndpointsProtocol=" + connectionProtocol + ";" + "AccountName=" + accessKey + ";" + "AccountKey=" + secretKey; CloudStorageAccount storageAccount = CloudStorageAccount.parse(storageConnectionString); tableClient = storageAccount.createCloudTableClient(); cloudTable = tableClient.getTableReference(tableName); cloudTable.createIfNotExists(); }
@Before public void tableSerializerTestMethodSetUp() throws URISyntaxException, StorageException { this.table = TableTestHelper.getRandomTableReference(); this.table.createIfNotExists(); }
@Before public void tableEscapingTestMethodSetUp() throws URISyntaxException, StorageException { this.table = TableTestHelper.getRandomTableReference(); this.table.createIfNotExists(); }
@Before public void tableBatchOperationTestMethodSetUp() throws URISyntaxException, StorageException { this.table = TableTestHelper.getRandomTableReference(); this.table.createIfNotExists(); }
@Before public void tableOperationTestMethodSetUp() throws URISyntaxException, StorageException { this.table = TableTestHelper.getRandomTableReference(); this.table.createIfNotExists(); }
@Before public void tableDateTestMethodSetUp() throws URISyntaxException, StorageException { this.table = TableTestHelper.getRandomTableReference(); this.table.createIfNotExists(); }
public void testTableQueryProjectionWithNull() throws URISyntaxException, StorageException { CloudTable table = TableTestHelper.getRandomTableReference(); try { // Create a new table so we don't pollute the main query table table.createIfNotExists(); // Insert an entity which is missing String and IntegerPrimitive DynamicTableEntity entity = new DynamicTableEntity(UUID.randomUUID().toString(), UUID.randomUUID() .toString()); table.execute(TableOperation.insert(entity)); testTableQueryProjectionWithSpecialCases(table); } finally { table.deleteIfExists(); } }
@NotNull public Table createTable(@NotNull StorageAccount storageAccount, @NotNull Table table) throws AzureCmdException { try { CloudTableClient client = getCloudTableClient(storageAccount); CloudTable cloudTable = client.getTableReference(table.getName()); cloudTable.createIfNotExists(); String uri = cloudTable.getUri() != null ? cloudTable.getUri().toString() : ""; table.setUri(uri); return table; } catch (Throwable t) { throw new AzureCmdException("Error creating the Table", t); } }
@BeforeClass public static void tableQueryTestMethodSetUp() throws Exception { table = TableTestHelper.getRandomTableReference(); table.createIfNotExists(); // Insert 500 entities in Batches to query for (int i = 0; i < 5; i++) { TableBatchOperation batch = new TableBatchOperation(); for (int j = 0; j < 100; j++) { Class1 ent = TableTestHelper.generateRandomEntity("javatables_batch_" + Integer.toString(i)); ent.setRowKey(String.format("%06d", j)); batch.insert(ent); } table.execute(batch); } }
@Test public void testTableCreateIfNotExists() throws StorageException, URISyntaxException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); String tableName = TableTestHelper.generateRandomTableName(); CloudTable table = tClient.getTableReference(tableName); try { assertTrue(table.createIfNotExists()); assertTrue(table.exists()); assertFalse(table.createIfNotExists()); } finally { // cleanup table.deleteIfExists(); } }
@Test public void testTableDoesTableExist() throws StorageException, URISyntaxException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); String tableName = TableTestHelper.generateRandomTableName(); CloudTable table = tClient.getTableReference(tableName); try { assertFalse(table.exists()); assertTrue(table.createIfNotExists()); assertTrue(table.exists()); } finally { // cleanup table.deleteIfExists(); } }
@Test public void testTableCreateExistsAndDelete() throws StorageException, URISyntaxException { CloudTableClient tClient = TableTestHelper.createCloudTableClient(); String tableName = TableTestHelper.generateRandomTableName(); CloudTable table = tClient.getTableReference(tableName); try { assertTrue(table.createIfNotExists()); assertTrue(table.exists()); assertTrue(table.deleteIfExists()); } finally { // cleanup table.deleteIfExists(); } }