Search in sources :

Example 1 with BasicType

use of org.hibernate.type.BasicType in project hibernate-orm by hibernate.

the class BasicTypeRegistryTest method testExpanding.

@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);
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractSingleColumnStandardBasicType(org.hibernate.type.AbstractSingleColumnStandardBasicType) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) Test(org.junit.Test)

Example 2 with BasicType

use of org.hibernate.type.BasicType in project hibernate-orm by hibernate.

the class BasicTypeRegistryTest method testOverriding.

@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);
}
Also used : BasicType(org.hibernate.type.BasicType) AbstractSingleColumnStandardBasicType(org.hibernate.type.AbstractSingleColumnStandardBasicType) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) UUIDCharType(org.hibernate.type.UUIDCharType) Test(org.junit.Test)

Example 3 with BasicType

use of org.hibernate.type.BasicType in project hibernate-orm by hibernate.

the class BasicTypeRegistryTest method testRegisteringUserTypes.

@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());
}
Also used : CustomType(org.hibernate.type.CustomType) CompositeCustomType(org.hibernate.type.CompositeCustomType) BasicType(org.hibernate.type.BasicType) AbstractSingleColumnStandardBasicType(org.hibernate.type.AbstractSingleColumnStandardBasicType) CompositeCustomType(org.hibernate.type.CompositeCustomType) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) UUID(java.util.UUID) Test(org.junit.Test)

Example 4 with BasicType

use of org.hibernate.type.BasicType in project hibernate-orm by hibernate.

the class MetadataBuildingProcess method handleTypes.

//	private static JandexInitManager buildJandexInitializer(
//			MetadataBuildingOptions options,
//			ClassLoaderAccess classLoaderAccess) {
//		final boolean autoIndexMembers = ConfigurationHelper.getBoolean(
//				org.hibernate.cfg.AvailableSettings.ENABLE_AUTO_INDEX_MEMBER_TYPES,
//				options.getServiceRegistry().getService( ConfigurationService.class ).getSettings(),
//				false
//		);
//
//		return new JandexInitManager( options.getJandexView(), classLoaderAccess, autoIndexMembers );
//	}
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() {

        @Override
        public void contributeType(org.hibernate.type.BasicType type) {
            basicTypeRegistry.register(type);
        }

        @Override
        public void contributeType(BasicType type, String... keys) {
            basicTypeRegistry.register(type, keys);
        }

        @Override
        public void contributeType(UserType type, String[] keys) {
            basicTypeRegistry.register(type, keys);
        }

        @Override
        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;
}
Also used : BasicType(org.hibernate.type.BasicType) TypeContributions(org.hibernate.boot.model.TypeContributions) Dialect(org.hibernate.dialect.Dialect) JdbcServices(org.hibernate.engine.jdbc.spi.JdbcServices) BasicTypeRegistry(org.hibernate.type.BasicTypeRegistry) BasicTypeRegistration(org.hibernate.boot.spi.BasicTypeRegistration) CompositeUserType(org.hibernate.usertype.CompositeUserType) UserType(org.hibernate.usertype.UserType) CompositeUserType(org.hibernate.usertype.CompositeUserType) ClassLoaderService(org.hibernate.boot.registry.classloading.spi.ClassLoaderService) TypeContributor(org.hibernate.boot.model.TypeContributor)

Example 5 with BasicType

use of org.hibernate.type.BasicType in project hibernate-orm by hibernate.

the class BasicAttributeOverrideTest method testIt.

@Test
@TestForIssue(jiraKey = "HHH-8630")
public void testIt() {
    final PersistentClass entityBinding = metadata().getEntityBinding(AggregatedTypeValue.class.getName());
    final Property attributesBinding = entityBinding.getProperty("attributes");
    final org.hibernate.mapping.Map attributesMap = (org.hibernate.mapping.Map) attributesBinding.getValue();
    final SimpleValue mapKey = assertTyping(SimpleValue.class, attributesMap.getIndex());
    final BasicType mapKeyType = assertTyping(BasicType.class, mapKey.getType());
    assertTrue(String.class.equals(mapKeyType.getReturnedClass()));
    // let's also make sure the @MapKeyColumn got applied
    assertThat(mapKey.getColumnSpan(), is(1));
    final org.hibernate.mapping.Column mapKeyColumn = assertTyping(org.hibernate.mapping.Column.class, mapKey.getColumnIterator().next());
    assertThat(mapKeyColumn.getName(), equalTo("attribute_name"));
}
Also used : BasicType(org.hibernate.type.BasicType) Property(org.hibernate.mapping.Property) Map(java.util.Map) PersistentClass(org.hibernate.mapping.PersistentClass) SimpleValue(org.hibernate.mapping.SimpleValue) Test(org.junit.Test) TestForIssue(org.hibernate.testing.TestForIssue)

Aggregations

BasicType (org.hibernate.type.BasicType)13 Test (org.junit.Test)10 SimpleValue (org.hibernate.mapping.SimpleValue)7 Type (org.hibernate.type.Type)6 MetadataSources (org.hibernate.boot.MetadataSources)5 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)5 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)5 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)5 PersistentClass (org.hibernate.mapping.PersistentClass)5 Property (org.hibernate.mapping.Property)5 AbstractStandardBasicType (org.hibernate.type.AbstractStandardBasicType)5 BasicTypeRegistry (org.hibernate.type.BasicTypeRegistry)4 AttributeConverterTypeAdapter (org.hibernate.type.descriptor.converter.AttributeConverterTypeAdapter)4 TestForIssue (org.hibernate.testing.TestForIssue)3 AbstractSingleColumnStandardBasicType (org.hibernate.type.AbstractSingleColumnStandardBasicType)3 Map (java.util.Map)2 SessionFactory (org.hibernate.SessionFactory)2 TypeContributor (org.hibernate.boot.model.TypeContributor)2 CustomType (org.hibernate.type.CustomType)2 HashMap (java.util.HashMap)1