Search in sources :

Example 6 with SerializedObjectConverter

use of org.eclipse.persistence.mappings.converters.SerializedObjectConverter in project eclipselink by eclipse-ee4j.

the class DefaultTableGenerator method postInitTableSchema.

/**
 * Build additional table/field definitions for the descriptor, like relation table
 * and direct-collection, direct-map table, as well as reset LOB type for serialized
 * object mapping and type conversion mapping for LOB usage
 */
protected void postInitTableSchema(ClassDescriptor descriptor) {
    for (DatabaseMapping mapping : descriptor.getMappings()) {
        if (descriptor.isChildDescriptor() && descriptor.getInheritancePolicy().getParentDescriptor().getMappingForAttributeName(mapping.getAttributeName()) != null) {
            // times for the same table.
            continue;
        } else if (mapping.isManyToManyMapping()) {
            buildRelationTableDefinition((ManyToManyMapping) mapping, ((ManyToManyMapping) mapping).getRelationTableMechanism(), ((ManyToManyMapping) mapping).getListOrderField(), mapping.getContainerPolicy());
        } else if (mapping.isDirectCollectionMapping()) {
            buildDirectCollectionTableDefinition((DirectCollectionMapping) mapping, descriptor);
        } else if (mapping.isDirectToFieldMapping()) {
            Converter converter = ((DirectToFieldMapping) mapping).getConverter();
            if (converter != null) {
                if (converter instanceof TypeConversionConverter) {
                    resetFieldTypeForLOB((DirectToFieldMapping) mapping);
                }
                if (converter instanceof SerializedObjectConverter) {
                    // serialized object mapping field should be BLOB/IMAGE
                    getFieldDefFromDBField(mapping.getField()).setType(((SerializedObjectConverter) converter).getSerializer().getType());
                }
            }
        } else if (mapping.isAggregateCollectionMapping()) {
            // need to figure out the target foreign key field and add it into the aggregate target table
            createAggregateTargetTable((AggregateCollectionMapping) mapping);
        } else if (mapping.isForeignReferenceMapping()) {
            if (mapping.isOneToOneMapping()) {
                RelationTableMechanism relationTableMechanism = ((OneToOneMapping) mapping).getRelationTableMechanism();
                if (relationTableMechanism == null) {
                    addForeignKeyFieldToSourceTargetTable((OneToOneMapping) mapping);
                } else {
                    buildRelationTableDefinition((OneToOneMapping) mapping, relationTableMechanism, null, null);
                }
            } else if (mapping.isOneToManyMapping()) {
                addForeignKeyFieldToSourceTargetTable((OneToManyMapping) mapping);
                TableDefinition targTblDef = getTableDefFromDBTable(mapping.getReferenceDescriptor().getDefaultTable());
                addFieldsForMappedKeyMapContainerPolicy(mapping.getContainerPolicy(), targTblDef);
            }
        } else if (mapping.isTransformationMapping()) {
            resetTransformedFieldType((TransformationMapping) mapping);
        } else if (mapping.isAggregateObjectMapping()) {
            postInitTableSchema(mapping.getReferenceDescriptor());
        }
    }
    processAdditionalTablePkFields(descriptor);
}
Also used : ManyToManyMapping(org.eclipse.persistence.mappings.ManyToManyMapping) DirectToFieldMapping(org.eclipse.persistence.mappings.DirectToFieldMapping) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) SerializedObjectConverter(org.eclipse.persistence.mappings.converters.SerializedObjectConverter) Converter(org.eclipse.persistence.mappings.converters.Converter) TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) SerializedObjectConverter(org.eclipse.persistence.mappings.converters.SerializedObjectConverter) DatabaseMapping(org.eclipse.persistence.mappings.DatabaseMapping) RelationTableMechanism(org.eclipse.persistence.mappings.RelationTableMechanism) OneToOneMapping(org.eclipse.persistence.mappings.OneToOneMapping)

Example 7 with SerializedObjectConverter

use of org.eclipse.persistence.mappings.converters.SerializedObjectConverter in project eclipselink by eclipse-ee4j.

the class LobMetadata method process.

/**
 * INTERNAL:
 * Every converter needs to be able to process themselves.
 */
@Override
public void process(DatabaseMapping mapping, MappingAccessor accessor, MetadataClass referenceClass, boolean isForMapKey) {
    // referenceClass type.
    if (isValidClobType(referenceClass)) {
        setFieldClassification(mapping, java.sql.Clob.class, isForMapKey);
        setConverter(mapping, new TypeConversionConverter(mapping), isForMapKey);
    } else if (isValidBlobType(referenceClass)) {
        setFieldClassification(mapping, java.sql.Blob.class, isForMapKey);
        setConverter(mapping, new TypeConversionConverter(mapping), isForMapKey);
    } else if (referenceClass.extendsInterface(Serializable.class)) {
        setFieldClassification(mapping, java.sql.Blob.class, isForMapKey);
        setConverter(mapping, new SerializedObjectConverter(mapping), isForMapKey);
    } else {
        // The referenceClass is neither a valid BLOB or CLOB attribute.
        throw ValidationException.invalidTypeForLOBAttribute(mapping.getAttributeName(), referenceClass, accessor.getJavaClass());
    }
}
Also used : TypeConversionConverter(org.eclipse.persistence.mappings.converters.TypeConversionConverter) SerializedObjectConverter(org.eclipse.persistence.mappings.converters.SerializedObjectConverter)

Aggregations

SerializedObjectConverter (org.eclipse.persistence.mappings.converters.SerializedObjectConverter)7 DirectToFieldMapping (org.eclipse.persistence.mappings.DirectToFieldMapping)4 TypeConversionConverter (org.eclipse.persistence.mappings.converters.TypeConversionConverter)3 ClassDescriptor (org.eclipse.persistence.descriptors.ClassDescriptor)2 ManyToManyMapping (org.eclipse.persistence.mappings.ManyToManyMapping)2 OneToOneMapping (org.eclipse.persistence.mappings.OneToOneMapping)2 ConverterClass (org.eclipse.persistence.mappings.converters.ConverterClass)2 ServerSession (org.eclipse.persistence.sessions.server.ServerSession)2 Vector (java.util.Vector)1 RelationalDescriptor (org.eclipse.persistence.descriptors.RelationalDescriptor)1 DatabaseMapping (org.eclipse.persistence.mappings.DatabaseMapping)1 DirectCollectionMapping (org.eclipse.persistence.mappings.DirectCollectionMapping)1 OneToManyMapping (org.eclipse.persistence.mappings.OneToManyMapping)1 RelationTableMechanism (org.eclipse.persistence.mappings.RelationTableMechanism)1 TransformationMapping (org.eclipse.persistence.mappings.TransformationMapping)1 Converter (org.eclipse.persistence.mappings.converters.Converter)1 ObjectTypeConverter (org.eclipse.persistence.mappings.converters.ObjectTypeConverter)1