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
Pattern which wraps a
Media
and applies a hash string. This allows
uniqueness.- Author:
- knoefel
- See Also:
-
Constructor Summary
ConstructorsConstructorDescriptionUniqueHashedMedia
(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
Modifier and TypeMethodDescriptionvoid
This method is called before the termination of any constructor of classModel
.copy
(CopyMapper mapper) SetValue<?>[]
execute
(Media.Value value, Item exceptionItem) <P extends Item>
PFinds an item by the hash value of it's unique hashed media.byte[]
Returns the body of the media.getContentType
(Item item) Returns the content type of this media.getHash()
Returns the hash of the body of this media.Returns the exceptions possibly thrown, when setting a value for this settable.getLastModified
(Item item) Returns the date of the last modification of the media.long
Returns the length of the body of the media.getLocator
(Item item) getMedia()
<P extends Item>
PgetOrCreate
(Class<P> typeClass, Media.Value value) Returns the item containing given media value or creates a new one.Deprecated.The result may cause anUnsupportedQueryException
when used, if the field is stored in avault
, or thealgorithm
is not supported by the database.Deprecated.UsehashMatchesIfSupported()
instead.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
Returns true, if a value for the settable should be specified on the creation of an item.boolean
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 Details
-
UniqueHashedMedia
Creates a new HashedMedia on the given media template using default values for other properties. -
UniqueHashedMedia
Creates a new HashedMedia on the given media template. Note: given media template must be mandatory
-
-
Method Details
-
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
-
getURL
-
getLocator
-
getContentType
Returns the content type of this media. Does never return null. -
getLastModified
Returns the date of the last modification of the media. Does never return null. -
getLength
Returns the length of the body of the media. -
getBody
Returns the body of the media. Does never return null. -
getHash
Returns the hash of the body of this media. Does never return null. -
forHash
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
-
getHash
-
getMessageDigestAlgorithm
-
getMedia
-
getHashConstraint
-
copy
-
execute
- 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
- 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
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
The result may cause anUnsupportedQueryException
when used, if the field is stored in avault
, or thealgorithm
is not supported by the database. -
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.UsehashMatchesIfSupported()
instead. -
hashDoesNotMatch
Deprecated.UsehashDoesNotMatchIfSupported()
instead.
-
hashDoesNotMatchIfSupported()
instead.