Skip to content

Commit be96e86

Browse files
committed
requested changes
1 parent 40d4946 commit be96e86

3 files changed

Lines changed: 16 additions & 2 deletions

File tree

readme.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public AttachmentDataSource attachmentDataSource(JdbcTemplate jdbcTemplate) {
3030
}
3131
```
3232

33+
By default, `JdbcAttachmentDataSource` creates its table on startup. If you prefer to manage the table yourself
34+
(e.g. via Liquibase), disable the built-in migration using the constructor-flag and create the table in your own migrations.
35+
3336
#### Inline (CID) attachments
3437

3538
To embed an attachment inline, set a `contentId` on the attachment and reference it in the `htmlBody` via the `cid:` scheme.

src/main/java/it/aboutbits/springboot/emailservice/lib/application/JdbcAttachmentDataSource.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,14 @@ public class JdbcAttachmentDataSource implements AttachmentDataSource {
1818
private final JdbcTemplate jdbcTemplate;
1919

2020
public JdbcAttachmentDataSource(JdbcTemplate jdbcTemplate) {
21+
this(jdbcTemplate, true);
22+
}
23+
24+
public JdbcAttachmentDataSource(JdbcTemplate jdbcTemplate, boolean runMigrations) {
2125
this.jdbcTemplate = jdbcTemplate;
22-
migrate();
26+
if (runMigrations) {
27+
migrate();
28+
}
2329
}
2430

2531
private void migrate() {

src/main/java/it/aboutbits/springboot/emailservice/lib/application/UnavailableAttachmentDataSource.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import it.aboutbits.springboot.emailservice.lib.exception.AttachmentException;
55
import org.jspecify.annotations.NullMarked;
66

7+
import java.io.IOException;
78
import java.io.InputStream;
89

910
@NullMarked
@@ -15,7 +16,11 @@ public InputStream getAttachmentPayload(long fileReference) throws AttachmentExc
1516

1617
@Override
1718
public long storeAttachmentPayload(InputStream payload) throws AttachmentException {
18-
throw new AttachmentException("attachments not available");
19+
try (payload) {
20+
throw new AttachmentException("attachments not available");
21+
} catch (IOException e) {
22+
throw new AttachmentException("attachments not available", e);
23+
}
1924
}
2025

2126
@Override

0 commit comments

Comments
 (0)