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

org.hibernate.type.descriptor.java.EnumJavaTypeDescriptor 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.java;

import org.hibernate.type.descriptor.WrapperOptions;

/**
 * Describes a Java Enum type.
 *
 * @author Steve Ebersole
 */
public class EnumJavaTypeDescriptor extends AbstractTypeDescriptor {
	@SuppressWarnings("unchecked")
	protected EnumJavaTypeDescriptor(Class type) {
		super( type, ImmutableMutabilityPlan.INSTANCE );

		JavaTypeDescriptorRegistry.INSTANCE.addDescriptor( this );
	}

	@Override
	public String toString(T value) {
		return value == null ? "" : value.name();
	}

	@Override
	public T fromString(String string) {
		return string == null ? null : (T) Enum.valueOf( getJavaTypeClass(), string );
	}

	@Override
	@SuppressWarnings("unchecked")
	public  X unwrap(T value, Class type, WrapperOptions options) {
		return (X) value;
	}

	@Override
	@SuppressWarnings("unchecked")
	public  T wrap(X value, WrapperOptions options) {
		return (T) value;
	}
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy