@Test public void testLocalSessionFactoryBeanWithTypeDefinitions() throws Exception { DefaultListableBeanFactory xbf = new DefaultListableBeanFactory(); new XmlBeanDefinitionReader(xbf).loadBeanDefinitions(new ClassPathResource("typeDefinitions.xml", getClass())); TypeTestLocalSessionFactoryBean sf = (TypeTestLocalSessionFactoryBean) xbf.getBean("&sessionFactory"); // Requires re-compilation when switching to Hibernate 3.5/3.6 // since Mappings changed from a class to an interface TypeDef type1 = sf.mappings.getTypeDef("type1"); TypeDef type2 = sf.mappings.getTypeDef("type2"); assertEquals("mypackage.MyTypeClass", type1.getTypeClass()); assertEquals(2, type1.getParameters().size()); assertEquals("value1", type1.getParameters().getProperty("param1")); assertEquals("othervalue", type1.getParameters().getProperty("otherParam")); assertEquals("mypackage.MyOtherTypeClass", type2.getTypeClass()); assertEquals(1, type2.getParameters().size()); assertEquals("myvalue", type2.getParameters().getProperty("myParam")); }
private static void resolveAndBindTypeDef(SimpleValue simpleValue, Mappings mappings, String typeName, Properties parameters) { TypeDef typeDef = mappings.getTypeDef( typeName ); if ( typeDef != null ) { typeName = typeDef.getTypeClass(); // parameters on the property mapping should // override parameters in the typedef Properties allParameters = new Properties(); allParameters.putAll( typeDef.getParameters() ); allParameters.putAll( parameters ); parameters = allParameters; }else if (typeName!=null && !mappings.isInSecondPass()){ BasicType basicType=mappings.getTypeResolver().basic(typeName); if (basicType==null) { /* * If the referenced typeName isn't a basic-type, it's probably a typedef defined * in a mapping file not read yet. * It should be solved by deferring the resolution and binding of this type until * all mapping files are read - the second passes. * Fixes issue HHH-7300 */ SecondPass resolveUserTypeMappingSecondPass=new ResolveUserTypeMappingSecondPass(simpleValue,typeName,mappings,parameters); mappings.addSecondPass(resolveUserTypeMappingSecondPass); } } if ( !parameters.isEmpty() ) simpleValue.setTypeParameters( parameters ); if ( typeName != null ) simpleValue.setTypeName( typeName ); }
private static void bindSimpleValueType(Element node, SimpleValue simpleValue, Mappings mappings) throws MappingException { String typeName = null; Properties parameters = new Properties(); Attribute typeNode = node.attribute( "type" ); if ( typeNode == null ) typeNode = node.attribute( "id-type" ); // for an any if ( typeNode != null ) typeName = typeNode.getValue(); Element typeChild = node.element( "type" ); if ( typeName == null && typeChild != null ) { typeName = typeChild.attribute( "name" ).getValue(); Iterator typeParameters = typeChild.elementIterator( "param" ); while ( typeParameters.hasNext() ) { Element paramElement = (Element) typeParameters.next(); parameters.setProperty( paramElement.attributeValue( "name" ), paramElement.getTextTrim() ); } } TypeDef typeDef = mappings.getTypeDef( typeName ); if ( typeDef != null ) { typeName = typeDef.getTypeClass(); // parameters on the property mapping should // override parameters in the typedef Properties allParameters = new Properties(); allParameters.putAll( typeDef.getParameters() ); allParameters.putAll( parameters ); parameters = allParameters; } if ( !parameters.isEmpty() ) simpleValue.setTypeParameters( parameters ); if ( typeName != null ) simpleValue.setTypeName( typeName ); }
protected void reset() { metadataSourceQueue = new MetadataSourceQueue(); createReflectionManager(); classes = new HashMap<String,PersistentClass>(); imports = new HashMap<String,String>(); collections = new HashMap<String,Collection>(); tables = new TreeMap<String,Table>(); namedQueries = new HashMap<String,NamedQueryDefinition>(); namedSqlQueries = new HashMap<String,NamedSQLQueryDefinition>(); sqlResultSetMappings = new HashMap<String, ResultSetMappingDefinition>(); namedEntityGraphMap = new HashMap<String, NamedEntityGraphDefinition>(); namedProcedureCallMap = new HashMap<String, NamedProcedureCallDefinition>( ); typeDefs = new HashMap<String,TypeDef>(); filterDefinitions = new HashMap<String, FilterDefinition>(); fetchProfiles = new HashMap<String, FetchProfile>(); auxiliaryDatabaseObjects = new ArrayList<AuxiliaryDatabaseObject>(); tableNameBinding = new HashMap(); columnNameBindingPerTable = new HashMap(); secondPasses = new ArrayList<SecondPass>(); propertyReferences = new ArrayList<Mappings.PropertyReference>(); extendsQueue = new HashMap<ExtendsQueueEntry, String>(); xmlHelper = new XMLHelper(); interceptor = EmptyInterceptor.INSTANCE; properties = Environment.getProperties(); entityResolver = XMLHelper.DEFAULT_DTD_RESOLVER; sqlFunctions = new HashMap<String, SQLFunction>(); entityTuplizerFactory = new EntityTuplizerFactory(); // componentTuplizerFactory = new ComponentTuplizerFactory(); identifierGeneratorFactory = new DefaultIdentifierGeneratorFactory(); mappedSuperClasses = new HashMap<Class<?>, MappedSuperclass>(); metadataSourcePrecedence = Collections.emptyList(); namedGenerators = new HashMap<String, IdGenerator>(); joins = new HashMap<String, Map<String, Join>>(); classTypes = new HashMap<String, AnnotatedClassType>(); generatorTables = new HashMap<String, Properties>(); defaultNamedQueryNames = new HashSet<String>(); defaultNamedNativeQueryNames = new HashSet<String>(); defaultSqlResultSetMappingNames = new HashSet<String>(); defaultNamedProcedure = new HashSet<String>( ); defaultNamedGenerators = new HashSet<String>(); uniqueConstraintHoldersByTable = new HashMap<Table, List<UniqueConstraintHolder>>(); jpaIndexHoldersByTable = new HashMap<Table,List<JPAIndexHolder>>( ); mappedByResolver = new HashMap<String, String>(); propertyRefResolver = new HashMap<String, String>(); caches = new ArrayList<CacheHolder>(); namingStrategyDelegator = LegacyNamingStrategyDelegator.DEFAULT_INSTANCE; setEntityResolver( new EJB3DTDEntityResolver() ); anyMetaDefs = new HashMap<String, AnyMetaDef>(); propertiesAnnotatedWithMapsId = new HashMap<XClass, Map<String, PropertyData>>(); propertiesAnnotatedWithIdAndToOne = new HashMap<XClass, Map<String, PropertyData>>(); specjProprietarySyntaxEnabled = System.getProperty( "hibernate.enable_specj_proprietary_syntax" ) != null; }
public TypeDef getTypeDef(String typeName) { return typeDefs.get( typeName ); }
public void addTypeDef(String typeName, String typeClass, Properties paramMap) { TypeDef def = new TypeDef( typeClass, paramMap ); typeDefs.put( typeName, def ); LOG.debugf( "Added %s with class %s", typeName, typeClass ); }
public void addTypeDef(String typeName, String typeClass, Properties paramMap) { TypeDef def = new TypeDef(typeClass, paramMap); typeDefs.put(typeName, def); log.debug("Added " + typeName + " with class " + typeClass); }
public TypeDef getTypeDef(String typeName) { return (TypeDef) typeDefs.get(typeName); }
/** * Retrieve a type definition by name. * * @param typeName The name of the type definition to retrieve. * @return The type definition, or null if none found. */ public TypeDef getTypeDef(String typeName);