/** * Creates an instance of the <code>RequestOptions</code> class by copying values from another * <code>TableRequestOptions</code> instance. * * @param other * A <code>TableRequestOptions</code> object that represents the request options to copy. */ public TableRequestOptions(final TableRequestOptions other) { super(other); if (other != null) { this.setTablePayloadFormat(other.getTablePayloadFormat()); this.setPropertyResolver(other.getPropertyResolver()); this.setDateBackwardCompatibility(other.getDateBackwardCompatibility()); } }
/** * Creates an instance of the <code>RequestOptions</code> class by copying values from another * <code>TableRequestOptions</code> instance. * * @param other * A <code>TableRequestOptions</code> object that represents the request options to copy. */ public TableRequestOptions(final TableRequestOptions other) { super(other); if (other != null) { this.setTablePayloadFormat(other.getTablePayloadFormat()); this.setPropertyResolver(other.getPropertyResolver()); this.setDateBackwardCompatibility(other.getDateBackwardCompatibility()); this.setEncryptionPolicy(other.getEncryptionPolicy()); this.setEncryptionResolver(other.getEncryptionResolver()); } }
/** * Populates any null fields in the first requestOptions object with values from the second requestOptions object. * * @param modifiedOptions * A {@link TableRequestOptions} object from which to copy options. * @param clientOptions * A {@link TableRequestOptions} object where options will be copied. * * @return A {@link RequestOptions} object. */ private static void populate(TableRequestOptions modifiedOptions, final TableRequestOptions clientOptions) { RequestOptions.populateRequestOptions(modifiedOptions, clientOptions, true /* setStartTime */); if (modifiedOptions.getTablePayloadFormat() == null) { modifiedOptions.setTablePayloadFormat(clientOptions.getTablePayloadFormat()); } if (modifiedOptions.getPropertyResolver() == null) { modifiedOptions.setPropertyResolver(clientOptions.getPropertyResolver()); } if (modifiedOptions.getDateBackwardCompatibility() == null) { modifiedOptions.setDateBackwardCompatibility(clientOptions.getDateBackwardCompatibility()); } }
private void executeQueryAndAssertResults(String filter, int expectedResults, TableRequestOptions options, boolean usePropertyResolver) { // instantiate class to use property resolver ComplexEntity ent = new ComplexEntity(); if (usePropertyResolver) { options.setPropertyResolver(ent); } int count = 0; TableQuery<ComplexEntity> query = TableQuery.from(ComplexEntity.class).where(filter); for (@SuppressWarnings("unused") ComplexEntity e : table.execute(query, options, null)) { count++; } assertEquals(expectedResults, count); }
private void testComplexEntityInsert(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { ComplexEntity ref = new ComplexEntity(); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); ref.populateEntity(); if (usePropertyResolver) { options.setPropertyResolver(ref); } this.table.execute(TableOperation.insert(ref), options, null); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), ComplexEntity.class), options, null); ComplexEntity retrievedComplexRef = res.getResultAsType(); ref.assertEquality(retrievedComplexRef); }
private void testDoubles(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { StrangeDoubles ref = new StrangeDoubles(); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); ref.populateEntity(); if (usePropertyResolver) { options.setPropertyResolver(ref); } // try with pojo this.table.execute(TableOperation.insert(ref), options, null); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), StrangeDoubles.class), options, null); StrangeDoubles retrievedComplexRef = res.getResultAsType(); ref.assertEquality(retrievedComplexRef); }
@Test public void testTableOperationRetrieveJsonNoMetadataFail() { // set custom property resolver this.options.setPropertyResolver(new CustomPropertyResolver()); try { this.table.execute(TableOperation.retrieve(this.ent.getPartitionKey(), this.ent.getRowKey(), Class1.class), this.options, null); fail("Invalid property resolver should throw"); } catch (StorageException e) { assertEquals("Failed to parse property 'fooint' with value '1234' as type 'Edm.Guid'", e.getMessage()); } }
@Test public void testTableOperationRetrieveJsonNoMetadataResolverFail() { // set custom property resolver which throws this.options.setPropertyResolver(new ThrowingPropertyResolver()); try { this.table.execute(TableOperation.retrieve(this.ent.getPartitionKey(), this.ent.getRowKey(), Class1.class), this.options, null); fail("Invalid property resolver should throw"); } catch (StorageException e) { assertEquals( "The custom property resolver delegate threw an exception. Check the inner exception for more details.", e.getMessage()); assertTrue(e.getCause().getClass() == IllegalArgumentException.class); } }
private void doEscapeTest(String data, boolean useBatch, boolean includeInKey) throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata); doEscapeTestHelper(data, useBatch, includeInKey, options); options.setTablePayloadFormat(TablePayloadFormat.Json); doEscapeTestHelper(data, useBatch, includeInKey, options); options.setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata); doEscapeTestHelper(data, useBatch, includeInKey, options); options.setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata); options.setPropertyResolver(new Class1()); doEscapeTestHelper(data, useBatch, includeInKey, options); }
private void doQueryEscapeTest(String data) throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata); doQueryEscapeTestHelper(data, options); options.setTablePayloadFormat(TablePayloadFormat.Json); doQueryEscapeTestHelper(data, options); options.setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata); doQueryEscapeTestHelper(data, options); options.setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata); options.setPropertyResolver(new Class1()); doQueryEscapeTestHelper(data, options); }
private void testWhitespaceTest(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { Class1 ref = new Class1(); ref.setA("B "); ref.setB(" A "); ref.setC(" "); ref.setD(new byte[] { 0, 1, 2 }); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); if (usePropertyResolver) { options.setPropertyResolver(ref); } this.table.execute(TableOperation.insert(ref), options, null); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class), options, null); assertEquals(((Class1) res.getResult()).getA(), ref.getA()); }
private void testNewLineTest(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { Class1 ref = new Class1(); ref.setA("B "); ref.setB(" A "); ref.setC("\r\n"); ref.setD(new byte[] { 0, 1, 2 }); ref.setPartitionKey("jxscl_odata"); ref.setRowKey(UUID.randomUUID().toString()); if (usePropertyResolver) { options.setPropertyResolver(ref); } this.table.execute(TableOperation.insert(ref), options, null); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class), options, null); assertEquals(((Class1) res.getResult()).getA(), ref.getA()); }
options.setPropertyResolver(randEnt);
private void testTableQueryWithFilter(TableRequestOptions options, boolean usePropertyResolver) { Class1 randEnt = TableTestHelper.generateRandomEntity(null); if (usePropertyResolver) { options.setPropertyResolver(randEnt); } TableQuery<Class1> query = TableQuery.from(Class1.class).where( String.format("(PartitionKey eq '%s') and (RowKey ge '%s')", "javatables_batch_1", "000050")); int count = 0; for (Class1 ent : table.execute(query, options, null)) { assertEquals(ent.getA(), randEnt.getA()); assertEquals(ent.getB(), randEnt.getB()); assertEquals(ent.getC(), randEnt.getC()); assertEquals(ent.getPartitionKey(), "javatables_batch_1"); assertEquals(ent.getRowKey(), String.format("%06d", count + 50)); count++; } assertEquals(50, count); }
@Test public void tableBatchRetrieveWithEntityResolver() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata); tableBatchRetrieveWithEntityResolver(options); options.setTablePayloadFormat(TablePayloadFormat.Json); tableBatchRetrieveWithEntityResolver(options); options.setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata); tableBatchRetrieveWithEntityResolver(options); options.setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata); options.setPropertyResolver(new Class1()); tableBatchRetrieveWithEntityResolver(options); }
@Test public void testBatchRetrieve() throws StorageException { TableRequestOptions options = new TableRequestOptions(); options.setTablePayloadFormat(TablePayloadFormat.JsonFullMetadata); testBatchRetrieve(options); options.setTablePayloadFormat(TablePayloadFormat.Json); testBatchRetrieve(options); options.setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata); testBatchRetrieve(options); options.setTablePayloadFormat(TablePayloadFormat.JsonNoMetadata); options.setPropertyResolver(new Class1()); testBatchRetrieve(options); }
private void testTableQueryWithReflection(TableRequestOptions options, boolean usePropertyResolver) { // Create entity to check against Class1 randEnt = TableTestHelper.generateRandomEntity(null); if (usePropertyResolver) { options.setPropertyResolver(randEnt); } final Iterable<Class1> result = table.execute(TableQuery.from(Class1.class), options, null); // Validate results for (Class1 ent : result) { assertEquals(ent.getA(), randEnt.getA()); assertEquals(ent.getB(), randEnt.getB()); assertEquals(ent.getC(), randEnt.getC()); assertTrue(Arrays.equals(ent.getD(), randEnt.getD())); } }
private void testTableQueryWithTake(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { // Create entity to check against Class1 randEnt = TableTestHelper.generateRandomEntity(null); if (usePropertyResolver) { options.setPropertyResolver(randEnt); } final ResultSegment<Class1> result = table.executeSegmented( TableQuery.from(Class1.class).select(new String[] { "A", "C" }).take(25), null, options, null); int count = 0; // Validate results for (Class1 ent : result.getResults()) { count++; assertEquals(ent.getA(), randEnt.getA()); assertEquals(ent.getB(), null); assertEquals(ent.getC(), randEnt.getC()); assertEquals(ent.getD(), null); } assertEquals(count, 25); }
private void testWhitespaceOnEmptyKeysTest(TableRequestOptions options, boolean usePropertyResolver) throws StorageException { Class1 ref = new Class1(); ref.setA("B "); ref.setB(" A "); ref.setC(" "); ref.setD(new byte[] { 0, 1, 2 }); ref.setPartitionKey(""); ref.setRowKey(""); if (usePropertyResolver) { options.setPropertyResolver(ref); } this.table.execute(TableOperation.insert(ref), options, null); TableResult res = this.table.execute( TableOperation.retrieve(ref.getPartitionKey(), ref.getRowKey(), Class1.class), options, null); assertEquals(((Class1) res.getResult()).getA(), ref.getA()); this.table.execute(TableOperation.delete(ref), options, null); }
private void testTableQueryWithProjection(TableRequestOptions options, boolean usePropertyResolver) { // Create entity to check against Class1 randEnt = TableTestHelper.generateRandomEntity(null); if (usePropertyResolver) { options.setPropertyResolver(randEnt); } final Iterable<Class1> result = table.execute(TableQuery.from(Class1.class).select(new String[] { "A", "C" }), options, null); // Validate results for (Class1 ent : result) { // Validate core properties were sent. assertNotNull(ent.getPartitionKey()); assertNotNull(ent.getRowKey()); assertNotNull(ent.getTimestamp()); // Validate correct column returned. assertEquals(ent.getA(), randEnt.getA()); assertEquals(ent.getB(), null); assertEquals(ent.getC(), randEnt.getC()); assertEquals(ent.getD(), null); } }