use of org.hibernate.mapping.SimpleValue in project hibernate-orm by hibernate.
the class ValueVisitorTest method testProperCallbacks.
@Test
public void testProperCallbacks() {
final MetadataImplementor metadata = (MetadataImplementor) new MetadataSources(serviceRegistry).buildMetadata();
final Table tbl = new Table();
final RootClass rootClass = new RootClass(metadataBuildingContext);
ValueVisitor vv = new ValueVisitorValidator();
new Any(metadata, tbl).accept(vv);
new Array(metadata, rootClass).accept(vv);
new Bag(metadata, rootClass).accept(vv);
new Component(metadata, rootClass).accept(vv);
new DependantValue(metadata, tbl, null).accept(vv);
new IdentifierBag(metadata, rootClass).accept(vv);
new List(metadata, rootClass).accept(vv);
new ManyToOne(metadata, tbl).accept(vv);
new Map(metadata, rootClass).accept(vv);
new OneToMany(metadata, rootClass).accept(vv);
new OneToOne(metadata, tbl, rootClass).accept(vv);
new PrimitiveArray(metadata, rootClass).accept(vv);
new Set(metadata, rootClass).accept(vv);
new SimpleValue(metadata).accept(vv);
}
use of org.hibernate.mapping.SimpleValue in project uPortal by Jasig.
the class TableXmlHandler method endElement.
/* (non-Javadoc)
* @see org.xml.sax.helpers.DefaultHandler#endElement(java.lang.String, java.lang.String, java.lang.String)
*/
@Override
public void endElement(String uri, String localName, String name) throws SAXException {
if ("table".equals(name)) {
for (final Column column : this.currentColumns.values()) {
this.currentTable.addColumn(column);
}
if (this.primaryKey != null) {
this.currentTable.setPrimaryKey(this.primaryKey);
}
this.tables.put(this.currentTable.getName(), this.currentTable);
this.tableColumnTypes.put(this.currentTable.getName(), this.currentColumnTypes);
this.primaryKey = null;
this.currentColumns = null;
this.currentColumnTypes = null;
this.currentTable = null;
} else if ("column".equals(name)) {
this.currentColumns.put(this.currentColumn.getName(), this.currentColumn);
this.currentColumn = null;
} else if ("name".equals(name)) {
final String itemName = this.chars.toString().trim();
if (this.currentIndex != null) {
this.currentIndex.setName(itemName);
} else if (this.currentUnique != null) {
this.currentUnique.setName(itemName);
} else if (this.currentTable == null) {
this.currentTable = new Table(itemName);
} else if (this.currentColumn == null) {
this.currentColumn = new Column(itemName);
}
} else if ("type".equals(name)) {
final String sqlTypeName = this.chars.toString().trim();
final int sqlType = this.getSqlType(sqlTypeName);
this.currentColumnTypes.put(this.currentColumn.getName(), sqlType);
final String hibType = this.getHibernateType(sqlType);
final SimpleValue value = new SimpleValue(this.mappings, this.currentTable);
value.setTypeName(hibType);
this.currentColumn.setValue(value);
} else if ("param".equals(name)) {
final String param = this.chars.toString().trim();
final Integer length = Integer.valueOf(param);
this.currentColumn.setLength(length);
} else if ("primary-key".equals(name)) {
final String columnName = this.chars.toString().trim();
if (this.primaryKey == null) {
this.primaryKey = new PrimaryKey();
}
final Column column = this.currentColumns.get(columnName);
this.primaryKey.addColumn(column);
} else if ("not-null".equals(name)) {
final String columnName = this.chars.toString().trim();
final Column column = this.currentColumns.get(columnName);
column.setNullable(false);
} else if ("column-ref".equals(name)) {
final String columnName = this.chars.toString().trim();
final Column column = this.currentColumns.get(columnName);
if (this.currentIndex != null) {
this.currentIndex.addColumn(column);
} else if (this.currentUnique != null) {
this.currentUnique.addColumn(column);
}
} else if ("index".equals(name)) {
this.currentTable.addIndex(this.currentIndex);
this.currentIndex = null;
} else if ("unique".equals(name)) {
this.currentTable.addUniqueKey(this.currentUnique);
this.currentUnique = null;
} else if ("key".equals(name)) {
this.logger.warn("the 'key' element is ignored, use the table level 'primary-key' element instead");
}
this.chars = null;
}
use of org.hibernate.mapping.SimpleValue 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;
}
use of org.hibernate.mapping.SimpleValue in project hibernate-orm by hibernate.
the class ModelBinder method bindMapKey.
private void bindMapKey(final MappingDocument mappingDocument, final IndexedPluralAttributeSource pluralAttributeSource, final org.hibernate.mapping.Map collectionBinding) {
if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceBasic) {
final PluralAttributeMapKeySourceBasic mapKeySource = (PluralAttributeMapKeySourceBasic) pluralAttributeSource.getIndexSource();
final SimpleValue value = new SimpleValue(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
bindSimpleValueType(mappingDocument, mapKeySource.getTypeInformation(), value);
if (!value.isTypeSpecified()) {
throw new MappingException("map index element must specify a type: " + pluralAttributeSource.getAttributeRole().getFullPath(), mappingDocument.getOrigin());
}
relationalObjectBinder.bindColumnsAndFormulas(mappingDocument, mapKeySource.getRelationalValueSources(), value, true, new RelationalObjectBinder.ColumnNamingDelegate() {
@Override
public Identifier determineImplicitName(LocalMetadataBuildingContext context) {
return database.toIdentifier(IndexedCollection.DEFAULT_INDEX_COLUMN_NAME);
}
});
collectionBinding.setIndex(value);
} else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeySourceEmbedded) {
final PluralAttributeMapKeySourceEmbedded mapKeySource = (PluralAttributeMapKeySourceEmbedded) pluralAttributeSource.getIndexSource();
final Component componentBinding = new Component(mappingDocument.getMetadataCollector(), collectionBinding);
bindComponent(mappingDocument, mapKeySource.getEmbeddableSource(), componentBinding, null, pluralAttributeSource.getName(), mapKeySource.getXmlNodeName(), false);
collectionBinding.setIndex(componentBinding);
} else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToManySource) {
final PluralAttributeMapKeyManyToManySource mapKeySource = (PluralAttributeMapKeyManyToManySource) pluralAttributeSource.getIndexSource();
final ManyToOne mapKeyBinding = new ManyToOne(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
mapKeyBinding.setReferencedEntityName(mapKeySource.getReferencedEntityName());
relationalObjectBinder.bindColumnsAndFormulas(mappingDocument, mapKeySource.getRelationalValueSources(), mapKeyBinding, true, new RelationalObjectBinder.ColumnNamingDelegate() {
@Override
public Identifier determineImplicitName(final LocalMetadataBuildingContext context) {
return implicitNamingStrategy.determineMapKeyColumnName(new ImplicitMapKeyColumnNameSource() {
@Override
public AttributePath getPluralAttributePath() {
return pluralAttributeSource.getAttributePath();
}
@Override
public MetadataBuildingContext getBuildingContext() {
return context;
}
});
}
});
collectionBinding.setIndex(mapKeyBinding);
} else if (pluralAttributeSource.getIndexSource() instanceof PluralAttributeMapKeyManyToAnySource) {
final PluralAttributeMapKeyManyToAnySource mapKeySource = (PluralAttributeMapKeyManyToAnySource) pluralAttributeSource.getIndexSource();
final Any mapKeyBinding = new Any(mappingDocument.getMetadataCollector(), collectionBinding.getCollectionTable());
bindAny(mappingDocument, mapKeySource, mapKeyBinding, pluralAttributeSource.getAttributeRole().append("key"), pluralAttributeSource.getAttributePath().append("key"));
collectionBinding.setIndex(mapKeyBinding);
}
}
use of org.hibernate.mapping.SimpleValue in project hibernate-orm by hibernate.
the class ModelBinder method bindAllCompositeAttributes.
private void bindAllCompositeAttributes(MappingDocument sourceDocument, EmbeddableSource embeddableSource, Component component) {
for (AttributeSource attributeSource : embeddableSource.attributeSources()) {
Property attribute = null;
if (SingularAttributeSourceBasic.class.isInstance(attributeSource)) {
attribute = createBasicAttribute(sourceDocument, (SingularAttributeSourceBasic) attributeSource, new SimpleValue(sourceDocument.getMetadataCollector(), component.getTable()), component.getComponentClassName());
} else if (SingularAttributeSourceEmbedded.class.isInstance(attributeSource)) {
attribute = createEmbeddedAttribute(sourceDocument, (SingularAttributeSourceEmbedded) attributeSource, new Component(sourceDocument.getMetadataCollector(), component), component.getComponentClassName());
} else if (SingularAttributeSourceManyToOne.class.isInstance(attributeSource)) {
attribute = createManyToOneAttribute(sourceDocument, (SingularAttributeSourceManyToOne) attributeSource, new ManyToOne(sourceDocument.getMetadataCollector(), component.getTable()), component.getComponentClassName());
} else if (SingularAttributeSourceOneToOne.class.isInstance(attributeSource)) {
attribute = createOneToOneAttribute(sourceDocument, (SingularAttributeSourceOneToOne) attributeSource, new OneToOne(sourceDocument.getMetadataCollector(), component.getTable(), component.getOwner()), component.getComponentClassName());
} else if (SingularAttributeSourceAny.class.isInstance(attributeSource)) {
attribute = createAnyAssociationAttribute(sourceDocument, (SingularAttributeSourceAny) attributeSource, new Any(sourceDocument.getMetadataCollector(), component.getTable()), component.getComponentClassName());
} else if (PluralAttributeSource.class.isInstance(attributeSource)) {
attribute = createPluralAttribute(sourceDocument, (PluralAttributeSource) attributeSource, component.getOwner());
} else {
throw new AssertionFailure(String.format(Locale.ENGLISH, "Unexpected AttributeSource sub-type [%s] as part of composite [%s]", attributeSource.getClass().getName(), attributeSource.getAttributeRole().getFullPath()));
}
component.addProperty(attribute);
}
}
Aggregations