org.hibernate.usertype.DynamicParameterizedType Java Examples

The following examples show how to use org.hibernate.usertype.DynamicParameterizedType. 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
Source File: EnumArrayType.java    From hibernate-types with Apache License 2.0 6 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    DynamicParameterizedType.ParameterType parameterType = (ParameterType) parameters.get(DynamicParameterizedType.PARAMETER_TYPE);
    Annotation[] annotations = parameterType.getAnnotationsMethod();
    if (annotations != null) {
        for (int i = 0; i < annotations.length; i++) {
            Annotation annotation = annotations[i];
            if (Type.class.isAssignableFrom(annotation.annotationType())) {
                Type type = (Type) annotation;
                name = type.type();
                break;
            }
        }
    }
    if (name == null) {
        name = String.format(DEFAULT_TYPE_NAME, parameters.getProperty(SQL_ARRAY_TYPE));
    }
    ((AbstractArrayTypeDescriptor) getJavaTypeDescriptor()).setParameterValues(parameters);
}
 
Example #2
Source File: EnumArrayType.java    From hibernate-types with Apache License 2.0 6 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    DynamicParameterizedType.ParameterType parameterType = (ParameterType) parameters.get(DynamicParameterizedType.PARAMETER_TYPE);
    Annotation[] annotations = parameterType.getAnnotationsMethod();
    if (annotations != null) {
        for (int i = 0; i < annotations.length; i++) {
            Annotation annotation = annotations[i];
            if (Type.class.isAssignableFrom(annotation.annotationType())) {
                Type type = (Type) annotation;
                name = type.type();
                break;
            }
        }
    }
    if (name == null) {
        name = String.format(DEFAULT_TYPE_NAME, parameters.getProperty(SQL_ARRAY_TYPE));
    }
    ((AbstractArrayTypeDescriptor) getJavaTypeDescriptor()).setParameterValues(parameters);
}
 
Example #3
Source File: EnumArrayType.java    From hibernate-types with Apache License 2.0 6 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    DynamicParameterizedType.ParameterType parameterType = (ParameterType) parameters.get(DynamicParameterizedType.PARAMETER_TYPE);
    Annotation[] annotations = parameterType.getAnnotationsMethod();
    if (annotations != null) {
        for (int i = 0; i < annotations.length; i++) {
            Annotation annotation = annotations[i];
            if (Type.class.isAssignableFrom(annotation.annotationType())) {
                Type type = (Type) annotation;
                name = type.type();
                break;
            }
        }
    }
    if (name == null) {
        name = String.format(DEFAULT_TYPE_NAME, parameters.getProperty(SQL_ARRAY_TYPE));
    }
    ((AbstractArrayTypeDescriptor) getJavaTypeDescriptor()).setParameterValues(parameters);
}
 
Example #4
Source File: EnumArrayType.java    From hibernate-types with Apache License 2.0 6 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    DynamicParameterizedType.ParameterType parameterType = (ParameterType) parameters.get(DynamicParameterizedType.PARAMETER_TYPE);
    Annotation[] annotations = parameterType.getAnnotationsMethod();
    if (annotations != null) {
        for (int i = 0; i < annotations.length; i++) {
            Annotation annotation = annotations[i];
            if (Type.class.isAssignableFrom(annotation.annotationType())) {
                Type type = (Type) annotation;
                name = type.type();
                break;
            }
        }
    }
    if (name == null) {
        name = String.format(DEFAULT_TYPE_NAME, parameters.getProperty(SQL_ARRAY_TYPE));
    }
    ((AbstractArrayTypeDescriptor) getJavaTypeDescriptor()).setParameterValues(parameters);
}
 
Example #5
Source File: PostgreSQLGuavaRangeType.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example #6
Source File: JSONType.java    From spring-data-jpa-extra with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
public void setParameterValues(Properties parameters) {
    try {
        Class eClass = ReflectHelper.classForName(parameters.getProperty(DynamicParameterizedType.ENTITY));
        Field field = ReflectionUtils.findField(eClass, parameters.getProperty(DynamicParameterizedType.PROPERTY));
        Type fieldType = field.getGenericType();
        if (fieldType instanceof Class || fieldType instanceof ParameterizedType) {
            type = fieldType;
        }
        parseSqlType(field.getAnnotations());
        return;
    } catch (Exception e) {
        LOG.error(e.getMessage());
    }
    final DynamicParameterizedType.ParameterType reader = (DynamicParameterizedType.ParameterType) parameters.get(
            DynamicParameterizedType.PARAMETER_TYPE);
    if (reader != null) {
        type = reader.getReturnedClass();
        parseSqlType(reader.getAnnotationsMethod());
    } else {
        try {
            type = ReflectHelper.classForName((String) parameters.get(CLASS_NAME));
        } catch (ClassNotFoundException exception) {
            throw new HibernateException("class not found", exception);
        }
    }
}
 
Example #7
Source File: JsonTypeDescriptor.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example #8
Source File: PostgreSQLRangeType.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example #9
Source File: PostgreSQLGuavaRangeType.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example #10
Source File: EnumArrayType.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
public EnumArrayType(Class arrayClass, String sqlArrayType) {
    this();
    Properties parameters = new Properties();
    parameters.setProperty(SQL_ARRAY_TYPE, sqlArrayType);
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}
 
Example #11
Source File: JsonTypeDescriptor.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example #12
Source File: PostgreSQLRangeType.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example #13
Source File: SimpleValue.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
public Type getType() throws MappingException {
	if ( type != null ) {
		return type;
	}

	if ( typeName == null ) {
		throw new MappingException( "No type name" );
	}

	if ( typeParameters != null
			&& Boolean.valueOf( typeParameters.getProperty( DynamicParameterizedType.IS_DYNAMIC ) )
			&& typeParameters.get( DynamicParameterizedType.PARAMETER_TYPE ) == null ) {
		createParameterImpl();
	}

	Type result = getMetadata().getTypeConfiguration().getTypeResolver().heuristicType( typeName, typeParameters );
	// if this is a byte[] version/timestamp, then we need to use RowVersionType
	// instead of BinaryType (HHH-10413)
	if ( isVersion && BinaryType.class.isInstance( result ) ) {
		log.debug( "version is BinaryType; changing to RowVersionType" );
		result = RowVersionType.INSTANCE;
	}
	if ( result == null ) {
		String msg = "Could not determine type for: " + typeName;
		if ( table != null ) {
			msg += ", at table: " + table.getName();
		}
		if ( columns != null && columns.size() > 0 ) {
			msg += ", for columns: " + columns;
		}
		throw new MappingException( msg );
	}

	return result;
}
 
Example #14
Source File: PostgreSQLTSVectorTypeDescriptor.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example #15
Source File: PostgreSQLRangeType.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example #16
Source File: SimpleValue.java    From lams with GNU General Public License v2.0 5 votes vote down vote up
private void createParameterImpl() {
	try {
		String[] columnsNames = new String[columns.size()];
		for ( int i = 0; i < columns.size(); i++ ) {
			Selectable column = columns.get(i);
			if (column instanceof Column){
				columnsNames[i] = ((Column) column).getName();
			}
		}

		final XProperty xProperty = (XProperty) typeParameters.get( DynamicParameterizedType.XPROPERTY );
		// todo : not sure this works for handling @MapKeyEnumerated
		final Annotation[] annotations = xProperty == null
				? null
				: xProperty.getAnnotations();

		final ClassLoaderService classLoaderService = getMetadata()
				.getMetadataBuildingOptions()
				.getServiceRegistry()
				.getService( ClassLoaderService.class );
		typeParameters.put(
				DynamicParameterizedType.PARAMETER_TYPE,
				new ParameterTypeImpl(
						classLoaderService.classForName(
								typeParameters.getProperty( DynamicParameterizedType.RETURNED_CLASS )
						),
						annotations,
						table.getCatalog(),
						table.getSchema(),
						table.getName(),
						Boolean.valueOf( typeParameters.getProperty( DynamicParameterizedType.IS_PRIMARY_KEY ) ),
						columnsNames
				)
		);
	}
	catch ( ClassLoadingException e ) {
		throw new MappingException( "Could not create DynamicParameterizedType for type: " + typeName, e );
	}
}
 
Example #17
Source File: ListArrayTypeDescriptor.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    Class entityClass = ReflectionUtils.getClass(parameters.getProperty(DynamicParameterizedType.ENTITY));
    String property = parameters.getProperty(DynamicParameterizedType.PROPERTY);
    Type memberGenericType = ReflectionUtils.getMemberGenericTypeOrNull(entityClass, property);
    if (memberGenericType instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) memberGenericType;
        Type genericType = parameterizedType.getActualTypeArguments()[0];
        if (genericType instanceof WildcardType) {
            genericType = ((WildcardType) genericType).getUpperBounds()[0];
        }
        Class arrayElementClass = ReflectionUtils.getClass(genericType.getTypeName());
        setArrayObjectClass(
            arrayElementClass.isArray() ?
                arrayElementClass :
                ArrayUtil.toArrayClass(arrayElementClass)
        );
        sqlArrayType = parameters.getProperty(AbstractArrayType.SQL_ARRAY_TYPE);
        if (sqlArrayType == null) {
            if (Integer.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "integer";
            } else if (Long.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "bigint";
            } else if (Double.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "float8";
            } else if (String.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "text";
            } else if (UUID.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "uuid";
            } else if (Date.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "timestamp";
            } else {
                throw new UnsupportedOperationException("The " + arrayElementClass + " is not supported yet!");
            }
        }

    } else {
        throw new UnsupportedOperationException("The property " + property + " in the " + entityClass + " entity is not parameterized!");
    }
}
 
Example #18
Source File: EnumArrayType.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
public EnumArrayType(Class arrayClass, String sqlArrayType) {
    this();
    Properties parameters = new Properties();
    parameters.setProperty(SQL_ARRAY_TYPE, sqlArrayType);
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}
 
Example #19
Source File: JsonTypeDescriptor.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example #20
Source File: PostgreSQLGuavaRangeType.java    From hibernate-types with Apache License 2.0 5 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    final XProperty xProperty = (XProperty) parameters.get(DynamicParameterizedType.XPROPERTY);
    if (xProperty instanceof JavaXMember) {
        type = ReflectionUtils.invokeGetter(xProperty, "javaType");
    } else {
        type = ((ParameterType) parameters.get(PARAMETER_TYPE)).getReturnedClass();
    }
}
 
Example #21
Source File: UUIDArrayType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public UUIDArrayType(Class arrayClass) {
    this();
    Properties parameters = new Properties();
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}
 
Example #22
Source File: LongArrayType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public LongArrayType(Class arrayClass) {
    this();
    Properties parameters = new Properties();
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}
 
Example #23
Source File: IntArrayType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public IntArrayType(Class arrayClass) {
    this();
    Properties parameters = new Properties();
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}
 
Example #24
Source File: StringArrayType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public StringArrayType(Class arrayClass) {
    this();
    Properties parameters = new Properties();
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}
 
Example #25
Source File: TimestampArrayType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public TimestampArrayType(Class arrayClass) {
    this();
    Properties parameters = new Properties();
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}
 
Example #26
Source File: UUIDArrayType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public UUIDArrayType(Class arrayClass) {
    this();
    Properties parameters = new Properties();
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}
 
Example #27
Source File: DoubleArrayType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public DoubleArrayType(Class arrayClass) {
    this();
    Properties parameters = new Properties();
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}
 
Example #28
Source File: DateArrayType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public DateArrayType(Class arrayClass) {
    this();
    Properties parameters = new Properties();
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}
 
Example #29
Source File: ListArrayTypeDescriptor.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
@Override
public void setParameterValues(Properties parameters) {
    Class entityClass = ReflectionUtils.getClass(parameters.getProperty(DynamicParameterizedType.ENTITY));
    String property = parameters.getProperty(DynamicParameterizedType.PROPERTY);
    Type memberGenericType = ReflectionUtils.getMemberGenericTypeOrNull(entityClass, property);
    if (memberGenericType instanceof ParameterizedType) {
        ParameterizedType parameterizedType = (ParameterizedType) memberGenericType;

        Type arrayElementType = parameterizedType.getActualTypeArguments()[0];
        String arrayElementClassName = ReflectionUtils.getFieldValue(arrayElementType, "name");
        if (arrayElementClassName == null) {
            arrayElementClassName = arrayElementType.toString().replaceAll("class ", "");
        }

        Class arrayElementClass = ReflectionUtils.getClass(arrayElementClassName);
        setArrayObjectClass(
            arrayElementClass.isArray() ?
                arrayElementClass :
                ArrayUtil.toArrayClass(arrayElementClass)
        );
        sqlArrayType = parameters.getProperty(AbstractArrayType.SQL_ARRAY_TYPE);
        if (sqlArrayType == null) {
            if (Integer.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "integer";
            } else if (Long.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "bigint";
            } else if (Double.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "float8";
            } else if (String.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "text";
            } else if (UUID.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "uuid";
            } else if (Date.class.isAssignableFrom(arrayElementClass)) {
                sqlArrayType = "timestamp";
            } else {
                throw new UnsupportedOperationException("The " + arrayElementClass + " is not supported yet!");
            }
        }

    } else {
        throw new UnsupportedOperationException("The property " + property + " in the " + entityClass + " entity is not parameterized!");
    }
}
 
Example #30
Source File: TimestampArrayType.java    From hibernate-types with Apache License 2.0 4 votes vote down vote up
public TimestampArrayType(Class arrayClass) {
    this();
    Properties parameters = new Properties();
    parameters.put(DynamicParameterizedType.PARAMETER_TYPE, new ParameterizedParameterType(arrayClass));
    setParameterValues(parameters);
}