Package com.exedio.cope.pattern
Class UniqueHashedMedia
- java.lang.Object
-
- com.exedio.cope.Feature
-
- com.exedio.cope.Pattern
-
- com.exedio.cope.pattern.UniqueHashedMedia
-
- All Implemented Interfaces:
Copyable
,Settable<Media.Value>
,Serializable
public final class UniqueHashedMedia extends Pattern implements Settable<Media.Value>, Copyable
Pattern which wraps aMedia
and applies a hash string. This allows uniqueness.- Author:
- knoefel
- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description UniqueHashedMedia(Media mediaTemplate)
Creates a new HashedMedia on the given media template using default values for other properties.UniqueHashedMedia(Media mediaTemplate, String messageDigestAlgorithm)
Creates a new HashedMedia on the given media template.
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
afterModelCreated()
This method is called before the termination of any constructor of classModel
.Feature
copy(CopyMapper mapper)
SetValue<?>[]
execute(Media.Value value, Item exceptionItem)
<P extends Item>
PforHash(Class<P> typeClass, String hash)
Finds an item by the hash value of it's unique hashed media.byte[]
getBody(Item item)
Returns the body of the media.String
getContentType(Item item)
Returns the content type of this media.StringField
getHash()
String
getHash(Item item)
Returns the hash of the body of this media.HashConstraint
getHashConstraint()
UniqueConstraint
getImplicitUniqueConstraint()
Set<Class<? extends Throwable>>
getInitialExceptions()
Returns the exceptions possibly thrown, when setting a value for this settable.Type
getInitialType()
Date
getLastModified(Item item)
Returns the date of the last modification of the media.long
getLength(Item item)
Returns the length of the body of the media.MediaPath.Locator
getLocator(Item item)
Media
getMedia()
String
getMessageDigestAlgorithm()
<P extends Item>
PgetOrCreate(Class<P> typeClass, Media.Value value)
Returns the item containing given media value or creates a new one.String
getURL(Item item)
Condition
hashDoesNotMatch()
Deprecated.UsehashDoesNotMatchIfSupported()
instead.Condition
hashDoesNotMatchIfSupported()
The result may cause anUnsupportedQueryException
when used, if the field is stored in avault
, or thealgorithm
is not supported by the database.Condition
hashMatches()
Deprecated.UsehashMatchesIfSupported()
instead.Condition
hashMatchesIfSupported()
The result may cause anUnsupportedQueryException
when used, if the field is stored in avault
, or thealgorithm
is not supported by the database.boolean
isFinal()
Returns true, if a value for the settable can be specified on the creation of an item only, thus cannot be modified later.boolean
isInitial()
Returns true, if a value for the settable should be specified on the creation of an item.boolean
isMandatory()
protected void
onMount()
Here you can do additional initialization not yet done in the constructor.-
Methods inherited from class com.exedio.cope.Pattern
addSource, addSource, addSource, addSource, addSourceFeature, addSourceFeature, addSourceFeature, annotationField, equals, getGeneratedTypes, getSourceFeatures, getSourceFeaturesGather, getSourceFields, getSources, getSourceTypes, getType, hashCode, initialize, newSourceType, newSourceType, newSourceType, newSourceType, newSourceType, newSourceType, newType, newType, registerSource
-
Methods inherited from class com.exedio.cope.Feature
getAbstractType, getAnnotation, getID, getLocalizationKeys, getName, getPattern, isAnnotationPresent, isSourceAlready, mount, readResolve, requireMounted, toString, toString, writeReplace
-
-
-
-
Constructor Detail
-
UniqueHashedMedia
public UniqueHashedMedia(Media mediaTemplate)
Creates a new HashedMedia on the given media template using default values for other properties.
-
-
Method Detail
-
onMount
protected void onMount()
Description copied from class:Pattern
Here you can do additional initialization not yet done in the constructor. In this method you can call methodsPattern.getType()
andFeature.getName()
for the first time.
-
afterModelCreated
public void afterModelCreated()
Description copied from class:Feature
This method is called before the termination of any constructor of classModel
. It allows any initialization of the feature, that cannot be done earlier. The default implementation is empty.- Overrides:
afterModelCreated
in classFeature
-
getLocator
@Nonnull public MediaPath.Locator getLocator(@Nonnull Item item)
-
getContentType
@Nonnull public String getContentType(@Nonnull Item item)
Returns the content type of this media. Does never return null.
-
getLastModified
@Nonnull public Date getLastModified(@Nonnull Item item)
Returns the date of the last modification of the media. Does never return null.
-
getBody
@Nonnull public byte[] getBody(@Nonnull Item item)
Returns the body of the media. Does never return null.
-
getHash
@Nonnull public String getHash(@Nonnull Item item)
Returns the hash of the body of this media. Does never return null.
-
forHash
@Nullable public <P extends Item> P forHash(@Nonnull Class<P> typeClass, @Nonnull String hash)
Finds an item by the hash value of it's unique hashed media.- Returns:
- null if there is no matching item.
- Throws:
NullPointerException
- if value is null.
-
getOrCreate
@Nullable public <P extends Item> P getOrCreate(@Nonnull Class<P> typeClass, @Nullable Media.Value value) throws IOException, IllegalArgumentException, IllegalContentTypeException
Returns the item containing given media value or creates a new one.- Returns:
- null if and only if value is null.
- Throws:
IOException
- if reading mediaValue throws an IOException.IllegalArgumentException
- if given mediaValue has a content type which is not equal to the content type of an already stored valueIllegalContentTypeException
- if given mediaValue has a content type which is not valid for the implicit Media
-
getImplicitUniqueConstraint
public UniqueConstraint getImplicitUniqueConstraint()
-
getHash
public StringField getHash()
-
getMessageDigestAlgorithm
public String getMessageDigestAlgorithm()
-
getMedia
public Media getMedia()
-
getHashConstraint
public HashConstraint getHashConstraint()
-
copy
public Feature copy(CopyMapper mapper)
-
execute
public SetValue<?>[] execute(Media.Value value, Item exceptionItem)
- Specified by:
execute
in interfaceSettable<Media.Value>
-
isFinal
public boolean isFinal()
Description copied from interface:Settable
Returns true, if a value for the settable can be specified on the creation of an item only, thus cannot be modified later.- Specified by:
isFinal
in interfaceSettable<Media.Value>
-
isMandatory
public boolean isMandatory()
- Specified by:
isMandatory
in interfaceSettable<Media.Value>
-
getInitialType
public Type getInitialType()
- Specified by:
getInitialType
in interfaceSettable<Media.Value>
-
isInitial
public boolean isInitial()
Description copied from interface:Settable
Returns true, if a value for the settable should be specified on the creation of an item.- Specified by:
isInitial
in interfaceSettable<Media.Value>
-
getInitialExceptions
public Set<Class<? extends Throwable>> getInitialExceptions()
Description copied from interface:Settable
Returns the exceptions possibly thrown, when setting a value for this settable.- Specified by:
getInitialExceptions
in interfaceSettable<Media.Value>
-
hashMatchesIfSupported
@Nonnull public Condition hashMatchesIfSupported()
The result may cause anUnsupportedQueryException
when used, if the field is stored in avault
, or thealgorithm
is not supported by the database.
-
hashDoesNotMatchIfSupported
@Nonnull public Condition hashDoesNotMatchIfSupported()
The result may cause anUnsupportedQueryException
when used, if the field is stored in avault
, or thealgorithm
is not supported by the database.
-
hashMatches
@Deprecated @Nonnull public Condition hashMatches()
Deprecated.UsehashMatchesIfSupported()
instead.
-
hashDoesNotMatch
@Deprecated @Nonnull public Condition hashDoesNotMatch()
Deprecated.UsehashDoesNotMatchIfSupported()
instead.
-
-