@Test public void testExpanding() { BasicTypeRegistry registry = new BasicTypeRegistry(); BasicType type = registry.getRegisteredType(SomeNoopType.INSTANCE.getName()); assertNull(type); registry.register(SomeNoopType.INSTANCE); type = registry.getRegisteredType(SomeNoopType.INSTANCE.getName()); assertNotNull(type); assertSame(SomeNoopType.INSTANCE, type); }
@Test public void testRegisteringUserTypes() { BasicTypeRegistry registry = new BasicTypeRegistry(); registry.register(new TotallyIrrelevantUserType(), new String[] {"key"}); BasicType type = registry.getRegisteredType("key"); assertNotNull(type); assertEquals(CustomType.class, type.getClass()); assertEquals(TotallyIrrelevantUserType.class, ((CustomType) type).getUserType().getClass()); registry.register(new TotallyIrrelevantCompositeUserType(), new String[] {"key"}); type = registry.getRegisteredType("key"); assertNotNull(type); assertEquals(CompositeCustomType.class, type.getClass()); assertEquals( TotallyIrrelevantCompositeUserType.class, ((CompositeCustomType) type).getUserType().getClass()); type = registry.getRegisteredType(UUID.class.getName()); assertSame(UUIDBinaryType.INSTANCE, type); registry.register(new TotallyIrrelevantUserType(), new String[] {UUID.class.getName()}); type = registry.getRegisteredType(UUID.class.getName()); assertNotSame(UUIDBinaryType.INSTANCE, type); assertEquals(CustomType.class, type.getClass()); }
private static BasicTypeRegistry handleTypes(MetadataBuildingOptions options) { final ClassLoaderService classLoaderService = options.getServiceRegistry().getService(ClassLoaderService.class); // ultimately this needs to change a little bit to account for HHH-7792 final BasicTypeRegistry basicTypeRegistry = new BasicTypeRegistry(); final TypeContributions typeContributions = new TypeContributions() { public void contributeType(BasicType type) { basicTypeRegistry.register(type); } public void contributeType(BasicType type, String... keys) { basicTypeRegistry.register(type, keys); } public void contributeType(UserType type, String... keys) { basicTypeRegistry.register(type, keys); } public void contributeType(CompositeUserType type, String... keys) { basicTypeRegistry.register(type, keys); } }; // add Dialect contributed types final Dialect dialect = options.getServiceRegistry().getService(JdbcServices.class).getDialect(); dialect.contributeTypes(typeContributions, options.getServiceRegistry()); // add TypeContributor contributed types. for (TypeContributor contributor : classLoaderService.loadJavaServices(TypeContributor.class)) { contributor.contribute(typeContributions, options.getServiceRegistry()); } // add explicit application registered types for (BasicTypeRegistration basicTypeRegistration : options.getBasicTypeRegistrations()) { basicTypeRegistry.register( basicTypeRegistration.getBasicType(), basicTypeRegistration.getRegistrationKeys()); } return basicTypeRegistry; }
@Test public void testOverriding() { BasicTypeRegistry registry = new BasicTypeRegistry(); BasicType type = registry.getRegisteredType("uuid-binary"); assertSame(UUIDBinaryType.INSTANCE, type); type = registry.getRegisteredType(UUID.class.getName()); assertSame(UUIDBinaryType.INSTANCE, type); BasicType override = new UUIDCharType() { @Override protected boolean registerUnderJavaType() { return true; } }; registry.register(override); type = registry.getRegisteredType(UUID.class.getName()); assertNotSame(UUIDBinaryType.INSTANCE, type); assertSame(override, type); }