Package org.apache.openjpa.persistence
Class AnnotationPersistenceMetaDataSerializer
- java.lang.Object
-
- org.apache.openjpa.persistence.AnnotationPersistenceMetaDataSerializer
-
- All Implemented Interfaces:
MetaDataSerializer
,AbstractCFMetaDataFactory.Serializer
- Direct Known Subclasses:
AnnotationPersistenceMappingSerializer
public class AnnotationPersistenceMetaDataSerializer extends java.lang.Object implements AbstractCFMetaDataFactory.Serializer
Serializes persistence metadata as annotations. This class processes all object level tags that are store-agnostic. However, it provides hooks for the subclasses to include store-specific tags to be serialized both at <entity-mappings> and <entity> level.- Since:
- 1.0.0
- Author:
- Steve Kim, Gokhan Ergul
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AnnotationPersistenceMetaDataSerializer.SerializationComparator
Compares clases, sequences, and queries to order them for serialization.
-
Field Summary
Fields Modifier and Type Field Description protected static int
TYPE_CLASS_QUERIES
protected static int
TYPE_CLASS_SEQS
protected static int
TYPE_META
protected static int
TYPE_QUERY
protected static int
TYPE_SEQ
-
Fields inherited from interface org.apache.openjpa.lib.meta.MetaDataSerializer
APPEND, COMPACT, PRETTY, VERBOSE
-
-
Constructor Summary
Constructors Constructor Description AnnotationPersistenceMetaDataSerializer(OpenJPAConfiguration conf)
Constructor.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addAll(MetaDataRepository repos)
Add all components in the given repository to the set to be serialized.protected AnnotationBuilder
addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annType, ClassMetaData meta)
Creates an an annotation builder for the specified class metadata and adds it to list of builders.protected AnnotationBuilder
addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annType, FieldMetaData meta)
Creates an an annotation builder for the specified class metadata and adds it to list of builders.protected AnnotationBuilder
addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annType, QueryMetaData meta)
Creates an an annotation builder for the specified class metadata and adds it to list of builders.protected AnnotationBuilder
addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annType, SequenceMetaData meta)
Creates an an annotation builder for the specified class metadata and adds it to list of builders.protected void
addAnnotation(AnnotationBuilder ab, java.lang.Object meta)
protected void
addAnnotation(AnnotationBuilder ab, ClassMetaData meta)
Add an annotation builder to list of builders for the specified class metadata.protected void
addAnnotation(AnnotationBuilder ab, FieldMetaData meta)
Add an annotation builder to list of builders for the specified field metadata.protected void
addAnnotation(AnnotationBuilder ab, QueryMetaData meta)
Add an annotation builder to list of builders for the specified query metadata.protected void
addAnnotation(AnnotationBuilder ab, SequenceMetaData meta)
Add an annotation builder to list of builders for the specified sequence metadata.protected void
addClassMappingAnnotations(ClassMetaData mapping)
Add mapping attributes for the given class.protected void
addFieldMappingAttributes(FieldMetaData fmd, FieldMetaData orig, AnnotationBuilder ab)
Add mapping attributes for the given field.void
addMetaData(ClassMetaData meta)
Add a class meta data to the set to be serialized.void
addQueryMetaData(QueryMetaData meta)
Add a query meta data to the set to be serialized.void
addSequenceMetaData(SequenceMetaData meta)
Add a sequence meta data to the set to be serialized.protected void
addStrategyMappingAttributes(FieldMetaData fmd, AnnotationBuilder ab)
Set mapping attributes for strategy.protected void
addSystemMappingElements(java.util.Collection toSerialize)
Add system-level mapping elements to be serialized.void
clear()
Clear the set of metadatas to be serialized.java.util.Map<java.lang.String,ClassMetaData>
getClassMetaData()
Returns the stored ClassMetaDataOpenJPAConfiguration
getConfiguration()
Configuration.Log
getLog()
The log to write to.int
getMode()
The serialization mode according to the expected document type.protected java.util.Collection
getObjects()
protected PersistenceStrategy
getStrategy(FieldMetaData fmd)
Return the serialized strategy name.protected boolean
isMappingMode()
Convenience method for interpretinggetMode()
.protected boolean
isMappingMode(ClassMetaData meta)
Convenience method for interpretinggetMode()
.protected boolean
isMappingMode(ValueMetaData vmd)
Convenience method for interpretinggetMode()
.protected boolean
isMetaDataMode()
Convenience method for interpretinggetMode()
.protected boolean
isQueryMode()
Convenience method for interpretinggetMode()
.protected AnnotationBuilder
newAnnotationBuilder(java.lang.Class<? extends java.lang.annotation.Annotation> annType)
Creates a new annotation builder for the specified annotation type.protected AnnotationPersistenceMetaDataSerializer.SerializationComparator
newSerializationComparator()
Create a new comparator for ordering objects that are to be serialized.boolean
removeAll(MetaDataRepository repos)
Remove all the components in the given repository from the set to be serialized.boolean
removeMetaData(ClassMetaData meta)
Remove a metadata from the set to be serialized.boolean
removeQueryMetaData(QueryMetaData meta)
Remove a query metadata from the set to be serialized.boolean
removeSequenceMetaData(SequenceMetaData meta)
Remove a sequence metadata from the set to be serialized.void
serialize(int flags)
Serialize the current set of objects to the files from which they were parsed.void
serialize(java.io.File file, int flags)
Serialize the current set of objects to the given file.void
serialize(java.io.Writer out, int flags)
Serialize the current set of objects to the given stream.protected void
serialize(java.util.Collection objects)
void
serialize(java.util.Map output, int flags)
Serialize the current set of objects to the files from which they were parsed.protected boolean
serializeAttributeOverride(FieldMetaData fmd, FieldMetaData orig)
Always returns false by default.protected void
serializeAttributeOverrideMappingContent(FieldMetaData fmd, FieldMetaData orig, AnnotationBuilder ab)
Serialize attribute override mapping content.protected void
serializeClass(ClassMetaData meta)
Serialize class metadata.protected void
serializeClassMappingContent(ClassMetaData mapping)
Serialize class mapping content.protected void
serializeFieldMappingContent(FieldMetaData fmd, PersistenceStrategy strategy, AnnotationBuilder ab)
Serialize field mapping content; this will be called before#serializeValueMappingContent
.protected void
serializeInheritanceContent(ClassMetaData mapping)
Serialize inheritance content.protected void
serializeQueryMappings(ClassMetaData meta)
Serialize query mappings.protected void
serializeSequence(SequenceMetaData meta)
Serialize sequence metadata.protected void
serializeSystemMappingElement(java.lang.Object obj)
Serialize unknown mapping element at system level.void
setLog(Log log)
The log to write to.void
setMode(int mode)
The serialization mode according to the expected document type.void
setMode(int mode, boolean on)
The serialization mode according to the expected document type.protected int
type(java.lang.Object o)
Return the type constant for the given object based on its runtime class.protected void
writeAnnotations(java.lang.Object meta, java.util.List<AnnotationBuilder> builders, java.util.Map output)
-
-
-
Field Detail
-
TYPE_SEQ
protected static final int TYPE_SEQ
- See Also:
- Constant Field Values
-
TYPE_QUERY
protected static final int TYPE_QUERY
- See Also:
- Constant Field Values
-
TYPE_META
protected static final int TYPE_META
- See Also:
- Constant Field Values
-
TYPE_CLASS_SEQS
protected static final int TYPE_CLASS_SEQS
- See Also:
- Constant Field Values
-
TYPE_CLASS_QUERIES
protected static final int TYPE_CLASS_QUERIES
- See Also:
- Constant Field Values
-
-
Constructor Detail
-
AnnotationPersistenceMetaDataSerializer
public AnnotationPersistenceMetaDataSerializer(OpenJPAConfiguration conf)
Constructor. Supply configuration.
-
-
Method Detail
-
getConfiguration
public OpenJPAConfiguration getConfiguration()
Configuration.
-
getLog
public Log getLog()
The log to write to.
-
setLog
public void setLog(Log log)
The log to write to.
-
getMode
public int getMode()
The serialization mode according to the expected document type. The mode constants act as bit flags, and therefore can be combined.
-
setMode
public void setMode(int mode)
The serialization mode according to the expected document type. The mode constants act as bit flags, and therefore can be combined.- Specified by:
setMode
in interfaceAbstractCFMetaDataFactory.Serializer
-
setMode
public void setMode(int mode, boolean on)
The serialization mode according to the expected document type.
-
isMetaDataMode
protected boolean isMetaDataMode()
Convenience method for interpretinggetMode()
.
-
isQueryMode
protected boolean isQueryMode()
Convenience method for interpretinggetMode()
.
-
isMappingMode
protected boolean isMappingMode()
Convenience method for interpretinggetMode()
.
-
isMappingMode
protected boolean isMappingMode(ClassMetaData meta)
Convenience method for interpretinggetMode()
. Takes into account whether mapping information is loaded for the given instance. OPENJPA-1360 - Allow @Column attributes when meta.isEmbeddedOnly()
-
isMappingMode
protected boolean isMappingMode(ValueMetaData vmd)
Convenience method for interpretinggetMode()
. Takes into account whether mapping information is loaded for the given instance.
-
addMetaData
public void addMetaData(ClassMetaData meta)
Add a class meta data to the set to be serialized.- Specified by:
addMetaData
in interfaceAbstractCFMetaDataFactory.Serializer
-
addSequenceMetaData
public void addSequenceMetaData(SequenceMetaData meta)
Add a sequence meta data to the set to be serialized.- Specified by:
addSequenceMetaData
in interfaceAbstractCFMetaDataFactory.Serializer
-
addQueryMetaData
public void addQueryMetaData(QueryMetaData meta)
Add a query meta data to the set to be serialized.- Specified by:
addQueryMetaData
in interfaceAbstractCFMetaDataFactory.Serializer
-
addAll
public void addAll(MetaDataRepository repos)
Add all components in the given repository to the set to be serialized.- Specified by:
addAll
in interfaceAbstractCFMetaDataFactory.Serializer
-
removeMetaData
public boolean removeMetaData(ClassMetaData meta)
Remove a metadata from the set to be serialized.- Specified by:
removeMetaData
in interfaceAbstractCFMetaDataFactory.Serializer
- Returns:
- true if removed, false if not in set
-
removeSequenceMetaData
public boolean removeSequenceMetaData(SequenceMetaData meta)
Remove a sequence metadata from the set to be serialized.- Returns:
- true if removed, false if not in set
-
removeQueryMetaData
public boolean removeQueryMetaData(QueryMetaData meta)
Remove a query metadata from the set to be serialized.- Returns:
- true if removed, false if not in set
-
removeAll
public boolean removeAll(MetaDataRepository repos)
Remove all the components in the given repository from the set to be serialized.- Returns:
- true if any components removed, false if none in set
-
clear
public void clear()
Clear the set of metadatas to be serialized.
-
addSystemMappingElements
protected void addSystemMappingElements(java.util.Collection toSerialize)
Add system-level mapping elements to be serialized. Does nothing by default.
-
newSerializationComparator
protected AnnotationPersistenceMetaDataSerializer.SerializationComparator newSerializationComparator()
Create a new comparator for ordering objects that are to be serialized.
-
newAnnotationBuilder
protected AnnotationBuilder newAnnotationBuilder(java.lang.Class<? extends java.lang.annotation.Annotation> annType)
Creates a new annotation builder for the specified annotation type.
-
addAnnotation
protected void addAnnotation(AnnotationBuilder ab, java.lang.Object meta)
-
addAnnotation
protected void addAnnotation(AnnotationBuilder ab, ClassMetaData meta)
Add an annotation builder to list of builders for the specified class metadata.
-
addAnnotation
protected void addAnnotation(AnnotationBuilder ab, FieldMetaData meta)
Add an annotation builder to list of builders for the specified field metadata.
-
addAnnotation
protected void addAnnotation(AnnotationBuilder ab, SequenceMetaData meta)
Add an annotation builder to list of builders for the specified sequence metadata.
-
addAnnotation
protected void addAnnotation(AnnotationBuilder ab, QueryMetaData meta)
Add an annotation builder to list of builders for the specified query metadata.
-
addAnnotation
protected AnnotationBuilder addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annType, ClassMetaData meta)
Creates an an annotation builder for the specified class metadata and adds it to list of builders.
-
addAnnotation
protected AnnotationBuilder addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annType, FieldMetaData meta)
Creates an an annotation builder for the specified class metadata and adds it to list of builders.
-
addAnnotation
protected AnnotationBuilder addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annType, SequenceMetaData meta)
Creates an an annotation builder for the specified class metadata and adds it to list of builders.
-
addAnnotation
protected AnnotationBuilder addAnnotation(java.lang.Class<? extends java.lang.annotation.Annotation> annType, QueryMetaData meta)
Creates an an annotation builder for the specified class metadata and adds it to list of builders.
-
serialize
protected void serialize(java.util.Collection objects)
-
type
protected int type(java.lang.Object o)
Return the type constant for the given object based on its runtime class. If the runtime class does not correspond to any of the known types then returns -1. This can happen for tags that are not handled at this store-agnostic level.
-
serializeSystemMappingElement
protected void serializeSystemMappingElement(java.lang.Object obj)
Serialize unknown mapping element at system level.
-
serializeSequence
protected void serializeSequence(SequenceMetaData meta)
Serialize sequence metadata.
-
serializeClass
protected void serializeClass(ClassMetaData meta)
Serialize class metadata.
-
addClassMappingAnnotations
protected void addClassMappingAnnotations(ClassMetaData mapping)
Add mapping attributes for the given class. Does nothing by default
-
serializeClassMappingContent
protected void serializeClassMappingContent(ClassMetaData mapping)
Serialize class mapping content. Does nothing by default.
-
serializeInheritanceContent
protected void serializeInheritanceContent(ClassMetaData mapping)
Serialize inheritance content. Does nothing by default.
-
serializeQueryMappings
protected void serializeQueryMappings(ClassMetaData meta)
Serialize query mappings. Does nothing by default.
-
addFieldMappingAttributes
protected void addFieldMappingAttributes(FieldMetaData fmd, FieldMetaData orig, AnnotationBuilder ab)
Add mapping attributes for the given field. Does nothing by default.
-
serializeAttributeOverride
protected boolean serializeAttributeOverride(FieldMetaData fmd, FieldMetaData orig)
Always returns false by default.
-
serializeAttributeOverrideMappingContent
protected void serializeAttributeOverrideMappingContent(FieldMetaData fmd, FieldMetaData orig, AnnotationBuilder ab)
Serialize attribute override mapping content. Does nothing by default,
-
getStrategy
protected PersistenceStrategy getStrategy(FieldMetaData fmd)
Return the serialized strategy name.
-
serializeFieldMappingContent
protected void serializeFieldMappingContent(FieldMetaData fmd, PersistenceStrategy strategy, AnnotationBuilder ab)
Serialize field mapping content; this will be called before#serializeValueMappingContent
. Does nothing by default.
-
addStrategyMappingAttributes
protected void addStrategyMappingAttributes(FieldMetaData fmd, AnnotationBuilder ab)
Set mapping attributes for strategy. Sets mapped-by by default.
-
getObjects
protected java.util.Collection getObjects()
-
writeAnnotations
protected void writeAnnotations(java.lang.Object meta, java.util.List<AnnotationBuilder> builders, java.util.Map output)
-
serialize
public void serialize(java.util.Map output, int flags) throws java.io.IOException
Description copied from interface:MetaDataSerializer
Serialize the current set of objects to the files from which they were parsed. The objects must implement theSourceTracker
interface.- Specified by:
serialize
in interfaceMetaDataSerializer
- Parameters:
output
- if null, then serialize directly to the file system; otherwise, populate the specifiedMap
with keys that are theFile
instances, and values that are theString
contents of the MetaDataflags
- bit flags specifying the output flags; e.g.MetaDataSerializer.PRETTY
- Throws:
java.io.IOException
-
serialize
public void serialize(java.io.File file, int flags) throws java.io.IOException
Description copied from interface:MetaDataSerializer
Serialize the current set of objects to the given file.- Specified by:
serialize
in interfaceMetaDataSerializer
flags
- bit flags specifying the output flags; e.g.MetaDataSerializer.PRETTY
|MetaDataSerializer.APPEND
- Throws:
java.io.IOException
-
serialize
public void serialize(java.io.Writer out, int flags) throws java.io.IOException
Description copied from interface:MetaDataSerializer
Serialize the current set of objects to the given stream.- Specified by:
serialize
in interfaceMetaDataSerializer
flags
- bit flags specifying the output flags; e.g.MetaDataSerializer.PRETTY
- Throws:
java.io.IOException
-
serialize
public void serialize(int flags) throws java.io.IOException
Description copied from interface:MetaDataSerializer
Serialize the current set of objects to the files from which they were parsed. Any objects for which a source file cannot be determined will not be included in the output.- Specified by:
serialize
in interfaceMetaDataSerializer
- Parameters:
flags
- bit flags specifying the output flags; e.g.MetaDataSerializer.PRETTY
- Throws:
java.io.IOException
-
getClassMetaData
public java.util.Map<java.lang.String,ClassMetaData> getClassMetaData()
Returns the stored ClassMetaData
-
-