/** * {@inheritDoc} */ @Override public EntityManagerFactory createEntityManagerFactory(String persistenceUnitName, Map properties) { LOGGER.trace("Starting createEntityManagerFactory for persistenceUnitName {}", persistenceUnitName); try { final EntityManagerFactoryBuilder builder = getEntityManagerFactoryBuilderOrNull(persistenceUnitName, properties); if (builder == null) { LOGGER.trace("Could not obtain matching EntityManagerFactoryBuilder, returning null"); return null; } else { EntityManagerFactoryImpl impl = (EntityManagerFactoryImpl) builder; TypeResolver typeResolver = impl.getSessionFactory().getTypeResolver(); return builder.build(); } } catch (PersistenceException pe) { throw pe; } catch (Exception e) { LOGGER.debug("Unable to build entity manager factory", e); throw new PersistenceException("Unable to build entity manager factory", e); } // EntityManagerFactory entityManagerFactory = super.createEntityManagerFactory(persistenceUnitName, // properties); // if (entityManagerFactory instanceof EntityManagerFactoryImpl) { // SessionFactoryImpl sessionFactory = ((EntityManagerFactoryImpl) // entityManagerFactory).getSessionFactory(); // TypeResolver typeResolver = sessionFactory.getTypeResolver(); // // typeResolver.registerTypeOverride(type, keys); // } // return entityManagerFactory; }
private void addFilterDefinitions(FilterProvider provider, ConfigurationProvider configurationProvider) { Configuration conf = configurationProvider.getConfiguration(); conf.buildMappings(); Map<?, ?> filterDefinitions = conf.getFilterDefinitions(); TypeResolver resolver = conf.getTypeResolver(); for (BasicFilterDefinition filterDef : provider.getFilterDefinitions()) { Map<String, Type> paramMapConverted = new HashMap<String, Type>(); for (Entry<String, String> paramEntry : filterDef.getParameterTypeMap().entrySet()) { Type type = resolver.heuristicType(paramEntry.getValue()); paramMapConverted.put(paramEntry.getKey(), type); } FilterDefinition definition = new FilterDefinition(filterDef.getName(), filterDef.getDefaultCondition(), paramMapConverted); LOG.debug("Registering new filter definition with name '{}'", definition.getFilterName()); if (filterDefinitions.containsKey(definition.getFilterName())) { LOG.warn("The configuration already has filter definition with name '{}', overwriting.", definition.getFilterName()); } conf.addFilterDefinition(definition); filterProviderMap.put(definition.getFilterName(), provider); Iterator<PersistentClass> classIterator = conf.getClassMappings(); while (classIterator.hasNext()) { PersistentClass persistentClass = classIterator.next(); provider.addFilterToClassIfNecesary(persistentClass, filterDef); } } configurationProvider.invalidate(); }
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()); } type = heuristicType; sqlTypes = new int[]{ type.sqlType() }; }
public TypeResolver getTypeResolver() { return sessionFactoryImplementor.getTypeResolver(); }
public TypeResolver getTypeResolver() { return typeResolver; }
public TypeLocatorImpl(TypeResolver typeResolver) { this.typeResolver = typeResolver; }
protected TypeResolver getTypeResolver(SessionFactory sessionFactory) { return ((SessionFactoryImplementor) sessionFactory).getTypeResolver(); }
@Override public FieldProviderResponse addMetadataFromFieldType(AddMetadataFromFieldTypeRequest addMetadataFromFieldTypeRequest, Map<String, FieldMetadata> metadata) { if (!canHandleFieldForTypeMetadata(addMetadataFromFieldTypeRequest, metadata)) { return FieldProviderResponse.NOT_HANDLED; } //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; }
/** * Retrieve the type resolver in effect. * * @return The type resolver. */ public TypeResolver getTypeResolver();
/** * Retrieve the {@link Type} resolver associated with this factory. * * @return The type resolver */ public TypeResolver getTypeResolver();
public TypeResolver getTypeResolver();