* 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:
Adam Warski 2010-06-09 08:52:22 +00:00
parent f0df563982
commit 3766cea7c2
1 changed files with 26 additions and 54 deletions

View File

@ -34,8 +34,6 @@ import org.hibernate.mapping.Column;
import org.hibernate.mapping.SimpleValue;
import org.hibernate.mapping.Value;
import org.hibernate.type.BasicType;
import org.hibernate.type.CompositeCustomType;
import org.hibernate.type.CustomType;
import org.hibernate.type.Type;
/**
@ -43,66 +41,40 @@ import org.hibernate.type.Type;
* @author Adam Warski (adam at warski dot org)
*/
public final class BasicMetadataGenerator {
@SuppressWarnings({"unchecked"})
boolean addBasic(Element parent, PropertyAuditingData propertyAuditingData,
Value value, SimpleMapperBuilder mapper, boolean insertable, boolean key) {
Type type = value.getType();
if ( type instanceof BasicType ) {
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);
if (type instanceof BasicType || "org.hibernate.type.PrimitiveByteArrayBlobType".equals(type.getClass().getName())) {
if (parent != null) {
boolean addNestedType = (value instanceof SimpleValue) && ((SimpleValue) value).getTypeParameters() != null;
Element prop_mapping = MetadataTools.addProperty(parent, propertyAuditingData.getName(),
addNestedType ? null : value.getType().getName(), propertyAuditingData.isForceInsertable() || insertable, key);
MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
if (addNestedType) {
Properties typeParameters = ((SimpleValue) value).getTypeParameters();
Element type_mapping = prop_mapping.addElement("type");
type_mapping.addAttribute("name", value.getType().getName());
for (java.util.Map.Entry paramKeyValue : typeParameters.entrySet()) {
Element type_param = type_mapping.addElement("param");
type_param.addAttribute("name", (String) paramKeyValue.getKey());
type_param.setText((String) paramKeyValue.getValue());
}
}
}
// A null mapper means that we only want to add xml mappings
if (mapper != null) {
mapper.add(propertyAuditingData.getPropertyData());
}
} 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) {
Element prop_mapping = MetadataTools.addProperty(parent, propertyAuditingData.getName(),
value.getType().getName(), propertyAuditingData.isForceInsertable() || insertable, key);
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();
Element type_mapping = prop_mapping.addElement("type");
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()) {
Element type_param = type_mapping.addElement("param");
type_param.addAttribute("name", (String) paramKeyValue.getKey());
type_param.setText((String) paramKeyValue.getValue());
}
}
}
MetadataTools.addColumns(prop_mapping, (Iterator<Column>) value.getColumnIterator());
}
if (mapper != null) {
mapper.add(propertyAuditingData.getPropertyData());
}
}
}