Skip to content

Commit 4fd4dc7

Browse files
authored
Merge branch 'master' into imds-token-other-calls
2 parents a32dada + 362ea4f commit 4fd4dc7

File tree

10 files changed

+486
-175
lines changed

10 files changed

+486
-175
lines changed
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
"type": "feature",
3+
"category": "AWS SDK for Java v2",
4+
"description": "Add `RequestBody.fromRemainingByteBuffer(ByteBuffer)` that copies only the remaining readable bytes of the buffer. See [#1534](https://github.com/aws/aws-sdk-java-v2/issues/1534)"
5+
}

core/sdk-core/src/main/java/software/amazon/awssdk/core/sync/RequestBody.java

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,9 @@ public static RequestBody fromBytes(byte[] bytes) {
161161
/**
162162
* Creates a {@link RequestBody} from a {@link ByteBuffer}. Buffer contents are copied so any modifications
163163
* made to the original {@link ByteBuffer} are not reflected in the {@link RequestBody}.
164+
* <p>
165+
* <b>NOTE:</b> This method always copies the entire contents of the buffer, ignoring the current read position. Use
166+
* {@link #fromRemainingByteBuffer(ByteBuffer)} if you need it to copy only the remaining readable bytes.
164167
*
165168
* @param byteBuffer ByteBuffer to send to the service.
166169
* @return RequestBody instance.
@@ -169,6 +172,18 @@ public static RequestBody fromByteBuffer(ByteBuffer byteBuffer) {
169172
return fromBytesDirect(BinaryUtils.copyAllBytesFrom(byteBuffer));
170173
}
171174

175+
/**
176+
* Creates a {@link RequestBody} from the remaining readable bytes from a {@link ByteBuffer}. Unlike
177+
* {@link #fromByteBuffer(ByteBuffer)}, this method respects the current read position of the buffer and reads only
178+
* the remaining bytes. The buffer is copied before reading so no changes are made to original buffer.
179+
*
180+
* @param byteBuffer ByteBuffer to send to the service.
181+
* @return RequestBody instance.
182+
*/
183+
public static RequestBody fromRemainingByteBuffer(ByteBuffer byteBuffer) {
184+
return fromBytesDirect(BinaryUtils.copyRemainingBytesFrom(byteBuffer));
185+
}
186+
172187
/**
173188
* Creates a {@link RequestBody} with no content.
174189
*

core/sdk-core/src/test/java/software/amazon/awssdk/core/sync/RequestBodyTest.java

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import com.google.common.jimfs.Configuration;
2121
import com.google.common.jimfs.Jimfs;
2222
import java.io.File;
23-
import java.io.FileInputStream;
2423
import java.io.FileWriter;
2524
import java.io.IOException;
2625
import java.io.InputStream;
@@ -104,4 +103,23 @@ public void emptyBytesConstructorHasCorrectContentType() {
104103
RequestBody requestBody = RequestBody.empty();
105104
assertThat(requestBody.contentType()).isEqualTo(Mimetype.MIMETYPE_OCTET_STREAM);
106105
}
106+
107+
@Test
108+
public void remainingByteBufferConstructorOnlyRemainingBytesCopied() throws IOException {
109+
ByteBuffer bb = ByteBuffer.allocate(4);
110+
bb.put(new byte[]{1, 2, 3, 4});
111+
bb.flip();
112+
113+
bb.get();
114+
bb.get();
115+
116+
int originalRemaining = bb.remaining();
117+
118+
RequestBody requestBody = RequestBody.fromRemainingByteBuffer(bb);
119+
120+
assertThat(requestBody.contentLength()).isEqualTo(originalRemaining);
121+
122+
byte[] requestBodyBytes = IoUtils.toByteArray(requestBody.contentStreamProvider().newStream());
123+
assertThat(ByteBuffer.wrap(requestBodyBytes)).isEqualTo(bb);
124+
}
107125
}

docs/design/services/dynamodb/high-level-library/README.md

Lines changed: 13 additions & 174 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
**Design:** New Feature, **Status:**
2-
[In Development](../../../README.md)
1+
**Design:** New Feature, **Status:** [Public Preview](../../../../../services-custom/dynamodb-enhanced/README.md)
32

43
## Tenets (unless you know better ones)
54

@@ -38,182 +37,22 @@ including AWS's own Document and Mapper Clients.
3837

3938
The AWS SDK for Java will add a new "enhanced DynamoDB client" that
4039
provides an alternative to the data-access portion of the generated
41-
DynamoDB APIs. Control-plane operations like "create table" will not be
42-
supported at launch, but may be added at a later time.
40+
DynamoDB APIs. Only limited control-plane operations will be available,
41+
specifically 'createTable'.
4342

4443
This enhanced client will make DynamoDB easier to use for Java customers
4544
by:
4645
1. Supporting conversions between Java objects and DynamoDB items
47-
2. Supporting conversions between Java built-in types (eg. `Instant`)
48-
and DynamoDB attribute value types
49-
3. Directly supporting every data-plane operation of DynamoDB
50-
4. Using the same verbs and nouns of DynamoDB
51-
52-
## Implementation Overview
53-
54-
**New Clients**
55-
56-
Two new client classes will be added:
57-
`DynamoDbEnhancedClient` and `DynamoDbEnhancedAsyncClient`. These
58-
classes act as a wrapper around the generated `DynamoDbClient` and
59-
`DynamoDbAsyncClient` classes, to provide additional functionality on
60-
top of that which can be provided by the generated clients.
61-
62-
```java
63-
DynamoDbEnhancedClient enhancedClient =
64-
DynamoDbEnhancedClient.builder()
65-
.dynamoDbClient(DynamoDbClient.create())
66-
.build();
67-
```
68-
69-
**Table Abstraction**
70-
71-
`DynamoDbEnhancedClient` provides access to `Table` and `MappedTable`,
72-
and `DynamoDbEnhancedAsyncClient`provides access to `AsyncTable`, and
73-
`AsyncMappedTable` abstractions.
74-
75-
The operations on these "tables" match the data-plane operations in the
76-
low-level DynamoDB client. For example, because `DynamoDbClient.putItem`
77-
exists, `Table.putItem` will also exist.
78-
79-
`Table` and `AsyncTable` work with "items", described below.
80-
`MappedTable` and `AsyncMappedTable` work with "objects", described
81-
below. `Table` and `MappedTable` returning results synchronously, and
82-
`AsyncTable` and `AsyncMappedTable` returning results asynchronously.
83-
84-
```java
85-
Table booksTable = enhancedClient.table("books");
86-
booksTable.putItem(...);
87-
88-
MappedTable mappedBooksTable = enhancedClient.mappedTable("books");
89-
mappedBooksTable.putItem(...);
90-
```
91-
92-
**Item Abstraction**
93-
94-
The operations on `Table` and `AsyncTable` work on `Item`s. An `Item` is
95-
a user-friendly representation of the generated `Map<String,
96-
AttributeValue>`. `Item`s support automatic type conversion between Java
97-
built-in types and DynamoDB-specific `AttributeValue` types.
98-
99-
```java
100-
booksTable.putItem(Item.builder()
101-
.putAttribute("isbn", "0-330-25864-8")
102-
.putAttribute("title", "The Hitchhiker's Guide to the Galaxy")
103-
.putAttribute("creationDate", Instant.now())
104-
.build());
105-
```
106-
107-
The `Table` and `AsyncTable` abstractions can be seen as a replacement
108-
for the 1.11.x DynamoDB Document client.
109-
110-
**Object Abstraction**
111-
112-
The operations on `MappedTable` and `AsyncMappedTable` work on Java
113-
objects (at launch, Java beans). These objects are automatically
114-
converted by the enhanced client to the generated `Map<String,
115-
AttributeValue>`. It's likely that the `MappedTable` and
116-
`AsyncMappedTable` will use the `Table` and `AsyncTable` as an
117-
implementation detail.
118-
119-
```java
120-
Book book = new Book();
121-
book.setIsbn("0-330-25864-8");
122-
book.setTitle("The Hitchhiker's Guide to the Galaxy");
123-
book.setCreationDate(Instant.now());
124-
mappedBooksTable.putItem(book);
125-
```
126-
127-
The `MappedTable` and `AsyncMappedTable` abstractions can be seen as a
128-
replacement for the 1.11.x DynamoDB Mapper client.
129-
130-
**Type Conversion**
131-
132-
The core feature of the mapper is the ability to convert common Java
133-
structures (e.g. Java beans) and types (e.g. `Instant`, `Number`) into
134-
DynamoDB attribute values.
135-
136-
These conversions are performed based on the types specified by the
137-
customer. For example, the SDK will automatically convert any `Number`
138-
types specified by the customer (as an Item attribute) into a DynamoDB
139-
number.
140-
141-
The customer has the ability to configure the type converters used at
142-
the `Item` or `DynamoDbEnhanced[Async]Client`-level. This allows the
143-
customer to add support for unsupported types, change the DynamoDB type
144-
associated with a Java type (e.g. storing an `Instant` as a DynamoDB
145-
string instead of a number), or to add support for custom POJO
146-
conversion logic (i.e. other than Java beans). This also allows the
147-
customer to provide a hard-coded converter for a specific object type
148-
that performs more efficiently than the built-in reflection-based object
149-
converter.
150-
151-
## Features
152-
153-
**Launch Features**
154-
155-
These features are intended for inclusion at launch of the library.
156-
157-
1. Support for all existing data plane operations: get, put, query,
158-
update, scan, delete, batch get, batch put, transaction get, and
159-
transaction put.
160-
2. Support for `[Async]Table` and `[Async]MappedTable`, as described
161-
above.
162-
3. Support for bean-based representations in `[Async]MappedTable`.
163-
4. Type converters for all Java built-in types that are currently
164-
supported by [Joda Convert](https://www.joda.org/joda-convert/).
165-
166-
| API | Feature | Development | Usability Study |
167-
| --- | --- | --- | --- |
168-
| Item | Get | Done | |
169-
| | Put | Done | |
170-
| | Query | | |
171-
| | Update | | |
172-
| | Scan | | |
173-
| | Delete | | |
174-
| | Batch Get | | |
175-
| | Batch Put | | |
176-
| | Transaction Get | | |
177-
| | Transaction Put | | |
178-
| Object | Get | | |
179-
| | Put | | |
180-
| | Query | | |
181-
| | Update | | |
182-
| | Scan | | |
183-
| | Delete | | |
184-
| | Batch Get | | |
185-
| | Batch Put | | |
186-
| | Transaction Get | | |
187-
| | Transaction Put | | |
188-
| All | Type Support | In Progress | |
189-
190-
**Post-Launch Features**
191-
192-
1. Support for inheritance in `[Async]MappedTable`.
193-
2. Support for immutable objects in `[Async]MappedTable`.
194-
3. Support for projection statements in `[Async]Table` and
195-
`[Async]MappedTable`.
196-
4. Support for DynamoDB-provided API metrics (e.g. consumed capacity).
197-
5. A `software.amazon.aws:dynamodb-all` module that automatically
198-
includes all AWS DynamoDB artifacts, to enhance client
199-
discoverability.
200-
201-
**Missing Features**
202-
203-
These features are not intended for inclusion at launch of the library
204-
(but may be added at a future time).
205-
206-
1. Support for control-plane operations, like create or delete table.
207-
*Justification for exclusion:* For testing purposes, this can be done
208-
through the AWS console or low-level SDK. For production purposes,
209-
this should be done through the AWS CDK or cloud formation.
210-
2. Versioning and UUID annotations. *Justification for exclusion:* This
211-
is a higher-level concern than the "type converter" goal that the
212-
enhanced client is attempting to deliver on. This is a piece of
213-
functionality that will be built on-top of the enhanced client, not
214-
in it.
46+
2. Directly supporting every data-plane operation of DynamoDB
47+
3. Using the same verbs and nouns of DynamoDB
48+
4. Support for tests, such as the ability to create tables using the
49+
same models as the data plane operations.
50+
51+
A fully functional public preview is available for this library. See
52+
[DynamoDb Enhanced Public Preview
53+
Library](../../../../../services-custom/dynamodb-enhanced/README.md).
21554

216-
**Requested Features**
55+
## Appendix A: Requested Features
21756

21857
* [Immutable classes](https://github.com/aws/aws-sdk-java-v2/issues/35#issuecomment-315049138)
21958
* [Getter/setter-less fields](https://github.com/aws/aws-sdk-java/issues/547)
@@ -257,7 +96,7 @@ These features are not intended for inclusion at launch of the library
25796
runtime (from email)
25897
* Structure versioning (from email)
25998

260-
## Appendix A: Alternative Solutions
99+
## Appendix B: Alternative Solutions
261100

262101
### Alternative Solution 1: Level 3 Storage Library
263102

0 commit comments

Comments
 (0)