* always adding a nested type mapping, if there are type properties; not only in case of instances of CustomType
* simplifying the basic generator because of the new type hierarchy git-svn-id: https://svn.jboss.org/repos/hibernate/core/trunk@19703 1b8cb986-b30d-0410-93ca-fae66ebed9b2
This commit is contained in:
parent
f0df563982
commit
3766cea7c2
|
@ -34,8 +34,6 @@ import org.hibernate.mapping.Column;
|
||||||
import org.hibernate.mapping.SimpleValue;
|
import org.hibernate.mapping.SimpleValue;
|
||||||
import org.hibernate.mapping.Value;
|
import org.hibernate.mapping.Value;
|
||||||
import org.hibernate.type.BasicType;
|
import org.hibernate.type.BasicType;
|
||||||
import org.hibernate.type.CompositeCustomType;
|
|
||||||
import org.hibernate.type.CustomType;
|
|
||||||
import org.hibernate.type.Type;
|
import org.hibernate.type.Type;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -43,53 +41,24 @@ import org.hibernate.type.Type;
|
||||||
* @author Adam Warski (adam at warski dot org)
|
* @author Adam Warski (adam at warski dot org)
|
||||||
*/
|
*/
|
||||||
public final class BasicMetadataGenerator {
|
public final class BasicMetadataGenerator {
|
||||||
|
@SuppressWarnings({"unchecked"})
|
||||||
boolean addBasic(Element parent, PropertyAuditingData propertyAuditingData,
|
boolean addBasic(Element parent, PropertyAuditingData propertyAuditingData,
|
||||||
Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
|
Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
|
||||||
Type type = value.getType();
|
Type type = value.getType();
|
||||||
|
|
||||||
if ( type instanceof BasicType ) {
|
if (type instanceof BasicType || "org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) {
|
||||||
addSimpleValue(parent, propertyAuditingData, value, mapper, insertable, key);
|
|
||||||
} else if (type instanceof CustomType || type instanceof CompositeCustomType) {
|
|
||||||
addCustomValue(parent, propertyAuditingData, value, mapper, insertable, key);
|
|
||||||
} else if ("org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) {
|
|
||||||
addSimpleValue(parent, propertyAuditingData, value, mapper, insertable, key);
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
|
||||||
private void addSimpleValue(Element parent, PropertyAuditingData propertyAuditingData,
|
|
||||||
Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
|
|
||||||
if (parent != null) {
|
if (parent != null) {
|
||||||
|
boolean addNestedType = (value instanceof SimpleValue) && ((SimpleValue) value).getTypeParameters() != null;
|
||||||
|
|
||||||
Element prop_mapping = MetadataTools.addProperty(parent, propertyAuditingData.getName(),
|
Element prop_mapping = MetadataTools.addProperty(parent, propertyAuditingData.getName(),
|
||||||
value.getType().getName(), propertyAuditingData.isForceInsertable() || insertable, key);
|
addNestedType ? null : value.getType().getName(), propertyAuditingData.isForceInsertable() || insertable, key);
|
||||||
MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
|
MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
|
||||||
}
|
|
||||||
|
|
||||||
// A null mapper means that we only want to add xml mappings
|
|
||||||
if (mapper != null) {
|
|
||||||
mapper.add(propertyAuditingData.getPropertyData());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@SuppressWarnings({"unchecked"})
|
|
||||||
private void addCustomValue(Element parent, PropertyAuditingData propertyAuditingData,
|
|
||||||
Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
|
|
||||||
if (parent != null) {
|
|
||||||
Element prop_mapping = MetadataTools.addProperty(parent, propertyAuditingData.getName(),
|
|
||||||
null, insertable, key);
|
|
||||||
|
|
||||||
//CustomType propertyType = (CustomType) value.getType();
|
|
||||||
|
|
||||||
|
if (addNestedType) {
|
||||||
|
Properties typeParameters = ((SimpleValue) value).getTypeParameters();
|
||||||
Element type_mapping = prop_mapping.addElement("type");
|
Element type_mapping = prop_mapping.addElement("type");
|
||||||
type_mapping.addAttribute("name", value.getType().getName());
|
type_mapping.addAttribute("name", value.getType().getName());
|
||||||
|
|
||||||
if (value instanceof SimpleValue) {
|
|
||||||
Properties typeParameters = ((SimpleValue) value).getTypeParameters();
|
|
||||||
if (typeParameters != null) {
|
|
||||||
for (java.util.Map.Entry paramKeyValue : typeParameters.entrySet()) {
|
for (java.util.Map.Entry paramKeyValue : typeParameters.entrySet()) {
|
||||||
Element type_param = type_mapping.addElement("param");
|
Element type_param = type_mapping.addElement("param");
|
||||||
type_param.addAttribute("name", (String) paramKeyValue.getKey());
|
type_param.addAttribute("name", (String) paramKeyValue.getKey());
|
||||||
|
@ -98,11 +67,14 @@ public final class BasicMetadataGenerator {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
|
// A null mapper means that we only want to add xml mappings
|
||||||
}
|
|
||||||
|
|
||||||
if (mapper != null) {
|
if (mapper != null) {
|
||||||
mapper.add(propertyAuditingData.getPropertyData());
|
mapper.add(propertyAuditingData.getPropertyData());
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue