Search in sources :

Example 1 with SerializableToBlobType

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

the class SerializableToBlobTypeTest method testTypeDefinition.

@Test
public void testTypeDefinition() {
    PersistentClass pc = metadata().getEntityBinding(EntitySerialize.class.getName());
    // explicitLob of SerializableToBlobType
    Type explicitLobType = pc.getProperty("explicitLob").getType();
    assertEquals(ExplicitSerializable.class, explicitLobType.getReturnedClass());
    assertEquals(SerializableToBlobType.class.getName(), explicitLobType.getName());
    // explicit of ExplicitSerializableType
    Type explicitType = pc.getProperty("explicit").getType();
    assertEquals(ExplicitSerializable.class, explicitType.getReturnedClass());
    assertEquals(ExplicitSerializableType.class.getName(), explicitType.getName());
    // implicit of ImplicitSerializableType
    Type implicitType = pc.getProperty("implicit").getType();
    assertEquals(ImplicitSerializable.class, implicitType.getReturnedClass());
    assertEquals(ImplicitSerializableType.class.getName(), implicitType.getName());
    // explicitOverridingImplicit ExplicitSerializableType overrides ImplicitSerializableType
    Type overrideType = pc.getProperty("explicitOverridingImplicit").getType();
    assertEquals(ImplicitSerializable.class, overrideType.getReturnedClass());
    assertEquals(ExplicitSerializableType.class.getName(), overrideType.getName());
}
Also used : SerializableToBlobType(org.hibernate.type.SerializableToBlobType) Type(org.hibernate.type.Type) SerializableToBlobType(org.hibernate.type.SerializableToBlobType) PersistentClass(org.hibernate.mapping.PersistentClass) Test(org.junit.Test)

Example 2 with SerializableToBlobType

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

the class BasicMetadataGenerator method addBasic.

@SuppressWarnings({ "unchecked" })
boolean addBasic(Element parent, PropertyAuditingData propertyAuditingData, Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
    final Type type = value.getType();
    if (type instanceof BasicType || type instanceof SerializableToBlobType || "org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) {
        if (parent != null) {
            final boolean addNestedType = (value instanceof SimpleValue) && ((SimpleValue) value).getTypeParameters() != null;
            String typeName = type.getName();
            if (typeName == null) {
                typeName = type.getClass().getName();
            }
            final Element propMapping = MetadataTools.addProperty(parent, propertyAuditingData.getName(), addNestedType ? null : typeName, propertyAuditingData.isForceInsertable() || insertable, key);
            MetadataTools.addColumns(propMapping, value.getColumnIterator());
            if (addNestedType) {
                final Properties typeParameters = ((SimpleValue) value).getTypeParameters();
                final Element typeMapping = propMapping.addElement("type");
                typeMapping.addAttribute("name", typeName);
                if ("org.hibernate.type.EnumType".equals(typeName)) {
                    // Proper handling of enumeration type
                    mapEnumerationType(typeMapping, type, typeParameters);
                } else {
                    // By default copying all Hibernate properties
                    for (Object object : typeParameters.keySet()) {
                        final String keyType = (String) object;
                        final String property = typeParameters.getProperty(keyType);
                        if (property != null) {
                            typeMapping.addElement("param").addAttribute("name", keyType).setText(property);
                        }
                    }
                }
            }
        }
        // A null mapper means that we only want to add xml mappings
        if (mapper != null) {
            mapper.add(propertyAuditingData.getPropertyData());
        }
    } else {
        return false;
    }
    return true;
}
Also used : BasicType(org.hibernate.type.BasicType) CustomType(org.hibernate.type.CustomType) SerializableToBlobType(org.hibernate.type.SerializableToBlobType) EnumType(org.hibernate.type.EnumType) Type(org.hibernate.type.Type) BasicType(org.hibernate.type.BasicType) SerializableToBlobType(org.hibernate.type.SerializableToBlobType) Element(org.dom4j.Element) Properties(java.util.Properties) SimpleValue(org.hibernate.mapping.SimpleValue)

Aggregations

SerializableToBlobType (org.hibernate.type.SerializableToBlobType)2 Type (org.hibernate.type.Type)2 Properties (java.util.Properties)1 Element (org.dom4j.Element)1 PersistentClass (org.hibernate.mapping.PersistentClass)1 SimpleValue (org.hibernate.mapping.SimpleValue)1 BasicType (org.hibernate.type.BasicType)1 CustomType (org.hibernate.type.CustomType)1 EnumType (org.hibernate.type.EnumType)1 Test (org.junit.Test)1