All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter Maven / Gradle / Ivy

There is a newer version: 7.0.0.Alpha1
Show newest version
/*
 * Hibernate, Relational Persistence for Idiomatic Java
 *
 * License: GNU Lesser General Public License (LGPL), version 2.1 or later.
 * See the lgpl.txt file in the root directory or .
 */
package org.hibernate.type.descriptor.converter;

import javax.persistence.AttributeConverter;

import org.hibernate.type.AbstractSingleColumnStandardBasicType;
import org.hibernate.type.descriptor.java.ImmutableMutabilityPlan;
import org.hibernate.type.descriptor.java.JavaTypeDescriptor;
import org.hibernate.type.descriptor.java.MutabilityPlan;
import org.hibernate.type.descriptor.sql.SqlTypeDescriptor;

import org.jboss.logging.Logger;

/**
 * Adapts the Hibernate Type contract to incorporate JPA AttributeConverter calls.
 *
 * @author Steve Ebersole
 */
public class AttributeConverterTypeAdapter extends AbstractSingleColumnStandardBasicType {
	private static final Logger log = Logger.getLogger( AttributeConverterTypeAdapter.class );

	public static final String NAME_PREFIX = "converted::";

	private final String name;
	private final String description;

	private final Class modelType;
	private final Class jdbcType;
	private final AttributeConverter attributeConverter;

	private final MutabilityPlan mutabilityPlan;

	@SuppressWarnings("unchecked")
	public AttributeConverterTypeAdapter(
			String name,
			String description,
			AttributeConverter attributeConverter,
			SqlTypeDescriptor sqlTypeDescriptorAdapter,
			Class modelType,
			Class jdbcType,
			JavaTypeDescriptor entityAttributeJavaTypeDescriptor) {
		super( sqlTypeDescriptorAdapter, entityAttributeJavaTypeDescriptor );
		this.name = name;
		this.description = description;
		this.modelType = modelType;
		this.jdbcType = jdbcType;
		this.attributeConverter = attributeConverter;

		this.mutabilityPlan =
				entityAttributeJavaTypeDescriptor.getMutabilityPlan().isMutable() ?
						new AttributeConverterMutabilityPlanImpl( attributeConverter ) :
						ImmutableMutabilityPlan.INSTANCE;

		log.debug( "Created AttributeConverterTypeAdapter -> " + name );
	}

	@Override
	public String getName() {
		return name;
	}

	public Class getModelType() {
		return modelType;
	}

	public Class getJdbcType() {
		return jdbcType;
	}

	public AttributeConverter getAttributeConverter() {
		return attributeConverter;
	}

	@Override
	protected MutabilityPlan getMutabilityPlan() {
		return mutabilityPlan;
	}

	@Override
	public String toString() {
		return description;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy