List of usage examples for org.hibernate.type TypeResolver TypeResolver
TypeResolver
From source file:br.com.tcc.common.support.GenericEnumUserType.java
/** * {@inheritDoc}/*from ww w . java 2s . c om*/ * @param parameters * {@inheritDoc} */ @SuppressWarnings("unchecked") @Override public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty(ENUM_CLASS_PARAM_NAME); try { enumClass = (Class<? extends Enum<?>>) Class.forName(enumClassName).asSubclass(Enum.class); } catch (ClassNotFoundException cfne) { throw new HibernateException((new StringBuilder()).append("Enum class named '").append(enumClass) .append("'not found").toString(), cfne); } String identifierMethodName = parameters.getProperty(IDENTIFIER_METHOD_PARAM_NAME, DEFAULT_IDENTIFIER_METHOD_NAME); try { identifierMethod = enumClass.getMethod(identifierMethodName, new Class[FIRST_ITEM]); identifierType = identifierMethod.getReturnType(); } catch (NoSuchMethodException e) { throw new HibernateException((new StringBuilder()).append(MSG_NO_METHOD_NAMED) .append(identifierMethodName).append(MSG_FOUND).toString(), e); } catch (SecurityException e) { throw new HibernateException((new StringBuilder()).append(MSG_NO_METHOD_NAMED) .append(identifierMethodName).append(MSG_FOUND).toString(), e); } TypeResolver tr = new TypeResolver(); type = (AbstractSingleColumnStandardBasicType) tr.basic(identifierType.getName()); if (type == null) { throw new HibernateException((new StringBuilder()).append("Unsupported identifier type ") .append(identifierType.getName()).toString()); } sqlTypes = new int[] { type.sqlType() }; String valueOfMethodName = parameters.getProperty(VALUE_OF_METHOD_PARAM_NAME, DEFAULT_VALUE_OF_METHOD_NAME); try { valueOfMethod = enumClass.getMethod(valueOfMethodName, new Class[] { identifierType }); } catch (NoSuchMethodException e) { throw new HibernateException((new StringBuilder()).append(MSG_NO_METHOD_NAMED).append(valueOfMethodName) .append(MSG_FOUND).toString(), e); } catch (SecurityException e) { throw new HibernateException((new StringBuilder()).append(MSG_NO_METHOD_NAMED).append(valueOfMethodName) .append(MSG_FOUND).toString(), e); } }
From source file:com.formkiq.core.dao.EnumCustomType.java
License:Apache License
/** * Transform to Enum.// ww w . j ava 2 s. c o m * @param clazzEnum {@link Class} * @return {@link Type} */ public static Type transform(final Class<?> clazzEnum) { Properties params = new Properties(); // type 12 represents enum value params.put("type", "12"); params.put("enumClass", clazzEnum.getName()); return new TypeLocatorImpl(new TypeResolver()).custom(EnumType.class, params); }
From source file:com.seethayya.shoppingcart.util.GenericEnumUserType.java
License:Apache License
@Override public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty("enumClass"); try {/*from ww w . j a v a 2s .co m*/ enumClass = Class.forName(enumClassName).asSubclass(Enum.class); } catch (ClassNotFoundException cfne) { throw new HibernateException("Enum class not found", cfne); } String identifierMethodName = parameters.getProperty("identifierMethod", DEFAULT_IDENTIFIER_METHOD_NAME); try { identifierMethod = enumClass.getMethod(identifierMethodName, new Class[0]); identifierType = identifierMethod.getReturnType(); } catch (Exception e) { throw new HibernateException("Failed to obtain identifier method", e); } type = (AbstractSingleColumnStandardBasicType<? extends Object>) new TypeResolver() .heuristicType(identifierType.getName(), parameters); if (type == null) { throw new HibernateException("Unsupported identifier type " + identifierType.getName()); } sqlTypes = new int[] { ((AbstractSingleColumnStandardBasicType<?>) type).sqlType() }; String valueOfMethodName = parameters.getProperty("valueOfMethod", DEFAULT_VALUE_OF_METHOD_NAME); try { valueOfMethod = enumClass.getMethod(valueOfMethodName, new Class[] { identifierType }); } catch (Exception e) { throw new HibernateException("Failed to obtain valueOf method", e); } }
From source file:org.ambraproject.hibernate.GenericEnumUserType.java
License:Apache License
@Override public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty("enumClass"); try {//from w w w. j ava2 s . c o m enumClass = Class.forName(enumClassName).asSubclass(Enum.class); } catch (ClassNotFoundException exception) { throw new HibernateException("Enum class not found", exception); } String identifierMethodName = parameters.getProperty("identifierMethod", defaultIdentifierMethodName); try { identifierMethod = enumClass.getMethod(identifierMethodName, new Class[0]); identifierType = identifierMethod.getReturnType(); } catch (Exception exception) { throw new HibernateException("Failed to optain identifier method", exception); } TypeResolver tr = new TypeResolver(); type = (AbstractSingleColumnStandardBasicType) tr.basic(identifierType.getName()); if (type == null) { throw new HibernateException("Unsupported identifier type " + identifierType.getName()); } sqlTypes = new int[] { type.sqlType() }; String valueOfMethodName = parameters.getProperty("valueOfMethod", defaultValueOfMethodName); try { valueOfMethod = enumClass.getMethod(valueOfMethodName, new Class[] { identifierType }); } catch (Exception exception) { throw new HibernateException("Failed to optain valueOf method", exception); } }
From source file:org.ambraproject.rhino.config.HibernateAdaptingType.java
License:Open Source License
private AbstractSingleColumnStandardBasicType<?> getDataType() { return (AbstractSingleColumnStandardBasicType<?>) new TypeResolver() .basic(adapter.getDataClass().getName()); }
From source file:org.archfirst.common.hibernate.GenericEnumUserType.java
License:Apache License
@SuppressWarnings({ "unchecked" }) public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty("enumClass"); try {/* w ww . j a va 2 s. com*/ enumClass = Class.forName(enumClassName).asSubclass(Enum.class); } catch (ClassNotFoundException cfne) { throw new HibernateException("Enum class not found", cfne); } String identifierMethodName = parameters.getProperty("identifierMethod", DEFAULT_TO_IDENTIFIER_METHOD_NAME); try { identifierMethod = enumClass.getMethod(identifierMethodName, new Class[0]); identifierType = identifierMethod.getReturnType(); } catch (Exception e) { throw new HibernateException("Failed to obtain identifier method", e); } type = (AbstractSingleColumnStandardBasicType<? extends Object>) new TypeResolver() .heuristicType(identifierType.getName(), parameters); if (type == null) throw new HibernateException("Unsupported identifier type " + identifierType.getName()); sqlTypes = new int[] { ((AbstractSingleColumnStandardBasicType<?>) type).sqlType() }; String valueOfMethodName = parameters.getProperty("valueOfMethod", DEFAULT_FROM_IDENTIFIER_METHOD_NAME); try { valueOfMethod = enumClass.getMethod(valueOfMethodName, new Class[] { identifierType }); } catch (Exception e) { throw new HibernateException("Failed to obtain valueOf method", e); } }
From source file:org.bedework.util.hibernate.GenericEnumUserType.java
License:Apache License
@Override @SuppressWarnings({ "unchecked" }) public void setParameterValues(final Properties parameters) { String enumClassName = parameters.getProperty("enumClassname"); try {//from www . ja va 2 s . c o m enumClass = Class.forName(enumClassName).asSubclass(Enum.class); } catch (ClassNotFoundException cfne) { throw new HibernateException("Enum class not found", cfne); } String identifierMethodName = parameters.getProperty("identifierMethod", DEFAULT_IDENTIFIER_METHOD_NAME); try { identifierMethod = enumClass.getMethod(identifierMethodName, new Class[0]); identifierType = identifierMethod.getReturnType(); } catch (Exception e) { throw new HibernateException("Failed to obtain identifier method", e); } type = (AbstractSingleColumnStandardBasicType<? extends Object>) new TypeResolver() .heuristicType(identifierType.getName(), parameters); if (type == null) { throw new HibernateException("Unsupported identifier type " + identifierType.getName()); } sqlTypes = new int[] { ((AbstractSingleColumnStandardBasicType<?>) type).sqlType() }; String valueOfMethodName = parameters.getProperty("valueOfMethod", DEFAULT_VALUE_OF_METHOD_NAME); try { valueOfMethod = enumClass.getMethod(valueOfMethodName, new Class[] { identifierType }); } catch (Exception e) { throw new HibernateException("Failed to obtain valueOf method", e); } }
From source file:org.broadleafcommerce.openadmin.server.dao.provider.metadata.MapFieldsFieldMetadataProvider.java
License:Apache License
@Override public FieldProviderResponse addMetadataFromFieldType( AddMetadataFromFieldTypeRequest addMetadataFromFieldTypeRequest, Map<String, FieldMetadata> metadata) { if (!canHandleFieldForTypeMetadata(addMetadataFromFieldTypeRequest, metadata)) { return FieldProviderResponse.NOT_HANDLED; }//from w w w. ja va 2 s. co m //look for any map field metadata that was previously added for the requested field for (Map.Entry<String, FieldMetadata> entry : addMetadataFromFieldTypeRequest.getPresentationAttributes() .entrySet()) { if (entry.getKey().startsWith( addMetadataFromFieldTypeRequest.getRequestedPropertyName() + FieldManager.MAPFIELDSEPARATOR)) { TypeLocatorImpl typeLocator = new TypeLocatorImpl(new TypeResolver()); Type myType = null; //first, check if an explicit type was declared String valueClass = ((BasicFieldMetadata) entry.getValue()).getMapFieldValueClass(); if (valueClass != null) { myType = typeLocator.entity(valueClass); } if (myType == null) { SupportedFieldType fieldType = ((BasicFieldMetadata) entry.getValue()).getExplicitFieldType(); Class<?> basicJavaType = getBasicJavaType(fieldType); if (basicJavaType != null) { myType = typeLocator.basic(basicJavaType); } } if (myType == null) { java.lang.reflect.Type genericType = addMetadataFromFieldTypeRequest.getRequestedField() .getGenericType(); if (genericType instanceof ParameterizedType) { ParameterizedType pType = (ParameterizedType) genericType; Class<?> clazz = (Class<?>) pType.getActualTypeArguments()[1]; Class<?>[] entities = addMetadataFromFieldTypeRequest.getDynamicEntityDao() .getAllPolymorphicEntitiesFromCeiling(clazz); if (!ArrayUtils.isEmpty(entities)) { myType = typeLocator.entity(entities[entities.length - 1]); } } } if (myType == null) { throw new IllegalArgumentException( "Unable to establish the type for the property (" + entry.getKey() + ")"); } //add property for this map field as if it was a normal field super.addMetadataFromFieldType( new AddMetadataFromFieldTypeRequest(addMetadataFromFieldTypeRequest.getRequestedField(), addMetadataFromFieldTypeRequest.getTargetClass(), addMetadataFromFieldTypeRequest.getForeignField(), addMetadataFromFieldTypeRequest.getAdditionalForeignFields(), addMetadataFromFieldTypeRequest.getMergedPropertyType(), addMetadataFromFieldTypeRequest.getComponentProperties(), addMetadataFromFieldTypeRequest.getIdProperty(), addMetadataFromFieldTypeRequest.getPrefix(), entry.getKey(), myType, addMetadataFromFieldTypeRequest.isPropertyForeignKey(), addMetadataFromFieldTypeRequest.getAdditionalForeignKeyIndexPosition(), addMetadataFromFieldTypeRequest.getPresentationAttributes(), entry.getValue(), ((BasicFieldMetadata) entry.getValue()).getExplicitFieldType(), myType.getReturnedClass(), addMetadataFromFieldTypeRequest.getDynamicEntityDao()), metadata); } } return FieldProviderResponse.HANDLED; }
From source file:org.jadira.usertype.spi.shared.AbstractHeuristicUserType.java
License:Apache License
public void setParameterValues(Properties parameters) { @SuppressWarnings("unchecked") final AbstractSingleColumnStandardBasicType<? extends Object> heuristicType = (AbstractSingleColumnStandardBasicType<? extends Object>) new TypeResolver() .heuristicType(identifierType.getName(), parameters); if (heuristicType == null) { throw new HibernateException("Unsupported identifier type " + identifierType.getName()); }/*from w w w . j av a 2 s . com*/ type = heuristicType; sqlTypes = new int[] { type.sqlType() }; }
From source file:org.jnap.core.persistence.hibernate.PersistentEnumType.java
License:Apache License
public void setParameterValues(Properties parameters) { String enumClassName = parameters.getProperty(ENUM_CLASS_PARAM); try {//from w w w . j av a 2s . c o m enumClass = Class.forName(enumClassName).asSubclass(Enum.class); } catch (ClassNotFoundException cfne) { throw new HibernateException("Enum class not found", cfne); } String identifierMethodName = parameters.getProperty(IDENTIFIER_METHOD_PARAM, DEFAULT_IDENTIFIER_METHOD_NAME); try { identifierMethod = enumClass.getMethod(identifierMethodName, new Class[0]); identifierType = identifierMethod.getReturnType(); } catch (Exception e) { throw new HibernateException("Failed to obtain identifier method", e); } type = (AbstractSingleColumnStandardBasicType) new TypeResolver().basic(identifierType.getName()); if (type == null) { throw new HibernateException("Unsupported identifier type " + identifierType.getName()); } sqlTypes = new int[] { type.getSqlTypeDescriptor().getSqlType() }; try { valuesMethod = enumClass.getMethod("values", ArrayUtils.EMPTY_CLASS_ARRAY); } catch (Exception e) { throw new HibernateException("Failed to obtain values method", e); } }