Search in sources :

Example 21 with SimpleValue

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);
}
Also used : RootClass(org.hibernate.mapping.RootClass) Table(org.hibernate.mapping.Table) Set(org.hibernate.mapping.Set) ValueVisitor(org.hibernate.mapping.ValueVisitor) DependantValue(org.hibernate.mapping.DependantValue) MetadataSources(org.hibernate.boot.MetadataSources) Bag(org.hibernate.mapping.Bag) IdentifierBag(org.hibernate.mapping.IdentifierBag) MetadataImplementor(org.hibernate.boot.spi.MetadataImplementor) IdentifierBag(org.hibernate.mapping.IdentifierBag) OneToMany(org.hibernate.mapping.OneToMany) Any(org.hibernate.mapping.Any) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) Array(org.hibernate.mapping.Array) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) OneToOne(org.hibernate.mapping.OneToOne) PrimitiveArray(org.hibernate.mapping.PrimitiveArray) List(org.hibernate.mapping.List) Component(org.hibernate.mapping.Component) Map(org.hibernate.mapping.Map) Test(org.junit.Test)

Example 22 with SimpleValue

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;
}
Also used : Table(org.hibernate.mapping.Table) Column(org.hibernate.mapping.Column) PrimaryKey(org.hibernate.mapping.PrimaryKey) SimpleValue(org.hibernate.mapping.SimpleValue)

Example 23 with SimpleValue

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;
}
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)

Example 24 with SimpleValue

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);
    }
}
Also used : PluralAttributeMapKeyManyToAnySource(org.hibernate.boot.model.source.spi.PluralAttributeMapKeyManyToAnySource) PluralAttributeElementSourceManyToAny(org.hibernate.boot.model.source.spi.PluralAttributeElementSourceManyToAny) Any(org.hibernate.mapping.Any) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) MappingException(org.hibernate.boot.MappingException) Identifier(org.hibernate.boot.model.naming.Identifier) PluralAttributeMapKeySourceEmbedded(org.hibernate.boot.model.source.spi.PluralAttributeMapKeySourceEmbedded) PluralAttributeMapKeyManyToManySource(org.hibernate.boot.model.source.spi.PluralAttributeMapKeyManyToManySource) LocalMetadataBuildingContext(org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext) Component(org.hibernate.mapping.Component) ImplicitMapKeyColumnNameSource(org.hibernate.boot.model.naming.ImplicitMapKeyColumnNameSource) PluralAttributeMapKeySourceBasic(org.hibernate.boot.model.source.spi.PluralAttributeMapKeySourceBasic)

Example 25 with SimpleValue

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);
    }
}
Also used : SingularAttributeSourceBasic(org.hibernate.boot.model.source.spi.SingularAttributeSourceBasic) VersionAttributeSource(org.hibernate.boot.model.source.spi.VersionAttributeSource) AttributeSource(org.hibernate.boot.model.source.spi.AttributeSource) PluralAttributeSource(org.hibernate.boot.model.source.spi.PluralAttributeSource) SingularAttributeSource(org.hibernate.boot.model.source.spi.SingularAttributeSource) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) AssertionFailure(org.hibernate.AssertionFailure) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) SingularAttributeSourceOneToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne) PluralAttributeElementSourceManyToAny(org.hibernate.boot.model.source.spi.PluralAttributeElementSourceManyToAny) Any(org.hibernate.mapping.Any) SingularAttributeSourceAny(org.hibernate.boot.model.source.spi.SingularAttributeSourceAny) SingularAttributeSourceEmbedded(org.hibernate.boot.model.source.spi.SingularAttributeSourceEmbedded) SingularAttributeSourceManyToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceManyToOne) ManyToOne(org.hibernate.mapping.ManyToOne) SimpleValue(org.hibernate.mapping.SimpleValue) PluralAttributeSource(org.hibernate.boot.model.source.spi.PluralAttributeSource) OneToOne(org.hibernate.mapping.OneToOne) SingularAttributeSourceOneToOne(org.hibernate.boot.model.source.spi.SingularAttributeSourceOneToOne) Component(org.hibernate.mapping.Component) Property(org.hibernate.mapping.Property) SyntheticProperty(org.hibernate.mapping.SyntheticProperty)

Aggregations

SimpleValue (org.hibernate.mapping.SimpleValue)42 Property (org.hibernate.mapping.Property)23 PersistentClass (org.hibernate.mapping.PersistentClass)18 Column (org.hibernate.mapping.Column)13 Test (org.junit.Test)12 AnnotationException (org.hibernate.AnnotationException)11 MetadataSources (org.hibernate.boot.MetadataSources)11 StandardServiceRegistry (org.hibernate.boot.registry.StandardServiceRegistry)10 StandardServiceRegistryBuilder (org.hibernate.boot.registry.StandardServiceRegistryBuilder)10 Identifier (org.hibernate.boot.model.naming.Identifier)9 Component (org.hibernate.mapping.Component)8 DependantValue (org.hibernate.mapping.DependantValue)8 BasicType (org.hibernate.type.BasicType)8 LocalMetadataBuildingContext (org.hibernate.boot.model.source.spi.LocalMetadataBuildingContext)7 MetadataImplementor (org.hibernate.boot.spi.MetadataImplementor)7 Table (org.hibernate.mapping.Table)7 RootClass (org.hibernate.mapping.RootClass)6 AssertionFailure (org.hibernate.AssertionFailure)5 Collection (org.hibernate.mapping.Collection)5 ManyToOne (org.hibernate.mapping.ManyToOne)5