public class AttachmentManager
extends java.lang.Object
attachmentsDir
parameter to each method. AttachmentManager assumes it has sole control of this directory.
For example, purging and compaction may delete non-attachment files.Modifier and Type | Class and Description |
---|---|
static class |
AttachmentManager.NameGenerationException |
Modifier and Type | Field and Description |
---|---|
static java.lang.String |
SQL_ATTACHMENTS_SELECT |
static java.lang.String |
SQL_ATTACHMENTS_SELECT_ALL |
Constructor and Description |
---|
AttachmentManager() |
Modifier and Type | Method and Description |
---|---|
static void |
addAttachment(SQLDatabase db,
java.lang.String attachmentsDir,
DocumentRevision rev,
PreparedAttachment a) |
static void |
addAttachmentsToRevision(SQLDatabase db,
java.lang.String attachmentsDir,
DocumentRevision rev,
java.util.List<PreparedAttachment> attachments) |
static void |
copyAttachment(SQLDatabase db,
long parentSequence,
long newSequence,
java.lang.String filename)
Copy a single attachment for a given revision to a new revision.
|
static void |
copyAttachmentsToRevision(SQLDatabase db,
java.util.List<SavedAttachment> attachments,
DocumentRevision rev) |
static java.io.File |
fileFromKey(SQLDatabase db,
byte[] key,
java.lang.String attachmentsDir,
boolean allowCreateName)
Lookup or create a on disk File representation of blob, in
db using key . |
static java.util.List<SavedAttachment> |
findExistingAttachments(java.util.Collection<? extends Attachment> attachments)
Return a list of the existing attachments in the list passed in.
|
static java.util.List<Attachment> |
findNewAttachments(java.util.Collection<? extends Attachment> attachments)
Return a list of the new attachments in the list passed in.
|
static PreparedAttachment |
prepareAttachment(java.lang.String attachmentsDir,
AttachmentStreamFactory attachmentStreamFactory,
Attachment attachment)
Creates a PreparedAttachment from
attachment , preparing it for insertion into
the datastore. |
static java.util.List<PreparedAttachment> |
prepareAttachments(java.lang.String attachmentsDir,
AttachmentStreamFactory attachmentStreamFactory,
java.util.List<Attachment> attachments)
Download each attachment in
attachments to a temporary location, and
return a list of attachments suitable for passing to setAttachments . |
static void |
purgeAttachments(SQLDatabase db,
java.lang.String attachmentsDir)
Called by BasicDatastore on the execution queue, this needs have the db passed ot it
|
public static final java.lang.String SQL_ATTACHMENTS_SELECT
public static final java.lang.String SQL_ATTACHMENTS_SELECT_ALL
public static void addAttachmentsToRevision(SQLDatabase db, java.lang.String attachmentsDir, DocumentRevision rev, java.util.List<PreparedAttachment> attachments) throws AttachmentNotSavedException
AttachmentNotSavedException
public static void addAttachment(SQLDatabase db, java.lang.String attachmentsDir, DocumentRevision rev, PreparedAttachment a) throws AttachmentNotSavedException
AttachmentNotSavedException
public static PreparedAttachment prepareAttachment(java.lang.String attachmentsDir, AttachmentStreamFactory attachmentStreamFactory, Attachment attachment) throws AttachmentException
attachment
, preparing it for insertion into
the datastore.attachmentStreamFactory
- attachment
- Attachment to prepare for insertion into datastoreAttachmentException
- if there was an error preparing the attachment, e.g., reading
attachment data.public static java.util.List<SavedAttachment> findExistingAttachments(java.util.Collection<? extends Attachment> attachments)
attachments
- Attachments to search.public static java.util.List<Attachment> findNewAttachments(java.util.Collection<? extends Attachment> attachments)
attachments
- Attachments to search.public static java.util.List<PreparedAttachment> prepareAttachments(java.lang.String attachmentsDir, AttachmentStreamFactory attachmentStreamFactory, java.util.List<Attachment> attachments) throws AttachmentException
attachments
to a temporary location, and
return a list of attachments suitable for passing to setAttachments
.
Typically attachments
is found via a call to findNewAttachments(java.util.Collection<? extends com.cloudant.sync.datastore.Attachment>)
.attachments
- List of attachments to prepare.AttachmentException
findNewAttachments(java.util.Collection<? extends com.cloudant.sync.datastore.Attachment>)
public static void copyAttachmentsToRevision(SQLDatabase db, java.util.List<SavedAttachment> attachments, DocumentRevision rev) throws DatastoreException
DatastoreException
public static void copyAttachment(SQLDatabase db, long parentSequence, long newSequence, java.lang.String filename) throws java.sql.SQLException
db
- database to useparentSequence
- identifies sequence number of revision to copy attachment data fromnewSequence
- identifies sequence number of revision to copy attachment data tofilename
- filename of attachment to copyjava.sql.SQLException
public static void purgeAttachments(SQLDatabase db, java.lang.String attachmentsDir)
db
- database to purge attachments frompublic static java.io.File fileFromKey(SQLDatabase db, byte[] key, java.lang.String attachmentsDir, boolean allowCreateName) throws AttachmentException
db
using key
.
Existing attachments will have an entry in db, so the method just looks this up
and returns the File object for the path.
For new attachments, the key
doesn't already have an associated filename,
one is generated and inserted into the database before returning a File object
for blob associated with key
.db
- database to use.key
- key to lookup filename for.attachmentsDir
- Root directory for attachment blobs.allowCreateName
- if the is no existing mapping, whether one should be created
and returned. If false, and no existing mapping, AttachmentException
is thrown.key
.AttachmentException
- if a mapping doesn't exist and allowCreateName
is
false or if the name generation process fails.