Java Code Examples for org.hibernate.type.descriptor.java.JavaTypeDescriptor

The following examples show how to use org.hibernate.type.descriptor.java.JavaTypeDescriptor. These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
@SuppressWarnings("unchecked")
public AttributeConverterTypeAdapter(
		String name,
		String description,
		JpaAttributeConverter<? extends T,?> attributeConverter,
		SqlTypeDescriptor sqlTypeDescriptorAdapter,
		Class modelType,
		Class jdbcType,
		JavaTypeDescriptor<T> 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<T>( attributeConverter )
			: ImmutableMutabilityPlan.INSTANCE;

	log.debug( "Created AttributeConverterTypeAdapter -> " + name );
}
 
Example 2
public JpaAttributeConverterImpl(
		ManagedBean<AttributeConverter<O, R>> attributeConverterBean,
		JavaTypeDescriptor<AttributeConverter<O,R>> converterJavaTypeDescriptor,
		JavaTypeDescriptor<O> domainJavaTypeDescriptor,
		JavaTypeDescriptor<R> relationalJavaTypeDescriptor) {
	this.attributeConverterBean = attributeConverterBean;
	this.converterJavaTypeDescriptor = converterJavaTypeDescriptor;
	this.domainJavaTypeDescriptor = (BasicJavaDescriptor<O>) domainJavaTypeDescriptor;
	this.relationalJavaTypeDescriptor = (BasicJavaDescriptor<R>) relationalJavaTypeDescriptor;
}
 
Example 3
public StandardBasicTypeTemplate(
		SqlTypeDescriptor sqlTypeDescriptor,
		JavaTypeDescriptor<J> javaTypeDescriptor,
		String... registrationKeys) {
	super( sqlTypeDescriptor, javaTypeDescriptor );
	this.registrationKeys = registrationKeys;

	this.name = javaTypeDescriptor.getJavaType() == null ? "(map-mode)" : javaTypeDescriptor.getJavaType().getName()
			+ " -> " + sqlTypeDescriptor.getSqlType();
}
 
Example 4
public AttributeConverterSqlTypeDescriptorAdapter(
		JpaAttributeConverter converter,
		SqlTypeDescriptor delegate,
		JavaTypeDescriptor intermediateJavaTypeDescriptor) {
	this.converter = converter;
	this.delegate = delegate;
	this.intermediateJavaTypeDescriptor = intermediateJavaTypeDescriptor;
}
 
Example 5
Source Project: lams   Source File: RegistryHelper.java    License: GNU General Public License v2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public <J> JavaTypeDescriptor<J> resolveDescriptor(
		Map<Class,JavaTypeDescriptor> descriptorsByClass,
		Class<J> cls,
		Supplier<JavaTypeDescriptor<J>> defaultValueSupplier) {
	if ( cls == null ) {
		throw new IllegalArgumentException( "Class passed to locate JavaTypeDescriptor cannot be null" );
	}

	JavaTypeDescriptor<J> descriptor = descriptorsByClass.get( cls );
	if ( descriptor != null ) {
		return descriptor;
	}

	if ( cls.isEnum() ) {
		descriptor = new EnumJavaTypeDescriptor( cls );
		descriptorsByClass.put( cls, descriptor );
		return descriptor;
	}

	// find the first "assignable" match
	for ( Map.Entry<Class, JavaTypeDescriptor> entry : descriptorsByClass.entrySet() ) {
		if ( entry.getKey().isAssignableFrom( cls ) ) {
			log.debugf( "Using  cached JavaTypeDescriptor instance for Java class [%s]", cls.getName() );
			return entry.getValue();
		}
	}

	return defaultValueSupplier.get();
}
 
Example 6
public <T> JavaTypeDescriptor<T> getDescriptor(Class<T> javaType) {
	return RegistryHelper.INSTANCE.resolveDescriptor(
			descriptorsByClass,
			javaType,
			() -> {
				log.debugf(
						"Could not find matching scoped JavaTypeDescriptor for requested Java class [%s]; " +
								"falling back to static registry",
						javaType.getName()
				);

				return org.hibernate.type.descriptor.java.JavaTypeDescriptorRegistry.INSTANCE.getDescriptor( javaType );
			}
	);
}
 
Example 7
public void addDescriptor(JavaTypeDescriptor descriptor) {
	JavaTypeDescriptor old = descriptorsByClass.put( descriptor.getJavaType(), descriptor );
	if ( old != null ) {
		log.debugf(
				"JavaTypeDescriptorRegistry entry replaced : %s -> %s (was %s)",
				descriptor.getJavaType(),
				descriptor,
				old
		);
	}
}
 
Example 8
@Override
public <X> GridValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
	return new BasicGridBinder<X>( javaTypeDescriptor, this ) {

		@Override
		protected void doBind(Tuple resultset, X value, String[] names, WrapperOptions options) {
			resultset.put( names[0], javaTypeDescriptor.unwrap( value, targetClass, options ) );
		}
	};
}
 
Example 9
Source Project: hibernate-types   Source File: PostgreSQLEnumType.java    License: Apache License 2.0 5 votes vote down vote up
/**
 * Initialization constructor taking the {@link Class}.
 *
 * @param enumClass The enum type
 */
public PostgreSQLEnumType(Class<? extends Enum> enumClass) {
    this();

    Class typeConfigurationClass = ReflectionUtils.getClassOrNull("org.hibernate.type.spi.TypeConfiguration");

    if(typeConfigurationClass != null) {
        Object typeConfiguration = ReflectionUtils.newInstance(typeConfigurationClass);

        Class enumJavaTypeDescriptorClass = ReflectionUtils.getClassOrNull("org.hibernate.type.descriptor.java.EnumJavaTypeDescriptor");

        Object enumJavaTypeDescriptor = ReflectionUtils.newInstance(enumJavaTypeDescriptorClass, new Object[] {enumClass}, new Class[]{enumClass.getClass()});

        Object javaTypeDescriptorRegistry = ReflectionUtils.invokeGetter(typeConfiguration, "javaTypeDescriptorRegistry");

        ReflectionUtils.invokeMethod(
            javaTypeDescriptorRegistry,
            ReflectionUtils.getMethod(javaTypeDescriptorRegistry, "addDescriptor", JavaTypeDescriptor.class),
            enumJavaTypeDescriptor
        );

        ReflectionUtils.invokeSetter(this, "typeConfiguration", typeConfiguration);
    }

    Properties properties = new Properties();
    properties.setProperty("enumClass", enumClass.getName());
    properties.setProperty("useNamed", Boolean.TRUE.toString());
    setParameterValues(properties);
}
 
Example 10
Source Project: hibernate-types   Source File: ArraySqlTypeDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>(javaTypeDescriptor, this) {
        @Override
        protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
            AbstractArrayTypeDescriptor<Object> abstractArrayTypeDescriptor = (AbstractArrayTypeDescriptor<Object>) javaTypeDescriptor;
            st.setArray(index, st.getConnection().createArrayOf(
                abstractArrayTypeDescriptor.getSqlArrayType(),
                abstractArrayTypeDescriptor.unwrap(value, Object[].class, options)
            ));
        }
    };
}
 
Example 11
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>(javaTypeDescriptor, this) {
        @Override
        protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
            st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
        }
    };
}
 
Example 12
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>(javaTypeDescriptor, this) {
        @Override
        protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
            st.setString(index, javaTypeDescriptor.unwrap(value, String.class, options));
        }
    };
}
 
Example 13
Source Project: hibernate-types   Source File: ArraySqlTypeDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>(javaTypeDescriptor, this) {
        @Override
        protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
            AbstractArrayTypeDescriptor<Object> abstractArrayTypeDescriptor = (AbstractArrayTypeDescriptor<Object>) javaTypeDescriptor;
            st.setArray(index, st.getConnection().createArrayOf(
                abstractArrayTypeDescriptor.getSqlArrayType(),
                abstractArrayTypeDescriptor.unwrap(value, Object[].class, options)
            ));
        }
    };
}
 
Example 14
Source Project: hibernate-types   Source File: ArraySqlTypeDescriptor.java    License: Apache License 2.0 5 votes vote down vote up
@Override
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicExtractor<X>(javaTypeDescriptor, this) {
        @Override
        protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
            return javaTypeDescriptor.wrap(rs.getArray(name), options);
        }
    };
}
 
Example 15
@Override
public <X> ValueExtractor<X> getExtractor(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicExtractor<X>(javaTypeDescriptor, this) {
        @Override
        protected X doExtract(ResultSet rs, String name, WrapperOptions options) throws SQLException {
            return javaTypeDescriptor.wrap(extractJson(rs, name), options);
        }
    };
}
 
Example 16
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>(javaTypeDescriptor, this) {
        @Override
        protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
            st.setObject(index, javaTypeDescriptor.unwrap(value, JsonNode.class, options), getSqlType());
        }
    };
}
 
Example 17
@Override
public <X> ValueBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
    return new BasicBinder<X>(javaTypeDescriptor, this) {
        @Override
        protected void doBind(PreparedStatement st, X value, int index, WrapperOptions options) throws SQLException {
            st.setString(index, javaTypeDescriptor.unwrap(value, String.class, options));
        }
    };
}
 
Example 18
Source Project: jadira   Source File: AbstractHeuristicUserType.java    License: Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({ "rawtypes", "unchecked" })
@Override
@Deprecated
   public String toXMLString(Object object) {
   	final JavaTypeDescriptor desc = type.getJavaTypeDescriptor();
   	return desc.toString(object);
   }
 
Example 19
@Override
public JavaTypeDescriptor<AttributeConverter<O, R>> getConverterJavaTypeDescriptor() {
	return converterJavaTypeDescriptor;
}
 
Example 20
Source Project: lams   Source File: MetadataBuilderImpl.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public void contributeJavaTypeDescriptor(JavaTypeDescriptor descriptor) {
	this.bootstrapContext.getTypeConfiguration().getJavaTypeDescriptorRegistry().addDescriptor( descriptor );
}
 
Example 21
public AbstractSingleColumnStandardBasicType(SqlTypeDescriptor sqlTypeDescriptor, JavaTypeDescriptor<T> javaTypeDescriptor) {
	super( sqlTypeDescriptor, javaTypeDescriptor );
}
 
Example 22
public AbstractStandardBasicType(SqlTypeDescriptor sqlTypeDescriptor, JavaTypeDescriptor<T> javaTypeDescriptor) {
	this.sqlTypeDescriptor = sqlTypeDescriptor;
	this.sqlTypes = new int[] { sqlTypeDescriptor.getSqlType() };
	this.javaTypeDescriptor = javaTypeDescriptor;
}
 
Example 23
public final JavaTypeDescriptor<T> getJavaTypeDescriptor() {
	return javaTypeDescriptor;
}
 
Example 24
public final void setJavaTypeDescriptor( JavaTypeDescriptor<T> javaTypeDescriptor ) {
	this.javaTypeDescriptor = javaTypeDescriptor;
}
 
Example 25
Source Project: lams   Source File: ClobTypeDescriptor.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
	return getClobBinder( javaTypeDescriptor );
}
 
Example 26
Source Project: lams   Source File: NClobTypeDescriptor.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public <X> ValueBinder<X> getBinder(JavaTypeDescriptor<X> javaTypeDescriptor) {
	return getNClobBinder( javaTypeDescriptor );
}
 
Example 27
Source Project: lams   Source File: BasicExtractor.java    License: GNU General Public License v2.0 4 votes vote down vote up
public BasicExtractor(JavaTypeDescriptor<J> javaDescriptor, SqlTypeDescriptor sqlDescriptor) {
	this.javaDescriptor = javaDescriptor;
	this.sqlDescriptor = sqlDescriptor;
}
 
Example 28
Source Project: lams   Source File: BasicExtractor.java    License: GNU General Public License v2.0 4 votes vote down vote up
public JavaTypeDescriptor<J> getJavaDescriptor() {
	return javaDescriptor;
}
 
Example 29
Source Project: lams   Source File: BlobTypeDescriptor.java    License: GNU General Public License v2.0 4 votes vote down vote up
@Override
public <X> BasicBinder<X> getBinder(final JavaTypeDescriptor<X> javaTypeDescriptor) {
	return getBlobBinder( javaTypeDescriptor );
}
 
Example 30
Source Project: lams   Source File: BasicBinder.java    License: GNU General Public License v2.0 4 votes vote down vote up
public JavaTypeDescriptor<J> getJavaDescriptor() {
	return javaDescriptor;
}